Sync plugins from current page

Signed-off-by: Adrian Nöthlich <git@promasu.tech>
This commit is contained in:
2019-09-11 19:08:46 +02:00
parent 85d41e4216
commit 8515ff9587
1847 changed files with 505469 additions and 0 deletions

View File

@@ -0,0 +1,79 @@
<?php
/**
* Admin Add-ons
*
* @package
* @subpackage Admin/Add-ons
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.0
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
/**
* Add-ons Page Init
*
* Hooks check feed to the page load action.
*
* @since 1.0
* @global $amre_add_ons_page Add-ons Pages
* @return void
*/
function amre_add_ons_init() {
global $amre_add_ons_page;
add_action( 'load-' . $amre_add_ons_page, 'amre_add_ons_check_feed' );
}
add_action( 'admin_menu', 'amre_add_ons_init');
/**
* Add-ons Page
*
* Renders the add-ons page content.
*
* @since 1.0
* @return void
*/
function amre_add_ons_page() {
$url = 'http://icalevents.com/plugins_downloads/'
.'?utm_source=plugin-addons-page'
.'&amp;utm_medium=plugin'
.'&amp;utm_campaign=amr-events-plugin%20addons%20page'
.'&amp;utm_content=All%20Addons';
?>
<div class="wrap" id="amru-add-ons">
<h2>
<?php _e( 'Add Ons for amr-events', 'amr-events' ); ?>
&nbsp;&mdash;&nbsp;<a href="<?php echo $url; ?>" class="button-primary" title="<?php _e( 'Browse All Add-ons', 'amr-events' ); ?>" target="_blank"><?php _e( 'Browse All Add-ons', 'amr-events' ); ?></a>
</h2>
<?php echo amre_add_ons_get_feed(); ?>
</div>
<?php
}
/**
* Add-ons Get Feed
*
* Gets the add-ons page feed.
*
* @since 1.0
* @return void
*/
function amre_add_ons_get_feed() {
$feed_url = 'http://icalevents.com/?feed=addons';
$transient_name = 'icalevents_add_ons_feed';
if ( false === ( $cache = get_transient( $transient_name ) ) ) {
$feed = wp_remote_get($feed_url);
//var_dump($feed);
if ( ! is_wp_error( $feed ) ) {
if ( isset( $feed['body'] ) && strlen( $feed['body'] ) > 0 ) {
$cache = wp_remote_retrieve_body( $feed );
set_transient( $transient_name, $cache, 1 );
}
} else {
$cache = '<div class="error"><p>' . __( 'There was an error retrieving the add-ons list from the server. Please try again later.', 'amr-events' ) . '</p></div>';
}
}
return $cache;
}

View File

