/** * 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; }
/** * Constructor. * initializes the linx. * * @param string $type The linx type * @param string $tagContent The tag content. * @param CMS_page $page The page we're parsing * @param boolean $publicTree Does the linx must be calculated in the public or edited tree ? * @return void * @access public */ function __construct($type, $tagContent, $page, $publicTree = false, $args = array()) { if (!SensitiveIO::isInSet($type, CMS_linxesCatalog::getAllTypes())) { $this->raiseError("Constructor has an unknown type : " . $type); return; } elseif (!is_a($page, "CMS_page")) { $this->raiseError("Constructor was not given a valid CMS_page"); return; } else { $this->_args = $args; $this->_type = $type; //Hack for shorthand writing of atm-linx //<atm-linx type="direct" node="pageID"> ... </atm-linx> //<atm-linx type="direct" codename="pageCodename"> ... </atm-linx> if ((isset($this->_args['node']) || isset($this->_args['codename'])) && $this->_type == 'direct') { $tag = new CMS_XMLTag('atm-linx', $this->_args); $tag->setTextContent($tagContent); $tagContent = '<atm-linx type="direct">' . '<selection ' . (isset($this->_args['crosswebsite']) ? ' crosswebsite="' . $this->_args['crosswebsite'] . '"' : '') . '>'; if (isset($this->_args['node'])) { $tagContent .= '<start><nodespec type="node" value="' . $this->_args['node'] . '" /></start>'; //remove useless node argument unset($this->_args['node']); } else { $tagContent .= '<start><nodespec type="codename" value="' . $this->_args['codename'] . '" /></start>'; //remove useless node argument unset($this->_args['codename']); } $tagContent .= '</selection>' . '<display>' . '<htmltemplate>' . $tag->getInnerContent() . '</htmltemplate>' . '</display>' . '</atm-linx>'; } $this->_page = $page; $this->_publicTree = $publicTree; $domdocument = new CMS_DOMDocument(); try { $domdocument->loadXML($tagContent); } catch (DOMException $e) { $this->raiseError('Malformed atm-linx content in page ' . $page->getID() . ' : ' . $e->getMessage() . "\n" . $tagContent, true); return false; } $selections = $domdocument->getElementsByTagName('selection'); if ($selections->length > 0) { $selection = $selections->item(0); //parse the selection for nodespecs and condition if (!$this->_parseSelection($selection)) { $this->raiseError(); return; } } $noselections = $domdocument->getElementsByTagName('noselection'); if ($noselections->length > 0) { $this->_noselection = $noselections->item(0); } $displays = $domdocument->getElementsByTagName('display'); //get the displays objects $unsortedDisplays = array(); foreach ($displays as $display) { $unsortedDisplays[] = new CMS_linxDisplay($display); } //put the default display (the one with no condition) at the end of the array $default = false; foreach ($unsortedDisplays as $dsp) { if ($dsp->hasCondition() && !$default) { $this->_displays[] = $dsp; } else { $default = $dsp; } } if ($default) { $this->_displays[] = $default; } } }
/** * 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); }
$website = $cms_page->getWebsite(); $status = $cms_page->getStatus()->getHTML(false, $cms_user, MOD_STANDARD_CODENAME, $cms_page->getID()); $lineage = CMS_tree::getLineage($website->getRoot(), $cms_page); //Page templates replacement $pageTemplate = $cms_page->getTemplate(); //hack if page has no valid template attached if (!is_a($pageTemplate, "CMS_pageTemplate")) { $pageTemplate = new CMS_pageTemplate(); } $pageTplId = CMS_pageTemplatesCatalog::getTemplateIDForCloneID($pageTemplate->getID()); $pageTplLabel = $pageTemplate->getLabel(); //print $print = $cms_page->getPrintStatus() ? $cms_language->getMessage(MESSAGE_PAGE_FIELD_YES) : $cms_language->getMessage(MESSAGE_PAGE_FIELD_NO); //page relations $linksFrom = CMS_linxesCatalog::searchRelations(CMS_linxesCatalog::PAGE_LINK_FROM, $cms_page->getID()); $linksTo = CMS_linxesCatalog::searchRelations(CMS_linxesCatalog::PAGE_LINK_TO, $cms_page->getID()); //page redirection $redirectlink = $cms_page->getRedirectLink(); $redirectValue = ''; $module = MOD_STANDARD_CODENAME; $visualmode = RESOURCE_DATA_LOCATION_EDITED; if ($redirectlink->hasValidHREF()) { $redirect = $cms_language->getMessage(MESSAGE_PAGE_FIELD_YES) . ' ' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_TO) . ' : '; if ($redirectlink->getLinkType() == RESOURCE_LINK_TYPE_INTERNAL) { $redirectPage = new CMS_page($redirectlink->getInternalLink()); if (!$redirectPage->hasError()) { $label = $cms_language->getMessage(MESSAGE_PAGE_FIELD_PAGE) . ' "' . $redirectPage->getTitle() . '" (' . $redirectPage->getID() . ')'; } } else { $label = $redirectlink->getExternalLink(); }
/** * Regenerate alias page and all pages related to this alias * * @return string * @access protected */ protected function _regenerate() { if (($this->_replace || $this->_needRegen) && $this->_pageID) { $page = CMS_tree::getPageById($this->_pageID); if ($page && !$page->hasError()) { $regen_pages = array(); $temp_regen = CMS_linxesCatalog::getWatchers($page); if ($temp_regen) { $regen_pages = array_merge($regen_pages, $temp_regen); } $temp_regen = CMS_linxesCatalog::getLinkers($page); if ($temp_regen) { $regen_pages = array_merge($regen_pages, $temp_regen); } $regen_pages = array_unique($regen_pages); //regen page itself CMS_tree::submitToRegenerator($page->getID(), false, false); //regen all pages which link this one and lauch regeneration CMS_tree::submitToRegenerator($regen_pages, false, true); } } return true; }