Esempio n. 1
0
 /**
  * Gets all available objects class names
  *
  * @return array(string "CMS_object_{type}")
  * @access public
  * @static
  */
 function getObjectsNames()
 {
     //Automatic listing
     $excludedFiles = array('object_catalog.php', 'object_common.php');
     $packages_dir = dir(PATH_MODULES_FS . '/' . MOD_POLYMOD_CODENAME . '/objects/');
     while (false !== ($file = $packages_dir->read())) {
         if (io::substr($file, -4) == ".php" && !in_array($file, $excludedFiles) && class_exists('CMS_' . io::substr($file, 0, -4))) {
             $objectsCatalog[] = 'CMS_' . io::substr($file, 0, -4);
         }
     }
     return $objectsCatalog;
 }
Esempio n. 2
0
 /**
  * Get the text definition.
  *
  * @return string The text definition based on the current elements
  * @access public
  */
 function getTextDefinition()
 {
     $text = '';
     foreach ($this->_elements as $atom) {
         $text .= $atom[0];
         if ($this->_valuesByAtom == 2) {
             $text .= "," . $atom[1];
         }
         $text .= ";";
     }
     $text = io::substr($text, 0, -1);
     return $text;
 }
Esempio n. 3
0
 /**
  * Move the data of a resource from one data location to another.
  * May be used by every module, provided it respects the naming rules described in the modules HOWTO
  *
  * @param CMS_module $module The module who  want its data moved
  * @param string $tablesPrefix The prefix of the tables containing the data
  * @param string $resourceIDFieldName The name of the field containing the resource ID
  * @param integer $resourceID The DB ID of the resource whose data we want to move
  * @param string $locationFrom The starting location, among the available RESOURCE_DATA_LOCATION
  * @param string $locationTo The ending location, among  the available RESOURCE_DATA_LOCATION
  * @param boolean $copyOnly If set to true, the deletion from the originating tables and dirs won't occur
  * @return boolean true on success, false on failure
  * @access public
  */
 static function moveResourceData(&$module, $tablesPrefix, $resourceIDFieldName, $resourceID, $locationFrom, $locationTo, $copyOnly = false)
 {
     if (!is_a($module, "CMS_module")) {
         CMS_grandFather::raiseError("Module is not a CMS_module");
         return false;
     }
     if (!SensitiveIO::isInSet($locationFrom, CMS_resource::getAllDataLocations()) || !SensitiveIO::isInSet($locationTo, CMS_resource::getAllDataLocations())) {
         CMS_grandFather::raiseError("Locations are not in the set");
         return false;
     }
     //get the tables : named PREFIXXXXX_public
     $sql = "show tables";
     $q = new CMS_query($sql);
     $tables_prefixes = array();
     while ($data = $q->getArray()) {
         if (preg_match("#" . $tablesPrefix . "(.*)_public#", $data[0])) {
             $tables_prefixes[] = io::substr($data[0], 0, strrpos($data[0], "_") + 1);
         }
     }
     foreach ($tables_prefixes as $table_prefix) {
         //delete all in the destination table just incase and insert
         if ($locationTo != RESOURCE_DATA_LOCATION_DEVNULL) {
             $sql = "\n\t\t\t\t\tdelete from\n\t\t\t\t\t\t" . $table_prefix . $locationTo . "\n\t\t\t\t\twhere\n\t\t\t\t\t\t" . $resourceIDFieldName . "='" . $resourceID . "'\n\t\t\t\t";
             $q = new CMS_query($sql);
             $sql = "\n\t\t\t\t\tinsert into\n\t\t\t\t\t\t" . $table_prefix . $locationTo . "\n\t\t\t\t\t\tselect\n\t\t\t\t\t\t\t*\n\t\t\t\t\t\tfrom\n\t\t\t\t\t\t\t" . $table_prefix . $locationFrom . "\n\t\t\t\t\t\twhere\n\t\t\t\t\t\t\t" . $resourceIDFieldName . "='" . $resourceID . "'\n\t\t\t\t";
             $q = new CMS_query($sql);
         }
         if (!$copyOnly) {
             //delete from the starting table
             $sql = "\n\t\t\t\t\tdelete from\n\t\t\t\t\t\t" . $table_prefix . $locationFrom . "\n\t\t\t\t\twhere\n\t\t\t\t\t\t" . $resourceIDFieldName . "='" . $resourceID . "'\n\t\t\t\t";
             $q = new CMS_query($sql);
         }
     }
     //second, move the files
     $locationFromDir = new CMS_file(PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationFrom, CMS_file::FILE_SYSTEM, CMS_file::TYPE_DIRECTORY);
     //cut here if the locationFromDir doesn't exists. That means the module doesn't have files
     if (!$locationFromDir->exists()) {
         return true;
     }
     if ($locationTo != RESOURCE_DATA_LOCATION_DEVNULL) {
         $locationToDir = new CMS_file(PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationTo, CMS_file::FILE_SYSTEM, CMS_file::TYPE_DIRECTORY);
         //cut here if the locationToDir doesn't exists.
         if (!$locationToDir->exists()) {
             CMS_grandFather::raiseError("LocationToDir does not exists : " . PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationTo);
             return false;
         }
         //delete all files of the locationToDir
         $files = glob(PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationTo . '/r' . $resourceID . '_*', GLOB_NOSORT);
         if (is_array($files)) {
             foreach ($files as $file) {
                 if (!CMS_file::deleteFile($file)) {
                     CMS_grandFather::raiseError("Can't delete file " . $file);
                     return false;
                 }
             }
         }
         //then copy or move them to the locationToDir
         $files = glob(PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationFrom . '/r' . $resourceID . '_*', GLOB_NOSORT);
         if (is_array($files)) {
             foreach ($files as $file) {
                 $to = str_replace('/' . $locationFrom . '/', '/' . $locationTo . '/', $file);
                 if ($copyOnly) {
                     if (!CMS_file::copyTo($file, $to)) {
                         CMS_grandFather::raiseError("Can't copy file " . $file . " to " . $to);
                         return false;
                     }
                 } else {
                     if (!CMS_file::moveTo($file, $to)) {
                         CMS_grandFather::raiseError("Can't move file " . $file . " to " . $to);
                         return false;
                     }
                 }
                 //then chmod new file
                 CMS_file::chmodFile(FILES_CHMOD, $to);
             }
         }
     }
     //cleans the initial dir if not a copy
     if (!$copyOnly) {
         //then get all files of the locationFromDir
         $files = glob(PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationFrom . '/r' . $resourceID . '_*', GLOB_NOSORT);
         if (is_array($files)) {
             foreach ($files as $file) {
                 if (!CMS_file::deleteFile($file)) {
                     CMS_grandFather::raiseError("Can't delete file " . $file);
                     return false;
                 }
             }
         }
     }
     return true;
 }
Esempio n. 4
0
 /**
  * Get the default language.
  *
  * @param boolean guessFromNavigator : try to guess default user language from HTTP_ACCEPT_LANGUAGE (default : false)
  * @return CMS_language The default language
  * @access public
  */
 static function getDefaultLanguage($guessFromNavigator = false)
 {
     if ($guessFromNavigator) {
         //load language object from get value if any
         if (isset($_GET["language"]) && SensitiveIO::isInSet($_GET["language"], array_keys(CMS_languagesCatalog::getAllLanguages()))) {
             $language = CMS_languagesCatalog::getByCode($_GET["language"]);
             if ($language) {
                 return $language;
             }
         } elseif (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"]) && SensitiveIO::isInSet(io::substr($_SERVER["HTTP_ACCEPT_LANGUAGE"], 0, 2), array_keys(CMS_languagesCatalog::getAllLanguages()))) {
             $language = CMS_languagesCatalog::getByCode(io::substr($_SERVER["HTTP_ACCEPT_LANGUAGE"], 0, 2));
             if ($language) {
                 return $language;
             }
         }
     }
     return CMS_languagesCatalog::getByCode(APPLICATION_DEFAULT_LANGUAGE);
 }
Esempio n. 5
0
 /**
  * get an object instance of the field type
  *
  * @param boolean $returnDefinition, return object CMS_poly_object_definition or CMS_poly_object otherwise
  * @return mixed, the object instance
  * @access public
  */
 function getTypeObject($returnDefinition = false, $public = false)
 {
     if (!$this->_objectFieldValues['type']) {
         return false;
     }
     if (sensitiveIO::isPositiveInteger($this->_objectFieldValues['type'])) {
         if ($returnDefinition) {
             return CMS_poly_object_catalog::getObjectDefinition($this->_objectFieldValues['type']);
         } else {
             $item = new CMS_poly_object($this->_objectFieldValues['type'], 0, array(), $public);
             //object is used as field as another object so set it
             $item->setField($this);
             return $item;
         }
     } elseif (io::strpos($this->_objectFieldValues['type'], 'multi|') !== false) {
         return new CMS_multi_poly_object(io::substr($this->_objectFieldValues['type'], 6), array(), $this, $public);
     } elseif (class_exists($this->_objectFieldValues['type'])) {
         return new $this->_objectFieldValues['type'](array(), $this, $public);
     }
 }