@@ -0,0 +1,157 @@
<?php
/**
* License handler - simplifies the process of adding license information
* to new extensions.
* Each addon will use this
*
* @version 1.1
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'amr_events_License' ) ) :
/**
* amr_events_License Class
*/
class amr_events_License {
private $file;
private $license;
private $item_name;
private $item_shortname;
private $version;
private $author;
private $api_url = 'http://icalevents.com';
/**
* Class constructor
*
* @global array $edd_options
* @param string $_file
* @param string $_item_name
* @param string $_version
* @param string $_author
* @param string $_optname
* @param string $_api_url
*/
function __construct( $_file, $_item_name, $_version, $_author, $_optname = null, $_api_url = null ) {
$this->file = $_file;
$this->item_name = $_item_name;
$this->item_shortname = //'amr_' .
preg_replace( '/[^a-zA-Z0-9-\s]/', '', str_replace( ' ', '-', strtolower( $this->item_name ) ) );
$this->version = $_version;
$this->license = get_option($this->item_shortname . '-license-key' ) ;
$this->status = get_option($this->item_shortname . '-license-status' ) ;
//$this->expiry = get_option $this->item_shortname . '-license-expiry' ] ) ;
$this->author = $_author;
$this->api_url = is_null( $_api_url ) ? $this->api_url : $_api_url;
// Setup hooks
$this->includes();
$this->hooks();
add_filter( 'amr_events_get_licenses', array($this, 'licenses' ) );
}
/**
* Include the updater class
*
* @access private
* @return void
*/
private function includes() {
if ( ! class_exists( 'amr_sl_plugin_updater' ) ) require_once 'plugin-updater.php';
}
/**
* Setup hooks
*
* @access private
* @return void
*/
private function hooks() {
// Register settings
//add_filter( 'amr_settings_licenses', array( $this, 'settings' ), 1 ); // adds licenses in NLR?
// Updater
add_action( 'admin_init', array( $this, 'auto_updater' ), 0 );
}
/**
* Auto updater
*
* @access private
* @global array $edd_options
* @return void
*/
public function auto_updater() {
// $valid = get_option( $this->item_shortname . '-license-status' );
// if ( 'valid' !== $valid )
// return;
// Setup the updater
$edd_updater = new amr_sl_plugin_updater(
$this->api_url,
$this->file,
array(
'version' => $this->version,
'license' => $this->license,
'item_name' => $this->item_name,
'author' => $this->author
)
);
}
/**
* Add license field to settings
*
* @access public
* @param array $settings
* @return array
*/
public function licenses( $licenses ) { // add to the list of licenses to check
$amr_events_Licenses[$this->item_shortname] = $this->item_name;
// NO ! messes up the license check.' '.$this->version;
//array(
// 'id' => $this->item_shortname . '-license-key',
// 'name' => sprintf( __( '%1$s license key', 'amr-events' ), $this->item_name ),
//'desc' => '',
//'type' => 'license_key',
//'options' => array( 'is_valid_license_option' => $this->item_shortname . '_licenseactive' ),
//'size' => 'regular'
//)
//);
return array_merge( $licenses, $amr_events_Licenses );
}
/**
* Activate the license key
*
* @access public
* @return void
*/
/**
* Deactivate the license key
*
* @access public
* @return void
*/
}
endif; // end class_exists check

View File

