/** * Duplicate current page into another one * All contents and external datas are duplicated too * * @param CMS_user user, the user processing to creation * @param integer templateID, a new template to duplicate the page with * @param boolean $dontDuplicateContent If true, the content of the page is not duplicated * @return CMS_page newly created, or null on error */ function duplicate(&$user, $templateID = 0, $dontDuplicateContent = false) { $pg = null; if ($user->hasPageClearance($this->getID(), CLEARANCE_PAGE_VIEW) && $user->hasModuleClearance(MOD_STANDARD_CODENAME, CLEARANCE_MODULE_EDIT)) { $pg = new CMS_page(); $pg->lock($user); $pg->addEdition(RESOURCE_EDITION_CONTENT, $user); //Which template to use? if (!$templateID) { $newTpl = CMS_pageTemplatesCatalog::getCloneFromID($this->_templateID, false, true, false, $this->_templateID); } else { $newTpl = CMS_pageTemplatesCatalog::getCloneFromID($templateID, false, true, false, $this->_templateID); } if (!is_a($newTpl, 'CMS_pageTemplate') || $newTpl->hasError()) { $this->raiseError("Error during template clone creation."); } else { $pg->setTemplate($newTpl->getID()); } //Duplicate page base datas $pg->setTitle($this->getTitle(), $user); $pg->setLinkTitle($this->getLinkTitle(), $user); $pg->setDescription($this->getDescription(false, false), $user); $pg->setKeywords($this->getKeywords(false, false), $user); $pg->setPublicationDates($this->getPublicationDateStart(false), $this->getPublicationDateEnd(false)); $pg->setReminderOn($this->getReminderOn(false, false), $user); $pg->setReminderOnMessage($this->getReminderOnMessage(false, false), $user); $pg->setCategory($this->getCategory(false, false), $user); $pg->setAuthor($this->getAuthor(false, false), $user); $pg->setReplyto($this->getReplyto(false, false), $user); $pg->setCopyright($this->getCopyright(false, false), $user); $pg->setLanguage($this->getLanguage(false, false), $user); $pg->setRobots($this->getRobots(false, false), $user); $pg->setPragma($this->getPragma(false, false), $user); $pg->setRefresh($this->getRefresh(false, false), $user); $pg->setRedirectLink($this->getRedirectLink(), $user); $pg->setMetas($this->getMetas(false, false), $user); $pg->setCodename($this->getCodename(), $user, false); if (SensitiveIO::isPositiveInteger($this->getReminderPeriodicity())) { $pg->setReminderPeriodicity($this->getReminderPeriodicity(), $user); } $pg->writeToPersistence(); $pg->unlock(); //Duplicate contents, get all blocks and duplicate them if (!$dontDuplicateContent) { $this->duplicateContent($user, $pg); } } else { $this->raiseError("User doesn't have rights to do this creation"); } return $pg; }
$cms_message = $cms_language->getMessage(MESSAGE_PAGE_ERROR_CREATION); break; } if (!$cms_user->hasPageClearance($father, CLEARANCE_PAGE_EDIT)) { $cms_message = $cms_language->getMessage(MESSAGE_PAGE_ERROR_FATHER_PAGE); break; } //must set the lastReminder to today $cms_page->touchLastReminder(); $cms_page->setTitle($title, $cms_user); if ($linktitle) { $cms_page->setLinkTitle($linktitle, $cms_user); } else { $cms_page->setLinkTitle($title, $cms_user); } $cms_page->writeToPersistence(); //create page, attach it to the tree CMS_tree::attachPageToTree($cms_page, $cms_father, false); //clone the template $pageTpl = CMS_pageTemplatesCatalog::getCloneFromID($template, false, true, $emptytpl); if ($cms_page->setTemplate($pageTpl->getID())) { $cms_page->writeToPersistence(); //goto copied page $jscontent = ' Automne.utils.getPageById(' . $cms_page->getID() . ', \'edit\'); '; $view->addJavascript($jscontent); } else { CMS_grandFather::raiseError('Page creation : Can\'t set page template : ' . $pageTpl->getID() . ' ...'); $cms_message = $cms_language->getMessage(MESSAGE_PAGE_ERROR_CREATION); }