Beispiel #1
0
 /**
  * Change action
  */
 function on_change()
 {
     static $flushed = false;
     if (!$flushed) {
         require_once W3TC_LIB_W3_DIR . '/ObjectCache.php';
         $wp_object_cache =& W3_ObjectCache::instance();
         $wp_object_cache->flush();
     }
 }
Beispiel #2
0
 /**
  * Init cache
  * 
  * @return void
  */
 function wp_cache_init()
 {
     $GLOBALS['wp_object_cache'] =& W3_ObjectCache::instance();
 }
 /**
  * Validate the Options options before insertion
  *
  * @since       3.0.0
  * @access      public
  *
  * @param       array $plugin_options The options array
  *
  * @return array|mixed|string|void
  */
 public function _validate_options($plugin_options)
 {
     //print_r($plugin_options);
     //              exit();
     if (isset($this->validation_ran)) {
         return $plugin_options;
     }
     $this->validation_ran = 1;
     // Save the values not in the panel
     if (isset($plugin_options['redux-no_panel'])) {
         $keys = explode('|', $plugin_options['redux-no_panel']);
         foreach ($keys as $key) {
             $plugin_options[$key] = $this->options[$key];
         }
         if (isset($plugin_options['redux-no_panel'])) {
             unset($plugin_options['redux-no_panel']);
         }
     }
     if (!empty($this->hidden_perm_fields) && is_array($this->hidden_perm_fields)) {
         foreach ($this->hidden_perm_fields as $id => $data) {
             $plugin_options[$id] = $data;
         }
     }
     if ($plugin_options == $this->options) {
         return $plugin_options;
     }
     $time = time();
     // Sets last saved time
     $this->transients['last_save'] = $time;
     // Import
     if (isset($plugin_options['import_code']) && !empty($plugin_options['import_code']) || isset($plugin_options['import_link']) && !empty($plugin_options['import_link'])) {
         $this->transients['last_save_mode'] = "import";
         // Last save mode
         $this->transients['last_compiler'] = $time;
         $this->transients['last_import'] = $time;
         $this->transients['run_compiler'] = 1;
         if ($plugin_options['import_code'] != '') {
             $import = $plugin_options['import_code'];
         } elseif ($plugin_options['import_link'] != '') {
             $import = wp_remote_retrieve_body(wp_remote_get($plugin_options['import_link']));
         }
         if (!empty($import)) {
             $imported_options = json_decode($import, true);
         }
         if (!empty($imported_options) && is_array($imported_options) && isset($imported_options['redux-backup']) && $imported_options['redux-backup'] == '1') {
             $this->transients['changed_values'] = array();
             foreach ($plugin_options as $key => $value) {
                 if (isset($imported_options[$key]) && $imported_options[$key] != $value) {
                     $this->transients['changed_values'][$key] = $value;
                     $plugin_options[$key] = $value;
                 }
             }
             /**
              * action 'redux/options/{opt_name}/import'
              *
              * @param  &array [&$plugin_options, redux_options]
              */
             do_action_ref_array("redux/options/{$this->args['opt_name']}/import", array(&$plugin_options, $imported_options, $this->transients['changed_values']));
             setcookie('redux_current_tab', '', 1, '/', $time + 1000, "/");
             $_COOKIE['redux_current_tab'] = 1;
             unset($plugin_options['defaults'], $plugin_options['compiler'], $plugin_options['import'], $plugin_options['import_code']);
             if ($this->args['database'] == 'transient' || $this->args['database'] == 'theme_mods' || $this->args['database'] == 'theme_mods_expanded' || $this->args['database'] == 'network') {
                 $this->set_options($plugin_options);
                 return;
             }
             $plugin_options = wp_parse_args($imported_options, $plugin_options);
             $this->set_transients();
             // Update the transients
             return $plugin_options;
         }
     }
     // Reset all to defaults
     if (!empty($plugin_options['defaults'])) {
         if (empty($this->options_defaults)) {
             $this->options_defaults = $this->_default_values();
         }
         /**
          * apply_filters 'redux/validate/{opt_name}/defaults'
          *
          * @param  &array [ $this->options_defaults, $plugin_options]
          */
         $plugin_options = apply_filters("redux/validate/{$this->args['opt_name']}/defaults", $this->options_defaults);
         // Section reset
         //setcookie('redux-compiler-' . $this->args['opt_name'], 1, time() + 3000, '/');
         $this->transients['changed_values'] = array();
         if (empty($this->options)) {
             $this->options = $this->options_defaults;
         }
         foreach ($this->options as $key => $value) {
             if (isset($plugin_options[$key]) && $value != $plugin_options[$key]) {
                 $this->transients['changed_values'][$key] = $value;
             }
         }
         $this->transients['run_compiler'] = 1;
         $this->transients['last_save_mode'] = "defaults";
         // Last save mode
         //setcookie('redux-compiler-' . $this->args['opt_name'], 1, time() + 1000, "/");
         //setcookie("redux-saved-{$this->args['opt_name']}", 'defaults', time() + 1000, "/");
         $this->set_transients();
         // Update the transients
         return $plugin_options;
     }
     // Section reset to defaults
     if (!empty($plugin_options['defaults-section'])) {
         if (isset($plugin_options['redux-section']) && isset($this->sections[$plugin_options['redux-section']]['fields'])) {
             /**
              * apply_filters 'redux/validate/{opt_name}/defaults_section'
              *
              * @param  &array [ $this->options_defaults, $plugin_options]
              */
             foreach ($this->sections[$plugin_options['redux-section']]['fields'] as $field) {
                 if (isset($this->options_defaults[$field['id']])) {
                     $plugin_options[$field['id']] = $this->options_defaults[$field['id']];
                 } else {
                     $plugin_options[$field['id']] = "";
                 }
                 if (isset($field['compiler'])) {
                     $compiler = true;
                 }
             }
             $plugin_options = apply_filters("redux/validate/{$this->args['opt_name']}/defaults_section", $plugin_options);
         }
         $this->transients['changed_values'] = array();
         foreach ($this->options as $key => $value) {
             if (isset($plugin_options[$key]) && $value != $plugin_options[$key]) {
                 $this->transients['changed_values'][$key] = $value;
             }
         }
         if (isset($compiler)) {
             //$this->run_compiler = true;
             //setcookie('redux-compiler-' . $this->args['opt_name'], 1, time()+1000, '/');
             //$plugin_options['REDUX_COMPILER'] = time();
             $this->transients['last_compiler'] = $time;
             $this->transients['run_compiler'] = 1;
         }
         $this->transients['last_save_mode'] = "defaults_section";
         // Last save mode
         //setcookie("redux-saved-{$this->args['opt_name']}", 'defaults_section', time() + 1000, "/");
         unset($plugin_options['defaults'], $plugin_options['defaults_section'], $plugin_options['import'], $plugin_options['import_code'], $plugin_options['import_link'], $plugin_options['compiler'], $plugin_options['redux-section']);
         $this->set_transients();
         return $plugin_options;
     }
     //                if ($this->transients['last_save_mode'] != 'remove') {
     $this->transients['last_save_mode'] = "normal";
     // Last save mode
     //               } else {
     //                    $this->transients['last_save_mode'] = '';
     //                }
     /**
      * apply_filters 'redux/validate/{opt_name}/before_validation'
      *
      * @param  &array [&$plugin_options, redux_options]
      */
     $plugin_options = apply_filters("redux/validate/{$this->args['opt_name']}/before_validation", $plugin_options, $this->options);
     // Validate fields (if needed)
     $plugin_options = $this->_validate_values($plugin_options, $this->options, $this->sections);
     if (!empty($this->errors) || !empty($this->warnings)) {
         $this->transients['notices'] = array('errors' => $this->errors, 'warnings' => $this->warnings);
     }
     /**
      * action 'redux-validate-{opt_name}'
      *
      * @deprecated
      *
      * @param  &array [&$plugin_options, redux_options]
      */
     do_action_ref_array("redux-validate-{$this->args['opt_name']}", array(&$plugin_options, $this->options));
     // REMOVE
     if (!isset($this->transients['changed_values'])) {
         $this->transients['changed_values'] = array();
     }
     /**
      * action 'redux/options/{opt_name}/validate'
      *
      * @param  &array [&$plugin_options, redux_options]
      */
     do_action_ref_array("redux/options/{$this->args['opt_name']}/validate", array(&$plugin_options, $this->options, $this->transients['changed_values']));
     if (!empty($plugin_options['compiler'])) {
         unset($plugin_options['compiler']);
         $this->transients['last_compiler'] = $time;
         $this->transients['run_compiler'] = 1;
     }
     $this->transients['changed_values'] = array();
     // Changed values since last save
     foreach ($this->options as $key => $value) {
         if (isset($plugin_options[$key]) && $value != $plugin_options[$key]) {
             $this->transients['changed_values'][$key] = $value;
         }
     }
     unset($plugin_options['defaults'], $plugin_options['defaults_section'], $plugin_options['import'], $plugin_options['import_code'], $plugin_options['import_link'], $plugin_options['compiler'], $plugin_options['redux-section']);
     if ($this->args['database'] == 'transient' || $this->args['database'] == 'theme_mods' || $this->args['database'] == 'theme_mods_expanded') {
         $this->set_options($plugin_options);
         return;
     }
     if (defined('WP_CACHE') && WP_CACHE && class_exists('W3_ObjectCache')) {
         //echo "here";
         $w3 = W3_ObjectCache::instance();
         $key = $w3->_get_cache_key($this->args['opt_name'] . '-transients', 'transient');
         //echo $key;
         $w3->delete($key, 'transient', true);
         //set_transient($this->args['opt_name'].'-transients', $this->transients);
         //exit();
     }
     $this->set_transients($this->transients);
     return $plugin_options;
 }
