/** * Constructor */ public function __construct() { $cx = \Cx\Core\Core\Controller\Cx::instanciate(); $folderPath = $cx->getWebsiteTempPath() . '/Update'; if (!file_exists($folderPath)) { \Cx\Lib\FileSystem\FileSystem::make_folder($folderPath); } if (!file_exists($folderPath . '/' . self::PENDING_DB_UPDATES_YML)) { \Cx\Lib\FileSystem\FileSystem::copy_file($cx->getCodeBaseCoreModulePath() . '/Update/Data/' . self::PENDING_DB_UPDATES_YML, $folderPath . '/' . self::PENDING_DB_UPDATES_YML); } parent::__construct($folderPath . '/' . self::PENDING_DB_UPDATES_YML); }
/** * Copy the Upload the image to the path * Note: validation should be done before calling this function * * @param string $filePath Temp path of the uploaded media * * @return boolean|string relative path of the uploaded file, false otherwise */ function uploadMedia($filePath) { if ($filePath == '' || !\FWValidator::is_file_ending_harmless($filePath)) { return false; } $fileName = basename($filePath); //get extension $arrFileInfo = pathinfo($fileName); $fileExtension = !empty($arrFileInfo['extension']) ? '.' . $arrFileInfo['extension'] : ''; $fileBasename = $arrFileInfo['filename']; $randomSum = rand(10, 99); //encode filename if ($this->arrSettings['settingsEncryptFilenames'] == 1) { $fileName = md5($randomSum . $fileBasename) . $fileExtension; } //check filename if (file_exists($this->imagePath . 'uploads/' . $fileName)) { $fileName = $fileBasename . '_' . time() . $fileExtension; } //upload file if (\Cx\Lib\FileSystem\FileSystem::copy_file($filePath, $this->imagePath . 'uploads/' . $fileName) !== false) { $objFile = new \File(); $objFile->setChmod($this->imagePath, $this->imageWebPath, 'uploads/' . $fileName); return $this->imageWebPath . 'uploads/' . $fileName; } else { return false; } }
/** * Copy the Upload the image to the path * Note: validation should be done before calling this function * * @param string $imagePath Temp path of the uploaded media * * @return boolean|string relative path of the uploaded file, false otherwise */ function uploadMedia($imagePath) { if ($imagePath == '' || !\FWValidator::is_file_ending_harmless($imagePath)) { return false; } // get extension $imageName = basename($imagePath); $arrImageInfo = pathinfo($imageName); $imageExtension = !empty($arrImageInfo['extension']) ? '.' . $arrImageInfo['extension'] : ''; $imageBasename = $arrImageInfo['filename']; $randomSum = rand(10, 99); // encode filename if ($this->arrSettings['settingsEncryptFilenames'] == 1) { $imageName = md5($randomSum . $imageBasename) . $imageExtension; } // check filename if (file_exists($this->imagePath . 'images/' . $imageName)) { $imageName = $imageBasename . '_' . time() . $imageExtension; } // upload file if (\Cx\Lib\FileSystem\FileSystem::copy_file($imagePath, $this->imagePath . 'images/' . $imageName) === false) { return false; } $imageDimension = getimagesize($this->imagePath . 'images/' . $imageName); $intNewWidth = $imageDimension[0]; $intNewHeight = $imageDimension[1]; $imageFormat = $imageDimension[0] > $imageDimension[1] ? 1 : 0; $setNewSize = 0; if ($imageDimension[0] > 640 && $imageFormat == 1) { $doubleFactorDimension = 640 / $imageDimension[0]; $intNewWidth = 640; $intNewHeight = round($doubleFactorDimension * $imageDimension[1], 0); $setNewSize = 1; } elseif ($imageDimension[1] > 480) { $doubleFactorDimension = 480 / $imageDimension[1]; $intNewHeight = 480; $intNewWidth = round($doubleFactorDimension * $imageDimension[0], 0); $setNewSize = 1; } if ($setNewSize == 1) { $objImage = new \ImageManager(); $objImage->loadImage($this->imagePath . 'images/' . $imageName); $objImage->resizeImage($intNewWidth, $intNewHeight, 100); $objImage->saveNewImage($this->imagePath . 'images/' . $imageName, true); } $objFile = new \File(); $objFile->setChmod($this->imagePath, $this->imageWebPath, 'images/' . $imageName); // create thumbnail $this->checkThumbnail($this->imageWebPath . 'images/' . $imageName); return $this->imageWebPath . 'images/' . $imageName; }
/** * Update and store all settings found in the $_POST array * * Note that you *MUST* call {@see init()} beforehand, or your settings * will be unknown and thus not be stored. * Sets up an error message on failure. * @return boolean True on success, null on noop, * or false on failure */ static function storeFromPost() { global $_CORELANG; //echo("self::storeFromPost(): POST:<br />".nl2br(htmlentities(var_export($_POST, true)))."<hr />"); //echo("self::storeFromPost(): FILES:<br />".nl2br(htmlentities(var_export($_FILES, true)))."<hr />"); // There may be several tabs for different groups being edited, so // load the full set of settings for the module. // Note that this is why setting names should be unique. // TODO: You *MUST* call this yourself *before* in order to // properly initialize the section! // self::init(); $engine = self::getSectionEngine(); if ($engine == null) { return false; } $arrSettings = $engine->getArraySetting(); $submittedGroup = !empty($_POST['settingGroup']) ? $_POST['settingGroup'] : null; unset($_POST['bsubmit']); $result = true; // Compare POST with current settings and only store what was changed. foreach (array_keys($arrSettings) as $name) { if (isset($_POST[$name])) { $value = contrexx_input2raw($_POST[$name]); //if (preg_match('/^'.preg_quote(CSRF::key(), '/').'$/', $name)) //continue; switch ($arrSettings[$name]['type']) { case self::TYPE_FILEUPLOAD: // An empty folder path has been posted, indicating that the // current file should be removed if (empty($value)) { //echo("Empty value, deleting file...<br />"); if ($arrSettings[$name]['value']) { if (\File::delete_file($arrSettings[$name]['value'])) { //echo("File deleted<br />"); $value = ''; } else { //echo("Failed to delete file<br />"); \Message::error(\File::getErrorString()); $result = false; } } } else { // No file uploaded. Skip. if (empty($_FILES[$name]['name'])) { continue; } // $value is the target folder path $target_path = $value . '/' . $_FILES[$name]['name']; // TODO: Test if this works in all browsers: // The path input field name is the same as the // file upload input field name! $result_upload = \File::upload_file_http($name, $target_path, \Filetype::MAXIMUM_UPLOAD_FILE_SIZE, $arrSettings[$name]['values']); // If no file has been uploaded at all, ignore the no-change // TODO: Noop is not implemented in File::upload_file_http() // if ($result_upload === '') continue; if ($result_upload === true) { $value = $target_path; } else { //echo("self::storeFromPost(): Error uploading file for setting $name to $target_path<br />"); // TODO: Add error message \Message::error(\File::getErrorString()); $result = false; } } break; case self::TYPE_CHECKBOX: break; case self::TYPE_DROPDOWN_MULTISELECT: $value = array_flip($value); case self::TYPE_CHECKBOXGROUP: $value = is_array($value) ? join(',', array_keys($value)) : $value; // 20120508 // 20120508 case self::TYPE_RADIO: break; case self::TYPE_IMAGE: $cx = \Cx\Core\Core\Controller\Cx::instanciate(); $options = json_decode($arrSettings[$name]['values'], true); if ($options['type'] && $options['type'] == 'copy') { \Cx\Lib\FileSystem\FileSystem::copy_file($cx->getWebsitePath() . $value, $cx->getWebsitePath() . '/' . $arrSettings[$name]['value'], true); $value = $arrSettings[$name]['value']; } break; default: // Regular value of any other type break; } //\DBG::log('setting value ' . $name . ' = ' . $value); self::set($name, $value); } elseif ($arrSettings[$name]['type'] == self::TYPE_CHECKBOX && $arrSettings[$name]['group'] == $submittedGroup) { self::set($name, null); } } //echo("self::storeFromPost(): So far, the result is ".($result ? 'okay' : 'no good')."<br />"); $result_update = self::updateAll(); if ($result_update === false) { \Message::error($_CORELANG['TXT_CORE_SETTING_ERROR_STORING']); } elseif ($result_update === true) { \Message::ok($_CORELANG['TXT_CORE_SETTING_STORED_SUCCESSFULLY']); } // If nothing bad happened above, return the result of updateAll(), // which may be true, false, or the empty string if ($result === true) { return $result_update; } // There has been an error anyway return false; }