Esempio n. 6
0
 /**
  * Creates compressed file by compressing raw data contained into $this->CMS_archive
  * 
  * @return true on success, false on failure
  */
 function create_zip()
 {
     $files = 0;
     $offset = 0;
     $central = "";
     if (!empty($this->options['sfx'])) {
         if ($fp = @fopen($this->options['sfx'], "rb")) {
             $temp = fread($fp, filesize($this->options['sfx']));
             fclose($fp);
             $this->add_data($temp);
             $offset += io::strlen($temp);
             unset($temp);
         } else {
             $this->raiseError("Could not open sfx module from {$this->options['sfx']}.");
         }
     }
     $pwd = getcwd();
     chdir($this->options['basedir']);
     foreach ($this->files as $current) {
         if ($current['name'] == $this->options['name']) {
             continue;
         }
         // Special chars management
         $translate = array('Ç' => pack("C", 128), 'ü' => pack("C", 129), 'é' => pack("C", 130), 'â' => pack("C", 131), 'ä' => pack("C", 132), 'à' => pack("C", 133), 'å' => pack("C", 134), 'ç' => pack("C", 135), 'ê' => pack("C", 136), 'ë' => pack("C", 137), 'è' => pack("C", 138), 'ï' => pack("C", 139), 'î' => pack("C", 140), 'ì' => pack("C", 141), 'Ä' => pack("C", 142), 'Å' => pack("C", 143), 'É' => pack("C", 144), 'æ' => pack("C", 145), 'Æ' => pack("C", 146), 'ô' => pack("C", 147), 'ö' => pack("C", 148), 'ò' => pack("C", 149), 'û' => pack("C", 150), 'ù' => pack("C", 151), 'Ö' => pack("C", 153), 'Ü' => pack("C", 154), '£' => pack("C", 156), '¥' => pack("C", 157), 'ƒ' => pack("C", 159), 'á' => pack("C", 160), 'í' => pack("C", 161), 'ó' => pack("C", 162), 'ú' => pack("C", 163), 'ñ' => pack("C", 164), 'Ñ' => pack("C", 165));
         $current['name2'] = strtr($current['name2'], $translate);
         $timedate = explode(" ", date("Y n j G i s", $current['stat'][9]));
         $timedate = $timedate[0] - 1980 << 25 | $timedate[1] << 21 | $timedate[2] << 16 | $timedate[3] << 11 | $timedate[4] << 5 | $timedate[5];
         $block = pack("VvvvV", 0x4034b50, 0xa, 0x0, isset($current['method']) || $this->options['method'] == 0 ? 0x0 : 0x8, $timedate);
         if ($current['stat'][7] == 0 && $current['type'] == 5) {
             $block .= pack("VVVvv", 0x0, 0x0, 0x0, io::strlen($current['name2']) + 1, 0x0);
             $block .= $current['name2'] . "/";
             $this->add_data($block);
             $central .= pack("VvvvvVVVVvvvvvVV", 0x2014b50, 0x14, $this->options['method'] == 0 ? 0x0 : 0xa, 0x0, isset($current['method']) || $this->options['method'] == 0 ? 0x0 : 0x8, $timedate, 0x0, 0x0, 0x0, io::strlen($current['name2']) + 1, 0x0, 0x0, 0x0, 0x0, $current['type'] == 5 ? 0x10 : 0x0, $offset);
             $central .= $current['name2'] . "/";
             $files++;
             $offset += 31 + io::strlen($current['name2']);
         } else {
             if ($current['stat'][7] == 0) {
                 $block .= pack("VVVvv", 0x0, 0x0, 0x0, io::strlen($current['name2']), 0x0);
                 $block .= $current['name2'];
                 $this->add_data($block);
                 $central .= pack("VvvvvVVVVvvvvvVV", 0x2014b50, 0x14, $this->options['method'] == 0 ? 0x0 : 0xa, 0x0, isset($current['method']) || $this->options['method'] == 0 ? 0x0 : 0x8, $timedate, 0x0, 0x0, 0x0, io::strlen($current['name2']), 0x0, 0x0, 0x0, 0x0, $current['type'] == 5 ? 0x10 : 0x0, $offset);
                 $central .= $current['name2'];
                 $files++;
                 $offset += 30 + io::strlen($current['name2']);
             } else {
                 if ($fp = @fopen($current['name'], "rb")) {
                     $temp = fread($fp, $current['stat'][7]);
                     fclose($fp);
                     $crc32 = crc32($temp);
                     if (!isset($current['method']) && $this->options['method'] == 1) {
                         $temp = gzcompress($temp, $this->options['level']);
                         $size = io::strlen($temp) - 6;
                         $temp = io::substr($temp, 2, $size);
                     } else {
                         $size = io::strlen($temp);
                     }
                     $block .= pack("VVVvv", $crc32, $size, $current['stat'][7], io::strlen($current['name2']), 0x0);
                     $block .= $current['name2'];
                     $this->add_data($block);
                     $this->add_data($temp);
                     unset($temp);
                     $central .= pack("VvvvvVVVVvvvvvVV", 0x2014b50, 0x14, $this->options['method'] == 0 ? 0x0 : 0xa, 0x0, isset($current['method']) || $this->options['method'] == 0 ? 0x0 : 0x8, $timedate, $crc32, $size, $current['stat'][7], io::strlen($current['name2']), 0x0, 0x0, 0x0, 0x0, 0x0, $offset);
                     $central .= $current['name2'];
                     $files++;
                     $offset += 30 + io::strlen($current['name2']) + $size;
                 } else {
                     $this->raiseError("Could not open file {$current['name']} for reading. It was not added.");
                 }
             }
         }
     }
     $this->add_data($central);
     $this->add_data(pack("VvvvvVVv", 0x6054b50, 0x0, 0x0, $files, $files, io::strlen($central), $offset, !empty($this->options['comment']) ? io::strlen($this->options['comment']) : 0x0));
     if (!empty($this->options['comment'])) {
         $this->add_data($this->options['comment']);
     }
     chdir($pwd);
     return true;
 }
Esempio n. 7
0
 /**
  * Extract files from the archive
  * 
  * @return true on success
  */
 function extract_files()
 {
     $pwd = getcwd();
     chdir($this->options['basedir']);
     if ($fp = $this->open_archive()) {
         if ($this->options['inmemory'] == 1) {
             $this->files = array();
         }
         while ($block = fread($fp, 512)) {
             $temp = unpack("a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100temp/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp", $block);
             $file = array('name' => $temp['prefix'] . $temp['name'], 'stat' => array(2 => $temp['mode'], 4 => octdec($temp['uid']), 5 => octdec($temp['gid']), 7 => octdec($temp['size']), 9 => octdec($temp['mtime'])), 'checksum' => octdec($temp['checksum']), 'type' => $temp['type'], 'magic' => $temp['magic']);
             if ($file['checksum'] == 0x0) {
                 break;
             } else {
                 /*if ($file['magic'] != "ustar") {
                 			$this->raiseError("This script does not support extracting this type of tar file.");
                 			break;
                 		}*/
                 $block = substr_replace($block, "        ", 148, 8);
             }
             $checksum = 0;
             for ($i = 0; $i < 512; $i++) {
                 $checksum += ord(io::substr($block, $i, 1));
             }
             if ($file['checksum'] != $checksum) {
                 $this->raiseError("Could not extract from {$this->options['name']}, it is corrupt.");
             }
             if ($this->options['inmemory'] == 1) {
                 $file['data'] = @fread($fp, $file['stat'][7]);
                 @fread($fp, 512 - $file['stat'][7] % 512 == 512 ? 0 : 512 - $file['stat'][7] % 512);
                 unset($file['checksum'], $file['magic']);
                 $this->files[] = $file;
             } else {
                 if ($file['type'] == 5) {
                     if (!is_dir($file['name'])) {
                         /*if ($this->options['forceWriting']) {
                         			chmod($file['name'], 1777);
                         		}*/
                         if (!$this->options['dontUseFilePerms']) {
                             @mkdir($file['name'], $file['stat'][2]);
                             //pr($file['name'].' : '.$file['stat'][4]);
                             //pr($file['name'].' : '.$file['stat'][5]);
                             @chown($file['name'], $file['stat'][4]);
                             @chgrp($file['name'], $file['stat'][5]);
                         } else {
                             @mkdir($file['name']);
                         }
                     }
                 } else {
                     if ($this->options['overwrite'] == 0 && file_exists($file['name'])) {
                         $this->raiseError("{$file['name']} already exists.");
                     } else {
                         //check if destination dir exists
                         $dirname = dirname($file['name']);
                         if (!is_dir($dirname)) {
                             CMS_file::makeDir($dirname);
                         }
                         if ($new = @fopen($file['name'], "wb")) {
                             @fwrite($new, @fread($fp, $file['stat'][7]));
                             @fread($fp, 512 - $file['stat'][7] % 512 == 512 ? 0 : 512 - $file['stat'][7] % 512);
                             @fclose($new);
                             //pr($file['name'].' : '.$file['stat'][2]);
                             if (!$this->options['dontUseFilePerms']) {
                                 @chmod($file['name'], $file['stat'][2]);
                                 @chown($file['name'], $file['stat'][4]);
                                 @chgrp($file['name'], $file['stat'][5]);
                             }
                             /*if ($this->options['forceWriting']) {
                             			chmod($file['name'], 0777);
                             		}*/
                         } else {
                             $this->raiseError("Could not open {$file['name']} for writing.");
                         }
                     }
                 }
             }
             unset($file);
         }
     } else {
         $this->raiseError("Could not open file {$this->options['name']}");
     }
     chdir($pwd);
     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;
 }
Esempio n. 9
0
 /**
  * Sets the image. Can be empty. Must have the gif, jpg, jpeg or png extension.
  *
  * @param string $image the image to set
  * @return boolean true on success, false on failure.
  * @access public
  */
 function setImage($image = 'nopicto.gif')
 {
     if (!trim($image)) {
         $image = 'nopicto.gif';
     }
     $extension = io::substr($image, strrpos($image, ".") + 1);
     if (SensitiveIO::isInSet(io::strtolower($extension), array("jpg", "jpeg", "gif", "png"))) {
         $this->_image = $image;
         return true;
     } else {
         $this->_image = 'nopicto.gif';
         return true;
     }
 }
Esempio n. 10
0
 /**
  * Proceeds to archive download
  * 
  * @return binary file content to be downloaded
  */
 function download_file()
 {
     if ($this->options['inmemory'] == 0) {
         $this->raiseError("Can only use download_file() if archive is in memory. Redirect to file otherwise, it is faster.");
         return;
     }
     switch ($this->options['type']) {
         case "zip":
             header("Content-type:application/zip");
             break;
         case "bzip":
             header("Content-type:application/x-compressed");
             break;
         case "gzip":
             header("Content-type:application/x-compressed");
             break;
         case "tar":
             header("Content-type:application/x-tar");
     }
     $header = "Content-disposition: attachment; filename=\"";
     $header .= strstr($this->options['name'], "/") ? io::substr($this->options['name'], strrpos($this->options['name'], "/") + 1) : $this->options['name'];
     $header .= "\"";
     header($header);
     header("Content-length: " . io::strlen($this->CMS_archive));
     header("Content-transfer-encoding: binary");
     header("Pragma: no-cache");
     header("Expires: 0");
     print $this->CMS_archive;
 }
