/**
  * 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;
 }
Esempio n. 2
0
 /**
  * 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;
 }
Esempio n. 3
0
 //create new directory
 if (!is_dir(PATH_MAIN_FS . "/sql")) {
     if (!CMS_file::makeDir(PATH_MAIN_FS . "/sql")) {
         $actionsTodo .= '- Create directory ' . PATH_MAIN_WR . '/sql <br/>';
     } else {
         $actionsDone .= '- Created directory ' . PATH_MAIN_WR . '/sql <br/>';
     }
 }
 //copy all files from old directory to new one if they do not already exists
 $errorCopy = false;
 try {
     foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(PATH_REALROOT_FS . '/sql'), RecursiveIteratorIterator::SELF_FIRST) as $file) {
         if ($file->isFile() && $file->getFilename() != ".htaccess") {
             $to = str_replace(PATH_REALROOT_FS . '/sql', '', $file->getPathname());
             if (!file_exists(PATH_MAIN_FS . '/sql' . $to)) {
                 if (!CMS_file::copyTo($file->getPathname(), PATH_MAIN_FS . '/sql' . $to)) {
                     $errorCopy = true;
                     $actionsTodo .= '- Copy file from ' . $file->getPathname() . ' to ' . PATH_MAIN_FS . '/sql' . $to . ' <br/>';
                 } else {
                     //$actionsDone .= '- File copied from '.$file->getPathname().' to '.PATH_MAIN_FS.'/sql'.$to.' <br/>';
                 }
             }
         }
     }
 } catch (Exception $e) {
 }
 //remove old dir
 if (!$errorCopy) {
     if (!CMS_file::deltree(PATH_REALROOT_FS . '/sql', true)) {
         $actionsTodo .= '- Delete directory ' . PATH_REALROOT_WR . '/sql <br/>';
     } else {
Esempio n. 4
0
 /**
  * Move the data of a resource from one data location to another.
  * May be used by every module, provided it respects the naming rules described in the modules HOWTO
  *
  * @param CMS_module $module The module who  want its data moved
  * @param string $tablesPrefix The prefix of the tables containing the data
  * @param string $resourceIDFieldName The name of the field containing the resource ID
  * @param integer $resourceID The DB ID of the resource whose data we want to move
  * @param string $locationFrom The starting location, among the available RESOURCE_DATA_LOCATION
  * @param string $locationTo The ending location, among  the available RESOURCE_DATA_LOCATION
  * @param boolean $copyOnly If set to true, the deletion from the originating tables and dirs won't occur
  * @return boolean true on success, false on failure
  * @access public
  */
 static function moveResourceData(&$module, $tablesPrefix, $resourceIDFieldName, $resourceID, $locationFrom, $locationTo, $copyOnly = false)
 {
     if (!is_a($module, "CMS_module")) {
         CMS_grandFather::raiseError("Module is not a CMS_module");
         return false;
     }
     if (!SensitiveIO::isInSet($locationFrom, CMS_resource::getAllDataLocations()) || !SensitiveIO::isInSet($locationTo, CMS_resource::getAllDataLocations())) {
         CMS_grandFather::raiseError("Locations are not in the set");
         return false;
     }
     //get the tables : named PREFIXXXXX_public
     $sql = "show tables";
     $q = new CMS_query($sql);
     $tables_prefixes = array();
     while ($data = $q->getArray()) {
         if (preg_match("#" . $tablesPrefix . "(.*)_public#", $data[0])) {
             $tables_prefixes[] = io::substr($data[0], 0, strrpos($data[0], "_") + 1);
         }
     }
     foreach ($tables_prefixes as $table_prefix) {
         //delete all in the destination table just incase and insert
         if ($locationTo != RESOURCE_DATA_LOCATION_DEVNULL) {
             $sql = "\n\t\t\t\t\tdelete from\n\t\t\t\t\t\t" . $table_prefix . $locationTo . "\n\t\t\t\t\twhere\n\t\t\t\t\t\t" . $resourceIDFieldName . "='" . $resourceID . "'\n\t\t\t\t";
             $q = new CMS_query($sql);
             $sql = "\n\t\t\t\t\tinsert into\n\t\t\t\t\t\t" . $table_prefix . $locationTo . "\n\t\t\t\t\t\tselect\n\t\t\t\t\t\t\t*\n\t\t\t\t\t\tfrom\n\t\t\t\t\t\t\t" . $table_prefix . $locationFrom . "\n\t\t\t\t\t\twhere\n\t\t\t\t\t\t\t" . $resourceIDFieldName . "='" . $resourceID . "'\n\t\t\t\t";
             $q = new CMS_query($sql);
         }
         if (!$copyOnly) {
             //delete from the starting table
             $sql = "\n\t\t\t\t\tdelete from\n\t\t\t\t\t\t" . $table_prefix . $locationFrom . "\n\t\t\t\t\twhere\n\t\t\t\t\t\t" . $resourceIDFieldName . "='" . $resourceID . "'\n\t\t\t\t";
             $q = new CMS_query($sql);
         }
     }
     //second, move the files
     $locationFromDir = new CMS_file(PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationFrom, CMS_file::FILE_SYSTEM, CMS_file::TYPE_DIRECTORY);
     //cut here if the locationFromDir doesn't exists. That means the module doesn't have files
     if (!$locationFromDir->exists()) {
         return true;
     }
     if ($locationTo != RESOURCE_DATA_LOCATION_DEVNULL) {
         $locationToDir = new CMS_file(PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationTo, CMS_file::FILE_SYSTEM, CMS_file::TYPE_DIRECTORY);
         //cut here if the locationToDir doesn't exists.
         if (!$locationToDir->exists()) {
             CMS_grandFather::raiseError("LocationToDir does not exists : " . PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationTo);
             return false;
         }
         //delete all files of the locationToDir
         $files = glob(PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationTo . '/r' . $resourceID . '_*', GLOB_NOSORT);
         if (is_array($files)) {
             foreach ($files as $file) {
                 if (!CMS_file::deleteFile($file)) {
                     CMS_grandFather::raiseError("Can't delete file " . $file);
                     return false;
                 }
             }
         }
         //then copy or move them to the locationToDir
         $files = glob(PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationFrom . '/r' . $resourceID . '_*', GLOB_NOSORT);
         if (is_array($files)) {
             foreach ($files as $file) {
                 $to = str_replace('/' . $locationFrom . '/', '/' . $locationTo . '/', $file);
                 if ($copyOnly) {
                     if (!CMS_file::copyTo($file, $to)) {
                         CMS_grandFather::raiseError("Can't copy file " . $file . " to " . $to);
                         return false;
                     }
                 } else {
                     if (!CMS_file::moveTo($file, $to)) {
                         CMS_grandFather::raiseError("Can't move file " . $file . " to " . $to);
                         return false;
                     }
                 }
                 //then chmod new file
                 CMS_file::chmodFile(FILES_CHMOD, $to);
             }
         }
     }
     //cleans the initial dir if not a copy
     if (!$copyOnly) {
         //then get all files of the locationFromDir
         $files = glob(PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationFrom . '/r' . $resourceID . '_*', GLOB_NOSORT);
         if (is_array($files)) {
             foreach ($files as $file) {
                 if (!CMS_file::deleteFile($file)) {
                     CMS_grandFather::raiseError("Can't delete file " . $file);
                     return false;
                 }
             }
         }
     }
     return true;
 }
