/** * Create XHTML select boxes XHTML * * Example : * Array ( * // Mandatory * 'field_name' => '', // Name of selecte field * 'items_possible' => array(integer => string), // First is the value, second the label of Options * // Optional * 'default_value' => integer, // Current category to show as selected * 'attributes' => ' class="input_admin_text"', // A string completing "select" tag with optionnal attributes * ) * * USAGE : * Add this javascript and HTML to your form * and such event to your form : * <form onSubmit="getSelectedOptions_${hidden field name}();"> * if your hioden field is "IDS", the function to call will be : getSelectedOptions_IDS() * To retrieve selected values from $_POST form use : * $my_values = @array_unique(@explode(';', $_POST["ids"])); * * @param mixed array() $args, This array contains all parameters. * @return string, XHTML formated */ function getListBox($args) { if (!$args || !$args['items_possible']) { return ''; } // Rewritre HTML tag attributes $attributes = ''; if (trim($args["attributes"]) != '') { if (io::strpos($args["attributes"], 'size') === false) { $attributes = 'size="1" '; } $attributes .= trim($args["attributes"]); } $s = ' <select name="' . $args["field_name"] . '" ' . $attributes . '> <option value="0"></option>'; if (is_array($args['items_possible'])) { @reset($args['items_possible']); while (list($id, $lbl) = each($args['items_possible'])) { $sel = $id == $args["default_value"] ? ' selected="selected"' : ''; $s .= ' <option value="' . $id . '"' . $sel . '>' . $lbl . '</option>'; } } $s .= ' </select>'; return $s; }
/** * Creates compressed file by compressing raw data contained into $this->CMS_archive * * @return true on success, false on failure */ function create_tar() { $pwd = getcwd(); chdir($this->options['basedir']); foreach ($this->files as $current) { if ($current['name'] == $this->options['name']) { continue; } if (io::strlen($current['name2']) > 99) { $path = io::substr($current['name2'], 0, io::strpos($current['name2'], "/", io::strlen($current['name2']) - 100) + 1); $current['name2'] = io::substr($current['name2'], io::strlen($path)); if (io::strlen($path) > 154 || io::strlen($current['name2']) > 99) { $this->raiseError("Could not add {$path}{$current['name2']} to archive because the filename is too long."); continue; } } $block = pack("a100a8a8a8a12a12a8a1a100a6a2a32a32a8a8a155a12", $current['name2'], decoct($current['stat'][2]), sprintf("%6s ", decoct($current['stat'][4])), sprintf("%6s ", decoct($current['stat'][5])), sprintf("%11s ", decoct($current['stat'][7])), sprintf("%11s ", decoct($current['stat'][9])), " ", $current['type'], "", "ustar", "00", "Unknown", "Unknown", "", "", !empty($path) ? $path : "", ""); $checksum = 0; for ($i = 0; $i < 512; $i++) { $checksum += ord(io::substr($block, $i, 1)); } $checksum = pack("a8", sprintf("%6s ", decoct($checksum))); $block = substr_replace($block, $checksum, 148, 8); if ($current['stat'][7] == 0) { $this->add_data($block); } else { if ($fp = @fopen($current['name'], "rb")) { $this->add_data($block); while ($temp = fread($fp, 1048576)) { $this->add_data($temp); } if ($current['stat'][7] % 512 > 0) { $temp = ""; for ($i = 0; $i < 512 - $current['stat'][7] % 512; $i++) { $temp .= ""; } $this->add_data($temp); } fclose($fp); } else { $this->raiseError("Could not open file {$current['name']} for reading. It was not added."); } } } $this->add_data(pack("a512", "")); chdir($pwd); return true; }
/** * Constructor. * Initializes the process manager and lauches the action if all went well, then delete the PIDFile * NOTE : SCRIPT_CODENAME is a constant that must be defined, and unique accross all usage of the background scripts * (i.e. One background script for one application should have the same, but two applications having the same script shouldn't collate) * * @param boolean $debug Set to true if you want a debug of what the script does * @return void * @access public */ function backgroundScript($debug = false, $scriptID = 'Master') { $this->_debug = $debug; $this->_processManager = new processManager(SCRIPT_CODENAME . '_' . $scriptID); // Cleans previous PIDs if (isset($_SERVER['argv']['3']) && $_SERVER['argv']['3'] == '-F') { if (!APPLICATION_IS_WINDOWS) { $tmpDir = dir($this->_processManager->getTempPath()); while (false !== ($file = $tmpDir->read())) { if (io::strpos($file, SCRIPT_CODENAME) !== false) { @unlink($this->_processManager->getTempPath() . '/' . $file); } } } else { $files = glob(realpath($this->_processManager->getTempPath()) . '/' . SCRIPT_CODENAME . '*.*', GLOB_NOSORT); if (is_array($files)) { foreach ($files as $file) { if (!CMS_file::deleteFile($file)) { $this->raiseError("Can't delete file " . $file); } } } } } //write script process PID File if ($this->_processManager->writePIDFile()) { if ($this->_debug) { $this->raiseError("PID file successfully written (" . $this->_processManager->getPIDFileName() . ")."); } //start script process $this->activate($this->_debug); //delete script process PID File if ($this->_processManager->deletePIDFile()) { if ($this->_debug) { $this->raiseError("PID file successfully deleted (" . $this->_processManager->getPIDFileName() . ")."); } } else { $this->raiseError("Can not delete PID file (" . $this->_processManager->getPIDFileName() . ")."); } exit; } else { if ($this->_debug) { $this->raiseError("PID file already exists or impossible to write (" . $this->_processManager->getPIDFileName() . ")."); } exit; } }
function formatBytes($val, $digits = 3, $mode = "SI", $bB = "B") { $si = array("", "K", "M", "G", "T", "P", "E", "Z", "Y"); $iec = array("", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi"); switch (io::strtoupper($mode)) { case "SI": $factor = 1000; $symbols = $si; break; case "IEC": $factor = 1024; $symbols = $iec; break; default: $factor = 1000; $symbols = $si; break; } switch ($bB) { case "b": $val *= 8; break; default: $bB = "B"; break; } for ($i = 0; $i < count($symbols) - 1 && $val >= $factor; $i++) { $val /= $factor; } $p = io::strpos($val, "."); if ($p !== false && $p > $digits) { $val = round($val); } elseif ($p !== false) { $val = round($val, $digits - $p); } return round($val, $digits) . " " . $symbols[$i] . $bB; }
function checkFile($value) { return io::strpos($value, '..') === false && io::strpos($value, '/') === false && io::strpos($value, '\\') === false; }
$checkedElements['rows'] = true; } //define here special search codes for each elements $searchCodes = array(); $searchCodes[MOD_STANDARD_CODENAME] = CMS_search::getAllCodes(); $searchCodes['users'] = array('user', 'group'); if ($elements) { foreach ($searchCodes as $searchElement => $searchCode) { foreach ($searchCode as $code) { if (io::strpos($search, $code . ':') !== false && isset($elements[$searchElement])) { $checkedElements = array(); $checkedElements[$searchElement] = true; } } } if (io::strpos($search, 'row:') !== false && isset($elements['templates'])) { $checkedElements['templates'] = true; } $searchPanel .= "{\n\t\txtype: \t\t'checkboxgroup',\n\t\tid: \t\t'searchCheckboxgroup',\n\t\tfieldLabel: '" . $cms_language->getJsMessage(MESSAGE_PAGE_FIELD_SEARCH_IN) . "',\n\t\tcolumns: \t1,\n\t\titems: [\n\t\t\t{boxLabel: '<em style=\"font-style:italic;\">" . $cms_language->getJSMessage(MESSAGE_PAGE_CHECK_ALL) . "</em>', checked: " . (sizeof($elements) == sizeof($checkedElements) ? 'true' : 'false') . ", listeners: {'check':function(field, checked) {\n\t\t\t\tif (searchWindow.ok) {\n\t\t\t\t\tsearchWindow.ok = false;\n\t\t\t\t\tExt.getCmp('searchCheckboxgroup').items.each(function(el, group, index){\n\t\t\t\t\t\tif (index == 0) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tel.setValue(checked);\n\t\t\t\t\t}, this);\n\t\t\t\t\tsearchWindow.ok = true;\n\t\t\t\t\t//launch search\n\t\t\t\t\tsearchWindow.search();\n\t\t\t\t}\n\t\t\t}, scope:this}},\n\t\t"; foreach ($elements as $element => $label) { $label = io::htmlspecialchars($label); //if search use special search code, only search on standard module $checked = !$search || isset($checkedElements[$element]) && $checkedElements[$element] ? 'true' : 'false'; $searchPanel .= "{boxLabel: '{$label}', ctCls:'x-masked', inputValue:'{$element}', checked: {$checked}, name: 'elements[]', listeners: {'check':searchWindow.search}},"; } //remove last comma from groups $searchPanel = substr($searchPanel, 0, -1); $searchPanel .= "]\n\t},"; } $searchCodes = sensitiveIO::jsonEncode($searchCodes); $searchPanel = io::substr($searchPanel, 0, -1);
/** * set object Values * * @param array $values : the POST result values * @param string $prefixname : the prefix used for post names * @param boolean newFormat : new automne v4 format (default false for compatibility) * @param integer $objectID : the current object id. Must be set, but default is blank for compatibility with other objects * @return boolean true on success, false on failure * @access public */ function setValues($values, $prefixName, $newFormat = false, $objectID = '') { if (!sensitiveIO::isPositiveInteger($objectID)) { $this->raiseError('ObjectID must be a positive integer : ' . $objectID); return false; } //get module codename $moduleCodename = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID()); //create a sub prefix for CMS_dialog_href object $subPrefixName = 'href' . $prefixName . $this->_field->getID() . '_0'; //create object CMS_href & CMS_dialog_href $hrefDialog = new CMS_dialog_href(new CMS_href($this->_subfieldValues[0]->getValue()), $subPrefixName); if ($newFormat) { $hrefDialog->create($values[$subPrefixName], $moduleCodename, $objectID, $this->_field->getID()); if ($hrefDialog->hasError()) { return false; } $href = $hrefDialog->getHREF(); if (!$this->_subfieldValues[0]->setValue($href->getTextDefinition())) { return false; } $content = array('datas' => array('polymodFieldsValue[' . $subPrefixName . ']' => sensitiveIO::decodeEntities($this->_subfieldValues[0]->getValue()))); $view = CMS_view::getInstance(); $view->addContent($content); } else { //check for http:// if ($values[$subPrefixName . 'link_external'] && io::strpos($values[$subPrefixName . 'link_external'], 'http://') !== 0) { $values[$subPrefixName . 'link_external'] = 'http://' . $values[$subPrefixName . 'link_external']; } $hrefDialog->doPost($moduleCodename, $objectID, $this->_field->getID()); if ($hrefDialog->hasError()) { return false; } $href = $hrefDialog->getHREF(); if (!$this->_subfieldValues[0]->setValue($href->getTextDefinition())) { return false; } } return true; }
/** * 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; }
/** * activates the script function. * * @return void * @access public */ function activate() { parent::activate(); if ($_SERVER['argv']['1'] == '-s' && SensitiveIO::isPositiveInteger($_SERVER['argv']['2'])) { // SUB-SCRIPT : Processes one script task @ini_set('max_execution_time', SUB_SCRIPT_TIME_OUT); //set max execution time for sub script @set_time_limit(SUB_SCRIPT_TIME_OUT); //set the PHP timeout for sub script $sql = "\n\t\t\t\tselect\n\t\t\t\t\t*\n\t\t\t\tfrom\n\t\t\t\t\tregenerator\n\t\t\t\twhere\n\t\t\t\t\tid_reg = '" . $_SERVER['argv']['2'] . "'\n\t\t\t"; $q = new CMS_query($sql); if ($q->getNumRows()) { $data = $q->getArray(); //send script informations to process manager $this->_processManager->setParameters($data['module_reg'], $data['parameters_reg']); //instanciate script module $module = CMS_modulesCatalog::getByCodename($data['module_reg']); //then send script task to module (return task title by reference) $task = $module->scriptTask(unserialize($data['parameters_reg'])); //delete the current script task $sql_delete = "\n\t\t\t\t\tdelete\n\t\t\t\t\tfrom\n\t\t\t\t\t\tregenerator\n\t\t\t\t\twhere\n\t\t\t\t\t\tid_reg='" . $data['id_reg'] . "'"; $q = new CMS_query($sql_delete); if ($this->_debug) { $this->raiseError($this->_processManager->getPIDFilePath() . " : task " . $_SERVER['argv']['2'] . " seems " . (!$task ? 'NOT ' : '') . "done !"); $this->raiseError($this->_processManager->getPIDFilePath() . " : PID file exists ? " . @file_exists($this->_processManager->getPIDFilePath())); } $fpath = $this->_processManager->getPIDFilePath() . '.ok'; if (@touch($fpath) && @chmod($fpath, octdec(FILES_CHMOD))) { $f = @fopen($fpath, 'a'); if (!@fwrite($f, 'Script OK')) { $this->raiseError($this->_processManager->getPIDFilePath() . " : Can't write into file: " . $fpath); } @fclose($f); } else { $this->raiseError($this->_processManager->getPIDFilePath() . " : Can't create file: " . $fpath); } } } else { // MASTER SCRIPT : Processes all sub-scripts @ini_set('max_execution_time', MASTER_SCRIPT_TIME_OUT); //set max execution time for master script @set_time_limit(MASTER_SCRIPT_TIME_OUT); //set the PHP timeout for master script //max simultaneous scripts $maxScripts = $_SERVER['argv']['2']; $scriptsArray = array(); //send script informations to process manager $this->_processManager->setParameters(processManager::MASTER_SCRIPT_NAME, ''); //the sql script which selects one script task at a time $sql_select = "\n\t\t\t\tselect\n\t\t\t\t\t*\n\t\t\t\tfrom\n\t\t\t\t\tregenerator\n\t\t\t\tlimit\n\t\t\t\t\t" . $maxScripts . "\n\t\t\t"; //and now, launch all sub-scripts until table is empty. while (true) { //get scripts $q = new CMS_query($sql_select); if ($q->getNumRows()) { while (count($scriptsArray) < $maxScripts && ($data = $q->getArray())) { // Launch sub-process if (!APPLICATION_IS_WINDOWS) { // On unix system $sub_system = PATH_PACKAGES_FS . "/scripts/script.php -s " . $data["id_reg"] . " > /dev/null 2>&1 &"; if (!defined('PATH_PHP_CLI_UNIX') || !PATH_PHP_CLI_UNIX) { CMS_patch::executeCommand("cd " . PATH_REALROOT_FS . "; php " . $sub_system, $error); if ($error) { CMS_grandFather::raiseError('Error during execution of sub script command (cd ' . PATH_REALROOT_FS . '; php ' . $sub_system . '), please check your configuration : ' . $error); return false; } } else { CMS_patch::executeCommand("cd " . PATH_REALROOT_FS . "; " . PATH_PHP_CLI_UNIX . " " . $sub_system, $error); if ($error) { CMS_grandFather::raiseError('Error during execution of sub script command (cd ' . PATH_REALROOT_FS . '; ' . PATH_PHP_CLI_UNIX . ' ' . $sub_system . '), please check your configuration : ' . $error); return false; } } $PIDfile = $this->_processManager->getTempPath() . "/" . SCRIPT_CODENAME . "_" . $data["id_reg"]; if ($this->_debug) { $this->raiseError(processManager::MASTER_SCRIPT_NAME . " : Executes system(" . $sub_system . ")"); } //sleep a little @sleep(SLEEP_TIME); } else { // On windows system //Create the BAT file $command = '@echo off' . "\r\n" . '@start /B /BELOWNORMAL ' . realpath(PATH_PHP_CLI_WINDOWS) . ' ' . realpath(PATH_PACKAGES_FS . '\\scripts\\script.php') . ' -s ' . $data["id_reg"]; if (!@touch(realpath(PATH_WINDOWS_BIN_FS) . DIRECTORY_SEPARATOR . "sub_script.bat")) { $this->raiseError(processManager::MASTER_SCRIPT_NAME . " : Create file error : sub_script.bat"); } $replace = array('program files (x86)' => 'progra~2', 'program files' => 'progra~1', 'documents and settings' => 'docume~1'); $command = str_ireplace(array_keys($replace), $replace, $command); $fh = fopen(realpath(PATH_WINDOWS_BIN_FS . DIRECTORY_SEPARATOR . "sub_script.bat"), "wb"); if (is_resource($fh)) { if (!fwrite($fh, $command, io::strlen($command))) { CMS_grandFather::raiseError(processManager::MASTER_SCRIPT_NAME . " : Save file error : sub_script.bat"); } fclose($fh); } $WshShell = new COM("WScript.Shell"); $oExec = $WshShell->Run(str_ireplace(array_keys($replace), $replace, realpath(PATH_WINDOWS_BIN_FS . '\\sub_script.bat')), 0, false); $PIDfile = $this->_processManager->getTempPath() . DIRECTORY_SEPARATOR . SCRIPT_CODENAME . "_" . $data["id_reg"]; //sleep a little @sleep(SLEEP_TIME); } if ($this->_debug) { $this->raiseError(processManager::MASTER_SCRIPT_NAME . " : script : " . $data["id_reg"] . " - sub_system : " . $sub_system); } $scriptsArray[] = array("PID" => $PIDfile, "startTime" => CMS_stats::getmicrotime(), "scriptID" => $data["id_reg"], "scriptDatas" => $data); } } else { // no more scripts to process // > delete all temporary files // > end script if (APPLICATION_IS_WINDOWS) { $files = glob(realpath($this->_processManager->getTempPath()) . DIRECTORY_SEPARATOR . SCRIPT_CODENAME . '*.ok', GLOB_NOSORT); if (is_array($files)) { foreach ($files as $file) { if (!CMS_file::deleteFile($file)) { $this->raiseError("Can't delete file " . $file); return false; } } } } else { $tmpDir = dir($this->_processManager->getTempPath()); while (false !== ($file = $tmpDir->read())) { if (io::strpos($file, SCRIPT_CODENAME) !== false) { @unlink($this->_processManager->getTempPath() . '/' . $file); } } } break; } while (true) { @sleep(SLEEP_TIME); //wait a little to check sub_scripts $break = false; $timeStop = CMS_stats::getmicrotime(); if ($this->_debug) { $this->raiseError(processManager::MASTER_SCRIPT_NAME . " Scripts in progress : " . sizeof($scriptsArray)); } foreach ($scriptsArray as $nb => $aScript) { if ($this->_debug) { $this->raiseError(processManager::MASTER_SCRIPT_NAME . " PID : " . $aScript["PID"] . " - time : " . ($timeStop - $aScript["startTime"])); } $ok = ''; $ok = is_file($aScript["PID"] . '.ok'); if ($ok) { //$break = true; if ($this->_debug) { $this->raiseError(processManager::MASTER_SCRIPT_NAME . " Script : " . $aScript["PID"] . " OK !"); } unset($scriptsArray[$nb]); } elseif ($timeStop - $aScript["startTime"] >= SUB_SCRIPT_TIME_OUT) { if ($this->_debug) { $this->raiseError(processManager::MASTER_SCRIPT_NAME . " : Script : " . $aScript["PID"] . " NOT OK !"); } $this->raiseError(processManager::MASTER_SCRIPT_NAME . ' : Error on task : ' . $aScript["scriptID"] . ' ... skip it. Task parameters : ' . print_r($aScript['scriptDatas'], true)); //$break = true; unset($scriptsArray[$nb]); //delete the script in error from task list $q_del = "\n\t\t\t\t\t\t\t\tdelete\n\t\t\t\t\t\t\t\tfrom\n\t\t\t\t\t\t\t\t\tregenerator\n\t\t\t\t\t\t\t\twhere\n\t\t\t\t\t\t\t\t\tid_reg='" . $aScript["scriptID"] . "'"; $q_del = new CMS_query($q_del); } } if (!$scriptsArray) { break; } } } } }
/** * Get the recursive HTML display for a recursivelinks, if it passes the condition of course. * * @param CMS_page $parsedPage The page in which the linx tag is * @param integer $level The current level of recursivity * @param multidimentionnal array $recursiveTree The tree to display * @param array $pages array of pages objects (indexed by id) * @param boolean $public Is the page data to show the public or edited one ? * @param array $lineage The lineage of the pages (used to see wich recursions need to be done in closed link display mode) * @return string The html of the recursive link * @access public */ function getRecursiveOutput(&$parsedPage, $level = 0, $recursiveTree, &$pages, $public, $lineage = array()) { $html = ''; if (is_array($recursiveTree) && $recursiveTree) { $rank = 1; $levelhtml = ''; foreach ($recursiveTree as $pageID => $subPages) { //get Page Object $page = $pages[$pageID]; //instanciate page if not exists as object if (!is_object($page) && sensitiveIO::isPositiveInteger($page)) { $page = CMS_tree::getPageByID($page); } $pagehtml = ''; //check if page pass the condition if (is_object($page) && (!$this->hasCondition() || $this->pagePassesConditions($parsedPage, $page, $public, $rank)) && (!$public || $public && $page->isUseable() && $page->getPublication() == RESOURCE_PUBLICATION_PUBLIC)) { //get pages infos $linkTitle = $page->getLinkTitle($public); $title = $page->getTitle($public); //set pages infos in html template $replace = array("{{title}}" => io::sanitizeHTMLString($linkTitle), "{{jstitle}}" => io::sanitizeHTMLString($linkTitle), "{{pagetitle}}" => io::sanitizeHTMLString($title), "{{jspagetitle}}" => io::sanitizeHTMLString($title), "{{desc}}" => io::sanitizeHTMLString($page->getDescription($public)), "{{href}}" => $page->getURL(), "{{id}}" => $page->getID(), "{{codename}}" => $page->getCodename($public), "{{number}}" => $rank - 1, "{{modulo}}" => ($rank - 1) % 2, "{{lvlClass}}" => "CMS_lvl" . ($level + 1), "{{currentClass}}" => $parsedPage->getID() == $page->getID() ? "CMS_current" : "", 'id="{{currentID}}"' => $parsedPage->getID() == $page->getID() ? 'id="CMS_current"' : ""); if (io::strpos($this->_htmlTemplate, '{{isParent}}') !== false) { //only if needed because getLineage require a lot of query $pagelineage = CMS_tree::getLineage($page->getID(), $parsedPage->getID(), false); $replace['class="{{isParent}}"'] = is_array($pagelineage) && in_array($parsedPage->getID(), $pagelineage) ? 'class="CMS_parent"' : ""; $replace['{{isParent}}'] = is_array($pagelineage) && in_array($parsedPage->getID(), $pagelineage) ? 'CMS_parent' : ""; $replace['id="{{isParent}}"'] = is_array($pagelineage) && in_array($parsedPage->getID(), $pagelineage) ? 'id="CMS_parent"' : ""; } if (io::strpos($this->_htmlTemplate, '{{website') !== false) { //only if needed because getWebsite require a lot of query $website = $page->getWebsite(); $replace['{{websitetitle}}'] = $website->getLabel(); $replace['{{websitecodename}}'] = $website->getCodename($public); } $pagehtml = str_replace(array_keys($replace), $replace, $this->_htmlTemplate); if ($level == 0 && ($this->_root === 'false' || !$this->_root)) { $pagehtml = str_replace(array_keys($replace), $replace, $this->getRecursiveOutput($parsedPage, $level + 1, $subPages, $pages, $public, $lineage)); } else { //check if link is in open or closed mode if ($this->_mode == "open") { //if it is open mode recurse indefinitely (until end of tree) //then mark info of sublevels or not $replace = array("{{typeClass}}" => $subPages ? "CMS_sub" : "CMS_nosub", "{{sublevel}}" => $this->getRecursiveOutput($parsedPage, $level + 1, $subPages, $pages, $public)); $pagehtml = str_replace(array_keys($replace), $replace, $pagehtml); } else { //if it is 'close' mode recurse only for pages in current lineage $recurse = false; if (is_array($lineage)) { $recurse = in_array($page->getID(), $lineage) ? true : false; } //then mark info of sublevels or not and if level is open or not $sub = $recurse ? "CMS_open" : "CMS_sub"; $replace = array("{{typeClass}}" => $subPages ? $sub : "CMS_nosub", "{{sublevel}}" => $recurse ? $this->getRecursiveOutput($parsedPage, $level + 1, $subPages, $pages, $public, $lineage) : ""); if (!$recurse) { //needed to update link targets which is used after to register watched links $it = new RecursiveArrayIterator($subPages); foreach ($it as $pageID => $element) { unset($pages[$pageID]); } } $pagehtml = str_replace(array_keys($replace), $replace, $pagehtml); } } //add APPLICATION_ENFORCES_ACCESS_CONTROL php access checking if (APPLICATION_ENFORCES_ACCESS_CONTROL && $public) { $pagehtml = $this->_addSlashAroundPHPContent($pagehtml); $replace = array("<?php" => "';", "?>" => "echo '"); $pagehtml = str_replace(array_keys($replace), $replace, $pagehtml); $pagehtml = '<?php if ($cms_user->hasPageClearance(' . $page->getID() . ', CLEARANCE_PAGE_VIEW)) {' . "\n" . 'echo \'' . $pagehtml . '\';' . "\n" . '}' . "\n" . '?>'; } $rank++; } else { //needed to update link targets which is used after to register watched links unset($pages[$pageID]); } $levelhtml .= $pagehtml; } if ($level == 0 && ($this->_root === 'false' || !$this->_root)) { $html = $levelhtml; } else { if ($levelhtml && io::strpos($this->_subleveltemplate, "{{sublevel}}") !== false) { $replace = array("{{sublevel}}" => $levelhtml, "{{lvlClass}}" => "CMS_lvl" . ($level + 1)); $html = str_replace(array_keys($replace), $replace, $this->_subleveltemplate); } else { $html = $levelhtml; } } } return $html; }
/** * Get object field as an array structure used for export * * @param array $params The export parameters. Not used here * @param array $files The reference to the found files used by object * @return array : the object array structure * @access public */ public function asArray($params = array(), &$files) { $aField = array('id' => $this->_fieldID, 'uuid' => $this->_objectFieldValues['uuid'], 'labels' => CMS_object_i18nm::getValues($this->_objectFieldValues['labelID']), 'descriptions' => CMS_object_i18nm::getValues($this->_objectFieldValues['descriptionID']), 'objectID' => $this->_objectFieldValues['objectID'], 'type' => null, 'multi' => null, 'params' => array('order' => $this->_objectFieldValues['order'], 'required' => $this->_objectFieldValues['required'], 'indexable' => $this->_objectFieldValues['indexable'], 'searchlist' => $this->_objectFieldValues['searchlist'], 'searchable' => $this->_objectFieldValues['searchable'])); $linkedObjectId = null; if (io::strpos($this->_objectFieldValues['type'], 'multi|') !== false) { $aField['multi'] = 1; $type = explode('|', $this->_objectFieldValues['type']); $aField['type'] = $type[1]; $linkedObjectId = $type[1]; } else { $aField['multi'] = 0; $aField['type'] = $this->_objectFieldValues['type']; if (io::isPositiveInteger($aField['type'])) { $linkedObjectId = $this->_objectFieldValues['type']; } } if ($linkedObjectId) { $objectDefition = new CMS_poly_object_definition($linkedObjectId); if ($objectDefition) { $aField['params']['linkedObjectUuid'] = $objectDefition->getValue('uuid'); } } if (!io::isPositiveInteger($aField['type'])) { if (class_exists($aField['type'])) { $oType = new $aField['type'](array(), $this, false); $aField['params']['params'] = $oType->asArray(); } } elseif ($aField['multi']) { $oType = new CMS_multi_poly_object($aField['type'], array(), $this, false); $aField['params']['params'] = $oType->asArray(); } return $aField; }
/** * set object Values * * @param array $values : the POST result values * @param string prefixname : the prefix used for post names * @param boolean newFormat : new automne v4 format (default false for compatibility) * @param integer $objectID : the current object id. Must be set, but default is blank for compatibility with other objects * @return boolean true on success, false on failure * @access public */ function setValues($values, $prefixName, $newFormat = false, $objectID = '') { if (!sensitiveIO::isPositiveInteger($objectID)) { $this->raiseError('ObjectID must be a positive integer : ' . $objectID); return false; } //get field parameters $params = $this->getParamsValues(); //get module codename $moduleCodename = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID()); if ($newFormat) { //delete old images ? //thumbnail if ($this->_subfieldValues[0]->getValue() && (!$values[$prefixName . $this->_field->getID() . '_0'] || pathinfo($values[$prefixName . $this->_field->getID() . '_0'], PATHINFO_BASENAME) != $this->_subfieldValues[0]->getValue())) { @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[0]->getValue()); $this->_subfieldValues[0]->setValue(''); } //image zoom if ($this->_subfieldValues[2]->getValue() && (!isset($values[$prefixName . $this->_field->getID() . '_2']) || !$values[$prefixName . $this->_field->getID() . '_2'] || pathinfo($values[$prefixName . $this->_field->getID() . '_2'], PATHINFO_BASENAME) != $this->_subfieldValues[2]->getValue())) { @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[2]->getValue()); $this->_subfieldValues[2]->setValue(''); } //set label from label field if (!$this->_subfieldValues[1]->setValue(io::htmlspecialchars($values[$prefixName . $this->_field->getID() . '_1']))) { return false; } //image zoom (if needed) if ((!isset($values[$prefixName . $this->_field->getID() . '_makeZoom']) || $values[$prefixName . $this->_field->getID() . '_makeZoom'] != 1) && isset($values[$prefixName . $this->_field->getID() . '_2']) && $values[$prefixName . $this->_field->getID() . '_2'] && io::strpos($values[$prefixName . $this->_field->getID() . '_2'], PATH_UPLOAD_WR . '/') !== false) { $filename = $values[$prefixName . $this->_field->getID() . '_2']; //check for image type before doing anything if (!in_array(io::strtolower(pathinfo($filename, PATHINFO_EXTENSION)), $this->_allowedExtensions)) { return false; } //destroy old image if any if ($this->_subfieldValues[2]->getValue()) { @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[2]->getValue()); $this->_subfieldValues[2]->setValue(''); } //move and rename uploaded file $filename = str_replace(PATH_UPLOAD_WR . '/', PATH_UPLOAD_FS . '/', $filename); $basename = pathinfo($filename, PATHINFO_BASENAME); //set thumbnail $path = PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED; $zoomBasename = "r" . $objectID . "_" . $this->_field->getID() . "_" . io::strtolower(SensitiveIO::sanitizeAsciiString($basename)); if (io::strlen($zoomBasename) > 255) { $zoomBasename = sensitiveIO::ellipsis($zoomBasename, 255, '-', true); } $zoomFilename = $path . '/' . $zoomBasename; CMS_file::moveTo($filename, $zoomFilename); CMS_file::chmodFile(FILES_CHMOD, $zoomFilename); //set it if (!$this->_subfieldValues[2]->setValue($zoomBasename)) { return false; } } //thumbnail if ($values[$prefixName . $this->_field->getID() . '_0'] && io::strpos($values[$prefixName . $this->_field->getID() . '_0'], PATH_UPLOAD_WR . '/') !== false) { $filename = $values[$prefixName . $this->_field->getID() . '_0']; //check for image type before doing anything if (!in_array(io::strtolower(pathinfo($filename, PATHINFO_EXTENSION)), $this->_allowedExtensions)) { return false; } //destroy old image if any if ($this->_subfieldValues[0]->getValue()) { @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[0]->getValue()); $this->_subfieldValues[0]->setValue(''); } //move and rename uploaded file $filename = str_replace(PATH_UPLOAD_WR . '/', PATH_UPLOAD_FS . '/', $filename); $basename = pathinfo($filename, PATHINFO_BASENAME); //set thumbnail $path = PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED; $newBasename = "r" . $objectID . "_" . $this->_field->getID() . "_" . io::strtolower(SensitiveIO::sanitizeAsciiString($basename)); //rename image $path_parts = pathinfo($newBasename); $extension = io::strtolower($path_parts['extension']); $newBasename = io::substr($path_parts['basename'], 0, -(io::strlen($extension) + 1)) . '_thumbnail.' . $extension; if (io::strlen($newBasename) > 255) { $newBasename = sensitiveIO::ellipsis($newBasename, 255, '-', true); } $newFilename = $path . '/' . $newBasename; //move file from upload dir to new dir CMS_file::moveTo($filename, $newFilename); CMS_file::chmodFile(FILES_CHMOD, $newFilename); //if we use original image as image zoom, set it if (isset($values[$prefixName . $this->_field->getID() . '_makeZoom']) && $values[$prefixName . $this->_field->getID() . '_makeZoom'] == 1) { $zoomFilename = str_replace('_thumbnail.' . $extension, '.' . $extension, $newFilename); //copy image as zoom CMS_file::copyTo($newFilename, $zoomFilename); $zoomBasename = pathinfo($zoomFilename, PATHINFO_BASENAME); //set image zoom if (!$this->_subfieldValues[2]->setValue($zoomBasename)) { return false; } } //resize thumbnail if needed if ($params['maxWidth'] > 0 || $params['maxHeight'] > 0) { $oImage = new CMS_image($newFilename); //get current file size $sizeX = $oImage->getWidth(); $sizeY = $oImage->getHeight(); //check thumbnail size if ($params['maxWidth'] && $sizeX > $params['maxWidth'] || $params['maxHeight'] && $sizeY > $params['maxHeight']) { $newSizeX = $sizeX; $newSizeY = $sizeY; // Check width if ($params['maxWidth'] && $newSizeX > $params['maxWidth']) { $newSizeY = round($params['maxWidth'] * $newSizeY / $newSizeX); $newSizeX = $params['maxWidth']; } if ($params['maxHeight'] && $newSizeY > $params['maxHeight']) { $newSizeX = round($params['maxHeight'] * $newSizeX / $newSizeY); $newSizeY = $params['maxHeight']; } if (!$oImage->resize($newSizeX, $newSizeY, $newFilename)) { return false; } } } //set thumbnail if (!$this->_subfieldValues[0]->setValue($newBasename)) { return false; } } // If label not set yet, set it /*if(!$this->_subfieldValues[1]->getValue()){ if($this->_subfieldValues[0]->getValue()){ $this->_subfieldValues[1]->setValue($this->_subfieldValues[0]->getValue()); } }*/ //if we had an imagezoom, check his size if ($this->_subfieldValues[2]->getValue() && ($params['maxZoomWidth'] > 0 || $params['maxZoomHeight'] > 0)) { //resize zoom if needed $path = PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED; $basename = $this->_subfieldValues[2]->getValue(); $filename = $path . '/' . $basename; $extension = io::strtolower(pathinfo($basename, PATHINFO_EXTENSION)); $oImage = new CMS_image($filename); //get current file size $sizeX = $oImage->getWidth(); $sizeY = $oImage->getHeight(); //check zoom size if ($params['maxZoomWidth'] && $sizeX > $params['maxZoomWidth'] || $params['maxZoomHeight'] && $sizeY > $params['maxZoomHeight']) { $newSizeX = $sizeX; $newSizeY = $sizeY; // Check width if ($params['maxZoomWidth'] && $newSizeX > $params['maxZoomWidth']) { $newSizeY = round($params['maxZoomWidth'] * $newSizeY / $newSizeX); $newSizeX = $params['maxZoomWidth']; } if ($params['maxZoomHeight'] && $newSizeY > $params['maxZoomHeight']) { $newSizeX = round($params['maxZoomHeight'] * $newSizeX / $newSizeY); $newSizeY = $params['maxZoomHeight']; } if (!$oImage->resize($newSizeX, $newSizeY, $filename)) { return false; } } } //update files infos if needed if ($this->_subfieldValues[0]->getValue() && file_exists(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[0]->getValue())) { $file = new CMS_file(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[0]->getValue()); $imageDatas = array('filename' => $file->getName(false), 'filepath' => $file->getFilePath(CMS_file::WEBROOT), 'filesize' => $file->getFileSize(), 'fileicon' => $file->getFileIcon(CMS_file::WEBROOT), 'extension' => $file->getExtension()); } else { $imageDatas = array('filename' => '', 'filepath' => '', 'filesize' => '', 'fileicon' => '', 'extension' => ''); } $imageDatas['module'] = $moduleCodename; $imageDatas['visualisation'] = RESOURCE_DATA_LOCATION_EDITED; if ($params['useDistinctZoom'] || $this->_subfieldValues[2]->getValue()) { //update files infos if needed if ($this->_subfieldValues[2]->getValue() && file_exists(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[2]->getValue())) { $file = new CMS_file(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[2]->getValue()); $zoomDatas = array('filename' => $file->getName(false), 'filepath' => $file->getFilePath(CMS_file::WEBROOT), 'filesize' => $file->getFileSize(), 'fileicon' => $file->getFileIcon(CMS_file::WEBROOT), 'extension' => $file->getExtension()); } else { $zoomDatas = array('filename' => '', 'filepath' => '', 'filesize' => '', 'fileicon' => '', 'extension' => ''); } $zoomDatas['module'] = $moduleCodename; $zoomDatas['visualisation'] = RESOURCE_DATA_LOCATION_EDITED; } else { $zoomDatas = ''; } $content = array('datas' => array('polymodFieldsValue[' . $prefixName . $this->_field->getID() . '_0]' => $imageDatas, 'polymodFieldsValue[' . $prefixName . $this->_field->getID() . '_2]' => $zoomDatas, 'polymodFieldsValue[' . $prefixName . $this->_field->getID() . '_1]' => sensitiveIO::decodeEntities($this->_subfieldValues[1]->getValue()))); $view = CMS_view::getInstance(); $view->addContent($content); return true; } else { //Old format //delete old images ? if (isset($values[$prefixName . $this->_field->getID() . '_delete']) && $values[$prefixName . $this->_field->getID() . '_delete'] == 1) { if ($this->_subfieldValues[0]->getValue()) { @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[0]->getValue()); $this->_subfieldValues[0]->setValue(''); } elseif (isset($values[$prefixName . $this->_field->getID() . '_0_hidden']) && $values[$prefixName . $this->_field->getID() . '_0_hidden']) { @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $values[$prefixName . $this->_field->getID() . '_0_hidden']); $this->_subfieldValues[0]->setValue(''); } if ($this->_subfieldValues[2]->getValue()) { @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[2]->getValue()); $this->_subfieldValues[2]->setValue(''); } elseif (isset($values[$prefixName . $this->_field->getID() . '_2_hidden']) && $values[$prefixName . $this->_field->getID() . '_2_hidden']) { @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $values[$prefixName . $this->_field->getID() . '_2_hidden']); $this->_subfieldValues[2]->setValue(''); } } //set label from label field if (!$this->_subfieldValues[1]->setValue(io::htmlspecialchars(@$values[$prefixName . $this->_field->getID() . '_1']))) { return false; } //thumbnail if (isset($_FILES[$prefixName . $this->_field->getID() . '_0']) && $_FILES[$prefixName . $this->_field->getID() . '_0']['name'] && !$_FILES[$prefixName . $this->_field->getID() . '_0']['error']) { //check for image type before doing anything if (!in_array(io::strtolower(pathinfo($_FILES[$prefixName . $this->_field->getID() . '_0']["name"], PATHINFO_EXTENSION)), $this->_allowedExtensions)) { return false; } //set label as image name if none set /*if (!$values[$prefixName.$this->_field->getID().'_1']) { if (!$this->_subfieldValues[1]->setValue(io::htmlspecialchars($_FILES[$prefixName.$this->_field->getID().'_0']["name"]))) { return false; } }*/ //destroy all old images if any if ($this->_subfieldValues[0]->getValue()) { @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[0]->getValue()); $this->_subfieldValues[0]->setValue(''); } elseif (isset($values[$prefixName . $this->_field->getID() . '_0_hidden']) && $values[$prefixName . $this->_field->getID() . '_0_hidden']) { @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $values[$prefixName . $this->_field->getID() . '_0_hidden']); $this->_subfieldValues[0]->setValue(''); } if ($this->_subfieldValues[2]->getValue()) { @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[2]->getValue()); $this->_subfieldValues[2]->setValue(''); } elseif (isset($values[$prefixName . $this->_field->getID() . '_2_hidden']) && $values[$prefixName . $this->_field->getID() . '_2_hidden']) { @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $values[$prefixName . $this->_field->getID() . '_2_hidden']); $this->_subfieldValues[2]->setValue(''); } //set thumbnail (resize it if needed) //create thumbnail path $path = PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED; $filename = "r" . $objectID . "_" . $this->_field->getID() . "_" . io::strtolower(SensitiveIO::sanitizeAsciiString($_FILES[$prefixName . $this->_field->getID() . '_0']["name"])); if (io::strlen($filename) > 255) { $filename = sensitiveIO::ellipsis($filename, 255, '-', true); } //move uploaded file $fileDatas = CMS_file::uploadFile($prefixName . $this->_field->getID() . '_0', PATH_TMP_FS); if ($fileDatas['error']) { return false; } if (!CMS_file::moveTo(PATH_TMP_FS . '/' . $fileDatas['filename'], $path . "/" . $filename)) { return false; } if ($params['maxWidth'] > 0) { $oImage = new CMS_image($path . "/" . $filename); //get current file size $sizeX = $oImage->getWidth(); $sizeY = $oImage->getHeight(); //check thumbnail size if ($sizeX > $params['maxWidth'] || $sizeY > $params['maxHeight']) { $newSizeX = $sizeX; $newSizeY = $sizeY; // Check width if ($params['maxWidth'] && $newSizeX > $params['maxWidth']) { $newSizeY = round($params['maxWidth'] * $newSizeY / $newSizeX); $newSizeX = $params['maxWidth']; } if ($params['maxHeight'] && $newSizeY > $params['maxHeight']) { $newSizeX = round($params['maxHeight'] * $newSizeX / $newSizeY); $newSizeY = $params['maxHeight']; } //resize image $srcfilepath = $path . "/" . $filename; $path_parts = pathinfo($srcfilepath); $thumbnailFilename = io::substr($path_parts['basename'], 0, -(io::strlen($path_parts['extension']) + 1)) . '_thumbnail.' . $path_parts['extension']; $destfilepath = $path . "/" . $thumbnailFilename; $extension = io::strtolower($path_parts['extension']); if (!$oImage->resize($newSizeX, $newSizeY, $destfilepath)) { return false; } //if we use original image as image zoom, set it if ($values[$prefixName . $this->_field->getID() . '_makeZoom'] == 1) { //set image zoom if (!$this->_subfieldValues[2]->setValue($filename)) { return false; } } else { //destroy original image unlink($srcfilepath); } //set resized thumbnail if (!$this->_subfieldValues[0]->setValue($thumbnailFilename)) { return false; } } else { //no need to resize thumbnail (below the maximum width), so set it if (!$this->_subfieldValues[0]->setValue($filename)) { return false; } //if we use original image as image zoom, set it if ($values[$prefixName . $this->_field->getID() . '_makeZoom'] == 1) { //set image zoom if (!$this->_subfieldValues[2]->setValue($filename)) { return false; } } } } else { //no need to resize thumbnail, so set it if (!$this->_subfieldValues[0]->setValue($filename)) { return false; } //if we use original image as image zoom, set it if ($values[$prefixName . $this->_field->getID() . '_makeZoom'] == 1) { //set image zoom if (!$this->_subfieldValues[2]->setValue($filename)) { return false; } } } } elseif (isset($_FILES[$prefixName . $this->_field->getID() . '_0']) && $_FILES[$prefixName . $this->_field->getID() . '_0']['name'] && $_FILES[$prefixName . $this->_field->getID() . '_0']['error'] != 0) { return false; } elseif (isset($values[$prefixName . $this->_field->getID() . '_0_hidden']) && $values[$prefixName . $this->_field->getID() . '_0_hidden'] && (!isset($values[$prefixName . $this->_field->getID() . '_delete']) || $values[$prefixName . $this->_field->getID() . '_delete'] != 1)) { //set label as image name if none set if (!$this->_subfieldValues[0]->setValue($values[$prefixName . $this->_field->getID() . '_0_hidden'])) { return false; } } //image zoom (if needed) if (isset($values[$prefixName . $this->_field->getID() . '_makeZoom']) && $values[$prefixName . $this->_field->getID() . '_makeZoom'] != 1 && isset($_FILES[$prefixName . $this->_field->getID() . '_2']['name']) && $_FILES[$prefixName . $this->_field->getID() . '_2']['name'] && !$_FILES[$prefixName . $this->_field->getID() . '_2']['error']) { //check for image type before doing anything if (!in_array(io::strtolower(pathinfo($_FILES[$prefixName . $this->_field->getID() . '_2']["name"], PATHINFO_EXTENSION)), $this->_allowedExtensions)) { return false; } //create thumbnail path $path = PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED; $filename = "r" . $objectID . "_" . $this->_field->getID() . "_" . io::strtolower(SensitiveIO::sanitizeAsciiString($_FILES[$prefixName . $this->_field->getID() . '_2']["name"])); if (io::strlen($filename) > 255) { $filename = sensitiveIO::ellipsis($filename, 255, '-', true); } //move uploaded file $fileDatas = CMS_file::uploadFile($prefixName . $this->_field->getID() . '_2', PATH_TMP_FS); if ($fileDatas['error']) { return false; } if (!CMS_file::moveTo(PATH_TMP_FS . '/' . $fileDatas['filename'], $path . "/" . $filename)) { return false; } //set it if (!$this->_subfieldValues[2]->setValue($filename)) { return false; } } elseif (isset($_FILES[$prefixName . $this->_field->getID() . '_2']) && $_FILES[$prefixName . $this->_field->getID() . '_2']['name'] && $_FILES[$prefixName . $this->_field->getID() . '_2']['error'] != 0) { return false; } elseif (isset($values[$prefixName . $this->_field->getID() . '_2_hidden']) && $values[$prefixName . $this->_field->getID() . '_2_hidden'] && (!isset($values[$prefixName . $this->_field->getID() . '_delete']) || $values[$prefixName . $this->_field->getID() . '_delete'] != 1)) { if (!$this->_subfieldValues[2]->setValue($values[$prefixName . $this->_field->getID() . '_2_hidden'])) { return false; } } return true; } }
/** * Try to authenticate user from : * SSO * COOKIE * Given parameters * SESSION * * @return Zend_Auth_Result */ public function authenticate() { if (isset($this->_params['authType'])) { switch ($this->_params['authType']) { case 'credentials': if (isset($this->_params['login']) && isset($this->_params['password']) && $this->_params['login'] && $this->_params['password']) { //check token if (isset($this->_params['tokenName']) && $this->_params['tokenName'] && (!isset($this->_params['token']) || !$this->_params['token'] || !CMS_session::checkToken($this->_params['tokenName'], $this->_params['token']))) { $this->_messages[] = self::AUTH_INVALID_TOKEN; $this->_result = new Zend_Auth_Result(Zend_Auth_Result::FAILURE, null, $this->_messages); } else { //check user credentials from DB $sql = "\n\t\t\t\t\t\t\t\tselect\n\t\t\t\t\t\t\t\t\tid_pru\n\t\t\t\t\t\t\t\tfrom\n\t\t\t\t\t\t\t\t\tprofilesUsers\n\t\t\t\t\t\t\t\twhere\n\t\t\t\t\t\t\t\t\tlogin_pru = '" . SensitiveIO::sanitizeSQLString($this->_params['login']) . "'\n\t\t\t\t\t\t\t\t\tand (\n\t\t\t\t\t\t\t\t\t\tpassword_pru = '" . SensitiveIO::sanitizeSQLString(md5($this->_params['password'])) . "'\n\t\t\t\t\t\t\t\t\t\tor password_pru = '{sha}" . SensitiveIO::sanitizeSQLString(sha1($this->_params['password'])) . "'\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\tand password_pru != ''\n\t\t\t\t\t\t\t\t\tand active_pru = 1\n\t\t\t\t\t\t\t\t\tand deleted_pru = 0\n\t\t\t\t\t\t\t"; $q = new CMS_query($sql); if ($q->getNumRows()) { $userId = $q->getValue("id_pru"); $this->_user = CMS_profile_usersCatalog::getByID($userId); if ($this->_user && !$this->_user->hasError() && !$this->_user->isDeleted() && $this->_user->isActive()) { $this->_messages[] = self::AUTH_VALID_CREDENTIALS; $this->_result = new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $this->_user->getUserId(), $this->_messages); //remove previous autologin cookie if exists if (isset($_COOKIE[CMS_session::getAutoLoginCookieName()])) { CMS_session::setCookie(CMS_session::getAutoLoginCookieName()); } return $this->_result; } else { $this->_messages[] = self::AUTH_INVALID_USER; $this->_result = new Zend_Auth_Result(Zend_Auth_Result::FAILURE, null, $this->_messages); $this->raiseError("user_id found don't instanciate a valid user object. ID : " . $userId); } } else { $this->_messages[] = self::AUTH_INVALID_CREDENTIALS; $this->_result = new Zend_Auth_Result(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, null, $this->_messages); //wait a little (5 seconds) to avoid multiple simultaneous attempts sleep(5); } } } break; case 'session': $authStorage = new Zend_Auth_Storage_Session('atm-auth'); $userId = $authStorage->read(); if (io::isPositiveInteger($userId)) { if (!isset($this->_params['disconnect']) || !$this->_params['disconnect']) { //check user from session table if ($this->_checkSession($userId)) { $this->_user = CMS_profile_usersCatalog::getByID($userId); if ($this->_user && !$this->_user->hasError() && !$this->_user->isDeleted() && $this->_user->isActive()) { $this->_messages[] = self::AUTH_VALID_USER_SESSION; $this->_result = new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $this->_user->getUserId(), $this->_messages); return $this->_result; } else { $this->_messages[] = self::AUTH_INVALID_USER_SESSION; $this->_result = new Zend_Auth_Result(Zend_Auth_Result::FAILURE, null, $this->_messages); //clear session content CMS_session::deleteSession(true); } } else { //clear session content CMS_session::deleteSession(); } } } break; case 'cookie': if (isset($_COOKIE[CMS_session::getAutoLoginCookieName()])) { if (!isset($this->_params['disconnect']) || !$this->_params['disconnect']) { if (!$this->_autoLogin()) { //remove cookie CMS_session::setCookie(CMS_session::getAutoLoginCookieName()); } else { return $this->_result; } } } break; case 'sso': if (!(isset($this->_params['login']) && isset($this->_params['password']) && $this->_params['login'] && $this->_params['password'])) { if (defined('MOD_STANDARD_SSO_LOGIN') && MOD_STANDARD_SSO_LOGIN) { $this->_user = CMS_profile_usersCatalog::getByLogin(MOD_STANDARD_SSO_LOGIN); if ($this->_user && !$this->_user->hasError()) { $this->_messages[] = self::AUTH_SSOLOGIN_VALID; $this->_result = new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $this->_user->getUserId(), $this->_messages); return $this->_result; } else { $this->_messages[] = self::AUTH_SSOLOGIN_INVALID_USER; $this->_result = new Zend_Auth_Result(Zend_Auth_Result::FAILURE, null, $this->_messages); } } elseif (defined('MOD_STANDARD_SSO_FUNCTION') && MOD_STANDARD_SSO_FUNCTION) { if (is_callable(MOD_STANDARD_SSO_FUNCTION, false)) { //check if function/method name exists. $login = ''; if (io::strpos(MOD_STANDARD_SSO_FUNCTION, '::') !== false) { //static method call $method = explode('::', MOD_STANDARD_SSO_FUNCTION); $login = call_user_func(array($method[0], $method[1])); } else { //function call $login = call_user_func(MOD_STANDARD_SSO_FUNCTION); } if ($login) { $this->_user = CMS_profile_usersCatalog::getByLogin($login); if ($this->_user && !$this->_user->hasError()) { $this->_messages[] = self::AUTH_SSOLOGIN_VALID; $this->_result = new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $this->_user->getUserId(), $this->_messages); return $this->_result; } else { $this->_messages[] = self::AUTH_SSOLOGIN_INVALID_USER; $this->_result = new Zend_Auth_Result(Zend_Auth_Result::FAILURE, null, $this->_messages); } } } else { $this->raiseError('Cannot call SSO method/function: ' . MOD_STANDARD_SSO_FUNCTION); } } } break; default: CMS_grandFather::raiseError('Unknown authType: ' . $this->_params['authType']); break; } } //Nothing found if (!$this->_result) { $this->_messages[] = self::AUTH_MISSING_CREDENTIALS; $this->_result = new Zend_Auth_Result(Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND, null, $this->_messages); } return $this->_result; }
/** * Module autoload handler * * @param string $classname the classname required for loading * @return string : the file to use for required classname * @access public */ function load($classname) { static $classes; if (!isset($classes)) { $classes = array('cms_poly_object_field' => PATH_MODULES_FS . '/polymod/polyobjects/poly_object_field.php', 'cms_poly_object' => PATH_MODULES_FS . '/polymod/polyobjects/poly_object.php', 'cms_poly_object_definition' => PATH_MODULES_FS . '/polymod/polyobjects/poly_object_definition.php', 'cms_poly_object_catalog' => PATH_MODULES_FS . '/polymod/polyobjects/poly_object_catalog.php', 'cms_multi_poly_object' => PATH_MODULES_FS . '/polymod/polyobjects/multi_poly_object.php', 'cms_object_search' => PATH_MODULES_FS . '/polymod/object_search.php', 'cms_poly_plugin_definitions' => PATH_MODULES_FS . '/polymod/poly_plugin_definition.php', 'cms_object_i18nm' => PATH_MODULES_FS . '/polymod/object_i18nm.php', 'cms_polymod_definition_parsing' => PATH_MODULES_FS . '/polymod/poly_definition_parsing.php', 'cms_poly_module_structure' => PATH_MODULES_FS . '/polymod/poly_module_structure.php', 'cms_poly_rss_definitions' => PATH_MODULES_FS . '/polymod/poly_rss_definition.php', 'cms_block_polymod' => PATH_MODULES_FS . '/polymod/block.php', 'cms_poly_definition_functions' => PATH_MODULES_FS . '/polymod/poly_definition_functions.php', 'cms_xmltag_if' => PATH_MODULES_FS . '/polymod/tags/if.php', 'cms_xmltag_else' => PATH_MODULES_FS . '/polymod/tags/else.php', 'cms_xmltag_start' => PATH_MODULES_FS . '/polymod/tags/start.php', 'cms_xmltag_end' => PATH_MODULES_FS . '/polymod/tags/end.php', 'cms_xmltag_setvar' => PATH_MODULES_FS . '/polymod/tags/setvar.php', 'cms_polymod_oembed_definition' => PATH_MODULES_FS . '/polymod/poly_oembed_definition.php', 'cms_polymod_oembed_definition_catalog' => PATH_MODULES_FS . '/polymod/poly_oembed_definition_catalog.php'); } $file = ''; if (isset($classes[io::strtolower($classname)])) { $file = $classes[io::strtolower($classname)]; } elseif (io::strpos($classname, 'CMS_object_') === 0 && file_exists(PATH_MODULES_FS . '/polymod/objects/object_' . io::substr($classname, 11) . '.php')) { $file = PATH_MODULES_FS . '/polymod/objects/object_' . io::substr($classname, 11) . '.php'; } elseif (io::strpos($classname, 'CMS_subobject_') === 0 && file_exists(PATH_MODULES_FS . '/polymod/subobjects/subobject_' . io::substr($classname, 14) . '.php')) { $file = PATH_MODULES_FS . '/polymod/subobjects/subobject_' . io::substr($classname, 14) . '.php'; } return $file; }
/** * Return a list of all objects of given type * * @param mixed $objectID the object ID to get names (integer or 'multi|objectID') * @param boolean $public are the needed datas public ? (default false) * @param array $searchConditions, search conditions to add. Format : array(conditionType => conditionValue) * @param boolean $returnObjects, search return list of objects (default) or list of objects ID * @param constant $searchMethod, search method used (default : false => POLYMOD_SEARCH_RETURN_OBJECTS) * @return array(integer objectID => string objectName) * @access public * @static */ static function getAllObjects($objectID, $public = false, $searchConditions = array(), $returnObjects = true, $searchMethod = false) { $return = array(); if (io::strpos($objectID, 'multi|') !== false) { $objectID = io::substr($objectID, 6); } if (!sensitiveIO::isPositiveInteger($objectID)) { CMS_grandFather::raiseError('objectID is not a positive integer : ' . $objectID); return array(); } //load current object definition $object = CMS_poly_object_catalog::getObjectDefinition($objectID); $search = new CMS_object_search($object, $public); if (is_array($searchConditions) && $searchConditions) { foreach ($searchConditions as $conditionType => $conditionValue) { $search->addWhereCondition($conditionType, $conditionValue); } } if ($returnObjects) { if ($searchMethod !== false) { return $search->search($searchMethod); } else { return $search->search(); } } else { //here in some case we can have a strange error if search result is returned directly (using function as a reference should cause this) $ids = $search->search(CMS_object_search::POLYMOD_SEARCH_RETURN_IDS); //so we use a variable return $ids; } }
//CREATION $row = new CMS_row(); $creation = true; } elseif (is_a($row, "CMS_row") && $row->hasError()) { $cms_message = $cms_language->getMessage(MESSAGE_ERROR_UNKNOWN_ROW); break; } //rename template and set description $row->setLabel($label); $row->setDescription($description); if ($creation) { //set basic definition $row->setDefinition('<row></row>'); } //remove the old file if any and if new one is different if ($newimage && io::strpos($newimage, PATH_UPLOAD_WR . '/') !== false) { //move and rename uploaded file $newimage = str_replace(PATH_UPLOAD_WR . '/', PATH_UPLOAD_FS . '/', $newimage); $basename = pathinfo($newimage, PATHINFO_BASENAME); $movedImage = PATH_TEMPLATES_ROWS_FS . '/images/' . SensitiveIO::sanitizeAsciiString($basename); CMS_file::moveTo($newimage, $movedImage); CMS_file::chmodFile(FILES_CHMOD, $movedImage); $image = pathinfo($movedImage, PATHINFO_BASENAME); } elseif ($image) { $image = pathinfo($image, PATHINFO_BASENAME); } $row->setImage($image); //groups $row->delAllGroups(); foreach ($groups as $group) { $row->addGroup($group);
/** * 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)) { $link = $this->_link; if ($link->hasValidHREF()) { if ($link->getLinkType() == RESOURCE_LINK_TYPE_FILE) { //get file path $file = $link->getFileLink(false, MOD_STANDARD_CODENAME, RESOURCE_DATA_LOCATION_EDITED, PATH_RELATIVETO_FILESYSTEM, true); $path = $link->getFileLink(true, MOD_STANDARD_CODENAME, RESOURCE_DATA_LOCATION_EDITED, PATH_RELATIVETO_FILESYSTEM, false); if ($file && file_exists($path . '/' . $file)) { //Copy linked file //In new file name, delete reference to old page and add refernce to new one $_newFilename = "p" . $destinationPage->getID() . io::substr($file, io::strpos($file, "_"), io::strlen($file)); if (@is_file(PATH_MODULES_FILES_STANDARD_FS . "/edited/" . $file) && CMS_file::copyTo(PATH_MODULES_FILES_STANDARD_FS . "/edited/" . $file, PATH_MODULES_FILES_STANDARD_FS . "/edited/" . $_newFilename) && CMS_file::chmodFile(FILES_CHMOD, PATH_MODULES_FILES_STANDARD_FS . "/edited/" . $_newFilename)) { //Public if ($public) { if (!is_file(PATH_MODULES_FILES_STANDARD_FS . "/public/" . $file) || !CMS_file::copyTo(PATH_MODULES_FILES_STANDARD_FS . "/public/" . $file, PATH_MODULES_FILES_STANDARD_FS . "/public/" . $_newFilename) || !CMS_file::chmodFile(FILES_CHMOD, PATH_MODULES_FILES_STANDARD_FS . "/public/" . $_newFilename)) { $this->raiseError("Duplicate, file copy failed : " . PATH_MODULES_FILES_STANDARD_FS . "/public/" . $file); } } $link->setFileLink($_newFilename); } } } $table = $this->_getDataTableName(RESOURCE_LOCATION_USERSPACE, $public); //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\ttype='CMS_block_link',\n\t\t\t\t\t\tvalue='" . SensitiveIO::sanitizeSQLString($link->getTextDefinition()) . "'\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; }
function checkNode($value) { return $value != 'source' && io::strpos($value, '..') === false; }
/** * 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); } }
/** * Return sub tree of a given category * * @param array $values : parameters values array(parameterName => parameterValue) in : * root : the category id to get subtree. If none set, use the defined root category for field * maxlevel : the maximum number of level to get (optional) * selected : the current selected category id (optional) * usedcategories : display only used categories (optional, default : true) * @param multidimentionnal array $tags : xml2Array content of atm-function tag * <item>...{lvl}...{id}...{label}...{sublevel}...</item> * <itemselected>...{lvl}...{id}...{label}...{sublevel}...</itemselected> * <template>...{sublevel}...</template> * @return string : the sub tree of the given category * @access public */ function categoriesTree($values, $tags) { global $cms_user, $cms_language; if (!isset($values['usedcategories']) || $values['usedcategories'] == 'true' || $values['usedcategories'] == '1') { $restrictToUsedCategories = true; } else { $restrictToUsedCategories = false; } $return = ""; $params = $this->getParamsValues(); if ((!isset($values['root']) || !sensitiveIO::isPositiveInteger($values['root'])) && (!isset($params['rootCategory']) || !sensitiveIO::IsPositiveInteger($params['rootCategory']))) { $this->raiseError("Root value parameter must be a valid category ID"); return false; } elseif ((!isset($values['root']) || !sensitiveIO::isPositiveInteger($values['root'])) && (isset($params['rootCategory']) && sensitiveIO::IsPositiveInteger($params['rootCategory']))) { $values['root'] = $params['rootCategory']; } $usedCategories = $this->getAllUsedCategoriesForField(); if (!$usedCategories) { return $return; } $xml2Array = new CMS_XML2Array(); $itemPattern = $xml2Array->getXMLInTag($tags, 'item'); $templatePattern = $xml2Array->getXMLInTag($tags, 'template'); $selectedPattern = $xml2Array->getXMLInTag($tags, 'itemselected'); $maxlevel = isset($values['maxlevel']) ? (int) $values['maxlevel'] : 0; if (isset($values['selected'])) { $selectedIDs = is_array($values['selected']) ? $values['selected'] : array($values['selected']); } else { $selectedIDs = array(); } //$disableCategories = isset($values['disable']) ? explode(';',$values['disable']) : array(); $disableCategories = array(); if (isset($values['disable'])) { $disableCategories = explode(';', $values['disable']); if (count($disableCategories) == 1) { $disableCategories = explode(',', $values['disable']); } } if (!$itemPattern) { $this->raiseError("No 'item' tag found or tag empty"); return false; } if (!$templatePattern) { $this->raiseError("No 'template' tag found or tag empty"); return false; } $module = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID()); if (isset($values['editableonly']) && ($values['editableonly'] == 'true' || $values['editableonly'] == '1')) { $viewvableCategoriesForProfile = CMS_moduleCategories_catalog::getViewvableCategoriesForProfile($cms_user, $module, true, CLEARANCE_MODULE_EDIT, true); } else { $viewvableCategoriesForProfile = CMS_moduleCategories_catalog::getViewvableCategoriesForProfile($cms_user, $module, true); } if ($restrictToUsedCategories || is_array($disableCategories) && $disableCategories) { //unset unused categories (keep categories parents in lineage) $usedCategoriesTree = array(); foreach ($usedCategories as $usedCategory) { if (isset($viewvableCategoriesForProfile[$usedCategory]) && $viewvableCategoriesForProfile[$usedCategory]) { $usedCategoriesTree = array_merge($usedCategoriesTree, explode(';', $viewvableCategoriesForProfile[$usedCategory])); } } $usedCategoriesTree = array_flip(array_unique($usedCategoriesTree)); foreach ($viewvableCategoriesForProfile as $catID => $lineage) { //restrict to used categories if ($restrictToUsedCategories) { if (!isset($usedCategoriesTree[$catID])) { unset($viewvableCategoriesForProfile[$catID]); } } // Disable categories if (is_array($disableCategories) && $disableCategories) { $lineageTab = explode(';', $lineage); foreach ($disableCategories as $disableCategory) { if (SensitiveIO::isPositiveInteger($disableCategory)) { if (in_array($disableCategory, $lineageTab)) { unset($viewvableCategoriesForProfile[$catID]); } } } } } } $rootLineage = CMS_moduleCategories_catalog::getLineageOfCategoryAsString($values['root'], $separator = ";"); //old method, seems buggy, keep it for now //$rootLineage = ($viewvableCategoriesForProfile[$values['root']]) ? $viewvableCategoriesForProfile[$values['root']] : $values['root']; //create recursive categories array foreach ($viewvableCategoriesForProfile as $catID => $lineage) { //this must be ^...;rootID;...$ or ^rootID;...$ if (io::strpos($lineage, ';' . $values['root'] . ';') !== false || io::strpos($lineage, $values['root'] . ';') === 0) { $lineage = preg_replace('#^' . $rootLineage . ';#', '', $lineage); $ln = sensitiveIO::sanitizeExecCommand('if (!isset($nLevelArray[' . str_replace(';', '][', $lineage) . '])) $nLevelArray[' . str_replace(';', '][', $lineage) . '] = array();'); eval($ln); } } //pr($nLevelArray); if (isset($nLevelArray) && is_array($nLevelArray) && $nLevelArray) { $return = $this->_createCategoriesTree($nLevelArray, $itemPattern, $templatePattern, $selectedPattern, $maxlevel, $selectedIDs); } return $return; }
function checkCatId($catId) { return io::strpos($catId, 'cat') === 0 && sensitiveIO::isPositiveInteger(io::substr($catId, 3)); }
/** * select all running scripts from scriptsStatuses Table and check PID files. * * @return array * @access public */ function getRunningScript() { //check temporary dir for orchan PID files //get temporary path $tempPath = CMS_file::getTmpPath(); //computes the directory to put files in $tempDir = @dir($tempPath); if (!is_object($tempDir)) { return array(); } //script application label $scriptAppLbl = processManager::getAppCode(); //Automatic list of directory content //Displayed in alphabetical order (noted on Windows platforms) $PIDFiles = array(); while (false !== ($file = $tempDir->read())) { if (stripos($file, $scriptAppLbl) !== false && io::strpos($file, ".ok") === false) { $PIDFiles[] = $file; } } //check the table $sql = "\n\t\t\tselect\n\t\t\t\t*\n\t\t\tfrom\n\t\t\t\tscriptsStatuses\n\t\t\torder by launchDate_ss\n\t\t\t"; $q = new CMS_query($sql); $scripts = array(); $modules = array(); while ($data = $q->getArray()) { $PIDFileStatus = 0; if (array_search($data["scriptName_ss"], $PIDFiles) !== false) { $process = new processManager($data["scriptName_ss"]); if (@is_file($process->getPIDFilePath() . ".ok")) { $PIDFileStatus = 3; } else { $PIDFileStatus = 1; } $key = array_search($data["scriptName_ss"], $PIDFiles); unset($PIDFiles[$key]); } $scriptTitle = ''; //instanciate module if not exists if (isset($data['module_ss']) && $data['module_ss'] != self::MASTER_SCRIPT_NAME) { if (!isset($modules[$data['module_ss']])) { $modules[$data['module_ss']] = CMS_modulesCatalog::getByCodename($data['module_ss']); } if (is_object($modules[$data['module_ss']])) { $scriptTitle = $modules[$data['module_ss']]->scriptInfo(unserialize($data['parameters_ss'])); } else { $scriptTitle = 'Error : script module not set'; } } elseif ($data['module_ss'] == self::MASTER_SCRIPT_NAME) { $scriptTitle = self::MASTER_SCRIPT_NAME; } else { $scriptTitle = 'Error : script module not set'; } $script = array("Title" => $scriptTitle, "Date" => $data["launchDate_ss"], "PIDFile" => $PIDFileStatus); $scripts[] = $script; } //add orphan PIDFiles to the report foreach ($PIDFiles as $anOrphanPIDFile) { $script = array("Title" => str_replace('_', ' ', str_replace('bgscript_', '', $anOrphanPIDFile)), "Date" => '', "PIDFile" => '2'); $scripts[] = $script; } return $scripts; }
/** * Get datas vars from a form formatted by such a Automne.LinkField class * and build a CMS_href * * @param array $datas, the datas sent by the Automne.LinkField return * @param string $module, the module concerned by this link * @param integer $resourceID, ID to prepend the filename uploaded with * @param integer $fieldID, optional field ID to surcharge file name representation ("r".$resourceID."_f".$fieldID."_") * @return boolean true on success, false on failure * @access public */ function create($datas = '', $module = MOD_STANDARD_CODENAME, $resourceID, $fieldID = '') { $datas = explode($this->_href->getSeparator(), $datas); $linkLabel = isset($datas[7]) ? $datas[7] : ''; $linkType = isset($datas[0]) ? $datas[0] : ''; $internalLink = isset($datas[1]) ? $datas[1] : ''; $externalLink = isset($datas[2]) ? $datas[2] : ''; $this->_href->setLabel($linkLabel); $this->_href->setLinkType($linkType); $this->_href->setInternalLink($internalLink); $this->_href->setExternalLink($externalLink); // Delete/Upload file if (isset($datas[3])) { switch ($module) { case MOD_STANDARD_CODENAME: $locationType = RESOURCE_DATA_LOCATION_EDITION; $uniqueName = md5(serialize($this) . microtime()); $fileprefix = $fieldID ? 'p' . $resourceID . '_' . $uniqueName . "_f" . $fieldID : 'p' . $resourceID . '_' . $uniqueName; break; default: $locationType = RESOURCE_DATA_LOCATION_EDITED; $fileprefix = $fieldID ? 'r' . $resourceID . "_f" . $fieldID . "_" : 'r' . $resourceID . "_"; break; } if ($datas[3] && io::strpos($datas[3], PATH_UPLOAD_WR . '/') !== false) { //move and rename uploaded file $datas[3] = str_replace(PATH_UPLOAD_WR . '/', PATH_UPLOAD_FS . '/', $datas[3]); $basename = pathinfo($datas[3], PATHINFO_BASENAME); $path = $this->_href->getFileLink(true, $module, $locationType, PATH_RELATIVETO_FILESYSTEM, false); $newFilename = $path . '/' . $fileprefix . $basename; CMS_file::moveTo($datas[3], $newFilename); CMS_file::chmodFile(FILES_CHMOD, $newFilename); $datas[3] = pathinfo($newFilename, PATHINFO_BASENAME); //remove the old file if any if (is_file($this->_href->getFileLink(true, $module, $locationType, PATH_RELATIVETO_FILESYSTEM))) { if (!unlink($this->_href->getFileLink(true, $module, $locationType, PATH_RELATIVETO_FILESYSTEM))) { $this->raiseError("Could not delete old linked file"); } } } elseif ($datas[3]) { //keep old file $datas[3] = pathinfo($datas[3], PATHINFO_BASENAME); } else { $datas[3] = ''; //remove the old file if any if (is_file($this->_href->getFileLink(true, $module, $locationType, PATH_RELATIVETO_FILESYSTEM))) { if (!unlink($this->_href->getFileLink(true, $module, $locationType, PATH_RELATIVETO_FILESYSTEM))) { $this->raiseError("Could not delete old linked file"); } } } $this->_href->setFileLink($datas[3]); } elseif (is_file($this->_href->getFileLink(true, $module, $locationType, PATH_RELATIVETO_FILESYSTEM))) { //remove the old file if (!unlink($this->_href->getFileLink(true, $module, $locationType, PATH_RELATIVETO_FILESYSTEM))) { $this->raiseError("Could not delete old linked file"); } } // Target and Popup > (width, height) list($width, $height) = explode(',', $datas[6]); if (sensitiveIO::isPositiveInteger($width) && sensitiveIO::isPositiveInteger($height)) { $this->_href->setPopup($width, $height); } else { switch ($datas[4]) { case "_top": $this->_href->setTarget('_top'); $this->_href->setPopup('', ''); break; case "_blank": $this->_href->setTarget('_blank'); $this->_href->setPopup('', ''); break; } } return true; }
/** * Sets subObjectsDefinitions * * @return boolean true on success, false on failure * @access private */ protected function _populateSubObjectsDefinitions() { if (!$this->_objectFieldsDefinition) { $this->raiseError("No fields for objectID : " . $this->_objectID . " in catalog"); return false; } //get all subDefinitions for fields foreach (array_keys($this->_objectFieldsDefinition) as $fieldID) { if (is_object($this->_objectFieldsDefinition[$fieldID])) { $type = $this->_objectFieldsDefinition[$fieldID]->getValue('type'); if (sensitiveIO::isPositiveInteger($type)) { //poly object $typeObject = new CMS_poly_object($type); $this->_subObjectsDefinitions[$fieldID] = $typeObject->getSubFieldsDefinition($this->_ID); } elseif (io::strpos($type, "multi|") !== false) { //multi objects $this->_subObjectsDefinitions[$fieldID] = CMS_multi_poly_object::getSubFieldsDefinition(io::substr($type, 6), $this->_ID, $this->_objectFieldsDefinition[$fieldID]); } elseif (class_exists($type)) { //object $typeObject = new $type(array(), $this->_objectFieldsDefinition[$fieldID]); $this->_subObjectsDefinitions[$fieldID] = $typeObject->getSubFieldsDefinition($this->_ID); } else { $this->raiseError("Unknown field type : " . $type); return false; } } } return true; }
/** * Get all subobjects values for searched objects results * * @access private * @return array of subobject ids sorted */ protected function _getSubObjectsIds() { $ids = array(); $subObjectsFieldsIds = array(); //load fields objects for object $objectFields = CMS_poly_object_catalog::getFieldsDefinition($this->_object->getID()); //Add all subobjects to search if any foreach (array_keys($objectFields) as $fieldID) { //if field is a poly object or a multi poly object, add it to search if (sensitiveIO::isPositiveInteger($objectFields[$fieldID]->getValue('type')) || io::strpos($objectFields[$fieldID]->getValue('type'), "multi|") !== false) { $subObjectsFieldsIds[] = $fieldID; } } if (is_array($subObjectsFieldsIds) && $subObjectsFieldsIds) { //update tmp table with found ids $this->_updateTmpList($this->_sortedResultsIds); $where = ' and objectID in (' . $this->_getSQLTmpList() . ')'; // Prepare conditions $where = "\n\t\t\twhere\n\t\t\t\tobjectID in (" . $this->_getSQLTmpList() . ")\n\t\t\t\tand objectFieldID in (" . implode($subObjectsFieldsIds, ',') . ")"; $statusSuffix = $this->_public ? "_public" : "_edited"; $sql = "select\n\t\t\t\t\t\tdistinct value\n\t\t\t\t\tfrom\n\t\t\t\t\t\tmod_subobject_integer" . $statusSuffix . "\n\t\t\t\t\t\t{$where}\n\t\t\t\t\t"; $q = new CMS_query($sql); //pr($sql); if (!$q->hasError()) { while ($r = $q->getArray()) { if ($r['value']) { $ids[$r['value']] = $r['value']; } } } } return $ids; }
/** * Check install parameters * * @param $array, install command to check, view documentation for format * @param $errorsInfo array, infos on errors found in checked install commands. Returned by reference. * @return string errors found in install array * @access public */ function checkInstall(&$array, &$errorsInfo) { if (is_array($array)) { $errorsInfo = array(); $error = ''; foreach ($array as $line => $aInstallCheck) { $line++; //to have the correct line number //remove blank lines if (!$aInstallCheck) { unset($array[$line - 1]); continue; } $installParams = array_map("trim", explode("\t", $aInstallCheck)); //read UPDATE.DENY file $updateDenyFile = new CMS_file(UPDATE_DENY, CMS_file::WEBROOT); if ($updateDenyFile->exists()) { $updateDeny = $updateDenyFile->readContent("array"); } else { $this->raiseError("File " . UPDATE_DENY . " does not exist"); return false; } //if we don't have parameter and line not a comment if (!isset($installParams[1]) && io::substr($installParams[0], 0, 1) != '#' && $installParams[0] != 'rc') { $error .= "Error at line : " . $line . " missing file parameter<br />"; $errorsInfo[] = array('no' => 1, 'line' => $line, 'command' => $aInstallCheck); unset($array[$line - 1]); } else { //first check needed file existence 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; } $filesExists = true; switch ($installParams[0]) { //check only patch file existence case "x": case ">": case "+": if (!file_exists($patchFile)) { $error .= "Error at line : " . $line . ", patch file " . $patchFile . " does not exist<br />"; $filesExists = false; $errorsInfo[] = array('no' => 2, 'line' => $line, 'command' => $aInstallCheck); unset($array[$line - 1]); } break; //check only original file existence //check only original file existence case "ch": case "co": case "cg": if (io::strpos($originalFile, '*') === false) { if (!file_exists($originalFile)) { $error .= "Error at line : " . $line . ", file " . $originalFile . " does not exist<br />"; $errorsInfo[] = array('no' => 3, 'line' => $line, 'command' => $aInstallCheck); $filesExists = false; //in this 2 case don't unset this command if it has an error because the file needed may be created by this script if ($installParams[0] != 'co' && $installParams[0] != 'cg') { unset($array[$line - 1]); } } } break; } if ($filesExists) { //then if files are ok, check installation request switch ($installParams[0]) { case ">": //add or update a file or folder if (in_array($installParams[1], $updateDeny) && !is_file($patchFile . '.updated')) { $error .= "Error at line : " . $line . ", file " . $installParams[1] . " is in the UPDATE.DENY list<br />"; $errorsInfo[] = array('no' => 5, 'line' => $line, 'command' => $aInstallCheck); unset($array[$line - 1]); } else { if (file_exists($originalFile)) { //check if file is writable if (!CMS_FILE::makeWritable($originalFile)) { $error .= "Error at line : " . $line . ", file " . $originalFile . " is not writable<br />"; $errorsInfo[] = array('no' => 6, 'line' => $line, 'command' => $aInstallCheck); unset($array[$line - 1]); } } else { //check if parent directory is writable $parent = CMS_file::getParent($originalFile); if (!CMS_FILE::makeWritable($parent)) { $error .= "Error at line : " . $line . ", file " . dirname($originalFile) . " is not writable<br />"; $errorsInfo[] = array('no' => 7, 'line' => $line, 'command' => $aInstallCheck); unset($array[$line - 1]); } } } //check right presence and format if (isset($installParams[2]) && $installParams[2]) { if (!$this->_checkRightFormat($installParams[2])) { $error .= "Error at line : " . $line . ", right command malformed<br />"; $errorsInfo[] = array('no' => 8, 'line' => $line, 'command' => $aInstallCheck); unset($array[$line - 1]); } } break; case "<": //delete a file or folder (recursively) if (in_array($installParams[1], $updateDeny)) { $error .= "Error at line : " . $line . ", file " . $installParams[1] . " is in the UPDATE.DENY list<br />"; $errorsInfo[] = array('no' => 9, 'line' => $line, 'command' => $aInstallCheck); unset($array[$line - 1]); } else { if (file_exists($originalFile)) { //check if file or directory is deletable if (is_file($originalFile)) { if (!CMS_FILE::makeWritable($originalFile)) { $error .= "Error at line : " . $line . ", file " . $originalFile . " is not deletable<br />"; $errorsInfo[] = array('no' => 10, 'line' => $line, 'command' => $aInstallCheck); unset($array[$line - 1]); } } elseif (is_dir($originalFile)) { if (!CMS_FILE::deltreeSimulation($originalFile, true)) { $error .= "Error at line : " . $line . ", directory " . $originalFile . " is not deletable<br />"; $errorsInfo[] = array('no' => 11, 'line' => $line, 'command' => $aInstallCheck); unset($array[$line - 1]); } } else { $error .= "Error at line : " . $line . ", what is " . $originalFile . " ???<br />"; $errorsInfo[] = array('no' => 12, 'line' => $line, 'command' => $aInstallCheck); unset($array[$line - 1]); } } } break; case "+": //concatenate module xml file //check extension of source file if (io::substr($patchFile, -4, 4) != '.xml') { $error .= "Error at line : " . $line . ", XML file to append " . $patchFile . " does not seem to be an XML file<br />"; $errorsInfo[] = array('no' => 14, 'line' => $line, 'command' => $aInstallCheck); unset($array[$line - 1]); } //Check XML validity of source file $sourceXML = new CMS_file($patchFile); $domdocument = new CMS_DOMDocument(); try { $domdocument->loadXML($sourceXML->readContent("string")); } catch (DOMException $e) { $error .= "Error at line : " . $line . ", XML parse error on file " . $patchFile . " : " . $e->getMessage() . "<br />"; $errorsInfo[] = array('no' => 15, 'line' => $line, 'command' => $aInstallCheck); unset($array[$line - 1]); } //check module to apply XML modifications if ($installParams[2]) { $module = CMS_modulesCatalog::getByCodename($installParams[2]); if ($module === false) { $error .= "Error at line : " . $line . ", module " . $installParams[2] . " does not exist<br />"; $errorsInfo[] = array('no' => 16, 'line' => $line, 'command' => $aInstallCheck); unset($array[$line - 1]); $filesExists = false; } elseif (!$module->hasParameters()) { $error .= "Error at line : " . $line . ", module " . $installParams[2] . " does not have parameters<br />"; $errorsInfo[] = array('no' => 17, 'line' => $line, 'command' => $aInstallCheck); unset($array[$line - 1]); $filesExists = false; } } else { $error .= "Error at line : " . $line . ", need module codename<br />"; $errorsInfo[] = array('no' => 18, 'line' => $line, 'command' => $aInstallCheck); unset($array[$line - 1]); $filesExists = false; } break; case "x": //execute SQL or PHP file //only check extension for the moment if (io::substr($patchFile, -4, 4) != '.sql' && io::substr($patchFile, -4, 4) != '.php') { $error .= "Error at line : " . $line . ", file to execute " . $patchFile . " does not seem to be an SQL or PHP file<br />"; $errorsInfo[] = array('no' => 19, 'line' => $line, 'command' => $aInstallCheck); unset($array[$line - 1]); } if (io::substr($patchFile, -4, 4) == '.sql') { //make a simulation on the sql script if (!$this->executeSqlScript($patchFile, true)) { $error .= "Error at line : " . $line . ", on " . $patchFile . ", no SQL request found..."; $errorsInfo[] = array('no' => 20, 'line' => $line, 'command' => $aInstallCheck); unset($array[$line - 1]); } } break; case "ch": //execute chmod //only check right presence and format if (!$installParams[2]) { $error .= "Error at line : " . $line . ", command does not have right<br />"; $errorsInfo[] = array('no' => 21, 'line' => $line, 'command' => $aInstallCheck); unset($array[$line - 1]); } else { if (!$this->_checkRightFormat($installParams[2])) { $error .= "Error at line : " . $line . ", right command malformed<br />"; $errorsInfo[] = array('no' => 22, 'line' => $line, 'command' => $aInstallCheck); unset($array[$line - 1]); } } break; case "co": //execute change owner //execute change owner case "cg": //execute change group //only check right presence if (!$installParams[2]) { $error .= "Error at line : " . $line . ", command does not have right<br />"; $errorsInfo[] = array('no' => 23, 'line' => $line, 'command' => $aInstallCheck); unset($array[$line - 1]); } break; case "rc": //do nothing break; case "htaccess": if (!$installParams[2]) { $error .= "Error at line : " . $line . ", missing htaccess type<br />"; $errorsInfo[] = array('no' => 26, 'line' => $line, 'command' => $aInstallCheck); unset($array[$line - 1]); } elseif (!is_file(PATH_HTACCESS_FS . '/htaccess_' . $installParams[2])) { $error .= "Error at line : " . $line . ", unknown htaccess type : " . $installParams[2] . "<br />"; $errorsInfo[] = array('no' => 26, 'line' => $line, 'command' => $aInstallCheck); unset($array[$line - 1]); } break; default: if (io::substr($installParams[0], 0, 1) != '#') { $error .= "Error at line : " . $line . ", \tunknown parameter : " . $installParams[0] . "<br />"; $errorsInfo[] = array('no' => 25, 'line' => $line, 'command' => $aInstallCheck); unset($array[$line - 1]); } break; } } } } return $error; } else { $this->raiseError("Param must be an array"); return false; } }
$view->setContent($datas); $edited = true; } else { CMS_grandFather::raiseError('Can\'t get row type ' . $rowId . ' from clientspace ' . $cs . ' of page ' . $cms_page->getID() . ' with row id ' . $rowTag); $view->setActionMessage($cms_language->getJsMessage(MESSAGE_PAGE_ERROR_UPDATE_BLOCK_CONTENT)); } } else { CMS_grandFather::raiseError('Can\'t get block class type ' . $blockClass . ' to update content'); $view->setActionMessage($cms_language->getJsMessage(MESSAGE_PAGE_ERROR_UPDATE_BLOCK_CONTENT)); } break; default: CMS_grandFather::raiseError('Unknown action ' . $action . ' to do for page ' . $currentPage); $view->show(); break; } //set user message if any if (isset($cms_message) && $cms_message) { $view->setActionMessage($cms_message); } //Eval PHP content if any $content = $view->getContent(); if (io::strpos($content, '<?php') !== false) { ob_start(); $content = sensitiveIO::evalPHPCode($content); $return = ob_get_clean(); $content = $return . $content; //set datas as returned content $view->setContent($content); } $view->show();
protected function _getFieldsFiles($item, &$files) { //get object fields definitions $objectFields = CMS_poly_object_catalog::getFieldsDefinition($item->getObjectID()); $itemFieldsObjects =& $item->getFieldsObjects(); foreach ($itemFieldsObjects as $fieldID => $itemField) { //check field type $fieldType = $objectFields[$fieldID]->getValue('type'); if (sensitiveIO::isPositiveInteger($fieldType)) { //this field is a poly_object so recurse on his values $this->_getFieldsFiles($itemField, $files); } elseif (io::strpos($fieldType, "multi|") !== false) { //this field is a multi_poly_object so recurse on all poly_objects it contain $params = $itemField->getParamsValues(); if ($itemField->getValue('count')) { $items = $itemField->getValue('fields'); foreach ($items as $anItem) { $this->_getFieldsFiles($anItem, $files); } } } else { //if this field is a file, check for file if ($fieldType == 'CMS_object_file') { if ($itemField->getValue('filename')) { $files[] = PATH_REALROOT_FS . $itemField->getValue('filePath') . '/' . $itemField->getValue('filename'); } } } } return; }
} } //websites denied $websites = CMS_websitesCatalog::getAll(); $deniedWebsites = array(); foreach ($websites as $id => $website) { if (!in_array($id, $selectedWebsites)) { $deniedWebsites[] = $id; } } $template->delAllWebsiteDenied(); foreach ($deniedWebsites as $deniedWebsite) { $template->denyWebsite($deniedWebsite); } //XML definition file if ($definitionfile && io::strpos($definitionfile, PATH_UPLOAD_WR . '/') !== false) { //read uploaded file $definitionfile = new CMS_file($definitionfile, CMS_file::WEBROOT); $template->setDebug(false); $template->setLog(false); $error = $template->setDefinition($definitionfile->readContent()); if ($error !== true) { $cms_message = $cms_language->getMessage(MESSAGE_PAGE_MALFORMED_DEFINITION_FILE) . "\n\n" . $error; } } if (!$cms_message && !$template->hasError()) { if ($template->writeToPersistence()) { $log = new CMS_log(); $log->logMiscAction(CMS_log::LOG_ACTION_TEMPLATE_EDIT, $cms_user, "Template : " . $template->getLabel() . " (create template)"); $content = array('success' => array('templateId' => $template->getID())); $cms_message = $cms_language->getMessage(MESSAGE_ACTION_CREATION_DONE);
/** * 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, flash file copy failed : " . PATH_MODULES_FILES_STANDARD_FS . "/public/" . $_newFilename); } } //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\tfile='" . SensitiveIO::sanitizeSQLString($_newFilename) . "',\n\t\t\t\t\t\twidth='" . SensitiveIO::sanitizeSQLString($this->_width) . "',\n\t\t\t\t\t\theight='" . SensitiveIO::sanitizeSQLString($this->_height) . "',\n\t\t\t\t\t\tname='" . SensitiveIO::sanitizeSQLString($this->_name) . "',\n\t\t\t\t\t\tversion='" . SensitiveIO::sanitizeSQLString($this->_version) . "',\n\t\t\t\t\t\tparams='" . SensitiveIO::sanitizeSQLString($this->_params) . "',\n\t\t\t\t\t\tflashvars='" . SensitiveIO::sanitizeSQLString($this->_flashvars) . "',\n\t\t\t\t\t\tattributes='" . SensitiveIO::sanitizeSQLString($this->_flashattributes) . "'\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 flash failed: " . $sql); } } else { $this->raiseError("Duplicate, copy of file failed :" . PATH_MODULES_FILES_STANDARD_FS . "/edited/" . $this->_file); } } return false; }