Пример #1
0
 /**
  * The process() method handles the "meat" of the template processing.
  */
 public function process($item)
 {
     SSViewer::$topLevel = $item;
     if (isset($this->chosenTemplates['main'])) {
         $template = $this->chosenTemplates['main'];
     } else {
         $template = $this->chosenTemplates[reset($dummy = array_keys($this->chosenTemplates))];
     }
     if (isset($_GET['debug_profile'])) {
         Profiler::mark("SSViewer::process", " for {$template}");
     }
     $cacheFile = TEMP_FOLDER . "/.cache" . str_replace(array('\\', '/', ':'), '.', realpath($template));
     $lastEdited = filemtime($template);
     if (!file_exists($cacheFile) || filemtime($cacheFile) < $lastEdited || isset($_GET['flush'])) {
         if (isset($_GET['debug_profile'])) {
             Profiler::mark("SSViewer::process - compile", " for {$template}");
         }
         $content = file_get_contents($template);
         $content = SSViewer::parseTemplateContent($content, $template);
         $fh = fopen($cacheFile, 'w');
         fwrite($fh, $content);
         fclose($fh);
         if (isset($_GET['debug_profile'])) {
             Profiler::unmark("SSViewer::process - compile", " for {$template}");
         }
     }
     if (isset($_GET['showtemplate']) && !Director::isLive()) {
         $lines = file($cacheFile);
         echo "<h2>Template: {$cacheFile}</h2>";
         echo "<pre>";
         foreach ($lines as $num => $line) {
             echo str_pad($num + 1, 5) . htmlentities($line);
         }
         echo "</pre>";
     }
     foreach (array('Content', 'Layout') as $subtemplate) {
         if (isset($this->chosenTemplates[$subtemplate])) {
             $subtemplateViewer = new SSViewer($this->chosenTemplates[$subtemplate]);
             $item = $item->customise(array($subtemplate => $subtemplateViewer->process($item)));
         }
     }
     $itemStack = array();
     $val = "";
     include $cacheFile;
     $output = $val;
     $output = Requirements::includeInHTML($template, $output);
     SSViewer::$topLevel = null;
     if (isset($_GET['debug_profile'])) {
         Profiler::unmark("SSViewer::process", " for {$template}");
     }
     // If we have our crazy base tag, then fix # links referencing the current page.
     if (strpos($output, '<base') !== false) {
         $thisURLRelativeToBase = Director::makeRelative(Director::absoluteURL($_SERVER['REQUEST_URI']));
         $output = preg_replace('/(<a[^>+]href *= *")#/i', '\\1' . $thisURLRelativeToBase . '#', $output);
     }
     return $output;
 }
Пример #2
0
 /**
  * Returns the top level ViewableData being rendered.
  * @return ViewableData
  */
 function Top()
 {
     return SSViewer::topLevel();
 }