Esempio n. 5
0
 /**
  * Copy a file located in the PATH_HTACCESS_FS directory to the edited, public, archived and edition directory of the module
  *
  * @param  string $original    name of the file to copy
  * @param  string $destination name of the file when copied
  */
 private function copyFilesToModuleDirectory($original, $destination)
 {
     $moduleDirectories = array(RESOURCE_DATA_LOCATION_EDITED, RESOURCE_DATA_LOCATION_PUBLIC, RESOURCE_DATA_LOCATION_ARCHIVED, RESOURCE_DATA_LOCATION_EDITION);
     foreach ($moduleDirectories as $directory) {
         if (is_dir(PATH_MODULES_FILES_FS . '/' . $this->_codename . '/' . $directory)) {
             CMS_file::copyTo(PATH_HTACCESS_FS . '/' . $original, PATH_MODULES_FILES_FS . '/' . $this->_codename . '/' . $directory . '/' . $destination);
             CMS_file::chmodFile(FILES_CHMOD, PATH_MODULES_FILES_FS . '/' . $this->_codename . '/' . $directory . '/' . $destination);
         }
     }
 }
Esempio n. 6
0
 /**
  * set object Values
  *
  * @param array $values : the POST result values
  * @param string prefixname : the prefix used for post names
  * @param boolean newFormat : new automne v4 format (default false for compatibility)
  * @param integer $objectID : the current object id. Must be set, but default is blank for compatibility with other objects
  * @return boolean true on success, false on failure
  * @access public
  */
 function setValues($values, $prefixName, $newFormat = false, $objectID = '')
 {
     if (!sensitiveIO::isPositiveInteger($objectID)) {
         $this->raiseError('ObjectID must be a positive integer : ' . $objectID);
         return false;
     }
     //get field parameters
     $params = $this->getParamsValues();
     //get module codename
     $moduleCodename = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID());
     if ($newFormat) {
         //delete old images ?
         //thumbnail
         if ($this->_subfieldValues[0]->getValue() && (!$values[$prefixName . $this->_field->getID() . '_0'] || pathinfo($values[$prefixName . $this->_field->getID() . '_0'], PATHINFO_BASENAME) != $this->_subfieldValues[0]->getValue())) {
             @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[0]->getValue());
             $this->_subfieldValues[0]->setValue('');
         }
         //image zoom
         if ($this->_subfieldValues[2]->getValue() && (!isset($values[$prefixName . $this->_field->getID() . '_2']) || !$values[$prefixName . $this->_field->getID() . '_2'] || pathinfo($values[$prefixName . $this->_field->getID() . '_2'], PATHINFO_BASENAME) != $this->_subfieldValues[2]->getValue())) {
             @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[2]->getValue());
             $this->_subfieldValues[2]->setValue('');
         }
         //set label from label field
         if (!$this->_subfieldValues[1]->setValue(io::htmlspecialchars($values[$prefixName . $this->_field->getID() . '_1']))) {
             return false;
         }
         //image zoom (if needed)
         if ((!isset($values[$prefixName . $this->_field->getID() . '_makeZoom']) || $values[$prefixName . $this->_field->getID() . '_makeZoom'] != 1) && isset($values[$prefixName . $this->_field->getID() . '_2']) && $values[$prefixName . $this->_field->getID() . '_2'] && io::strpos($values[$prefixName . $this->_field->getID() . '_2'], PATH_UPLOAD_WR . '/') !== false) {
             $filename = $values[$prefixName . $this->_field->getID() . '_2'];
             //check for image type before doing anything
             if (!in_array(io::strtolower(pathinfo($filename, PATHINFO_EXTENSION)), $this->_allowedExtensions)) {
                 return false;
             }
             //destroy old image if any
             if ($this->_subfieldValues[2]->getValue()) {
                 @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[2]->getValue());
                 $this->_subfieldValues[2]->setValue('');
             }
             //move and rename uploaded file
             $filename = str_replace(PATH_UPLOAD_WR . '/', PATH_UPLOAD_FS . '/', $filename);
             $basename = pathinfo($filename, PATHINFO_BASENAME);
             //set thumbnail
             $path = PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED;
             $zoomBasename = "r" . $objectID . "_" . $this->_field->getID() . "_" . io::strtolower(SensitiveIO::sanitizeAsciiString($basename));
             if (io::strlen($zoomBasename) > 255) {
                 $zoomBasename = sensitiveIO::ellipsis($zoomBasename, 255, '-', true);
             }
             $zoomFilename = $path . '/' . $zoomBasename;
             CMS_file::moveTo($filename, $zoomFilename);
             CMS_file::chmodFile(FILES_CHMOD, $zoomFilename);
             //set it
             if (!$this->_subfieldValues[2]->setValue($zoomBasename)) {
                 return false;
             }
         }
         //thumbnail
         if ($values[$prefixName . $this->_field->getID() . '_0'] && io::strpos($values[$prefixName . $this->_field->getID() . '_0'], PATH_UPLOAD_WR . '/') !== false) {
             $filename = $values[$prefixName . $this->_field->getID() . '_0'];
             //check for image type before doing anything
             if (!in_array(io::strtolower(pathinfo($filename, PATHINFO_EXTENSION)), $this->_allowedExtensions)) {
                 return false;
             }
             //destroy old image if any
             if ($this->_subfieldValues[0]->getValue()) {
                 @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[0]->getValue());
                 $this->_subfieldValues[0]->setValue('');
             }
             //move and rename uploaded file
             $filename = str_replace(PATH_UPLOAD_WR . '/', PATH_UPLOAD_FS . '/', $filename);
             $basename = pathinfo($filename, PATHINFO_BASENAME);
             //set thumbnail
             $path = PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED;
             $newBasename = "r" . $objectID . "_" . $this->_field->getID() . "_" . io::strtolower(SensitiveIO::sanitizeAsciiString($basename));
             //rename image
             $path_parts = pathinfo($newBasename);
             $extension = io::strtolower($path_parts['extension']);
             $newBasename = io::substr($path_parts['basename'], 0, -(io::strlen($extension) + 1)) . '_thumbnail.' . $extension;
             if (io::strlen($newBasename) > 255) {
                 $newBasename = sensitiveIO::ellipsis($newBasename, 255, '-', true);
             }
             $newFilename = $path . '/' . $newBasename;
             //move file from upload dir to new dir
             CMS_file::moveTo($filename, $newFilename);
             CMS_file::chmodFile(FILES_CHMOD, $newFilename);
             //if we use original image as image zoom, set it
             if (isset($values[$prefixName . $this->_field->getID() . '_makeZoom']) && $values[$prefixName . $this->_field->getID() . '_makeZoom'] == 1) {
                 $zoomFilename = str_replace('_thumbnail.' . $extension, '.' . $extension, $newFilename);
                 //copy image as zoom
                 CMS_file::copyTo($newFilename, $zoomFilename);
                 $zoomBasename = pathinfo($zoomFilename, PATHINFO_BASENAME);
                 //set image zoom
                 if (!$this->_subfieldValues[2]->setValue($zoomBasename)) {
                     return false;
                 }
             }
             //resize thumbnail if needed
             if ($params['maxWidth'] > 0 || $params['maxHeight'] > 0) {
                 $oImage = new CMS_image($newFilename);
                 //get current file size
                 $sizeX = $oImage->getWidth();
                 $sizeY = $oImage->getHeight();
                 //check thumbnail size
                 if ($params['maxWidth'] && $sizeX > $params['maxWidth'] || $params['maxHeight'] && $sizeY > $params['maxHeight']) {
                     $newSizeX = $sizeX;
                     $newSizeY = $sizeY;
                     // Check width
                     if ($params['maxWidth'] && $newSizeX > $params['maxWidth']) {
                         $newSizeY = round($params['maxWidth'] * $newSizeY / $newSizeX);
                         $newSizeX = $params['maxWidth'];
                     }
                     if ($params['maxHeight'] && $newSizeY > $params['maxHeight']) {
                         $newSizeX = round($params['maxHeight'] * $newSizeX / $newSizeY);
                         $newSizeY = $params['maxHeight'];
                     }
                     if (!$oImage->resize($newSizeX, $newSizeY, $newFilename)) {
                         return false;
                     }
                 }
             }
             //set thumbnail
             if (!$this->_subfieldValues[0]->setValue($newBasename)) {
                 return false;
             }
         }
         // If label not set yet, set it
         /*if(!$this->_subfieldValues[1]->getValue()){
         			if($this->_subfieldValues[0]->getValue()){
         				$this->_subfieldValues[1]->setValue($this->_subfieldValues[0]->getValue());
         			}
         		}*/
         //if we had an imagezoom, check his size
         if ($this->_subfieldValues[2]->getValue() && ($params['maxZoomWidth'] > 0 || $params['maxZoomHeight'] > 0)) {
             //resize zoom if needed
             $path = PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED;
             $basename = $this->_subfieldValues[2]->getValue();
             $filename = $path . '/' . $basename;
             $extension = io::strtolower(pathinfo($basename, PATHINFO_EXTENSION));
             $oImage = new CMS_image($filename);
             //get current file size
             $sizeX = $oImage->getWidth();
             $sizeY = $oImage->getHeight();
             //check zoom size
             if ($params['maxZoomWidth'] && $sizeX > $params['maxZoomWidth'] || $params['maxZoomHeight'] && $sizeY > $params['maxZoomHeight']) {
                 $newSizeX = $sizeX;
                 $newSizeY = $sizeY;
                 // Check width
                 if ($params['maxZoomWidth'] && $newSizeX > $params['maxZoomWidth']) {
                     $newSizeY = round($params['maxZoomWidth'] * $newSizeY / $newSizeX);
                     $newSizeX = $params['maxZoomWidth'];
                 }
                 if ($params['maxZoomHeight'] && $newSizeY > $params['maxZoomHeight']) {
                     $newSizeX = round($params['maxZoomHeight'] * $newSizeX / $newSizeY);
                     $newSizeY = $params['maxZoomHeight'];
                 }
                 if (!$oImage->resize($newSizeX, $newSizeY, $filename)) {
                     return false;
                 }
             }
         }
         //update files infos if needed
         if ($this->_subfieldValues[0]->getValue() && file_exists(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[0]->getValue())) {
             $file = new CMS_file(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[0]->getValue());
             $imageDatas = array('filename' => $file->getName(false), 'filepath' => $file->getFilePath(CMS_file::WEBROOT), 'filesize' => $file->getFileSize(), 'fileicon' => $file->getFileIcon(CMS_file::WEBROOT), 'extension' => $file->getExtension());
         } else {
             $imageDatas = array('filename' => '', 'filepath' => '', 'filesize' => '', 'fileicon' => '', 'extension' => '');
         }
         $imageDatas['module'] = $moduleCodename;
         $imageDatas['visualisation'] = RESOURCE_DATA_LOCATION_EDITED;
         if ($params['useDistinctZoom'] || $this->_subfieldValues[2]->getValue()) {
             //update files infos if needed
             if ($this->_subfieldValues[2]->getValue() && file_exists(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[2]->getValue())) {
                 $file = new CMS_file(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[2]->getValue());
                 $zoomDatas = array('filename' => $file->getName(false), 'filepath' => $file->getFilePath(CMS_file::WEBROOT), 'filesize' => $file->getFileSize(), 'fileicon' => $file->getFileIcon(CMS_file::WEBROOT), 'extension' => $file->getExtension());
             } else {
                 $zoomDatas = array('filename' => '', 'filepath' => '', 'filesize' => '', 'fileicon' => '', 'extension' => '');
             }
             $zoomDatas['module'] = $moduleCodename;
             $zoomDatas['visualisation'] = RESOURCE_DATA_LOCATION_EDITED;
         } else {
             $zoomDatas = '';
         }
         $content = array('datas' => array('polymodFieldsValue[' . $prefixName . $this->_field->getID() . '_0]' => $imageDatas, 'polymodFieldsValue[' . $prefixName . $this->_field->getID() . '_2]' => $zoomDatas, 'polymodFieldsValue[' . $prefixName . $this->_field->getID() . '_1]' => sensitiveIO::decodeEntities($this->_subfieldValues[1]->getValue())));
         $view = CMS_view::getInstance();
         $view->addContent($content);
         return true;
     } else {
         //Old format
         //delete old images ?
         if (isset($values[$prefixName . $this->_field->getID() . '_delete']) && $values[$prefixName . $this->_field->getID() . '_delete'] == 1) {
             if ($this->_subfieldValues[0]->getValue()) {
                 @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[0]->getValue());
                 $this->_subfieldValues[0]->setValue('');
             } elseif (isset($values[$prefixName . $this->_field->getID() . '_0_hidden']) && $values[$prefixName . $this->_field->getID() . '_0_hidden']) {
                 @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $values[$prefixName . $this->_field->getID() . '_0_hidden']);
                 $this->_subfieldValues[0]->setValue('');
             }
             if ($this->_subfieldValues[2]->getValue()) {
                 @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[2]->getValue());
                 $this->_subfieldValues[2]->setValue('');
             } elseif (isset($values[$prefixName . $this->_field->getID() . '_2_hidden']) && $values[$prefixName . $this->_field->getID() . '_2_hidden']) {
                 @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $values[$prefixName . $this->_field->getID() . '_2_hidden']);
                 $this->_subfieldValues[2]->setValue('');
             }
         }
         //set label from label field
         if (!$this->_subfieldValues[1]->setValue(io::htmlspecialchars(@$values[$prefixName . $this->_field->getID() . '_1']))) {
             return false;
         }
         //thumbnail
         if (isset($_FILES[$prefixName . $this->_field->getID() . '_0']) && $_FILES[$prefixName . $this->_field->getID() . '_0']['name'] && !$_FILES[$prefixName . $this->_field->getID() . '_0']['error']) {
             //check for image type before doing anything
             if (!in_array(io::strtolower(pathinfo($_FILES[$prefixName . $this->_field->getID() . '_0']["name"], PATHINFO_EXTENSION)), $this->_allowedExtensions)) {
                 return false;
             }
             //set label as image name if none set
             /*if (!$values[$prefixName.$this->_field->getID().'_1']) {
             			if (!$this->_subfieldValues[1]->setValue(io::htmlspecialchars($_FILES[$prefixName.$this->_field->getID().'_0']["name"]))) {
             				return false;
             			}
             		}*/
             //destroy all old images if any
             if ($this->_subfieldValues[0]->getValue()) {
                 @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[0]->getValue());
                 $this->_subfieldValues[0]->setValue('');
             } elseif (isset($values[$prefixName . $this->_field->getID() . '_0_hidden']) && $values[$prefixName . $this->_field->getID() . '_0_hidden']) {
                 @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $values[$prefixName . $this->_field->getID() . '_0_hidden']);
                 $this->_subfieldValues[0]->setValue('');
             }
             if ($this->_subfieldValues[2]->getValue()) {
                 @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[2]->getValue());
                 $this->_subfieldValues[2]->setValue('');
             } elseif (isset($values[$prefixName . $this->_field->getID() . '_2_hidden']) && $values[$prefixName . $this->_field->getID() . '_2_hidden']) {
                 @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $values[$prefixName . $this->_field->getID() . '_2_hidden']);
                 $this->_subfieldValues[2]->setValue('');
             }
             //set thumbnail (resize it if needed)
             //create thumbnail path
             $path = PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED;
             $filename = "r" . $objectID . "_" . $this->_field->getID() . "_" . io::strtolower(SensitiveIO::sanitizeAsciiString($_FILES[$prefixName . $this->_field->getID() . '_0']["name"]));
             if (io::strlen($filename) > 255) {
                 $filename = sensitiveIO::ellipsis($filename, 255, '-', true);
             }
             //move uploaded file
             $fileDatas = CMS_file::uploadFile($prefixName . $this->_field->getID() . '_0', PATH_TMP_FS);
             if ($fileDatas['error']) {
                 return false;
             }
             if (!CMS_file::moveTo(PATH_TMP_FS . '/' . $fileDatas['filename'], $path . "/" . $filename)) {
                 return false;
             }
             if ($params['maxWidth'] > 0) {
                 $oImage = new CMS_image($path . "/" . $filename);
                 //get current file size
                 $sizeX = $oImage->getWidth();
                 $sizeY = $oImage->getHeight();
                 //check thumbnail size
                 if ($sizeX > $params['maxWidth'] || $sizeY > $params['maxHeight']) {
                     $newSizeX = $sizeX;
                     $newSizeY = $sizeY;
                     // Check width
                     if ($params['maxWidth'] && $newSizeX > $params['maxWidth']) {
                         $newSizeY = round($params['maxWidth'] * $newSizeY / $newSizeX);
                         $newSizeX = $params['maxWidth'];
                     }
                     if ($params['maxHeight'] && $newSizeY > $params['maxHeight']) {
                         $newSizeX = round($params['maxHeight'] * $newSizeX / $newSizeY);
                         $newSizeY = $params['maxHeight'];
                     }
                     //resize image
                     $srcfilepath = $path . "/" . $filename;
                     $path_parts = pathinfo($srcfilepath);
                     $thumbnailFilename = io::substr($path_parts['basename'], 0, -(io::strlen($path_parts['extension']) + 1)) . '_thumbnail.' . $path_parts['extension'];
                     $destfilepath = $path . "/" . $thumbnailFilename;
                     $extension = io::strtolower($path_parts['extension']);
                     if (!$oImage->resize($newSizeX, $newSizeY, $destfilepath)) {
                         return false;
                     }
                     //if we use original image as image zoom, set it
                     if ($values[$prefixName . $this->_field->getID() . '_makeZoom'] == 1) {
                         //set image zoom
                         if (!$this->_subfieldValues[2]->setValue($filename)) {
                             return false;
                         }
                     } else {
                         //destroy original image
                         unlink($srcfilepath);
                     }
                     //set resized thumbnail
                     if (!$this->_subfieldValues[0]->setValue($thumbnailFilename)) {
                         return false;
                     }
                 } else {
                     //no need to resize thumbnail (below the maximum width), so set it
                     if (!$this->_subfieldValues[0]->setValue($filename)) {
                         return false;
                     }
                     //if we use original image as image zoom, set it
                     if ($values[$prefixName . $this->_field->getID() . '_makeZoom'] == 1) {
                         //set image zoom
                         if (!$this->_subfieldValues[2]->setValue($filename)) {
                             return false;
                         }
                     }
                 }
             } else {
                 //no need to resize thumbnail, so set it
                 if (!$this->_subfieldValues[0]->setValue($filename)) {
                     return false;
                 }
                 //if we use original image as image zoom, set it
                 if ($values[$prefixName . $this->_field->getID() . '_makeZoom'] == 1) {
                     //set image zoom
                     if (!$this->_subfieldValues[2]->setValue($filename)) {
                         return false;
                     }
                 }
             }
         } elseif (isset($_FILES[$prefixName . $this->_field->getID() . '_0']) && $_FILES[$prefixName . $this->_field->getID() . '_0']['name'] && $_FILES[$prefixName . $this->_field->getID() . '_0']['error'] != 0) {
             return false;
         } elseif (isset($values[$prefixName . $this->_field->getID() . '_0_hidden']) && $values[$prefixName . $this->_field->getID() . '_0_hidden'] && (!isset($values[$prefixName . $this->_field->getID() . '_delete']) || $values[$prefixName . $this->_field->getID() . '_delete'] != 1)) {
             //set label as image name if none set
             if (!$this->_subfieldValues[0]->setValue($values[$prefixName . $this->_field->getID() . '_0_hidden'])) {
                 return false;
             }
         }
         //image zoom (if needed)
         if (isset($values[$prefixName . $this->_field->getID() . '_makeZoom']) && $values[$prefixName . $this->_field->getID() . '_makeZoom'] != 1 && isset($_FILES[$prefixName . $this->_field->getID() . '_2']['name']) && $_FILES[$prefixName . $this->_field->getID() . '_2']['name'] && !$_FILES[$prefixName . $this->_field->getID() . '_2']['error']) {
             //check for image type before doing anything
             if (!in_array(io::strtolower(pathinfo($_FILES[$prefixName . $this->_field->getID() . '_2']["name"], PATHINFO_EXTENSION)), $this->_allowedExtensions)) {
                 return false;
             }
             //create thumbnail path
             $path = PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED;
             $filename = "r" . $objectID . "_" . $this->_field->getID() . "_" . io::strtolower(SensitiveIO::sanitizeAsciiString($_FILES[$prefixName . $this->_field->getID() . '_2']["name"]));
             if (io::strlen($filename) > 255) {
                 $filename = sensitiveIO::ellipsis($filename, 255, '-', true);
             }
             //move uploaded file
             $fileDatas = CMS_file::uploadFile($prefixName . $this->_field->getID() . '_2', PATH_TMP_FS);
             if ($fileDatas['error']) {
                 return false;
             }
             if (!CMS_file::moveTo(PATH_TMP_FS . '/' . $fileDatas['filename'], $path . "/" . $filename)) {
                 return false;
             }
             //set it
             if (!$this->_subfieldValues[2]->setValue($filename)) {
                 return false;
             }
         } elseif (isset($_FILES[$prefixName . $this->_field->getID() . '_2']) && $_FILES[$prefixName . $this->_field->getID() . '_2']['name'] && $_FILES[$prefixName . $this->_field->getID() . '_2']['error'] != 0) {
             return false;
         } elseif (isset($values[$prefixName . $this->_field->getID() . '_2_hidden']) && $values[$prefixName . $this->_field->getID() . '_2_hidden'] && (!isset($values[$prefixName . $this->_field->getID() . '_delete']) || $values[$prefixName . $this->_field->getID() . '_delete'] != 1)) {
             if (!$this->_subfieldValues[2]->setValue($values[$prefixName . $this->_field->getID() . '_2_hidden'])) {
                 return false;
             }
         }
         return true;
     }
 }
