コード例 #1
0
 /**
  * Move the data of a resource from one data location to another.
  * May be used by every module, provided it respects the naming rules described in the modules HOWTO
  *
  * @param 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;
 }
コード例 #2
0
ファイル: pagetemplate.php プロジェクト: davidmottet/automne
 /**
  * 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();
     }
 }
コード例 #3
0
ファイル: update.php プロジェクト: davidmottet/automne
                $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) {
    $content .= '<fieldset style="padding:3px;margin:3px;"><legend>/!\\ Warning : Remaining actions to be done manually to complete update :</legend>' . $actionsTodo . '</fieldset><br />';
コード例 #4
0
 /**
  * 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;
 }
コード例 #5
0
ファイル: page.php プロジェクト: davidmottet/automne
 /**
  * Regenerate the page file, either from scratch or from the linx file.
  * If linx file doesn't exists, the file is regenerated from scratch (obviously).
  *
  * @param boolean $fromScratch If false, regenerate from the linx file, otherwise regenerate linx file first.
  * @return boolean true on success, false on failure
  * @access public
  */
 function regenerate($fromScratch = false)
 {
     //regenerate don't work on pages that are not public or which not have website
     if ($this->getPublication() != RESOURCE_PUBLICATION_PUBLIC || !$this->_checkWebsite()) {
         return true;
     }
     //need pageTemplate for regeneration
     $this->_checkTemplate();
     //get linx file path
     $linxFile = new CMS_file($this->getLinxFilePath());
     //should we regenerate the linx file ?
     if ($fromScratch || !$linxFile->exists()) {
         if (!$this->_template) {
             $this->raiseError('Can\'t find page template for page ' . $this->getID());
             return false;
         }
         if (!$this->writeLinxFile()) {
             return false;
         }
         //reload linx file
         $linxFile = new CMS_file($this->getLinxFilePath());
     }
     //unregister all linxes
     CMS_linxesCatalog::deleteLinxes($this);
     //instanciate modules treatments for page linx tags
     $modulesTreatment = new CMS_modulesTags(MODULE_TREATMENT_LINXES_TAGS, PAGE_VISUALMODE_HTML_PUBLIC, $this);
     $modulesTreatment->setDefinition($linxFile->getContent());
     if ($content = $modulesTreatment->treatContent(true)) {
         $pageHTMLPath = $this->_getHTMLFilePath(PATH_RELATIVETO_FILESYSTEM) . "/" . $this->_getHTMLFilename();
         $pageFile = new CMS_file($pageHTMLPath, CMS_file::FILE_SYSTEM, CMS_file::TYPE_FILE);
         $pageFile->setContent($content);
         $pageFile->writeToPersistence();
         $this->_lastFileCreation->setNow();
         $this->writeToPersistence();
         //if the page is a website root, create the index page redirecting to this one
         if ($fromScratch && CMS_websitesCatalog::isWebsiteRoot($this->getID())) {
             CMS_websitesCatalog::writeRootRedirection();
         }
     } else {
         $this->raiseError('Malformed linx file');
         return false;
     }
     //write significant url page
     $pagePath = $this->_getFilePath(PATH_RELATIVETO_FILESYSTEM) . "/" . $this->_getFilename();
     $redirectionFile = new CMS_file($pagePath, CMS_file::FILE_SYSTEM, CMS_file::TYPE_FILE);
     $redirectionFile->setContent($this->redirectionCode($pageHTMLPath));
     $redirectionFile->writeToPersistence(true, true);
     //write website index
     if (CMS_websitesCatalog::isWebsiteRoot($this->getID())) {
         $ws = $this->getWebsite();
         if ($ws && !$ws->isMain()) {
             $wsPath = $ws->getPagesPath(PATH_RELATIVETO_FILESYSTEM) . '/index.php';
             $redirectionFile = new CMS_file($wsPath, CMS_file::FILE_SYSTEM, CMS_file::TYPE_FILE);
             $redirectionFile->setContent($this->redirectionCode($pageHTMLPath));
             $redirectionFile->writeToPersistence(true, true);
         }
     }
     //write print page if any
     if (USE_PRINT_PAGES && $this->_template->getPrintingClientSpaces()) {
         //reload linx file
         $printLinxFile = new CMS_file($this->getLinxFilePath() . '.print', CMS_file::FILE_SYSTEM, CMS_file::TYPE_FILE);
         if ($printLinxFile->exists()) {
             $modulesTreatment = new CMS_modulesTags(MODULE_TREATMENT_LINXES_TAGS, PAGE_VISUALMODE_PRINT, $this);
             $modulesTreatment->setDefinition($printLinxFile->getContent());
             if ($content = $modulesTreatment->treatContent(true)) {
                 $printHTMLPath = $this->_getHTMLFilePath(PATH_RELATIVETO_FILESYSTEM) . "/print-" . $this->_getHTMLFilename();
                 $printFile = new CMS_file($printHTMLPath);
                 $printFile->setContent($content);
                 $printFile->writeToPersistence();
             } else {
                 $this->raiseError('Malformed print linx file');
                 return false;
             }
             //write significant url print page
             $printPath = $this->_getFilePath(PATH_RELATIVETO_FILESYSTEM) . "/print-" . $this->_getFilename();
             $redirectionFile = new CMS_file($printPath);
             $redirectionFile->setContent($this->redirectionCode($printHTMLPath));
             $redirectionFile->writeToPersistence();
         } else {
             $this->raiseError('Malformed print linx file');
             return false;
         }
     }
     return true;
 }
