$n) {
$license = '';
if (isset($_POST['key']) and is_array($_POST['key']) ) {
if (!empty($_POST['key'][$l])) {
$license = sanitize_key($_POST['key'][$l]);
}
}
amr_events_change_license($l, $license); // delete when empty
}
//else amr_flag_error ('Error processing license key updates','amr-events');
}
function amr_events_activate_licenses($licenses) {
if ( ! isset( $_POST['activate'] ) and !is_array($_POST['activate']) ) {
return;
}
foreach( $_POST['activate'] as $l => $activate ) { // will only do one at a time really
if (empty($_POST['key']) or (empty($_POST['key'][$l]))) {
amr_flag_error(sprintf(__('No license key entered for %s', 'amr-events'), $l));
continue; // we havent got this key
}
$license_key = sanitize_text_field( $_POST['key'][$l] );
// Data to send to the API
$api_params = array(
'edd_action' => 'activate_license',
'license' => $license_key,
'item_name' => urlencode( $licenses[$l] ),
'url' => home_url()
);
// Call the API
$response = wp_remote_post(
AMR_EVENTS_STORE_URL,
array(
'timeout' => 15,
'sslverify' => false,
'body' => $api_params
)
);
// Make sure there are no errors
if ( is_wp_error( $response ) or empty($response['body']) ) {
amr_flag_error(__('Error activating', 'amr-events'));
echo '
';print_r($response['response']);
print_r($response['body']); echo '
';
return;
}
// Decode license data
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
if (!empty($license_data->success) and $license_data->success) {
update_option( $l . '-license-status', $license_data->license );
// Tell WordPress to look for updates
set_site_transient( 'update_plugins', null );
amr_confirm_message(sprintf(__('%s auto updates activated','amr-events'),$l));
}
else {
amr_flag_error(__('Error activating with that license key', 'amr-events')
.' '.print_r($response['body'], true ));
}
}
}
function amr_events_deactivate_license($licenses) {
if ( ! isset( $_POST['deactivate'] ) and !is_array($_POST['deactivate']) ) {
return;
}
foreach( $_POST['deactivate'] as $l => $activate ) { // will only do one at a time really
if (empty($_POST['key'])) continue; // we got no keys
if (empty($_POST['key'][$l])) continue; // we havent got this key
$license_key = sanitize_text_field( $_POST['key'][$l] );
// Data to send to the API
$api_params = array(
'edd_action' => 'deactivate_license',
'license' => $license_key,
'item_name' => urlencode( $licenses[$l] ),
'url' => home_url()
);
// Call the API
$response = wp_remote_post(
AMR_EVENTS_STORE_URL,
array(
'timeout' => 15,
'sslverify' => false,
'body' => $api_params
)
);
if ( is_wp_error( $response ) or empty($response['body']) ) {
amr_flag_error(__('Error deactivating', 'amr-events'));
echo '';print_r($response['response']);
print_r($response['body']); echo '
';
return;
}
// Decode license data
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
if (!empty($license_data->license) and ($license_data->license=='deactivated')) {
delete_option( $l . '-license-status', $license_data->license );
amr_confirm_message(sprintf(__('%s auto updates deactivated','amr-events'),$l));
}
else {
amr_flag_error(__('License expired or error deactivating with that license key', 'amr-events').' '
.print_r($response['body'], true ));
//license probably expired
delete_option( $l . '-license-status', $license_data->license );
}
}
}
function amr_events_get_plugin_version($id) {
$license = trim( get_option( $id.'-license-key' ) );
$api_params = array(
'edd_action' => 'get_version',
'license' => $license,
'item_name' => urlencode( $id ),
'url' => home_url()
);
// Call the custom API.
$response = wp_remote_get(
add_query_arg( $api_params, AMR_EVENTS_STORE_URL ), // we specified this url so not coming from external sources - no esc_url_raw needed
array( 'timeout' => 15, 'sslverify' => false ) );
if ( is_wp_error( $response ) )
return false;
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
return $license_data;
}
function amr_events_show_version ($version_data) {
?> string '2.12' (length=4)
public 'name' => string 'amr users plus' (length=14)
public 'slug' => boolean false
public 'url' => string 'http://wpusersplugin.com/downloads/amr-events/?changelog=1' (length=62)
public 'homepage' => string 'http://wpusersplugin.com/downloads/amr-events/' (length=50)
public 'package' => string 'http://wpusersplugin.com/?edd_action=package_download&id=4213&key=001fe02f8ba95e799d29efedf9e80885&expires=MTQxMzg3Nzg1Nw%3D%3D' (length=127)
public 'download_link' => string 'http://wpusersplugin.com/?edd_action=package_download&id=4213&key=001fe02f8ba95e799d29efedf9e80885&expires=MTQxMzg3Nzg1Nw%3D%3D' (length=127)
public 'sections'
*/
//var_dump($version_data);
}
function amr_events_get_license_data($l) {
global $wp_version;
$license = trim( get_option( $l.'-license-key' ) );
$api_params = array(
'edd_action'=> 'check_license',
'license' => $license,
'item_name' => urlencode( $l ),
'url' => home_url()
);
// Call the custom API.
$response = wp_remote_get(
add_query_arg( $api_params,
AMR_EVENTS_STORE_URL ),
array( 'timeout' => 15,
'sslverify' => false )
);
if ( is_wp_error( $response ) )
return false;
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
if ($license_data->license == 'site_inactive') { // deactivated remotely at host site?
delete_option( $l . '-license-status', $license_data->license );
amr_flag_error(sprintf(__('%s at this site is inactive at remote host', 'amr-events'), $license_data->item_name));
}
return $license_data;
}
function amr_events_show_license($license_data) {
/*
'license_limit' =>__('Maximum sites for license','amr-events'),
'site_count' =>__('Sites using license key','amr-events'),
'activations_left' =>__('Activations left','amr-events')
*/
if (!empty($license_data->site_count))
$license_data->sites_limit = $license_data->site_count;
if (!empty($license_data->license_limit))
$license_data->sites_limit .= ' / '.$license_data->license_limit;
unset ($license_data->license_limit);
unset ($license_data->site_count);
unset ($license_data->activations_left);
$license_fields = array (
'license' =>__('Remote Status','amr-events'),
'sites_limit' =>__('Sites / Limit','amr-events'),
//'item_name' =>__('Item name','amr-events'),
'expires' =>__('Expiry Date','amr-events'),
//'payment_id' =>__('Payment id','amr-events'),
//'customer_name' =>__('Customer Name','amr-events'),
'customer_email' =>__('Customer Email','amr-events'),
);
if (!empty($license_data)) {
?> $fldtitle) {
echo '| '.$fldtitle.' | ';
}
?>
$fldtitle) {
?>| $fld)) {
if (($fld == 'expires') and ($license_data->$fld == '1970-01-01 00:00:00'))
echo '';
else
echo $license_data->$fld;
}
else echo ' ';
?> |
Error Fetching License Status. Try logging on to '.AMR_EVENTS_STORE_URL.'';
return false;
}
}
function amr_events_handle_license_data_request ($licenses) { // will normally only be one
foreach ($licenses as $l => $license_name) {
if (!empty($_POST['get_license_data'][$l])) {
$license_data = amr_events_get_license_data($l);
amr_events_show_license($license_data);
}
}
}
function amr_events_get_status_text($status) {
if (empty($status)) {
$status_text= ''.
__('Plugin updates not activated','amr-events')
.'';
}
elseif ( $status == 'valid' ) {
$status_text = ''.
__('Activated','amr-events')
.'';
}
else {
''.
$status_text =__('Deactivated','amr-events')
.'';
}
return ($status_text);
}
function amr_events_license_page() {
if (!current_user_can('manage_options')) return;
$licenses = amr_events_get_licenses(); // ones we already have saved and new ones from plugins just activated.
// check if we should be doing any form processing and was the post from this page
if ( isset( $_POST['submit'] ) or
!empty($_POST['activate'] ) or
!empty($_POST['deactivate'] ) or
!empty($_POST['get_license_data'] ) or
!empty($_POST['get_plugin_version'] )
) {
check_admin_referer('amr_events_nonce','amr_events_nonce');
if ( isset( $_POST['submit'] ) or !empty($_POST['activate']) )
amr_events_save_licenses($licenses);
if (!empty($_POST['activate'])) {
amr_events_activate_licenses($licenses);
}
elseif (!empty($_POST['deactivate'])) {
amr_events_deactivate_license($licenses);
}
elseif (!empty($_POST['get_license_data']) and is_array($_POST['get_license_data'])) {
//amr_events_handle_license_data_request($licenses);
}
elseif (!empty($_POST['get_plugin_version'])) {
//amr_events_get_plugin_version($id);
}
}
$key=array();
foreach ($licenses as $license_short_name => $license_name) {
$key[$license_short_name] = get_option( $license_short_name.'-license-key' ); // array (plugin -> array (licensekey, status, url?)
$status [$license_short_name] = get_option( $license_short_name.'-license-status' );
$status_text[$license_short_name] = amr_events_get_status_text($status[$license_short_name]);
}
$base = get_permalink();
?>
'.AMR_EVENTS_STORE_URL.''); ?>
'.AMR_EVENTS_STORE_URL.''); ?>