예제 #1
0
 public static function getCachedPage()
 {
     $key = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
     if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
         $key = 'SECURE_' . $key;
     }
     //get params from config to exclude from url key
     $config = simplexml_load_file('app/etc/local.xml');
     $excludes = array();
     $excludeParams = $config->lightspeed->global->params;
     $excludeArr = explode(",", $excludeParams);
     foreach ($excludeArr as $param) {
         $excludes[] = $param;
     }
     //see if we even need to remove some params
     if (count($excludes)) {
         //if we do, blow it up and remake it
         $keyPart = explode("?", $key);
         if (isset($keyPart[1])) {
             $keyParse = parse_url($key);
             $newParams = explode("&", $keyParse['query']);
             $newString = '?';
             foreach ($newParams as $iteration => $newParam) {
                 $paramArr = explode("=", $newParam);
                 if (!in_array($paramArr[0], $excludes)) {
                     $newString .= $paramArr[0] . "=" . $paramArr[1] . "&";
                 }
                 $key = $keyPart[0] . $newString;
                 $key = rtrim($key, "&");
                 $key = preg_replace('/(\\?|&|&&)debug_front=1/s', '', $key);
             }
         }
     } else {
         $key = preg_replace('/(\\?|&|&&)debug_front=1/s', '', $key);
     }
     if (self::$multiCurrency) {
         self::report("configuration set to use multi_currency");
         $key .= '_' . self::getCurrencyCode();
     }
     self::report("attempting to fetch url: {$key}");
     if ($data = self::get($key)) {
         if (self::messageExists()) {
             self::report("a global message exists, we must not allow a cached page", true);
             return false;
         }
         if (isset($data[1]) && $data[1]) {
             $disqualified = false;
             if ($data[1] == '*') {
                 // auto disqualify when messages exist in the session
                 self::report("disqualified because the disqualifier is *");
                 $disqualified = true;
             } else {
                 self::initConditions();
                 $disqualifiers = explode(",", $data[1]);
                 if ($count = count($disqualifiers)) {
                     for ($i = 0; $i < $count; $i++) {
                         if (in_array($disqualifiers[$i], self::$conditions)) {
                             self::report("disqualified with {$disqualifiers[$i]}");
                             $disqualified = true;
                             break 1;
                         }
                     }
                 }
             }
             if ($disqualified) {
                 // handle dynamic content retrieval here
                 if (isset($data[2]) && $data[2]) {
                     self::report("attempting to retrieve hole punched content from {$data[2]}");
                     $_SERVER['REQUEST_URI'] = self::$request_path . "/" . $data[2];
                     require_once 'app/Mage.php';
                     ob_start();
                     //Single Site
                     if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
                         $_SERVER['HTTPS'] = 'on';
                         $_SERVER['SERVER_PORT'] = 443;
                     }
                     Mage::run();
                     //Multi-site test settings
                     // Add a "case" statement for each new site
                     // switch($_SERVER['HTTP_HOST']) {
                     //   case 'www.site1.com':
                     //     Mage::run('site1', 'website');
                     //     break;
                     //
                     //   case 'www.site2.com':
                     //     Mage::run('site2', 'website');
                     //     break;
                     //
                     //   default:
                     //     Mage::run();
                     //     break;
                     //End Multi-site Config
                     $content = ob_get_clean();
                     self::$holeContent = Zend_Json::decode($content);
                     return self::fillNoCacheHoles($data[0]);
                 } else {
                     self::report("valid disqualifiers without hole punch content... bummer", true);
                     return false;
                 }
             } else {
                 return $data[0];
             }
         } else {
             return $data[0];
         }
     } else {
         self::report("No match found in the cache store", true);
         return false;
     }
 }