コード例 #6
0
 /**
  * Move the data of a resource from one data location to another.
  * May be used by every module, provided it respects the naming rules described in the modules HOWTO
  *
  * @param CMS_module $module The module who  want its data moved
  * @param string $tablesPrefix The prefix of the tables containing the data
  * @param string $resourceIDFieldName The name of the field containing the resource ID
  * @param integer $resourceID The DB ID of the resource whose data we want to move
  * @param string $locationFrom The starting location, among the available RESOURCE_DATA_LOCATION
  * @param string $locationTo The ending location, among  the available RESOURCE_DATA_LOCATION
  * @param boolean $copyOnly If set to true, the deletion from the originating tables and dirs won't occur
  * @return boolean true on success, false on failure
  * @access public
  */
 static function moveResourceData(&$module, $tablesPrefix, $resourceIDFieldName, $resourceID, $locationFrom, $locationTo, $copyOnly = false)
 {
     if (!is_a($module, "CMS_module")) {
         CMS_grandFather::raiseError("Module is not a CMS_module");
         return false;
     }
     if (!SensitiveIO::isInSet($locationFrom, CMS_resource::getAllDataLocations()) || !SensitiveIO::isInSet($locationTo, CMS_resource::getAllDataLocations())) {
         CMS_grandFather::raiseError("Locations are not in the set");
         return false;
     }
     //get the tables : named PREFIXXXXX_public
     $sql = "show tables";
     $q = new CMS_query($sql);
     $tables_prefixes = array();
     while ($data = $q->getArray()) {
         if (preg_match("#" . $tablesPrefix . "(.*)_public#", $data[0])) {
             $tables_prefixes[] = io::substr($data[0], 0, strrpos($data[0], "_") + 1);
         }
     }
     foreach ($tables_prefixes as $table_prefix) {
         //delete all in the destination table just incase and insert
         if ($locationTo != RESOURCE_DATA_LOCATION_DEVNULL) {
             $sql = "\n\t\t\t\t\tdelete from\n\t\t\t\t\t\t" . $table_prefix . $locationTo . "\n\t\t\t\t\twhere\n\t\t\t\t\t\t" . $resourceIDFieldName . "='" . $resourceID . "'\n\t\t\t\t";
             $q = new CMS_query($sql);
             $sql = "\n\t\t\t\t\tinsert into\n\t\t\t\t\t\t" . $table_prefix . $locationTo . "\n\t\t\t\t\t\tselect\n\t\t\t\t\t\t\t*\n\t\t\t\t\t\tfrom\n\t\t\t\t\t\t\t" . $table_prefix . $locationFrom . "\n\t\t\t\t\t\twhere\n\t\t\t\t\t\t\t" . $resourceIDFieldName . "='" . $resourceID . "'\n\t\t\t\t";
             $q = new CMS_query($sql);
         }
         if (!$copyOnly) {
             //delete from the starting table
             $sql = "\n\t\t\t\t\tdelete from\n\t\t\t\t\t\t" . $table_prefix . $locationFrom . "\n\t\t\t\t\twhere\n\t\t\t\t\t\t" . $resourceIDFieldName . "='" . $resourceID . "'\n\t\t\t\t";
             $q = new CMS_query($sql);
         }
     }
     //second, move the files
     $locationFromDir = new CMS_file(PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationFrom, CMS_file::FILE_SYSTEM, CMS_file::TYPE_DIRECTORY);
     //cut here if the locationFromDir doesn't exists. That means the module doesn't have files
     if (!$locationFromDir->exists()) {
         return true;
     }
     if ($locationTo != RESOURCE_DATA_LOCATION_DEVNULL) {
         $locationToDir = new CMS_file(PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationTo, CMS_file::FILE_SYSTEM, CMS_file::TYPE_DIRECTORY);
         //cut here if the locationToDir doesn't exists.
         if (!$locationToDir->exists()) {
             CMS_grandFather::raiseError("LocationToDir does not exists : " . PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationTo);
             return false;
         }
         //delete all files of the locationToDir
         $files = glob(PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationTo . '/r' . $resourceID . '_*', GLOB_NOSORT);
         if (is_array($files)) {
             foreach ($files as $file) {
                 if (!CMS_file::deleteFile($file)) {
                     CMS_grandFather::raiseError("Can't delete file " . $file);
                     return false;
                 }
             }
         }
         //then copy or move them to the locationToDir
         $files = glob(PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationFrom . '/r' . $resourceID . '_*', GLOB_NOSORT);
         if (is_array($files)) {
             foreach ($files as $file) {
                 $to = str_replace('/' . $locationFrom . '/', '/' . $locationTo . '/', $file);
                 if ($copyOnly) {
                     if (!CMS_file::copyTo($file, $to)) {
                         CMS_grandFather::raiseError("Can't copy file " . $file . " to " . $to);
                         return false;
                     }
                 } else {
                     if (!CMS_file::moveTo($file, $to)) {
                         CMS_grandFather::raiseError("Can't move file " . $file . " to " . $to);
                         return false;
                     }
                 }
                 //then chmod new file
                 CMS_file::chmodFile(FILES_CHMOD, $to);
             }
         }
     }
     //cleans the initial dir if not a copy
     if (!$copyOnly) {
         //then get all files of the locationFromDir
         $files = glob(PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationFrom . '/r' . $resourceID . '_*', GLOB_NOSORT);
         if (is_array($files)) {
             foreach ($files as $file) {
                 if (!CMS_file::deleteFile($file)) {
                     CMS_grandFather::raiseError("Can't delete file " . $file);
                     return false;
                 }
             }
         }
     }
     return true;
 }
