Example #1
0
 /**
  * Sets the codename base data.
  *
  * @param string $data The new base data to set
  * @param CMS_profile_user &$user the user who did the edition
  * @param boolean $checkForDuplicate : check the codename for website duplication
  * @return boolean true on success, false on failure
  * @access public
  */
 function setCodename($data, &$user, $checkForDuplicate = true)
 {
     if (!is_a($user, "CMS_profile_user")) {
         $this->raiseError("Didn't received a valid user");
         return false;
     }
     if (strtolower(io::sanitizeAsciiString($data)) != $data) {
         $this->raiseError("Page codename must be alphanumeric only");
         return false;
     }
     if (strlen($data) > 100) {
         $this->raiseError("Page codename must have 100 characters max");
         return false;
     }
     //check if codename already exists
     if ($checkForDuplicate && $data) {
         $pageId = CMS_tree::getPageByCodename($data, $this->getWebsite(), false, false);
         if ($pageId && (!$this->getID() && $pageId || $this->getID() != $pageId)) {
             $this->raiseError("Page codename already exists in current website");
             return false;
         }
     }
     if (!$this->_checkBaseData(false)) {
         return false;
     }
     $this->_editedBaseData["codename"] = $data;
     $this->addEdition(RESOURCE_EDITION_BASEDATA, $user);
     return true;
 }
 protected function checkTagValues(&$tag, $requirements)
 {
     if (!is_array($requirements)) {
         $this->raiseError('Tag requirements must be an array');
         return false;
     }
     foreach ($requirements as $name => $requirementType) {
         //check parameter existence
         if ($requirementType['mandatory'] && !isset($tag['attributes'][$name])) {
             if ($this->_mode == self::CHECK_PARSING_MODE) {
                 $this->_parsingError .= "\n" . 'Malformed ' . $tag['nodename'] . ' tag : missing \'' . $name . '\' attribute';
                 return false;
             } else {
                 $this->raiseError('Malformed ' . $tag['nodename'] . ' tag : missing \'' . $name . '\' attribute');
                 return false;
             }
         } elseif (isset($tag['attributes'][$name])) {
             //if any, check value requirement
             $message = false;
             switch ($requirementType['value']) {
                 case 'alphanum':
                     if ($tag['attributes'][$name] != sensitiveIO::sanitizeAsciiString($tag['attributes'][$name], '', '_')) {
                         $message = 'Malformed ' . $tag['nodename'] . ' tag : \'' . $name . '\' attribute must only be composed with alphanumeric caracters (0-9a-z_) : ' . $tag['attributes'][$name];
                     }
                     break;
                 case 'language':
                     if (isset($this->_parameters['module'])) {
                         $languages = CMS_languagesCatalog::getAllLanguages($this->_parameters['module']);
                     } else {
                         $languages = CMS_languagesCatalog::getAllLanguages();
                     }
                     if (!isset($languages[$tag['attributes'][$name]])) {
                         $message = 'Malformed ' . $tag['nodename'] . ' tag : \'' . $name . '\' attribute must only be a valid language code : ' . $tag['attributes'][$name];
                     }
                     break;
                 case 'object':
                     if (!sensitiveIO::isPositiveInteger(io::substr($tag['attributes'][$name], 9, -3))) {
                         $message = 'Malformed ' . $tag['nodename'] . ' tag : \'' . $name . '\' attribute does not represent a valid object';
                     }
                     break;
                 case 'field':
                     if (strrpos($tag['attributes'][$name], 'fields') === false || !sensitiveIO::isPositiveInteger(io::substr($tag['attributes'][$name], strrpos($tag['attributes'][$name], 'fields') + 9, -2))) {
                         $message = 'Malformed ' . $tag['nodename'] . ' tag : \'' . $name . '\' attribute does not represent a valid object field';
                     }
                     break;
                 case 'page':
                     if (!io::isPositiveInteger($tag['attributes'][$name])) {
                         // Assuming the structure {websitecodename:pagecodename}
                         $page = trim($tag['attributes'][$name], "{}");
                         if (strpos($page, ":") !== false) {
                             list($websiteCodename, $pageCodename) = explode(':', $page);
                             $website = CMS_websitesCatalog::getByCodename($websiteCodename);
                             if (!$website) {
                                 $message = 'Malformed ' . $tag['nodename'] . ' tag : \'' . $name . '\' attribute : unknow Website codename : ' . $websiteCodename . '';
                             } else {
                                 $pageID = CMS_tree::getPageByCodename($pageCodename, $website, false, false);
                                 if (!$pageID) {
                                     $message = 'Malformed ' . $tag['nodename'] . ' tag : \'' . $name . '\' attribute : unknow page codename ' . $pageCodename . ' in website : ' . $websiteCodename . '';
                                 }
                             }
                         } else {
                             $message = 'Malformed ' . $tag['nodename'] . ' tag : \'' . $name . '\' attribute must be an integer or use the format websitecodename:pagecodename';
                         }
                     } else {
                         if (!CMS_tree::getPageByID($tag['attributes'][$name])) {
                             $message = 'Malformed ' . $tag['nodename'] . ' tag : \'' . $name . '\' attribute : unknow pageID : ' . $tag['attributes'][$name];
                         }
                     }
                     break;
                 default:
                     //check
                     if (!preg_match('#^' . $requirementType['value'] . '$#i', $tag['attributes'][$name])) {
                         $message = 'Malformed ' . $tag['nodename'] . ' tag : \'' . $name . '\' attribute must match expression \'' . $requirementType['value'] . '\' : ' . $tag['attributes'][$name];
                     }
                     break;
             }
             if ($message) {
                 if ($this->_mode == self::CHECK_PARSING_MODE) {
                     $this->_parsingError .= "\n<br />" . $message;
                     return false;
                 } else {
                     $this->raiseError($message);
                     return false;
                 }
             }
         }
     }
     return true;
 }
