示例#1
0
    /**
     * Get file pointer
     * This dedicates to greatest developer of all time, Maxim Shamaev. Because getFilename() is not enough for name combining.
     *
     * @return resource
     */
    protected function getFilePointer()
    {
        if (!isset($this->filePointer)) {
            $name = $this->getFilename();
            $dir = \Includes\Utils\FileManager::getRealPath(LC_DIR_VAR . $this->generator->getOptions()->dir);
            if (is_writable($dir)) {
                if (!\Includes\Utils\FileManager::isExists($dir . LC_DS . '.htaccess')) {
                    // Try to create .htaccess file to protect directory
                    $out = <<<OUT
Options -Indexes

Deny from all

OUT;
                    \Includes\Utils\FileManager::write($dir . LC_DS . '.htaccess', $out);
                }
                $this->filePath = $dir . LC_DS . $name;
                $this->filePointer = @fopen($dir . LC_DS . $name, 'ab');
            } else {
                $this->generator->addError(static::t('Directory does not have permissions to write'), static::t('Directory X does not have permissions to write. Please set necessary permissions to directory X.', array('path' => $dir)));
            }
        }
        return $this->filePointer;
    }
示例#2
0
 /**
  * Import 'image' value
  *
  * @param \XLite\Model\Category $model  Category
  * @param string                $value  Value
  * @param array                 $column Column info
  *
  * @return void
  */
 protected function importImageColumn(\XLite\Model\Category $model, $value, array $column)
 {
     if ($value && $this->verifyValueAsFile($value)) {
         $image = $model->getImage();
         if (!$image) {
             $image = new \XLite\Model\Image\Category\Image();
             $image->setCategory($model);
             $model->setImage($image);
             \XLite\Core\Database::getEM()->persist($image);
         }
         if (1 < count(parse_url($value))) {
             $success = $image->loadFromURL($value, true);
         } else {
             $dir = \Includes\Utils\FileManager::getRealPath(LC_DIR_VAR . $this->importer->getOptions()->dir);
             $success = $image->loadFromLocalFile($dir . LC_DS . $value);
         }
         if (!$success) {
             $this->addError('PRODUCT-IMG-LOAD-FAILED', array('column' => $column, 'value' => $path));
         } else {
             $image->setNeedProcess(1);
         }
     }
 }
示例#3
0
 /**
  * Delete all files
  *
  * @return void
  */
 public function deleteAllFiles()
 {
     $dir = \Includes\Utils\FileManager::getRealPath(LC_DIR_VAR . $this->getOptions()->dir);
     if (!\Includes\Utils\FileManager::isExists($dir)) {
         \Includes\Utils\FileManager::mkdir($dir);
     }
     $list = glob($dir . LC_DS . '*');
     if ($list) {
         foreach ($list as $path) {
             if (is_file($path)) {
                 \Includes\Utils\FileManager::deleteFile($path);
             } else {
                 \Includes\Utils\FileManager::unlinkRecursive($path);
             }
         }
     }
 }
示例#4
0
 /**
  * Verify value as file
  *
  * @param mixed @value Value
  *
  * @return boolean
  */
 protected function verifyValueAsFile($value)
 {
     // Do not verify files in verification mode and if 'ignoreFileChecking' option is true
     if (!$this->isVerification() || !$this->importer->getOptions()->ignoreFileChecking) {
         if (1 < count(parse_url($value))) {
             $request = new \XLite\Core\HTTP\Request($value);
             $response = $request->sendRequest();
             $result = $response && 200 == $response->code;
         } else {
             $dir = \Includes\Utils\FileManager::getRealPath(LC_DIR_VAR . $this->importer->getOptions()->dir);
             $result = \Includes\Utils\FileManager::isReadable($dir . LC_DS . $value);
         }
     } else {
         $result = true;
     }
     return $result;
 }
