示例#1
0
 /** Handle the processing of the es-cache template function.
  * @see process()
  */
 private function processESCacheFunction($tpl, &$textElements, $functionName, $functionChildren, $functionParameters, $functionPlacement, $rootNamespace, $currentNamespace)
 {
     if (isset($functionParameters['ttl'])) {
         $ttl = $tpl->elementValue($functionParameters['ttl'], $rootNamespace, $currentNamespace, $functionPlacement);
         $parts = array();
         if (!preg_match('/^(\\d+\\.?\\d*|\\.\\d+)\\s*([a-z]?)$/', $ttl, $parts)) {
             $tpl->warning($this->ESCacheName, 'Invalid TTL: ' . $ttl, $functionPlacement);
         } else {
             $ttl = $parts[1];
             // NOTE: This switch uses fall-through on purpose.
             switch ($parts[2]) {
                 case 'w':
                     $ttl *= 7;
                     // weeks
                 // weeks
                 case 'd':
                     $ttl *= 24;
                     // days
                 // days
                 case 'h':
                     $ttl *= 60;
                     // hours
                 // hours
                 case 'm':
                     $ttl *= 60;
                     // minutes
                 // minutes
                 case '':
                     // Empty unit is defaulted to seconds.
                 // Empty unit is defaulted to seconds.
                 case 's':
                     // $ttl *= 1; // seconds
                     break;
                 default:
                     $tpl->warning($this->ESCacheName, 'Unknown unit on TTL, assuming seconds: ' . $parts[2], $functionPlacement);
                     break;
             }
             // Ensure we have an integer number of seconds.
             $ttl = round($ttl);
             nxcESIEAS::setMaxAge($ttl);
         }
     }
     if (isset($functionParameters['no-store'])) {
         $noStore = $tpl->elementValue($functionParameters['no-store'], $rootNamespace, $currentNamespace, $functionPlacement);
         if (!is_bool($noStore)) {
             $tpl->warning($this->ESCacheName, 'Non-boolean value given to no-store', $functionPlacement);
         } else {
             nxcESIEAS::setNoStore($noStore);
         }
     }
     if (isset($functionParameters['no-store-remote'])) {
         $noStore = $tpl->elementValue($functionParameters['no-store-remote'], $rootNamespace, $currentNamespace, $functionPlacement);
         if (!is_bool($noStore)) {
             $tpl->warning($this->ESCacheName, 'Non-boolean value given to no-store-remote', $functionPlacement);
         } else {
             nxcESIEAS::setNoStoreRemote($noStore);
         }
     }
     return true;
 }