Exemplo n.º 1
0
 public final function __toString()
 {
     $catchMeta = Patchwork::$catchMeta;
     Patchwork::$catchMeta = true;
     if ($this->loopLength === false) {
         $this->loopLength = (int) $this->prepare();
     }
     Patchwork::$catchMeta = $catchMeta;
     return (string) $this->loopLength;
 }
Exemplo n.º 2
0
 protected static function render($agentClass)
 {
     p::openMeta($agentClass);
     $a = self::$args;
     $g = self::$get;
     $agent = new $agentClass($_GET);
     $group = p::closeGroupStage();
     $is_cacheable = !in_array('private', $group);
     $cagent = p::agentCache($agentClass, $agent->get, 'ser', $group);
     $filter = false;
     if (isset(self::$cache[$cagent])) {
         $cagent =& self::$cache[$cagent];
         $v = clone $cagent[0];
         $template = $cagent[1];
     } else {
         if (!($is_cacheable && (list($v, $template) = self::getFromCache($cagent)))) {
             ob_start();
             ++p::$ob_level;
             $v = (object) $agent->compose((object) array());
             if (!p::$is_enabled) {
                 p::closeMeta();
                 return;
             }
             $template = $agent->getTemplate();
             if (!p::$binaryMode) {
                 foreach ($v as &$h) {
                     is_string($h) && ($h = htmlspecialchars($h));
                 }
                 unset($h);
             }
             $filter = true;
             $rawdata = ob_get_flush();
             --p::$ob_level;
         }
         isset(p::$headers['content-type']) || p::header('Content-Type: text/html');
         $vClone = clone $v;
     }
     p::$catchMeta = false;
     self::$values = $v->{'$'} = $v;
     $ctemplate = p::getContextualCachePath('templates/' . $template, (p::$binaryMode ? 'bin' : 'html') . '.php');
     $ftemplate = 'template' . md5($ctemplate);
     p::$lockedContentType = true;
     if (function_exists($ftemplate)) {
         $ftemplate($v, $a, $g);
     } else {
         Superloader::$turbo || p::syncTemplate($template, $ctemplate);
         if ($h = p::fopenX($ctemplate)) {
             opcache_reset();
             p::openMeta('agent__template/' . $template, false);
             $compiler = new \ptlCompiler_php($template, p::$binaryMode);
             $ftemplate = "<?php function {$ftemplate}(&\$v,&\$a,&\$g){global \$a�,\$c�;\$d=\$v;" . $compiler->compile() . "} {$ftemplate}(\$v,\$a,\$g);";
             fwrite($h, $ftemplate);
             flock($h, LOCK_UN);
             fclose($h);
             list(, , , $watch) = p::closeMeta();
             p::writeWatchTable($watch, $ctemplate);
         }
         require $ctemplate;
     }
     if ($filter) {
         p::$catchMeta = true;
         $agent->metaCompose();
         list($maxage, $group, $expires, $watch, $headers, $canPost) = p::closeMeta();
         if ('ontouch' === $expires && !$watch) {
             $expires = 'auto';
         }
         $expires = 'auto' === $expires && $watch ? 'ontouch' : 'onmaxage';
         p::setExpires($expires);
         if ($is_cacheable && 'POST' !== $_SERVER['REQUEST_METHOD'] && !in_array('private', $group) && ($maxage || 'ontouch' === $expires)) {
             $fagent = $cagent;
             if ($canPost) {
                 $fagent = substr($cagent, 0, -4) . '.post' . substr($cagent, -4);
             }
             if ($h = p::fopenX($fagent)) {
                 $rawdata = array('rawdata' => $rawdata, 'v' => array());
                 self::freezeAgent($rawdata['v'], $vClone);
                 $rawdata['template'] = $template;
                 $rawdata['maxage'] = $maxage;
                 $rawdata['expires'] = $expires;
                 $rawdata['watch'] = $watch;
                 $rawdata['headers'] = $headers;
                 $rawdata = serialize($rawdata);
                 fwrite($h, $rawdata);
                 flock($h, LOCK_UN);
                 fclose($h);
                 touch($fagent, $_SERVER['REQUEST_TIME'] + ('ontouch' === $expires ? $CONFIG['maxage'] : $maxage));
                 p::writeWatchTable($watch, $fagent);
             }
         }
     } else {
         p::closeMeta();
     }
     if (isset($vClone)) {
         self::$cache[$cagent] = array($vClone, $template);
     }
 }