/var/www/vhosts/ihelp.ro/ajutam.ro/wp-content/plugins/give/includes
Edit: /var/www/vhosts/ihelp.ro/ajutam.ro/wp-content/plugins/give/includes/class-give-license-handler.php (27610B)
item_id = absint( $_item_id );
}
$this->file = $_file;
$this->item_name = $_item_name;
$this->plugin_dirname = dirname( plugin_basename( $this->file ) );
$this->item_shortname = self::get_short_name( $this->item_name );
$this->license_data = self::get_license_by_plugin_dirname( $this->plugin_dirname );
$this->version = $_version;
$this->license = ! empty( $this->license_data['license_key'] ) ? $this->license_data['license_key'] : '';
$this->author = $_author;
self::$api_url = is_null( $_api_url ) ? self::$api_url : $_api_url;
self::$checkout_url = is_null( $_checkout_url ) ? self::$checkout_url : $_checkout_url;
self::$account_url = is_null( $_account_url ) ? self::$account_url : $_account_url;
$this->auto_updater_obj = null;
// Add plugin to registered licenses list.
array_push( self::$licensed_addons, plugin_basename( $this->file ) );
}
/**
* Get plugin shortname
*
* @param $plugin_name
*
* @return string
* @since 2.1.0
* @access public
*/
public static function get_short_name( $plugin_name ) {
$plugin_name = trim( str_replace( 'Give - ', '', $plugin_name ) );
$plugin_name = 'give_' . preg_replace( '/[^a-zA-Z0-9_\s]/', '', str_replace( ' ', '_', strtolower( $plugin_name ) ) );
return $plugin_name;
}
/**
* Activate License
*
* Activate the license key.
*
* @access public
* @return void
* @since 1.0
*/
public function activate_license() {
}
/**
* Deactivate License
*
* Deactivate the license key.
*
* @access public
* @return void
* @since 1.0
*/
public function deactivate_license() {
}
/**
* Get license information.
*
* @param string $edd_action
* @param bool $response_in_array
*
* @return mixed
* @deprecated 2.5.0 Use self::request_license_api instead.
*
* @since 1.8.9
* @access public
*/
public function get_license_info($edd_action = '', $response_in_array = false)
{
if ( empty($edd_action) ) {
return false;
}
give_doing_it_wrong(__FUNCTION__, 'Use self::request_license_api instead from GiveWP 2.5.0');
// Data to send to the API.
$api_params = [
'edd_action' => $edd_action, // never change from "edd_" to "give_"!
'license' => $this->license,
'item_name' => urlencode($this->item_name),
];
return self::request_license_api($api_params, $response_in_array);
}
/**
* Return licensed addons info
*
* Note: note only for internal logic
*
* @since 2.1.4
* @return array
*/
static function get_licensed_addons()
{
return self::$licensed_addons;
}
/**
* Check if license key attached to subscription
*
* @since 2.5.0
*
* @param string $license_key
*
* @return array
*/
static function is_subscription($license_key = '')
{
// Check if current license is part of subscription or not.
$subscriptions = get_option('give_subscriptions');
$subscription = [];
if ( $subscriptions ) {
foreach ($subscriptions as $subs) {
if ( in_array($license_key, $subs['licenses']) ) {
$subscription = $subs;
break;
}
}
}
return $subscription;
}
/**
* Get license information.
*
* @since 1.8.9
* @since 2.18.0 log failed license api request information
*
* @param bool $response_in_array
*
* @param array $api_params
*
* @return array|WP_Error
*/
public static function request_license_api($api_params = [], $response_in_array = false)
{
// Bailout.
if ( empty($api_params['edd_action']) ) {
return new WP_Error('give-invalid-edd-action', __('Valid edd_action not defined', 'give'));
}
// Data to send to the API.
$default_api_params = [
// 'edd_action' => $edd_action, never change from "edd_" to "give_"!
// 'license' => $this->license,
// 'item_name' => urlencode( $this->item_name ),
'url' => home_url(),
];
$api_params = wp_parse_args($api_params, $default_api_params);
// Call the API.
$response = wp_remote_post(
self::$api_url,
apply_filters(
'give_request_license_api_args',
[
'timeout' => 15,
'sslverify' => false,
'body' => $api_params,
]
)
);
$statusCode = wp_remote_retrieve_response_code($response);
$body = json_decode(wp_remote_retrieve_body($response), $response_in_array);
if ( 200 !== $statusCode ) {
Log::http(
'License Api request failed',
[
'category' => 'License',
'api url' => self::$api_url,
'request' => $api_params,
'status code' => $statusCode,
'response' => $response
]
);
}
// Make sure there are no errors.
if ( is_wp_error($response) ) {
return $response;
}
return $body;
}
/**
* Get license by plugin dirname
*
* @param string $plugin_dirname
*
* @return array
*
* @since 2.5.0
* @access public
*/
public static function get_license_by_plugin_dirname( $plugin_dirname ) {
$license = [];
$give_licenses = get_option( 'give_licenses', [] );
if ( ! empty( $give_licenses ) ) {
foreach ( $give_licenses as $give_license ) {
// Logic to match all access pass license to add-on.
$compares = $give_license['is_all_access_pass']
? $give_license['download']
// Prevent PHP notice if somehow automatic update does not run properly.
// Because plugin_slug will only define in updated license rest api response.
: [ [ 'plugin_slug' => ! empty( $give_license['plugin_slug'] ) ? $give_license['plugin_slug'] : '' ] ];
foreach ( $compares as $compare ) {
if ( ! empty( $compare['plugin_slug'] ) && $plugin_dirname === $compare['plugin_slug'] ) {
$license = $give_license;
break;
}
}
}
}
return $license;
}
/**
* Get checkout url
*
* @return string|null
* @since 2.5.0
*/
public static function get_checkout_url() {
return self::$checkout_url;
}
/**
* Get account url
*
* @return string|null
* @since 2.5.0
*/
public static function get_account_url() {
return self::$account_url;
}
/**
* Get downloads url
*
* @return string|null
* @since 2.5.0
*/
public static function get_downloads_url() {
return self::$downloads_url;
}
/**
* Get account url
*
* @return string|null
* @since 2.5.0
*/
public static function get_website_url() {
return self::$site_url;
}
/**
* Get plugin information by id.
* Note: only for internal use
*
* @param string $plugin_slug
*
* @return array
* @since 2.5.0
*/
public static function get_plugin_by_slug( $plugin_slug ) {
$give_plugins = give_get_plugins();
$matching_list = wp_list_pluck( $give_plugins, 'Dir', 'Path' );
$is_match_found = array_search( $plugin_slug, $matching_list, true );
return $is_match_found ? $give_plugins[ $is_match_found ] : [];
}
/**
* Get plugin information by id.
* Note: only for internal use
*
* @param string $plugin_slug
*
* @return string
* @since 2.5.0
*/
public static function build_plugin_name_from_slug( $plugin_slug ) {
$plugin_name = str_replace( [ '-', 'give ' ], [ ' ', 'Give - ' ], $plugin_slug );
return ucwords( $plugin_name );
}
/**
* Render license section
*
* @return string
* @since 2.5.0
*/
public static function render_licenses_list() {
$give_plugins = give_get_plugins( [ 'only_premium_add_ons' => true ] );
$give_licenses = get_option( 'give_licenses', [] );
$licenses_without_addon = $give_licenses;
// Get all access pass licenses
$all_access_pass_licenses = [];
$all_access_pass_addon_list = [];
foreach ( $give_licenses as $key => $give_license ) {
if ( $give_license['is_all_access_pass'] ) {
$all_access_pass_licenses[ $key ] = $give_license;
unset( $licenses_without_addon[ $key ] );
foreach ( $give_license['download'] as $download ) {
$all_access_pass_addon_list[] = $download['plugin_slug'];
}
}
}
$html = [
'unlicensed' => '',
'licensed' => '',
'licenses_without_addon' => '',
'all_access_licensed' => '',
];
if ( ! empty( $give_plugins ) ) {
foreach ( $give_plugins as $give_plugin ) {
if ( in_array( $give_plugin['Dir'], $all_access_pass_addon_list ) ) {
continue;
}
$addon_license = self::get_license_by_plugin_dirname( $give_plugin['Dir'] );
$html_arr_key = 'unlicensed';
if ( $addon_license ) {
$html_arr_key = 'licensed';
unset( $licenses_without_addon[ $addon_license['license_key'] ] );
}
$html[ "{$html_arr_key}" ] .= self::html_by_plugin( $give_plugin );
}
}
if ( ! empty( $all_access_pass_licenses ) ) {
foreach ( $all_access_pass_licenses as $key => $all_access_pass_license ) {
$html['all_access_licensed'] .= self::html_by_license( $all_access_pass_license );
}
}
if ( ! empty( $licenses_without_addon ) ) {
foreach ( $licenses_without_addon as $key => $license ) {
if ( in_array( $license['plugin_slug'], $all_access_pass_addon_list ) ) {
continue;
}
$html['licenses_without_addon'] .= self::html_by_license( $license );
}
}
ksort( $html );
// After sorting order will be all_access_licensed -> licensed -> unlicensed
return implode( '', $html );
}
/**
* Get add-on item html
* Note: only for internal use
*
* @param $plugin
*
* @return string
* @since 2.5.0
*/
public static function html_by_plugin( $plugin ) {
// Bailout.
if ( empty( $plugin ) ) {
return '';
}
ob_start();
$license = self::get_license_by_plugin_dirname( $plugin['Dir'] );
$default_plugin = [
'ChangeLogSlug' => $plugin['Dir'],
'DownloadURL' => '',
];
if ( false !== strpos( $default_plugin['ChangeLogSlug'], '-gateway' ) ) {
// We found that each gateway addon does not have `-gateway` in changelog file slug
$default_plugin['ChangeLogSlug'] = str_replace( '-gateway', '', $default_plugin['ChangeLogSlug'] );
}
if ( $license ) {
$license['renew_url'] = self::$checkout_url . "?edd_license_key={$license['license_key']}";
$default_plugin['ChangeLogSlug'] = $license['readme'];
$default_plugin['DownloadURL'] = $license['download'];
}
$plugin['License'] = $license = wp_parse_args(
$license,
[
'item_name' => str_replace( 'give-', '', $plugin['Dir'] ),
'purchase_link' => $plugin['PluginURI'],
]
);
$plugin = wp_parse_args( $plugin, $default_plugin );
?>
! empty( $addon['item_name'] ) ? $addon['item_name'] : $addon['name'],
'ChangeLogSlug' => $addon['readme'],
'Version' => $addon['current_version'],
'Status' => 'not installed',
// In single license key we will get download instead of file.
'DownloadURL' => ! empty( $addon['download'] ) ? $addon['download'] : $addon['file'],
];
$plugin = wp_parse_args(
self::get_plugin_by_slug( $addon['plugin_slug'] ),
$default_plugin
);
$plugin['Name'] = false !== strpos( $plugin['Name'], 'Give' )
? $plugin['Name']
: self::build_plugin_name_from_slug( $addon['plugin_slug'] );
$plugin['License'] = $license;
echo self::html_plugin_row( $plugin );
}
?>
>
%1$s',
__( 'Deactivate', 'give' ),
$license['license_key'],
$license['item_name'],
wp_create_nonce( "give-deactivate-license-{$license['item_name']}" ),
! empty( $license['plugin_slug'] ) ? $license['plugin_slug'] : ''
);
?>
%1$s',
$is_license_expired
? __( 'License is expired. Please activate your license key.', 'give' )
: __( 'License is active and you are receiving updates and support.', 'give' ),
$is_license_expired
? 'no'
: 'yes'
)
: sprintf(
'
%1$s %2$s',
__( 'License is inactive.', 'give' ),
$license_is_inactive
? sprintf(
__( 'Please
Visit your dashboard to check this license details and activate this license to receive updates and support.', 'give' ),
self::get_account_url()
)
: __( 'Please activate your license key.', 'give' )
);
?>
%1$s %2$s',
$is_license_expired ? __( 'Expired:', 'give' ) : __( 'Renews:', 'give' ),
date( give_date_format(), $expires_timestamp )
);
?>
%2$s',
$license['renew_url'],
__( 'Renew to manage sites', 'give' )
);
} elseif ( $license_key ) {
if ( ! $license['activations_left'] ) {
echo sprintf(
'
%1$s ',
__( 'No activations remaining', 'give' )
);
} else {
echo sprintf(
'
%1$s %2$s',
$license['activations_left'],
_n( 'Activation Remaining', 'Activations Remaining', $license['activations_left'], 'give' )
);
}
}
?>
%2$s',
$license['purchase_link'],
__( 'Purchase License', 'give' )
);
?>
%4$s',
trailingslashit( self::get_website_url() ),
$license['license_id'],
$license['payment_id'],
__( 'Manage License', 'give' )
);
echo sprintf(
'
%2$s ',
trailingslashit( self::get_website_url() ),
__( 'Access Support', 'give' )
);
}
?>
%2$s',
give_modal_ajax_url(
[
'url' => filter_var( $plugin['ChangeLogSlug'], FILTER_VALIDATE_URL )
? urldecode_deep( $plugin['ChangeLogSlug'] )
: urlencode_deep( give_get_addon_readme_url( $plugin['ChangeLogSlug'] ) ),
'show_changelog' => 1,
]
),
__( 'View Changelog', 'give' ),
__( 'Changelog of', 'give' ) . " {$plugin['Name']}"
);
?>
%1$s',
'active' === $plugin['Status'] ? __( 'activated', 'give' ) : __( 'installed', 'give' )
);
}
printf(
'<%3$s class="give-button button button-secondary button-small" href="%1$s"%4$s> %2$s%3$s>',
$plugin['DownloadURL'],
__( 'Download', 'give' ),
$is_license_expired || ! $plugin['DownloadURL'] ? 'button' : 'a',
$is_license_expired || ! $plugin['DownloadURL'] ? ' disabled' : ''
);
?>
date( 'Ymd' ),
'time' => time(),
'count' => 0,
]
);
}
/**
* Get all download slugs from all access pass key.
* Note: only for internal use and will be refactored in the future.
*
* @param array $license All access pass license data
*
* @return string[]
* @since 2.6.3
*/
public static function getAddonSlugsFromAllAccessPassLicense( $license ) {
$result = [];
foreach ( $license['download'] as $download ) {
$result[] = $download['plugin_slug'];
}
return $result;
}
}
endif; // end class_exists check.