/** * Add a group to the list. * * @param string $group The group to add * @return boolean true on success, false on failure * @access public */ function addGroup($group) { if (trim($group) && $group == SensitiveIO::sanitizeSQLString($group)) { $groups = $this->getGroups(); $group = trim($group); if (!in_array($group, $groups)) { $this->_groups->add($group); } return true; } else { $this->raiseError('Trying to set an empty group or which contains illegal characters'); return false; } }
/** * Set the proposedFor location of the resource. Also add the editor who proposed the location. * * @param integer $location the location to set * @param CMS_profile_user &$user the user who did the edition * @return boolean true on success, false on failure * @access public */ function setProposedLocation($location, &$user) { if (!is_a($user, "CMS_profile_user")) { $this->raiseError("Didn't received a valid user"); return false; } if (is_object($this->_status) && $this->_status->setProposedFor($location)) { //add the edition $this->_status->addEdition(RESOURCE_EDITION_LOCATION); //add the user to the editors $this->_editors->add($user->getUserID(), RESOURCE_EDITION_LOCATION); return true; } else { return false; } }
/** * Add category clearances to current stack * * @param CMS_stack $clearances, clearances to add * @return boolean true on success * @access public */ function add($clearances) { if (is_a($clearances, "CMS_stack")) { $arr = $clearances->getElements(); if (is_array($arr) && $arr) { while (list($k, $v) = each($arr)) { $this->_categoriesClearances->delAllWithOneValue($v[1], 1); $this->_categoriesClearances->add($v[1], $v[2]); } } return true; } else { $this->raiseError("Stack object required : " . var_dump($clearances)); return false; } }
/** * Parse the definition file as to get the client spaces * * @param CMS_modulesTags $modulesTreatment tags object treatment * @return string The error string from the parser, false if no error * @access private */ protected function _parseDefinitionFile(&$modulesTreatment, $convert = null) { global $cms_language; if (!$this->_definitionFile) { return false; } $filename = PATH_TEMPLATES_FS . "/" . $this->_definitionFile; $tpl = new CMS_file(PATH_TEMPLATES_FS . "/" . $this->_definitionFile); if (!$tpl->exists()) { $this->raiseError('Can not found template file ' . PATH_TEMPLATES_FS . "/" . $this->_definitionFile); return false; } $definition = $tpl->readContent(); //we need to remove doctype if any $definition = trim(preg_replace('#<!doctype[^>]*>#siU', '', $definition)); $modulesTreatment->setDefinition($definition); //get client spaces modules codename $this->_clientSpacesTags = $modulesTreatment->getTags(array('atm-clientspace'), true); if (is_array($this->_clientSpacesTags)) { $modules = array(); foreach ($this->_clientSpacesTags as $cs_tag) { if ($cs_tag->getAttribute("module")) { $modules[] = $cs_tag->getAttribute("module"); } } $blocks = $modulesTreatment->getTags(array('block'), true); foreach ($blocks as $block) { if ($block->getAttribute("module")) { $modules[] = $block->getAttribute("module"); } else { return $cms_language->getMessage(self::MESSAGE_TPL_SYNTAX_ERROR, array($cms_language->getMessage(self::MESSAGE_BLOCK_SYNTAX_ERROR))); } } $modules = array_unique($modules); $this->_modules->emptyStack(); foreach ($modules as $module) { $this->_modules->add($module); } if ($convert !== null) { $tplConverted = false; foreach ($modules as $moduleCodename) { if (CMS_modulesCatalog::isPolymod($moduleCodename)) { $tplConverted = true; $module = CMS_modulesCatalog::getByCodename($moduleCodename); $definition = $module->convertDefinitionString($definition, $convert == self::CONVERT_TO_HUMAN); } } if ($tplConverted) { //check definition parsing $parsing = new CMS_polymod_definition_parsing($definition, true, CMS_polymod_definition_parsing::CHECK_PARSING_MODE); $errors = $parsing->getParsingError(); if ($errors) { return $cms_language->getMessage(self::MESSAGE_TPL_SYNTAX_ERROR, array($errors)); } $filename = $this->getDefinitionFile(); $file = new CMS_file(PATH_TEMPLATES_FS . "/" . $filename); $file->setContent($definition); $file->writeToPersistence(); } } return true; } else { $this->raiseError("Malformed definition file : " . $this->_definitionFile . "<br />" . $modulesTreatment->getParsingError()); return $modulesTreatment->getParsingError(); } }
/** * Add two Clearances stacks together * * @param CMS_stack $pageClearances page clearances to add to this profile * @return void * @access public */ protected function _addStackClearances($stack1, $stack2) { if (!is_a($stack1, "CMS_stack")) { $this->raiseError('Stack1 must be a valid stack object : ' . $stack1); return false; } if (!is_a($stack2, "CMS_stack")) { $this->raiseError('Stack2 must be a valid stack object : ' . $stack2); return false; } if ($stack1->getValuesByAtom() == 2 && $stack2->getValuesByAtom() == 2) { //create arrays from clearances stacks (easier to manage) $stack1Clearance = array(); foreach ($stack1->getElements() as $clearanre) { $stack1Clearance[$clearanre[0]] = $clearanre[1]; } $stack2Clearance = array(); foreach ($stack2->getElements() as $clearanre) { $stack2Clearance[$clearanre[0]] = $clearanre[1]; } //then add both together $newClearance = array(); foreach ($stack1Clearance as $clearance => $clearanceValue) { if (isset($newClearance[$clearance]) && $newClearance[$clearance] < $clearanceValue || !isset($newClearance[$clearance])) { $newClearance[$clearance] = $clearanceValue; } } foreach ($stack2Clearance as $clearance => $clearanceValue) { if (isset($newClearance[$clearance]) && $newClearance[$clearance] < $clearanceValue || !isset($newClearance[$clearance])) { $newClearance[$clearance] = $clearanceValue; } } //set CMS_stack with new pages clearance $addedClearances = new CMS_stack(); foreach ($newClearance as $clearance => $clearanceValue) { $addedClearances->add($clearance, $clearanceValue); } return $addedClearances; } elseif ($stack1->getValuesByAtom() == 1 && $stack2->getValuesByAtom() == 1) { //create arrays from clearances stacks (easier to manage) $stack1Clearance = array(); foreach ($stack1->getElements() as $clearanre) { $stack1Clearance[$clearanre[0]] = $clearanre[0]; } $stack2Clearance = array(); foreach ($stack2->getElements() as $clearanre) { $stack2Clearance[$clearanre[0]] = $clearanre[0]; } //then add both together $newClearance = array_unique(array_merge($stack1Clearance, $stack2Clearance)); //set CMS_stack with new pages clearance $addedClearances = new CMS_stack(); $addedClearances->setValuesByAtom(1); // Assume 1 atom foreach ($newClearance as $clearance) { $addedClearances->add($clearance); } return $addedClearances; } else { $this->raiseError('Can\'t add stack objects without the same value by atom number ...'); return false; } }
/** * Get All Groups * Static function * * @return array(string) * @access public */ static function getAllGroups($returnStack = false, $reset = false) { static $rowGroups; if (!isset($rowGroups) || $reset) { $rowGroups = array(); $sql = ' select distinct groupsStack_row from mod_standard_rows '; $q = new CMS_query($sql); while ($data = $q->getArray()) { $groupStackString = $data["groupsStack_row"]; $groupStack = new CMS_stack(); $groupStack->setTextDefinition($groupStackString); foreach ($groupStack->getElements() as $group) { if (!SensitiveIO::isInSet($group[0], $rowGroups) && $group[0]) { $rowGroups[] = $group[0]; } } } } //sort groups natcasesort($rowGroups); if ($returnStack) { $stack = new CMS_stack(); $stack->setValuesByAtom(1); foreach ($rowGroups as $rowGroup) { $stack->add($rowGroup); } return $stack; } else { return $rowGroups; } }
/** * Get All Groups * Static function * * @return array(string) * @access public */ static function getAllGroups($returnStack = false) { static $templateGroups; if (!isset($templateGroups)) { $templateGroups = array(); $sql = ' select distinct groupsStack_pt from pageTemplates where private_pt=0 '; $q = new CMS_query($sql); while ($data = $q->getArray()) { $groupStackString = $data["groupsStack_pt"]; $groupStack = new CMS_stack(); $groupStack->setTextDefinition($groupStackString); foreach ($groupStack->getElements() as $group) { if (!SensitiveIO::isInSet($group[0], $templateGroups) && $group[0]) { $templateGroups[] = $group[0]; } } } } //sort groups natcasesort($templateGroups); if ($returnStack) { $stack = new CMS_stack(); $stack->setValuesByAtom(1); foreach ($templateGroups as $tplGroup) { $stack->add($tplGroup); } return $stack; } else { return $templateGroups; } }