Esempio n. 11
0
 /**
  * Analyse an xhtml identifier for a CMS_forms_field object then return decoded datas
  *
  * @access public
  * @param string $datas base64 encoded xhtml identifier
  * @return array : decoded datas
  */
 function decodeFieldIdDatas($datas)
 {
     return explode('_', base64_decode(io::substr($datas, 1)));
 }
Esempio n. 12
0
$modulesCodeInclude = $modulesCodes->getModulesCodes(MODULE_TREATMENT_TEMPLATES_EDITION_LABELS, PAGE_VISUALMODE_CLIENTSPACES_FORM, $template, array("language" => $cms_language, "user" => $cms_user));
$modulesTab = '';
if (is_array($modulesCodeInclude) && $modulesCodeInclude) {
    foreach ($modulesCodeInclude as $codename => $description) {
        //if user has rights on module
        if ($cms_user->hasModuleClearance($codename, CLEARANCE_MODULE_EDIT)) {
            $module = CMS_modulesCatalog::getByCodename($codename);
            $label = sensitiveIO::sanitizeJSString($module->getLabel($cms_language));
            $description = sensitiveIO::sanitizeJSString($description);
            $modulesTab .= "{\n\t\t\t\ttitle:\t\t\t\t'{$label}',\n\t\t\t\thtml:\t\t\t\t'{$description}'\n\t\t\t},";
        }
    }
}
//remove last comma
if ($modulesTab) {
    $modulesTab = io::substr($modulesTab, 0, -1);
}
$jscontent = <<<END
\tvar helpWindow = Ext.getCmp('{$winId}');
\t//set window title
\thelpWindow.setTitle('{$cms_language->getJsMessage(MESSAGE_PAGE_TITLE)}');
\t//set help button on top of page
\thelpWindow.tools['help'].show();
\t//add a tooltip on button
\tvar propertiesTip = new Ext.ToolTip({
\t\ttarget: \t\thelpWindow.tools['help'],
\t\ttitle: \t\t\t'{$cms_language->getJsMessage(MESSAGE_TOOLBAR_HELP)}',
\t\thtml: \t\t\t'{$cms_language->getJsMessage(MESSAGE_TOOLBAR_HELP_DESC)}',
\t\tdismissDelay:\t0
\t});
Esempio n. 13
0
//
// Search Panel
//
$searchPanel = '';
// Keywords
$searchPanel .= "{\n\tfieldLabel:\t\t'{$cms_language->getJSMessage(MESSAGE_PAGE_BY_NAME_DESCRIPTION)}',\n\txtype:\t\t\t'textfield',\n\tname: \t\t\t'keyword',\n\tvalue:\t\t\t'',\n\tminLength:\t\t3,\n\tanchor:\t\t\t'-20px',\n\tvalidateOnBlur:\tfalse,\n\tlisteners:\t\t{\n\t\t'valid':{\n\t\t\tfn: \t\t\trowWindow.search, \n\t\t\toptions:\t\t{buffer:300}\n\t\t},\n\t\t'invalid':{\n\t\t\tfn: function(field, event) {\n\t\t\t\tif (!isNaN(parseInt(field.getValue()))) {\n\t\t\t\t\tfield.clearInvalid();\n\t\t\t\t\tfield.fireEvent('valid', field);\n\t\t\t\t} else if (!field.getValue()) {\n\t\t\t\t\tfield.clearInvalid();\n\t\t\t\t}\n\t\t\t}, \n\t\t\toptions:\t\t{buffer:300}\n\t\t}\n\t}\n},";
$allGroups = CMS_rowsCatalog::getAllGroups();
natcasesort($allGroups);
if ($allGroups) {
    $columns = sizeof($allGroups) < 2 ? sizeof($allGroups) : 2;
    $searchPanel .= "{\n\t\txtype: \t\t'checkboxgroup',\n\t\tfieldLabel: '{$cms_language->getJSMessage(MESSAGE_PAGE_GROUPS)}',\n\t\tcolumns: \t{$columns},\n\t\titems: [";
    foreach ($allGroups as $aGroup) {
        $searchPanel .= "{boxLabel: '{$aGroup}', inputValue:'{$aGroup}', name: 'groups[]', listeners: {'check':rowWindow.search}},";
    }
    //remove last comma from groups
    $searchPanel = io::substr($searchPanel, 0, -1);
    $searchPanel .= "\n\t\t]\n\t},";
}
$modules = CMS_modulesCatalog::getAll();
if (sizeof($modules) > 1) {
    $modulesDatas = array();
    $modulesDatas['module'] = array(array('id' => 0, 'label' => '-'));
    foreach ($modules as $module) {
        $modulesDatas['module'][] = array('id' => $module->getCodename(), 'label' => $module->getLabel($cms_language));
    }
    //json encode websites datas
    $modulesDatas = sensitiveIO::jsonEncode($modulesDatas);
    $searchPanel .= "{\n\t\txtype:\t\t\t\t'combo',\n\t\tid:\t\t\t\t\t'moduleField',\n\t\tname:\t\t\t\t'module',\n\t\tfieldLabel:\t\t\t'{$cms_language->getJSMessage(MESSAGE_PAGE_MODULES)}',\n\t\tanchor:\t\t\t\t'-20px',\n\t\tforceSelection:\t\ttrue,\n\t\tmode:\t\t\t\t'local',\n\t\ttriggerAction:\t\t'all',\n\t\tvalueField:\t\t\t'id',\n\t\thiddenName: \t\t'module',\n\t\tdisplayField:\t\t'label',\n\t\tstore:\t\t\t\tnew Ext.data.JsonStore({\n\t\t\tid:\t\t\t\t'id',\n\t\t\troot: \t\t\t'module',\n\t\t\tfields: \t\t['id', 'label'],\n\t\t\tdata:\t\t\t{$modulesDatas}\n\t\t}),\n\t\tvalidateOnBlur:\t\tfalse,\n\t\tallowBlank: \t\ttrue,\n\t\tselectOnFocus:\t\ttrue,\n\t\teditable:\t\t\ttrue,\n\t\ttypeAhead:\t\t\ttrue,\n\t\tlisteners:\t\t\t{'valid':rowWindow.search}\n\t},";
}
$searchPanel .= "{\n\txtype:\t\t\t'atmPageField',\n\tfieldLabel:\t\t'{$cms_language->getJSMessage(MESSAGE_PAGE_PAGE)}',\n\tname:\t\t\t'page',\n\tvalue:\t\t\t'',\n\tanchor:\t\t\t'-20px',\n\tallowBlank:\t\ttrue,\n\tvalidateOnBlur:\tfalse,\n\tlisteners:\t\t{'valid':{\n\t\tfn: \t\t\trowWindow.search,\n\t\toptions:\t\t{buffer:300}\n\t}}\n},";
$searchPanel .= "{\n\thideLabel:\t\ttrue,\n\tlabelSeparator:\t'',\n\tlabelAlign:\t\t'left',\n\txtype:\t\t\t'checkbox',\n\tboxLabel: \t\t'{$cms_language->getJSMessage(MESSAGE_PAGE_VIEW_INACTIVE_ROWS)}',\n\tname: \t\t\t'viewinactive',\n\tinputValue:\t\t'1',\n\tchecked:\t\ttrue,\n\tlisteners: \t\t{'check':rowWindow.search}\n}";
Esempio n. 14
0
 /**
  * Sets the value from a formatted date
  *
  * @param string $date The date formatted with the current format
  * @param boolean $canBeNull If set to true, the function won't complain if the date is set to a null value
  * @return boolean true is successful to set it
  * @access public
  */
 function setLocalizedDate($date, $canBeNull = false)
 {
     if (!$this->_format) {
         $this->raiseError("Format not set");
         return false;
     }
     if (!$date) {
         if ($canBeNull) {
             $this->_day = $this->_month = $this->_hours = $this->_minutes = $this->_seconds = "00";
             $this->_year = "0000";
             return true;
         } else {
             $this->raiseError("Date null");
             return false;
         }
     }
     //analyse format
     $year_found = 0;
     switch (io::substr($this->_format, 0, 1)) {
         case "d":
             $day_pos = 0;
             break;
         case "m":
             $month_pos = 0;
             break;
         case "Y":
             $year_pos = 0;
             $year_found = 1;
             break;
     }
     switch (io::substr($this->_format, 2, 1)) {
         case "d":
             $day_pos = 3 + $year_found * 2;
             break;
         case "m":
             $month_pos = 3 + $year_found * 2;
             break;
         case "Y":
             $year_pos = 3;
             $year_found = 1;
             break;
     }
     switch (io::substr($this->_format, 4, 1)) {
         case "d":
             $day_pos = 6 + $year_found * 2;
             break;
         case "m":
             $month_pos = 6 + $year_found * 2;
             break;
         case "Y":
             $year_pos = 6;
             break;
     }
     return $this->setDay(io::substr($date, $day_pos, 2)) && $this->setMonth(io::substr($date, $month_pos, 2)) && $this->setYear(io::substr($date, $year_pos, 4));
 }