コード例 #7
0
ファイル: row.php プロジェクト: davidmottet/automne
 /**
  * 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;
     }
 }
コード例 #8
0
ファイル: server-update.php プロジェクト: davidmottet/automne
 $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
             $send = '
コード例 #9
0
ファイル: object_email.php プロジェクト: davidmottet/automne
 /**
  * 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;
     }
 }
コード例 #10
0
ファイル: patch.php プロジェクト: davidmottet/automne
 /**
  * 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;
     }
 }
コード例 #11
0
 /**
  * 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;
     }
 }
コード例 #12
0
ファイル: cache.php プロジェクト: davidmottet/automne
 /**
  * Clear type cache using metas
  *
  * @param string $type : the cache type to clear
  * @param array $metas : the cache metas to clear
  * @param contant $mode : the zend cache constant to clean matching cache
  *		Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG (default)
  *  	Zend_Cache::CLEANING_MODE_MATCHING_TAG
  * 	Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG
  * @return boolean
  * @access public
  * @static
  */
 function clearTypeCacheByMetas($type, $metas, $mode = Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG)
 {
     $type = io::sanitizeAsciiString($type);
     //Convert metas into tags
     $tags = CMS_cache::_createTags($metas);
     //CMS_grandFather::log('Clear cache '.$type.' for metas '.print_r($tags, true).' ('.io::getCallInfos().')');
     $return = true;
     //check cache dir
     $cachedir = new CMS_file(PATH_CACHE_FS . '/' . $type, CMS_file::FILE_SYSTEM, CMS_file::TYPE_DIRECTORY);
     if ($cachedir->exists()) {
         //Frontend cache options
         $frontendOptions = array('lifetime' => null, 'caching' => true, 'automatic_cleaning_factor' => 10);
         //Backend cache options
         $backendOptions = array('cache_dir' => PATH_CACHE_FS . '/' . $type, 'cache_file_umask' => octdec(FILES_CHMOD), 'hashed_directory_umask' => octdec(DIRS_CHMOD), 'hashed_directory_level' => 1);
         // getting a Zend_Cache_Core object
         try {
             $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
         } catch (Zend_Cache_Exception $e) {
             CMS_grandFather::raiseError($e->getMessage());
         }
         if ($cache) {
             try {
                 $return = $cache->clean($mode, $tags);
             } catch (Zend_Cache_Exception $e) {
                 CMS_grandFather::raiseError($e->getMessage());
                 $return = false;
             }
         } else {
             $return = false;
         }
     }
     return $return;
 }