Esempio n. 7
0
 /**
  * Do patch installation
  *
  * @param array of install command to do, view documentation for format
  *  This array MUST be checked before by checkInstall method to ensure it format is as correct as possible
  * @param array of excluded commands
  * @return void
  * @access public
  */
 function doInstall(&$array, $excludeCommand = array(), $stopOnErrors = true)
 {
     if (is_array($array)) {
         foreach ($array as $line => $aInstallCheck) {
             $line++;
             //to have the correct line number
             $installParams = array_map("trim", explode("\t", $aInstallCheck));
             if ($installParams[0] != 'ex') {
                 $originalFile = isset($installParams[1]) ? PATH_REALROOT_FS . $installParams[1] : PATH_REALROOT_FS;
                 $patchFile = isset($installParams[1]) ? PATH_TMP_FS . $installParams[1] : PATH_TMP_FS;
             }
             if (!in_array($installParams[0], $excludeCommand)) {
                 //launch installation request
                 switch ($installParams[0]) {
                     case ">":
                         //add or update a file or folder
                         //copy file or folder
                         if (CMS_FILE::copyTo($patchFile, $originalFile)) {
                             $this->_verbose(' -> File ' . $patchFile . ' successfully copied to ' . $originalFile);
                         } else {
                             $this->_report('Error during copy of ' . $patchFile . ' to ' . $originalFile, true);
                             if ($stopOnErrors) {
                                 return;
                             }
                         }
                         if (!isset($installParams[2])) {
                             break;
                         }
                     case "ch":
                         //execute chmod
                         $filesNOK = $this->applyChmod($installParams[2], $originalFile);
                         if (!$filesNOK) {
                             switch ($installParams[2]) {
                                 case 'r':
                                     $this->_verbose(' -> File(s) ' . $originalFile . ' are readable.');
                                     break;
                                 case 'w':
                                     $this->_verbose(' -> File(s) ' . $originalFile . ' are writable.');
                                     break;
                                 case 'x':
                                     $this->_verbose(' -> File(s) ' . $originalFile . ' are executable.');
                                     break;
                                 default:
                                     $this->_verbose(' -> File(s) ' . $originalFile . ' successfully chmoded with value ' . $installParams[2]);
                                     break;
                             }
                         } else {
                             $this->_report('Error during chmod operation of ' . $originalFile . '. Can\'t apply chmod value \'' . $installParams[2] . '\' on files :<br />' . $filesNOK . '<br />', true);
                             //do not stop on chmod error : only report them
                             //if ($stopOnErrors) return;
                         }
                         break;
                     case "<":
                         //delete a file or folder (recursively)
                         if (file_exists($originalFile) && CMS_FILE::deleteFile($originalFile)) {
                             $this->_verbose(' -> File ' . $originalFile . ' successfully deleted');
                         } else {
                             $this->_verbose(' -> Cannot delete ' . $originalFile . '. It does not exists.');
                         }
                         break;
                     case "+":
                         //concatenate module xml file
                         //load destination module parameters
                         $module = CMS_modulesCatalog::getByCodename($installParams[2]);
                         $moduleParameters = $module->getParameters(false, true);
                         //load the XML data of the source the files
                         $sourceXML = new CMS_file($patchFile);
                         $domdocument = new CMS_DOMDocument();
                         try {
                             $domdocument->loadXML($sourceXML->readContent("string"));
                         } catch (DOMException $e) {
                         }
                         $paramsTags = $domdocument->getElementsByTagName('param');
                         $sourceParameters = array();
                         foreach ($paramsTags as $aTag) {
                             $name = $aTag->hasAttribute('name') ? $aTag->getAttribute('name') : '';
                             $type = $aTag->hasAttribute('type') ? $aTag->getAttribute('type') : '';
                             $sourceParameters[$name] = array(CMS_DOMDocument::DOMElementToString($aTag, true), $type);
                         }
                         //merge the two tables of parameters
                         $resultParameters = array_merge($sourceParameters, $moduleParameters);
                         //set new parameters to the module
                         if ($module->setAndWriteParameters($resultParameters)) {
                             $this->_verbose(' -> File ' . $patchFile . ' successfully merged with module ' . $installParams[2] . ' parameters');
                         } else {
                             $this->_report('Error during merging of ' . $patchFile . ' with module ' . $installParams[2] . ' parameters', true);
                             if ($stopOnErrors) {
                                 return;
                             }
                         }
                         break;
                     case "x":
                         //execute SQL or PHP file
                         //exec sql script with help of some phpMyAdmin classes
                         if (io::substr($patchFile, -4, 4) == '.sql') {
                             if ($this->executeSqlScript($patchFile)) {
                                 $this->_verbose(' -> File ' . $patchFile . ' successfully executed');
                             } else {
                                 $this->_report('Error during execution of ' . $patchFile, true);
                                 if ($stopOnErrors) {
                                     return;
                                 }
                             }
                         } elseif (io::substr($patchFile, -4, 4) == '.php') {
                             //exec php script
                             $executionReturn = $this->executePhpScript($patchFile);
                             if ($executionReturn === false) {
                                 $this->_report('Error during execution of ' . $patchFile, true);
                                 if ($stopOnErrors) {
                                     return;
                                 }
                             } else {
                                 $executionReturn = $executionReturn ? ' -> Return :<br /><div style="border:1px;background-color:#000080;color:#C0C0C0;padding:5px;">' . $executionReturn . '</div><br />' : '';
                                 $this->_report(' -> File ' . $patchFile . ' executed<br />' . $executionReturn);
                             }
                         }
                         break;
                     case "co":
                         //execute change owner
                         $filesNOK = $this->changeOwner($installParams[2], $originalFile);
                         if (!$filesNOK) {
                             $this->_verbose(' -> Owner of file(s) ' . $originalFile . ' successfully changed to ' . $installParams[2]);
                         } else {
                             $this->_report('Error during operation on ' . $originalFile . '. Can\'t change owner to \'' . $installParams[2] . '\' on files :<br />' . $filesNOK . '<br />', true);
                             if ($stopOnErrors) {
                                 return;
                             }
                         }
                         break;
                     case "cg":
                         //execute change group
                         $filesNOK = $this->changeGroup($installParams[2], $originalFile);
                         if (!$filesNOK) {
                             $this->_verbose(' -> Group of file(s) ' . $originalFile . ' successfully changed to ' . $installParams[2]);
                         } else {
                             $this->_report('Error during operation on ' . $originalFile . '. Can\'t change group to \'' . $installParams[2] . '\' on files :<br />' . $filesNOK . '<br />', true);
                             if ($stopOnErrors) {
                                 return;
                             }
                         }
                         break;
                     case "rc":
                         $this->automneGeneralScript();
                         break;
                     case "htaccess":
                         $installParams[1] = io::substr($installParams[1], -1) == '/' ? io::substr($installParams[1], 0, -1) : $installParams[1];
                         $pathes = glob(PATH_REALROOT_FS . $installParams[1]);
                         if ($pathes) {
                             foreach ($pathes as $path) {
                                 if ($installParams[2] == 'root' && file_exists($path . '/.htaccess')) {
                                     //for root file, if already exists, only replace ErrorDocument instructions to set correct path
                                     $htaccessFile = new CMS_file($path . '/.htaccess');
                                     $lines = $htaccessFile->readContent('array', '');
                                     foreach ($lines as $key => $line) {
                                         if (substr($line, 0, 13) == 'ErrorDocument') {
                                             list($errorDoc, $code, $file) = preg_split("/[\\s]+/", $line);
                                             if ($code == '404') {
                                                 $lines[$key] = 'ErrorDocument 404 ' . PATH_REALROOT_WR . '/404.php' . "\n";
                                             } elseif ($code == '403') {
                                                 $lines[$key] = 'ErrorDocument 403 ' . PATH_REALROOT_WR . '/403.php' . "\n";
                                             }
                                         }
                                     }
                                     $htaccessFile->setContent(implode('', $lines), false);
                                     if ($htaccessFile->writeToPersistence()) {
                                         $this->_report('File ' . $path . '/.htaccess (' . $installParams[2] . ') successfully updated');
                                     } else {
                                         $this->_report('Error during operation on ' . $path . '/.htaccess. Can\'t write file.<br />', true);
                                     }
                                 } else {
                                     if (is_dir($path) && CMS_file::makeWritable($path)) {
                                         if (CMS_file::copyTo(PATH_HTACCESS_FS . '/htaccess_' . $installParams[2], $path . '/.htaccess')) {
                                             CMS_file::chmodFile(FILES_CHMOD, $path . '/.htaccess');
                                             $this->_report('File ' . $path . '/.htaccess (' . $installParams[2] . ') successfully writen');
                                         } else {
                                             $this->_report('Error during operation on ' . $path . '/.htaccess. Can\'t write file.<br />', true);
                                             if ($stopOnErrors) {
                                                 return;
                                             }
                                         }
                                     } else {
                                         $this->_report('Error during operation. ' . $path . ' must be a writable directory.<br />', true);
                                         if ($stopOnErrors) {
                                             return;
                                         }
                                     }
                                 }
                             }
                         }
                         break;
                     default:
                         if (io::substr($installParams[0], 0, 1) != '#') {
                             $this->raiseError("Unknown parameter : " . $installParams[0]);
                             return false;
                         }
                         break;
                 }
             } else {
                 $this->_report('Error during operation of "' . $aInstallCheck . '". Command execution is not allowed.<br />', true);
                 if ($stopOnErrors) {
                     return;
                 }
             }
         }
     } else {
         $this->raiseError("Param must be an array");
         return false;
     }
     //at end of any patch process, update Automne subversion to force reload of JS and CSS cache from client
     if (@file_put_contents(PATH_MAIN_FS . "/SUBVERSION", time()) !== false) {
         CMS_file::chmodFile(FILES_CHMOD, PATH_MAIN_FS . "/SUBVERSION");
     }
 }