Beispiel #4
0
/**
 * Shortcut for objectcache cache flush
 *
 * @return boolean
 */
function w3tc_objectcache_flush()
{
    require_once W3TC_LIB_W3_DIR . '/ObjectCache.php';
    $w3_objectcache =& W3_ObjectCache::instance();
    return $w3_objectcache->flush();
}
Beispiel #5
0
 /**
  * Output buffering callback
  *
  * @param string $buffer
  * @return string
  */
 function ob_callback(&$buffer)
 {
     global $wpdb;
     if ($buffer != '' && w3_is_xml($buffer)) {
         if (w3_is_database_error($buffer)) {
             @header('HTTP/1.1 503 Service Unavailable');
         } else {
             /**
              * Replace links for preview mode
              */
             if (w3_is_preview_mode() && isset($_SERVER['HTTP_USER_AGENT']) && $_SERVER['HTTP_USER_AGENT'] != W3TC_POWERED_BY) {
                 $domain_url_regexp = w3_get_domain_url_regexp();
                 $buffer = preg_replace_callback('~(href|src|action)=([\'"])(' . $domain_url_regexp . ')?(/[^\'"]*)~', array(&$this, 'link_replace_callback'), $buffer);
             }
             /**
              * Add footer comment
              */
             $date = date_i18n('Y-m-d H:i:s');
             $host = !empty($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost';
             if ($this->is_supported()) {
                 $buffer .= sprintf("\r\n<!-- Served from: %s @ %s by W3 Total Cache -->", w3_escape_comment($host), $date);
             } else {
                 $strings = array();
                 if ($this->_config->get_boolean('minify.enabled') && !$this->_config->get_boolean('minify.debug')) {
                     require_once W3TC_LIB_W3_DIR . '/Plugin/Minify.php';
                     $w3_plugin_minify =& W3_Plugin_Minify::instance();
                     $strings[] = sprintf("Minified using %s%s", w3_get_engine_name($this->_config->get_string('minify.engine')), $w3_plugin_minify->minify_reject_reason != '' ? sprintf(' (%s)', $w3_plugin_minify->minify_reject_reason) : '');
                 }
                 if ($this->_config->get_boolean('pgcache.enabled') && !$this->_config->get_boolean('pgcache.debug')) {
                     require_once W3TC_LIB_W3_DIR . '/PgCache.php';
                     $w3_pgcache =& W3_PgCache::instance();
                     $strings[] = sprintf("Page Caching using %s%s", w3_get_engine_name($this->_config->get_string('pgcache.engine')), $w3_pgcache->cache_reject_reason != '' ? sprintf(' (%s)', $w3_pgcache->cache_reject_reason) : '');
                 }
                 if ($this->_config->get_boolean('dbcache.enabled') && !$this->_config->get_boolean('dbcache.debug') && is_a($wpdb, 'W3_Db')) {
                     $append = is_user_logged_in() ? ' (user is logged in)' : '';
                     if ($wpdb->query_hits) {
                         $strings[] = sprintf("Database Caching %d/%d queries in %.3f seconds using %s%s", $wpdb->query_hits, $wpdb->query_total, $wpdb->time_total, w3_get_engine_name($this->_config->get_string('dbcache.engine')), $append);
                     } else {
                         $strings[] = sprintf("Database Caching using %s%s", w3_get_engine_name($this->_config->get_string('dbcache.engine')), $append);
                     }
                 }
                 if ($this->_config->get_boolean('objectcache.enabled') && !$this->_config->get_boolean('objectcache.debug')) {
                     require_once W3TC_LIB_W3_DIR . '/ObjectCache.php';
                     $w3_objectcache =& W3_ObjectCache::instance();
                     $strings[] = sprintf("Object Caching %d/%d objects using %s", $w3_objectcache->cache_hits, $w3_objectcache->cache_total, w3_get_engine_name($this->_config->get_string('objectcache.engine')));
                 }
                 if ($this->_config->get_boolean('cdn.enabled') && !$this->_config->get_boolean('cdn.debug')) {
                     require_once W3TC_LIB_W3_DIR . '/Plugin/Cdn.php';
                     $w3_plugin_cdn =& W3_Plugin_Cdn::instance();
                     $cdn =& $w3_plugin_cdn->get_cdn();
                     $via = $cdn->get_via();
                     $strings[] = sprintf("Content Delivery Network via %s%s", $via ? $via : 'N/A', $w3_plugin_cdn->cdn_reject_reason != '' ? sprintf(' (%s)', $w3_plugin_cdn->cdn_reject_reason) : '');
                 }
                 $buffer .= "\r\n<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/\r\n";
                 if (count($strings)) {
                     $buffer .= "\r\n" . implode("\r\n", $strings) . "\r\n";
                 }
                 $buffer .= sprintf("\r\nServed from: %s @ %s -->", w3_escape_comment($host), $date);
             }
         }
     }
     return $buffer;
 }
 function update_term($term_id, $tt_id, $taxonomy)
 {
     $tax_meta = get_option('wpseo_taxonomy_meta');
     foreach (array('title', 'desc', 'metakey', 'bctitle', 'canonical', 'sitemap_include') as $key) {
         if (isset($_POST['wpseo_' . $key])) {
             $tax_meta[$taxonomy][$term_id]['wpseo_' . $key] = $_POST['wpseo_' . $key];
         }
     }
     foreach (array('noindex', 'nofollow') as $key) {
         if (isset($_POST['wpseo_' . $key])) {
             $tax_meta[$taxonomy][$term_id]['wpseo_' . $key] = true;
         } else {
             $tax_meta[$taxonomy][$term_id]['wpseo_' . $key] = false;
         }
     }
     update_option('wpseo_taxonomy_meta', $tax_meta);
     if (defined('W3TC_DIR')) {
         require_once W3TC_DIR . '/lib/W3/ObjectCache.php';
         $w3_objectcache =& W3_ObjectCache::instance();
         $w3_objectcache->flush();
     }
 }
Beispiel #7
0
 /**
  * Update the taxonomy meta data on save.
  *
  * @param int    $term_id  ID of the term to save data for
  * @param int    $tt_id    The taxonomy_term_id for the term.
  * @param string $taxonomy The taxonmy the term belongs to.
  */
 function update_term($term_id, $tt_id, $taxonomy)
 {
     $tax_meta = get_option('wpseo_taxonomy_meta');
     if (!isset($tax_meta[$taxonomy]) || !isset($tax_meta[$taxonomy][$term_id]) || !is_array($tax_meta[$taxonomy][$term_id])) {
         $tax_meta[$taxonomy][$term_id] = array();
     }
     foreach (array('title', 'desc', 'metakey', 'bctitle', 'canonical', 'noindex', 'sitemap_include') as $key) {
         if (isset($_POST['wpseo_' . $key]) && !empty($_POST['wpseo_' . $key])) {
             $val = trim($_POST['wpseo_' . $key]);
             if ($key == 'canonical') {
                 $val = esc_url($val);
             } else {
                 $val = esc_html($val);
             }
             $tax_meta[$taxonomy][$term_id]['wpseo_' . $key] = $val;
         } else {
             if (isset($tax_meta[$taxonomy][$term_id]['wpseo_' . $key])) {
                 unset($tax_meta[$taxonomy][$term_id]['wpseo_' . $key]);
             }
         }
     }
     update_option('wpseo_taxonomy_meta', $tax_meta, 99);
     if (defined('W3TC_DIR') && class_exists('W3_ObjectCache')) {
         require_once W3TC_DIR . '/lib/W3/ObjectCache.php';
         $w3_objectcache =& W3_ObjectCache::instance();
         $w3_objectcache->flush();
     }
 }
 function update_term($term_id, $tt_id, $taxonomy)
 {
     global $wds_options;
     $tax_meta = get_option('wds_taxonomy_meta');
     foreach (array('title', 'desc', 'bctitle', 'canonical') as $key) {
         $tax_meta[$taxonomy][$term_id]['wds_' . $key] = @$_POST['wds_' . $key];
     }
     foreach (array('noindex', 'nofollow') as $key) {
         $global = !empty($wds_options["meta_robots-{$key}-{$taxonomy}"]) ? (bool) $wds_options["meta_robots-{$key}-{$taxonomy}"] : false;
         if (!$global) {
             $tax_meta[$taxonomy][$term_id]['wds_' . $key] = isset($_POST["wds_{$key}"]) ? (bool) $_POST["wds_{$key}"] : false;
         } else {
             $tax_meta[$taxonomy][$term_id]["wds_override_{$key}"] = isset($_POST["wds_override_{$key}"]) ? (bool) $_POST["wds_override_{$key}"] : false;
         }
     }
     update_option('wds_taxonomy_meta', $tax_meta);
     if (defined('W3TC_DIR')) {
         require_once W3TC_DIR . '/lib/W3/ObjectCache.php';
         $w3_objectcache =& W3_ObjectCache::instance();
         $w3_objectcache->flush();
     }
 }