コード例 #13
0
ファイル: import.php プロジェクト: davidmottet/automne
             $cms_message .= $cms_language->getMessage(MESSAGE_PAGE_ERROR_FILE_DIR, array(PATH_TMP_FS)) . "\n";
             break;
         }
     } else {
         $cms_message .= $cms_language->getMessage(MESSAGE_PAGE_ERROR_FILE_EXTRACT, array($filename)) . "\n";
         break;
     }
     if (!$archive->hasError()) {
         $cms_message .= $cms_language->getMessage(MESSAGE_PAGE_MODULE_EXTRACT_DONE) . "\n";
     } else {
         $cms_message .= $cms_language->getMessage(MESSAGE_PAGE_MODULE_EXTRACT_ERROR) . "\n";
         break;
     }
     unset($archive);
     $file = new CMS_file(PATH_TMP_FS . '/export.xml');
     if (!$file->exists()) {
         $cms_message .= $cms_language->getMessage(MESSAGE_PAGE_MODULE_NO_EXPORT) . "\n";
         break;
     }
     $importDatas = $file->getContent();
     $format = 'xml';
 } elseif (io::post('import')) {
     $importDatas = io::post('import');
     if ($format == 'php') {
         //try to eval PHP Array
         try {
             $importDatas = eval('return ' . $importDatas . ';');
         } catch (Exception $e) {
         }
     }
 } else {
コード例 #14
0
ファイル: server-check.php プロジェクト: davidmottet/automne
                     case 0:
                         $content .= '<li class="atm-pic-ok">' . $line['text'] . '</li>';
                         break;
                     case 1:
                         $content .= '<li class="atm-pic-cancel">' . $line['text'] . '</li>';
                         break;
                 }
                 break;
         }
     }
     $content .= '</ul>';
     break;
 case 'browser-cache-reset':
     //update SUBVERSION file
     $file = new CMS_file(PATH_MAIN_FS . "/SUBVERSION");
     if ($file->exists()) {
         $date = (int) $file->getContent();
         $date++;
         $file->setContent((string) $date);
         if ($file->writeToPersistence()) {
             $cms_message = $cms_language->getMessage(MESSAGE_OPERATION_DONE);
         } else {
             $cms_message = $cms_language->getMessage(MESSAGE_UPDATE_ERROR);
         }
     } else {
         if (@file_put_contents(PATH_MAIN_FS . "/SUBVERSION", time()) !== false) {
             CMS_file::chmodFile(FILES_CHMOD, PATH_MAIN_FS . "/SUBVERSION");
             $cms_message = $cms_language->getMessage(MESSAGE_OPERATION_DONE);
         } else {
             $cms_message = $cms_language->getMessage(MESSAGE_CREATION_ERROR);
         }
コード例 #15
0
ファイル: install.php プロジェクト: davidmottet/automne
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;
}
コード例 #16
0
ファイル: array2csv.php プロジェクト: davidmottet/automne
 /**
  * Get current CSV file
  * 
  * @return CMS_file : the CSV file
  */
 function getFile()
 {
     @fclose($this->_file);
     $file = new CMS_file($this->_filepath . '/' . $this->_filename);
     if ($file->exists()) {
         return $file;
     } else {
         $this->raiseError('File ' . ($this->_filepath . '/' . $this->_filename) . ' does not exists');
         return false;
     }
 }