Esempio n. 8
0
 /**
  * Duplicate this block
  * Used to duplicate a CMS_page.
  *
  * @param CMS_page $destinationPage, the page receiving a copy of this block
  * @param boolean $public The precision needed for USERSPACE location
  * @return CMS_block object
  */
 function duplicate(&$destinationPage, $public = false)
 {
     if (SensitiveIO::isPositiveInteger($this->_dbID)) {
         $link = $this->_link;
         if ($link->hasValidHREF()) {
             if ($link->getLinkType() == RESOURCE_LINK_TYPE_FILE) {
                 //get file path
                 $file = $link->getFileLink(false, MOD_STANDARD_CODENAME, RESOURCE_DATA_LOCATION_EDITED, PATH_RELATIVETO_FILESYSTEM, true);
                 $path = $link->getFileLink(true, MOD_STANDARD_CODENAME, RESOURCE_DATA_LOCATION_EDITED, PATH_RELATIVETO_FILESYSTEM, false);
                 if ($file && file_exists($path . '/' . $file)) {
                     //Copy linked file
                     //In new file name, delete reference to old page and add refernce to new one
                     $_newFilename = "p" . $destinationPage->getID() . io::substr($file, io::strpos($file, "_"), io::strlen($file));
                     if (@is_file(PATH_MODULES_FILES_STANDARD_FS . "/edited/" . $file) && CMS_file::copyTo(PATH_MODULES_FILES_STANDARD_FS . "/edited/" . $file, PATH_MODULES_FILES_STANDARD_FS . "/edited/" . $_newFilename) && CMS_file::chmodFile(FILES_CHMOD, PATH_MODULES_FILES_STANDARD_FS . "/edited/" . $_newFilename)) {
                         //Public
                         if ($public) {
                             if (!is_file(PATH_MODULES_FILES_STANDARD_FS . "/public/" . $file) || !CMS_file::copyTo(PATH_MODULES_FILES_STANDARD_FS . "/public/" . $file, PATH_MODULES_FILES_STANDARD_FS . "/public/" . $_newFilename) || !CMS_file::chmodFile(FILES_CHMOD, PATH_MODULES_FILES_STANDARD_FS . "/public/" . $_newFilename)) {
                                 $this->raiseError("Duplicate, file copy failed : " . PATH_MODULES_FILES_STANDARD_FS . "/public/" . $file);
                             }
                         }
                         $link->setFileLink($_newFilename);
                     }
                 }
             }
             $table = $this->_getDataTableName(RESOURCE_LOCATION_USERSPACE, $public);
             //Save new datas
             $str_set = "\n\t\t\t\t\t\tpage='" . $destinationPage->getID() . "',\n\t\t\t\t\t\tclientSpaceID='" . $this->_clientSpaceID . "',\n\t\t\t\t\t\trowID='" . $this->_rowID . "',\n\t\t\t\t\t\tblockID='" . $this->_tagID . "',\n\t\t\t\t\t\ttype='CMS_block_link',\n\t\t\t\t\t\tvalue='" . SensitiveIO::sanitizeSQLString($link->getTextDefinition()) . "'\n\t\t\t\t";
             $sql = "\n\t\t\t\t\tinsert into\n\t\t\t\t\t\t" . $table . "\n\t\t\t\t\tset\n\t\t\t\t\t\t" . $str_set . "\n\t\t\t\t";
             $q = new CMS_query($sql);
             if (!$q->hasError()) {
                 //Table Edition
                 $sql = "\n\t\t\t\t\t\tinsert into\n\t\t\t\t\t\t\t" . $this->_getDataTableName(RESOURCE_LOCATION_EDITION, false) . "\n\t\t\t\t\t\tset\n\t\t\t\t\t\t\tid='" . $q->getLastInsertedID() . "',\n\t\t\t\t\t\t\t" . $str_set . "\n\t\t\t\t\t";
                 $q = new CMS_query($sql);
                 return !$q->hasError();
             } else {
                 $this->raiseError("Duplicate, SQL insertion of new filename failed: " . $sql);
             }
         } else {
             $this->raiseError("Duplicate, copy of file failed :" . PATH_MODULES_FILES_STANDARD_FS . "/edited/" . $this->_file);
         }
     }
     return false;
 }
