/**
  * Overrides the standard w3sTemplateEngine constructor to render only the
  * a template without contents.
  * 
  * @param The id of the template to render
  * 
  */
 public function __construct($idTemplate, $otherTemplate)
 {
     $this->idTemplate = $idTemplate;
     $template = DbFinder::from('W3sTemplate')->with('W3sProject')->findPK($idTemplate);
     if ($template != null) {
         $this->otherTemplate = $otherTemplate;
         // Finds the current template for slot mapper, if exists
         $currentTemplate = sprintf('[%s][%s]', $idTemplate, $otherTemplate);
         $slots = DbFinder::from('W3sSlotMapper')->where('Templates', $currentTemplate)->count();
         // Current template doesn't exist
         if ($slots == 0) {
             // Checks for corrispondence, tring to invert destination with source
             $currentTemplate = sprintf('[%s][%s]', $otherTemplate, $idTemplate);
             $slots = DbFinder::from('W3sSlotMapper')->where('Templates', $currentTemplate)->count();
             if ($slots > 0) {
                 $this->currentTemplate = $currentTemplate;
             }
         } else {
             $this->currentTemplate = sprintf('[%s][%s]', $idTemplate, $otherTemplate);
         }
         $this->templateName = $template->getTemplateName();
         $this->projectName = $template->getW3sProject()->getProjectName();
         $this->pageContents = w3sCommonFunctions::readFileContents(self::getTemplateFile($this->projectName, $this->templateName));
     } else {
         $this->templateName = null;
         $this->projectName = null;
         $this->pageContents = w3sCommonFunctions::toI18n('The requested template has not been found in the database and cannot be rendered.');
     }
 }
 /** 
  * Publish all the website's pages
  */
 public function publish()
 {
     if ($this->updateDb()) {
         // Deletes the old directory with the previous published version
         w3sCommonFunctions::clearDirectory(sfConfig::get('app_w3s_web_published_dir'), array('.svn'));
         // Retrieves all the website's languages and pages from the database
         $languages = DbFinder::from('W3sLanguage')->find();
         $pages = DbFinder::from('W3sPage')->with('W3sTemplate', 'W3sProject')->leftJoin('W3sGroup')->leftJoin('W3sTemplate')->leftJoin('W3sProject')->find();
         // Cycles all the website's languages
         foreach ($languages as $language) {
             // Creates the directory for the lanugage if doesn't exists
             if (!is_dir(sfConfig::get('app_w3s_web_published_dir') . '/' . $language->getLanguage())) {
                 mkdir(sfConfig::get('app_w3s_web_published_dir') . '/' . $language->getLanguage());
             }
             // Cycles all the website's pages
             foreach ($pages as $page) {
                 // Retrieves the information needed to publish every single page
                 $pageContents = '';
                 $templateInfo = self::retrieveTemplateAttributesFromPage($page);
                 $pageContents = w3sCommonFunctions::readFileContents(self::getTemplateFile($templateInfo["projectName"], $templateInfo["templateName"]));
                 $this->idTemplate = $templateInfo["idTemplate"];
                 // Renders ther page
                 $slotContents = $this->getSlotContents($language->getId(), $page->getId());
                 foreach ($slotContents as $slot) {
                     $contents = $this->drawSlot($slot);
                     $pageContents = preg_replace('/\\<\\?php.*?include_slot\\(\'' . $slot['slotName'] . '\'\\).*?\\?\\>/', $contents, $pageContents);
                     /*$pageContents = str_replace('<?php include_slot(\'' . $slot['slotName'] . '\')?>', $contents, $pageContents);*/
                 }
                 // Renders the W3StudioCMS Copyright button. Please do not remove. See the function
                 // declaration to learn the best way to implement it in your web site.
                 // Thank you
                 $pageContents = $this->renderCopyright($pageContents);
                 // Writes the page
                 $handle = fopen(sfConfig::get('app_w3s_web_published_dir') . '/' . $language->getLanguage() . '/' . $page->getPageName() . '.php', "w");
                 fwrite($handle, $pageContents);
                 fclose($handle);
             }
         }
     } else {
         return 0;
     }
     return 1;
 }
