/**
  * Renders the given page and sends the result to the standard output.
  */
 public function render()
 {
     $pieCrust = $this->page->getApp();
     $pageConfig = $this->page->getConfig();
     // Get the template name.
     $templateName = $this->page->getConfig()->getValue('layout');
     if ($templateName == null or $templateName == '' or $templateName == 'none') {
         $templateName = false;
     } else {
         if (!preg_match('/\\.[a-zA-Z0-9]+$/', $templateName)) {
             $templateName .= '.html';
         }
     }
     if ($templateName !== false) {
         // Get the template engine and the page data.
         $extension = pathinfo($templateName, PATHINFO_EXTENSION);
         $templateEngine = PieCrustHelper::getTemplateEngine($pieCrust, $extension);
         // Render the page.
         $data = DataBuilder::getTemplateRenderingData($this->page);
         $templateEngine->renderFile($templateName, $data);
     } else {
         // No template... just output the 'content' segment.
         echo $this->page->getContentSegment();
     }
     if ($pieCrust->isDebuggingEnabled()) {
         // Add a footer with version, caching and timing information.
         $this->renderStatsFooter($this->page);
     }
 }
Exemple #2
0
 /**
  * Renders the given page and sends the result to the standard output.
  */
 public function render()
 {
     $pieCrust = $this->page->getApp();
     $pageConfig = $this->page->getConfig();
     // Set the page as the current context.
     $executionContext = $pieCrust->getEnvironment()->getExecutionContext(true);
     $executionContext->pushPage($this->page);
     // Get the template name.
     $templateNames = $this->page->getConfig()->getValue('layout');
     if ($templateNames == null or $templateNames == '' or $templateNames == 'none') {
         $templateNames = false;
     } else {
         $templateNames = explode(',', $templateNames);
         foreach ($templateNames as &$name) {
             if (!preg_match('/\\.[a-zA-Z0-9]+$/', $name)) {
                 $name .= '.html';
             }
         }
     }
     if ($templateNames !== false) {
         // Get the template engine and the page data.
         $extension = pathinfo($templateNames[0], PATHINFO_EXTENSION);
         $templateEngine = PieCrustHelper::getTemplateEngine($pieCrust, $extension);
         // Render the page.
         $data = DataBuilder::getTemplateRenderingData($this->page);
         $templateEngine->renderFile($templateNames, $data);
     } else {
         // No template... just output the 'content' segment.
         echo $this->page->getContentSegment();
     }
     // Restore the previous context.
     $executionContext->popPage();
 }
 /**
  * Gets all the template data for rendering a page's contents.
  */
 public static function getPageRenderingData(IPage $page)
 {
     $pageData = $page->getPageData();
     $siteData = self::getSiteData($page);
     $appData = DataBuilder::getAppData($page->getApp(), $siteData, $pageData, null, false);
     $renderData = Configuration::mergeArrays($pageData, $siteData, $appData);
     return $renderData;
 }
Exemple #4
0
 /**
  * Gets the data used for rendering the page.
  */
 public function getPageData()
 {
     if ($this->pageData == null) {
         $this->pageData = DataBuilder::getPageData($this);
     }
     return $this->pageData;
 }
 protected function formatContentsUnsafe(array $rawSegments)
 {
     $data = DataBuilder::getPageRenderingData($this->page);
     $pieCrust = $this->page->getApp();
     $templateEngineName = $this->page->getConfig()->getValue('template_engine');
     $templateEngine = PieCrustHelper::getTemplateEngine($pieCrust, $templateEngineName);
     if (!$templateEngine) {
         throw new PieCrustException("Unknown template engine '{$templateEngineName}'.");
     }
     $contents = array();
     foreach ($rawSegments as $key => $pieces) {
         $contents[$key] = '';
         foreach ($pieces as $piece) {
             $content = $piece['content'];
             $format = $piece['format'];
             ob_start();
             try {
                 $templateEngine->renderString($content, $data);
                 $renderedContent = ob_get_clean();
             } catch (Exception $e) {
                 ob_end_clean();
                 throw $e;
             }
             if (!$format) {
                 $format = $this->page->getConfig()->getValue('format');
             }
             $renderedAndFormattedContent = PieCrustHelper::formatText($pieCrust, $renderedContent, $format);
             $contents[$key] .= $renderedAndFormattedContent;
         }
     }
     if (!empty($contents['content'])) {
         $matches = array();
         if (preg_match('/^<!--\\s*(more|(page)?break)\\s*-->\\s*$/m', $contents['content'], $matches, PREG_OFFSET_CAPTURE)) {
             // Add a special content segment for the "intro/abstract" part
             // of the article.
             $offset = $matches[0][1];
             $abstract = substr($contents['content'], 0, $offset);
             $this->page->getConfig()->appendValue('segments', 'content.abstract');
             $contents['content.abstract'] = $abstract;
         }
     }
     return $contents;
 }
Exemple #6
0
 public function testSiteWithPageAssets()
 {
     $fs = MockFileSystem::create()->withPage('foo', array(), '')->withPageAsset('foo', 'bar1')->withPageAsset('foo', 'bar2')->withPage('something-assets', array(), '');
     $pc = $fs->getApp();
     $page = Page::createFromUri($pc, '/foo', false);
     $data = DataBuilder::getSiteData($page);
     $linker = $data['site']->pages();
     $this->assertLinkerIsPagesArray($linker, array($this->makeLinkData('foo', '/?/foo', true), $this->makeLinkData('something-assets', '/?/something-assets')));
     $page = Page::createFromUri($pc, '/something-assets', false);
     $data = DataBuilder::getSiteData($page);
     $linker = $data['site']->pages();
     $this->assertLinkerIsPagesArray($linker, array($this->makeLinkData('foo', '/?/foo'), $this->makeLinkData('something-assets', '/?/something-assets', true)));
 }