array(
* 'keywords' => 'keywords'
* )
*
* instead of
*
* 'driver_defaults' => array(
* 'keywords' => 'csl-mp-ebay-keywords'
* )
*
* * 'name' :: The name of the plugin.
*
* * 'prefix' :: A string used to prefix all of the Wordpress
* settings for the plugin.
*
* * 'support_url' :; The URL for the support page at WordPress
*
* * 'purchase_url' :: The URL for purchasing the plugin
*
* * 'url' :: The URL for the product page for purchases.
*
* * 'has_packages' :: defaults to false, if true that means the main product is
* not licensed but we still need the license class to manage add-ons.
*
* * 'admin_slugs' :: and array (or single string) of valid admin page slugs for this plugin.
*
*/
class wpCSL_plugin__adpress {
/**-------------------------------------
**/
function __construct($params) {
// These settings can be overridden
//
$this->no_license = false;
$this->themes_enabled = false;
$this->columns = 1;
$this->driver_type = 'Panhandler';
$this->css_prefix = '';
$this->sku = '';
$this->uses_money = true;
$this->has_packages = false;
$this->display_settings = true;
$this->display_settings_collapsed = false;
$this->show_locale = true;
$this->broadcast_url = 'http://www.charlestonsw.com/signage/index.php';
$this->shortcode_was_rendered = false;
$this->current_admin_page = '';
$this->prefix = '';
// Set current admin page
//
if ( isset($_GET['page']) ) {
$plugin_page = stripslashes($_GET['page']);
$plugin_page = plugin_basename($plugin_page);
$this->current_admin_page = $plugin_page;
}
// Do the setting override or initial settings.
//
foreach ($params as $name => $value) {
$this->$name = $value;
}
// Check to see if we are doing an update
//
if (isset($this->version)) {
if ($this->version != get_option($this->prefix."-installed_base_version")) {
if (isset($this->on_update)) {
call_user_func_array($this->on_update, array($this, get_option($this->prefix."-installed_base_version")));
}
update_option($this->prefix.'-installed_base_version', $this->version);
$destruct_time = get_option($this->prefix."-notice-countdown");
// We're doing an update, so check to see if they didn't check the check box,
// and if they didn't... well, show it to them again
if ($destruct_time) {
delete_option($this->prefix."-notice-countdown");
}
}
}
// Our Admin Page : true if we are on the admin page for this plugin
// or we are processing the update action sent from this page
//
$this->isOurAdminPage = ($this->current_admin_page == $this->prefix.'-options');
if (!$this->isOurAdminPage) {
$this->isOurAdminPage =
isset($_REQUEST['action']) &&
($_REQUEST['action'] === 'update') &&
isset($_REQUEST['option_page']) &&
(substr($_REQUEST['option_page'], 0, strlen($this->prefix)) === $this->prefix)
;
}
// This test allows for direct calling of the options page from an
// admin page call direct from the sidebar using a class/method
// operation.
//
// To use: pass an array of strings that are valid admin page slugs for
// this plugin. You can also pass a single string, we catch that too.
//
if ((!$this->isOurAdminPage) && isset($this->admin_slugs)) {
if (is_array($this->admin_slugs)) {
foreach ($this->admin_slugs as $admin_slug) {
$this->isOurAdminPage = ($this->current_admin_page === $admin_slug);
if ($this->isOurAdminPage) { break; }
}
} else {
$this->isOurAdminPage = ($this->current_admin_page === $this->admin_slugs);
}
}
// Debugging Flag
$this->debugging = (get_option($this->prefix.'-debugging') == 'on');
// What prefix do we add to the CSS elements?
if ($this->css_prefix == '') {
$this->css_prefix = $this->prefix;
}
// Store the license option here to prevent
// multiple DB lookups
$this->purchased = false;
// Determine whether or not we need to have a valid license
// this will disable all license checking/presentation
//
if (!isset($this->paypal_button_id)) { $this->paypal_button_id = ''; }
$this->no_license = ($this->paypal_button_id == '');
// Make sure we have WP_Http for http posts
// then instatiate it here in the http_handler property
// of this class.
//
if( !class_exists( 'WP_Http' ) ) {
include_once( ABSPATH . WPINC. '/class-http.php' );
}
if ( class_exists( 'WP_Http' ) ) {
$this->http_handler = new WP_Http;
} else if ($this->debugging) {
print "WordPress HTTP Handler is not available.
\n";
}
// Debugging Flag
$this->debugging = (get_option($this->prefix.'-debugging') == 'on');
$this->notifications_config = array(
'prefix' => $this->prefix,
'name' => $this->name,
'url' => 'options-general.php?page='.$this->prefix.'-options',
);
if ($this->driver_type != 'none') {
$this->products_config = array(
'prefix' => $this->prefix,
'css_prefix' => $this->css_prefix,
'columns' => $this->columns,
);
}
$this->settings_config = array(
'http_handler' => $this->http_handler,
'broadcast_url' => $this->broadcast_url,
'prefix' => $this->prefix,
'css_prefix' => $this->css_prefix,
'plugin_url' => $this->plugin_url,
'name' => $this->name,
'url' => $this->url,
'paypal_button_id' => $this->paypal_button_id,
'no_license' => $this->no_license,
'sku' => $this->sku,
'has_packages' => $this->has_packages,
'parent' => $this
);
/**
* Cache Object Config (if needed)
*/
if ($this->use_obj_defaults || ($this->cache_obj_name != 'none')) {
$this->cache_config = array(
'prefix' => $this->prefix,
'path' => $this->cache_path
);
}
/**
* Helper Object Config (if needed)
*/
if ($this->use_obj_defaults || ($this->helper_obj_name != 'none')) {
$this->helper_config = array(
'parent' => $this
);
}
/**
* License Object Config (if needed)
*/
if ($this->has_packages || !$this->no_license) {
$this->license_config = array(
'prefix' => $this->prefix,
'http_handler' => $this->http_handler,
'sku' => $this->sku,
'has_packages' => $this->has_packages,
'parent' => $this
);
}
$this->themes_config = array(
'prefix' => $this->prefix,
'plugin_path' => $this->plugin_path,
'plugin_url' => $this->plugin_url,
'support_url' => $this->support_url,
'parent' => $this
);
$this->initialize();
}
/**-------------------------------------
** method: ok_to_show
**
** returns true if...
**
** the plugin has been purchased
** the user is an admin
**
**/
function ok_to_show() {
global $current_user;
// this instantiation already knows we're licensed
if ($this->purchased) {
return true; // Short circuit, no need to set this again below
// purchase already recorded
} else if (get_option($this->prefix.'-purchased') == '1') {
$this->purchased = true;
return true;
// user is an admin
} else if (current_user_can('administrator')) {
$this->purchased = true;
return true;
// purchase not recorded - recheck it on the server
} else if ($this->no_license || $this->license->check_license_key()) {
$this->purchased = true;
return true;
}
// We are not running a licensed copy
// show the reason via debugging
if ($this->debugging) {
print "Purchased flag: " . get_option($this->prefix.'-purchased') . "
\n";
if (!isset($current_user)) {
print "Current user is not set.
\n";
} else {
print "Current User ID: " . $current_user->ID . "
\n";
if ($current_user->ID > 0) {
print "Capabilities:
\n";
print_r($current_user->wp_capabilities);
print "\n";
} else {
print "You are not logged in.'. setlocale(LC_MONETARY, 0) .'',
array(
money_format('%!i', 1234.56) => '%!i',
money_format('%!^i', 1234.56) => '%!^i',
money_format('%!=*(#10.2n', 1234.56) => '%!=*(#10.2n',
money_format('%!=*^-14#8.2i', 1234.56) => '%!=*^-14#8.2i'
)
);
}
if (isset($this->rate_url)){
$time = time();
$destruct_time =($time+(3*24*60*60));
//-use this to force the notification for 72 hours checked or not
//update_option($this->prefix."-notice-countdown", $destruct_time);
$destruct_time = get_option($this->prefix."-notice-countdown", $destruct_time);
// have we already expired a timer
if ($destruct_time === false) {
return;
}
if ($destruct_time === true) {
//if you want something special to happen to people that did not check
// the check box to turn this off, here's the place to do it...
return;
}
$hours_remaining = '';
$suffix = array('d' => 86400, 'h' => 3600, 'm' => 60,);
$remainder = abs($destruct_time - $time);
foreach($suffix as $key => $val) {
$$key = floor($remainder/$val);
$remainder -= ($$key*$val);
$hours_remaining .= ($$key==0) ? '' : $$key . "$key ";
}
$hours_remaining .= $remainder . 's ';
$this->settings->add_item(
'Display Settings',
'Turn off rate notification',
'thisbox',
'checkbox',
false,
__('This will disable the notification asking you to rate our product.',WPCSL__adpress__VERSION)
);
//if the checkbox is not checked
if($this->settings->get_item('thisbox')==false){
//and there is still time left on the timer
if ($time < $destruct_time){
//add our notice
$this->notifications->add_notice(
9,
sprintf(
__('Let us know how awesome '.$this->name.' is! Go to
the plugin page.
and rate the plugin. Turn off this message in
Display Settings.
Is something not right? Let us know.
This message will self destruct in: '.$hours_remaining.'',WPCSL__adpress__VERSION)
)
);
}
}
//checkbox was hit, so update to false
else {
update_option($this->prefix."-notice-countdown", false);
}
//is the timer up?
if ($time >= $destruct_time) {
//if the checkbox has been hit, then set to false
if ($this->settings->get_item('thisbox')==true) {
$destruct_time = false;
}
//if not then set it to true
else {
$destruct_time = true;
}
}
update_option($this->prefix."-notice-countdown", $destruct_time);
}
}
/**-------------------------------------
* method: display_objects
*
* This method generates the HTML that will be used to display
* the HTML output for this plugin.
*
* Parameters:
* $objectlist (named array) - an array of the objects to render
*
* Returns:
* A basic error message string if the render class is missing, otherwise
* the HTML that was returned from the render_objects_to_HTML method in
* the driver class.
*
**/
function display_objects($objectlist = NULL) {
$HTML_to_display = 'Could not figure out how to display the data for this shortcode.';
if ( is_callable(array($this->driver,'render_objects_to_HTML'), true)) {
$HTML_to_display = $this->driver->render_objects_to_HTML($objectlist);
}
return $HTML_to_display;
}
/**-------------------------------------
** method: render_shortcode
**
** process the shortcode for custom data drivers
** should get back an HTML string to replace the shortcode with
**
**/
function render_shortcode($atts) {
$HTML_to_display = 'Could not figure out how to display this shortcode.';
if ( is_callable(array($this->driver,'render_shortcode_as_HTML'), true)) {
$HTML_to_display = $this->driver->render_shortcode_as_HTML($atts);
}
return $HTML_to_display;
}
/**-------------------------------------
* Method: SHORTCODE_SHOW_ITEMS
*
* Shows the products in a formatted output on the page wherever the shortcode appears.
* This is the default output, custom shortcodes and functions can be put in the main
* calling function.
*
*/
function shortcode_show_items($atts, $content = NULL) {
if ( $this->ok_to_show() ) {
$this->shortcode_was_rendered = true;
$content = '';
// Debugging
//
if ($this->debugging) {
if (is_array($atts)) {
print __('DEBUG: Shortcode called with attributes:',WPCSL__adpress__VERSION) . "