Exemplo n.º 3
0
 /**
  * Adds a page and inserts default contents where content is available
  *
  * @param  string The name of the page to save
  * @param  int The id of the related group
  * 
  * @return int 0 - The save operation failed
  *             1 - Success
  *             2 - Page already exists
  */
 public function add($pageName, $idGroup)
 {
     try {
         $pageName = trim($pageName);
         if ($pageName != '') {
             // Checks if page already exists
             $pageName = w3sCommonFunctions::slugify($pageName);
             $oPage = W3sPagePeer::getFromPageName($pageName);
             if ($oPage == null) {
                 if ($idGroup != null) {
                     if (DbFinder::from('W3sGroup')->findPK($idGroup) != null) {
                         $con = Propel::getConnection();
                         // We assure that all the operations W3StudioCMS makes will be successfully done
                         $rollBack = false;
                         $con = w3sPropelWorkaround::beginTransaction($con);
                         // Save page
                         $this->page->setGroupId($idGroup);
                         $this->page->setPageName($pageName);
                         $result = $this->page->save();
                         if ($this->page->isModified() && $result == 0) {
                             $rollBack = true;
                         } else {
                             // Getting the page's id inserted yet
                             $idPage = $this->page->getId();
                             $attributes = w3sTemplateEngine::retrieveTemplateAttributesFromPage($this->page);
                             $templateContents = w3sCommonFunctions::readFileContents(sprintf("%1\$s%2\$s%3\$s%2\$sdata%2\$s%4\$s.yml", sfConfig::get('app_w3s_web_themes_dir'), DIRECTORY_SEPARATOR, $attributes["projectName"], $attributes["templateName"]));
                             $defaultContents = sfYaml::load($templateContents);
                             $defaultContents = $defaultContents["W3sContent"];
                             // Inserts the contents for every language
                             $oLanguages = DbFinder::from('W3sLanguage')->where('ToDelete', '0')->find();
                             foreach ($oLanguages as $language) {
                                 $idLanguage = $language->getId();
                                 // Cycles the slot's three repeated contents status
                                 for ($i = 0; $i <= 2; $i++) {
                                     // Retrieve the slots with the $i status for the page's template
                                     $slots = W3sSlotPeer::getTemplateSlots($attributes["idTemplate"], $i);
                                     foreach ($slots as $slot) {
                                         // Retrieves a content that belongs to the current slot
                                         $baseContent = DbFinder::from('W3sContent')->where('SlotId', $slot->getId())->where('LanguageId', $idLanguage)->findOne();
                                         // When no repeated content, the content is simply copied
                                         if ($slot->getRepeatedContents() == 0 || $baseContent == null) {
                                             $slotName = $slot->getSlotName();
                                             foreach ($defaultContents as $defaultContent) {
                                                 if ($defaultContent['slotId'] == $slotName) {
                                                     $content = w3sContentManagerFactory::create($defaultContent["contentTypeId"]);
                                                     $contentValue = array("PageId" => $idPage, "SlotId" => $slot->getId(), "LanguageId" => $idLanguage, "GroupId" => $idGroup, "Content" => $defaultContent["content"], "ContentTypeId" => $defaultContent["contentTypeId"], "ContentPosition" => $defaultContent["contentPosition"], "Edited" => 1);
                                                     $content->setUpdateForeigns(false);
                                                     $content->add($contentValue);
                                                 }
                                             }
                                         } else {
                                             // Retrive base page, if any, but NOT current one
                                             $pageFinder = DbFinder::from('W3sPage')->whereToDelete(0)->whereIdNot($idPage);
                                             if ($basePage = $pageFinder->findOne()) {
                                                 // Retrieve a content that belongs to the current slot
                                                 $baseContents = DbFinder::from('W3sContent')->whereToDelete(0)->relatedTo($basePage)->relatedTo($slot)->whereLanguageId($idLanguage)->find();
                                                 foreach ($baseContents as $baseContent) {
                                                     // Creates a new content from the base content
                                                     $newContent = w3sContentManagerFactory::create($baseContent->getContentTypeId(), $baseContent);
                                                     // Converts the content in array and changes the page's id and the group's id
                                                     $contentValue = W3sContentPeer::contentToArray($newContent->getContent());
                                                     $contentValue["PageId"] = $idPage;
                                                     $contentValue["GroupId"] = $idGroup;
                                                     // Updates the content and copies the related elements
                                                     $newContent->setUpdateForeigns(false);
                                                     $newContent->add($contentValue);
                                                     w3sContentManagerMenuPeer::copyRelatedElements($baseContent->getId(), $newContent->getContent()->getId());
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                         if (!$rollBack) {
                             // Everything was fine so W3StudioCMS commits to database
                             $con->commit();
                             $result = 1;
                         } else {
                             // Something was wrong so W3StudioCMS aborts the operation and restores to previous status
                             w3sPropelWorkaround::rollBack($con);
                             $result = 0;
                         }
                     } else {
                         $result = 16;
                     }
                 } else {
                     $result = 8;
                 }
             } else {
                 $result = 2;
             }
         } else {
             $result = 4;
         }
     } catch (Exception $e) {
         w3sPropelWorkaround::rollBack($con);
         $result = 0;
         sfContext::getInstance()->getLogger()->info("W3StudioCMS - An Error occoured while addin a language. The exception message is:\n" . $e->getMessage() . "\n");
     }
     return $result;
 }
Exemplo n.º 4
0
 protected function getSlotsFromTemplate($themeName, $templateName)
 {
     $templateFile = sprintf("%1\$s%2\$s%3\$s%2\$stemplates%2\$s%4\$s.php", sfConfig::get('app_w3s_web_themes_dir'), DIRECTORY_SEPARATOR, $themeName, $templateName);
     $contents = w3sCommonFunctions::readFileContents($templateFile);
     preg_match_all('/include_slot\\s*\\(\\s*[\'|"](.*?)[\'|"]\\s*\\)/', $contents, $matchResults);
     return $matchResults[1];
 }
Exemplo n.º 5
0
 /**
  * Retrieves from the database the template associated to page requested
  * 
  * @return object  The retrieved page
  *
  */
 protected function setCurrentTemplate($page)
 {
     if ($page != null) {
         $templateInfo = self::retrieveTemplateAttributesFromPage($page);
         $this->idTemplate = $templateInfo["idTemplate"];
         $this->templateName = $templateInfo["templateName"];
         $this->projectName = $templateInfo["projectName"];
         $this->pageContents = w3sCommonFunctions::readFileContents(self::getTemplateFile($this->projectName, $this->templateName));
     }
 }