Esempio n. 15
0
 /**
  * Return the needed form field tag for current object field
  *
  * @param array $values : parameters values array(parameterName => parameterValue) in :
  *     id : the form field id to set
  * @param multidimentionnal array $tags : xml2Array content of atm-function tag
  * @return string : the form field HTML tag
  * @access public
  */
 function getInput($fieldID, $language, $inputParams)
 {
     //hidden field : use parent method
     if (isset($inputParams['hidden']) && ($inputParams['hidden'] == 'true' || $inputParams['hidden'] == 1)) {
         return parent::getInput($fieldID, $language, $inputParams);
     }
     global $cms_user;
     $params = $this->getParamsValues();
     if (isset($inputParams['prefix'])) {
         $prefixName = $inputParams['prefix'];
     } else {
         $prefixName = '';
     }
     //serialize all htmlparameters
     //$htmlParameters = $this->serializeHTMLParameters($inputParams);
     $html = '';
     //create fieldname
     $fieldName = $prefixName . $this->_field->getID() . '_0';
     //create field value
     $value = $this->_subfieldValues[0]->getValue();
     if ($params['html']) {
         // Insert prefered text editor for textarea field
         $module = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID());
         $toolbarset = !$params['toolbar'] ? $module : $params['toolbar'];
         if (class_exists('CMS_wysiwyg_toolbar')) {
             $toolbar = CMS_wysiwyg_toolbar::getByCode($toolbarset, $cms_user);
             $value = $toolbar->hasModulePlugins() ? CMS_textEditor::parseInnerContent($value, $module) : $value;
         }
         $CKEditor = new CKEditor(PATH_MAIN_WR . '/ckeditor/');
         $CKEditor->returnOutput = true;
         $html .= $CKEditor->editor($fieldName, $value, array('language' => $language->getCode(), 'width' => $params['toolbarWidth'] ? $params['toolbarWidth'] : '100%', 'height' => sensitiveIO::isPositiveInteger($params['toolbarHeight']) ? $params['toolbarHeight'] : 200, 'customConfig' => PATH_MAIN_WR . '/ckeditor/config.php?toolbar=' . $toolbarset));
     } else {
         //serialize all htmlparameters
         $htmlParameters = $this->serializeHTMLParameters($inputParams);
         //append field id to html field parameters (if not already exists)
         $htmlParameters .= !isset($inputParams['id']) ? ' id="' . $prefixName . $this->_field->getID() . '_0"' : '';
         $width = '100%';
         if ($params['toolbarWidth']) {
             $width = io::substr($params['toolbarWidth'], -1, 1) == '%' ? $params['toolbarWidth'] : $params['toolbarWidth'] . 'px';
         }
         $html .= '<textarea type="text" name="' . $fieldName . '"' . $htmlParameters . ' style="width:' . $width . ';height:' . (sensitiveIO::isPositiveInteger($params['toolbarHeight']) ? $params['toolbarHeight'] : 200) . 'px">' . str_replace('<br />', "\n", str_replace(array("\n", "\r"), "", $value)) . '</textarea>' . "\n";
     }
     if (POLYMOD_DEBUG) {
         $html .= ' <span class="admin_text_alert">(Field : ' . $this->_field->getID() . ' - SubField : 0)</span>';
     }
     //append html hidden field which store field name
     if ($html) {
         $html .= '<input type="hidden" name="polymodFields[' . $this->_field->getID() . ']" value="' . $this->_field->getID() . '" />';
     }
     return $html;
 }
Esempio n. 16
0
 /**
  * Do patch installation
  *
  * @param array of install command to do, view documentation for format
  *  This array MUST be checked before by checkInstall method to ensure it format is as correct as possible
  * @param array of excluded commands
  * @return void
  * @access public
  */
 function doInstall(&$array, $excludeCommand = array(), $stopOnErrors = true)
 {
     if (is_array($array)) {
         foreach ($array as $line => $aInstallCheck) {
             $line++;
             //to have the correct line number
             $installParams = array_map("trim", explode("\t", $aInstallCheck));
             if ($installParams[0] != 'ex') {
                 $originalFile = isset($installParams[1]) ? PATH_REALROOT_FS . $installParams[1] : PATH_REALROOT_FS;
                 $patchFile = isset($installParams[1]) ? PATH_TMP_FS . $installParams[1] : PATH_TMP_FS;
             }
             if (!in_array($installParams[0], $excludeCommand)) {
                 //launch installation request
                 switch ($installParams[0]) {
                     case ">":
                         //add or update a file or folder
                         //copy file or folder
                         if (CMS_FILE::copyTo($patchFile, $originalFile)) {
                             $this->_verbose(' -> File ' . $patchFile . ' successfully copied to ' . $originalFile);
                         } else {
                             $this->_report('Error during copy of ' . $patchFile . ' to ' . $originalFile, true);
                             if ($stopOnErrors) {
                                 return;
                             }
                         }
                         if (!isset($installParams[2])) {
                             break;
                         }
                     case "ch":
                         //execute chmod
                         $filesNOK = $this->applyChmod($installParams[2], $originalFile);
                         if (!$filesNOK) {
                             switch ($installParams[2]) {
                                 case 'r':
                                     $this->_verbose(' -> File(s) ' . $originalFile . ' are readable.');
                                     break;
                                 case 'w':
                                     $this->_verbose(' -> File(s) ' . $originalFile . ' are writable.');
                                     break;
                                 case 'x':
                                     $this->_verbose(' -> File(s) ' . $originalFile . ' are executable.');
                                     break;
                                 default:
                                     $this->_verbose(' -> File(s) ' . $originalFile . ' successfully chmoded with value ' . $installParams[2]);
                                     break;
                             }
                         } else {
                             $this->_report('Error during chmod operation of ' . $originalFile . '. Can\'t apply chmod value \'' . $installParams[2] . '\' on files :<br />' . $filesNOK . '<br />', true);
                             //do not stop on chmod error : only report them
                             //if ($stopOnErrors) return;
                         }
                         break;
                     case "<":
                         //delete a file or folder (recursively)
                         if (file_exists($originalFile) && CMS_FILE::deleteFile($originalFile)) {
                             $this->_verbose(' -> File ' . $originalFile . ' successfully deleted');
                         } else {
                             $this->_verbose(' -> Cannot delete ' . $originalFile . '. It does not exists.');
                         }
                         break;
                     case "+":
                         //concatenate module xml file
                         //load destination module parameters
                         $module = CMS_modulesCatalog::getByCodename($installParams[2]);
                         $moduleParameters = $module->getParameters(false, true);
                         //load the XML data of the source the files
                         $sourceXML = new CMS_file($patchFile);
                         $domdocument = new CMS_DOMDocument();
                         try {
                             $domdocument->loadXML($sourceXML->readContent("string"));
                         } catch (DOMException $e) {
                         }
                         $paramsTags = $domdocument->getElementsByTagName('param');
                         $sourceParameters = array();
                         foreach ($paramsTags as $aTag) {
                             $name = $aTag->hasAttribute('name') ? $aTag->getAttribute('name') : '';
                             $type = $aTag->hasAttribute('type') ? $aTag->getAttribute('type') : '';
                             $sourceParameters[$name] = array(CMS_DOMDocument::DOMElementToString($aTag, true), $type);
                         }
                         //merge the two tables of parameters
                         $resultParameters = array_merge($sourceParameters, $moduleParameters);
                         //set new parameters to the module
                         if ($module->setAndWriteParameters($resultParameters)) {
                             $this->_verbose(' -> File ' . $patchFile . ' successfully merged with module ' . $installParams[2] . ' parameters');
                         } else {
                             $this->_report('Error during merging of ' . $patchFile . ' with module ' . $installParams[2] . ' parameters', true);
                             if ($stopOnErrors) {
                                 return;
                             }
                         }
                         break;
                     case "x":
                         //execute SQL or PHP file
                         //exec sql script with help of some phpMyAdmin classes
                         if (io::substr($patchFile, -4, 4) == '.sql') {
                             if ($this->executeSqlScript($patchFile)) {
                                 $this->_verbose(' -> File ' . $patchFile . ' successfully executed');
                             } else {
                                 $this->_report('Error during execution of ' . $patchFile, true);
                                 if ($stopOnErrors) {
                                     return;
                                 }
                             }
                         } elseif (io::substr($patchFile, -4, 4) == '.php') {
                             //exec php script
                             $executionReturn = $this->executePhpScript($patchFile);
                             if ($executionReturn === false) {
                                 $this->_report('Error during execution of ' . $patchFile, true);
                                 if ($stopOnErrors) {
                                     return;
                                 }
                             } else {
                                 $executionReturn = $executionReturn ? ' -> Return :<br /><div style="border:1px;background-color:#000080;color:#C0C0C0;padding:5px;">' . $executionReturn . '</div><br />' : '';
                                 $this->_report(' -> File ' . $patchFile . ' executed<br />' . $executionReturn);
                             }
                         }
                         break;
                     case "co":
                         //execute change owner
                         $filesNOK = $this->changeOwner($installParams[2], $originalFile);
                         if (!$filesNOK) {
                             $this->_verbose(' -> Owner of file(s) ' . $originalFile . ' successfully changed to ' . $installParams[2]);
                         } else {
                             $this->_report('Error during operation on ' . $originalFile . '. Can\'t change owner to \'' . $installParams[2] . '\' on files :<br />' . $filesNOK . '<br />', true);
                             if ($stopOnErrors) {
                                 return;
                             }
                         }
                         break;
                     case "cg":
                         //execute change group
                         $filesNOK = $this->changeGroup($installParams[2], $originalFile);
                         if (!$filesNOK) {
                             $this->_verbose(' -> Group of file(s) ' . $originalFile . ' successfully changed to ' . $installParams[2]);
                         } else {
                             $this->_report('Error during operation on ' . $originalFile . '. Can\'t change group to \'' . $installParams[2] . '\' on files :<br />' . $filesNOK . '<br />', true);
                             if ($stopOnErrors) {
                                 return;
                             }
                         }
                         break;
                     case "rc":
                         $this->automneGeneralScript();
                         break;
                     case "htaccess":
                         $installParams[1] = io::substr($installParams[1], -1) == '/' ? io::substr($installParams[1], 0, -1) : $installParams[1];
                         $pathes = glob(PATH_REALROOT_FS . $installParams[1]);
                         if ($pathes) {
                             foreach ($pathes as $path) {
                                 if ($installParams[2] == 'root' && file_exists($path . '/.htaccess')) {
                                     //for root file, if already exists, only replace ErrorDocument instructions to set correct path
                                     $htaccessFile = new CMS_file($path . '/.htaccess');
                                     $lines = $htaccessFile->readContent('array', '');
                                     foreach ($lines as $key => $line) {
                                         if (substr($line, 0, 13) == 'ErrorDocument') {
                                             list($errorDoc, $code, $file) = preg_split("/[\\s]+/", $line);
                                             if ($code == '404') {
                                                 $lines[$key] = 'ErrorDocument 404 ' . PATH_REALROOT_WR . '/404.php' . "\n";
                                             } elseif ($code == '403') {
                                                 $lines[$key] = 'ErrorDocument 403 ' . PATH_REALROOT_WR . '/403.php' . "\n";
                                             }
                                         }
                                     }
                                     $htaccessFile->setContent(implode('', $lines), false);
                                     if ($htaccessFile->writeToPersistence()) {
                                         $this->_report('File ' . $path . '/.htaccess (' . $installParams[2] . ') successfully updated');
                                     } else {
                                         $this->_report('Error during operation on ' . $path . '/.htaccess. Can\'t write file.<br />', true);
                                     }
                                 } else {
                                     if (is_dir($path) && CMS_file::makeWritable($path)) {
                                         if (CMS_file::copyTo(PATH_HTACCESS_FS . '/htaccess_' . $installParams[2], $path . '/.htaccess')) {
                                             CMS_file::chmodFile(FILES_CHMOD, $path . '/.htaccess');
                                             $this->_report('File ' . $path . '/.htaccess (' . $installParams[2] . ') successfully writen');
                                         } else {
                                             $this->_report('Error during operation on ' . $path . '/.htaccess. Can\'t write file.<br />', true);
                                             if ($stopOnErrors) {
                                                 return;
                                             }
                                         }
                                     } else {
                                         $this->_report('Error during operation. ' . $path . ' must be a writable directory.<br />', true);
                                         if ($stopOnErrors) {
                                             return;
                                         }
                                     }
                                 }
                             }
                         }
                         break;
                     default:
                         if (io::substr($installParams[0], 0, 1) != '#') {
                             $this->raiseError("Unknown parameter : " . $installParams[0]);
                             return false;
                         }
                         break;
                 }
             } else {
                 $this->_report('Error during operation of "' . $aInstallCheck . '". Command execution is not allowed.<br />', true);
                 if ($stopOnErrors) {
                     return;
                 }
             }
         }
     } else {
         $this->raiseError("Param must be an array");
         return false;
     }
     //at end of any patch process, update Automne subversion to force reload of JS and CSS cache from client
     if (@file_put_contents(PATH_MAIN_FS . "/SUBVERSION", time()) !== false) {
         CMS_file::chmodFile(FILES_CHMOD, PATH_MAIN_FS . "/SUBVERSION");
     }
 }