Example #3
0
         $item['format'] = $cms_language->getDateFormat();
     }
     break;
 case 'page':
     $item['xtype'] = 'atmPageField';
     $item['mandatory'] = false;
     $item['anchor'] = '97%';
     if (isset($varAttributes['root'])) {
         if (!io::isPositiveInteger($varAttributes['root'])) {
             // Assuming the structure {websitecodename:pagecodename}
             $page = trim($varAttributes['root'], "{}");
             if (strpos($page, ":") !== false) {
                 list($websiteCodename, $pageCodename) = explode(':', $page);
                 $website = CMS_websitesCatalog::getByCodename($websiteCodename);
                 if ($website) {
                     $pageID = CMS_tree::getPageByCodename($pageCodename, $website, false, false);
                     if ($pageID) {
                         $item['root'] = $pageID;
                     }
                 }
             }
         } else {
             if (CMS_tree::getPageByID($tag['attributes'][$name])) {
                 $item['root'] = $varAttributes['root'];
             }
         }
     }
     break;
 default:
     if (strpos($varAttributes['vartype'], 'fields') !== false) {
         // Assume it's a polymod object field
Example #4
0
 /**
  * Computes the target of the tag.
  *
  * @param CMS_page $page The page where the linx tag is.
  * @param string $publicTree Is the calculus made in the public or edited tree ?
  * @return CMS_page The target page, of false if no target.
  * @access public
  */
 function getTarget(&$page, $publicTree)
 {
     $pg = false;
     switch ($this->_type) {
         case "node":
             $pg = CMS_tree::getPageByID($this->_value);
             if ($pg && !$pg->hasError()) {
                 return $pg;
             } else {
                 return false;
             }
             break;
         case "codename":
             if ($this->_website) {
                 $website = CMS_websitesCatalog::getByCodename($this->_website);
                 if ($website) {
                     $pg = CMS_tree::getPageByCodename($this->_value, $website, $publicTree, true);
                 }
             } else {
                 if ($this->_crosswebsite) {
                     return CMS_tree::getPagesByCodename($this->_value, $publicTree, true);
                 } else {
                     $pg = CMS_tree::getPageByCodename($this->_value, $page->getWebsite(), $publicTree, true);
                 }
             }
             if ($pg && !$pg->hasError()) {
                 return $pg;
             } else {
                 return false;
             }
             break;
         case "relative":
             switch ($this->_value) {
                 case "root":
                     if ($this->_website) {
                         $website = CMS_websitesCatalog::getByCodename($this->_website);
                         if ($website) {
                             $pg = $website->getRoot();
                         }
                     } else {
                         $offset = abs($this->_relativeOffset) * -1;
                         $pg = CMS_tree::getAncestor($page, $offset, !$this->_crosswebsite, false);
                         //here we do not want to use public tree because, in public tree, some page may be unpublished or in this case, it break the lineage and root page cannot be found
                     }
                     break;
                 case "father":
                     $offset = abs($this->_relativeOffset);
                     $pg = CMS_tree::getAncestor($page, $offset, !$this->_crosswebsite, $publicTree);
                     break;
                 case "self":
                     $pg = $page;
                     break;
                 case "brother":
                     $pg = CMS_tree::getBrother($page, $this->_relativeOffset, $publicTree);
                     break;
             }
             if ($this->_website && is_a($pg, 'CMS_page') && !$pg->hasError()) {
                 if ($pg->getCodename()) {
                     $website = CMS_websitesCatalog::getByCodename($this->_website);
                     $pg = $website ? CMS_tree::getPageByCodename($pg->getCodename(), $website, $publicTree, true) : false;
                 } else {
                     $pg = false;
                 }
             }
             if (is_a($pg, 'CMS_page') && !$pg->hasError()) {
                 return $pg;
             } else {
                 return false;
             }
             break;
     }
 }
Example #5
0
 function duplicatePage($user, $page, $pageToAttachTo)
 {
     global $pageDuplicated, $duplicatedCodenames, $cms_user;
     if (is_a($page, "CMS_page") && is_a($pageToAttachTo, "CMS_page") && $page->getTemplate()) {
         //check codename duplication
         $removeCodename = false;
         if ($page->getCodename()) {
             //if codename already exists in website destination, then we must remove it
             if (CMS_tree::getPageByCodename($page->getCodename(), $pageToAttachTo->getWebsite(), false, false)) {
                 $removeCodename = true;
             }
         }
         //Duplicate page template
         $tpl = $page->getTemplate();
         $tpl_copy = CMS_pageTemplatesCatalog::getCloneFromID($tpl->getID(), false, true, false, $tpl->getID());
         $_tplID = $tpl_copy->getID();
         //Create copy of given page
         $newPage = $page->duplicate($user, $_tplID);
         if ($removeCodename) {
             $newPage->setCodename('', $cms_user);
             $newPage->writeToPersistence();
             $duplicatedCodenames[] = $page->getCodename();
         }
         //Move to destination in tree
         if (is_null($newPage) || !CMS_tree::attachPageToTree($newPage, $pageToAttachTo)) {
             return null;
         }
         $pageDuplicated[] = $newPage->getID();
         //Proceed with siblings
         $sibs = CMS_tree::getSiblings($page);
         if (!$sibs || !sizeof($sibs)) {
             return $pageToAttachTo;
         } else {
             $pageToAttachTo = $newPage;
         }
         foreach ($sibs as $sib) {
             if ($user->hasPageClearance($sib->getID(), CLEARANCE_PAGE_EDIT) && !in_array($sib->getID(), $pageDuplicated)) {
                 duplicatePage($user, $sib, $pageToAttachTo);
             }
         }
     }
 }
Example #6
0
 /**
  * Returns a queried CMS_page value identified by it's codename and a reference page to identify the requested website
  * Static function.
  *
  * @param string $codename The codename of the wanted CMS_page
  * @param integer $id The DB ID of the reference CMS_page. This id is used to get the website of reference
  * @param string $type The value type to get
  * @return CMS_page or false on failure to find it
  * @access public
  */
 static function getPageCodenameValue($codename, $referencePageId, $type)
 {
     static $pagesInfos;
     if (!SensitiveIO::isPositiveInteger($referencePageId)) {
         CMS_grandFather::raiseError("Reference Page id must be positive integer : " . $referencePageId);
         return false;
     }
     if (strtolower(io::sanitizeAsciiString($codename)) != $codename) {
         $this->raiseError("Page codename must be alphanumeric only");
         return false;
     }
     if (!isset($pagesInfos[$codename][$referencePageId])) {
         //get website of reference page Id
         $website = CMS_tree::getPageWebsite($referencePageId);
         if (!$website) {
             $pagesInfos[$codename][$referencePageId] = false;
         } else {
             //get page by codename
             $pagesInfos[$codename][$referencePageId] = CMS_tree::getPageByCodename($codename, $website, true, false);
         }
     }
     if ($pagesInfos[$codename][$referencePageId]) {
         return CMS_tree::getPageValue($pagesInfos[$codename][$referencePageId], $type);
     }
     return false;
 }