/** * Get a module by its codename. * * @param string $codename the codename of the module to get * @return CMS_module The module wanted * @access public */ static function getByCodename($datas) { static $modules; if (is_string($datas)) { $codename = $datas; if (!$codename) { parent::raiseError("Codename is null"); return false; } if (isset($modules[$codename])) { return $modules[$codename]; } //test the codename to see if it is valid if ($codename != SensitiveIO::sanitizeAsciiString($codename)) { parent::raiseError("Codename is not valid"); return false; } //Try to instanciate a module named CMS_module_CODENAME $class_name = "CMS_module_" . $codename; if (class_exists($class_name)) { $modules[$codename] = new $class_name($codename); return $modules[$codename]; } elseif (CMS_modulesCatalog::isPolymod($codename)) { $modules[$codename] = new CMS_polymod($codename); return $modules[$codename]; } else { parent::raiseError("Unknown codename : " . $codename); return false; } } elseif (is_array($datas)) { $codename = isset($datas['codename_mod']) ? $datas['codename_mod'] : ''; if (!$codename) { parent::raiseError("Codename is null"); return false; } if (isset($modules[$codename])) { return $modules[$codename]; } //test the codename to see if it is valid if ($codename != SensitiveIO::sanitizeAsciiString($codename)) { parent::raiseError("Codename is not valid"); return false; } //Try to instanciate a module named CMS_module_CODENAME $class_name = "CMS_module_" . $codename; if (class_exists($class_name)) { $modules[$codename] = new $class_name($datas); return $modules[$codename]; } elseif ($datas['isPolymod_mod']) { $modules[$codename] = new CMS_polymod($datas); return $modules[$codename]; } else { parent::raiseError("Unknown codename : " . $codename); return false; } } else { parent::raiseError("Unknown datas type : " . gettype($datas)); return false; } }
/** * Constructor * * @param string $codename, the codename of the module to export datas * @return void */ function __construct($codename) { if (!in_array($codename, CMS_modulesCatalog::getAllCodenames())) { $this->raiseError('Unknown module : ' . $codename); return false; } $this->_module = $codename; //only polymod for now, but can be switched by modules later $this->_hasExport = CMS_modulesCatalog::isPolymod($this->_module); if ($this->_hasExport) { $this->_defaultParameters = array('objects', 'categories', 'rows', 'css', 'js', 'img'); $this->_availableParameters = array('objects' => self::MESSAGE_PARAM_OBJECTS, 'categories' => self::MESSAGE_PARAM_CATEGORIES, 'rows' => self::MESSAGE_PARAM_ROWS, 'css' => self::MESSAGE_PARAM_CSS, 'js' => self::MESSAGE_PARAM_JS, 'img' => self::MESSAGE_PARAM_IMG); } }
/** * 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(); } }
/** * 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; }
if (!is_object($cms_user)) { //no user => LOGIN header('Location: ' . PATH_FRONTEND_SPECIAL_LOGIN_WR . '?referer=' . base64_encode($_SERVER['REQUEST_URI'])); exit; } elseif (!$cms_user->hasPageClearance($pageId, CLEARANCE_PAGE_VIEW)) { if ($cms_user->getLogin() == DEFAULT_USER_LOGIN) { //no rights and anonymous => LOGIN header('Location: ' . PATH_FRONTEND_SPECIAL_LOGIN_WR . '?referer=' . base64_encode($_SERVER['REQUEST_URI'])); } else { //no rights and logged => 403 header('Location: ' . PATH_FORBIDDEN_WR . '?referer=' . base64_encode($_SERVER['REQUEST_URI'])); } exit; } } } elseif (CMS_modulesCatalog::isPolymod($codename)) { //get object item id $itemID = ''; if (preg_match('#^r[0-9]+_[0-9]+_.*#', $pathinfo['basename'])) { $itemID = preg_replace('#^r([0-9]+)_[0-9]+_.*#', '\\1', $pathinfo['basename']); } if (sensitiveIO::isPositiveInteger($itemID)) { if (!is_object($cms_user)) { //no user => LOGIN header('Location: ' . PATH_FRONTEND_SPECIAL_LOGIN_WR . '?referer=' . base64_encode($_SERVER['REQUEST_URI'])); exit; } else { $public = preg_match('#.*/(edited|edition)$#', $pathinfo['dirname']) ? false : true; $item = CMS_poly_object_catalog::getObjectByID($itemID, false, $public); if (!$item || !is_object($item) || !$item->userHasClearance($cms_user, CLEARANCE_MODULE_VIEW, true)) { if ($cms_user->getLogin() == DEFAULT_USER_LOGIN) {