Exemplo n.º 1
0
 /**
  * Returns current blog ID
  *
  * @return integer
  */
 public static function blog_id()
 {
     global $w3_current_blog_id;
     if (!is_null($w3_current_blog_id)) {
         return $w3_current_blog_id;
     }
     if (!Util_Environment::is_wpmu() || is_network_admin()) {
         $w3_current_blog_id = 0;
         return $w3_current_blog_id;
     }
     $blog_data = Util_WpmuBlogmap::get_current_blog_data();
     if (!is_null($blog_data)) {
         $w3_current_blog_id = substr($blog_data, 1);
     } else {
         $w3_current_blog_id = 0;
     }
     return $w3_current_blog_id;
 }
Exemplo n.º 2
0
 /**
  * Init action
  *
  * @return void
  */
 function init()
 {
     // Load plugin text domain
     load_plugin_textdomain(W3TC_TEXT_DOMAIN, null, plugin_basename(W3TC_DIR) . '/languages/');
     if (is_multisite() && !is_network_admin()) {
         global $w3_current_blog_id, $current_blog;
         if ($w3_current_blog_id != $current_blog->blog_id && !isset($GLOBALS['w3tc_blogmap_register_new_item'])) {
             $url = Util_Environment::host_port() . $_SERVER['REQUEST_URI'];
             $pos = strpos($url, '?');
             if ($pos !== false) {
                 $url = substr($url, 0, $pos);
             }
             $GLOBALS['w3tc_blogmap_register_new_item'] = $url;
         }
     }
     if (isset($GLOBALS['w3tc_blogmap_register_new_item'])) {
         $do_redirect = false;
         // true value is a sign to just generate config cache
         if ($GLOBALS['w3tc_blogmap_register_new_item'] != 'cache_options') {
             if (Util_Environment::is_wpmu_subdomain()) {
                 $blog_home_url = $GLOBALS['w3tc_blogmap_register_new_item'];
             } else {
                 $home_url = rtrim(get_home_url(), '/');
                 if (substr($home_url, 0, 7) == 'http://') {
                     $home_url = substr($home_url, 7);
                 } else {
                     if (substr($home_url, 0, 8) == 'https://') {
                         $home_url = substr($home_url, 8);
                     }
                 }
                 if (substr($GLOBALS['w3tc_blogmap_register_new_item'], 0, strlen($home_url)) == $home_url) {
                     $blog_home_url = $home_url;
                 } else {
                     $blog_home_url = $GLOBALS['w3tc_blogmap_register_new_item'];
                 }
             }
             $do_redirect = Util_WpmuBlogmap::register_new_item($blog_home_url, $this->_config);
             // reset cache of blog_id
             global $w3_current_blog_id;
             $w3_current_blog_id = null;
             // change config to actual blog, it was master before
             $this->_config = new Config();
             // fix environment, potentially it's first request to a specific blog
             $environment = Dispatcher::component('Root_Environment');
             $environment->fix_on_event($this->_config, 'first_frontend', $this->_config);
         }
         // need to repeat request processing, since we was not able to realize
         // blog_id before so we are running with master config now.
         // redirect to the same url causes "redirect loop" error in browser,
         // so need to redirect to something a bit different
         if ($do_redirect) {
             if (strpos($_SERVER['REQUEST_URI'], '?') === false) {
                 Util_Environment::redirect_temp($_SERVER['REQUEST_URI'] . '?repeat=w3tc');
             } else {
                 if (strpos($_SERVER['REQUEST_URI'], 'repeat=w3tc') === false) {
                     Util_Environment::redirect_temp($_SERVER['REQUEST_URI'] . '&repeat=w3tc');
                 }
             }
         }
     }
     /**
      * Check for rewrite test request
      */
     $rewrite_test = Util_Request::get_boolean('w3tc_rewrite_test');
     if ($rewrite_test) {
         echo 'OK';
         exit;
     }
     $admin_bar = false;
     if (function_exists('is_admin_bar_showing')) {
         $admin_bar = is_admin_bar_showing();
     }
     if ($admin_bar) {
         add_action('wp_print_scripts', array($this, 'popup_script'));
     }
     // dont add system stuff to search results
     if (isset($_GET['repeat']) && $_GET['repeat'] == 'w3tc' || Util_Environment::is_preview_mode()) {
         header('X-Robots-Tag: noindex');
     }
 }
Exemplo n.º 3
0
 /**
  * Registers new blog url in url=>blog mapfile
  */
 public static function register_new_item($blog_home_url, $config)
 {
     if (!isset($GLOBALS['current_blog'])) {
         return false;
     }
     $filename = Util_WpmuBlogmap::blogmap_filename_by_home_url($blog_home_url);
     if (!@file_exists($filename)) {
         $blog_ids = array();
     } else {
         $data = @file_get_contents($filename);
         $blog_ids = @json_decode($data, true);
         if (!is_array($blog_ids)) {
             $blog_ids = array();
         }
     }
     if (isset($blog_ids[$blog_home_url])) {
         return false;
     }
     $data = $config->get_boolean('common.force_master') ? 'm' : 'c';
     $blog_home_url = preg_replace('/[^a-zA-Z0-9\\+\\.%~!()\\/\\-\\_]/', '', $blog_home_url);
     $blog_ids[$blog_home_url] = $data . $GLOBALS['current_blog']->blog_id;
     $data = json_encode($blog_ids);
     try {
         Util_File::file_put_contents_atomic($filename, $data);
     } catch (\Exception $ex) {
         return false;
     }
     unset(self::$content_by_filename[$filename]);
     return true;
 }