final class thesis_skin_manager {
public function __construct() {
}
public $class = null;
public $name = null;
public $table = null;
public $table_suffix = 'thesis_backups'; // Suffix to identify the Thesis Backups table
public $options = array(
public function __construct($skin = array()) {
// allow in all environments except the front end
extract($skin); // $class, $name
$this->class = !empty($class) ? trim($this->verify_class_name($class)) : false;
$this->name = isset($name) ? $name : false;
$this->table = $wpdb->prefix. $this->table_suffix;
$this->defaults($thesis->skin->_skin, 'new');
// TODO: The Exporter could probably be run through ajax like everything else...
add_action('admin_post_export_skin', array($this, 'export'));
add_action('wp_ajax_backup_skin', array($this, 'backup'));
add_action('wp_ajax_update_backup_skin_table', array($this, 'update_backup'));
add_action('wp_ajax_restore_skin_backup', array($this, 'restore_backup'));
add_action('wp_ajax_delete_skin_backup', array($this, 'delete_backup'));
add_action('wp_ajax_restore_skin_default', array($this, 'restore_default'));
}
}
/*---:[ Skin Manager interface ]:---*/
public function editor() {
return
"$tab
\n";
}
/*---:[ Skin Manager core database actions ]:---*/
public function add($notes = false, $skin = false) {
wp_cache_flush(); // make sure we have the latest by flushing the cache first
foreach ($this->options as $option)
$data[$option] = get_option("{$skin}_{$option}"); // fetch options
return true; // there are no options, so we don't need to save anything.
$data['notes'] = $notes;
$data['time'] = current_time('timestamp'); // add timestamp
$data['class'] = $skin; // add Skin class
return (bool) $wpdb->insert($this->table, $data); // return true on success, false on failure
}
public function delete($id = false) {
return false;
return (bool) $wpdb->delete($this->table, $where);
}
public function get() {
return false;
foreach ($results as $result)
$valid[absint(maybe_unserialize($result['ID']))] = array(
krsort($valid);
return empty($valid) ? array() : $valid;
}
public function get_entry($id = false) {
return false;
return !empty($result['class']) && $result['class'] === $this->class ? $result : false;
}
/*---:[ ajax data handling methods ]:---*/
public function backup() {
$thesis->wp->check();
$thesis->wp->nonce($_POST['nonce'], 'thesis-skin-manager');
echo $thesis->api->alert($this->add(stripslashes($_POST['note'])) === false ?
__('Backup failed.', 'thesis') :
__('Backup complete!', 'thesis'), 'manager_saved', true);
}
/*
— Called when the backup table is updated with a new entry
— Echoes a new backup_table() based on the most recent (updated) data
*/
public function update_backup() {
$thesis->wp->check();
$thesis->wp->nonce($_POST['nonce'], 'thesis-skin-manager');
echo $this->backup_table();
}
/*
— Wholesale replaces all Skin options
— Any options present in the requested backup state will be restored
— Any options not present will be deleted (and will revert to defaults, if applicable)
*/
public function restore_backup() {
$thesis->wp->check();
$thesis->wp->nonce($_POST['nonce'], 'thesis-skin-manager');
// Remove data that is not needed for the restoration
unset($result['ID'], $result['time'], $result['class'], $result['notes']);
$this->automatic_backup(__('Restore Skin data', 'thesis'));
foreach (array_filter($result) as $key => $check)
$verified[$key] = $value;
foreach ($this->options as $option) {
update_option("{$this->class}_$option", $verified[$option]);
else
delete_option("{$this->class}_$option");
}
wp_cache_flush();
$thesis->skin->_write_css();
}
}
public function delete_backup() {
$thesis->wp->check();
$thesis->wp->nonce($_POST['nonce'], 'thesis-skin-manager');
echo $thesis->api->alert($this->delete((int) $_POST['id']) === false ?
__('Deletion failed.', 'thesis') :
__('Backup deleted!', 'thesis'), 'manager_saved', true);
}
/*
Export selected Skin data items
— Generates a serialized Thesis Skin import file (.txt) with selected options (even if they are empty)
*/
public function export() {
$thesis->wp->check();
$thesis->wp->nonce($_POST['_wpnonce-thesis-skin-export'], 'thesis-skin-export');
$this->error(__('The export data was incomplete. Please revisit the Skin Data Manager and try again.', 'thesis'));
elseif (($options = array_filter($_POST['export'])) && (empty($options) || empty($options['id'])))
$this->error(__('No backup state was specified for export. Revisit the Skin Data Manager and try again.', 'thesis'));
unset($options['id']);
$this->error(__('The requested export data does not match the current Skin. Please revisit the Skin Data Manager and try again.', 'thesis'));
unset($data['ID']);
unset($data['notes']);
unset($data['time']);
foreach (array_intersect(array_keys($options), $this->options) as $option)
$new[$option] = maybe_unserialize($data[$option]);
$new['class'] = $data['class'];
$this->error(__('Export data serialization failed. Please revisit the Skin Data Manager and try again', 'thesis'));
$this->error(__('Export data serialization (with hashing) failed. Please revisit the Skin Data Manager and try again.', 'thesis'));
header('Content-Type: text/plain; charset='. get_option('blog_charset'));
header('Content-Disposition: attachment; filename="'. str_replace('_', '-', $this->class). '-'. @date('Y\-m\-d\-H\-i'). '.txt"');
printf('%s', $out);
exit;
}
/*
Import a Thesis Skin data file
— Any included (and valid) options will be overwritten, even if empty.
*/
public function import($file, $action) {
$thesis->wp->check();
check_admin_referer($action, 'thesis_form_nonce');
return __('The import file is not present!', 'thesis');
elseif ($_FILES[$file]['error'] > 0)
return __('The server encountered an error with the import file. No data will be imported.', 'thesis');
elseif (!is_array($data = $this->verify_skin_data_file($_FILES[$file], $this->class)))
return empty($data) || !is_string($data) ?
__('The import file does not contain valid Thesis Skin data.', 'thesis') :
$data;
unset($data['class']);
return __('The import file does not contain any Skin data.', 'thesis');
$this->automatic_backup(__('Import Skin data', 'thesis'));
foreach ($data as $option => $value)
update_option("{$this->class}_$option", $value);
else
delete_option("{$this->class}_$option");
wp_cache_flush();
$thesis->skin->_write_css();
return true;
}
public function restore_default() {
$thesis->wp->check();
$thesis->wp->nonce($_POST['nonce'], 'thesis-skin-manager');
parse_str(stripslashes($_POST['form']), $form);
echo $response = $this->defaults(
$thesis->skin->_skin, // Skin
!empty($form['restore']) ? $form['restore'] : array(), // options
!empty($_POST['backup']) && $_POST['backup'] == 'true' ? __('Restore defaults', 'thesis') : false) === true ?
$thesis->api->alert($thesis->api->efn($response), 'default_not_saved', true);
}
/*---:[ Manager action helper methods ]:---*/
public function defaults($skin = array(), $restore = array(), $backup = false) {
return __('No Skin was selected for restoration', 'thesis');
array_filter(array_map('intval', $restore)) : ($restore == 'new' ?
array_combine($this->options, array_fill(0, count($this->options), 1)) :
array());
return __('No data was selected for restoration!', 'thesis');
THESIS_USER_SKINS. "/{$skin['folder']}" : false;
include_once($dir. '/default.php');
return __('The default Skin data is not in valid array format!', 'thesis');
$this->automatic_backup($backup, $skin['class']);
unset($restore['css_custom']);
delete_option("{$skin['class']}_css_custom");
}
foreach (array_keys($restore) as $option)
update_option("{$skin['class']}_$option", $default_data[$option]);
else
delete_option("{$skin['class']}_$option");
wp_cache_flush();
}
else
return __('This Skin does not have a valid default.php file.', 'thesis');
}
else
return __('This Skin does not have a default.php file!', 'thesis');
$thesis->skin->_write_css();
return true;
}
public function automatic_backup($state = false, $skin = false) {
$this->add('['. __('Automatic backup', 'thesis'). (!empty($state) ? ': '. $state : ''). ']', !empty($skin) ? $skin : false);
}
public function error($error) {
echo
__('Return to the Thesis Skin Editor', 'thesis'),
exit;
}
/*---:[ Skin Manager database table ]:---*/
private function table() {
return $return && true;
else { // make the table
ID bigint(20) unsigned NOT NULL auto_increment,
time bigint(20) NOT NULL,
class varchar(200) NOT NULL,
boxes longtext NOT NULL,
templates longtext NOT NULL,
packages longtext NOT NULL,
vars longtext NOT NULL,
css longtext NOT NULL,
css_editor longtext NOT NULL,
css_custom longtext NOT NULL,
notes longtext NOT NULL,
_design longtext NOT NULL,
_display longtext NOT NULL,
PRIMARY KEY (ID)
) COLLATE utf8_general_ci;"; // force utf8 collation to avoid latin1: destroyer of worlds
return (bool) $query && $return;
}
}
/*---:[ data verification ]:---*/
public function verify_class_name($class) {
return preg_match('/\A[a-zA-Z_]\w*\Z/', $class) ? $class : false;
}
public function verify_skin_data_file($file, $class) {
return __('The import file does not exist. Please try again.', 'thesis');
elseif (empty($class))
return __('A valid Skin class name was not specified. No data was imported.', 'thesis');
elseif (empty($name))
return __('The file name is inadequate. No data will be imported.', 'thesis');
elseif (!preg_match('/^[a-z0-9-]+\.txt$/', strtolower($name)))
return __('The import file name did not pass a basic legitimacy test. No data was imported.', 'thesis');
elseif (!($serialized = file_get_contents($location)))
return __('Thesis could not read the specified import file.', 'thesis');
elseif (!is_serialized($serialized))
return __('The import file is not properly serialized. No data will be imported.', 'thesis');
elseif (!($contents = unserialize($serialized)))
return __('The import file could not be unserialized. No data will be imported.', 'thesis');
elseif (empty($contents['checksum']))
return __('The import file does not have a proper checksum value and cannot be trusted.', 'thesis');
elseif (empty($contents['data']))
return __('The import file does not contain any data.', 'thesis');
elseif (!is_array($contents['data']))
return __('The import file data is not formatted properly (it should be an array).', 'thesis');
elseif ($contents['checksum'] !== md5(serialize($contents['data'])))
return __('The import file checksum does not match the file data. No data will be imported.', 'thesis');
elseif (empty($contents['data']['class']))
return __('The import file does not specify the Skin class to which it applies. No data will be imported.', 'thesis');
elseif ($contents['data']['class'] !== $class)
return __('The import file does not apply to this Skin.', 'thesis');
return !empty($contents['data']) ?
$contents['data'] :
__('The import file only included empty data, so nothing was imported.', 'thesis');
}
}
define('THESIS_SKIN', THESIS_CORE. '/skin');
require_once(THESIS_SKIN. '/user_boxes.php');
class thesis_skin {
public function __construct() {
}
public function __construct() {
}
public $_boxes = null;
public $_class = null;
public $_css = null;
public $_design = null;
public $_display = null;
public $_docs = null;
public $_images = null;
public $_instances = null;
public $_license_key = null;
public $_manager = null;
public $_name = null;
public $_skin = null;
public $_template = null;
public $_templates = null;
public $_user_packages = null;
public $color = null;
public $css_tools = null;
public $design = null;
public $display = null;
public $fonts = null;
public $functionality = null;
public $grt = null;
public $header_image = null;
public $logo = null;
public $page_404 = null;
public $typography = null;
public $license_key = false; // (string) product ID to use for license key-protected automatic updates
// Skin-defined properties
protected $filters = array(); // (array) Skin-defined functionality overrides (replaced by $functionality)
}
protected function construct() {}
public function _api() {
// Base design tools
require_once(THESIS_SKIN_API. '/color.php');
require_once(THESIS_SKIN_API. '/css_tools.php');
require_once(THESIS_SKIN_API. '/fonts.php');
require_once(THESIS_SKIN_API. '/grt.php');
require_once(THESIS_SKIN_API. '/mce.php');
require_once(THESIS_SKIN_API. '/typography.php'); // deprecated
$this->color = new thesis_skin_color;
$this->css_tools = new thesis_skin_css_tools;
$this->fonts = new thesis_skin_fonts;
$this->grt = new thesis_grt;
$this->typography = new thesis_skin_typography; // deprecated
new thesis_mce;
// Add-on functionality
if (!empty($this->functionality['fonts_google']) && $this->functionality['fonts_google'] === true) {
require_once(THESIS_SKIN_API. '/fonts_google.php');
new thesis_skin_fonts_google(get_option("{$this->_class}__design"));
}
if (!empty($this->functionality['header_image']) && $this->functionality['header_image'] === true) {
require_once(THESIS_SKIN_API. '/header_image.php');
$this->header_image = new thesis_skin_header_image;
}
if (!empty($this->functionality['logo']) && $this->functionality['logo'] === true) {
require_once(THESIS_SKIN_API. '/logo.php');
$this->logo = new thesis_skin_logo;
}
}
public function _manager() {
$this->_manager = new thesis_skin_manager($this->_skin);
}
public function _css() {
require_once(THESIS_SKIN. '/css.php');
$css = array();
$css['css'] = ($css_skin = get_option("{$this->_class}_css")) ? $css_skin : '';
$css['css_editor'] = ($css_editor = get_option("{$this->_class}_css_editor")) ? $css_editor : '';
$css['css_custom'] = ($css_custom = get_option("{$this->_class}_css_custom")) ? $css_custom : '';
$css['vars'] = is_array($vars = get_option("{$this->_class}_vars")) ? $vars : array();
$css['preprocessor'] = !empty($this->functionality['css_preprocessor']) ? $this->functionality['css_preprocessor'] : false;
$css['packages'] = is_array($packages = get_option("{$this->_class}_packages")) ? $packages : array();
$css['user_packages'] = is_array($this->_user_packages->active) ? $this->_user_packages->active : array();
if (method_exists($this, 'packages')) {
add_action('thesis_include_packages', array($this, '_include_packages'));
add_filter('thesis_packages', array($this, '_add_packages'));
}
$this->_design_options();
$this->_css = new thesis_css($css);
}
public function _design_options() {
global $thesis;
$this->design = $thesis->api->get_options($this->_design(), is_array($this->_design = get_option("{$this->_class}__design")) ? $this->_design : array());
}
public function _init_wp() {
global $thesis;
if (!empty($_GET['t_quicklaunch_editor'])) {
wp_redirect(set_url_scheme(home_url('?thesis_editor=1')));
exit;
}
if (!empty($_GET['t_skin_docs']) && !empty($this->_docs))
wp_redirect(esc_url($this->_docs));
require_once(THESIS_SKIN. '/images.php');
$this->_images = new thesis_images;
new thesis_upload(array(
'title' => sprintf(__('Import %s Data', 'thesis'), $thesis->skins->skin['name']),
'prefix' => 'import_skin',
'file_type' => 'txt'));
if (is_array($instances = apply_filters('thesis_skin_instances', array())) && !empty($instances))
$this->_instances = $instances;
add_filter('thesis_quicklaunch_menu', array($this, '_quicklaunch'));
add_action('admin_post_thesis_head', array($this, '_save_head'));
if (method_exists($this, 'display'))
add_action("admin_post_{$this->_class}__display", array($this, '_save_display'));
if (method_exists($this, 'design'))
add_action("admin_post_{$this->_class}__design", array($this, '_save_design'));
if (!empty($this->license_key))
add_action('admin_post_skin_license', array($this, '_save_license_key'));
if (!empty($this->functionality['formatting_class']) || !empty($this->functionality['editor_grt']))
add_filter('tiny_mce_before_init', array($this, '_mce'));
add_action('thesis_after_update_skin', array($this, '_update'));
// Deprecated header image functionality
if (method_exists($this, 'header_image') && empty($this->functionality['header_image']))
add_action("admin_post_{$this->_class}__header_image", array($this, '_save_header_image'));
}
public function _init_admin() {
add_filter('thesis_skin_menu', array($this, '_add_menu'));
add_action('thesis_skin_menu', array($this, '_append_menu_links'), 99);
add_action('thesis_admin_home', array($this, '_admin_home'));
if (!empty($this->_instances) || method_exists($this, 'display'))
$this->_menu["{$this->_class}__content"] = array(
'text' => __('Content & Display', 'thesis'),
'url' => admin_url("admin.php?page=thesis&canvas={$this->_class}__content"),
'description' => __('Manage what displays in your Skin and edit selected Skin content', 'thesis'));
if (!empty($_GET['canvas'])) {
if ($_GET['canvas'] == "{$this->_class}__content") {
add_action('admin_init', array($this, '_init_content_admin'));
add_action('thesis_admin_canvas', array($this, '_content_admin'));
}
elseif ($_GET['canvas'] == 'head') {
add_action('admin_init', array($this, '_admin_init_head_editor'));
add_action('thesis_admin_canvas', array($this, '_head_editor'));
}
}
if (method_exists($this, 'design') || method_exists($this, 'design_admin') || !empty($this->functionality['design_admin'])) {
$this->_menu["{$this->_class}__design"] = array(
'text' => __('Design', 'thesis'),
'url' => !empty($this->functionality['design_url']) ?
esc_url($this->functionality['design_url']) :
admin_url("admin.php?page=thesis&canvas={$this->_class}__design"),
'description' => __('Change certain aspects of your Skin’s design, like fonts and colors', 'thesis'));
if (empty($this->functionality['design_url'])) {
if (!empty($_GET['canvas']) && $_GET['canvas'] == "{$this->_class}__design") {
add_action('thesis_admin_canvas', array($this, !empty($this->functionality['design_admin']) && method_exists($this, $this->functionality['design_admin']) ?
$this->functionality['design_admin'] : (method_exists($this, 'design_admin') ?
'design_admin' :
'_design_admin')));
add_action('admin_init', array($this, '_init_design_admin'));
}
}
}
if (!empty($this->license_key) && !empty($_GET['canvas']) && $_GET['canvas'] == 'skin_license') {
add_action('thesis_admin_canvas', array($this, '_license_key_admin'));
add_action('admin_init', array($this, '_init_license_key_admin'));
}
// Deprecated header image functionality
if (method_exists($this, 'header_image') && empty($this->functionality['header_image'])) {
$this->_menu["{$this->_class}__header_image"] = array(
'text' => __('Header Image', 'thesis'),
'url' => admin_url("admin.php?page=thesis&canvas={$this->_class}__header_image"));
if (!empty($_GET['canvas']) && $_GET['canvas'] == "{$this->_class}__header_image") {
add_action('admin_init', array($this, '_init_header_image'));
add_action('thesis_admin_canvas', array($this, '_header_image'));
}
}
}
public function _admin_home() {
global $thesis;
$items = '';
foreach (apply_filters('thesis_skin_menu', array()) as $item)
if ($item['url'] !== '#')
$items .= "\t\t\t\t
". sprintf(__('Note: You are previewing this Skin in Development Mode. To change this, visit the Manage Skins page.', 'thesis'), admin_url('admin.php?page=thesis&canvas=select_skin')). "
\n" : ''),
"\t\t\t
\n",
$items,
"\t\t\t
\n";
}
public function _add_menu($menu) {
return is_array($this->_menu) ? (is_array($menu) ? array_merge($menu, $this->_menu) : $this->_menu) : $menu;
}
public function _add_boxes($boxes) {
if (file_exists(THESIS_USER_SKIN. '/box.php'))
include_once(THESIS_USER_SKIN. '/box.php');
return is_array($add_boxes = $this->boxes()) ? (is_array($boxes) ? array_merge($boxes, $add_boxes) : $add_boxes) : $boxes;
}
public function _include_packages() {
if (file_exists(THESIS_USER_SKIN. '/package.php'))
include_once(THESIS_USER_SKIN. '/package.php');
}
public function _add_packages($packages) {
return is_array($add_packages = $this->packages()) ? (is_array($packages) ? array_merge($packages, $add_packages) : $add_packages) : $packages;
}
public function _add_fonts($fonts) {
return is_array($add_fonts = $this->fonts()) ? (is_array($fonts) ? array_merge($fonts, $add_fonts) : $add_fonts) : $fonts;
}
public function _init_license_key_admin() {
wp_enqueue_style('thesis-options');
wp_enqueue_script('thesis-options');
}
public function _license_key_admin() {
global $thesis;
$this->_license_key = trim(get_option("{$this->_class}_license_key", false));
$status = get_option("{$this->_class}_license_key_status", false);
$message = get_transient("{$this->_class}_license_message", false);
if (empty($message) && !empty($this->_license_key)) {
set_transient("{$this->_class}_license_message", $thesis->api->check_license(
$this->_license_key,
$this->license_key,
!empty($this->license_key_name) ? $this->license_key_name : $this->_name,
$this->_class,
'admin.php?page=thesis&canvas=skin_license'), 60*60*24);
$message = get_transient("{$this->_class}_license_message");
}
$license = $thesis->api->form->fields(array(
'license_key' => array(
'type' => 'text',
'width' => 'long',
'code' => true,
'label' => sprintf(__('Enter Your %s License Key', 'thesis'), $this->_name),
'tooltip' => sprintf(__('Check out the Skin License Key documentation for everything you need to know about license keys.', 'thesis'), esc_url('https://diythemes.com/thesis/rtfm/how-to/skin-license-key/')))), !empty($this->_license_key) ? array('license_key' => $this->_license_key) : array(), 'skin_license_', false, 3, 3);
echo
"\t\t
". sprintf(__('Please enter a %s license key!', 'thesis'), $this->_name). "
\n".
"$tab\t
". sprintf(__('You’ll need to enter a valid %2$s license key to receive automatic updates.', 'thesis'), admin_url('admin.php?page=thesis&canvas=skin_license'), $this->_name). "
\n".
"$tab
\n";
}
public function _admin_init_head_editor() {
global $thesis;
wp_enqueue_style('thesis-options'); #wp
wp_enqueue_style('thesis-box-form'); #wp
wp_enqueue_script('jquery-ui-droppable'); #wp
wp_enqueue_script('jquery-ui-sortable'); #wp
wp_enqueue_script('thesis-options');
wp_enqueue_script('thesis-ui', THESIS_JS_URL. '/ui.js', array('thesis-menu', 'thesis-options'), $thesis->version, true); #wp
add_action('admin_head', array($this, '_admin_head_js'));
}
public function _admin_head_js() {
echo
"\n";
}
public function _head_editor() {
echo $this->_templates->head($this->_boxes->get_box_form_data($this->_templates->head, true));
}
/*---:[ ajax interface actions ]:---*/
public function _init_ajax() {
add_action('wp_ajax_add_box', array($this, '_add_box'));
add_action('wp_ajax_save_box', array($this, '_save_box'));
add_action('wp_ajax_save_template', array($this, '_save_template'));
add_action('wp_ajax_change_template', array($this, '_change_template'));
add_action('wp_ajax_create_template', array($this, '_create_template'));
add_action('wp_ajax_delete_template', array($this, '_delete_template'));
add_action('wp_ajax_copy_template', array($this, '_copy_template'));
add_action('wp_ajax_save_css', array($this, '_save_css'));
add_action('wp_ajax_save_css_package', array($this, '_save_css_package'));
add_action('wp_ajax_delete_css_package', array($this, '_delete_css_package'));
add_action('wp_ajax_save_css_variable', array($this, '_save_css_variable'));
add_action('wp_ajax_delete_css_variable', array($this, '_delete_css_variable'));
add_action('wp_ajax_color_complement', array($this, '_color_complement'));
if (method_exists($this, 'admin_ajax'))
$this->admin_ajax();
}
public function _change_template() {
global $thesis;
$thesis->wp->nonce($_POST['nonce'], 'thesis-save-template');
echo $this->_templates->editor($this->_template_form());
if ($thesis->environment == 'ajax') die();
}
public function _create_template() {
global $thesis;
$thesis->wp->check();
$thesis->wp->nonce($_POST['nonce'], 'thesis-save-template');
if (!is_array($save = $this->_templates->create($_POST['title'])) || empty($save['id']) || empty($save['templates'])) return;
update_option("{$this->_class}_templates", $save['templates']);
wp_cache_flush();
echo $save['id'];
if ($thesis->environment == 'ajax') die();
}
public function _delete_template() {
global $thesis;
$thesis->wp->check();
$thesis->wp->nonce($_POST['nonce'], 'thesis-save-template');
if (!is_array($templates = $this->_templates->delete($_POST['template'])))
echo $thesis->api->alert(__('Template not deleted.', 'thesis'), 'template_deleted', true);
else {
if (empty($templates))
delete_option("{$this->_class}_templates");
else
update_option("{$this->_class}_templates", $templates);
wp_cache_flush();
echo $thesis->api->alert(__('Template deleted!', 'thesis'), 'template_deleted', true);
}
if ($thesis->environment == 'ajax') die();
}
public function _copy_template() {
global $thesis;
$thesis->wp->check();
$thesis->wp->nonce($_POST['nonce'], 'thesis-save-template');
if (!is_array($templates = $this->_templates->copy($_POST['to'], $_POST['from'])))
echo $thesis->api->alert(__('Template not copied.', 'thesis'), 'template_copied', true);
else {
update_option("{$this->_class}_templates", $templates); #wp
wp_cache_flush();
echo $thesis->api->alert(__('Template copied!', 'thesis'), 'template_copied', true);
}
if ($thesis->environment == 'ajax') die();
}
public function _save_template() {
global $thesis;
$thesis->wp->check();
parse_str(stripslashes($_POST['form']), $form);
$thesis->wp->nonce($form['_wpnonce-thesis-ajax'], 'thesis-save-template');
if (!is_array($save = $this->_templates->save($form)))
echo $thesis->api->alert(__('Template not saved.', 'thesis'), 'template_saved', true);
else {
if (is_array($save['templates']) && empty($save['templates']))
delete_option("{$this->_class}_templates");
elseif (is_array($save['templates']))
update_option("{$this->_class}_templates", $save['templates']); #wp
$this->_boxes->delete($save['delete_boxes']);
$boxes = $this->_boxes->save($form);
if (is_array($boxes) && empty($boxes))
delete_option("{$this->_class}_boxes");
elseif (is_array($boxes))
update_option("{$this->_class}_boxes", $boxes);
wp_cache_flush();
echo $thesis->api->alert(__('Template saved!', 'thesis'), 'template_saved', true);
}
if ($thesis->environment == 'ajax') die();
}
public function _save_box() {
global $thesis;
$thesis->wp->check();
parse_str(stripslashes($_POST['form']), $form);
if ($thesis->wp->nonce($form['_wpnonce-thesis-save-box'], 'thesis-save-box', true)) {
$boxes = $this->_boxes->save($form);
if (is_array($boxes) && empty($boxes))
delete_option("{$this->_class}_boxes");
elseif (is_array($boxes))
update_option("{$this->_class}_boxes", $boxes);
wp_cache_flush();
echo $thesis->api->alert(__('Options saved!', 'thesis'), 'options_saved', true);
}
else
echo $thesis->api->alert(__('Options not saved.', 'thesis'), 'options_saved', true);
if ($thesis->environment == 'ajax') die();
}
public function _save_head() {
global $thesis;
$thesis->wp->check();
$thesis->wp->nonce($_POST['_wpnonce-thesis-save-head'], 'thesis-save-head');
$saved = 'no';
if ($head = $this->_templates->save_head($_POST)) {
if (is_array($head))
$this->_boxes->delete($head);
$this->_boxes->save(stripslashes_deep($_POST), true);
$saved = 'yes';
}
wp_redirect("admin.php?page=thesis&canvas=head&saved=$saved");
exit;
}
public function _add_box() {
global $thesis;
$thesis->wp->nonce($_POST['nonce'], 'thesis-add-box');
if (is_array($boxes = $this->_boxes->add($_POST['id']))) {
update_option("{$this->_class}_boxes", $boxes);
wp_cache_flush();
}
if ($thesis->environment == 'ajax') die();
}
public function _write_css() {
if (!isset($this->_css)) return;
$this->_css->reset_vars(get_option("{$this->_class}_vars"));
$this->_design_options();
if (method_exists($this, 'css_variables') && is_array($map = $this->css_variables()) && is_array($vars = $this->_css->update_vars($map)))
update_option("{$this->_class}_vars", $vars);
$this->_css->write();
}
public function _save_css() {
global $thesis;
$thesis->wp->check();
$thesis->wp->nonce($_POST['nonce'], 'thesis-save-css');
if (isset($_POST['editors']) && is_array($_POST['editors']))
foreach ($_POST['editors'] as $editor => $css)
update_option("{$this->_class}_$editor", trim(stripslashes($css)));
elseif (isset($_POST['custom']))
update_option("{$this->_class}_css_custom", trim(stripslashes($_POST['custom'])));
wp_cache_flush();
$this->_write_css();
echo $thesis->api->alert(__('CSS saved!', 'thesis'), 'css_saved', true);
if ($thesis->environment == 'ajax') die();
}
public function _save_css_variable() {
global $thesis;
$thesis->wp->check();
$thesis->wp->nonce($_POST['nonce'], 'thesis-save-css-variable');
if (is_array($save = $this->_css->save_variable(stripslashes_deep($_POST['item'])))) {
update_option("{$this->_class}_vars", $save);
wp_cache_flush();
echo $thesis->api->alert(__('Variable saved!', 'thesis'), 'var_saved', true);
}
else
echo $thesis->api->alert(__('Variable not saved.', 'thesis'), 'var_saved', true);
if ($thesis->environment == 'ajax') die();
}
public function _delete_css_variable() {
global $thesis;
$thesis->wp->check();
$thesis->wp->nonce($_POST['nonce'], 'thesis-save-css-variable');
if (is_array($save = $this->_css->delete_variable($_POST['item']))) {
if (empty($save))
delete_option("{$this->_class}_vars");
else
update_option("{$this->_class}_vars", $save);
wp_cache_flush();
echo $thesis->api->alert(__('Variable deleted!', 'thesis'), 'var_deleted', true);
}
else
echo $thesis->api->alert(__('Variable not deleted.', 'thesis'), 'var_deleted', true);
if ($thesis->environment == 'ajax') die();
}
public function _save_css_package() {
global $thesis;
$thesis->wp->check();
parse_str(stripslashes($_POST['pkg']), $pkg);
$thesis->wp->nonce($pkg['_wpnonce-thesis-save-package'], 'thesis-save-package');
if (is_array($packages = $this->_css->save_package($pkg))) {
update_option("{$this->_class}_packages", $packages);
echo $thesis->api->alert(__('Package saved!', 'thesis'), 'package_saved', true);
wp_cache_flush();
}
else
echo $thesis->api->alert(__('Package not saved.', 'thesis'), 'package_saved', true);
if ($thesis->environment == 'ajax') die();
}
public function _delete_css_package() {
global $thesis;
$thesis->wp->check();
parse_str(stripslashes($_POST['pkg']), $pkg);
$thesis->wp->nonce($pkg['_wpnonce-thesis-save-package'], 'thesis-save-package');
if (is_array($packages = $this->_css->delete_package($pkg))) {
if (empty($packages))
delete_option("{$this->_class}_packages");
else
update_option("{$this->_class}_packages", $packages);
wp_cache_flush();
echo $thesis->api->alert(__('Package deleted!', 'thesis'), 'package_deleted', true);
}
else
echo $thesis->api->alert(__('Package not deleted.', 'thesis'), 'package_deleted', true);
if ($thesis->environment == 'ajax') die();
}
public function _color_complement() {
global $thesis;
$thesis->wp->check();
echo ($complement = $thesis->api->colors->complement($_POST['color'])) ? $complement : "N/A";
if ($thesis->environment == 'ajax') die();
}
/*---:[ Front-end Skin output ]:---*/
public function _skin() {
global $thesis;
if ($thesis->environment == 'editor') {
$this->_editor();
exit();
}
else
return $this->_template();
}
public function _query($query) {
global $thesis, $wp_version;
if (!$query->is_main_query()) return $query;
$page = $custom = false;
if ($query->is_page && ($page = !empty($query->queried_object_id) ? $query->queried_object_id : (!empty($query->query_vars['page_id']) ? $query->query_vars['page_id'] : false)) && !empty($page)) {
$redirect = ($redirect = get_post_meta($page, '_thesis_redirect', true)) ? $redirect : false; #wp
if (is_array($redirect) && !empty($redirect['url'])) {
wp_redirect($redirect['url'], 301); #wp
exit;
}
$custom = is_array($post_meta = get_post_meta($page, "_{$this->_class}", true)) ? (!empty($post_meta['template']) ? $post_meta['template'] : false) : false;
}
elseif ($query->is_category || $query->is_tax || $query->is_tag) {
$query->get_queried_object();
if (is_object($query->queried_object)) {
if ($query->is_tag && version_compare($wp_version, '3.8.2', '<') && version_compare($wp_version, '3.8', '>=')) {
$query->queried_object = get_term_by('slug', $query->query_vars['tag'], 'post_tag');
$query->queried_object_id = $query->queried_object->term_id;
}
if (!empty($thesis->wp->terms[$query->queried_object->term_id][$this->_class]['template']) && ($template = $thesis->wp->terms[$query->queried_object->term_id][$this->_class]['template']))
$custom = !empty($template) ? $template : false;
do_action('thesis_init_term', $query->queried_object->term_id);
}
}
do_action('thesis_init_template', $this->_template = $this->_templates->get_template($custom));
return apply_filters('thesis_query', $query);
}
private function _template() {
global $thesis, $wp_query;
if (empty($this->_boxes->active) || !is_array($this->_boxes->active)) {
echo __('Uh oh, no template data is present!', 'thesis');
return;
}
$custom = false;
if ($wp_query->is_single) {
$redirect = ($redirect = get_post_meta($wp_query->post->ID, '_thesis_redirect', true)) ? $redirect : false; #wp
if (is_array($redirect) && !empty($redirect['url'])) wp_redirect($redirect['url'], 301); #wp
$custom = is_array($post_meta = get_post_meta($wp_query->post->ID, "_{$this->_class}", true)) ? (!empty($post_meta['template']) ? $post_meta['template'] : false) : false;
}
if ($wp_query->is_404 || $custom) {
$this->_template = $this->_templates->get_template($custom);
do_action('thesis_init_custom_template', $this->_template);
$this->page_404 = $wp_query->is_404 ? apply_filters('thesis_404_page', false) : false;
}
if ($wp_query->is_singular)
do_action('thesis_init_post_meta', $wp_query->post->ID);
if (is_array($preload = apply_filters('thesis_template_preload', array())) && !empty($preload)) {
$boxes = $this->_preload(array('thesis_html_head', 'thesis_html_body'));
if (is_array($boxes))
foreach ($preload as $id)
if (in_array($id, $boxes) && is_object($this->_boxes->active[$id]) && method_exists($this->_boxes->active[$id], 'preload'))
$this->_boxes->active[$id]->preload();
}
return apply_filters('thesis_template', THESIS_SKIN. '/template.php');
}
private function _preload($roots) {
$boxes = array();
foreach ($roots as $root) {
if (!in_array($root, $boxes))
$boxes[] = $root;
if (!empty($this->_template['boxes'][$root]) && is_array($this->_template['boxes'][$root]))
$boxes = array_merge_recursive($boxes, $this->_preload($this->_template['boxes'][$root]));
}
return $boxes;
}
public function _body_class($classes) {
global $wp_query;
$add = $this->_template['id'];
if (in_array($this->_template['id'], array_keys($this->_templates->custom_select())))
$add = 'custom';
$classes[] = "template-$add";
if (isset($wp_query->queried_object) && is_object($wp_query->queried_object) && !empty($wp_query->queried_object->taxonomy))
$classes[] = "template-". esc_attr($wp_query->queried_object->slug);
return $classes;
}
public function _editor_launcher() {
global $thesis;
if (!current_user_can('manage_options') || $thesis->wp_customize === true) return;
$scheme = defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN === true ? 'https' : 'http';
echo
"
\n",
"\t\n",
"
\n";
}
public function _editor_launcher_css() {
global $thesis;
if (!current_user_can('manage_options') || $thesis->wp_customize === true) return;
$position = !empty($this->functionality['launcher_position']) && $this->functionality['launcher_position'] == 'right' ?
'right' : 'left';
echo
"\n";
}
/*---:[ 301 redirect post meta and custom template options for posts, pages, and archive pages ]:---*/
public function _post_meta($post_meta) {
global $thesis;
$options = array(
'thesis_redirect' => array(
'title' => __('301 Redirect', 'thesis'),
'fields' => array(
'url' => array(
'type' => 'text',
'width' => 'full',
'code' => true,
'label' => sprintf(__('Redirect %s', 'thesis'), $thesis->api->base['url']),
'tooltip' => sprintf(__('Use this handy tool to set up nice-looking affiliate links for your site. If you place a %1$s in this field, users will get redirected to this %1$s whenever they visit the %1$s defined in the Permalink above (located beneath the post title field).', 'thesis'), $thesis->api->base['url']),
'description' => $thesis->api->strings['include_http']))),
$this->_class => array(
'title' => $thesis->api->ef0(sprintf(__('%1$s Skin Custom Template', 'thesis'), $this->_name)),
'context' => 'side',
'priority' => 'default',
'fields' => array(
'template' => array(
'type' => 'select',
'label' => $thesis->api->strings['custom_template'],
'options' => $this->_templates->custom_select()))));
return is_array($post_meta) ? array_merge($post_meta, $options) : $options;
}
public function _term_options($term_options) {
global $thesis;
$options[$this->_class] = array(
'template' => array(
'type' => 'select',
'label' => sprintf(__('%1$s Skin %2$s','thesis'), $this->_name, $thesis->api->strings['custom_template']),
'options' => $this->_templates->custom_select()));
return is_array($term_options) ? array_merge($term_options, $options) : $options;
}
/*---:[ Skin API valet methods ]:---*/
public function color_scheme($scheme) {
global $thesis;
if (!is_array($scheme)) return;
$label = !empty($scheme['label']) ? $scheme['label'] : __('Color Scheme', 'thesis');
$tooltip = !empty($scheme['tooltip']) ? $scheme['tooltip'] : false;
$scheme['default'] = $options = is_array($scheme['default']) ? $scheme['default'] : array();
$values = array_merge($scheme['default'], $this->design);
return array(
'type' => 'custom',
'label' => $label,
'tooltip' => $tooltip,
'options' => $options,
'output' => $thesis->api->colors->scheme($scheme, $values, $this->_class));
}
/*---:[ Deprecated Skin API methods ]:---*/
public function _init_header_image() {
wp_enqueue_style('thesis-options');
wp_enqueue_media();
wp_enqueue_script('custom-header');
}
public function _header_image() {
global $thesis;
$width = is_numeric($w = $this->header_image()) ? strip_tags($w) : false;
$save_url = esc_url(add_query_arg(array('action' => "{$this->_class}__header_image", '_wpnonce' => wp_create_nonce('thesis-header-image')), admin_url("admin-post.php")));
$delete_url = esc_url(add_query_arg(array('action' => "{$this->_class}__header_image", '_wpnonce' => wp_create_nonce('thesis-header-image'), 'delete' => 'true'), admin_url("admin-post.php")));
$data_attributes = "data-style=\"save button\" data-update-link=\"$save_url\" data-choose=\"". __('Select a Header Image', 'thesis'). "\" data-update=\"". __('Set Header Image', 'thesis'). "\"";
echo
$width == false ?
"\t\t
". __('You must declare a width for your header image before this functionality can be enabled.', 'thesis'). "