Esempio n. 9
0
 /**
  * public static getCloneFromID
  *
  * Clones a Row, changes some attributes
  * and writes it to persistence (MySQL for now)
  *
  * @param anyRowID as the ID of Row to be cloned
  * @param String label receive a new label for this Row
  * @param boolean $setPrivate Should the template be set as a private one ?  ALSO determines if the new row should point to the same file
  * @return a valid new CMS_row
  */
 static function getCloneFromID($rowID = 0, $label = false, $setPrivate = false)
 {
     $ret = false;
     $model = new CMS_row($rowID);
     if ($model->getID() > 0) {
         //New blank one
         $row = new CMS_row();
         //First write a new object to get it's ID
         $row->writeToPersistence();
         //Setting label
         $label = $label ? $label : $model->getLabel();
         $row->setLabel($label);
         //Copying template definition file (if not private template)
         if ($setPrivate) {
             $filename = $model->getDefinitionFileName();
         } else {
             $filename = "r" . $row->getID() . "_" . SensitiveIO::sanitizeAsciiString($row->getLabel()) . ".xml";
         }
         if ($setPrivate || CMS_file::copyTo(PATH_TEMPLATES_ROWS_FS . "/" . $model->getDefinitionFileName(), PATH_TEMPLATES_ROWS_FS . "/" . $filename)) {
             $row->setDefinitionFile($filename);
             //Copying groupsStack from database
             foreach ($model->getGroups() as $grp) {
                 $row->addGroup($grp);
             }
             //Copying image
             $row->setImage($model->getImage(CMS_file::WEBROOT, true));
             //set private if asked to.
             if ($setPrivate) {
                 $row->setPrivate(true);
             }
             //copy description
             $row->setDescription($model->getDescription());
             //add filtered templates
             $row->setFilteredTemplates($model->getFilteredTemplates());
             //Partial update for groups and image
             $row->writeToPersistence();
             $ret = $row;
         }
         unset($model);
     }
     if ($row) {
         //Clean if any error when out
         if (!$ret) {
             $row->destroy();
         }
         unset($row);
     }
     return $ret;
 }
