示例#1
0
 /**
  * process_scripts()
  *
  * @param bool $header_scripts
  * @return void
  **/
 static function process_scripts($header_scripts = true)
 {
     global $wp_scripts;
     if (!$wp_scripts instanceof WP_Scripts) {
         $wp_scripts = new WP_Scripts();
     }
     $queue = $wp_scripts->queue;
     $wp_scripts->all_deps($queue);
     if (!$wp_scripts->to_do) {
         return;
     }
     $todo = array();
     $js = array();
     $dirs = array(content_url(), plugins_url());
     foreach ($wp_scripts->to_do as $key => $handle) {
         if (!empty($wp_scripts->registered[$handle]->args)) {
             continue;
         }
         // bail if is a footer script and we're doing headers
         if ($header_scripts && $wp_scripts->groups[$handle] > 0) {
             continue;
         }
         $jsPath = $wp_scripts->registered[$handle]->src;
         // bail if alias
         if (!$jsPath) {
             continue;
         }
         if (!asset_cache::startsWith($jsPath, site_url())) {
             $jsPath = site_url() . $jsPath;
         }
         $inDir = false;
         foreach ($dirs as $dir) {
             if (asset_cache::startsWith($jsPath, $dir)) {
                 $inDir = true;
                 break;
             }
         }
         $suffixMatch = asset_cache::endsWith($jsPath, ".js");
         if ($inDir && $suffixMatch) {
             $js[$handle] = $wp_scripts->registered[$handle]->ver;
             $todo[] = $handle;
             unset($wp_scripts->to_do[$key]);
             $wp_scripts->done[] = $handle;
         }
     }
     if ($todo) {
         $file = '/assets/' . md5(serialize($js)) . '.js';
         if (!cache_fs::exists($file)) {
             asset_cache::concat_scripts($file, $todo);
         }
         $wp_scripts->default_version = null;
         if ($header_scripts) {
             wp_enqueue_script('scripts_concat', content_url() . '/cache' . $file);
         } else {
             wp_enqueue_script('footer_scripts_concat', content_url() . '/cache' . $file, array(), false, true);
             $wp_scripts->groups['footer_scripts_concat'] = 1;
             $wp_scripts->in_footer[] = 'footer_scripts_concat';
         }
     }
     $wp_scripts->do_concat = true;
     $header_scripts ? $wp_scripts->do_head_items() : $wp_scripts->do_footer_items();
     if ($wp_scripts->print_code) {
         echo "<script type='text/javascript'>\n";
         echo "/* <![CDATA[ */\n";
         echo $wp_scripts->print_code;
         echo "/* ]]> */\n";
         echo "</script>\n";
     }
     //		$wp_scripts->reset();
 }
示例#2
0
 /**
  * start()
  *
  * @return void
  **/
 static function start()
 {
     # some things can be taken care of at all times
     switch (basename($_SERVER['REQUEST_URI'])) {
         case 'favicon.ico':
             # bypass WP entirely on favicon.ico
             $protocol = $_SERVER["SERVER_PROTOCOL"];
             if ('HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol) {
                 $protocol = 'HTTP/1.0';
             }
             $headers = array("{$protocol} 404 Not Found", 'Expires: Wed, 11 Jan 1984 05:00:00 GMT', 'Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT', 'Cache-Control: no-cache, must-revalidate, max-age=0', 'Pragma: no-cache', 'Content-Type: image/x-icon');
             foreach ($headers as $header) {
                 header($header, true);
             }
             die;
         case 'sitemap.xml':
         case 'sitemap.xml.gz':
             # let xml sitemap plugins cache themselves
             return;
     }
     global $sem_cache_cookies;
     if (!defined('WP_CACHE') || !WP_CACHE || isset($_GET['action']) || isset($_GET['doing_wp_cron']) || isset($_GET['debug']) || isset($_GET['preview']) || defined('WP_INSTALLING') && WP_INSTALLING || defined('WP_ADMIN') && WP_ADMIN || defined('DOING_CRON') && DOING_CRON || defined('DOING_AJAX') && DOING_AJAX || $_POST || !$sem_cache_cookies || array_intersect(array_keys($_COOKIE), (array) $sem_cache_cookies) || self::$nocache) {
         return;
     }
     global $sem_mobile_agents;
     $mobile_agents = $sem_mobile_agents;
     //		$mobile_agents = array_map('preg_quote', (array) $mobile_agents);
     $mobile_agents = implode("|", $mobile_agents);
     if (preg_match("{({$mobile_agents})}i", $_SERVER['HTTP_USER_AGENT'])) {
         return;
     }
     if (preg_match("/(?=.*?\\bandroid\\b)(?=.*?\\bmobile\\b).*\$/i", $_SERVER['HTTP_USER_AGENT'])) {
         return;
     }
     #header("Content-Type: text/plain");
     #var_dump($_SERVER);
     #die;
     # kill static cache on multisite installs
     self::$static &= !(function_exists('is_multisite') && is_multisite());
     if (self::$started || headers_sent() || !self::$static && !self::$memory) {
         return;
     }
     if (isset($_SERVER['HTTPS']) && ('on' == strtolower($_SERVER['HTTPS']) || '1' == $_SERVER['HTTPS']) || isset($_SERVER['SERVER_PORT']) && '443' == $_SERVER['SERVER_PORT']) {
         self::$host = 'https://' . $_SERVER['HTTP_HOST'];
     } else {
         self::$host = 'http://' . $_SERVER['HTTP_HOST'];
     }
     $cache_id = self::$host . preg_replace("/#.*/", '', $_SERVER['REQUEST_URI']);
     $cache_id = md5($cache_id);
     if (self::$memory) {
         $headers = wp_cache_get($cache_id, 'cached_headers');
         if ($headers !== false) {
             self::send_headers($headers);
             $buffer = wp_cache_get($cache_id, 'cached_buffers');
             if ($buffer) {
                 echo $buffer;
             }
             die;
         }
     } elseif (!(function_exists('is_multisite') && is_multisite())) {
         # poor man's memcached
         $headers = '/semi-static/' . $cache_id . '.meta';
         if (cache_fs::exists($headers, cache_timeout)) {
             $headers = unserialize(cache_fs::get_contents($headers));
             self::send_headers($headers);
             $buffer = '/semi-static/' . $cache_id . '.html';
             if (cache_fs::exists($buffer)) {
                 cache_fs::readfile($buffer);
             }
             die;
         }
     }
     self::$started = true;
     ob_start(array('static_cache', 'ob_callback'));
 }