Ejemplo n.º 1
0
 public function checkDefinition($returnErrors = false)
 {
     global $cms_language;
     //check definition parsing
     $module = CMS_poly_object_catalog::getModuleCodenameForObjectType($this->objectdefinition);
     $polymod = CMS_modulesCatalog::getByCodename($module);
     $convertedDefinition = $polymod->convertDefinitionString($this->html, false);
     $parsing = new CMS_polymod_definition_parsing($convertedDefinition, true, CMS_polymod_definition_parsing::CHECK_PARSING_MODE, $module);
     $errors = $parsing->getParsingError();
     if ($errors) {
         return $returnErrors ? $errors : false;
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  * 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();
     }
 }
Ejemplo n.º 3
0
 /**
  * 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;
 }
Ejemplo n.º 4
0
 /**
  * Sets an object value.
  *
  * @param string $valueName the name of the value to set
  * @param mixed $value the value to set
  * @return boolean true on success, false on failure
  * @access public
  */
 function setValue($valueName, $value)
 {
     if (!in_array($valueName, array_keys($this->_objectValues))) {
         $this->raiseError("Unknown valueName to set :" . $valueName);
         return false;
     }
     if ($valueName == 'uuid') {
         $this->raiseError("Cannot change UUID");
         return false;
     }
     if ($valueName == 'indexURL') {
         $parsing = new CMS_polymod_definition_parsing($value, true, CMS_polymod_definition_parsing::CHECK_PARSING_MODE);
         $errors = $parsing->getParsingError();
         if ($errors) {
             return $errors;
         }
     }
     $this->_objectValues[$valueName] = $value;
     if ($valueName == 'indexURL') {
         $this->compileDefinition();
     }
     return true;
 }
Ejemplo n.º 5
0
 /**
  * Sets an object value.
  *
  * @param string $valueName the name of the value to set
  * @param mixed $value the value to set
  * @return boolean true on success, false on failure
  * @access public
  */
 function setValue($valueName, $value)
 {
     if (!in_array($valueName, array_keys($this->_objectValues))) {
         $this->raiseError("Unknown valueName to set :" . $valueName);
         return false;
     }
     if ($valueName == 'uuid') {
         $this->raiseError("Cannot change UUID");
         return false;
     }
     if ($valueName == 'definition') {
         global $cms_language;
         //check definition parsing
         $module = CMS_poly_object_catalog::getModuleCodenameForObjectType($this->getValue('objectID'));
         $parsing = new CMS_polymod_definition_parsing($value, true, CMS_polymod_definition_parsing::CHECK_PARSING_MODE, $module);
         //$parsing = new CMS_polymod_definition_parsing($value, $parameters, true, false, CMS_polymod_definition_parsing::CHECK_PARSING_MODE);
         $errors = $parsing->getParsingError();
         if ($errors) {
             return $errors;
         }
     }
     $this->_objectValues[$valueName] = $value;
     if ($valueName == 'definition') {
         $this->compileDefinition();
     }
     return true;
 }
Ejemplo n.º 6
0
 /**
  * Sets an object value.
  *
  * @param string $valueName the name of the value to set
  * @param mixed $value the value to set
  * @return boolean true on success, false on failure
  * @access public
  */
 function setValue($valueName, $value)
 {
     if (!in_array($valueName, array_keys($this->_objectValues))) {
         $this->raiseError("Unknown valueName to set :" . $valueName);
         return false;
     }
     if ($valueName == 'uuid') {
         $this->raiseError("Cannot change UUID");
         return false;
     }
     if ($valueName == 'definition') {
         global $cms_language;
         //check definition parsing
         $module = CMS_poly_object_catalog::getModuleCodenameForObjectType($this->getValue('objectID'));
         $parsing = new CMS_polymod_definition_parsing($value, true, CMS_polymod_definition_parsing::CHECK_PARSING_MODE, $module);
         $errors = $parsing->getParsingError();
         if ($errors) {
             return $errors;
         }
     } elseif ($valueName == 'email') {
         if (!sensitiveIO::isValidEmail($value)) {
             $this->raiseError("Email value must be a valid email :" . $value);
             return false;
         }
     } elseif ($valueName == 'link') {
         if ($value && io::substr($value, 0, 4) != "http") {
             $value = strip_tags('http://' . $value);
         }
     } else {
         $value = strip_tags(trim($value));
     }
     $this->_objectValues[$valueName] = $value;
     if ($valueName == 'definition') {
         $this->compileDefinition();
     }
     return true;
 }