Esempio n. 17
0
            $paramFields .= "{\n\t\t\t\tfieldLabel: '{$fieldLabel}',\n\t\t\t\tname: \t\t'params[{$labelCode}]',\n\t\t\t\tvalue:\t\t'{$value}',\n\t\t\t\tvtype:\t\t'email'\n\t\t\t},";
            break;
        case 'integer':
            $paramFields .= "{\n\t\t\t\txtype:\t\t'numberfield',\n\t\t\t\tfieldLabel: '{$fieldLabel}',\n\t\t\t\tname: \t\t'params[{$labelCode}]',\n\t\t\t\tvalue:\t\t'{$value}'\n\t\t\t},";
            break;
        case 'boolean':
            $checked = $value ? 'checked:true,' : '';
            $paramFields .= "{\n\t\t\t\t" . $checked . "\n\t\t\t\tboxLabel: \t\t'{$fieldLabel}',\n\t\t\t\tname: \t\t\t'params[{$labelCode}]',\n\t\t\t\txtype:\t\t\t'checkbox',\n\t\t\t\tinputValue:\t\t'1',\n\t\t\t\tfieldLabel: \t'',\n\t\t\t\thideLabel:\t\ttrue,\n\t\t\t\tlabelSeparator:\t''\n\t\t\t},";
            break;
        case 'text':
        default:
            $paramFields .= "{\n\t\t\t\tfieldLabel: '{$fieldLabel}',\n\t\t\t\tname: \t\t'params[{$labelCode}]',\n\t\t\t\tvalue:\t\t'{$value}'\n\t\t\t},";
            break;
    }
}
$paramFields = io::substr($paramFields, 0, -1);
$jscontent = <<<END
\tvar moduleParamWindow = Ext.getCmp('{$winId}');
\t//set window title
\tmoduleParamWindow.setTitle('{$pageLabel}');
\t//set help button on top of page
\tmoduleParamWindow.tools['help'].show();
\t//add a tooltip on button
\tvar propertiesTip = new Ext.ToolTip({
\t\ttarget: \t\tmoduleParamWindow.tools['help'],
\t\ttitle: \t\t\t'{$cms_language->getJsMessage(MESSAGE_TOOLBAR_HELP)}',
\t\thtml: \t\t\t'{$cms_language->getJsMessage(MESSAGE_TOOLBAR_HELP_MESSAGE)}',
\t\tdismissDelay:\t0
    });
\t
\t//create center panel
Esempio n. 18
0
 /**
  * Get subfields definition for current object
  *
  * @param integer (can be null - for compatibility only) $objectID the object ID who requests these infos
  * @return array(integer "subFieldID" =>  array("type" => string [integer|string|text|date], "objectID" => integer, "fieldID" => integer, "subFieldID" => integer))
  * @access public
  */
 function getSubFieldsDefinition($objectID = "")
 {
     $subFieldsDefinition = array();
     foreach (array_keys($this->_objectValues) as $subFieldID) {
         if (!is_a($this->_objectValues[$subFieldID], 'CMS_multi_poly_object')) {
             $subFieldDefinition = $this->_objectValues[$subFieldID]->getSubFieldsDefinition($this->_ID);
         } else {
             $type = $this->_objectFieldsDefinition[$subFieldID]->getValue('type');
             $subFieldDefinition = CMS_multi_poly_object::getSubFieldsDefinition(io::substr($type, 6), $this->_ID, $this->_objectFieldsDefinition[$subFieldID]);
         }
         $subFieldsDefinition = array_merge($subFieldsDefinition, $subFieldDefinition);
     }
     return $subFieldsDefinition;
 }
function checkCatId($catId)
{
    return io::strpos($catId, 'cat') === 0 && sensitiveIO::isPositiveInteger(io::substr($catId, 3));
}
Esempio n. 20
0
 /**
  * Return an echapped input to use into an SQL query
  *
  * @param string $input The string to echap
  * @return string echapped query
  * @access public
  */
 static function echap($input)
 {
     try {
         $db = is_array(self::$_connection) ? current(self::$_connection) : new PDO(APPLICATION_DB_DSN, APPLICATION_DB_USER, APPLICATION_DB_PASSWORD, array(PDO::ATTR_PERSISTENT => APPLICATION_DB_PERSISTENT_CONNNECTION, PDO::ERRMODE_EXCEPTION => true, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true));
     } catch (PDOException $e) {
         CMS_query::raiseError($e->getMessage());
         exit;
     }
     return io::substr($db->quote($input), 1, -1);
 }
