/** * @ajax */ public function ajax_admin_save_options() { if (!tf_current_user_can(array('manage_options'), false)) { die('Access denied'); } // check security with nonce. check_ajax_referer('tfuse_framework_save_options', '_ajax_nonce'); $tfuse_framework_options = array(); $post_options = $this->request->isset_POST('options') ? $this->request->POST('options') : ''; $unserialized = json_decode($post_options); $values = get_object_vars($unserialized); $admin_options = $this->get->options('admin'); $admin_options = tf_only_options($admin_options); $do_refresh = FALSE; foreach ($admin_options as $option_id => $option) { if (isset($option['on_update']) && $option['on_update'] == 'reload_page') { if (!isset($values[$option_id]) && $this->get->option('admin', $option_id) == 'true' || isset($values[$option_id]) && $this->get->option('admin', $option_id) != $values[$option_id]) { $do_refresh = TRUE; } } if ($this->optisave->has_method("admin_{$option['type']}")) { $this->optisave->{"admin_{$option['type']}"}($option, $values, $tfuse_framework_options); } else { $this->optisave->admin_text($option, $values, $tfuse_framework_options); } } update_option(TF_THEME_PREFIX . '_tfuse_framework_options', $tfuse_framework_options); do_action('tfuse_admin_save_options', $values, $tfuse_framework_options); if ($do_refresh) { $this->ajax->out_json['reload_page'] = TRUE; } $this->ajax->ajax_finish(); }
function ext_option($ext_name, $type, $option, $directory = '') { if (!isset($this->ext_options_cache[$ext_name]) && !isset($this->ext_options_cache[$ext_name][$type])) { $this->ext_options_cache[$ext_name][$type] = $this->ext_options($ext_name, $type, $directory); if (isset($this->ext_options_cache[$ext_name][$type]['tabs'])) { $tmp = tf_only_options($this->ext_options_cache[$ext_name][$type]); } } $db_options = get_option(TF_THEME_PREFIX . '_tfuse_' . $type . '_options'); if (isset($db_options[$option])) { return $db_options[$option]; } else { if (isset($this->options_cache[$ext_name][$type][$option]) || isset($tmp[$option])) { if (!isset($tmp)) { return $this->options_cache[$ext_name][$type][$option]; } else { return $tmp[$option]; } } else { return NULL; } } }
/** * Extract form options array for optigen/interface, only id=>value */ function tf_only_options(&$options, $without_types = array(), $only_types = array(), &$__recursionData = NULL) { global $TFUSE; if (gettype(@$TFUSE->optigen) != 'object') { user_error('$TFUSE is not loaded', E_USER_ERROR); } if ($__recursionData === NULL) { $__recursionData['without_types'] = (array) $without_types; $__recursionData['only_types'] = (array) $only_types; $__recursionData['check_without'] = count($without_types); $__recursionData['check_only'] = count($only_types); } $collectedOptions = array(); if (is_array($options) && count($options)) { foreach ($options as $key => $option) { if (!is_array($option)) { continue; } // Check if option has correct structure if (isset($option['type']) && substr($option['type'], 0, 1) != '_' && method_exists($TFUSE->optigen, $option['type']) && isset($option['id'])) { if ($__recursionData['check_only']) { if (!in_array($option['type'], $__recursionData['only_types'])) { continue; } } if ($__recursionData['check_without']) { if (in_array($option['type'], $__recursionData['without_types'])) { continue; } } $collectedOptions[$option['id']] = $option; } else { $collectedOptions = array_merge($collectedOptions, tf_only_options($option, array(), array(), $__recursionData)); } } } return $collectedOptions; }
function _tfuse_fix_new_options_negate($options, $type) { if ($type != 'admin' || !get_option(TF_THEME_PREFIX . '_tfuse_framework_options')) { return $options; } static $called = false; if ($called) { return $options; } $called = true; global $TFUSE; $negateOldOptions = array('disable_tfuse_seo_tab' => 'enable_tfuse_seo_tab', 'deactivate_tfuse_style' => 'activate_tfuse_style'); $tp = TF_THEME_PREFIX . '_'; $adminOptions = tf_only_options($options); foreach ($negateOldOptions as $oldId => $newId) { if (isset($adminOptions[$tp . $newId])) { // new id exists in options (this is new theme) if (tfuse_options($newId) === null) { // new id is not set // set it with negated old value tfuse_set_option($newId, !(bool) tfuse_options($oldId)); } } else { // new id does not exists in options (this is old theme) // set it with negated old value // (verifications in code by this options id to work properly (emulate it exists)) tfuse_set_option($newId, !(bool) tfuse_options($oldId)); } } return $options; }
public function get_ext_setup_option($option) { static $cache_setup_option = array(); if (!empty($cache_setup_option)) { $cache_setup_option = $this->get_ext_setup_options(); if (isset($cache_setup_option['tabs'])) { $tmp = tf_only_options($cache_setup_option); } } $db_options = $this->model->get_options(); if (isset($db_options[$option])) { return $db_options[$option]; } else { if (isset($cache_setup_option[$option]) || isset($tmp[$option])) { if (!isset($tmp)) { return $cache_setup_option[$option]; } else { return $tmp[$option]; } } else { return NULL; } } }
/** * By 'default' all options of an form generated by optigen are saved in one place together even there are options appended from other filters. * With this method, you can catch specific array of "child options" to be detected and saved into another custom "location" * This is useful when appending/injecting options via filters into some optigen form and cannot change manually the code from * the main form that saves that options, and do not know exactly where it is. * This method checks every ajax submit and if options are within the submitted options, * it triggers save process for that options */ public function catch_options_submit($arguments) { // $arguments Structure array('options' => array(), 'skip_tf_action' => array('or string'), 'only_tf_action' => array('or string'), 'skip_tfuse_ajax' => array('or string'), 'only_tfuse_ajax' => array('or string'), 'callback' => 'callable', 'callback_arguments' => array(), 'wp_option' => 'option_name'); // Check required options if (!isset($arguments['options'])) { die('Undefined required argument "options" in ' . __METHOD__ . '()'); } $current_ajax = $this->get_current_ajax(); do { if ($current_ajax['type'] === null) { return; } // if is some valid ajax, verify if pass the filters if ($current_ajax['type'] == 'tf_action') { if (isset($arguments['skip_tf_action'])) { $arguments['skip_tf_action'] = (array) $arguments['skip_tf_action']; if (in_array($current_ajax['callback'], $arguments['skip_tf_action'])) { return; } } if (isset($arguments['only_tf_action'])) { $arguments['only_tf_action'] = (array) $arguments['only_tf_action']; if (!in_array($current_ajax['callback'], $arguments['only_tf_action'])) { return; } } } elseif ($current_ajax['type'] == 'tfuse_ajax') { $class = explode('\\', get_class($current_ajax['callback'][0])); $class = end($class); if (isset($arguments['skip_tfuse_ajax'])) { $arguments['skip_tfuse_ajax'] = (array) $arguments['skip_tfuse_ajax']; foreach ($arguments['skip_tfuse_ajax'] as $skipClass) { if (is_array($skipClass)) { if (($class == $skipClass[0] || $current_ajax['action'] == $skipClass[0]) && $current_ajax['callback'][1] == $skipClass[1]) { return; } } else { if ($class == $skipClass || $current_ajax['action'] == $skipClass) { return; } } } } if (isset($arguments['only_tfuse_ajax'])) { $arguments['only_tfuse_ajax'] = (array) $arguments['only_tfuse_ajax']; foreach ($arguments['only_tfuse_ajax'] as $onlyClass) { if (is_array($onlyClass)) { if (($class == $onlyClass[0] || $current_ajax['action'] == $onlyClass[0]) && $current_ajax['callback'][1] == $onlyClass[1]) { break 2; } } else { if ($class == $onlyClass || $current_ajax['action'] == $onlyClass) { break 2; } } } // Current tfuse_ajax class not found in 'only' filters, but the filters are set, so the class is not allowed return; } } } while (false); $options = tf_only_options($arguments['options'], array('raw')); if (!count($options)) { echo sprintf(__('Invalid options given in %s(). Only options that sure creates _POST values are allowed (and be sure they are unique enough, a few options in id containing "general"/"not unique" names its not a good idea)' . "\n", 'tfuse'), __METHOD__); print_r($arguments['options']); die; } // check if _POST contains options if (!$this->request->isset_POST('options')) { return; } $post_options = json_decode($this->request->POST('options')); if (!is_object($post_options)) { return; } $post_options_clean_keys = array(); foreach ($post_options as $key => $val) { $post_options_clean_keys[rtrim($key, '[]')] = $val; } // If at least one option is not in _POST, that means the whole array does not match if (count($options) > count(array_intersect_key($options, $post_options_clean_keys))) { return; } $values = get_object_vars($post_options); $data_options = array(); foreach ($options as $option_id => $option) { if ($this->optisave->has_method("admin_{$option['type']}")) { $this->optisave->{"admin_{$option['type']}"}($option, $values, $data_options); } else { $this->optisave->admin_text($option, $values, $data_options); } } array_walk_recursive($data_options, create_function('&$i', 'if (strtolower($i) === "true") $i = true; elseif (strtolower($i) === "false") $i = false;')); if (isset($arguments['wp_option'])) { if (empty($arguments['wp_option'])) { die(sprintf(__('Argument "wp_option" cannot be empty, in %s ()' . 'tfuse'), __METHOD__)); } update_option($arguments['wp_option'], $data_options); } $action_arguments = array('current_ajax' => $current_ajax, 'raw_options' => $arguments['options'], 'data_options' => $data_options, 'wp_option' => isset($arguments['wp_option']) ? $arguments['wp_option'] : NULL, 'callback_arguments' => @$arguments['callback_arguments']); if (isset($arguments['callback'])) { if (empty($arguments['callback'])) { die(sprintf(__('Argument "callback" cannot be empty, in %s ()', 'tfuse'), __METHOD__)); } if (is_array($arguments['callback'])) { // Object method $arguments['callback'][0]->{$arguments['callback'][1]}($action_arguments); } else { // Function $arguments['callback']($action_arguments); } } do_action('tf_ajax_catch_options_submit', $action_arguments); return $action_arguments; }
function save_slides($id, $options = '', $additional = array()) { if (isset($additional['design'])) { $this->design = $additional['design']; } if (isset($additional['type'])) { $this->type = $additional['type']; } if (isset($id)) { $this->id = $id; } $slider_settings = array('general' => '', 'slides' => ''); $option_list = $this->get->ext_options($this->_ext_name, $this->design, 'designs/' . $this->design); $option_list = $this->__parent->add_default_config($option_list); $options_file = array(); $options_file = tf_only_options($option_list); unset($option_list); foreach ($options['general'] as $tmp_id => $val) { $slide_prefix = $this->__parent->get_slide_prefix(); if (stripos($tmp_id, $slide_prefix) !== FALSE) { unset($options['general'][$tmp_id]); } } foreach ($options['general'] as $opt_name => $opt_val) { if ($this->optisave->has_method("admin_{$options_file[$opt_name]['type']}")) { $this->optisave->{"admin_{$options_file[$opt_name]['type']}"}($options_file[$opt_name], $options['general'], $slider_settings['general']); } else { $this->optisave->admin_text($options_file[$opt_name], $options['general'], $slider_settings['general']); } } $i = 0; foreach ($options['slides'] as $key => $slide) { foreach ($slide as $slide_opt_name => $slide_opt_val) { apply_filters('tfuse_slider_value', $slide_opt_val, $options['general']['slider_title'] . ' slide ' . $key . ' ' . $slide_opt_name); if ($this->optisave->has_method("admin_{$options_file[$slide_opt_name]['type']}")) { $this->optisave->{"admin_{$options_file[$slide_opt_name]['type']}"}($options_file[$slide_opt_name], $slide, $slider_settings['slides'][$i]); } else { $this->optisave->admin_text($options_file[$slide_opt_name], $slide, $slider_settings['slides'][$i]); } } $i++; } $slides = $this->get_sliders(true); if (isset($slides[$this->id])) { $slides[$this->id] = $slider_settings; } else { $uniqid = uniqid(); while (isset($slides[$uniqid])) { $uniqid = uniqid(); } $slides[$uniqid] = $slider_settings; $this->id = $uniqid; } $slides[$this->id]['general']['design'] = $this->design; $slides[$this->id]['general']['type'] = $this->type; $slides[$this->id]['id'] = $this->id; $slides[$this->id]['design'] = $this->design; $slides[$this->id]['type'] = $this->type; if (!isset($slides[$this->id]['created_at'])) { $slides[$this->id]['created_at'] = time(); } foreach ($slides[$this->id]['general'] as $key => $val) { if (stripos($key, 'slider_title') !== false) { $slides[$this->id]['title'] = $slides[$this->id]['general'][$key]; break; } } update_option($this->wp_option, $slides); $this->get_sliders(); return $this->id; }