Exemple #1
0
 /**
  * Regenerate the page file, either from scratch or from the linx file.
  * If linx file doesn't exists, the file is regenerated from scratch (obviously).
  *
  * @param boolean $fromScratch If false, regenerate from the linx file, otherwise regenerate linx file first.
  * @return boolean true on success, false on failure
  * @access public
  */
 function regenerate($fromScratch = false)
 {
     //regenerate don't work on pages that are not public or which not have website
     if ($this->getPublication() != RESOURCE_PUBLICATION_PUBLIC || !$this->_checkWebsite()) {
         return true;
     }
     //need pageTemplate for regeneration
     $this->_checkTemplate();
     //get linx file path
     $linxFile = new CMS_file($this->getLinxFilePath());
     //should we regenerate the linx file ?
     if ($fromScratch || !$linxFile->exists()) {
         if (!$this->_template) {
             $this->raiseError('Can\'t find page template for page ' . $this->getID());
             return false;
         }
         if (!$this->writeLinxFile()) {
             return false;
         }
         //reload linx file
         $linxFile = new CMS_file($this->getLinxFilePath());
     }
     //unregister all linxes
     CMS_linxesCatalog::deleteLinxes($this);
     //instanciate modules treatments for page linx tags
     $modulesTreatment = new CMS_modulesTags(MODULE_TREATMENT_LINXES_TAGS, PAGE_VISUALMODE_HTML_PUBLIC, $this);
     $modulesTreatment->setDefinition($linxFile->getContent());
     if ($content = $modulesTreatment->treatContent(true)) {
         $pageHTMLPath = $this->_getHTMLFilePath(PATH_RELATIVETO_FILESYSTEM) . "/" . $this->_getHTMLFilename();
         $pageFile = new CMS_file($pageHTMLPath, CMS_file::FILE_SYSTEM, CMS_file::TYPE_FILE);
         $pageFile->setContent($content);
         $pageFile->writeToPersistence();
         $this->_lastFileCreation->setNow();
         $this->writeToPersistence();
         //if the page is a website root, create the index page redirecting to this one
         if ($fromScratch && CMS_websitesCatalog::isWebsiteRoot($this->getID())) {
             CMS_websitesCatalog::writeRootRedirection();
         }
     } else {
         $this->raiseError('Malformed linx file');
         return false;
     }
     //write significant url page
     $pagePath = $this->_getFilePath(PATH_RELATIVETO_FILESYSTEM) . "/" . $this->_getFilename();
     $redirectionFile = new CMS_file($pagePath, CMS_file::FILE_SYSTEM, CMS_file::TYPE_FILE);
     $redirectionFile->setContent($this->redirectionCode($pageHTMLPath));
     $redirectionFile->writeToPersistence(true, true);
     //write website index
     if (CMS_websitesCatalog::isWebsiteRoot($this->getID())) {
         $ws = $this->getWebsite();
         if ($ws && !$ws->isMain()) {
             $wsPath = $ws->getPagesPath(PATH_RELATIVETO_FILESYSTEM) . '/index.php';
             $redirectionFile = new CMS_file($wsPath, CMS_file::FILE_SYSTEM, CMS_file::TYPE_FILE);
             $redirectionFile->setContent($this->redirectionCode($pageHTMLPath));
             $redirectionFile->writeToPersistence(true, true);
         }
     }
     //write print page if any
     if (USE_PRINT_PAGES && $this->_template->getPrintingClientSpaces()) {
         //reload linx file
         $printLinxFile = new CMS_file($this->getLinxFilePath() . '.print', CMS_file::FILE_SYSTEM, CMS_file::TYPE_FILE);
         if ($printLinxFile->exists()) {
             $modulesTreatment = new CMS_modulesTags(MODULE_TREATMENT_LINXES_TAGS, PAGE_VISUALMODE_PRINT, $this);
             $modulesTreatment->setDefinition($printLinxFile->getContent());
             if ($content = $modulesTreatment->treatContent(true)) {
                 $printHTMLPath = $this->_getHTMLFilePath(PATH_RELATIVETO_FILESYSTEM) . "/print-" . $this->_getHTMLFilename();
                 $printFile = new CMS_file($printHTMLPath);
                 $printFile->setContent($content);
                 $printFile->writeToPersistence();
             } else {
                 $this->raiseError('Malformed print linx file');
                 return false;
             }
             //write significant url print page
             $printPath = $this->_getFilePath(PATH_RELATIVETO_FILESYSTEM) . "/print-" . $this->_getFilename();
             $redirectionFile = new CMS_file($printPath);
             $redirectionFile->setContent($this->redirectionCode($printHTMLPath));
             $redirectionFile->writeToPersistence();
         } else {
             $this->raiseError('Malformed print linx file');
             return false;
         }
     }
     return true;
 }
Exemple #2
0
 /**
  * Process the daily routine unpublication part : unpublish page that needs to be
  *
  * @return void
  * @access private
  */
 protected function _dailyRoutineUnpublish()
 {
     $today = new CMS_date();
     $today->setNow();
     //process all pages that are to be unpublished
     $sql = "\n\t\t\tselect\n\t\t\t\tid_pag\n\t\t\tfrom\n\t\t\t\tpages,\n\t\t\t\tresources,\n\t\t\t\tresourceStatuses\n\t\t\twhere\n\t\t\t\tresource_pag=id_res\n\t\t\t\tand status_res=id_rs\n\t\t\t\tand location_rs='" . RESOURCE_LOCATION_USERSPACE . "'\n\t\t\t\tand publication_rs='" . RESOURCE_PUBLICATION_PUBLIC . "'\n\t\t\t\tand\t(publicationDateStart_rs > '" . $today->getDBValue(true) . "'\n\t\t\t\t\tor (publicationDateEnd_rs < '" . $today->getDBValue(true) . "' and publicationDateEnd_rs!='0000-00-00'))\n\t\t";
     $q = new CMS_query($sql);
     $unpublished = array();
     while ($id = $q->getValue("id_pag")) {
         $unpublished[] = $id;
     }
     $regen_pages = array();
     foreach ($unpublished as $page_id) {
         $page = CMS_tree::getPageByID($page_id);
         //calculate the pages to regenerate
         $temp_regen = CMS_linxesCatalog::getLinkers($page);
         if ($temp_regen) {
             $regen_pages = array_merge($regen_pages, $temp_regen);
         }
         $father = CMS_tree::getAncestor($page, 1);
         if ($father) {
             $temp_regen = CMS_linxesCatalog::getWatchers($father);
             if ($temp_regen) {
                 $regen_pages = array_merge($regen_pages, $temp_regen);
             }
         }
         //apply changes on the page
         $page->deleteFiles();
         CMS_linxesCatalog::deleteLinxes($page, true);
         CMS_tree::detachPageFromTree($page, true);
     }
     //regenerate the pages that needs to be, but first pull off the array the ids of the unpublished pages
     $regen_pages = array_unique(array_diff($regen_pages, $unpublished));
     CMS_tree::submitToRegenerator($regen_pages, false);
 }