@@ -0,0 +1,326 @@
<?php
// uncomment this line for testing
//set_site_transient( 'update_plugins', null );
/**
* Allows plugins to use their own update API.
*
* @author Pippin Williamson
* @version 1.4
*/
class amr_sl_plugin_updater {
private $api_url = '';
private $api_data = array();
private $name = '';
private $slug = '';
private $did_check = false;
/**
* Class constructor.
*
* @uses plugin_basename()
* @uses hook()
*
* @param string $_api_url The URL pointing to the custom API endpoint.
* @param string $_plugin_file Path to the plugin file.
* @param array $_api_data Optional data to send with API calls.
* @return void
*/
function __construct( $_api_url, $_plugin_file, $_api_data = null ) {
$this->api_url = trailingslashit( $_api_url );
$this->api_data = $_api_data;
$this->name = plugin_basename( $_plugin_file );
$this->slug = basename( $_plugin_file, '.php' );
$this->version = $_api_data['version'];
// Set up hooks.
//add_action( 'admin_init', array( $this, 'init' ) );
$this->init();
add_action( 'admin_init', array( $this, 'show_changelog' ) );
}
/**
* Set up WordPress filters to hook into WP's update process.
*
* @uses add_filter()
*
* @return void
*/
public function init() {
add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) );
add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 );
add_action( 'after_plugin_row_' . $this->name, array( $this, 'show_update_notification' ), 10, 2 );
}
/**
* Check for Updates at the defined API endpoint and modify the update array.
*
* This function dives into the update API just when WordPress creates its update array,
* then adds a custom API call and injects the custom plugin data retrieved from the API.
* It is reassembled from parts of the native WordPress plugin update code.
* See wp-includes/update.php line 121 for the original wp_update_plugins() function.
*
* @uses api_request()
*
* @param array $_transient_data Update array build by WordPress.
* @return array Modified update array with custom plugin data.
*/
function check_update( $_transient_data ) {
global $pagenow;
// if ( $this->did_check ) {
// return $_transient_data;
// }
if( ! is_object( $_transient_data ) ) {
$_transient_data = new stdClass;
}
if( 'plugins.php' == $pagenow && is_multisite() ) {
return $_transient_data;
}
if ( empty( $_transient_data->response ) || empty( $_transient_data->response[ $this->name ] ) ) {
$version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) );
if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) {
$this->did_check = true;
if( version_compare( $this->version, $version_info->new_version, '<' ) ) {
$_transient_data->response[ $this->name ] = $version_info;
}
$_transient_data->last_checked = time();
$_transient_data->checked[ $this->name ] = $this->version;
}
}
return $_transient_data;
}
/**
* show update nofication row -- needed for multisite subsites, because WP won't tell you otherwise!
*
* @param string $file
* @param array $plugin
*/
public function show_update_notification( $file, $plugin ) {
if( ! current_user_can( 'update_plugins' ) ) {
return;
}
if( ! is_multisite() ) {
return;
}
if ( $this->name != $file ) {
return;
}
// Remove our filter on the site transient
remove_filter( 'pre_site_transient_update_plugins', array( $this, 'check_update' ), 10 );
$update_cache = get_site_transient( 'update_plugins' );
if ( empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) {
$version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) );
if( version_compare( $this->version, $version_info->new_version, '<' ) ) {
$update_cache->response[ $this->name ] = $version_info;
}
$update_cache->last_checked = time();
$update_cache->checked[ $this->name ] = $this->version;
set_site_transient( 'update_plugins', $update_cache );
}
// Restore our filter
add_filter( 'pre_site_transient_update_plugins', array( $this, 'check_update' ) );
if ( ! empty( $update_cache->response[ $this->name ] ) && version_compare( $this->version, $version_info->new_version, '<' ) ) {
// build a plugin list row, with update notification
$wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
echo '<tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"><div class="update-message">';
$changelog_link = self_admin_url( 'index.php?edd_sl_action=view_plugin_changelog&plugin=' . $this->name . '&slug=' . $this->slug . '&TB_iframe=true&width=772&height=911' );
if ( empty( $version_info->download_link ) ) {
printf(
__( 'There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a>.' ),
esc_html( $version_info->name ),
esc_url( $changelog_link ),
esc_html( $version_info->new_version )
);
} else {
printf(
__( 'There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a> or <a href="%4$s">update now</a>.' ),
esc_html( $version_info->name ),
esc_url( $changelog_link ),
esc_html( $version_info->new_version ),
esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name, 'upgrade-plugin_' . $this->name ) )
);
}
echo '</div></td></tr>';
}
}
/**
* Updates information on the "View version x.x details" page with custom data.
*
* @uses api_request()
*
* @param mixed $_data
* @param string $_action
* @param object $_args
* @return object $_data
*/
function plugins_api_filter( $_data, $_action = '', $_args = null ) {
if ( $_action != 'plugin_information' ) {
return $_data;
}
if ( ! isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) {
return $_data;
}
$to_send = array(
'slug' => $this->slug,
'is_ssl' => is_ssl(),
'fields' => array(
'banners' => false, // These will be supported soon hopefully
'reviews' => false
)
);
$api_response = $this->api_request( 'plugin_information', $to_send );
if ( false !== $api_response ) {
$_data = $api_response;
}
return $_data;
}
/**
* Disable SSL verification in order to prevent download update failures
*
* @param array $args
* @param string $url
* @return object $array
*/
function http_request_args( $args, $url ) {
// If it is an https request and we are performing a package download, disable ssl verification
if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) {
$args['sslverify'] = false;
}
return $args;
}
/**
* Calls the API and, if successfull, returns the object delivered by the API.
*
* @uses get_bloginfo()
* @uses wp_remote_post()
* @uses is_wp_error()
*
* @param string $_action The requested action.
* @param array $_data Parameters for the API action.
* @return false||object
*/
private function api_request( $_action, $_data ) {
global $wp_version;
$data = array_merge( $this->api_data, $_data );
if ( $data['slug'] != $this->slug ) {
return;
}
if ( empty( $data['license'] ) ) {
return;
}
if( $this->api_url == home_url() ) {
return false; // Don't allow a plugin to ping itself
}
$api_params = array(
'edd_action' => 'get_version',
'license' => $data['license'],
'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false,
'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false,
'slug' => $this->slug,
'author' => $data['author'],
'url' => home_url()
);
$request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) );
if ( ! is_wp_error( $request ) ) {
$request = json_decode( wp_remote_retrieve_body( $request ) );
}
if ( $request && isset( $request->sections ) ) {
$request->sections = maybe_unserialize( $request->sections );
} else {
$request = false;
}
return $request;
}
public function show_changelog() {
if( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) {
return;
}
if( empty( $_REQUEST['plugin'] ) ) {
return;
}
if( empty( $_REQUEST['slug'] ) ) {
return;
}
if( ! current_user_can( 'update_plugins' ) ) {
wp_die( __( 'You do not have permission to install plugin updates' ) );
}
$response = $this->api_request( 'plugin_latest_version', array( 'slug' => $_REQUEST['slug'] ) );
if( $response && isset( $response->sections['changelog'] ) ) {
echo '<div style="background:#fff;padding:10px;">' . $response->sections['changelog'] . '</div>';
}
exit;
}
}

