/**
  * Do logic
  */
 function process()
 {
     /**
      * Skip some pages
      */
     switch (true) {
         case defined('DOING_AJAX'):
         case defined('DOING_CRON'):
         case defined('APP_REQUEST'):
         case defined('XMLRPC_REQUEST'):
         case defined('WP_ADMIN'):
         case defined('SHORTINIT') && SHORTINIT:
             return;
     }
     /**
      * Handle mobile or referrer redirects
      */
     if ($this->_mobile || $this->_referrer) {
         $mobile_redirect = $this->_mobile->get_redirect();
         $referrer_redirect = $this->_referrer->get_redirect();
         $redirect = $mobile_redirect ? $mobile_redirect : $referrer_redirect;
         if ($redirect) {
             w3_redirect($redirect);
             exit;
         }
     }
 }
示例#2
0
/**
 * Redirects when in WP Admin
 * @param array $params
 * @param bool $check_referrer
 * @param string $page
 */
function w3_admin_redirect($params = array(), $check_referrer = false, $page = '')
{
    w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
    $url = W3_Request::get_string('redirect');
    $page_url = W3_Request::get_string('page');
    if ($url == '') {
        if ($check_referrer && !empty($_SERVER['HTTP_REFERER'])) {
            $url = $_SERVER['HTTP_REFERER'];
        } else {
            $url = 'admin.php';
            if (empty($page)) {
                $page = $page_url;
            }
            $params = array_merge(array('page' => $page), $params);
        }
    }
    w3_redirect($url, $params);
}
 /**
  * Do cache logic
  */
 function process()
 {
     /**
      * Skip caching for some pages
      */
     switch (true) {
         case defined('DOING_AJAX'):
         case defined('DOING_CRON'):
         case defined('APP_REQUEST'):
         case defined('XMLRPC_REQUEST'):
         case defined('WP_ADMIN'):
             return;
     }
     /**
      * Handle mobile redirects
      */
     $mobile_redirect = $this->_config->get_string('pgcache.mobile.redirect');
     if ($mobile_redirect != '' && $this->_is_mobile()) {
         w3_redirect($mobile_redirect);
         exit;
     }
     /**
      * Do page cache logic
      */
     if ($this->_debug) {
         $this->_time_start = w3_microtime();
     }
     $this->_caching = $this->_can_cache();
     $compression = $this->_get_compression();
     $page_key = $this->_get_page_key($_SERVER['REQUEST_URI'], $compression);
     if ($this->_caching) {
         /**
          * Check if page is cached
          */
         $cache =& $this->_get_cache();
         $data = $cache->get($page_key);
         if ($data) {
             /**
              * Do Bad Behavior check
              */
             $this->_bad_behavior();
             if ($this->_enhanced_mode) {
                 $is_404 = false;
                 $headers = array();
                 $time = $cache->mtime($page_key);
                 $content = $data;
             } else {
                 $is_404 = $data['404'];
                 $headers = $data['headers'];
                 $time = $data['time'];
                 $content = $data['content'];
             }
             /**
              * Calculate content etag
              */
             $etag = md5($content);
             /**
              * Send headers
              */
             $this->_send_headers($is_404, $time, $etag, $compression, $headers);
             /**
              * Append debug info
              */
             if ($this->_debug) {
                 $time_total = w3_microtime() - $this->_time_start;
                 $debug_info = $this->_get_debug_info($page_key, true, '', true, $time_total);
                 $this->_append_content($content, "\r\n\r\n" . $debug_info, $compression);
             }
             echo $content;
             exit;
         }
     }
     /**
      * Start output buffering
      */
     ob_start(array(&$this, 'ob_callback'));
 }
 /**
  * Redirects to authorization url
  */
 public function authorize()
 {
     $tokens = $this->_get_auth_request_tokens();
     $oauth_token = $tokens['oauth_token'];
     $oauth_token_secret = $tokens['oauth_token_secret'];
     $auth_url = $this->_get_authorize_url($oauth_token, $oauth_token_secret);
     w3_redirect($auth_url);
 }
示例#5
0
 /**
  * Start previewing
  */
 function action_default_previewing()
 {
     setcookie('w3tc_preview', true, 0, '/');
     w3_redirect(w3_get_home_url());
 }
