/** * Parse the definition file to instanciate the _blocks attribute * * @param CMS_modulesTags $modulesTreatment tags object treatment * @return string false on success, the parsing error string if any * @access public */ protected function _parseDefinitionFile(&$modulesTreatment) { if ($this->_definitionFile) { $filename = PATH_TEMPLATES_ROWS_FS . "/" . $this->_definitionFile; $tplrow = new CMS_file(PATH_TEMPLATES_ROWS_FS . "/" . $this->_definitionFile); if (!$tplrow->exists()) { $this->raiseError('Can not found row template file ' . PATH_TEMPLATES_ROWS_FS . "/" . $this->_definitionFile); return true; } $modulesTreatment->setDefinition($tplrow->readContent()); $this->_blocks = $modulesTreatment->getTags(array('block')); if (is_array($this->_blocks)) { return false; } else { $this->raiseError("Malformed definition file : " . $this->_definitionFile . "<br />" . $modulesTreatment->getParsingError()); return $modulesTreatment->getParsingError(); } } else { $this->raiseError('No row definition file found for row : ' . $this->getLabel()); return 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(); } }
/** * 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; } }
$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 $content = '<textarea id="file-content-' . $fileId . '" style="display:none;">' . htmlspecialchars($fileDefinition) . '</textarea>';
//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 $send = ' <div id="correctUpdateErrors"></div>
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 { $cms_message = $cms_language->getMessage(MESSAGE_ERROR_WRITE_TEMPLATE); } }
/** * 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; } }
/** * Get all available languages codes from ISO 639-1 standard * Static function. * * @return array(code => label) * @access public */ function getAllLanguagesCodes() { if (!file_exists(PATH_PACKAGES_FS . '/files/iso639-1.txt')) { return array(); } $codeFile = new CMS_file(PATH_PACKAGES_FS . '/files/iso639-1.txt'); $languagesCodes = $codeFile->readContent('array'); $return = array(); foreach ($languagesCodes as $languagesCode) { if (substr($languagesCode, 0, 1) != '#') { list($code, $label) = explode("\t", $languagesCode); if (io::strtolower(APPLICATION_DEFAULT_ENCODING) != 'utf-8') { $label = utf8_decode($label); } $return[$code] = ucfirst($label); } } return $return; }
//load interface instance $view = CMS_view::getInstance(); //set default display mode for this page $view->setDisplayMode(CMS_view::SHOW_RAW); //This file is an admin file. Interface must be secure $view->setSecure(); //CHECKS user has templates clearance if (!$cms_user->hasAdminClearance(CLEARANCE_ADMINISTRATION_EDIT_TEMPLATES)) { //templates CMS_grandFather::raiseError('User has no rights template editions'); $view->setActionMessage($cms_language->getMessage(MESSAGE_ERROR_NO_RIGHTS_FOR_TEMPLATES)); $view->show(); } //MAIN TAB $templateFile = new CMS_file(PATH_TEMPLATES_FS . "/print.xml"); $templateDefinition = $templateFile->readContent(); //DEFINITION TAB $content = '<textarea id="tpl-definition-' . $templateId . '" style="display:none;">' . htmlspecialchars($templateDefinition) . '</textarea>'; $view->setContent($content); $jscontent = <<<END \tvar templateWindow = Ext.getCmp('{$winId}'); \ttemplateWindow.templateId = '{$templateId}'; \t//set window title \ttemplateWindow.setTitle('{$cms_language->getJsMessage(MESSAGE_PAGE_TITLE)}'); \t//set help button on top of page \ttemplateWindow.tools['help'].show(); \t//add a tooltip on button \tvar propertiesTip = new Ext.ToolTip({ \t\ttarget:\t\t templateWindow.tools['help'], \t\ttitle:\t\t\t '{$cms_language->getJsMessage(MESSAGE_TOOLBAR_HELP)}', \t\thtml:\t\t\t '{$cms_language->getJsMessage(MESSAGE_TOOLBAR_HELP_DESC)}',
// ************************************************************************* // ** REDIRECTION HANDLER. KEEP ALL THIS PHP CODE IN 404 ERROR DOCUMENT ! ** // ** YOU CAN DEFINE YOUR OWN ERROR PAGE WITH THE FILE /404.html ** // ************************************************************************* //disactive HTML compression define("ENABLE_HTML_COMPRESSION", false); require_once dirname(__FILE__) . '/cms_rc_frontend.php'; //parse requested URL to try to find a matching page $redirectTo = ''; if ($_SERVER['REQUEST_URI'] && $_SERVER['REQUEST_URI'] != $_SERVER['SCRIPT_NAME']) { $pathinfo = pathinfo($_SERVER['REQUEST_URI']); $basename = isset($pathinfo['filename']) ? $pathinfo['filename'] : $pathinfo['basename']; //first try to get redirection rules from CSV file if exists if (file_exists(PATH_MAIN_FS . '/redirect/redirectRules.csv')) { $csvFile = new CMS_file(PATH_MAIN_FS . '/redirect/redirectRules.csv'); $csvDatas = $csvFile->readContent('csv', 'trim', array('delimiter' => ';', 'enclosure' => '"', 'strict' => true)); $rules = array(); foreach ($csvDatas as $line => $csvData) { if (isset($csvData[0]) && $csvData[0] && isset($csvData[1]) && $csvData[1]) { $rules[$csvData[0]] = $csvData[1]; } } if (isset($rules[$_SERVER['REQUEST_URI']]) && io::isPositiveInteger($rules[$_SERVER['REQUEST_URI']])) { $page = CMS_tree::getPageById($rules[$_SERVER['REQUEST_URI']]); } elseif (isset($rules[parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)]) && io::isPositiveInteger($rules[parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)])) { $page = CMS_tree::getPageById($rules[parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)]); } } if (!isset($page)) { //get page from requested url $page = CMS_tree::analyseURL($_SERVER['REQUEST_URI'], false);
function patch($patchFile, &$error) { $archive = new CMS_gzip_file($patchFile); if (!$archive->hasError()) { $archive->set_options(array('basedir' => PATH_TMP_FS . "/", 'overwrite' => 1, 'level' => 1, 'dontUseFilePerms' => 1, 'forceWriting' => 1)); if (is_dir(PATH_TMP_FS)) { if (!method_exists($archive, 'extract_files') || !$archive->extract_files()) { $error = 'Error : Extraction error...'; return false; } } else { $error = 'Error : Extraction directory does not exist'; return false; } } else { $error = 'Error : Unable to extract archive wanted ' . $filename . '. It is not a valid format...'; return false; } if (!$archive->hasError()) { unset($archive); } else { $error = 'Extraction error...'; return false; } //Check files content $automnePatch = new CMS_patch(); //read patch param file and check versions $patchFile = new CMS_file(PATH_TMP_FS . "/patch"); if ($patchFile->exists()) { $patch = $patchFile->readContent("array"); } else { $error = 'Error : File ' . PATH_TMP_FS . '/patch does not exists ...'; return false; } if (!$automnePatch->checkPatch($patch)) { $error = 'Error : Patch does not match current version ...'; return false; } //read install param file and do maximum check on it before starting the installation process $installFile = new CMS_file(PATH_TMP_FS . "/install"); if ($installFile->exists()) { $install = $installFile->readContent("array"); } else { $error = 'Error : File ' . PATH_TMP_FS . '/install does not exists ...'; return false; } $installError = $automnePatch->checkInstall($install, $errorsInfos); if ($installError) { $error = 'Error : Invalid install file :'; $error .= $installError; return false; } //start Installation process $automnePatch->doInstall($install); $installError = false; $return = $automnePatch->getReturn(); foreach ($return as $line) { if ($line['type'] == 'report') { $error .= $line['text']; } } if ($installError) { $error = 'Error during installation process : ' . $error; return false; } //remove temporary files !CMS_file::deltree(PATH_TMP_FS); return true; }