Пример #1
0
 public function renderSitePage(Theme $theme, Site $site, $pageName, $language = null)
 {
     // TODO: Verify if $language is a supported language
     $context = new Context();
     $context->setLanguage($language);
     $context->setTheme($theme);
     // Load all site-wide contents into the context
     foreach ($site->getContents() as $content) {
         $context->addContent($content);
     }
     $page = $site->getPageByName($pageName);
     // Load all page-wide contents into the context
     foreach ($page->getContents() as $content) {
         $context->addContent($content);
     }
     if (!$page) {
         throw new RuntimeException("No such page in site: " . $pageName);
     }
     foreach ($page->getPropertiesByLanguage($language) as $property) {
         $context->setProperty($property);
     }
     $templateName = $page->getTemplate();
     $templateFilename = $theme->getBasePath() . '/code/' . $templateName;
     $data = file_get_contents($templateFilename);
     $data = $this->processTags($data, $context);
     $data = $this->processProperties($data, $context);
     //echo "\n##FINAL:##\n" . $data; exit('boom');
     return $data;
 }
Пример #2
0
 public function load($filename)
 {
     $site = new Site();
     $xml = file_get_contents($filename);
     $rootNode = new SimpleXMLElement($xml);
     $site->setName((string) $rootNode['name']);
     $this->loadContents($rootNode->content, $site);
     foreach ($rootNode->page as $pageNode) {
         $page = new Page();
         $page->setName((string) $pageNode['name']);
         $page->setUrl((string) $pageNode['url']);
         $page->setTemplate((string) $pageNode['template']);
         $this->loadProperties($pageNode->property, $page);
         $this->loadContents($pageNode->content, $page);
         $site->addPage($page);
     }
     return $site;
 }