render_csl_blocks = true; // Display the CSL info blocks
$this->form_action = 'options.php'; // The form action for this page
$this->save_text =__('Save Changes',WPCSL__adpress__VERSION);
$this->css_prefix = '';
$this->has_packages = false;
// Passed Params
//
foreach ($params as $name => $value) {
$this->$name = $value;
}
// Only do this if we are on admin panel
//
if (isset($this->parent) && (is_admin() && $this->parent->isOurAdminPage)) {
// Only show the license section if the plugin settings
// wants a license module
if (!$this->no_license) {
$this->license_section_title = 'Plugin License';
$this->add_section(array(
'name' => $this->license_section_title,
'description' => "
",
'auto' => false,
'div_id' => 'csl_license_block'
)
);
// We don't have a main license but we have paid option
// packages
} else if ($this->has_packages) {
$this->license_section_title = 'Premium Options';
$this->add_section(array(
'name' => $this->license_section_title,
'description' => "
{$this->name} has premium options available.
" .
"
Visit url}\" target=\"_new\">{$this->url} to " .
"learn more about the available add-on packages. After you purchase " .
"an add-on package come back here to activate your add-on packages.
",
'auto' => false,
'div_id' => 'csl_license_block'
)
);
}
// Render CSL Blocks - if set false we don't need this overhead
//
if ($this->render_csl_blocks) {
$this->csl_php_modules = get_loaded_extensions();
natcasesort($this->csl_php_modules);
global $wpdb;
$this->add_section(
array(
'name' => 'Plugin Environment',
'description' =>
'
We develop desktop, mobile, and web applications for clients large and small
from all around the world. We hope our plugin brings you closer to the perfect site.
If there is anything we can do to improve our work or if you wish to hire us to customize
this plugin please call our Charleston South Carolina headquarters or
email us
and let us know.
' ;
}
/**------------------------------------
** method: add_section
**
**/
function add_section($params) {
if (!isset($this->sections[$params['name']])) {
$this->sections[$params['name']] = new wpCSL_settings_section__adpress(
array_merge(
$params,
array('plugin_url' => $this->plugin_url,
'css_prefix' => $this->css_prefix,
)
)
);
}
}
/**------------------------------------
** method: get_item
**
** Return the value of a WordPress option that was saved via the settings interface.
**/
function get_item($name, $default = null, $separator='-') {
$option_name = $this->prefix . $separator . $name;
if (!isset($this->$option_name)) {
$this->$option_name =
($default == null) ?
get_option($option_name) :
get_option($option_name,$default)
;
}
return $this->$option_name;
}
/**------------------------------------
** Class: WPCSL_Settings
**------------------------------------
** Method: add_item
**
** Parameters:
** section name
** display name, the label that shows before the input field
** name, the database key for the setting
** type (default: text, list, checkbox, textarea)
** required setting? (default: false, true)
** description (default: null) - this is what shows via the expand/collapse setting
** custom (default: null, name/value pair if list
** value (default: null), the value to use if not using get_option
** disabled (default: false), show the input but keep it disabled
**
**/
function add_item($section, $display_name, $name, $type = 'text',
$required = false, $description = null, $custom = null,
$value = null, $disabled = false
) {
$name = $this->prefix .'-'.$name;
//** Need to check the section exists first. **/
if (!isset($this->sections[$section])) {
if (isset($this->notifications)) {
$this->notifications->add_notice(
3,
sprintf(
__('Program Error: section %s not defined.',WPCSL__adpress__VERSION),
$section
)
);
}
return;
}
$this->sections[$section]->add_item(
array(
'prefix' => $this->prefix,
'css_prefix' => $this->css_prefix,
'display_name' => $display_name,
'name' => $name,
'type' => $type,
'required' => $required,
'description' => $description,
'custom' => $custom,
'value' => $value,
'disabled' => $disabled
)
);
if ($required) {
if (get_option($name) == '') {
if (isset($this->notifications)) {
$this->notifications->add_notice(
1,
"Please provide a value for $display_name",
"options-general.php?page={$this->prefix}-options#".
strtolower(strtr($display_name,' ', '_'))
);
}
}
}
}
/**
* Add a simple checkbox to the settings array.
*
* @param string $section - slug for the parent section
* @param string $label - text to appear before the setting
* @param string $fieldID - the option value field
* @param string $description - the help text under the more icon expansion
* @param string $value - the default value to use, overrides get-option(name)
* @param boolean $disabled - true if the field is disabled
*/
function add_checkbox($section,$label,$fieldID,$description=null,$value=null,$disabled=false) {
$this->add_item(
$section,
$label,
$fieldID,
'checkbox',
false,
$description,
null,
$value,
$disabled
);
}
/**
* Add a simple text input to the settings array.
*
* @param string $section - slug for the parent section
* @param string $label - text to appear before the setting
* @param string $fieldID - the option value field
* @param string $description - the help text under the more icon expansion
* @param string $value - the default value to use, overrides get-option(name)
* @param boolean $disabled - true if the field is disabled
*/
function add_input($section,$label,$fieldID,$description=null,$value=null,$disabled=false) {
$this->add_item(
$section,
$label,
$fieldID,
'text',
false,
$description,
null,
$value,
$disabled
);
}
/**------------------------------------
** Method: register
**
** This function should be used via an admin_init action
**
**/
function register() {
if (isset($this->license)) {
$this->license->initialize_options();
}
if (isset($this->cache)) {
$this->cache->initialize_options();
}
if (isset($this->sections)) {
foreach ($this->sections as $section) {
$section->register($this->prefix);
}
}
}
/**------------------------------------
** method: render_settings_page
**
** Create the HTML for the plugin settings page on the admin panel
**/
function render_settings_page() {
$this->header();
// Redner all top menus first.
//
foreach ($this->sections as $section) {
if (isset($section->is_topmenu) && ($section->is_topmenu)) {
$section->display();
}
}
// Show the plugin environment and info section on every plugin
//
if ($this->render_csl_blocks) {
$this->sections['Plugin Info']->display();
}
// Only render license section if plugin settings
// asks for it
if (isset($this->license_section_title) && (isset($this->sections[$this->license_section_title]))) {
if ($this->has_packages || !$this->no_license) {
$this->sections[$this->license_section_title]->header();
$this->show_plugin_settings();
$this->sections[$this->license_section_title]->footer();
}
}
// Draw each settings section as defined in the plugin config file
//
foreach ($this->sections as $section) {
if ($section->auto) {
$section->display();
}
}
// Show the plugin environment and info section on every plugin
//
if ($this->render_csl_blocks) {
$this->sections['Plugin Environment']->display();
}
$this->render_javascript();
$this->footer();
}
/**------------------------------------
** method: show_plugin_settings
**
** This is a function specifically for showing the licensing stuff,
** should probably be moved over to the licensing submodule
**/
function show_plugin_settings() {
$theLicenseKey = get_option($this->prefix.'-license_key');
$license_ok =( (get_option($this->prefix.'-purchased') == '1') &&
($theLicenseKey != '')
);
// If has_packages is true that means we have an unlicensed product
// so we don't want to show the license box
//
if (!$this->has_packages) {
$content = "
';
// If we are using has_packages we need to seed our content string
//
} else {
$content ='';
}
// List Packages
//
$content .= $this->ListThePackages($license_ok);
// If the main product or packages show the license box
// Then show a save button here
//
$license_ok =( (get_option($this->prefix.'-purchased') == '1') &&
(get_option($this->prefix.'-license_key') != '')
);
if (!$license_ok) {
$content .= '
' .
$this->generate_save_button_string().
'
';
}
echo $content;
}
/**
* Create the package license otuput for the admin interface.
*/
function ListThePackages($license_ok = false) {
$content = '';
if (isset($this->parent->license->packages) && ($this->parent->license->packages > 0)) {
$content .= '
';
foreach ($this->parent->license->packages as $package) {
$content .= '
';
}
return $content;
}
/**------------------------------------
** method: EnabledOrBuymeString
**
**/
function EnabledOrBuymeString($mainlicenseOK, $package) {
$content = '';
// If the main product is licensed or we want to force
// the packages list, show the checkbox or buy/validate button.
//
if ($mainlicenseOK || $this->has_packages) {
// Check if package is licensed now.
//
$package->isenabled = (
$package->force_enabled ||
$package->parent->check_license_key(
$package->sku,
true,
($this->has_packages ? $package->license_key : ''),
true // Force a server check
)
);
$installed_version = (isset($package->force_version)?
$package->force_version :
get_option($this->prefix.'-'.$package->sku.'-version')
);
$latest_version = get_option($this->prefix.'-'.$package->sku.'-latest-version');
// Upgrade is available if the current package version < the latest available
// -AND- the current package version is has been set
$upgrade_available = (
($installed_version != '') &&
( get_option($this->prefix.'-'.$package->sku.'-version-numeric') <
get_option($this->prefix.'-'.$package->sku.'-latest-version-numeric')
)
);
// Package is enabled, just show that
//
if ($package->isenabled && ($package->license_key != '')) {
$packString = $package->name . ' is enabled!';
$content .=
'
'.
'lk_option_name.'" '.
' value="'.$package->license_key.'" '.
' />';
;
// OK - the license was verified, this package is valid
// but the mainlicense was not set...
// go set it.
if (!$mainlicenseOK && ($package->license_key != '')) {
update_option($this->prefix.'-purchased',true);
update_option($this->prefix.'-license_key',$package->license_key);
}
// Package not enabled, show buy button
//
}
if (!$package->isenabled || $upgrade_available || ($package->license_key == '')) {
if ($package->isenabled && $upgrade_available) {
$content .= 'There is a new version available: ' . $latest_version . ' ';
$content .= $this->MakePayPalButton($package->paypal_upgrade_button_id, $package->help_text);
$content .= "Once you've made your purchase, the plugin will automatically re-validate with the latest version.";
} else {
$content .= $this->MakePayPalButton($package->paypal_button_id, $package->help_text);
}
// Show license entry box if we need to
//
if (
($this->has_packages && !$upgrade_available) ||
($package->license_key == '')
){
$content .= "{$package->sku} Activation Key: lk_option_name}'" .
" value='' ".
" />";
if ($package->license_key != '') {
$content .=
" ".
"The key {$package->license_key} could not be validated.".
"";
}
}
}
// Main product not licensed, tell them.
//
} else {
$content .= 'You must license the product before you can purchase add-on packages.';
}
return $content;
}
/**------------------------------------
** method: MakePayPalButton
**
**/
function MakePayPalButton($buttonID, $helptext = '') {
// Set default help text
//
if ($helptext == '') {
$helptext = 'Your license key is emailed within minutes of your purchase. '.
'If you do not receive your license check your spam '.
'folder then Contact us.';
}
// PayPal Form String
$ppFormString =
""
;
// Modal Form Helpers
//
//
//
$modalFormSetup = '
';
// Build paypal form and send it back
//
return $modalFormSetup .
''.
'
\n";
}
/**------------------------------------
**/
function footer() {
echo "
\n";
}
}
/****************************************************************************
**
** class: wpCSL_settings_item__adpress
**
** Settings Page : Items Class
** This class manages individual settings on the admin panel settings page.
**
**/
class wpCSL_settings_item__adpress {
/**------------------------------------
**/
function __construct($params) {
foreach ($params as $name => $value) {
$this->$name = $value;
}
}
/**------------------------------------
**/
function register($prefix) {
register_setting( $prefix.'-settings', $this->name );
}
/**------------------------------------
**/
function display() {
$this->header();
if (isset($this->value)) {
$showThis = $this->value;
} else {
$showThis = get_option($this->name);
}
$showThis = htmlspecialchars($showThis);
echo '
';
switch ($this->type) {
case 'textarea':
echo '';
break;
case 'text':
echo 'disabled?'disabled="disabled" ':'').
'value="'. $showThis .'" />';
break;
case "checkbox":
echo 'disabled?'disabled="disabled" ':'').
($showThis?' checked' : '').'>';
break;
case "list":
echo $this->create_option_list();
break;
case "submit_button":
echo '';
break;
default:
echo $this->custom;
break;
}
echo '
';
if ($this->description != null) {
$this->display_description_icon();
}
if ($this->required) {
echo ((get_option($this->name) == '') ?
'
'.
''.
'
This field is required.
'.
'
'
: ''
);
}
if ($this->description != null) {
$this->display_description_text($this->description);
}
$this->footer();
}
/**------------------------------------
* If $type is 'list' then $custom is a hash used to make a