Esempio n. 10
0
 /**
  * Crop current image from specified dimensions
  * 
  * @param integer $cropTop, the top value of the crop in pixels
  * @param integer $cropBottom, the bottom value of the crop in pixels
  * @param integer $cropLeft, the left value of the crop in pixels
  * @param integer $cropRight, the right value of the crop in pixels
  * @param integer $saveToPathFS, save cropped image to given FS path instead of replacing current one
  * @return boolean true on success, false on failure
  * @access public
  */
 function crop($cropTop, $cropBottom, $cropLeft, $cropRight, $saveToPathFS = '')
 {
     $imagepathFS = $this->getFilename();
     $sizeX = $this->getWidth();
     $sizeY = $this->getHeight();
     if (!io::isPositiveInteger($sizeX) || !io::isPositiveInteger($sizeY)) {
         $this->raiseError('Unkown image size ...');
         return false;
     }
     //if no crop needed
     if (!$cropTop && !$cropBottom && !$cropLeft && !$cropRight) {
         if (!$saveToPathFS) {
             return true;
         }
         return CMS_file::copyTo($imagepathFS, $saveToPathFS);
     }
     //if we do not have a path to save image, replace current file
     if (!$saveToPathFS) {
         $this->_height = $this->_width = null;
         $saveToPathFS = $imagepathFS;
     }
     //calculate cropped width and height
     $cWidth = $sizeX - $cropLeft - $cropRight;
     $cHeight = $sizeY - $cropTop - $cropBottom;
     //resize image and keep transparency if any
     switch ($this->getExtension()) {
         case "gif":
             $src = imagecreatefromgif($imagepathFS);
             $dest = imagecreate($cWidth, $cHeight);
             $transparent = imagecolortransparent($src);
             // If we have a specific transparent color
             if ($transparent >= 0) {
                 $transColor = imagecolorsforindex($src, $transparent);
                 $transparent = imagecolorallocate($dest, $transColor['red'], $transColor['green'], $transColor['blue']);
                 imagefill($dest, 0, 0, $transparent);
                 imagecolortransparent($dest, $transparent);
             }
             //create new image
             @imagecopyresampled($dest, $src, 0, 0, $cropLeft, $cropTop, $cWidth, $cHeight, $cWidth, $cHeight);
             imagegif($dest, $saveToPathFS);
             //destroy resources
             imagedestroy($src);
             imagedestroy($dest);
             break;
         case "jpg":
         case "jpeg":
         case "jpe":
             $src = imagecreatefromjpeg($imagepathFS);
             $dest = imagecreatetruecolor($cWidth, $cHeight);
             //create new image
             @imagecopyresampled($dest, $src, 0, 0, $cropLeft, $cropTop, $cWidth, $cHeight, $cWidth, $cHeight);
             imagejpeg($dest, $saveToPathFS, self::JPEG_QUALITY);
             //destroy resources
             imagedestroy($src);
             imagedestroy($dest);
             break;
         case "png":
             $src = imagecreatefrompng($imagepathFS);
             $dest = imagecreatetruecolor($cWidth, $cHeight);
             //save alpha channel
             imagealphablending($dest, false);
             imagesavealpha($dest, true);
             $transparent = imagecolorallocatealpha($dest, 255, 255, 255, 127);
             imagefilledrectangle($dest, 0, 0, $cWidth, $cHeight, $transparent);
             //create new image
             @imagecopyresampled($dest, $src, 0, 0, $cropLeft, $cropTop, $cWidth, $cHeight, $cWidth, $cHeight);
             imagepng($dest, $saveToPathFS, self::PNG_COMPRESSION);
             //destroy resources
             imagedestroy($src);
             imagedestroy($dest);
             break;
     }
     //chmod new file
     CMS_file::chmodFile(FILES_CHMOD, $saveToPathFS);
     return true;
 }