Esempio n. 21
0
    $pubEnd = $item->getPublicationDateEnd(false)->getLocalizedDate($cms_language->getDateFormat());
    $dateMask = $cms_language->getDateFormatMask();
    $itemFields .= "{\n\t\ttitle:\t\t\t'{$cms_language->getJSMessage(MESSAGE_PAGE_SUBTITLE_WEBSITE_PUBS, false, MOD_POLYMOD_CODENAME)}',\n\t\txtype:\t\t\t'fieldset',\n\t\tautoHeight:\t\ttrue,\n\t\tdefaultType:\t'datefield',\n\t\tlabelWidth:\t\t140,\n\t\tdefaults:\t\t{\n\t\t\twidth:\t\t\t100,\n\t\t\tanchor:\t\t\t'',\n\t\t\tformat:\t\t\t'{$cms_language->getDateFormat()}'\n\t\t},\n\t\titems:\t\t\t[{\n\t\t\tfieldLabel:\t'<span ext:qtip=\"{$cms_language->getJSMessage(MESSAGE_PAGE_FIELD_DATE_COMMENT, array($dateMask))}\" class=\"atm-help\"><span class=\"atm-red\">*</span> {$cms_language->getJSMessage(MESSAGE_PAGE_FIELD_PUBDATE_BEG)}</span>',\n\t\t\tname:\t\t'pubStart',\n\t\t\tallowBlank:\tfalse,\n\t\t\tvalue:\t\t'{$pubStart}'\n\t\t},{\n\t\t\tfieldLabel:\t'<span ext:qtip=\"{$cms_language->getJSMessage(MESSAGE_PAGE_FIELD_DATE_COMMENT, array($dateMask))}\" class=\"atm-help\">{$cms_language->getJSMessage(MESSAGE_PAGE_FIELD_PUBDATE_END)}</span>',\n\t\t\tname:\t\t'pubEnd',\n\t\t\tallowBlank:\ttrue,\n\t\t\tvalue:\t\t'{$pubEnd}'\n\t\t}]\n\t},";
    if ($cms_user->hasValidationClearance($codename)) {
        $saveAndValidate = ",{\n\t\t\tid:\t\t\t\t'{$winId}-save-validate',\n\t\t\txtype:\t\t\t'button',\n\t\t\ttext:\t\t\t'{$cms_language->getJSMessage(MESSAGE_PAGE_PUBLISH)}',\n\t\t\ttooltip:\t\t'{$cms_language->getJSMessage(MESSAGE_PAGE_SAVE_AND_VALID_DESC, false, MOD_POLYMOD_CODENAME)}',\n\t\t\ticonCls:\t\t'atm-pic-validate',\n\t\t\tname:\t\t\t'submitAndValidAdmin',\n\t\t\thandler:\t\tsubmitItem.createDelegate(this, ['save-validate']),\n\t\t\tscope:\t\t\tthis\n\t\t}";
        $saveIconCls = 'atm-pic-draft-validation';
        $saveTooltip = $cms_language->getJSMessage(MESSAGE_PAGE_SAVE_PRIMARY_DESC, false, MOD_POLYMOD_CODENAME);
    }
    $saveLabel = $cms_language->getJSMessage(MESSAGE_PAGE_SUBMIT_TO_VALID);
} else {
    $saveLabel = $cms_language->getJSMessage(MESSAGE_PAGE_PUBLISH);
    $saveIconCls = 'atm-pic-validate';
    $saveTooltip = $cms_language->getJSMessage(MESSAGE_PAGE_SAVE_DESC, false, MOD_POLYMOD_CODENAME);
}
//remove last comma
$itemFields = io::substr($itemFields, 0, -1);
$itemControler = PATH_ADMIN_MODULES_WR . '/' . MOD_POLYMOD_CODENAME . '/items-controler.php';
$jscontent = <<<END
\tvar window = Ext.getCmp('{$winId}');
\t//set window title
\twindow.setTitle('{$winLabel}');
\t//set help button on top of page
\twindow.tools['help'].show();
\t//add a tooltip on button
\tvar propertiesTip = new Ext.ToolTip({
\t\ttarget:\t\t window.tools['help'],
\t\ttitle:\t\t\t '{$cms_language->getJsMessage(MESSAGE_TOOLBAR_HELP)}',
\t\thtml:\t\t\t '{$cms_language->getJSMessage(MESSAGE_TOOLBAR_HELP_DESC, array($objectLabel), MOD_POLYMOD_CODENAME)}',
\t\tdismissDelay:\t0
\t});
\twindow.objectId = '{$itemId}';
Esempio n. 22
0
                                        }
                                    } else {
                                        $addItem = false;
                                        $cms_message .= $cms_language->getMessage(MESSAGE_PAGE_SEARCH_FIELD_ERROR, array($varId, $row->getLabel()), MOD_POLYMOD_CODENAME) . "\n";
                                    }
                                } else {
                                    $addItem = false;
                                    $cms_message .= $cms_language->getMessage(MESSAGE_PAGE_SEARCH_FIELDTYPE_ERROR, array($varId, $row->getLabel(), $paramType), MOD_POLYMOD_CODENAME) . "\n";
                                }
                            } else {
                                $addItem = false;
                                $cms_message .= $cms_language->getMessage(MESSAGE_PAGE_SEARCH_FIELDTYPE_ERROR, array($varId, $row->getLabel(), $paramType), MOD_POLYMOD_CODENAME) . "\n";
                            }
                        } else {
                            // Assume it's an object
                            $objectDefinitionId = io::substr($varAttributes['vartype'], 9, -3);
                            $object = CMS_poly_object_catalog::getObjectDefinition($objectDefinitionId);
                            $item = array('fieldLabel' => $label, 'name' => 'value[var][' . $varId . '][' . $varName . ']', 'hiddenName' => 'value[var][' . $varId . '][' . $varName . ']', 'anchor' => '99%', 'xtype' => 'atmCombo', 'forceSelection' => true, 'mode' => 'remote', 'valueField' => 'id', 'displayField' => 'label', 'triggerAction' => 'all', 'allowBlank' => !$mandatory, 'selectOnFocus' => true, 'editable' => true, 'typeAhead' => true, 'value' => $value, 'store' => array('url' => PATH_ADMIN_MODULES_WR . '/' . MOD_POLYMOD_CODENAME . '/list-objects.php', 'baseParams' => array('objectId' => $object->getID(), 'module' => $codename), 'root' => 'objects', 'fields' => array('id', 'label')));
                        }
                        break;
                }
            }
            if ($addItem) {
                $blockVarContent[] = $item;
            }
        }
    }
    if ($blockVarContent) {
        $items[] = array('title' => $cms_language->getMessage(MESSAGE_VAR_SUBTITLE, null, MOD_POLYMOD_CODENAME), 'xtype' => 'fieldset', 'autoHeight' => true, 'defaults' => array('anchor' => '97%'), 'items' => $blockVarContent);
    }
}
Esempio n. 23
0
 /**
  * Get the page https status
  *
  * @return boolean
  * @access public
  */
 function isHTTPS()
 {
     if (io::substr($this->getWebsite()->getURL(true), 0, 8) == "https://") {
         return true;
     } else {
         return ALLOW_SPECIFIC_PAGE_HTTPS && $this->_https ? true : false;
     }
 }
Esempio n. 24
0
 /**
  * Return the module CSS files
  *
  * @return array : the module css file in /css/modules/codename
  * @access public
  */
 function getCSSFiles($pageId = '', $allFiles = false)
 {
     $files = array();
     $medias = array('all', 'aural', 'braille', 'embossed', 'handheld', 'print', 'projection', 'screen', 'tty', 'tv');
     //get generic files
     foreach ($medias as $media) {
         if ($media == 'all') {
             if (file_exists(PATH_CSS_FS . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $this->_codename . '.css')) {
                 $files['all'][] = str_replace(DIRECTORY_SEPARATOR, '/', str_replace(PATH_REALROOT_FS . '/', '', PATH_CSS_FS . '/modules/' . $this->_codename . '.css'));
             }
         }
         if (file_exists(PATH_CSS_FS . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $this->_codename . '-' . $media . '.css')) {
             $files[$media][] = str_replace(DIRECTORY_SEPARATOR, '/', str_replace(PATH_REALROOT_FS . '/', '', PATH_CSS_FS . '/modules/' . $this->_codename . '-' . $media . '.css'));
         }
     }
     //get subdir files if any
     $dirname = PATH_CSS_FS . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $this->_codename;
     if (@is_dir($dirname)) {
         try {
             //all subdirs or only this dir
             $dir = $allFiles ? new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dirname), RecursiveIteratorIterator::CHILD_FIRST) : new DirectoryIterator($dirname);
             foreach ($dir as $file) {
                 if ($file->isFile() && io::substr($file->getFilename(), -4) == ".css") {
                     $found = false;
                     foreach ($medias as $media) {
                         if (io::substr($file->getFilename(), -5 - strlen($media)) == '-' . $media . '.css') {
                             $files[$media][] = str_replace(DIRECTORY_SEPARATOR, '/', str_replace(PATH_REALROOT_FS . '/', '', $file->getPathname()));
                             $found = true;
                         }
                     }
                     if (!$found) {
                         $files['all'][] = str_replace(DIRECTORY_SEPARATOR, '/', str_replace(PATH_REALROOT_FS . '/', '', $file->getPathname()));
                     }
                 }
             }
         } catch (Exception $e) {
         }
     }
     //get website files if any
     if (!$allFiles && io::isPositiveInteger($pageId)) {
         $page = CMS_tree::getPageById($pageId);
         if ($page) {
             $website = $page->getWebsite();
             if ($website) {
                 if (@is_dir($dirname . DIRECTORY_SEPARATOR . $website->getCodename())) {
                     try {
                         foreach (new DirectoryIterator($dirname . DIRECTORY_SEPARATOR . $website->getCodename()) as $file) {
                             if ($file->isFile() && io::substr($file->getFilename(), -4) == ".css") {
                                 $found = false;
                                 foreach ($medias as $media) {
                                     if (io::substr($file->getFilename(), -5 - strlen($media)) == '-' . $media . '.css') {
                                         $files[$media][] = str_replace(DIRECTORY_SEPARATOR, '/', str_replace(PATH_REALROOT_FS . '/', '', $file->getPathname()));
                                         $found = true;
                                     }
                                 }
                                 if (!$found) {
                                     $files['all'][] = str_replace(DIRECTORY_SEPARATOR, '/', str_replace(PATH_REALROOT_FS . '/', '', $file->getPathname()));
                                 }
                             }
                         }
                     } catch (Exception $e) {
                     }
                 }
             }
         }
     }
     return $files;
 }
Esempio n. 25
0
 /**
  * Sets the external link
  * Reset the target to "_blank"
  *
  * @param string $url The url to set
  * @return boolean true on success, false on failure
  * @access public
  */
 function setExternalLink($url)
 {
     if (io::substr($url, 0, 4) == "http" || io::substr($url, 0, 3) == "ftp" || io::substr($url, 0, 6) == "mailto" || io::substr($url, 0, 1) == "/") {
         if ($url != 'http://') {
             $this->_externalLink = $url;
         } else {
             $this->_externalLink = '';
         }
     } elseif ($url) {
         $this->_externalLink = 'http://' . $url;
     }
     if ($url != '') {
         $this->_target = '_blank';
     }
     return true;
 }
Esempio n. 26
0
 /**
  * Return a list of all objects names of given type
  *
  * @param boolean $public are the needed datas public ? (default false)
  * @param array $searchConditions, search conditions to add. Format : array(conditionType => conditionValue)
  * @return array(integer objectID => string objectName)
  * @access public
  * @static
  */
 function getListOfNamesForObject($public = false, $searchConditions = array())
 {
     return CMS_poly_object_catalog::getListOfNamesForObject(io::substr($this->_field->getValue('type'), 6), $public, $searchConditions);
 }
