/** * 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; }
/** * Get datas vars from a form formatted by such a Automne.LinkField class * and build a CMS_href * * @param array $datas, the datas sent by the Automne.LinkField return * @param string $module, the module concerned by this link * @param integer $resourceID, ID to prepend the filename uploaded with * @param integer $fieldID, optional field ID to surcharge file name representation ("r".$resourceID."_f".$fieldID."_") * @return boolean true on success, false on failure * @access public */ function create($datas = '', $module = MOD_STANDARD_CODENAME, $resourceID, $fieldID = '') { $datas = explode($this->_href->getSeparator(), $datas); $linkLabel = isset($datas[7]) ? $datas[7] : ''; $linkType = isset($datas[0]) ? $datas[0] : ''; $internalLink = isset($datas[1]) ? $datas[1] : ''; $externalLink = isset($datas[2]) ? $datas[2] : ''; $this->_href->setLabel($linkLabel); $this->_href->setLinkType($linkType); $this->_href->setInternalLink($internalLink); $this->_href->setExternalLink($externalLink); // Delete/Upload file if (isset($datas[3])) { switch ($module) { case MOD_STANDARD_CODENAME: $locationType = RESOURCE_DATA_LOCATION_EDITION; $uniqueName = md5(serialize($this) . microtime()); $fileprefix = $fieldID ? 'p' . $resourceID . '_' . $uniqueName . "_f" . $fieldID : 'p' . $resourceID . '_' . $uniqueName; break; default: $locationType = RESOURCE_DATA_LOCATION_EDITED; $fileprefix = $fieldID ? 'r' . $resourceID . "_f" . $fieldID . "_" : 'r' . $resourceID . "_"; break; } if ($datas[3] && io::strpos($datas[3], PATH_UPLOAD_WR . '/') !== false) { //move and rename uploaded file $datas[3] = str_replace(PATH_UPLOAD_WR . '/', PATH_UPLOAD_FS . '/', $datas[3]); $basename = pathinfo($datas[3], PATHINFO_BASENAME); $path = $this->_href->getFileLink(true, $module, $locationType, PATH_RELATIVETO_FILESYSTEM, false); $newFilename = $path . '/' . $fileprefix . $basename; CMS_file::moveTo($datas[3], $newFilename); CMS_file::chmodFile(FILES_CHMOD, $newFilename); $datas[3] = pathinfo($newFilename, PATHINFO_BASENAME); //remove the old file if any if (is_file($this->_href->getFileLink(true, $module, $locationType, PATH_RELATIVETO_FILESYSTEM))) { if (!unlink($this->_href->getFileLink(true, $module, $locationType, PATH_RELATIVETO_FILESYSTEM))) { $this->raiseError("Could not delete old linked file"); } } } elseif ($datas[3]) { //keep old file $datas[3] = pathinfo($datas[3], PATHINFO_BASENAME); } else { $datas[3] = ''; //remove the old file if any if (is_file($this->_href->getFileLink(true, $module, $locationType, PATH_RELATIVETO_FILESYSTEM))) { if (!unlink($this->_href->getFileLink(true, $module, $locationType, PATH_RELATIVETO_FILESYSTEM))) { $this->raiseError("Could not delete old linked file"); } } } $this->_href->setFileLink($datas[3]); } elseif (is_file($this->_href->getFileLink(true, $module, $locationType, PATH_RELATIVETO_FILESYSTEM))) { //remove the old file if (!unlink($this->_href->getFileLink(true, $module, $locationType, PATH_RELATIVETO_FILESYSTEM))) { $this->raiseError("Could not delete old linked file"); } } // Target and Popup > (width, height) list($width, $height) = explode(',', $datas[6]); if (sensitiveIO::isPositiveInteger($width) && sensitiveIO::isPositiveInteger($height)) { $this->_href->setPopup($width, $height); } else { switch ($datas[4]) { case "_top": $this->_href->setTarget('_top'); $this->_href->setPopup('', ''); break; case "_blank": $this->_href->setTarget('_blank'); $this->_href->setPopup('', ''); break; } } return true; }
CMS_file::chmodFile(FILES_CHMOD, $newFilename); $data["file"] = pathinfo($newFilename, PATHINFO_BASENAME); } elseif ($filename) { //keep old file $data["file"] = pathinfo($filename, PATHINFO_BASENAME); } else { $data["file"] = ''; } //Image Zoom if ($zoomname && io::strpos($zoomname, PATH_UPLOAD_WR . '/') !== false) { //move and rename uploaded file $zoomname = str_replace(PATH_UPLOAD_WR . '/', PATH_UPLOAD_FS . '/', $zoomname); $basename = pathinfo($zoomname, PATHINFO_BASENAME); $newFilename = $cms_block->getFilePath($basename, $cms_page, $cs, $rowTag, $blockId, true); CMS_file::moveTo($zoomname, $newFilename); CMS_file::chmodFile(FILES_CHMOD, $newFilename); $data["enlargedFile"] = pathinfo($newFilename, PATHINFO_BASENAME); } elseif ($zoomname) { //keep old file $data["enlargedFile"] = pathinfo($zoomname, PATHINFO_BASENAME); } else { $data["enlargedFile"] = ''; } //Link $link = $old_data['externalLink'] ? new CMS_href($old_data['externalLink']) : new CMS_href(); $linkDialog = new CMS_dialog_href($link); $linkDialog->create($imagelink, MOD_STANDARD_CODENAME, $cms_page->getID()); $link = $linkDialog->getHref(); $data['externalLink'] = $link->getTextDefinition(); $cms_block->writeToPersistence($cms_page->getID(), $cs, $rowTag, RESOURCE_LOCATION_EDITION, false, $data); //instanciate the clientspace
/** * 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); } } }
/** * Raises an error. Shows it to the screen * Deprecated, use raiseError instead * @param string $errorMessage the error message. * @param boolean $encodeOutput, does the screen output should be encoded (default : false) * @return void * @access public */ public function _raiseError($errorMessage, $encodeOutput = false, $error = true) { static $errorNumber; $systemDebug = !defined('SYSTEM_DEBUG') ? true : SYSTEM_DEBUG; if (isset($this) && isset($this->_debug) && $this->_debug === NULL) { $this->_debug = $systemDebug; } if ($errorMessage) { //second condition are for static calls (made by static methods) if (!defined('APPLICATION_EXEC_TYPE') || APPLICATION_EXEC_TYPE == 'http' && (!isset($this) && $systemDebug || isset($this) && isset($this->_debug) && $this->_debug)) { $backTrace = $backTraceLink = ''; if (version_compare(phpversion(), "5.2.5", "<")) { $bt = @array_reverse(debug_backtrace()); } else { $bt = @array_reverse(debug_backtrace(false)); } $backtrace = array('summary' => sensitiveIO::printBackTrace($bt), 'backtrace' => @print_r($bt, true)); $backtraceName = 'bt_' . md5(rand()); $backTraceLink = PATH_ADMIN_WR . '/backtrace.php?bt=' . $backtraceName; //save backtrace to cache (for 10 min) $cache = new CMS_cache($backtraceName, 'atm-backtrace', 600, false); if ($cache) { $cache->save($backtrace); } unset($backtrace, $cache, $bt); //append error to current view $view = CMS_view::getInstance(); $outputMessage = $encodeOutput ? io::htmlspecialchars($errorMessage) : $errorMessage; $view->addError(array('error' => $outputMessage, 'backtrace' => $backTraceLink)); } //second condition are for static calls (made by static methods) if (!isset($this) || !isset($this->_log) || $this->_log) { if (@file_put_contents(PATH_MAIN_FS . '/' . self::ERROR_LOG, date("Y-m-d H:i:s", time()) . '|' . APPLICATION_EXEC_TYPE . '|' . $errorMessage . "\n", FILE_APPEND) !== false) { CMS_file::chmodFile(FILES_CHMOD, PATH_MAIN_FS . '/' . self::ERROR_LOG); } else { die('<pre><b>' . CMS_view::SYSTEM_LABEL . ' ' . AUTOMNE_VERSION . ' error : /automne dir is not writable' . "</b></pre>\n"); } } } //must be at the end because it interferes with the static calls conditions above if ($error && isset($this)) { $this->_errRaised = true; } }
if (!$cms_message) { //description $template->setDescription($description); //remove the old file if any and if new one is different if ($image) { if (is_file(PATH_TEMPLATES_IMAGES_FS . '/' . $template->getImage()) && $image != PATH_TEMPLATES_IMAGES_WR . '/' . $template->getImage() && $template->getImage() != 'nopicto.gif') { unlink(PATH_TEMPLATES_IMAGES_FS . '/' . $template->getImage()); } } if ($image && io::strpos($image, PATH_UPLOAD_WR . '/') !== false) { //move and rename uploaded file $image = str_replace(PATH_UPLOAD_WR . '/', PATH_UPLOAD_FS . '/', $image); $basename = pathinfo($image, PATHINFO_BASENAME); $movedImage = PATH_TEMPLATES_IMAGES_FS . '/' . SensitiveIO::sanitizeAsciiString($basename); CMS_file::moveTo($image, $movedImage); CMS_file::chmodFile(FILES_CHMOD, $movedImage); $image = pathinfo($movedImage, PATHINFO_BASENAME); } elseif ($template->getImage()) { //keep old file $image = $template->getImage(); } else { $image = 'nopicto.gif'; } $template->setImage($image); //groups $template->delAllGroups(); foreach ($groups as $group) { $template->addGroup($group); } if ($newgroups) { foreach ($newgroups as $group) {
/** * 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; }
/** * 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; } }
/** * Apply chmod on file(s) * * @param $right, string : rights to apply to file(s) * format : * r read (and execute if it's a folder) * w read and write (and execute if it's a folder) * x read+write+execute * XXX unix chmod octal value (ex : 664, 775, etc.) * @param $files, string : the files to apply new rights (relative to CMS_file::FILE_SYSTEM) * @return string, the files who can't apply the chmod, else nothing if all is done. * @access public */ function applyChmod($right, $files) { $filesList = CMS_file::getFileList($files); if (is_array($filesList) && $filesList) { $nok = ''; foreach ($filesList as $aFile) { switch ($right) { case 'r': $nok .= CMS_file::makeReadable($aFile['name']) ? '' : $aFile['name'] . '<br />'; break; case 'w': $nok .= CMS_file::makeWritable($aFile['name']) ? '' : $aFile['name'] . '<br />'; break; case 'x': $nok .= CMS_file::makeExecutable($aFile['name']) ? '' : $aFile['name'] . '<br />'; break; default: $nok .= CMS_file::chmodFile($right, $aFile['name']) ? '' : $aFile['name'] . '<br />'; break; } } return $nok; } else { return ''; } }
/** * Import row from given array datas * * @param array $data The module datas to import * @param array $params The import parameters. * array( * module => false|true : the module to create categories (required) * 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 (!isset($params['module'])) { $infos .= 'Error : missing module codename for categories importation ...' . "\n"; return false; } $module = CMS_modulesCatalog::getByCodename($params['module']); if ($module->hasError()) { $infos .= 'Error : invalid module for categories importation : ' . $params['module'] . "\n"; return false; } if (!$this->getID() && CMS_moduleCategories_catalog::uuidExists($data['uuid'])) { //check imported uuid. If categories does not have an Id, the uuid must be unique or must be regenerated $uuid = io::uuid(); //store old uuid relation $idsRelation['categories-uuid'][$data['uuid']] = $uuid; $data['uuid'] = $uuid; } //set category uuid if not exists if (!$this->_uuid) { $this->_uuid = $data['uuid']; } if (!isset($params['files']) || $params['files'] == true) { if (isset($data['icon'])) { $icon = $data['icon']; if ($icon && file_exists(PATH_TMP_FS . $icon)) { //destroy old file if any if ($this->getIconPath(false, PATH_RELATIVETO_WEBROOT, true)) { @unlink($this->getIconPath(true, PATH_RELATIVETO_FILESYSTEM, true)); $this->setAttribute('icon', ''); } //move and rename uploaded file $filename = PATH_TMP_FS . $icon; $basename = pathinfo($filename, PATHINFO_BASENAME); if (!$this->getID()) { //need item ID $this->writeToPersistence(); } //create file path $path = $this->getIconPath(true, PATH_RELATIVETO_FILESYSTEM, false) . '/'; $extension = pathinfo($icon, PATHINFO_EXTENSION); $newBasename = "cat-" . $this->getID() . "-icon." . $extension; $newFilename = $path . '/' . $newBasename; if (CMS_file::moveTo($filename, $newFilename)) { CMS_file::chmodFile(FILES_CHMOD, $newFilename); //set it $this->setAttribute('icon', $newBasename); } } elseif (!$icon) { //destroy old file if any if ($this->getIconPath(false, PATH_RELATIVETO_WEBROOT, true)) { @unlink($this->getIconPath(true, PATH_RELATIVETO_FILESYSTEM, true)); $this->setAttribute('icon', ''); } } } } if (isset($data['labels'])) { foreach ($data['labels'] as $language => $label) { $this->setLabel($label, $language); } } if (isset($data['descriptions'])) { foreach ($data['descriptions'] as $language => $desc) { $this->setDescription($desc, $language); } } if (!isset($params['files']) || $params['files'] == true) { if (isset($data['files']) && is_array($data['files'])) { foreach ($data['files'] as $language => $file) { if ($file && file_exists(PATH_TMP_FS . $file)) { //destroy old file if any if ($this->getFilePath($language, false, PATH_RELATIVETO_WEBROOT, true)) { @unlink($this->getFilePath($language, true, PATH_RELATIVETO_FILESYSTEM, true)); $this->setFile('', $language); } //move and rename uploaded file $filename = PATH_TMP_FS . $file; $basename = pathinfo($filename, PATHINFO_BASENAME); if (!$this->getID()) { //need item ID $this->writeToPersistence(); } //create file path $path = $this->getFilePath($language, true, PATH_RELATIVETO_FILESYSTEM, false) . '/'; $extension = pathinfo($file, PATHINFO_EXTENSION); $newBasename = "cat-" . $this->getID() . "-file-" . $language . "." . $extension; $newFilename = $path . '/' . $newBasename; if (CMS_file::moveTo($filename, $newFilename)) { CMS_file::chmodFile(FILES_CHMOD, $newFilename); //set it $this->setFile($newBasename, $language); } } elseif (!$file) { //destroy old file if any if ($this->getFilePath($language, false, PATH_RELATIVETO_WEBROOT, true)) { @unlink($this->getFilePath($language, true, PATH_RELATIVETO_FILESYSTEM, true)); $this->setFile('', $language); } } } } } //write object if (!$this->writeToPersistence()) { $infos .= 'Error : can not write category ...' . "\n"; return false; } //if current category id has changed from imported id, set relation if (isset($data['id']) && $data['id'] && $this->getID() != $data['id']) { $idsRelation['categories'][$data['id']] = $this->getID(); if (isset($data['uuid']) && $data['uuid']) { $idsRelation['categories'][$data['uuid']] = $this->getID(); } } //set category order if (isset($data['order']) && $data['order']) { CMS_moduleCategories_catalog::moveCategoryIndex($this, $data['order']); } //set categories childs if (isset($data['childs']) && $data['childs']) { return CMS_moduleCategories_catalog::fromArray($data['childs'], $params, $cms_language, $idsRelation, $infos); } return true; }
/** * Duplicate this block * Used to duplicate a CMS_page. * * @param CMS_page $destinationPage, the page receiving a copy of this block * @param boolean $public The precision needed for USERSPACE location * @return CMS_block object */ function duplicate(&$destinationPage, $public = false) { if (SensitiveIO::isPositiveInteger($this->_dbID)) { $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; }
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); } } //remove JS and CSS cache if (!CMS_cache::clearTypeCache('text/javascript') || !CMS_cache::clearTypeCache('text/css')) { $cms_message = $cms_language->getMessage(MESSAGE_CREATION_ERROR); } break; case 'polymod-cache-reset': //remove polymod cache if (CMS_cache::clearTypeCache('polymod') && CMS_cache::clearTypeCache('atm-polymod-structure')) { $cms_message = $cms_language->getMessage(MESSAGE_OPERATION_DONE); } else {
/** * 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 files ? //thumbnail if ($this->_subfieldValues[1]->getValue() && (!$values[$prefixName . $this->_field->getID() . '_1'] || pathinfo($values[$prefixName . $this->_field->getID() . '_1'], PATHINFO_BASENAME) != $this->_subfieldValues[1]->getValue())) { @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[1]->getValue()); $this->_subfieldValues[1]->setValue(''); } //file if ($this->_subfieldValues[4]->getValue() && (!$values[$prefixName . $this->_field->getID() . '_4'] || pathinfo($values[$prefixName . $this->_field->getID() . '_4'], PATHINFO_BASENAME) != $this->_subfieldValues[4]->getValue())) { @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[4]->getValue()); $this->_subfieldValues[4]->setValue(''); //reset filesize if (!$this->_subfieldValues[2]->setValue(0)) { return false; } } if (!(isset($values[$prefixName . $this->_field->getID() . '_0']) && $this->_subfieldValues[0]->setValue(io::htmlspecialchars($values[$prefixName . $this->_field->getID() . '_0'])))) { return false; } //thumbnail if (isset($values[$prefixName . $this->_field->getID() . '_1']) && $values[$prefixName . $this->_field->getID() . '_1'] && io::strpos($values[$prefixName . $this->_field->getID() . '_1'], PATH_UPLOAD_WR . '/') !== false) { $filename = $values[$prefixName . $this->_field->getID() . '_1']; //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[1]->getValue()) { @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[1]->getValue()); $this->_subfieldValues[1]->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); //resize thumbnail if needed if ($params['thumbMaxWidth'] > 0 || $params['thumbMaxHeight'] > 0) { $oImage = new CMS_image($newFilename); //get current file size $sizeX = $oImage->getWidth(); $sizeY = $oImage->getHeight(); //check thumbnail size list($sizeX, $sizeY) = @getimagesize($newFilename); if ($params['thumbMaxWidth'] && $sizeX > $params['thumbMaxWidth'] || $params['thumbMaxHeight'] && $sizeY > $params['thumbMaxHeight']) { $newSizeX = $sizeX; $newSizeY = $sizeY; // Check width if ($params['thumbMaxWidth'] && $newSizeX > $params['thumbMaxWidth']) { $newSizeY = round($params['thumbMaxWidth'] * $newSizeY / $newSizeX); $newSizeX = $params['thumbMaxWidth']; } if ($params['thumbMaxHeight'] && $newSizeY > $params['thumbMaxHeight']) { $newSizeX = round($params['thumbMaxHeight'] * $newSizeX / $newSizeY); $newSizeY = $params['thumbMaxHeight']; } if (!$oImage->resize($newSizeX, $newSizeY, $newFilename)) { return false; } } } //set thumbnail if (!$this->_subfieldValues[1]->setValue($newBasename)) { return false; } } //File //1- from external location if (isset($values[$prefixName . $this->_field->getID() . '_externalfile']) && $values[$prefixName . $this->_field->getID() . '_externalfile']) { //from FTP directory $filename = $values[$prefixName . $this->_field->getID() . '_externalfile']; //check file extension if ($params['allowedType'] || $params['disallowedType']) { $extension = io::strtolower(pathinfo($filename, PATHINFO_EXTENSION)); if (!$extension) { return false; } //extension must be in allowed list if ($params['allowedType'] && !in_array($extension, explode(',', io::strtolower($params['allowedType'])))) { return false; } //extension must not be in disallowed list if ($params['disallowedType'] && in_array($extension, explode(',', io::strtolower($params['disallowedType'])))) { return false; } } //destroy old file if any if ($this->_subfieldValues[4]->getValue()) { @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[4]->getValue()); $this->_subfieldValues[4]->setValue(''); } $new_filename = 'r' . $objectID . "_" . $this->_field->getID() . "_" . io::strtolower(SensitiveIO::sanitizeAsciiString($filename)); if (io::strlen($new_filename) > 255) { $new_filename = sensitiveIO::ellipsis($new_filename, 255, '-', true); } $destination_path = PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/'; $ftp_dir = PATH_REALROOT_FS . $params['ftpDir']; if (@file_exists($ftp_dir . $filename) && is_file($ftp_dir . $filename)) { if (CMS_file::moveTo($ftp_dir . $filename, $destination_path . '/' . $new_filename)) { CMS_file::chmodFile(FILES_CHMOD, $destination_path . '/' . $new_filename); //set label as file name if none set if (!$values[$prefixName . $this->_field->getID() . '_0']) { if (!$this->_subfieldValues[0]->setValue(io::htmlspecialchars($filename))) { return false; } } //set it if (!$this->_subfieldValues[4]->setValue($new_filename)) { return false; } //and set filesize $filesize = @filesize($destination_path . '/' . $new_filename); if ($filesize !== false && $filesize > 0) { //convert in MB $filesize = round($filesize / 1048576, 2); } else { $filesize = '0'; } if (!$this->_subfieldValues[2]->setValue($filesize)) { return false; } //set file type if (!$this->_subfieldValues[3]->setValue(self::OBJECT_FILE_TYPE_INTERNAL)) { return false; } } else { return false; } } else { return false; } } else { //2- from post if ($values[$prefixName . $this->_field->getID() . '_4'] && io::strpos($values[$prefixName . $this->_field->getID() . '_4'], PATH_UPLOAD_WR . '/') !== false) { //check file extension if ($params['allowedType'] || $params['disallowedType']) { $extension = io::strtolower(pathinfo($values[$prefixName . $this->_field->getID() . '_4'], PATHINFO_EXTENSION)); if (!$extension) { return false; } //extension must be in allowed list if ($params['allowedType'] && !in_array($extension, explode(',', io::strtolower($params['allowedType'])))) { return false; } //extension must not be in disallowed list if ($params['disallowedType'] && in_array($extension, explode(',', io::strtolower($params['disallowedType'])))) { return false; } } //set file type if (!$this->_subfieldValues[3]->setValue(self::OBJECT_FILE_TYPE_INTERNAL)) { return false; } //destroy old file if any if ($this->_subfieldValues[4]->getValue()) { @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[4]->getValue()); $this->_subfieldValues[4]->setValue(''); } //move and rename uploaded file $filename = str_replace(PATH_UPLOAD_WR . '/', PATH_UPLOAD_FS . '/', $values[$prefixName . $this->_field->getID() . '_4']); $basename = pathinfo($filename, PATHINFO_BASENAME); //create file path $path = PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED; $newBasename = "r" . $objectID . "_" . $this->_field->getID() . "_" . io::strtolower(SensitiveIO::sanitizeAsciiString($basename)); if (io::strlen($newBasename) > 255) { $newBasename = sensitiveIO::ellipsis($newBasename, 255, '-', true); } $newFilename = $path . '/' . $newBasename; if (!CMS_file::moveTo($filename, $newFilename)) { return false; } CMS_file::chmodFile(FILES_CHMOD, $newFilename); //set it if (!$this->_subfieldValues[4]->setValue($newBasename)) { return false; } //and set filesize $filesize = @filesize($newFilename); if ($filesize !== false && $filesize > 0) { //convert in MB $filesize = round($filesize / 1048576, 2); } else { $filesize = '0'; } if (!$this->_subfieldValues[2]->setValue($filesize)) { return false; } } } // If label not set yet, set it if (!$this->_subfieldValues[0]->getValue()) { if ($this->_subfieldValues[4]->getValue()) { $this->_subfieldValues[0]->setValue($this->_subfieldValues[4]->getValue()); } } //update files infos if needed if ($this->_subfieldValues[1]->getValue() && file_exists(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[1]->getValue())) { $file = new CMS_file(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[1]->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' => ''); } //update files infos if needed if ($this->_subfieldValues[4]->getValue() && file_exists(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[4]->getValue())) { $file = new CMS_file(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[4]->getValue()); $fileDatas = array('filename' => $file->getName(false), 'filepath' => $file->getFilePath(CMS_file::WEBROOT), 'filesize' => $file->getFileSize(), 'fileicon' => $file->getFileIcon(CMS_file::WEBROOT), 'extension' => $file->getExtension()); } else { $fileDatas = array('filename' => '', 'filepath' => '', 'filesize' => '', 'fileicon' => '', 'extension' => ''); } $imageDatas['module'] = $fileDatas['module'] = $moduleCodename; $imageDatas['visualisation'] = $fileDatas['visualisation'] = RESOURCE_DATA_LOCATION_EDITED; $content = array('datas' => array('polymodFieldsValue[' . $prefixName . $this->_field->getID() . '_1]' => $imageDatas, 'polymodFieldsValue[' . $prefixName . $this->_field->getID() . '_4]' => $fileDatas, 'polymodFieldsValue[' . $prefixName . $this->_field->getID() . '_externalfile]' => '', 'polymodFieldsValue[' . $prefixName . $this->_field->getID() . '_0]' => sensitiveIO::decodeEntities($this->_subfieldValues[0]->getValue()))); $view = CMS_view::getInstance(); $view->addContent($content); return true; } else { //Old format //delete old files ? if (isset($values[$prefixName . $this->_field->getID() . '_delete']) && $values[$prefixName . $this->_field->getID() . '_delete'] == 1) { //thumbnail if ($this->_subfieldValues[1]->getValue()) { @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[1]->getValue()); $this->_subfieldValues[1]->setValue(''); } elseif ($values[$prefixName . $this->_field->getID() . '_1_hidden']) { @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $values[$prefixName . $this->_field->getID() . '_1_hidden']); $this->_subfieldValues[1]->setValue(''); } //file if ($this->_subfieldValues[4]->getValue()) { @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[4]->getValue()); $this->_subfieldValues[4]->setValue(''); } elseif ($values[$prefixName . $this->_field->getID() . '_4_hidden']) { @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $values[$prefixName . $this->_field->getID() . '_4_hidden']); $this->_subfieldValues[4]->setValue(''); } //reset filesize if (!$this->_subfieldValues[2]->setValue(0)) { return false; } } if (!(isset($values[$prefixName . $this->_field->getID() . '_0']) && $this->_subfieldValues[0]->setValue(io::htmlspecialchars($values[$prefixName . $this->_field->getID() . '_0'])))) { return false; } //thumbnail if (isset($_FILES[$prefixName . $this->_field->getID() . '_1']) && $_FILES[$prefixName . $this->_field->getID() . '_1']['name'] && !$_FILES[$prefixName . $this->_field->getID() . '_1']['error']) { //check for image type before doing anything if (!in_array(io::strtolower(pathinfo($_FILES[$prefixName . $this->_field->getID() . '_1']["name"], PATHINFO_EXTENSION)), $this->_allowedExtensions)) { return false; } //destroy old image if any if ($this->_subfieldValues[1]->getValue()) { @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[1]->getValue()); $this->_subfieldValues[1]->setValue(''); } elseif ($values[$prefixName . $this->_field->getID() . '_1_hidden']) { @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $values[$prefixName . $this->_field->getID() . '_1_hidden']); $this->_subfieldValues[1]->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() . '_1']["name"])); if (io::strlen($filename) > 255) { $filename = sensitiveIO::ellipsis($filename, 255, '-', true); } //move uploaded file $fileDatas = CMS_file::uploadFile($prefixName . $this->_field->getID() . '_1', PATH_TMP_FS); if ($fileDatas['error']) { return false; } if (!CMS_file::moveTo(PATH_TMP_FS . '/' . $fileDatas['filename'], $path . "/" . $filename)) { return false; } if ($params['thumbMaxWidth'] > 0 || $params['thumbMaxHeight'] > 0) { $oImage = new CMS_image($path . "/" . $filename); //get current file size $sizeX = $oImage->getWidth(); $sizeY = $oImage->getHeight(); //check thumbnail size if ($sizeX > $params['thumbMaxWidth'] || $sizeX > $params['thumbMaxHeight']) { $newSizeX = $sizeX; $newSizeY = $sizeY; // Check width if ($params['thumbMaxWidth'] && $newSizeX > $params['thumbMaxWidth']) { $newSizeY = round($params['thumbMaxWidth'] * $newSizeY / $newSizeX); $newSizeX = $params['thumbMaxWidth']; } if ($params['thumbMaxHeight'] && $newSizeY > $params['thumbMaxHeight']) { $newSizeX = round($params['thumbMaxHeight'] * $newSizeX / $newSizeY); $newSizeY = $params['thumbMaxHeight']; } //resize image $srcfilepath = $path . "/" . $filename; $path_parts = pathinfo($srcfilepath); $thumbnailFilename = io::substr($path_parts['basename'], 0, -(io::strlen($path_parts['extension']) + 1)) . '.png'; $destfilepath = $path . "/" . $thumbnailFilename; if (!$oImage->resize($newSizeX, $newSizeY, $destfilepath)) { return false; } //destroy original image @unlink($srcfilepath); //set resized thumbnail if (!$this->_subfieldValues[1]->setValue($thumbnailFilename)) { return false; } } else { //no need to resize thumbnail (below the maximum width), so set it if (!$this->_subfieldValues[1]->setValue($filename)) { return false; } } } else { //no need to resize thumbnail (no size limit), so set it if (!$this->_subfieldValues[1]->setValue($filename)) { return false; } } } elseif (isset($_FILES[$prefixName . $this->_field->getID() . '_1']) && $_FILES[$prefixName . $this->_field->getID() . '_1']['name'] && $_FILES[$prefixName . $this->_field->getID() . '_1']['error'] != 0) { return false; } elseif (isset($values[$prefixName . $this->_field->getID() . '_1_hidden']) && $values[$prefixName . $this->_field->getID() . '_1_hidden'] && $values[$prefixName . $this->_field->getID() . '_delete'] != 1) { if (!$this->_subfieldValues[1]->setValue($values[$prefixName . $this->_field->getID() . '_1_hidden'])) { return false; } } //File //1- from external location if (isset($values[$prefixName . $this->_field->getID() . '_externalfile']) && $values[$prefixName . $this->_field->getID() . '_externalfile']) { //destroy old file if any if ($this->_subfieldValues[4]->getValue()) { @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[4]->getValue()); $this->_subfieldValues[4]->setValue(''); } elseif ($values[$prefixName . $this->_field->getID() . '_4_hidden']) { @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $values[$prefixName . $this->_field->getID() . '_4_hidden']); $this->_subfieldValues[4]->setValue(''); } //from FTP directory $filename = $values[$prefixName . $this->_field->getID() . '_externalfile']; //io::substr($values[$prefixName.$this->_field->getID().'_externalfile'], 1); //check file extension if ($params['allowedType'] || $params['disallowedType']) { $extension = io::strtolower(pathinfo($filename, PATHINFO_EXTENSION)); if (!$extension) { return false; } //extension must be in allowed list if ($params['allowedType'] && !in_array($extension, explode(',', io::strtolower($params['allowedType'])))) { return false; } //extension must not be in disallowed list if ($params['disallowedType'] && in_array($extension, explode(',', io::strtolower($params['disallowedType'])))) { return false; } } $new_filename = 'r' . $objectID . "_" . $this->_field->getID() . "_" . io::strtolower(SensitiveIO::sanitizeAsciiString($filename)); if (io::strlen($new_filename) > 255) { $new_filename = sensitiveIO::ellipsis($new_filename, 255, '-', true); } $destination_path = PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/'; $ftp_dir = PATH_REALROOT_FS . $params['ftpDir']; if (@file_exists($ftp_dir . $filename) && is_file($ftp_dir . $filename)) { if (@copy($ftp_dir . $filename, $destination_path . '/' . $new_filename)) { @chmod($destination_path . '/' . $new_filename, octdec(FILES_CHMOD)); //set label as file name if none set if (!$values[$prefixName . $this->_field->getID() . '_0']) { if (!$this->_subfieldValues[0]->setValue(io::htmlspecialchars($filename))) { return false; } } //set it if (!$this->_subfieldValues[4]->setValue($new_filename)) { return false; } //and set filesize $filesize = @filesize($destination_path . '/' . $new_filename); if ($filesize !== false && $filesize > 0) { //convert in MB $filesize = round($filesize / 1048576, 2); } else { $filesize = '0'; } if (!$this->_subfieldValues[2]->setValue($filesize)) { return false; } //set file type if (!$this->_subfieldValues[3]->setValue(self::OBJECT_FILE_TYPE_INTERNAL)) { return false; } } else { return false; } } else { return false; } } else { //2- from post if (isset($_FILES[$prefixName . $this->_field->getID() . '_4']) && $_FILES[$prefixName . $this->_field->getID() . '_4']['name'] && !$_FILES[$prefixName . $this->_field->getID() . '_4']['error']) { //check file extension if ($params['allowedType'] || $params['disallowedType']) { $extension = io::strtolower(pathinfo($_FILES[$prefixName . $this->_field->getID() . '_4']['name'], PATHINFO_EXTENSION)); if (!$extension) { return false; } //extension must be in allowed list if ($params['allowedType'] && !in_array($extension, explode(',', io::strtolower($params['allowedType'])))) { return false; } //extension must not be in disallowed list if ($params['disallowedType'] && in_array($extension, explode(',', io::strtolower($params['disallowedType'])))) { return false; } } //set label as image name if none set if (!$values[$prefixName . $this->_field->getID() . '_0']) { if (!$this->_subfieldValues[0]->setValue(io::htmlspecialchars($_FILES[$prefixName . $this->_field->getID() . '_4']["name"]))) { return false; } } //set file type if (!$this->_subfieldValues[3]->setValue(self::OBJECT_FILE_TYPE_INTERNAL)) { return false; } //destroy old file if any if ($this->_subfieldValues[4]->getValue()) { @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[4]->getValue()); $this->_subfieldValues[4]->setValue(''); } //create thumnail 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() . '_4']["name"])); if (io::strlen($filename) > 255) { $filename = sensitiveIO::ellipsis($filename, 255, '-', true); } //move uploaded file $fileDatas = CMS_file::uploadFile($prefixName . $this->_field->getID() . '_4', 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[4]->setValue($filename)) { return false; } //and set filesize $filesize = @filesize($path . "/" . $filename); if ($filesize !== false && $filesize > 0) { //convert in MB $filesize = round($filesize / 1048576, 2); } else { $filesize = '0'; } if (!$this->_subfieldValues[2]->setValue($filesize)) { return false; } } elseif (isset($_FILES[$prefixName . $this->_field->getID() . '_4']) && $_FILES[$prefixName . $this->_field->getID() . '_4']['name'] && $_FILES[$prefixName . $this->_field->getID() . '_4']['error'] != 0) { return false; } else { //from hidden fields (previously set but not already saved) if (isset($values[$prefixName . $this->_field->getID() . '_4_hidden']) && $values[$prefixName . $this->_field->getID() . '_4_hidden'] && (!isset($values[$prefixName . $this->_field->getID() . '_delete']) || $values[$prefixName . $this->_field->getID() . '_delete'] != 1)) { //set label as image name if none set if ($values[$prefixName . $this->_field->getID() . '_0']) { if (!$this->_subfieldValues[0]->setValue(io::htmlspecialchars($values[$prefixName . $this->_field->getID() . '_0']))) { return false; } } //set filesize if (!$this->_subfieldValues[2]->setValue($values[$prefixName . $this->_field->getID() . '_2_hidden'])) { return false; } //set file type if (!$this->_subfieldValues[3]->setValue($values[$prefixName . $this->_field->getID() . '_3_hidden'])) { return false; } if (!$this->_subfieldValues[4]->setValue($values[$prefixName . $this->_field->getID() . '_4_hidden'])) { return false; } } } } // If label not set yet, set it if (!$this->_subfieldValues[0]->getValue()) { if ($this->_subfieldValues[4]->getValue()) { $this->_subfieldValues[0]->setValue($this->_subfieldValues[4]->getValue()); } } return true; } }
/** * 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; }
$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)))); $dialog->setBackLink('modules_admin.php?moduleCodename=' . $moduleCodename);
/** * function moveTo * Try to move a file (and create all parents if needed) * @param string $from, the full filename of the file to move * @param string $to, the full filename of the file moved * @return boolean true on success, false on failure * @static */ function moveTo($from, $to) { $from = realpath($from); if (@is_file($from)) { //check if parent directory exist else create it if (!@is_dir(dirname($to))) { CMS_file::makeDir(dirname($to)); } //move the file (ie : rename it) $return = @rename($from, $to); if ($return) { CMS_file::chmodFile(FILES_CHMOD, $to); } return $return; } return false; }