/** * Constructor. * initializes the resource if the id is given * * @param integer $id DB id * @return void * @access public */ function CMS_resource($id = 0) { if ($id) { if (SensitiveIO::isPositiveInteger($id)) { $sql = "\n\t\t\t\t\tselect\n\t\t\t\t\t\t*\n\t\t\t\t\tfrom\n\t\t\t\t\t\tresources,\n\t\t\t\t\t\tresourceStatuses\n\t\t\t\t\twhere\n\t\t\t\t\t\tid_res='{$id}'\n\t\t\t\t\t\tand status_res=id_rs\n\t\t\t\t"; $q = new CMS_query($sql); if ($q->getNumRows()) { $data = $q->getArray(); $this->_id = $id; $this->_status = new CMS_resourceStatus($data); if ($this->_status->hasError()) { $this->raiseError("Unfound status :" . $data["status_res"]); return; } //build editors stack. If stack is malformed, it's a minor error, so proceed. $this->_editors = new CMS_stack(); if (!$this->_editors->setTextDefinition($data["editorsStack_res"])) { $this->raiseError("Editors stack malformed"); $this->_editors->emptyStack(); } } else { $this->raiseError("Unknown ID :" . $id); } } elseif (is_array($id)) { $data = $id; $this->_id = $data["id_res"]; $this->_status = new CMS_resourceStatus($data); if ($this->_status->hasError()) { $this->raiseError("Unfound status :" . $data["status_res"]); return; } //build editors stack. If stack is malformed, it's a minor error, so proceed. $this->_editors = new CMS_stack(); if (!$this->_editors->setTextDefinition($data["editorsStack_res"])) { $this->raiseError("Editors stack malformed"); $this->_editors->emptyStack(); } } else { $this->raiseError("Id is not a positive integer nor array"); return; } } else { $this->_status = new CMS_resourceStatus(); $this->_editors = new CMS_stack(); } }
/** * Sets the definition from a string. Must write the definition to file and try to parse it * The file must be in a specific directory : PATH_TEMPLATES_ROWS_FS (see constants from rc file) * * @param string $definition The definition * @param boolean $haltOnPolymodParsing Stop setting definition if error on polymod parsing are found (default : true) * @return boolean true on success, false on failure * @access public */ function setDefinition($definition, $haltOnPolymodParsing = true) { global $cms_language; $defXML = new CMS_DOMDocument(); try { $defXML->loadXML($definition); } catch (DOMException $e) { return $cms_language->getMessage(self::MESSAGE_PAGE_ROW_SYNTAX_ERROR, array($e->getMessage())); } $blocks = $defXML->getElementsByTagName('block'); $modules = array(); foreach ($blocks as $block) { if ($block->hasAttribute("module")) { $modules[] = $block->getAttribute("module"); } else { return $cms_language->getMessage(self::MESSAGE_PAGE_ROW_SYNTAX_ERROR, array($cms_language->getMessage(self::MESSAGE_PAGE_BLOCK_SYNTAX_ERROR))); } } $modules = array_unique($modules); $this->_modules->emptyStack(); foreach ($modules as $module) { $this->_modules->add($module); } //check if rows use a polymod block, if so pass to module for variables conversion $rowConverted = false; foreach ($this->getModules(false) as $moduleCodename) { if (CMS_modulesCatalog::isPolymod($moduleCodename)) { $rowConverted = true; $module = CMS_modulesCatalog::getByCodename($moduleCodename); $definition = $module->convertDefinitionString($definition, false); } } if ($rowConverted) { //check definition parsing $parsing = new CMS_polymod_definition_parsing($definition, true, CMS_polymod_definition_parsing::CHECK_PARSING_MODE); $errors = $parsing->getParsingError(); if ($errors && $haltOnPolymodParsing) { return $cms_language->getMessage(self::MESSAGE_PAGE_ROW_SYNTAX_ERROR, array($errors)); } } $filename = $this->getDefinitionFileName(); if (!$filename) { //must write it to persistence to have its ID if (!$this->_id) { $this->writeToPersistence(); } //build the filename $filename = "r" . $this->_id . "_" . SensitiveIO::sanitizeAsciiString($this->_label) . ".xml"; } $rowFile = new CMS_file(PATH_TEMPLATES_ROWS_FS . "/" . $filename); $rowFile->setContent($definition); $rowFile->writeToPersistence(); $this->_definitionFile = $filename; return true; }
/** * 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(); } }
/** * Del Validation Clearances * * @return void * @access public */ function delValidationClearances() { $this->_validationClearances->emptyStack(); $this->_validationClearances->setValuesByAtom(1); }