Esempio n. 27
0
 /**
  * Duplicate this block
  * Used to duplicate a CMS_page.
  *
  * @param CMS_page $destinationPage, the page receiving a copy of this block
  * @param boolean $public The precision needed for USERSPACE location
  * @return CMS_block object
  */
 function duplicate(&$destinationPage, $public = false)
 {
     if (SensitiveIO::isPositiveInteger($this->_dbID) && $this->_file) {
         $table = $this->_getDataTableName(RESOURCE_LOCATION_USERSPACE, $public);
         //Copy linked file
         //In new file name, delete reference to old page and add refernce to new one
         $_newFilename = "p" . $destinationPage->getID() . io::substr($this->_file, io::strpos($this->_file, "_"), io::strlen($this->_file));
         if (@is_file(PATH_MODULES_FILES_STANDARD_FS . "/edited/" . $this->_file) && @copy(PATH_MODULES_FILES_STANDARD_FS . "/edited/" . $this->_file, PATH_MODULES_FILES_STANDARD_FS . "/edited/" . $_newFilename) && @chmod(PATH_MODULES_FILES_STANDARD_FS . "/edited/" . $_newFilename, octdec(FILES_CHMOD))) {
             //Public
             if ($public) {
                 if (!@copy(PATH_MODULES_FILES_STANDARD_FS . "/public/" . $this->_file, PATH_MODULES_FILES_STANDARD_FS . "/public/" . $_newFilename) || !@chmod(PATH_MODULES_FILES_STANDARD_FS . "/public/" . $_newFilename, octdec(FILES_CHMOD))) {
                     $this->raiseError("Duplicate, copy of new file failed : " . PATH_MODULES_FILES_STANDARD_FS . "/public/" . $_newFilename);
                 }
             }
             $_newEnlargedFilename = '';
             //With enlarged file
             if ($this->_enlargedFile != '') {
                 $_newEnlargedFilename = "p" . $destinationPage->getID() . io::substr($this->_enlargedFile, io::strpos($this->_enlargedFile, "_"), io::strlen($this->_enlargedFile));
                 //Edited
                 if (!@copy(PATH_MODULES_FILES_STANDARD_FS . "/edited/" . $this->_enlargedFile, PATH_MODULES_FILES_STANDARD_FS . "/edited/" . $_newEnlargedFilename) || !@chmod(PATH_MODULES_FILES_STANDARD_FS . "/edited/" . $_newEnlargedFilename, octdec(FILES_CHMOD))) {
                     $this->raiseError("Duplicate, copy of new enlarged file failed : " . PATH_MODULES_FILES_STANDARD_FS . "/edited/" . $_newEnlargedFilename);
                 }
                 //Public
                 if ($public) {
                     if (!@copy(PATH_MODULES_FILES_STANDARD_FS . "/public/" . $this->_enlargedFile, PATH_MODULES_FILES_STANDARD_FS . "/public/" . $_newEnlargedFilename) || !@chmod(PATH_MODULES_FILES_STANDARD_FS . "/public/" . $_newEnlargedFilename, octdec(FILES_CHMOD))) {
                         $this->raiseError("Duplicate, copy of new enlarged file failed : " . PATH_MODULES_FILES_STANDARD_FS . "/public/" . $_newEnlargedFilename);
                     }
                 }
             }
             //Save new datas
             $str_set = "\n\t\t\t\t\t\tpage='" . $destinationPage->getID() . "',\n\t\t\t\t\t\tclientSpaceID='" . $this->_clientSpaceID . "',\n\t\t\t\t\t\trowID='" . $this->_rowID . "',\n\t\t\t\t\t\tblockID='" . $this->_tagID . "',\n\t\t\t\t\t\tlabel='" . SensitiveIO::sanitizeSQLString(SensitiveIO::stripPHPTags($this->_label)) . "',\n\t\t\t\t\t\tfile='" . SensitiveIO::sanitizeSQLString(SensitiveIO::stripPHPTags($_newFilename)) . "',\n\t\t\t\t\t\texternalLink='" . SensitiveIO::sanitizeSQLString(SensitiveIO::stripPHPTags($this->_externalLink)) . "',\n\t\t\t\t\t\tenlargedFile='" . SensitiveIO::sanitizeSQLString(SensitiveIO::stripPHPTags($_newEnlargedFilename)) . "'\n\t\t\t\t";
             $sql = "\n\t\t\t\t\tinsert into\n\t\t\t\t\t\t" . $table . "\n\t\t\t\t\tset\n\t\t\t\t\t\t" . $str_set . "\n\t\t\t\t";
             $q = new CMS_query($sql);
             if (!$q->hasError()) {
                 //Table Edition
                 $sql = "\n\t\t\t\t\t\tinsert into\n\t\t\t\t\t\t\t" . $this->_getDataTableName(RESOURCE_LOCATION_EDITION, false) . "\n\t\t\t\t\t\tset\n\t\t\t\t\t\t\tid='" . $q->getLastInsertedID() . "',\n\t\t\t\t\t\t\t" . $str_set . "\n\t\t\t\t\t";
                 $q = new CMS_query($sql);
                 return !$q->hasError();
             } else {
                 $this->raiseError("Duplicate, SQL insertion of new filename failed : " . $sql);
             }
         } else {
             $this->raiseError("Duplicate, copy of file failed :" . PATH_MODULES_FILES_STANDARD_FS . "/edited/" . $this->_file);
         }
     }
     return false;
 }
Esempio n. 28
0
 /**
  * Start the scripts process queue.
  * Remove the lock file then relaunch the script if force is true
  *
  * @param boolean $force Set to true if you wish to remove the lock file before launch
  * @return void
  * @access public
  * @static
  */
 static function startScript($force = false)
 {
     if (USE_BACKGROUND_REGENERATOR) {
         $forceRestart = '';
         if ($force) {
             $forceRestart = ' -F';
         } elseif (processManager::hasRunningScript()) {
             return false;
         }
         //test if we're on windows or linux, for the output redirection
         if (APPLICATION_IS_WINDOWS) {
             if (realpath(PATH_PHP_CLI_WINDOWS) === false) {
                 CMS_grandFather::raiseError("Unknown CLI location : " . PATH_PHP_CLI_WINDOWS . ", please check your configuration.");
                 return false;
             }
             // Create the BAT file
             $command = '@echo off' . "\r\n" . 'start /B /LOW ' . realpath(PATH_PHP_CLI_WINDOWS) . ' ' . realpath(PATH_PACKAGES_FS . '\\scripts\\script.php') . ' -m ' . REGENERATION_THREADS . $forceRestart;
             $replace = array('program files (x86)' => 'progra~2', 'program files' => 'progra~1', 'documents and settings' => 'docume~1');
             $command = str_ireplace(array_keys($replace), $replace, $command);
             if (!@touch(PATH_WINDOWS_BIN_FS . "/script.bat")) {
                 CMS_grandFather::_raiseError("CMS_scriptsManager : startScript : Create file error : " . PATH_WINDOWS_BIN_FS . "/script.bat");
                 return false;
             }
             $fh = @fopen(PATH_WINDOWS_BIN_FS . "/script.bat", "wb");
             if (is_resource($fh)) {
                 if (!@fwrite($fh, $command, io::strlen($command))) {
                     CMS_grandFather::raiseError("Save file error : script.bat");
                 }
                 @fclose($fh);
             }
             $WshShell = new COM("WScript.Shell");
             $oExec = $WshShell->Run(str_ireplace(array_keys($replace), $replace, realpath(PATH_WINDOWS_BIN_FS . '\\script.bat')), 0, false);
         } else {
             $error = '';
             if (!defined('PATH_PHP_CLI_UNIX') || !PATH_PHP_CLI_UNIX) {
                 $return = CMS_patch::executeCommand('which php 2>&1', $error);
                 if ($error) {
                     CMS_grandFather::raiseError('Error when finding php CLI with command "which php", please check your configuration : ' . $error);
                     return false;
                 }
                 if (io::substr($return, 0, 1) != '/') {
                     CMS_grandFather::raiseError('Can\'t find php CLI with command "which php", please check your configuration.');
                     return false;
                 }
                 $return = CMS_patch::executeCommand("cd " . PATH_REALROOT_FS . "; php " . PATH_PACKAGES_FS . "/scripts/script.php -m " . REGENERATION_THREADS . $forceRestart . " > /dev/null 2>&1 &", $error);
                 if ($error) {
                     CMS_grandFather::raiseError('Error during execution of script command (cd ' . PATH_REALROOT_FS . '; php ' . PATH_PACKAGES_FS . '/scripts/script.php -m ' . REGENERATION_THREADS . $forceRestart . '), please check your configuration : ' . $error);
                     return false;
                 }
             } else {
                 $return = CMS_patch::executeCommand(PATH_PHP_CLI_UNIX . ' -v 2>&1', $error);
                 if ($error) {
                     CMS_grandFather::raiseError('Error when testing php CLI with command "' . PATH_PHP_CLI_UNIX . ' -v", please check your configuration : ' . $error);
                     return false;
                 }
                 if (io::strpos(io::strtolower($return), '(cli)') === false) {
                     CMS_grandFather::raiseError(PATH_PHP_CLI_UNIX . ' is not the CLI version');
                     return false;
                 }
                 $return = CMS_patch::executeCommand("cd " . PATH_REALROOT_FS . "; " . PATH_PHP_CLI_UNIX . " " . PATH_PACKAGES_FS . "/scripts/script.php -m " . REGENERATION_THREADS . $forceRestart . " > /dev/null 2>&1 &", $error);
                 if ($error) {
                     CMS_grandFather::raiseError('Error during execution of script command (cd ' . PATH_REALROOT_FS . '; ' . PATH_PHP_CLI_UNIX . ' ' . PATH_PACKAGES_FS . '/scripts/script.php -m ' . REGENERATION_THREADS . $forceRestart . '), please check your configuration : ' . $error);
                     return false;
                 }
             }
             //CMS_grandFather::log($return);
             //CMS_grandFather::log("cd ".PATH_REALROOT_FS."; php ".PATH_PACKAGES_FS."/scripts/script.php -m ".REGENERATION_THREADS.$forceRestart." > /dev/null 2>&1 &");
             //@system("cd ".PATH_REALROOT_FS."; php ".PATH_PACKAGES_FS."/scripts/script.php -m ".REGENERATION_THREADS.$forceRestart." > /dev/null 2>&1 &");
         }
     } else {
         CMS_session::setSessionVar('start_script', true);
     }
 }
