/** * Proceed to file upload * * @return boolean true if file upload successfully done, false otherwise * @access public */ function doUpload() { if ($this->ready()) { if ($this->_checkDestinationPath()) { // Check file size and server max uploading file size if ($this->inputFileTooWide()) { $this->raiseError("File too wide for server (" . $this->getInputValue("name") . "), upload failed"); return false; } //move uploaded file $fileDatas = CMS_file::uploadFile($this->getInputValue("tmp_name"), PATH_TMP_FS); if ($fileDatas['error']) { $this->raiseError("Move uploaded file " . $this->getInputValue("tmp_name") . " to " . $this->_pathes["destination"] . " failed"); return false; } if (!CMS_file::moveTo(PATH_TMP_FS . '/' . $fileDatas['filename'], $this->_pathes["destination"])) { $this->raiseError("Move uploaded file " . $this->getInputValue("tmp_name") . " to " . $this->_pathes["destination"] . " failed"); return false; } $this->file = new CMS_file($this->_pathes["destination"]); return $this->file->chmod(FILES_CHMOD); } else { return false; } } 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; } }
/** * Move the data of a resource from one data location to another. * May be used by every module, provided it respects the naming rules described in the modules HOWTO * * @param string $module, The module codename * @param integer $resourceID The DB ID of the resource whose data we want to move * @param string $locationFrom The starting location, among the available RESOURCE_DATA_LOCATION * @param string $locationTo The ending location, among the available RESOURCE_DATA_LOCATION * @param boolean $copyOnly If set to true, the deletion from the originating tables and dirs won't occur * @return boolean true on success, false on failure * @access public * @static */ function moveResourceData($module, $resourceID, $locationFrom, $locationTo, $copyOnly = false) { //get all datas locations $locations = CMS_resource::getAllDataLocations(); if (!in_array($locationFrom, $locations)) { CMS_grandFather::raiseError("LocationFrom is not a valid location : " . $locationFrom); return false; } if (!in_array($locationTo, $locations)) { CMS_grandFather::raiseError("LocationTo is not a valid location : " . $locationTo); return false; } if (!sensitiveIO::IsPositiveInteger($resourceID)) { CMS_grandFather::raiseError("ResourceID must be a positive integer : " . $resourceID); return false; } //first move DB datas $tables_prefixes = array('mod_subobject_date_', 'mod_subobject_integer_', 'mod_subobject_string_', 'mod_subobject_text_'); foreach ($tables_prefixes as $table_prefix) { //delete all in the destination table and insert new ones if ($locationTo != RESOURCE_DATA_LOCATION_DEVNULL) { $sql = "\n\t\t\t\t\tdelete from\n\t\t\t\t\t\t" . $table_prefix . $locationTo . "\n\t\t\t\t\twhere\n\t\t\t\t\t\tobjectID='" . $resourceID . "'\n\t\t\t\t"; $q = new CMS_query($sql); $sql = "\n\t\t\t\t\treplace into\n\t\t\t\t\t\t" . $table_prefix . $locationTo . "\n\t\t\t\t\t\tselect\n\t\t\t\t\t\t\t*\n\t\t\t\t\t\tfrom\n\t\t\t\t\t\t\t" . $table_prefix . $locationFrom . "\n\t\t\t\t\t\twhere\n\t\t\t\t\t\t\tobjectID='" . $resourceID . "'\n\t\t\t\t"; $q = new CMS_query($sql); } if (!$copyOnly) { //delete from the starting table $sql = "\n\t\t\t\t\tdelete from\n\t\t\t\t\t\t" . $table_prefix . $locationFrom . "\n\t\t\t\t\twhere\n\t\t\t\t\t\tobjectID='" . $resourceID . "'\n\t\t\t\t"; $q = new CMS_query($sql); } } //second, move the files $locationFromDir = new CMS_file(PATH_MODULES_FILES_FS . "/" . $module . "/" . $locationFrom, CMS_file::FILE_SYSTEM, CMS_file::TYPE_DIRECTORY); //cut here if the locationFromDir doesn't exists. That means the module doesn't have files if (!$locationFromDir->exists()) { return true; } if ($locationTo != RESOURCE_DATA_LOCATION_DEVNULL) { $locationToDir = new CMS_file(PATH_MODULES_FILES_FS . "/" . $module . "/" . $locationTo, CMS_file::FILE_SYSTEM, CMS_file::TYPE_DIRECTORY); //cut here if the locationToDir doesn't exists. if (!$locationToDir->exists()) { CMS_grandFather::raiseError("LocationToDir does not exists : " . PATH_MODULES_FILES_FS . "/" . $module . "/" . $locationTo); return false; } //delete all files of the locationToDir $files = glob(PATH_MODULES_FILES_FS . "/" . $module . "/" . $locationTo . '/r' . $resourceID . '_*', GLOB_NOSORT); if (is_array($files)) { foreach ($files as $file) { if (!CMS_file::deleteFile($file)) { $this->raiseError("Can't delete file " . $file); return false; } } } //then copy or move them to the locationToDir $files = glob(PATH_MODULES_FILES_FS . "/" . $module . "/" . $locationFrom . '/r' . $resourceID . '_*', GLOB_NOSORT); if (is_array($files)) { foreach ($files as $file) { $to = str_replace('/' . $locationFrom . '/', '/' . $locationTo . '/', $file); if ($copyOnly) { if (!CMS_file::copyTo($file, $to)) { $this->raiseError("Can't copy file " . $file . " to " . $to); return false; } } else { if (!CMS_file::moveTo($file, $to)) { $this->raiseError("Can't move file " . $file . " to " . $to); return false; } } //then chmod new file CMS_file::chmodFile(FILES_CHMOD, $to); } } } else { //then get all files of the locationFromDir $files = glob(PATH_MODULES_FILES_FS . "/" . $module . "/" . $locationFrom . '/r' . $resourceID . '_*', GLOB_NOSORT); if (is_array($files)) { foreach ($files as $file) { if (!CMS_file::deleteFile($file)) { $this->raiseError("Can't delete file " . $file); return false; } } } } return true; }
if (strpos($configContent, 'PATH_PAGES_HTML_WR') === false) { $configContent = str_replace('?>', '//HTML pages dir (DO NOT CHANGE)' . "\n" . 'define("PATH_PAGES_HTML_WR", "' . PATH_REALROOT_WR . '/html");' . "\n" . '?>', $configContent); $configFile->setContent($configContent); $configFile->writeToPersistence(); $actionsDone .= '- Add HTML directory constant PATH_PAGES_HTML_WR in config.php file <br/>'; } } } else { $actionsTodo .= '- Add the following config in config.php file <br/>'; $actionsTodo .= 'define("PATH_PAGES_HTML_WR", "' . PATH_REALROOT_WR . '/html");<br/>'; } } # Create config for /automne_modules_files if (is_dir(PATH_REALROOT_FS . '/automne_modules_files') && PATH_MODULES_FILES_FS == PATH_REALROOT_FS . '/files') { if ($configWritable) { $configFile = new CMS_file(PATH_REALROOT_FS . '/config.php'); if ($configFile->exists()) { $configContent = $configFile->getContent(); if (strpos($configContent, 'PATH_MODULES_FILES_WR') === false) { $configContent = str_replace('?>', '//Modules files dir (DO NOT CHANGE)' . "\n" . 'define("PATH_MODULES_FILES_WR", "' . PATH_REALROOT_WR . '/automne_modules_files");' . "\n" . '?>', $configContent); $configFile->setContent($configContent); $configFile->writeToPersistence(); $actionsDone .= '- Add modules files directory constant PATH_MODULES_FILES_WR in config.php file <br/>'; } } } else { $actionsTodo .= '- Add the following config in config.php file <br/>'; $actionsTodo .= 'define("PATH_MODULES_FILES_WR", "' . PATH_REALROOT_WR . '/automne_modules_files");<br/>'; } } if ($actionsTodo) {
} switch ($_POST["cms_action"]) { case "validate": $errorCorrected = false; //correct first error of the array $errors = CMS_session::getSessionVar('patchErrors'); $error = $errors[0]; switch ($error['no']) { case 5: //try to update a protected file (UPDATE.DENY) if ($_POST["updated_file"]) { $installParams = array_map("trim", explode("\t", $error['command'])); $updatedFile = new CMS_file(PATH_TMP_FS . $installParams[1]); $updatedFile->setContent(trim($_POST["updated_file"])); //add a flag file to mark file is updated $flagFile = new CMS_file(PATH_TMP_FS . $installParams[1] . '.updated'); $flagFile->setContent('ok'); if ($updatedFile->writeToPersistence() && $flagFile->writeToPersistence()) { $errorCorrected = true; } } else { $cms_message .= $cms_language->getMessage(MESSAGE_FORM_ERROR_MANDATORY_FIELDS); } break; default: $cms_message .= $cms_language->getMessage(MESSAGE_PAGE_ERROR_CANT_CORRECT); break; } if ($errorCorrected && !$cms_message) { unset($errors[0]); }
/** * Write to disk the linx file, i.e. the content for the specified page. * Doesn't translates the atm-linx tags. * Also writes the "print" linx file * * @return boolean true on success, false on failure to write the content to this file. * @access private */ function writeLinxFile() { $defaultLanguage = CMS_languagesCatalog::getDefaultLanguage(); //get public page content (without linxes process) $pageContent = $this->getContent($defaultLanguage, PAGE_VISUALMODE_HTML_PUBLIC); //then write the page linx file $linxFile = new CMS_file($this->getLinxFilePath()); $linxFile->setContent($pageContent); if (!$linxFile->writeToPersistence()) { $this->raiseError("Can't write linx file : " . $this->getLinxFilePath()); return false; } //writes the "print" linx file if any if (USE_PRINT_PAGES && $this->_template->getPrintingClientSpaces()) { //get print page content (without linxes process) $printPageContent = $this->getContent($defaultLanguage, PAGE_VISUALMODE_PRINT); //then write the print page linx file $linxFile = new CMS_file($this->getLinxFilePath() . ".print", CMS_file::FILE_SYSTEM, CMS_file::TYPE_FILE); $linxFile->setContent($printPageContent); if (!$linxFile->writeToPersistence()) { $this->raiseError("Can't write print linx file : " . $this->getLinxFilePath() . ".print"); return false; } } return true; }
/** * 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; }
if (!$cms_user->hasPageClearance($cms_page->getID(), CLEARANCE_PAGE_EDIT)) { CMS_grandFather::raiseError('Error, user has no rights on page : ' . $cms_page->getID()); $view->show(); } //get block datas if (class_exists($blockClass)) { $cms_block = new $blockClass(); $cms_block->initializeFromBasicAttributes($blockId); $rawDatas = $cms_block->getRawData($cms_page->getID(), $cs, $rowTag, RESOURCE_LOCATION_EDITION, false); } else { CMS_grandFather::raiseError('Error, can\'t get block class : ' . $blockClass); $view->show(); } $maxFileSize = CMS_file::getMaxUploadFileSize('K'); if ($rawDatas['file'] && file_exists(PATH_MODULES_FILES_STANDARD_FS . '/edition/' . $rawDatas['file'])) { $file = new CMS_file(PATH_MODULES_FILES_STANDARD_FS . '/edition/' . $rawDatas['file']); $fileDatas = array('filename' => $file->getName(false), 'filepath' => $file->getFilePath(CMS_file::WEBROOT), 'filesize' => $file->getFileSize(), 'fileicon' => $file->getFileIcon(CMS_file::WEBROOT), 'extension' => $file->getExtension()); } else { $fileDatas = array('filename' => '', 'filepath' => '', 'filesize' => '', 'fileicon' => '', 'extension' => ''); } $filePath = $fileDatas['filepath']; $fileDatas = sensitiveIO::jsonEncode($fileDatas); $flashvars = sensitiveIO::sanitizeJSString($rawDatas["flashvars"]); $params = sensitiveIO::sanitizeJSString($rawDatas["params"]); $attributes = sensitiveIO::sanitizeJSString($rawDatas["attributes"]); $jscontent = <<<END \tvar blockWindow = Ext.getCmp('{$winId}'); \t//set window title \tblockWindow.setTitle('{$cms_language->getJsMessage(MESSAGE_EDIT_FLASH)}'); \t//set help button on top of page \tblockWindow.tools['help'].show();
if ($file->setContent($definition) && $file->writeToPersistence()) { $log = new CMS_log(); $log->logMiscAction(CMS_log::LOG_ACTION_TEMPLATE_EDIT_FILE, $cms_user, "File : " . $node); $content = array('success' => true); $cms_message = $cms_language->getMessage(MESSAGE_ACTION_UPDATE_FILE, array($node)); } else { $cms_message = $cms_language->getMessage(MESSAGE_ERROR_UPDATE_FILE) . ' ' . $node; } } break; case 'create': if (is_dir($file) && $filelabel) { if (!is_file($file . '/' . $filelabel)) { $extension = io::strtolower(pathinfo($file . '/' . $filelabel, PATHINFO_EXTENSION)); if (isset($allowedFiles[$extension])) { $file = new CMS_file($file . '/' . $filelabel); if ($file->setContent($definition) && $file->writeToPersistence()) { $log = new CMS_log(); $log->logMiscAction(CMS_log::LOG_ACTION_TEMPLATE_EDIT_FILE, $cms_user, "File : " . $node . '/' . $filelabel); $content = array('success' => true); $cms_message = $cms_language->getMessage(MESSAGE_ACTION_CREATE_FILE, array($filelabel)); } else { $cms_message = $cms_language->getMessage(MESSAGE_ERROR_UPDATE_FILE) . ' ' . $filelabel; } } else { $cms_message = $cms_language->getMessage(MESSAGE_ERROR_CREATE_FILE_EXTENSION, array($filelabel)); } } else { $cms_message = $cms_language->getMessage(MESSAGE_ERROR_CREATE_FILE_EXISTS, array($filelabel)); } }
/** * Move the data of a resource from one data location to another. * May be used by every module, provided it respects the naming rules described in the modules HOWTO * * @param CMS_module $module The module who want its data moved * @param string $tablesPrefix The prefix of the tables containing the data * @param string $resourceIDFieldName The name of the field containing the resource ID * @param integer $resourceID The DB ID of the resource whose data we want to move * @param string $locationFrom The starting location, among the available RESOURCE_DATA_LOCATION * @param string $locationTo The ending location, among the available RESOURCE_DATA_LOCATION * @param boolean $copyOnly If set to true, the deletion from the originating tables and dirs won't occur * @return boolean true on success, false on failure * @access public */ static function moveResourceData(&$module, $tablesPrefix, $resourceIDFieldName, $resourceID, $locationFrom, $locationTo, $copyOnly = false) { if (!is_a($module, "CMS_module")) { CMS_grandFather::raiseError("Module is not a CMS_module"); return false; } if (!SensitiveIO::isInSet($locationFrom, CMS_resource::getAllDataLocations()) || !SensitiveIO::isInSet($locationTo, CMS_resource::getAllDataLocations())) { CMS_grandFather::raiseError("Locations are not in the set"); return false; } //get the tables : named PREFIXXXXX_public $sql = "show tables"; $q = new CMS_query($sql); $tables_prefixes = array(); while ($data = $q->getArray()) { if (preg_match("#" . $tablesPrefix . "(.*)_public#", $data[0])) { $tables_prefixes[] = io::substr($data[0], 0, strrpos($data[0], "_") + 1); } } foreach ($tables_prefixes as $table_prefix) { //delete all in the destination table just incase and insert if ($locationTo != RESOURCE_DATA_LOCATION_DEVNULL) { $sql = "\n\t\t\t\t\tdelete from\n\t\t\t\t\t\t" . $table_prefix . $locationTo . "\n\t\t\t\t\twhere\n\t\t\t\t\t\t" . $resourceIDFieldName . "='" . $resourceID . "'\n\t\t\t\t"; $q = new CMS_query($sql); $sql = "\n\t\t\t\t\tinsert into\n\t\t\t\t\t\t" . $table_prefix . $locationTo . "\n\t\t\t\t\t\tselect\n\t\t\t\t\t\t\t*\n\t\t\t\t\t\tfrom\n\t\t\t\t\t\t\t" . $table_prefix . $locationFrom . "\n\t\t\t\t\t\twhere\n\t\t\t\t\t\t\t" . $resourceIDFieldName . "='" . $resourceID . "'\n\t\t\t\t"; $q = new CMS_query($sql); } if (!$copyOnly) { //delete from the starting table $sql = "\n\t\t\t\t\tdelete from\n\t\t\t\t\t\t" . $table_prefix . $locationFrom . "\n\t\t\t\t\twhere\n\t\t\t\t\t\t" . $resourceIDFieldName . "='" . $resourceID . "'\n\t\t\t\t"; $q = new CMS_query($sql); } } //second, move the files $locationFromDir = new CMS_file(PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationFrom, CMS_file::FILE_SYSTEM, CMS_file::TYPE_DIRECTORY); //cut here if the locationFromDir doesn't exists. That means the module doesn't have files if (!$locationFromDir->exists()) { return true; } if ($locationTo != RESOURCE_DATA_LOCATION_DEVNULL) { $locationToDir = new CMS_file(PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationTo, CMS_file::FILE_SYSTEM, CMS_file::TYPE_DIRECTORY); //cut here if the locationToDir doesn't exists. if (!$locationToDir->exists()) { CMS_grandFather::raiseError("LocationToDir does not exists : " . PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationTo); return false; } //delete all files of the locationToDir $files = glob(PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationTo . '/r' . $resourceID . '_*', GLOB_NOSORT); if (is_array($files)) { foreach ($files as $file) { if (!CMS_file::deleteFile($file)) { CMS_grandFather::raiseError("Can't delete file " . $file); return false; } } } //then copy or move them to the locationToDir $files = glob(PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationFrom . '/r' . $resourceID . '_*', GLOB_NOSORT); if (is_array($files)) { foreach ($files as $file) { $to = str_replace('/' . $locationFrom . '/', '/' . $locationTo . '/', $file); if ($copyOnly) { if (!CMS_file::copyTo($file, $to)) { CMS_grandFather::raiseError("Can't copy file " . $file . " to " . $to); return false; } } else { if (!CMS_file::moveTo($file, $to)) { CMS_grandFather::raiseError("Can't move file " . $file . " to " . $to); return false; } } //then chmod new file CMS_file::chmodFile(FILES_CHMOD, $to); } } } //cleans the initial dir if not a copy if (!$copyOnly) { //then get all files of the locationFromDir $files = glob(PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationFrom . '/r' . $resourceID . '_*', GLOB_NOSORT); if (is_array($files)) { foreach ($files as $file) { if (!CMS_file::deleteFile($file)) { CMS_grandFather::raiseError("Can't delete file " . $file); return false; } } } } return true; }
/** * Module script task * @param array $parameters the task parameters * task : string task to execute * object : string module codename for the task * field : string module uid * ... : optional field relative parameters * @return Boolean true/false * @access public */ function scriptTask($parameters) { switch ($parameters['task']) { case 'emailNotification': @set_time_limit(300); $module = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID()); //create a new script for all recipients $allUsers = $this->_getRecipients($parameters['object']); foreach ($allUsers as $userId) { //add script to send email for user if needed CMS_scriptsManager::addScript($module, array('task' => 'emailSend', 'user' => $userId, 'field' => $parameters['field'], 'object' => $parameters['object'])); } //then set sending date to current date $sendingDate = new CMS_date(); $sendingDate->setNow(); $this->_subfieldValues[1]->setValue($sendingDate->getDBValue()); $this->writeToPersistence(); break; case 'emailSend': @set_time_limit(300); $params = $this->getParamsValues(); if (!sensitiveIO::isPositiveInteger($parameters['user'])) { return false; } //instanciate script related item $item = CMS_poly_object_catalog::getObjectByID($parameters['object'], false, true); if (!is_object($item) || $item->hasError()) { return false; } //instanciate user $cms_user = new CMS_profile_user($parameters['user']); //check user if (!$cms_user || $cms_user->hasError() || !$cms_user->isActive() || $cms_user->isDeleted() || !sensitiveIO::isValidEmail($cms_user->getEmail())) { return false; } $cms_language = $cms_user->getLanguage(); //globalise cms_user and cms_language $GLOBALS['cms_language'] = $cms_user->getLanguage(); $GLOBALS['cms_user'] = $cms_user; //check user clearance on object if (!$item->userHasClearance($cms_user, CLEARANCE_MODULE_VIEW)) { return false; } //create email subject $parameters['item'] = $item; $parameters['public'] = true; $polymodParsing = new CMS_polymod_definition_parsing($params['emailSubject'], false); $subject = $polymodParsing->getContent(CMS_polymod_definition_parsing::OUTPUT_RESULT, $parameters); $body = ''; //create email body if ($params['emailBody']['type'] == 1) { //send body $parameters['module'] = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID()); $polymodParsing = new CMS_polymod_definition_parsing($params['emailBody']['html'], true, CMS_polymod_definition_parsing::PARSE_MODE, $parameters['module']); $body = $polymodParsing->getContent(CMS_polymod_definition_parsing::OUTPUT_RESULT, $parameters); } elseif ($params['emailBody']['type'] == 2) { //send a page $page = CMS_tree::getPageById($params['emailBody']['pageID']); if (!$page || $page->hasError()) { $this->raiseError('Page ID is not a valid page : ' . $params['emailBody']['pageID']); return false; } $pageHTMLFile = new CMS_file($page->getHTMLURL(false, false, PATH_RELATIVETO_FILESYSTEM)); if (!$pageHTMLFile->exists()) { $this->raiseError('Page HTML file does not exists : ' . $page->getHTMLURL(false, false, PATH_RELATIVETO_FILESYSTEM)); return false; } $body = $pageHTMLFile->readContent(); //create page URL call $polymodParsing = new CMS_polymod_definition_parsing($params['emailBody']['pageURL'], false); $pageURL = $polymodParsing->getContent(CMS_polymod_definition_parsing::OUTPUT_RESULT, $parameters); parse_str($pageURL, $GLOBALS['_REQUEST']); //$GLOBALS['_REQUEST'] //parse and eval HTML page $cms_page_included = true; $GLOBALS['cms_page_included'] = $cms_page_included; //eval() the PHP code $body = sensitiveIO::evalPHPCode($body); $website = $page->getWebsite(); $webroot = $website->getURL(); //replace URLs values $replace = array('="/' => '="' . $webroot . '/', "='/" => "='" . $webroot . "/", "url(/" => "url(" . $webroot . "/"); $body = str_replace(array_keys($replace), $replace, $body); } else { $this->raiseError('No valid email type to send : ' . $params['emailBody']['type']); return false; } if (isset($sendmail)) { //$body .= print_r($sendmail,true); } //drop email sending if (isset($sendmail) && $sendmail === false) { return false; } //if no body for email or if sendmail var is set to false, quit if (!$body) { $this->raiseError('No email body to send ... Email parameters : user : '******'user'] . ' - object ' . $parameters['object']); return false; } //This code is for debug purpose only. //$testFile = new CMS_file('/test/test_'.$cms_user->getUserId().'.php', CMS_file::WEBROOT); //$testFile->setContent($body); //$testFile->writeToPersistence(); // Set email $email = new CMS_email(); $email->setSubject($subject); $email->setEmailHTML($body); $email->setEmailTo($cms_user->getEmail()); if ($params['includeFiles']) { //check for file fields attached to object $files = array(); $this->_getFieldsFiles($item, $files); if (sizeof($files)) { foreach ($files as $file) { $email->setFile($file); } } } //set email From if (!$params['emailFrom']) { $email->setFromName(APPLICATION_LABEL); $email->setEmailFrom(APPLICATION_POSTMASTER_EMAIL); } else { $email->setFromName($params['emailFrom']); $email->setEmailFrom($params['emailFrom']); } //Send if ($email->sendEmail()) { //store email sent number $this->_subfieldValues[2]->setValue($this->_subfieldValues[2]->getValue() + 1); $this->writeToPersistence(); return true; } else { return false; } break; default: $this->raiseError('No valid task given : ' . $parameters['task']); return false; break; } }
//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); $view->setContent($content); } else {
report('Start patching process...'); $automnePatch = new CMS_patch($cms_user); //read patch or export param file and check versions verbose('Read patch file...'); $patchFile = new CMS_file(PATH_TMP_FS . "/patch"); $exportFile = new CMS_file(PATH_TMP_FS . "/export.xml"); if ($patchFile->exists()) { $patch = $patchFile->readContent("array"); if (!$automnePatch->checkPatch($patch)) { report('Error : Patch does not match current version ...', true); } else { verbose('-> Patch version match.'); } //read install param file and do maximum check on it before starting the installation process verbose('Read install file...'); $installFile = new CMS_file(PATH_TMP_FS . "/install"); if ($installFile->exists()) { $install = $installFile->readContent("array"); } else { report('Error : File ' . PATH_TMP_FS . '/install does not exists ... This file is not a valid Automne patch.', true); } $installError = $automnePatch->checkInstall($install, $errorsInfos); if ($installError) { report('Error : Invalid install file :'); $stopProcess = $automnePatch->canCorrectErrors($errorsInfos) ? false : true; report($installError, $stopProcess); if (!$force) { //if process continue, then we can correct patch errors. //save errors infos CMS_session::setSessionVar('patchErrors', $errorsInfos); //go to errors correction page
/** * Parse the content of a template for module parameters and returns the content. * Usually used by the getData() function to handle template files and feed them with module parameters * * @param string $filename The filename of the template, located in the templates directory * @return string the data from the rows. * @access private */ protected function _parseTemplateForParameters($filename) { $module = CMS_modulesCatalog::getByCodename($this->_attributes["module"]); if (!$module instanceof CMS_module) { $this->raiseError("No module defined for the clientspace"); return false; } $parameters = $module->getParameters(); $templateFile = new CMS_file(PATH_TEMPLATES_FS . "/" . $filename); if ($templateFile->exists()) { $cdata = $templateFile->getContent(); //no need to be complicated if no parameters if (!$parameters) { return $cdata; } //"parse" template for parameters. No XML parsing (PHP code produces strange results) //MUST wipe out the linefeeds, because pcre's stop at them !!! $cdata_pcre = str_replace("\n", "§§", $cdata); while (true) { unset($regs); preg_match('/(.*)(<module-param [^>]*\\/>)(.*)/', $cdata_pcre, $regs); if (isset($regs[2])) { $param_value = ''; $domdocument = new CMS_DOMDocument(); try { $domdocument->loadXML('<dummy>' . $regs[2] . '</dummy>'); } catch (DOMException $e) { $this->raiseError('Parse error during search for module-param parameters : ' . $e->getMessage() . " :\n" . io::htmlspecialchars($regs[2])); return false; } $paramsTags = $domdocument->getElementsByTagName('module-param'); foreach ($paramsTags as $paramTag) { $param_value = str_replace("\n", "§§", $parameters[$paramTag->getAttribute("name")]); } $cdata_pcre = $regs[1] . $param_value . $regs[3]; } else { break; } } $cdata = str_replace("§§", "\n", $cdata_pcre); return $cdata; } else { $this->raiseError("Template " . $filename . " isn't readable"); return false; } }
/** * Launch script PATH_AUTOMNE_CHMOD_SCRIPT_FS * * @return boolean true on success, false on failure. * @access public */ function automneGeneralScript() { $chmodScript = new CMS_file(PATH_AUTOMNE_CHMOD_SCRIPT_FS); if ($chmodScript->exists()) { $commandLine = $chmodScript->readContent("array"); } else { $this->_report('Error : File ' . PATH_AUTOMNE_CHMOD_SCRIPT_FS . ' does not exists ...', true); return false; } //read command lines and do maximum check on it before starting the installation process $this->_verbose('Read script...'); $installError = $this->checkInstall($commandLine, $errorsInfos, false); //start command process $this->_verbose('Execute script...'); $this->doInstall($commandLine); if ($installError) { $this->_report('Error with command :'); $this->_report($installError); return false; } else { return true; } }
$jsfiles[] = PATH_ADMIN_JS_FS . '/ext/GMapPanel.js'; $jsfiles[] = PATH_ADMIN_JS_FS . '/ext/Connection.js'; //set specific source debug files here //$jsfiles [] = PATH_MAIN_FS.'/ext/source/data/Connection.js'; $jsfiles[] = PATH_ADMIN_JS_FS . '/ext/conf.js'; break; case 'fr': //Ext french locales $jsfiles[] = PATH_MAIN_FS . '/ext/src/locale/ext-lang-fr.js'; break; case 'en': //Ext english locales (nothing for now) break; default: $replace = array('..' => '', '\\' => '', '/' => ''); $docrootPath = realpath($_SERVER["DOCUMENT_ROOT"] . $file); $realrootPath = realpath(PATH_REALROOT_FS . '/' . $file); $dirnamePath = realpath(dirname(__FILE__) . '/' . $file); if ($file == str_replace(array_keys($replace), $replace, $file) && file_exists($dirnamePath) && is_file($dirnamePath)) { $jsfiles[] = $dirnamePath; } elseif (pathinfo($file, PATHINFO_EXTENSION) == 'js' && substr($file, 0, 1) == '/' && file_exists($docrootPath) && is_file($docrootPath) && (strpos(pathinfo($docrootPath, PATHINFO_DIRNAME), realpath(PATH_JS_FS)) === 0 || strpos(pathinfo($docrootPath, PATHINFO_DIRNAME), realpath(PATH_ADMIN_JS_FS)) === 0)) { $jsfiles[] = $docrootPath; } elseif (pathinfo($file, PATHINFO_EXTENSION) == 'js' && substr($file, 0, 1) != '/' && file_exists($realrootPath) && is_file($realrootPath) && (strpos(pathinfo($realrootPath, PATHINFO_DIRNAME), realpath(PATH_JS_FS)) === 0 || strpos(pathinfo($realrootPath, PATHINFO_DIRNAME), realpath(PATH_ADMIN_JS_FS)) === 0)) { $jsfiles[] = $realrootPath; } break; } } } CMS_file::sendFiles($jsfiles, 'text/javascript');
<br /> <input onclick="manageFormFromDefault();" type="button" fckLang="DlgCMSFormsReturn" value="Retour au formulaire"><br /> ' . $cms_language->getMessage(MESSAGE_PAGE_BLOCK_GENERAL_VARS_EXPLANATION, array($cms_language->getDateFormatMask(), $cms_language->getDateFormatMask(), $cms_language->getDateFormatMask())) . ' </div> <div id="divFileParams" style="display: none"> <strong><span fckLang="DlgCMSFormsFileParamsTitle">Modifiez ici les parametres :</span></strong> <input id="fieldIDFileParamValue" type="hidden" name="formIDValue" value="" /> <input id="serverMaxFileSize" type="hidden" name="serverMaxFileSize" value="' . CMS_file::getMaxUploadFileSize('K') . '" /> <div style="display:none;" id="fileParamsError"><span style="color:red;" fckLang="DlgCMSFormsFileParamsError">Erreur</span></div> <table width="100%"> <tr> <td nowrap width="100%" colSpan="4"><span fckLang="DlgCMSFormsAllowedExtensions">Extensions autorisees :</span> <input style="WIDTH: 50%" id="fileParamsExtensions" type="text"> <span fckLang="allowedExtensionsHelp">Separees par des points-virgules</span></td> </tr> <tr> <td nowrap width="100%" colSpan="4"><span fckLang="DlgCMSFormsMaxWeight">Poids maximum :</span> <input style="WIDTH: 20%" id="fileParamsWeight" type="text"> <span fckLang="DlgCMSFormsMaxWeightHelp">ko (1Mo = 1024Ko)</span> <br/><span fckLang="DlgCMSFormsMaxServerFileSize">Max server file size</span>' . CMS_file::getMaxUploadFileSize('K') . 'Ko (' . CMS_file::getMaxUploadFileSize('M') . 'Mo) </td> </tr> </table> <br /> <input onclick="manageFormFromFileParams();" type="button" fckLang="DlgCMSFormsReturn" value="Retour au formulaire"><br /> ' . $cms_language->getMessage(MESSAGE_PAGE_BLOCK_GENERAL_VARS_EXPLANATION, array($cms_language->getDateFormatMask(), $cms_language->getDateFormatMask(), $cms_language->getDateFormatMask())) . ' </div>'; break; case 4: // used to send server form content to wysiwyg after analyse $replace = array("\n" => "", "\r" => "", "'" => "\\'"); //pr($xhtml); $content = ' <div id="divInfo" style="DISPLAY: none"> <input id="codeSent" name="codeSent" value="" type="hidden" />
$extension = ''; $fileId = md5(rand()); $fileDefinition = ''; $labelField = "{\n\t\txtype:\t\t\t'textfield',\n\t\tvalue:\t\t\t'',\n\t\tname:\t\t\t'filelabel',\n\t\tfieldLabel:\t\t'{$cms_language->getJsMessage(MESSAGE_PAGE_LABEL)}',\n\t\tborder:\t\t\tfalse,\n\t\tbodyStyle: \t\t'padding-bottom:10px'\n\t},"; $anchor = '-110'; $action = 'create'; } else { //file edition $fileCreation = false; $extension = io::strtolower(pathinfo($file, PATHINFO_EXTENSION)); if (!isset($allowedFiles[$extension])) { CMS_grandFather::raiseError('Action on this type of file is not allowed.'); $view->show(); } $fileId = md5($file); $file = new CMS_file($file); $fileDefinition = $file->readContent(); $labelField = ''; $anchor = '-60'; $action = 'update'; } if (strtolower(APPLICATION_DEFAULT_ENCODING) == 'utf-8') { if (!io::isUTF8($fileDefinition)) { $fileDefinition = utf8_encode($fileDefinition); } } else { if (io::isUTF8($fileDefinition)) { $fileDefinition = utf8_decode($fileDefinition); } } //DEFINITION TAB
/** * Get field XHTML * * @param CMS_language $formLanguage : the language for messages * @return array array(label, input) */ function getFieldXHTML($formLanguage = '') { // Language global $cms_language; if (!$formLanguage) { $formLanguage = $cms_language; } //generate field id datas $fieldIDDatas = $this->generateFieldIdDatas(); $input = $label = ''; switch ($this->getAttribute("type")) { case 'hidden': $input = '<input type="hidden" value="' . io::htmlspecialchars($this->getAttribute("value")) . '" id="' . $fieldIDDatas . '" name="' . $this->getAttribute("name") . '" />'; break; case 'select': $label = '<label for="' . $fieldIDDatas . '">' . $this->getAttribute("label") . '</label>'; $input = '<select name="' . $this->getAttribute("name") . '" id="' . $fieldIDDatas . '">'; $options = $this->getAttribute("options"); if (sizeof($options)) { foreach ($options as $aValue => $anOption) { $selected = $this->getAttribute("value") == $aValue ? ' selected="selected"' : ''; $input .= '<option value="' . $aValue . '"' . $selected . '>' . $anOption . '</option>'; } } $input .= '</select>'; break; case 'text': case 'email': case 'url': case 'integer': case 'file': case 'pass': case 'checkbox': $label = '<label for="' . $fieldIDDatas . '">' . $this->getAttribute("label") . '</label>'; $input = '<input'; $fileHelp = ''; switch ($this->getAttribute("type")) { case 'file': $input .= ' type="file"'; $fileParams = $this->getAttribute("params"); $fileHelpTab = array(); if ($fileParams) { foreach ($fileParams as $fileParamName => $fileParamValue) { switch ($fileParamName) { case 'extensions': $fileHelpTab['extensions'] = $formLanguage->getMessage(self::MESSAGE_CMS_FORMS_FILE_PARAMS_ALLOWED_EXTENSIONS, false, MOD_CMS_FORMS_CODENAME) . ' ' . $fileParamValue; break; case 'weight': $fileHelpTab['weight'] = $formLanguage->getMessage(self::MESSAGE_CMS_FORMS_FILE_PARAMS_MAX_FILESIZE, false, MOD_CMS_FORMS_CODENAME) . ' ' . $fileParamValue . 'Ko'; break; } } } if (!isset($fileHelpTab['weight'])) { $fileHelpTab['weight'] = $formLanguage->getMessage(self::MESSAGE_CMS_FORMS_FILE_PARAMS_MAX_FILESIZE, false, MOD_CMS_FORMS_CODENAME) . ' ' . CMS_file::getMaxUploadFileSize('K') . 'Ko'; } if ($fileHelpTab) { $fileHelp = '<br/>(' . implode(' ; ', $fileHelpTab) . ')'; } break; case 'pass': $input .= ' type="password" value=""'; break; case 'checkbox': $input .= ' type="checkbox" value="1" class="checkbox" ' . ($this->getAttribute("value") ? ' checked="checked"' : ''); break; case 'text': case 'email': case 'url': case 'integer': default: $input .= ' type="text" value="' . io::htmlspecialchars($this->getAttribute("value")) . '"'; break; } $fileHelp = $fileHelp ? ' <span class="inputHelp">' . $fileHelp . '</span>' : ''; $input .= ' id="' . $fieldIDDatas . '" name="' . $this->getAttribute("name") . '" />' . $fileHelp; break; case 'submit': $input = '<input id="' . $fieldIDDatas . '" type="submit" class="button" name="' . $this->getAttribute("name") . '" value="' . $this->getAttribute("label") . '" />'; break; case 'textarea': $label = '<label for="' . $fieldIDDatas . '">' . $this->getAttribute("label") . '</label>'; $input = '<textarea cols="40" rows="6" id="' . $fieldIDDatas . '" name="' . $this->getAttribute("name") . '">' . io::htmlspecialchars($this->getAttribute("value")) . '</textarea>'; break; } return array($label, $input); }
/** * Remove a file located in the edited, public, archived and edition directory of the module * * @param string $filename name of the file to remove */ private function removeFilesFromModuleDirectory($filename) { $moduleDirectories = array(RESOURCE_DATA_LOCATION_EDITED, RESOURCE_DATA_LOCATION_PUBLIC, RESOURCE_DATA_LOCATION_ARCHIVED, RESOURCE_DATA_LOCATION_EDITION); foreach ($moduleDirectories as $directory) { if (file_exists(PATH_MODULES_FILES_FS . '/' . $this->_codename . '/' . $directory . '/' . $filename)) { CMS_file::deleteFile(PATH_MODULES_FILES_FS . '/' . $this->_codename . '/' . $directory . '/' . $filename); } } }
/** * 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; } } } } }
/** * Raises an error. Shows it to the screen * Deprecated, use raiseError instead * @param string $errorMessage the error message. * @param boolean $encodeOutput, does the screen output should be encoded (default : false) * @return void * @access public */ public function _raiseError($errorMessage, $encodeOutput = false, $error = true) { static $errorNumber; $systemDebug = !defined('SYSTEM_DEBUG') ? true : SYSTEM_DEBUG; if (isset($this) && isset($this->_debug) && $this->_debug === NULL) { $this->_debug = $systemDebug; } if ($errorMessage) { //second condition are for static calls (made by static methods) if (!defined('APPLICATION_EXEC_TYPE') || APPLICATION_EXEC_TYPE == 'http' && (!isset($this) && $systemDebug || isset($this) && isset($this->_debug) && $this->_debug)) { $backTrace = $backTraceLink = ''; if (version_compare(phpversion(), "5.2.5", "<")) { $bt = @array_reverse(debug_backtrace()); } else { $bt = @array_reverse(debug_backtrace(false)); } $backtrace = array('summary' => sensitiveIO::printBackTrace($bt), 'backtrace' => @print_r($bt, true)); $backtraceName = 'bt_' . md5(rand()); $backTraceLink = PATH_ADMIN_WR . '/backtrace.php?bt=' . $backtraceName; //save backtrace to cache (for 10 min) $cache = new CMS_cache($backtraceName, 'atm-backtrace', 600, false); if ($cache) { $cache->save($backtrace); } unset($backtrace, $cache, $bt); //append error to current view $view = CMS_view::getInstance(); $outputMessage = $encodeOutput ? io::htmlspecialchars($errorMessage) : $errorMessage; $view->addError(array('error' => $outputMessage, 'backtrace' => $backTraceLink)); } //second condition are for static calls (made by static methods) if (!isset($this) || !isset($this->_log) || $this->_log) { if (@file_put_contents(PATH_MAIN_FS . '/' . self::ERROR_LOG, date("Y-m-d H:i:s", time()) . '|' . APPLICATION_EXEC_TYPE . '|' . $errorMessage . "\n", FILE_APPEND) !== false) { CMS_file::chmodFile(FILES_CHMOD, PATH_MAIN_FS . '/' . self::ERROR_LOG); } else { die('<pre><b>' . CMS_view::SYSTEM_LABEL . ' ' . AUTOMNE_VERSION . ' error : /automne dir is not writable' . "</b></pre>\n"); } } } //must be at the end because it interferes with the static calls conditions above if ($error && isset($this)) { $this->_errRaised = true; } }
/** * Parse the definition file as to get the client spaces * * @param CMS_modulesTags $modulesTreatment tags object treatment * @return string The error string from the parser, false if no error * @access private */ protected function _parseDefinitionFile(&$modulesTreatment, $convert = null) { global $cms_language; if (!$this->_definitionFile) { return false; } $filename = PATH_TEMPLATES_FS . "/" . $this->_definitionFile; $tpl = new CMS_file(PATH_TEMPLATES_FS . "/" . $this->_definitionFile); if (!$tpl->exists()) { $this->raiseError('Can not found template file ' . PATH_TEMPLATES_FS . "/" . $this->_definitionFile); return false; } $definition = $tpl->readContent(); //we need to remove doctype if any $definition = trim(preg_replace('#<!doctype[^>]*>#siU', '', $definition)); $modulesTreatment->setDefinition($definition); //get client spaces modules codename $this->_clientSpacesTags = $modulesTreatment->getTags(array('atm-clientspace'), true); if (is_array($this->_clientSpacesTags)) { $modules = array(); foreach ($this->_clientSpacesTags as $cs_tag) { if ($cs_tag->getAttribute("module")) { $modules[] = $cs_tag->getAttribute("module"); } } $blocks = $modulesTreatment->getTags(array('block'), true); foreach ($blocks as $block) { if ($block->getAttribute("module")) { $modules[] = $block->getAttribute("module"); } else { return $cms_language->getMessage(self::MESSAGE_TPL_SYNTAX_ERROR, array($cms_language->getMessage(self::MESSAGE_BLOCK_SYNTAX_ERROR))); } } $modules = array_unique($modules); $this->_modules->emptyStack(); foreach ($modules as $module) { $this->_modules->add($module); } if ($convert !== null) { $tplConverted = false; foreach ($modules as $moduleCodename) { if (CMS_modulesCatalog::isPolymod($moduleCodename)) { $tplConverted = true; $module = CMS_modulesCatalog::getByCodename($moduleCodename); $definition = $module->convertDefinitionString($definition, $convert == self::CONVERT_TO_HUMAN); } } if ($tplConverted) { //check definition parsing $parsing = new CMS_polymod_definition_parsing($definition, true, CMS_polymod_definition_parsing::CHECK_PARSING_MODE); $errors = $parsing->getParsingError(); if ($errors) { return $cms_language->getMessage(self::MESSAGE_TPL_SYNTAX_ERROR, array($errors)); } $filename = $this->getDefinitionFile(); $file = new CMS_file(PATH_TEMPLATES_FS . "/" . $filename); $file->setContent($definition); $file->writeToPersistence(); } } return true; } else { $this->raiseError("Malformed definition file : " . $this->_definitionFile . "<br />" . $modulesTreatment->getParsingError()); return $modulesTreatment->getParsingError(); } }
/** * Import row from given array datas * * @param array $data The module datas to import * @param array $params The import parameters. * array( * create => false|true : create missing objects (default : true) * update => false|true : update existing objects (default : true) * files => false|true : use files from PATH_TMP_FS (default : true) * ) * @param CMS_language $cms_language The CMS_langage to use * @param array $idsRelation : Reference : The relations between import datas ids and real imported ids * @param string $infos : Reference : The import infos returned * @return boolean : true on success, false on failure * @access public */ function fromArray($data, $params, $cms_language, &$idsRelation, &$infos) { if (!$this->getID() && CMS_rowsCatalog::uuidExists($data['uuid'])) { //check imported uuid. If rows does not have an Id, the uuid must be unique or must be regenerated $uuid = io::uuid(); //store old uuid relation $idsRelation['rows-uuid'][$data['uuid']] = $uuid; $data['uuid'] = $uuid; } //set uuid if not exists if (!$this->_uuid) { $this->_uuid = $data['uuid']; } //icon if (!isset($params['files']) || $params['files'] == true) { if (isset($data['image'])) { $icon = $data['image']; //create icon (do not update existing icon) if ($icon && file_exists(PATH_TMP_FS . $icon) && !file_exists(PATH_REALROOT_FS . $icon)) { //move and rename icon file $filename = PATH_TMP_FS . $icon; $basename = pathinfo($filename, PATHINFO_BASENAME); if ($basename != 'nopicto.gif') { if (CMS_file::copyTo($filename, PATH_REALROOT_FS . $icon)) { //set it $this->setImage($basename); } } } } } //label if (isset($data['label'])) { $this->setLabel($data['label']); } //description if (isset($data['description'])) { $this->setDescription($data['description']); } //groups if (isset($data['groups'])) { $this->delAllGroups(); $groups = explode(';', $data['groups']); foreach ($groups as $group) { if ($group) { $this->addGroup($group); } } } //usability if (isset($data['useable'])) { $this->setUsability($data['useable']); } //definition & module if (!isset($params['files']) || $params['files'] == true) { if (isset($data['definition']) && $data['definition']) { if (!isset($params['updateRows']) || $params['updateRows'] == true) { //set definition (and unescape cdata) $return = $this->setDefinition(str_replace(']]\\>', ']]>', $data['definition']), false); if ($return !== true) { $infos .= 'Error : cannot set row definition ... : ' . $return . "\n"; return false; } } } } //write object if (!$this->writeToPersistence()) { $infos .= 'Error : cannot write row ...' . "\n"; return false; } //if current row id has changed from imported id, set relation if (isset($data['id']) && $data['id'] && $this->getID() != $data['id']) { $idsRelation['rows'][$data['id']] = $this->getID(); } //set this object into definition to convert array so it can be converted again at end of import process $idsRelation['definitionToConvert'][] = $this; return true; }
CMS_file::chmodFile(FILES_CHMOD, $newFilename); $data["file"] = pathinfo($newFilename, PATHINFO_BASENAME); } elseif ($filename) { //keep old file $data["file"] = pathinfo($filename, PATHINFO_BASENAME); } else { $data["file"] = ''; } //Image Zoom if ($zoomname && io::strpos($zoomname, PATH_UPLOAD_WR . '/') !== false) { //move and rename uploaded file $zoomname = str_replace(PATH_UPLOAD_WR . '/', PATH_UPLOAD_FS . '/', $zoomname); $basename = pathinfo($zoomname, PATHINFO_BASENAME); $newFilename = $cms_block->getFilePath($basename, $cms_page, $cs, $rowTag, $blockId, true); CMS_file::moveTo($zoomname, $newFilename); CMS_file::chmodFile(FILES_CHMOD, $newFilename); $data["enlargedFile"] = pathinfo($newFilename, PATHINFO_BASENAME); } elseif ($zoomname) { //keep old file $data["enlargedFile"] = pathinfo($zoomname, PATHINFO_BASENAME); } else { $data["enlargedFile"] = ''; } //Link $link = $old_data['externalLink'] ? new CMS_href($old_data['externalLink']) : new CMS_href(); $linkDialog = new CMS_dialog_href($link); $linkDialog->create($imagelink, MOD_STANDARD_CODENAME, $cms_page->getID()); $link = $linkDialog->getHref(); $data['externalLink'] = $link->getTextDefinition(); $cms_block->writeToPersistence($cms_page->getID(), $cs, $rowTag, RESOURCE_LOCATION_EDITION, false, $data); //instanciate the clientspace
/** * Destroy this object, in DB and filesystem if needed * Destroy title label also * * @return boolean true on success, false on failure * @access public */ function destroy() { if ($this->_fieldID) { //delete all files of objects for this field $module = CMS_poly_object_catalog::getModuleCodenameForField($this->_fieldID); $filesDir = new CMS_file(PATH_MODULES_FILES_FS . '/' . $module, CMS_file::FILE_SYSTEM, CMS_file::TYPE_DIRECTORY); if ($filesDir->exists()) { //search all files of this field $filesList = $filesDir->getFileList(PATH_MODULES_FILES_FS . '/' . $module . '/*_f' . $this->_fieldID . '_*'); //then delete them foreach ($filesList as $aFile) { if (!CMS_file::deleteFile($aFile['name'])) { $this->raiseError("Can't delete file " . $aFile['name'] . " for field : " . $this->_fieldID); return false; } } } //delete all datas of objects for this field $tables = array('mod_subobject_date_deleted', 'mod_subobject_date_edited', 'mod_subobject_date_public', 'mod_subobject_integer_deleted', 'mod_subobject_integer_edited', 'mod_subobject_integer_public', 'mod_subobject_string_deleted', 'mod_subobject_string_edited', 'mod_subobject_string_public', 'mod_subobject_text_deleted', 'mod_subobject_text_edited', 'mod_subobject_text_public'); foreach ($tables as $aTable) { $sql = "\n\t\t\t\t\tdelete from\n\t\t\t\t\t\t" . $aTable . "\n\t\t\t\t\twhere\n\t\t\t\t\t\tobjectFieldID = '" . $this->_fieldID . "'\n\t\t\t\t"; $q = new CMS_query($sql); if ($q->hasError()) { $this->raiseError("Can't delete datas of table " . $aTable . " for field : " . $this->_fieldID); return false; } } //delete title label object if (sensitiveIO::IsPositiveInteger($this->_objectFieldValues["labelID"])) { $label = new CMS_object_i18nm($this->_objectFieldValues["labelID"]); $label->destroy(); } //delete field DB record $sql = "\n\t\t\t\tdelete from\n\t\t\t\t\tmod_object_field \n\t\t\t\twhere\n\t\t\t\t\tid_mof='" . $this->_fieldID . "'\n\t\t\t"; $q = new CMS_query($sql); if ($q->hasError()) { $this->raiseError("Can't delete datas of table mod_object_field for field : " . $this->_fieldID); return false; } //unset fields catalog in cache CMS_cache::clearTypeCache('atm-polymod-structure'); //Clear polymod cache //CMS_cache::clearTypeCacheByMetas('polymod', array('module' => CMS_poly_object_catalog::getModuleCodenameForField($this->_fieldID))); CMS_cache::clearTypeCache('polymod'); } //unset fields catalog in cache CMS_cache::clearTypeCacheByMetas('atm-polymod-structure', array('type' => 'fields')); //finally destroy object instance unset($this); return true; }
/** * get HTML admin (used to enter object values in admin) * * @param integer $fieldID, the current field id (only for poly object compatibility) * @param CMS_language $language, the current admin language * @param string prefixname : the prefix to use for post names * @return string : the html admin * @access public */ function getHTMLAdmin($fieldID, $language, $prefixName) { $return = parent::getHTMLAdmin($fieldID, $language, $prefixName); //$params = $this->getParamsValues(); //get module codename $moduleCodename = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID()); //create field value $maxFileSize = CMS_file::getMaxUploadFileSize('K'); $value = $this->_subfieldValues[0]->getValue(); $return['name'] = 'polymodFieldsValue[href' . $prefixName . $this->_field->getID() . '_0]'; $return['xtype'] = 'atmLinkField'; $return['value'] = (string) $value; $return['uploadCfg'] = array('file_size_limit' => $maxFileSize, 'file_types' => '*.*', 'file_types_description' => $language->getMessage(self::MESSAGE_OBJECT_HREF_ALL_FILES) . ' ...'); $return['fileinfos'] = array('module' => $moduleCodename, 'visualisation' => RESOURCE_DATA_LOCATION_EDITED); $return['linkConfig'] = array(); return $return; }
break; case 'edit': //Automne edition CSS file $cssfiles[] = PATH_ADMIN_CSS_FS . '/edit.css'; break; case 'debug': //Blackbird CSS file $cssfiles[] = PATH_MAIN_FS . '/blackbirdjs/blackbird.css'; break; case 'codemirror': //CodeMirror CSS file $cssfiles[] = PATH_MAIN_FS . '/codemirror/codemirror.css'; break; default: $replace = array('..' => '', '\\' => '', '/' => ''); $docrootPath = realpath($_SERVER["DOCUMENT_ROOT"] . $file); $realrootPath = realpath(PATH_REALROOT_FS . '/' . $file); $dirnamePath = realpath(dirname(__FILE__) . '/' . $file); if ($file == str_replace(array_keys($replace), $replace, $file) && file_exists($dirnamePath) && is_file($dirnamePath)) { $cssfiles[] = $dirnamePath; } elseif (in_array(pathinfo($file, PATHINFO_EXTENSION), array('css', 'less')) && substr($file, 0, 1) == '/' && file_exists($docrootPath) && is_file($docrootPath) && (strpos(pathinfo($docrootPath, PATHINFO_DIRNAME), realpath(PATH_CSS_FS)) === 0 || strpos(pathinfo($docrootPath, PATHINFO_DIRNAME), realpath(PATH_ADMIN_CSS_FS)) === 0)) { $cssfiles[] = $docrootPath; } elseif (in_array(pathinfo($file, PATHINFO_EXTENSION), array('css', 'less')) && substr($file, 0, 1) != '/' && file_exists($realrootPath) && is_file($realrootPath) && (strpos(pathinfo($realrootPath, PATHINFO_DIRNAME), realpath(PATH_CSS_FS)) === 0 || strpos(pathinfo($realrootPath, PATHINFO_DIRNAME), realpath(PATH_ADMIN_CSS_FS)) === 0)) { $cssfiles[] = $realrootPath; } break; } } } CMS_file::sendFiles($cssfiles, 'text/css');
/** * Extract files from the archive * * @return true on success */ function extract_files() { $pwd = getcwd(); chdir($this->options['basedir']); if ($fp = $this->open_archive()) { if ($this->options['inmemory'] == 1) { $this->files = array(); } while ($block = fread($fp, 512)) { $temp = unpack("a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100temp/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp", $block); $file = array('name' => $temp['prefix'] . $temp['name'], 'stat' => array(2 => $temp['mode'], 4 => octdec($temp['uid']), 5 => octdec($temp['gid']), 7 => octdec($temp['size']), 9 => octdec($temp['mtime'])), 'checksum' => octdec($temp['checksum']), 'type' => $temp['type'], 'magic' => $temp['magic']); if ($file['checksum'] == 0x0) { break; } else { /*if ($file['magic'] != "ustar") { $this->raiseError("This script does not support extracting this type of tar file."); break; }*/ $block = substr_replace($block, " ", 148, 8); } $checksum = 0; for ($i = 0; $i < 512; $i++) { $checksum += ord(io::substr($block, $i, 1)); } if ($file['checksum'] != $checksum) { $this->raiseError("Could not extract from {$this->options['name']}, it is corrupt."); } if ($this->options['inmemory'] == 1) { $file['data'] = @fread($fp, $file['stat'][7]); @fread($fp, 512 - $file['stat'][7] % 512 == 512 ? 0 : 512 - $file['stat'][7] % 512); unset($file['checksum'], $file['magic']); $this->files[] = $file; } else { if ($file['type'] == 5) { if (!is_dir($file['name'])) { /*if ($this->options['forceWriting']) { chmod($file['name'], 1777); }*/ if (!$this->options['dontUseFilePerms']) { @mkdir($file['name'], $file['stat'][2]); //pr($file['name'].' : '.$file['stat'][4]); //pr($file['name'].' : '.$file['stat'][5]); @chown($file['name'], $file['stat'][4]); @chgrp($file['name'], $file['stat'][5]); } else { @mkdir($file['name']); } } } else { if ($this->options['overwrite'] == 0 && file_exists($file['name'])) { $this->raiseError("{$file['name']} already exists."); } else { //check if destination dir exists $dirname = dirname($file['name']); if (!is_dir($dirname)) { CMS_file::makeDir($dirname); } if ($new = @fopen($file['name'], "wb")) { @fwrite($new, @fread($fp, $file['stat'][7])); @fread($fp, 512 - $file['stat'][7] % 512 == 512 ? 0 : 512 - $file['stat'][7] % 512); @fclose($new); //pr($file['name'].' : '.$file['stat'][2]); if (!$this->options['dontUseFilePerms']) { @chmod($file['name'], $file['stat'][2]); @chown($file['name'], $file['stat'][4]); @chgrp($file['name'], $file['stat'][5]); } /*if ($this->options['forceWriting']) { chmod($file['name'], 0777); }*/ } else { $this->raiseError("Could not open {$file['name']} for writing."); } } } } unset($file); } } else { $this->raiseError("Could not open file {$this->options['name']}"); } chdir($pwd); return true; }
/** * Export module datas * * @param string $format, the export format in : php (default), xml, patch * @return mixed : the exported datas */ function export($format = 'php') { $aExport = array(); if ($this->_hasExport) { //force default language loading to overwrite user language global $cms_language; $oModule = CMS_modulesCatalog::getByCodename($this->_module); if (!$oModule->hasError()) { $aModule = $oModule->asArray($this->_parameters, $files); //append files to exported module datas $aModule['files'] = array(); if ($files) { $aModule['files'] = $files; } //create export datas $aExport = array('version' => AUTOMNE_VERSION, 'language' => $cms_language->getCode(), 'description' => isset($this->_parameters['description']) ? $this->_parameters['description'] : '', 'modules' => array($aModule)); } $return = ''; switch ($format) { case 'php': $return = $aExport; break; case 'xml': $array2Xml = new CMS_array2Xml($aExport, "export"); $return = $array2Xml->getXMLString(); break; case 'patch': //create patch datas $archiveFile = PATH_TMP_FS . '/' . $this->_module . '-' . date('Ymd-His') . '.tgz'; $archive = new CMS_gzip_file(substr($archiveFile, strlen(PATH_REALROOT_FS) + 1)); $archive->set_options(array('basedir' => PATH_REALROOT_FS . '/')); if (isset($aExport['modules'])) { foreach ($aExport['modules'] as $moduleDatas) { if (isset($moduleDatas['files'])) { foreach ($moduleDatas['files'] as $file) { if (file_exists(PATH_REALROOT_FS . $file)) { $archive->add_files(array(substr($file, 1))); } } } } } $array2Xml = new CMS_array2Xml($aExport, "export"); $sOutput = $array2Xml->getXMLString(); $datas = new CMS_file(PATH_REALROOT_FS . '/export.xml'); $datas->setContent($sOutput); $datas->writeToPersistence(); $archive->add_files(array('export.xml')); //create archive if ($archive->create_archive()) { $return = $archiveFile; } else { $this->raiseError('Error during archive creation ...'); } //delete tmp file $datas->delete(); break; default: $this->raiseError('Unknown format : ' . $format); return false; break; } } return $return; }