Your IP : 216.73.216.171


Current Path : /home/ereika83/www/wp-content/plugins/genesis-club-pro/classes/
Upload File :
Current File : /home/ereika83/www/wp-content/plugins/genesis-club-pro/classes/class-api-admin.php

<?php
class Genesis_Club_API_Admin extends Genesis_Club_Admin {
   private $api;
	protected $tips = array('key' => array('heading' => 'Genesis Club Pro API Key', 'tip' => 'Enter 32 character key'));
		
	function init() {
	   $this->api = $this->plugin->get_module('api');
		add_action('admin_menu',array($this, 'admin_menu'));
		add_action('after_plugin_row_'.$this->path, array($this, 'plugin_row_message'));
		add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2 );
		add_filter('transient_update_plugins', array($this, 'check_update'));
		add_filter('site_transient_update_plugins', array($this, 'check_update'));
		add_filter('plugins_api', array($this, 'plugins_api'), 10, 3);		
		add_action('install_plugins_pre_plugin-information', array($this, 'plugin_version_popup'));
  	}

	function admin_menu() {
		$intro = sprintf('API Key', GENESIS_CLUB_DOMAIN);				
		$this->screen_id = add_submenu_page($this->get_parent_slug(), $intro, $intro, 'manage_options', $this->get_slug(), array($this,'page_content') );
 		add_action('load-'.$this->get_screen_id(), array($this, 'load_page')); 		
	}

	function page_content() {
 		$title =  $this->admin_heading('Genesis Club API Settings');				
		$this->print_admin_form($title, __CLASS__, $this->get_keys()); 
	} 

	function load_page() {
		if (isset($_POST['options_update']) ) $this->save_key();
		$this->fetch_message();
		$updates_panel = $this->api->check_validity() ? 'updates_panel' : 'no_updates_panel';
		$this->add_meta_box('settings', __('Settings',GENESIS_CLUB_DOMAIN), 'api_panel');
		$this->add_meta_box('news', 'Genesis Club News', 'news_panel', null, 'advanced');
		$this->set_tooltips($this->tips);
 		add_action('admin_enqueue_scripts',array($this, 'enqueue_styles'));		
  		add_action('admin_enqueue_scripts',array($this, 'enqueue_admin_styles'));		
 		add_action('admin_enqueue_scripts',array($this, 'enqueue_metabox_scripts'));	
 		add_action('admin_enqueue_scripts',array($this, 'enqueue_postbox_scripts'));		
	}

	function enqueue_styles() {
		wp_enqueue_style($this->get_code('api'), plugins_url('styles/api.css',dirname(__FILE__)), array(),$this->get_version());
 	}

 	function api_panel($post, $metabox) { 	
		print $this->tabbed_metabox( $metabox['id'], array(
        	'Genesis Club Pro API Key' => $this->key_panel(),
         	'Updates' => $this->updates_panel(),
		));
	}

	function key_panel () {
      $support = GENESIS_CLUB_SUPPORT_URL;
      $friendly = GENESIS_CLUB_FRIENDLY_NAME;
		$version = GENESIS_CLUB_VERSION;
		$url=$_SERVER['REQUEST_URI'];
		$key = $this->api->get_key();
		$is_pro = false;
		$key_status_indicator ='';
		$notice ='';
		if (! empty($key)) {
         $is_pro = $this->api->check_validity();
   		$flag = $is_pro ? 'yes' : 'no';
    		$expiry = $this->api->get_expiry(); 
    		if (!empty($expiry)) $expiry = 'License Expiry : '.$expiry;   			
    		$key_status_indicator = sprintf('<div class="dashicons dashicons-%1$s"></div>%2$s', $flag, $expiry);	
   		$notice = $is_pro ? '': sprintf('<p>%1$s</p>', $this->api->get_notice());
  		}
  		$fld = $this->fetch_form_field('key', $key, 'password', array(), array('size' => 20,  'maxlength' => 32, 'suffix' => $key_status_indicator));
  		return <<< KEY_PANEL
<p>A {$friendly} API key is required for automatic plugin updates and also if you want to get <a href="{$support}">Priority Support</a>.</p>
{$fld}
{$notice}
KEY_PANEL;
	}

	function updates_panel () {
      $friendly = GENESIS_CLUB_FRIENDLY_NAME;
		$version = GENESIS_CLUB_VERSION;
		$url=$_SERVER['REQUEST_URI'];
    	$update = array_key_exists('update',$_GET);
    	if ($update) {
        	$cache = false;
        	$this->api->update($cache); //update cache with version info
		} else {
			$cache = true;
			$url .= "&tabselect0=tab2&update=true";
		}
    	$update = $this->api->is_old_version();
    	$latest_version = $this->api->get_version();
    	$noup = (! $update && !$cache) ? '<span style="color:red;">No update available right now</span>' : '';
    	$link = sprintf('<a href="%1$s">Plugins</a>',admin_url('plugins.php?s='.$friendly));
		$updatenow = $noup ? '' : ( $update ? sprintf(__('If an update is available then click %1$s and then the <b>update now</b> link.'), $link) :
		 sprintf(__('New releases will appear automatically within 24 hours of being released.  However, if you do not want to wait then you can click to <a rel="nofollow" href="%1$s">check for an update of %2$s</a>. '), $url, $friendly) );
		return <<< UPDATES_PANEL
<p>The installed version of this plugin is {$version}. Latest available version is <a href="http://www.genesisclubpro.com/change-log/">{$latest_version}</a>. {$noup}</p>
<p>{$updatenow}</p>
UPDATES_PANEL;
	}

	function no_updates_panel ($post, $metabox) {
      $home = GENESIS_CLUB_PRO_URL;
      $friendly = GENESIS_CLUB_FRIENDLY_NAME;
		$version = GENESIS_CLUB_VERSION;
		print <<< NO_PRO_PANEL
<p>The installed version of this plugin is {$version}.</p>
<p>In order to receive plugin updates you need a valid license key.</p>
<p>To purchase a license key please visit the <a href="{$home}">{$friendly} website</a></p>
NO_PRO_PANEL;
	}

	function save_key() {
		check_admin_referer(__CLASS__);
		$old_key = $this->api->get_key(false);
		$val = $_POST['key'];
 		$updateslic = $this->api->save_key($val, $old_key!=$val, true);
 		$message = $updateslic ? __('Genesis Club License updated successfully.',GENESIS_CLUB_DOMAIN) : __('Genesis Club License has not been changed.',GENESIS_CLUB_DOMAIN);
   	$this->api->update(false); //refresh cache
		$redir = add_query_arg( array('message' => urlencode($message)), $_SERVER['REQUEST_URI'] ); //add the message 
    	wp_redirect( $redir ); 
    	exit;
	}

	function plugin_row_message($plugin){
	    if (!$this->api->check_validity()) {
	        echo '</tr><tr class="plugin-update-tr"><td colspan="5" class="plugin-update"><div class="update-message">Please enter a valid license key in Genesis Club Pro settings to enable automatic plugin updates.</div></td>';
	    }
	}

	function plugin_version_popup(){
	    if($_REQUEST["plugin"] != GENESIS_CLUB_PLUGIN_NAME) return;
	    echo $this->fetch_version_features();
	    exit;
	}

	function fetch_version_features(){
	    $features = $this->api->update(false,'features');
	    return (!empty($features)) ? $features : __('Plugin information not available at this time.') ;
	}	
	
	function check_for_updates_now() {  $this->api->update(false) ; } 

	function check_update($plugin_updates) {
		if (!is_object($plugin_updates) 
		|| ! property_exists($plugin_updates,'response')
		|| ! is_array($plugin_updates->response)) {
			return $plugin_updates;
	    }
	    $updates = $this->api->update();  //check for updates
	    if ($this->api->is_old_version())  {
         $current_version_info = array_key_exists($this->path,$plugin_updates->response) ? $plugin_updates->response[$this->path] : '';
         if(empty($current_version_info)) $current_version_info = new stdClass();
         $current_version_info->id = "0";
         $current_version_info->new_version = $this->api->get_version();	
         $current_version_info->slug = GENESIS_CLUB_PLUGIN_NAME;
         $current_version_info->url = GENESIS_CLUB_PRO_URL;
         $current_version_info->package = $this->api->get_package();
         $current_version_info->upgrade_notice = $this->api->get_notice();
         $plugin_updates->response[$this->path] =  $current_version_info ;
         } else {
         if (array_key_exists($this->path,$plugin_updates->response)) 
            unset($plugin_updates->response[$this->path]);
	    }
	    return $plugin_updates;
	}	

	public function plugins_api($result, $action, $args) {

      $updates = $this->api->update();  //check for updates

		if(isset($args->slug) && ($args->slug == GENESIS_CLUB_PLUGIN_NAME) && $action == 'plugin_information') {
			$info = new stdClass();
         $info->tested = $this->api->get_tested();
         $result = $info;
		}
		return $result;
	}
}