Esempio n. 29
0
    /**
     * Get the HTML form given the block HTML example data.
     *
     * @param CMS_language &$language The language of the administration frontend
     * @param CMS_page &$page The page which contains the client space
     * @param CMS_clientSpace &$clientSpace The client space which contains the row
     * @param CMS_row &$row The row which contains the block
     * @param integer $blockID The tag ID of the block
     * @param string $data The data to show as example
     * @return string The HTML form which can send to the page that will modify the block
     * @access private
     */
    protected function _getHTMLForm($language, &$page, &$clientSpace, &$row, $blockID, $data)
    {
        global $cms_user;
        //append atm-block class and block-id to all first level tags found in block datas
        $domdocument = new CMS_DOMDocument();
        try {
            $domdocument->loadXML('<block>' . $data . '</block>');
        } catch (DOMException $e) {
            $this->raiseError('Parse error for ' . get_class($this) . ' : Page ' . $page->getID() . ' - Row "' . $row->getTagID() . '" - Block "' . $blockID . '" : ' . $e->getMessage());
            $data = '<div class="atm-error-block atm-block-helper">' . $language->getMessage(self::MESSAGE_BLOCK_CONTENT_ERROR) . '</div>';
            $domdocument = new CMS_DOMDocument();
            $domdocument->loadXML('<block>' . $data . '</block>');
        }
        $blockNodes = $domdocument->getElementsByTagName('block');
        if ($blockNodes->length == 1) {
            $blockXML = $blockNodes->item(0);
        }
        //check for valid tags nodes inside current block tag
        $hasNode = false;
        foreach ($blockXML->childNodes as $blockChildNode) {
            //scripts tags and p tags are not correctly handled by javascript
            if (is_a($blockChildNode, 'DOMElement') && $blockChildNode->tagName != 'script') {
                $hasNode = true;
            }
        }
        foreach ($blockXML->childNodes as $blockChildNode) {
            //scripts tags and p tags are not correctly handled by javascript
            if (is_a($blockChildNode, 'DOMElement') && ($blockChildNode->tagName != 'p' || io::substr($blockChildNode->tagName, 0, 4) != 'atm-')) {
                $hasNode = false;
            }
        }
        if (!$hasNode) {
            //append div with atm-empty-block class around datas
            $domdocument = new CMS_DOMDocument();
            try {
                $domdocument->loadXML('<block><div class="atm-empty-block atm-block-helper">' . $data . '</div></block>');
            } catch (DOMException $e) {
                $this->raiseError('Parse error for block : ' . $e->getMessage() . " :\n" . $data, true);
                return '';
            }
            $blockNodes = $domdocument->getElementsByTagName('block');
            if ($blockNodes->length == 1) {
                $blockXML = $blockNodes->item(0);
            }
        }
        $elements = array();
        $uniqueId = 'block-' . md5(mt_rand() . microtime());
        foreach ($blockXML->childNodes as $blockChildNode) {
            if (is_a($blockChildNode, 'DOMElement') && $blockChildNode->tagName != 'script' && $blockChildNode->tagName != 'p' && io::substr($blockChildNode->tagName, 0, 4) != 'atm-') {
                if ($blockChildNode->hasAttribute('class')) {
                    $blockChildNode->setAttribute('class', $blockChildNode->getAttribute('class') . ' atm-block ' . $uniqueId);
                } else {
                    $blockChildNode->setAttribute('class', 'atm-block ' . $uniqueId);
                }
                $elementId = 'el-' . md5(mt_rand() . microtime());
                $blockChildNode->setAttribute('id', $elementId);
                $elements[] = $elementId;
            }
        }
        $data = CMS_DOMDocument::DOMElementToString($blockXML, true);
        //add block JS specification
        $data = '
		<script type="text/javascript">
			atmBlocksDatas[\'' . $uniqueId . '\'] = {
				page:				\'' . $page->getID() . '\',
				document:			document,
				clientSpaceTagID:	\'' . $clientSpace->getTagID() . '\',
				row:				\'' . $row->getTagID() . '\',
				id:					\'' . $blockID . '\',
				jsBlockClass:		\'' . $this->_jsBlockClass . '\',
				hasContent:			\'' . $this->_hasContent . '\',
				editable:			\'' . $this->_editable . '\',
				administrable:		\'' . $this->_administrable . '\',
				options:			' . io::jsonEncode($this->_options) . ',
				value:				' . (is_array($this->_value) ? sensitiveIO::jsonEncode($this->_value) : '\'' . sensitiveIO::sanitizeJSString($this->_value) . '\'') . ',
				elements:			[' . ($elements ? '\'' . implode('\',\'', $elements) . '\'' : '') . ']
			};
		</script>
		' . $data;
        return $data;
    }
Esempio n. 30
0
    /**
     * Gets the data, using the specified visualization mode.
     * The data is taken from the blocks and reintroduced into the definition file which may itself contain HTML instructions.
     *
     * @param CMS_language &$language The language of the administration frontend
     * @param CMS_page &$page the page parsed
     * @param CMS_clientSpace &$clientSpace the client space parsed
     * @param integer $visualizationMode the visualization mode
     * @param boolean $templateHasPages, set to true will die access to up/down buttons
     * @param boolean $rowCanBeEdited determine we can edit it this page (Display form)
     * @return string the data from the blocks and the definition file.
     * @access public
     */
    function getData(&$language, &$page, &$clientSpace, $visualizationMode, $templateHasPages = false, $rowCanBeEdited = true)
    {
        global $cms_user;
        $modulesTreatment = new CMS_modulesTags(MODULE_TREATMENT_BLOCK_TAGS, $visualizationMode, $this);
        $modulesTreatment->setTreatmentParameters(array("page" => $page, "language" => $language, "clientSpace" => $clientSpace));
        if (!$this->_parseDefinitionFile($modulesTreatment)) {
            //here we expect a false (otherwise, it is an error)
            $data = $modulesTreatment->treatContent();
            //if $visualizationMode is CLIENTSPACES_FORM and
            //no page uses the template calling this row, add the form here
            if ($visualizationMode == PAGE_VISUALMODE_CLIENTSPACES_FORM || $visualizationMode == PAGE_VISUALMODE_FORM) {
                //append atm-row class and row-id to all first level tags found in row datas
                $domdocument = new CMS_DOMDocument();
                try {
                    $domdocument->loadXML('<row>' . $data . '</row>');
                } catch (DOMException $e) {
                    //$this->raiseError('Parse error for row : Page '.$page->getID().' - Row "'.$this->getTagID().'" : '.$e->getMessage());
                    //$data = '<div class="atm-error-block atm-block-helper">'.$language->getMessage(self::MESSAGE_BLOCK_CONTENT_ERROR).'</div>';
                    //$domdocument = new CMS_DOMDocument();
                    //$domdocument->loadXML('<row>'.$data.'</row>');
                    $this->raiseError('Parse error for row : ' . $e->getMessage() . " :\n" . $data, true);
                    return '';
                }
                $rowNodes = $domdocument->getElementsByTagName('row');
                if ($rowNodes->length == 1) {
                    $rowXML = $rowNodes->item(0);
                }
                //search for valid tags
                $hasNode = false;
                foreach ($rowXML->childNodes as $rowChildNode) {
                    //scripts tags and p tags are not correctly handled by javascript
                    if (is_a($rowChildNode, 'DOMElement') && $rowChildNode->tagName != 'script') {
                        $hasNode = true;
                    }
                }
                foreach ($rowXML->childNodes as $rowChildNode) {
                    //scripts tags and p tags are not correctly handled by javascript
                    if (is_a($rowChildNode, 'DOMElement') && ($rowChildNode->tagName != 'p' || io::substr($rowChildNode->tagName, 0, 4) != 'atm-')) {
                        $hasNode = false;
                    }
                }
                if (!$hasNode) {
                    //append atm-row class and row-id to all first level tags found in row datas
                    $domdocument = new CMS_DOMDocument();
                    try {
                        $domdocument->loadXML('<row><div class="atm-dummy-row-tag">' . $data . '</div></row>');
                    } catch (DOMException $e) {
                        $this->raiseError('Parse error for row : ' . $e->getMessage() . " :\n" . $data, true);
                        return '';
                    }
                    $rowNodes = $domdocument->getElementsByTagName('row');
                    if ($rowNodes->length == 1) {
                        $rowXML = $rowNodes->item(0);
                    }
                }
                $elements = array();
                $rowId = 'row-' . $this->_tagID;
                foreach ($rowXML->childNodes as $rowChildNode) {
                    if (is_a($rowChildNode, 'DOMElement') && $rowChildNode->tagName != 'script' && $rowChildNode->tagName != 'p' && io::substr($rowChildNode->tagName, 0, 4) != 'atm-') {
                        if ($rowChildNode->hasAttribute('id')) {
                            $elementId = $rowChildNode->getAttribute('id');
                        } else {
                            $elementId = 'el-' . md5(mt_rand() . microtime());
                            $rowChildNode->setAttribute('id', $elementId);
                        }
                        $elements[] = $elementId;
                    }
                }
                $data = CMS_DOMDocument::DOMElementToString($rowXML, true);
                //add row specification
                $data = '
				<script type="text/javascript">
					atmRowsDatas[\'' . $rowId . '\'] = {
						id:					\'' . $rowId . '\',
						template:			\'' . $clientSpace->getTemplateID() . '\',
						clientSpaceTagID:	\'' . $clientSpace->getTagID() . '\',
						rowTagID:			\'' . $this->_tagID . '\',
						rowType:			\'' . $this->_id . '\',
						label:				\'' . sensitiveIO::sanitizeJSString($this->getLabel()) . '\',
						userRight:			\'' . $this->hasUserRight($cms_user) . '\',
						visualMode:			\'' . $visualizationMode . '\',
						document:			document,
						elements:			[' . ($elements ? '\'' . implode('\',\'', $elements) . '\'' : '') . ']
					};
				</script>
				' . $data;
                //decode brackets encoded in CMS_block_text::_getHTMLForm
                $replace = array('||bo||' => '&#123;', '||bc||' => '&#125;');
                $data = str_replace(array_keys($replace), $replace, $data);
            }
            $data = '<?php /* Start row [' . $this->getLabel() . ' - ' . $this->getDefinitionFileName() . '] */?>' . $data . '<?php /* End row [' . $this->getLabel() . ' - ' . $this->getDefinitionFileName() . '] */?>';
            return $data;
        } else {
            $this->raiseError('Can not use row template file ' . $this->_definitionFile);
            return false;
        }
    }