示例#6
0
 /**
  * Do cache logic
  */
 function process()
 {
     if ($this->_config->get_boolean('pgcache.enabled')) {
         /**
          * Skip caching for some pages
          */
         switch (true) {
             case defined('DONOTCACHEPAGE'):
             case defined('DOING_AJAX'):
             case defined('DOING_CRON'):
             case defined('APP_REQUEST'):
             case defined('XMLRPC_REQUEST'):
             case defined('WP_ADMIN'):
             case defined('SHORTINIT') && SHORTINIT:
                 return;
         }
         /**
          * Handle mobile or referrer redirects
          */
         if ($this->_mobile || $this->_referrer) {
             $mobile_redirect = $this->_mobile->get_redirect();
             $referrer_redirect = $this->_referrer->get_redirect();
             $redirect = $mobile_redirect ? $mobile_redirect : $referrer_redirect;
             if ($redirect) {
                 w3_redirect($redirect);
                 exit;
             }
         }
         /**
          * Do page cache logic
          */
         if ($this->_debug) {
             $this->_time_start = w3_microtime();
         }
         $this->_caching = $this->_can_cache();
         if ($this->_caching && !$this->_enhanced_mode) {
             $cache =& $this->_get_cache();
             $mobile_group = $this->_get_mobile_group();
             $referrer_group = $this->_get_referrer_group();
             $encryption = $this->_get_encryption();
             $compression = $this->_get_compression();
             $raw = !$compression;
             $this->_page_key = $this->_get_page_key($this->_request_uri, $mobile_group, $referrer_group, $encryption, $compression);
             /**
              * Check if page is cached
              */
             $data = $cache->get($this->_page_key);
             /**
              * Try to get uncompressed version of cache
              */
             if ($compression && !$data) {
                 $raw = true;
                 $this->_page_key = $this->_get_page_key($this->_request_uri, $mobile_group, $referrer_group, $encryption, false);
                 $data = $cache->get($this->_page_key);
             }
             /**
              * If cache exists
              */
             if ($data) {
                 /**
                  * Do Bad Behavior check
                  */
                 $this->_bad_behavior();
                 if ($this->_enhanced_mode) {
                     $is_404 = false;
                     $headers = array();
                     $time = $cache->mtime($this->_page_key);
                     $content =& $data;
                 } else {
                     $is_404 = $data['404'];
                     $headers = $data['headers'];
                     $time = $data['time'];
                     $content =& $data['content'];
                 }
                 /**
                  * Calculate content etag
                  */
                 $etag = md5($content);
                 /**
                  * Send headers
                  */
                 $this->_send_headers($is_404, $time, $etag, $compression, $headers);
                 /**
                  * Do manual compression for uncompressed page
                  */
                 if ($raw) {
                     /**
                      * Append debug info
                      */
                     if ($this->_debug) {
                         $time_total = w3_microtime() - $this->_time_start;
                         $debug_info = $this->_get_debug_info(true, '', true, $time_total);
                         $content .= "\r\n\r\n" . $debug_info;
                     }
                     /**
                      * Parse dynamic tags
                      */
                     $this->_parse_dynamic($content);
                     /**
                      * Compress content
                      */
                     $this->_compress($content, $compression);
                 }
                 echo $content;
                 exit;
             }
         }
         /**
          * Start output buffering
          */
         ob_start(array(&$this, 'ob_callback'));
     }
 }
示例#7
0
 function action_cdn_netdna_authorize()
 {
     w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/ui.php');
     try {
         /**
          * @var W3_ConfigAdmin $config_admin
          */
         $config_admin = w3_instance('W3_ConfigAdmin');
         if ($config_admin->get_integer('track.maxcdn_authorize', 0) == 0) {
             $config_admin->set('track.maxcdn_authorize', time());
             $config_admin->save();
         }
     } catch (Exception $ex) {
     }
     w3_redirect(NETDNA_AUTHORIZE_URL);
 }
 /**
  * Init action
  *
  * @return void
  */
 function init()
 {
     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'] !== true) {
             w3_require_once(W3TC_INC_DIR . '/functions/multisite.php');
             $do_redirect = w3_blogmap_register_new_item($GLOBALS['w3tc_blogmap_register_new_item'], $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 W3_Config();
         }
         $do_redirect |= $this->_config->fill_missing_cache_options_and_save();
         // 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) {
                 w3_redirect($_SERVER['REQUEST_URI'] . '?repeat=w3tc');
             } else {
                 if (strpos($_SERVER['REQUEST_URI'], 'repeat=w3tc') === false) {
                     w3_redirect($_SERVER['REQUEST_URI'] . '&repeat=w3tc');
                 }
             }
         }
     }
     /**
      * Check request and handle w3tc_request_data requests
      */
     $pos = strpos($_SERVER['REQUEST_URI'], '/w3tc_request_data/');
     if ($pos !== false) {
         $hash = substr($_SERVER['REQUEST_URI'], $pos + 19, 32);
         if (strlen($hash) == 32) {
             $request_data = (array) get_option('w3tc_request_data');
             if (isset($request_data[$hash])) {
                 echo '<pre>';
                 foreach ($request_data[$hash] as $key => $value) {
                     printf("%s: %s\n", $key, $value);
                 }
                 echo '</pre>';
                 unset($request_data[$hash]);
                 update_option('w3tc_request_data', $request_data);
             } else {
                 echo 'Requested hash expired or invalid';
             }
             exit;
         }
     }
     /**
      * Check for rewrite test request
      */
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     $rewrite_test = W3_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 (current_user_can('manage_options') && $admin_bar) {
         add_action('wp_print_scripts', array($this, 'popup_script'));
     }
 }
示例#9
0
 /**
  * Redirect function
  * 
  * @param boolean $check_referer
  */
 function redirect($params = array(), $check_referer = false)
 {
     require_once W3TC_LIB_W3_DIR . '/Request.php';
     $url = W3_Request::get_string('redirect');
     if ($url == '') {
         if ($check_referer && !empty($_SERVER['HTTP_REFERER'])) {
             $url = $_SERVER['HTTP_REFERER'];
         } else {
             $url = 'options-general.php';
             $params = array_merge(array('page' => W3TC_FILE, 'tab' => $this->_tab), $params);
         }
     }
     w3_redirect($url, $params);
 }