示例#5
0
 /**
  * Import 'variantImage' value
  *
  * @param \XLite\Model\Product $model  Product
  * @param array                $value  Value
  * @param array                $column Column info
  *
  * @return void
  */
 protected function importVariantImageColumn(\XLite\Model\Product $model, $value, array $column)
 {
     foreach ($this->variants as $rowIndex => $variant) {
         if (isset($value[$rowIndex])) {
             $path = $value[$rowIndex];
             if ($this->verifyValueAsFile($path)) {
                 $image = $variant->getImage();
                 $isNew = false;
                 if (!$image) {
                     $isNew = true;
                     $image = new \XLite\Module\XC\ProductVariants\Model\Image\ProductVariant\Image();
                 }
                 if (1 < count(parse_url($path))) {
                     $success = $image->loadFromURL($path, true);
                 } else {
                     $dir = \Includes\Utils\FileManager::getRealPath(LC_DIR_VAR . $this->importer->getOptions()->dir);
                     $success = $image->loadFromLocalFile($dir . LC_DS . $path);
                 }
                 if (!$success) {
                     $this->addError('PRODUCT-IMG-LOAD-FAILED', array('column' => $column, 'value' => $path));
                 } elseif ($isNew) {
                     $image->setProductVariant($variant);
                     $variant->setImage($image);
                     \XLite\Core\Database::getEM()->persist($image);
                 }
             }
         }
     }
 }
示例#6
0
 /**
  * Import 'images' value
  *
  * @param \XLite\Model\Product $model  Product
  * @param array                $value  Value
  * @param array                $column Column info
  *
  * @return void
  */
 protected function importImagesColumn(\XLite\Model\Product $model, array $value, array $column)
 {
     if ($value) {
         foreach ($value as $index => $path) {
             if ($this->verifyValueAsFile($path)) {
                 $image = $model->getImages() ? $model->getImages()->get($index) : null;
                 $isNew = false;
                 if (!$image) {
                     $isNew = true;
                     $image = new \XLite\Model\Image\Product\Image();
                 }
                 if (1 < count(parse_url($path))) {
                     $success = $image->loadFromURL($path, true);
                 } else {
                     $dir = \Includes\Utils\FileManager::getRealPath(LC_DIR_VAR . $this->importer->getOptions()->dir);
                     $success = $image->loadFromLocalFile($dir . LC_DS . $path);
                 }
                 if (!$success) {
                     $this->addError('PRODUCT-IMG-LOAD-FAILED', array('column' => $column, 'value' => $path));
                 } else {
                     $image->setNeedProcess(1);
                     if ($isNew) {
                         $image->setProduct($model);
                         $model->getImages()->add($image);
                         \XLite\Core\Database::getEM()->persist($image);
                     }
                 }
             }
         }
         while (count($model->getImages()) > count($value)) {
             $image = $model->getImages()->last();
             \XLite\Core\Database::getRepo('XLite\\Model\\Image\\Product\\Image')->delete($image, false);
             $model->getImages()->removeElement($image);
         }
     }
 }
示例#7
0
 /**
  * Read file from package
  *
  * @param string $relativePath File relative path in package
  *
  * @return string
  */
 protected function getFileSource($relativePath)
 {
     $source = null;
     $path = \Includes\Utils\FileManager::getCanonicalDir($this->getRepositoryPath());
     if (!empty($path)) {
         $path = \Includes\Utils\FileManager::getRealPath($this->getFullPath($relativePath, $path));
     }
     if (!empty($path)) {
         $source = \Includes\Utils\FileManager::read($path);
     }
     return $source;
 }
示例#8
0
 /**
  * Import 'image' value
  *
  * @param \XLite\Model\Category $model  Category
  * @param string                $value  Value
  * @param array                 $column Column info
  *
  * @return void
  */
 protected function importImageColumn(\XLite\Model\Category $model, $value, array $column)
 {
     if ($value && $this->verifyValueAsFile($value)) {
         $image = $model->getImage();
         if (!$image) {
             $image = new \XLite\Model\Image\Category\Image();
             $image->setCategory($model);
             $model->setImage($image);
             \XLite\Core\Database::getEM()->persist($image);
         }
         if (1 < count(parse_url($value))) {
             $image->loadFromURL($value, true);
         } else {
             $dir = \Includes\Utils\FileManager::getRealPath(LC_DIR_VAR . $this->importer->getOptions()->dir);
             $image->loadFromLocalFile($dir . LC_DS . $value);
         }
     }
 }
示例#9
0
 /**
  * Check path to be inside the files catalog repository. {lc_catalog}/files
  * Return full path that inside the repository.
  * If path is out the one then returns the catalog repository path.
  *
  * @return string
  */
 public static function getNormalizedPath($path)
 {
     $filesCatalog = \XLite\View\BrowseServer::getFilesCatalog();
     $path = \Includes\Utils\FileManager::getRealPath($filesCatalog . LC_DS . $path);
     return $filesCatalog !== substr($path, 0, strlen($filesCatalog)) ? $filesCatalog : $path;
 }