View File

@@ -0,0 +1,464 @@
<?php
/* Description: license page to manage update check licenses.
Licenses will be added by other (add-on or related) plugins via filters and call to license object */
define ('AMR_EVENTS_STORE_URL','https://icalevents.com/plugins_downloads/');
function amr_events_get_licenses() {
$licenses = get_option( 'amr_events_Licenses' );
if ( empty( $licenses ) ) $licenses = array(); //we have no licenses saved
return apply_filters( 'amr_events_get_licenses', $licenses ); // in case new plugins where license not saved yet
}
function amr_events_change_license( $l, $new ) {
$old = get_option( $l.'-license-key' );
$done = true;
if ( isset($old) and ($old !== $new )) {
delete_option( $l.'-license-status' ); // new license has been entered, so must reactivate
$done = update_option( $l.'-license-key', $new );
if ($done) {
amr_confirm_message(sprintf(__('%s -license-key updated','amr-events'),$l));
}
else amr_flag_error ('Error updating '.$l.'-license-key');
}
return $done;
}
function amr_events_save_licenses($licenses) { // security check already done, save in DB if changed
foreach ($licenses as $l => $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 '<pre>';print_r($response['response']);
print_r($response['body']); echo '</pre>';
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 '<pre>';print_r($response['response']);
print_r($response['body']); echo '</pre>';
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) {
?><table class="form-table"><caption><?php
if (!empty($version_data->msg)) {
echo $version_data->msg;
?></caption><?php
}?>
<tbody><tr><th><?php
_e('Latest Version','amr-events' ) ;
?></th><td><?php
if (!empty($version_data->new_version)) {
?><a href=" <?php
echo $version_data->homepage; ?>" title="<?php _e('Plugin details','amr-events'); ?> ">
<?php
echo $version_data->new_version; ?>
</a><?php
if (!empty($version_data->download_link)) {
?>&nbsp;<a href=" <?php
echo $version_data->download_link; ?>"
title="<?php _e('Or wait for wordpress to pick it up in the plugin update check','amr-events'); ?> ">
<?php _e('Download','amr-events'); ?></a>
<?php
}
}
else {
_e('Version information not available for this license key and this site.','amr-events' );
_e('Verify at:','amr-events' );
?> <a href="<?php echo AMR_EVENTS_STORE_URL;?>"><?php echo AMR_EVENTS_STORE_URL;?></a>
<?php
} ?>
</td></tr></tbody></table><?php
/*
public 'new_version' => 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)) {
?><table class="widefat"><tr><?php
foreach ($license_fields as $fld => $fldtitle) {
echo '<th>'.$fldtitle.'</th>';
}
?></tr><tr><?php
foreach ($license_fields as $fld => $fldtitle) {
?><td><?php
if (!empty($license_data->$fld)) {
if (($fld == 'expires') and ($license_data->$fld == '1970-01-01 00:00:00'))
echo '';
else
echo $license_data->$fld;
}
else echo '&nbsp;';
?></td><?php
}
?></tr>
</table><?php
}
else {
echo '<p class="error"><strong>Error Fetching License Status. Try logging on to '.AMR_EVENTS_STORE_URL.'</strong></p>';
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= '<span style="color:red;">'.
__('Plugin updates not activated','amr-events')
.'</span>';
}
elseif ( $status == 'valid' ) {
$status_text = '<span style="color:green;">'.
__('Activated','amr-events')
.'</span>';
}
else {
'<span style="color:red;">'.
$status_text =__('Deactivated','amr-events')
.'</span>';
}
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();
?>
<div class="wrap">
<h2><?php _e('add on plugin updates','amr-events'); ?></h2>
<?php if (empty ($licenses)) { ?>
<p><?php _e('Either you have no add-ons active or the versions you have cannot yet check for updates.','amr-events');
?></p><p><?php
printf(__('Please check manually for updates at %s.','amr-events'),
'<a title="'.__('See plugins','amr-events').'" href="'.AMR_EVENTS_STORE_URL.'">'.AMR_EVENTS_STORE_URL.'</a>'); ?></p>
<?php }
else {?>
<p><?php printf(__('Enter your license keys to activate automatic plugin updates from %s','amr-events'),
'<a title="'.__('See plugins','amr-events').'" href="'.AMR_EVENTS_STORE_URL.'">'.AMR_EVENTS_STORE_URL.'</a>'); ?></p>
<form method="post" action="<?php echo $base; ?>">
<?php
wp_nonce_field( 'amr_events_nonce', 'amr_events_nonce' );?>
<table class="widefat">
<tbody><tr>
<th><?php _e('Plugin name','amr-events'); ?>
</th>
<th><?php _e('License key','amr-events'); ?>
</th>
</tr>
<?php
foreach ($licenses as $l => $license_name) {
?>
<tr>
<td><b style="font-size: larger; valign:bottom;"><?php echo $license_name; ?></b>
</td>
<td>
<input id="<?php echo $key[$l]; ?>" name="key[<?php echo $l; ?>]" type="text" class="regular-text" value="<?php esc_attr_e( $key[$l] ); ?>" />
</td>
</tr>
<tr>
<td valign="top">
<?php
if (!empty($_POST['get_license_data'] )) { //needs changing
if (is_array($_POST['get_license_data']) and (!empty ($_POST['get_license_data'][$l]))) {
$license_data = amr_events_get_license_data($l);
amr_events_show_license( $license_data );
}
}
elseif (!empty($_POST['get_plugin_version'] )) {
if (is_array($_POST['get_plugin_version']) and (!empty ($_POST['get_plugin_version'][$l]))) {
$version_data = amr_events_get_plugin_version($l);
amr_events_show_version( $version_data );
}
}
else echo ($status_text[$l]); ?>
</td>
<td>
<?php
if ( !empty( $key[$l] ) and ( $status[$l] !== false && $status[$l] == 'valid' )) { ?>
<input type="submit" class="button-secondary" name="deactivate[<?php echo $l; ?>]" value="<?php _e('Deactivate','amr-events'); ?>"
title="<?php _e('Deactivate this site from automatic plugin update checking.','amr-events'); ?>" />
<?php }
else { ?>
<input type="submit" class="button-primary" name="activate[<?php echo $l; ?>]" value="<?php _e('Activate','amr-events'); ?>"
title="<?php _e('Activate automatic plugin update checking with valid license key.','amr-events'); ?>" />
<?php }
?>
&nbsp;
<input type="submit" class="button-secondary" name="get_license_data[<?php echo $l; ?>]" value="<?php _e('Check License','amr-events'); ?>"
title="<?php _e('Check updates license details on plugin hosting system.','amr-events'); ?>" />
&nbsp;
<input type="submit" class="button-secondary" name="get_plugin_version[<?php echo $l; ?>]" value="<?php _e('Latest Version','amr-events'); ?>"
title="<?php _e('Check for latest plugin version after entering your updates license key','amr-events'); ?>" />
<?php
//}
?>
</td>
</tr>
<?php }
?>
</tbody>
</table>
<?php submit_button( __('Save without activating','amr-events')); ?>
</form>
<?php }
}