/** * 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; }