function handleResourceData($tpl, $handler, &$resourceData, $method, &$extraParameters)
 {
     // &$templateRoot, &$text, &$tstamp, $uri, $resourceName, &$path, &$keyData
     $templateRoot =& $resourceData['root-node'];
     $text =& $resourceData['text'];
     $tstamp =& $resourceData['time-stamp'];
     $uri =& $resourceData['uri'];
     $resourceName =& $resourceData['resource'];
     $path =& $resourceData['template-filename'];
     $keyData =& $resourceData['key-data'];
     $localeData =& $resourceData['locales'];
     if (!file_exists($path)) {
         return false;
     }
     $tstamp = filemtime($path);
     $result = false;
     $canCache = true;
     $templateRoot = null;
     if (!$handler->servesStaticData()) {
         $canCache = false;
     }
     if (!$tpl->isCachingAllowed()) {
         $canCache = false;
     }
     $keyData = 'file:' . $path;
     if ($method == eZTemplate::RESOURCE_FETCH) {
         if ($canCache) {
             if ($handler->hasCompiledTemplate($keyData, $uri, $resourceData, $path, $extraParameters, $tstamp)) {
                 $resourceData['compiled-template'] = true;
                 return true;
             }
         }
         if ($canCache) {
             $templateRoot = $handler->cachedTemplateTree($keyData, $uri, $resourceName, $path, $extraParameters, $tstamp);
         }
         if ($templateRoot !== null) {
             return true;
         }
         if (is_readable($path)) {
             $text = file_get_contents($path);
             $text = preg_replace("/\n|\r\n|\r/", "\n", $text);
             $tplINI = $tpl->ini();
             $charset = $tplINI->variable('CharsetSettings', 'DefaultTemplateCharset');
             $locales = array();
             $pos = strpos($text, "\n");
             if ($pos !== false) {
                 $line = substr($text, 0, $pos);
                 if (preg_match("/^\\{\\*\\?template(.+)\\?\\*\\}/", $line, $tpl_arr)) {
                     $args = explode(" ", trim($tpl_arr[1]));
                     foreach ($args as $arg) {
                         $vars = explode('=', trim($arg));
                         switch ($vars[0]) {
                             case 'charset':
                                 $val = $vars[1];
                                 if ($val[0] == '"' and strlen($val) > 0 and $val[strlen($val) - 1] == '"') {
                                     $val = substr($val, 1, strlen($val) - 2);
                                 }
                                 $charset = $val;
                                 break;
                             case 'locale':
                                 $val = $vars[1];
                                 if ($val[0] == '"' and strlen($val) > 0 and $val[strlen($val) - 1] == '"') {
                                     $val = substr($val, 1, strlen($val) - 2);
                                 }
                                 $locales = explode(',', $val);
                                 break;
                         }
                     }
                 }
             }
             /* Setting locale to allow standard PHP functions to handle
              * strtoupper/lower() */
             $defaultLocale = trim($tplINI->variable('CharsetSettings', 'DefaultTemplateLocale'));
             if ($defaultLocale != '') {
                 $locales = array_merge($locales, explode(',', $defaultLocale));
             }
             $localeData = $locales;
             if ($locales && count($locales)) {
                 setlocale(LC_CTYPE, $locales);
             }
             if (eZTemplate::isDebugEnabled()) {
                 eZDebug::writeNotice("{$path}, {$charset}");
             }
             $codec = eZTextCodec::instance($charset, false, false);
             if ($codec) {
                 eZDebug::accumulatorStart('template_resource_conversion', 'template_total', 'String conversion in template resource');
                 $text = $codec->convertString($text);
                 eZDebug::accumulatorStop('template_resource_conversion');
             }
             $result = true;
         }
     } else {
         if ($method == eZTemplate::RESOURCE_QUERY) {
             $result = true;
         }
     }
     return $result;
 }
Beispiel #2
0
 function resourceFor($uri, &$res, &$template)
 {
     $args = explode(":", $uri);
     if (isset($args[1])) {
         $res = $args[0];
         $template = $args[1];
     } else {
         $template = $uri;
     }
     if (eZTemplate::isDebugEnabled()) {
         eZDebug::writeNotice("eZTemplate: Loading template \"{$template}\" with resource \"{$res}\"");
     }
     if (isset($this->Resources[$res]) and is_object($this->Resources[$res])) {
         return $this->Resources[$res];
     }
     return $this->DefaultResource;
 }