Exemplo n.º 1
0
 /**
  * Populate model object properties by the passed data
  *
  * @param array $data Data to set
  *
  * @return void
  */
 protected function setModelProperties(array $data)
 {
     $options = $this->getOptions();
     $dir = LC_DIR_SKINS . \XLite\Core\Layout::PATH_COMMON . LC_DS;
     if ('CDev\\SimpleCMS' == $options[0]->category) {
         if ($_FILES && $_FILES['logo'] && $_FILES['logo']['name']) {
             $path = \Includes\Utils\FileManager::moveUploadedFile('logo', $dir);
             if ($path) {
                 if ($options[0]->value) {
                     \Includes\Utils\FileManager::deleteFile($dir . $options[0]->value);
                 }
                 $data['logo'] = basename($path);
             }
         } elseif (\XLite\Core\Request::getInstance()->useDefaultLogo) {
             $data['logo'] = '';
             if ($options[0]->value) {
                 \Includes\Utils\FileManager::deleteFile($dir . $options[0]->value);
             }
         } else {
             $data['logo'] = $options[0]->value;
         }
     }
     parent::setModelProperties($data);
 }
Exemplo n.º 2
0
 /**
  * Install uploaded add-on
  *
  * @return void
  */
 protected function doActionUploadAddon()
 {
     $this->setReturnURL($this->buildURL('addons_list_installed'));
     $path = \Includes\Utils\FileManager::moveUploadedFile('modulePack');
     if ($path) {
         \XLite\Upgrade\Cell::getInstance()->clear(true, true, false);
         $entry = \XLite\Upgrade\Cell::getInstance()->addUploadedModule($path);
         if (!isset($entry)) {
             $this->showError(__FUNCTION__, static::t('unable to add module entry to the installation list: X', array('path' => $path)));
         } elseif (\XLite::getInstance()->checkVersion($entry->getMajorVersionNew(), '!=')) {
             $this->showError(__FUNCTION__, static::t('module version X is not equal to the core one (Y)', array('module_version' => $entry->getMajorVersionNew(), 'core_version' => \XLite::getInstance()->getMajorVersion())));
         } elseif ($this->isNextStepAvailable()) {
             $this->setReturnURL($this->buildURL('upgrade', 'download', $this->getActionParamsCommon(true)));
         } else {
             $this->showError(__FUNCTION__);
         }
     } else {
         $this->showError(__FUNCTION__, static::t('unable to upload module'));
     }
 }
Exemplo n.º 3
0
 /**
  * Additional preparations for images.
  * Upload them into specific directory
  *
  * @param string $optionValue Option value
  * @param string $imageType   Image type
  *
  * @return string
  */
 protected function prepareImageData($optionValue, $imageType)
 {
     $dir = static::getLogoFaviconDir();
     if ($_FILES && $_FILES[$imageType] && $_FILES[$imageType]['name']) {
         $path = null;
         $realName = preg_replace('/([^a-zA-Z0-9_\\-\\.]+)/', '_', $_FILES[$imageType]['name']);
         if ($this->isImage($_FILES[$imageType]['tmp_name'], $realName)) {
             if (!\Includes\Utils\FileManager::isDir($dir)) {
                 \Includes\Utils\FileManager::mkdirRecursive($dir);
             }
             if (\Includes\Utils\FileManager::isDir($dir)) {
                 // Remove file with same name as uploaded file in the destination directory
                 \Includes\Utils\FileManager::deleteFile($dir . LC_DS . ('favicon' === $imageType ? static::FAVICON : $realName));
                 // Move uploaded file to destination directory
                 $path = \Includes\Utils\FileManager::moveUploadedFile($imageType, $dir, 'favicon' === $imageType ? static::FAVICON : $realName);
                 if ($path) {
                     if ($optionValue && 'favicon' !== $imageType && basename($optionValue) != $realName) {
                         // Remove old image file
                         \Includes\Utils\FileManager::deleteFile($dir . basename($optionValue));
                     }
                     $optionValue = static::getLogoFaviconSubDir() . basename($path);
                 }
             }
             if (!isset($path)) {
                 $this->logoFaviconValidation = false;
                 \XLite\Core\TopMessage::addError('The "{{file}}" file was not uploaded', array('file' => $realName));
             }
         } else {
             $this->logoFaviconValidation = false;
             \XLite\Core\TopMessage::addError('The "{{file}}" file is not allowed image and was not uploaded. Allowed images are: {{extensions}}', array('file' => $realName, 'extensions' => implode(', ', $this->getImageExtensions())));
         }
     } elseif (\XLite\Core\Request::getInstance()->useDefaultImage[$imageType]) {
         if ($optionValue) {
             \Includes\Utils\FileManager::deleteFile($dir . basename($optionValue));
         }
         $optionValue = '';
     }
     return $optionValue;
 }
Exemplo n.º 4
0
 /**
  * Load from request
  *
  * @param string $key Key in $_FILES service array
  *
  * @return boolean
  */
 public function loadFromRequest($key)
 {
     $path = \Includes\Utils\FileManager::moveUploadedFile($key, $this->getStoreFileSystemRoot());
     if ($path) {
         $this->setStorageType(static::STORAGE_RELATIVE);
         if (!empty($_FILES[$key]['type'])) {
             $this->setMime($_FILES[$key]['type']);
         }
         if (!$this->savePath($path)) {
             \Includes\Utils\FileManager::deleteFile($path);
             $path = null;
         }
     } else {
         \XLite\Logger::getInstance()->log('The file was not loaded', LOG_ERR);
     }
     return !empty($path);
 }
Exemplo n.º 5
0
 /**
  * Load from request
  *
  * @param string $key Key in $_FILES service array
  *
  * @return boolean
  */
 public function loadFromRequest($key)
 {
     if (!$this->s3Forbid && $this->getS3()) {
         $result = false;
         $path = \Includes\Utils\FileManager::moveUploadedFile($key, LC_DIR_TMP);
         if ($path) {
             $result = $this->loadFromLocalFile($path, $_FILES[$key]['name']);
             \Includes\Utils\FileManager::deleteFile($path);
         } else {
             \XLite\Logger::getInstance()->log('The file was not loaded', LOG_ERR);
         }
     } else {
         $result = parent::loadFromRequest($key);
     }
     return $result;
 }