Esempio n. 11
0
 /**
  * public static getCloneFromID
  *
  * Clones a Template, changes some attributes
  * and writes it to persistence (MySQL for now)
  *
  * @param anyTemplateID as the ID of Template to be cloned
  * @param String label receive a new label for this Template
  * @param boolean $setPrivate Should the template be set as a private one ?  ALSO determines if the new template should point to the same file
  * @param boolean $dontCopyClientSpaces Should the clientspaces be copied ?
  * @param integer $tplFrom the original template ID to get good rows
  * @return a valid new CMS_pageTemplate
  */
 static function getCloneFromID($templateID = 0, $label = false, $setPrivate = false, $dontCopyClientSpaces = false, $tplFrom = false)
 {
     $ret = false;
     $model = new CMS_pageTemplate($templateID);
     if ($model->getID() > 0) {
         //New blank one
         $tpl = new CMS_pageTemplate();
         //First write a new object to get it's ID
         $tpl->writeToPersistence();
         //Setting label
         $label = $label ? $label : $model->getLabel();
         $tpl->setLabel($label);
         //Copying template definition file (if not private template)
         if ($setPrivate) {
             $filename = $model->getDefinitionFile();
         } else {
             $filename = "pt" . $tpl->getID() . "_" . SensitiveIO::sanitizeAsciiString($tpl->getLabel()) . ".xml";
         }
         if ($setPrivate || CMS_file::copyTo(PATH_TEMPLATES_FS . "/" . $model->getDefinitionFile(), PATH_TEMPLATES_FS . "/" . $filename)) {
             $tpl->setDefinitionFile($filename);
             //Copying groupsStack from database
             foreach ($model->getGroups() as $grp) {
                 $tpl->addGroup($grp);
             }
             //Copying image file from model to a new one
             if ($setPrivate) {
                 $tpl->setImage($model->getImage());
             } else {
                 if ($model->getImage()) {
                     $ext = io::substr($model->getImage(), strrpos($model->getImage(), "."));
                     $imagefilename = "pt" . $tpl->getID() . "_" . SensitiveIO::sanitizeAsciiString($tpl->getLabel()) . $ext;
                     if (CMS_file::copyTo(PATH_TEMPLATES_IMAGES_FS . "/" . $model->getImage(), PATH_TEMPLATES_IMAGES_FS . "/" . $imagefilename)) {
                         $tpl->setImage($imagefilename);
                     }
                 } else {
                     $tpl->setImage();
                 }
             }
             //set private if asked to.
             if ($setPrivate) {
                 $tpl->setPrivate(true);
             }
             //copy description
             $tpl->setDescription($model->getDescription());
             //websites denied
             $websitesDenied = $model->getWebsitesDenied();
             foreach ($websitesDenied as $websiteId) {
                 if (CMS_websitesCatalog::exists($websiteId)) {
                     //to check if website still exists
                     $tpl->denyWebsite($websiteId);
                 }
             }
             //Copy printing definition
             $tpl->setPrintingClientSpaces($model->getPrintingClientSpaces());
             //Partial update for groups and image
             $tpl->writeToPersistence();
             //Copying template clientspaces rows definitions
             if (!$dontCopyClientSpaces) {
                 $suffixes = array('archived', 'deleted', 'edited', 'edition', 'public');
                 foreach ($suffixes as $suffix) {
                     if ($tplFrom) {
                         $sql = "\n\t\t\t\t\t\t\t\tselect\n\t\t\t\t\t\t\t\t\t*\n\t\t\t\t\t\t\t\tfrom\n\t\t\t\t\t\t\t\t\t`mod_standard_clientSpaces_" . $suffix . "`\n\t\t\t\t\t\t\t\twhere\n\t\t\t\t\t\t\t\t\t`template_cs`='" . $tplFrom . "'\n\t\t\t\t\t\t\t";
                     } else {
                         $sql = "\n\t\t\t\t\t\t\t\tselect\n\t\t\t\t\t\t\t\t\t*\n\t\t\t\t\t\t\t\tfrom\n\t\t\t\t\t\t\t\t\t`mod_standard_clientSpaces_" . $suffix . "`\n\t\t\t\t\t\t\t\twhere\n\t\t\t\t\t\t\t\t\t`template_cs`='" . $model->getID() . "'\n\t\t\t\t\t\t\t";
                     }
                     $q = new CMS_query($sql);
                     while ($arr = $q->getArray()) {
                         $sql1 = "\n\t\t\t\t\t\t\t\tinsert into\n\t\t\t\t\t\t\t\t\t`mod_standard_clientSpaces_" . $suffix . "`\n\t\t\t\t\t\t\t\tset\n\t\t\t\t\t\t\t\t\t`template_cs`='" . $tpl->getID() . "',\n\t\t\t\t\t\t\t\t\t`tagID_cs`='" . SensitiveIO::sanitizeSQLString($arr["tagID_cs"]) . "',\n\t\t\t\t\t\t\t\t\t`rowsDefinition_cs`='" . SensitiveIO::sanitizeSQLString($arr["rowsDefinition_cs"]) . "',\n\t\t\t\t\t\t\t\t\t`type_cs`='" . $arr["type_cs"] . "',\n\t\t\t\t\t\t\t\t\t`order_cs`='" . $arr["order_cs"] . "'\n\t\t\t\t\t\t\t";
                         $q1 = new CMS_query($sql1);
                         unset($q1);
                     }
                     unset($q);
                 }
             }
             //CMS_Template to return
             $ret = $tpl;
         }
         unset($model);
     }
     if ($tpl) {
         //Clean if any error when out
         if (!$ret) {
             $tpl->destroy();
         }
         unset($tpl);
     }
     return $ret;
 }
Esempio n. 12
0
                $module->setLabel(1);
                $module->setPolymod(true);
                $module->setAdminFrontend('index.php');
                if ($module->writeToPersistence()) {
                    //create module label
                    //this is a direct sql query cause no writing interface exists now for messages table
                    $count = 0;
                    foreach ($languages as $aLanguage) {
                        $sql = "\n\t\t\t\t\t\t\tinsert into\n\t\t\t\t\t\t\t\tmessages\n\t\t\t\t\t\t\tset\n\t\t\t\t\t\t\t\tid_mes = '1',\n\t\t\t\t\t\t\t\tmodule_mes = '" . SensitiveIO::sanitizeSQLString($moduleCodename) . "',\n\t\t\t\t\t\t\t\tlanguage_mes = '" . SensitiveIO::sanitizeSQLString($aLanguage->getCode()) . "',\n\t\t\t\t\t\t\t\tmessage_mes = '" . SensitiveIO::sanitizeSQLString($_POST['label' . $aLanguage->getCode()]) . "'\n\t\t\t\t\t\t";
                        $q = new CMS_query($sql);
                    }
                    //create all needed .htaccess files
                    if (isset($_POST['hasprotect']) && $_POST['protect'] == 1) {
                        CMS_file::copyTo(PATH_HTACCESS_FS . '/htaccess_file', PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/edited/.htaccess');
                        CMS_file::chmodFile(FILES_CHMOD, PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/edited/.htaccess');
                        CMS_file::copyTo(PATH_HTACCESS_FS . '/htaccess_file', PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/public/.htaccess');
                        CMS_file::chmodFile(FILES_CHMOD, PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/public/.htaccess');
                    }
                    header("Location: modules_admin.php?moduleCodename=" . $moduleCodename . "&cms_message_id=" . MESSAGE_ACTION_OPERATION_DONE . "&" . session_name() . "=" . session_id());
                    exit;
                } else {
                    $cms_message .= "\n" . $cms_language->getMessage(MESSAGE_FORM_ERROR_DIRECTORY_CREATION, array($moduledir->getName(), $moduleDeleted->getName(), $moduleEdited->getName(), $modulePublic->getName()));
                }
            }
        }
        break;
}
//page dialog
$dialog = new CMS_dialog();
if (is_object($module)) {
    $dialog->setTitle($cms_language->getMessage(MESSAGE_PAGE_TITLE_EDIT, array($module->getLabel($cms_language))));