Пример #1
0
 /**
  * Get valid file system storage root
  *
  * @return string
  */
 protected function getStoreFileSystemRoot()
 {
     $shipments = $this->getLink()->getManifest()->getShipments();
     $path = parent::getStoreFileSystemRoot() . $shipments[0]->getParcel()->getOrder()->getOrderId() . LC_DS;
     \Includes\Utils\FileManager::mkdirRecursive($path);
     return $path;
 }
Пример #2
0
 /**
  * Clean aggregation cache directory
  *
  * @return void
  */
 public function doActionCleanAggregationCache()
 {
     \Includes\Utils\FileManager::unlinkRecursive(LC_DIR_CACHE_RESOURCES);
     \Less_Cache::SetCacheDir(LC_DIR_DATACACHE);
     \Less_Cache::CleanCache();
     \XLite\Core\TopMessage::addInfo('Aggregation cache has been cleaned');
 }
Пример #3
0
 /**
  * Get promotion message
  *
  * @return string
  */
 protected function getPromotionMessage()
 {
     $addons = $this->getAddons();
     $modules = array();
     $params = array('clearCnd' => 1);
     foreach ($addons as $addon => $title) {
         if (!\Includes\Utils\Operator::checkIfClassExists('\\XLite\\Module\\' . $addon . '\\Main')) {
             $match = explode('\\', $addon);
             $mainClassFile = LC_DIR_MODULES . str_replace('\\', '/', $addon) . '/Main.php';
             if (\Includes\Utils\FileManager::isExists($mainClassFile)) {
                 // Module is installed but not enabled
                 $limit = \XLite\View\Pager\Admin\Module\Manage::getInstance()->getItemsPerPage();
                 $pageId = \XLite\Core\Database::getRepo('XLite\\Model\\Module')->getInstalledPageId($match[0], $match[1], $limit);
                 $pageParam = 'page';
                 $target = 'addons_list_installed';
             } else {
                 // Module is not installed
                 list(, $limit) = $this->getWidget(array(), '\\XLite\\View\\Pager\\Admin\\Module\\Install')->getLimitCondition()->limit;
                 $pageId = \XLite\Core\Database::getRepo('XLite\\Model\\Module')->getMarketplacePageId($match[0], $match[1], $limit);
                 $pageParam = 'pageId';
                 $target = 'addons_list_marketplace';
             }
             if (0 < $pageId) {
                 $params[$pageParam] = $pageId;
             }
             $url = $this->buildURL($target, '', $params) . '#' . $match[1];
             $modules[] = '<a href="' . $url . '">' . $title . '</a>';
         }
     }
     return 0 < count($modules) ? static::t('Install additional modules to add more product sources', array('list' => implode(', ', $modules))) : '';
 }
Пример #4
0
 /**
  * Modify class source
  *
  * @param \Includes\Decorator\DataStructure\Graph\Classes $node Current node
  *
  * @return void
  */
 protected function writeCallToSourceFile(\Includes\Decorator\DataStructure\Graph\Classes $node)
 {
     $path = LC_DIR_CACHE_CLASSES . $node->getPath();
     $content = \Includes\Utils\FileManager::read($path);
     $content .= PHP_EOL . '// Call static constructor' . PHP_EOL;
     $content .= '\\' . $node->getClass() . '::' . static::STATIC_CONSTRUCTOR_METHOD . '();';
     \Includes\Utils\FileManager::write($path, $content);
 }
Пример #5
0
 public static function getCounter()
 {
     $data = \Includes\Utils\FileManager::read(static::getFilePath());
     if ($data) {
         $data = substr($data, strlen('; <' . '?php /*' . PHP_EOL), strlen('; */ ?' . '>') * -1);
         $data = unserialize($data);
     }
     return $data && is_array($data) && isset($data['count']) ? intval($data['count']) : 0;
 }
Пример #6
0
 /**
  * doActionDelete
  *
  * @return void
  * @throws
  */
 protected function doActionDelete()
 {
     if (\Includes\Utils\FileManager::isExists($this->sqldumpFile) && !\Includes\Utils\FileManager::deleteFile($this->sqldumpFile)) {
         \XLite\Core\TopMessage::addError(static::t('Unable to delete file') . ' ' . $this->sqldumpFile);
     } else {
         \XLite\Core\TopMessage::addInfo('SQL file was deleted successfully');
     }
     $this->doRedirect();
 }
Пример #7
0
 public function testGetPublicTitle()
 {
     \Includes\Utils\FileManager::unlinkRecursive(LC_DIR_FILES . 'attachments');
     $attach = $this->getTestAttachment();
     $this->assertEquals('max_ava.png', $attach->getPublicTitle(), 'check default title');
     $this->assertEquals('', $attach->getTitle(), 'check empty title');
     $attach->setTitle('test');
     $this->assertEquals('test', $attach->getPublicTitle(), 'check normal title');
 }
Пример #8
0
 /**
  * Return URL for module icon
  *
  * @return string
  */
 public static function getIconURL()
 {
     list($author, $name) = explode('\\', \Includes\Utils\ModulesManager::getModuleNameByClassName(get_called_class()));
     $path = \Includes\Utils\ModulesManager::getModuleIconFile($author, $name);
     $url = '';
     if (\Includes\Utils\FileManager::isFileReadable($path)) {
         $url = \XLite\Core\Converter::buildURL('module', null, compact('author', 'name'), 'image.php');
     }
     return $url;
 }
Пример #9
0
 /**
  * Constructor
  * Creates directory for locks if needed
  */
 public function __construct()
 {
     if (!\Includes\Utils\FileManager::isExists(rtrim(static::LOCK_DIR, LC_DS))) {
         \Includes\Utils\FileManager::mkdirRecursive(rtrim(static::LOCK_DIR, LC_DS));
     }
     if (!\Includes\Utils\FileManager::isReadable(static::LOCK_DIR) || !\Includes\Utils\FileManager::isWriteable(static::LOCK_DIR)) {
         \XLite\Logger::getInstance()->log('Cannot create lock for keys', LOG_DEBUG);
     }
     parent::__construct();
 }
Пример #10
0
 /**
  * Action 'import'
  *
  * @return void
  */
 protected function doActionImport()
 {
     $fileName = \XLite\Core\Session::getInstance()->language_import_file;
     if (\Includes\Utils\FileManager::isExists($fileName)) {
         $result = \XLite\Core\Database::getRepo('XLite\\Model\\Language')->parseImportFile($fileName, true);
         \XLite\Core\Session::getInstance()->language_import_result = $result;
     } else {
         \XLite\Core\Session::getInstance()->language_import_file = null;
         \XLite\Core\TopMessage::addError('File not found');
     }
     $this->setReturnURL($this->buildURL('languages'));
 }
Пример #11
0
 /**
  * Return classes tree
  * 
  * @param boolean $create Flag OPTIONAL
  *  
  * @return \Includes\Decorator\DataStructure\Graph\Classes
  */
 public static function getClassesTree($create = true)
 {
     if (!isset(static::$classesTree) && $create) {
         if (\Includes\Utils\FileManager::isFileReadable(static::getClassesHashPath())) {
             $data = unserialize(\Includes\Utils\FileManager::read(static::getClassesHashPath()));
             static::$classesTree = array_pop($data);
         } else {
             static::$classesTree = \Includes\Decorator\Utils\Operator::createClassesTree();
         }
     }
     return static::$classesTree;
 }
Пример #12
0
 /**
  * Return list of registered plugins
  *
  * @param string $hook Hook name OPTIONAL
  *
  * @return array
  */
 protected static function getPlugins($hook = null)
 {
     if (!isset(static::$plugins)) {
         // Check config file
         if (\Includes\Utils\FileManager::isFileReadable(static::getConfigFile())) {
             // Iterate over all sections
             foreach (parse_ini_file(static::getConfigFile(), true) as $section => $plugins) {
                 // Set plugins order
                 asort($plugins, SORT_NUMERIC);
                 // Save plugins list
                 static::$plugins[$section] = array_fill_keys(array_keys($plugins), null);
             }
         } else {
             \Includes\ErrorHandler::fireError('Unable to read config file for the Decorator plugins');
         }
     }
     return \Includes\Utils\ArrayManager::getIndex(static::$plugins, $hook);
 }
Пример #13
0
 /**
  * Return templates chain
  *
  * @return array
  */
 protected function getChain()
 {
     $result = array();
     /** @var \XLite\Core\Layout $layout */
     $layout = \XLite\Core\Layout::getInstance();
     $shortPath = $this->getValue();
     $files = array();
     foreach ($layout->getSkinPaths(\XLite::CUSTOMER_INTERFACE) as $path) {
         $fullPath = $path['fs'] . LC_DS . $shortPath;
         if (file_exists($fullPath) && is_file($fullPath)) {
             array_unshift($files, $fullPath);
         }
     }
     foreach ($files as $fullPath) {
         $result[substr($fullPath, strlen(LC_DIR_SKINS))] = htmlspecialchars(\Includes\Utils\FileManager::read($fullPath));
     }
     return $result;
 }
Пример #14
0
function bindRegionsToUK()
{
    $statesFile = __DIR__ . LC_DS . 'regionForUkStates.yaml';
    if (!\Includes\Utils\FileManager::isFileReadable($statesFile)) {
        return false;
    }
    $data = \Symfony\Component\Yaml\Yaml::parse($statesFile);
    foreach ($data['states'] as $state) {
        $foundByCode = \XLite\Core\Database::getRepo('XLite\\Model\\State')->findOneBy(array('code' => $state['code']));
        // If we found state with code we should bind region
        if ($foundByCode) {
            $region = \XLite\Core\Database::getRepo('XLite\\Model\\Region')->findOneBy(array('code' => $state['region']['code']));
            if ($region) {
                $foundByCode->setRegion($region);
            }
        }
    }
    \XLite\Core\Database::getEM()->flush();
    return true;
}
Пример #15
0
 /**
  * Execute certain hook handler
  *
  * @return void
  */
 public function executeHookHandler()
 {
     // Remove old capsular directories
     if (\Includes\Decorator\Utils\CacheManager::isCapsular()) {
         $currentKey = \Includes\Decorator\Utils\CacheManager::getKey();
         foreach (\Includes\Decorator\Utils\CacheManager::getCacheDirs(true) as $dir) {
             $list = glob(rtrim($dir, LC_DS) . '.*');
             if ($list) {
                 foreach ($list as $subdir) {
                     list($main, $key) = explode('.', $subdir, 2);
                     if ($key && $key != $currentKey) {
                         \Includes\Utils\FileManager::unlinkRecursive($subdir);
                     }
                 }
             }
         }
     }
     \Includes\Decorator\Utils\CacheManager::cleanupCache();
     // Load classes from "classes" (do not use cache)
     \Includes\Autoloader::switchLcAutoloadDir();
     \Includes\Decorator\Plugin\Doctrine\Plugin\QuickData\Main::initializeCounter();
 }
Пример #16
0
 /**
  * Process item
  *
  * @param mixed $item Item
  *
  * @return boolean
  */
 protected function processItem($item)
 {
     $result = false;
     $path = tempnam(LC_DIR_TMP, 'migrate_file');
     file_put_contents($path, $item->getBody());
     if (\Includes\Utils\FileManager::isExists($path)) {
         $localPath = $item->isURL() ? null : $item->getStoragePath();
         $result = $item->loadFromLocalFile($path, $item->getFileName() ?: basename($item->getPath()));
         if ($result && $localPath && \Includes\Utils\FileManager::isExists($localPath)) {
             \Includes\Utils\FileManager::deleteFile($localPath);
         }
         \Includes\Utils\FileManager::deleteFile($path);
     }
     if (!$result) {
         if (!isset($this->record['s3_error_count'])) {
             $this->record['s3_error_count'] = 0;
         }
         $this->record['s3_error_count']++;
         \XLite\Logger::getInstance()->log('Couldn\'t move image ' . $item->getPath() . ' (local file system to Amazon S3)', LOG_ERR);
     }
     return true;
 }
Пример #17
0
 /**
  * Return wrong permissions
  *
  * @return array
  */
 protected function getWrongPermissions()
 {
     if (!isset($this->wrongPermissions)) {
         $this->wrongPermissions = array('666' => array(), '777' => array());
         foreach ($this->getUpgradeEntries() as $entry) {
             foreach ($entry->getWrongPermissions() as $path) {
                 if (\Includes\Utils\FileManager::isDir($path)) {
                     $this->wrongPermissions['777'][] = $path;
                 } else {
                     $this->wrongPermissions['666'][] = $path;
                 }
             }
         }
         foreach ($this->wrongPermissions as $k => $v) {
             if ($v) {
                 $this->wrongPermissions[$k] = 'chmod ' . $k . ' ' . implode(' ', array_unique($v)) . ';';
             } else {
                 unset($this->wrongPermissions[$k]);
             }
         }
     }
     return $this->wrongPermissions;
 }
Пример #18
0
 /**
  * Update custom images
  *
  * @return void
  */
 protected function updateCustomImages()
 {
     $dir = \XLite\Module\XC\ThemeTweaker\Main::getThemeDir() . 'images' . LC_DS;
     if ($_FILES && $_FILES['new_images'] && $_FILES['new_images']['name']) {
         if (!\Includes\Utils\FileManager::isExists($dir)) {
             \Includes\Utils\FileManager::mkdirRecursive($dir);
         }
         if (\Includes\Utils\FileManager::isDirWriteable($dir)) {
             foreach ($_FILES['new_images']['name'] as $i => $data) {
                 \Includes\Utils\FileManager::moveUploadedFileByMultiple('new_images', $i, $dir);
             }
         } else {
             \XLite\Core\TopMessage::addError('The directory {{dir}} does not exist or is not writable.', array('dir' => $dir));
         }
     }
     $delete = \XLite\Core\Request::getInstance()->delete;
     if ($delete && is_array($delete)) {
         foreach ($delete as $file => $del) {
             if ($del) {
                 \Includes\Utils\FileManager::deleteFile($dir . $file);
             }
         }
     }
 }
Пример #19
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);
 }
Пример #20
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;
    }
Пример #21
0
 /**
  * Check if file exists and is readable
  *
  * @param string $file file to check
  *
  * @return bool
  */
 protected static function checkFile($file)
 {
     return \Includes\Utils\FileManager::isFileReadable($file);
 }
Пример #22
0
 /**
  * Show log file content
  *
  * @return void
  */
 protected function doActionViewLogFile()
 {
     $path = \XLite\Upgrade\Logger::getInstance()->getLastLogFile();
     if ($path) {
         header('Content-Type: text/plain', true);
         \Includes\Utils\Operator::flush(\Includes\Utils\FileManager::read($path));
         exit(0);
     } else {
         \XLite\Core\TopMessage::addWarning('Log files not found');
     }
 }
Пример #23
0
 /**
  * Save cell data
  *
  * @param string  $id       Cell id
  * @param mixed   $data     Cell data
  * @param integer $lifeTime Cell TTL OPTIONAL
  *
  * @return boolean
  */
 protected function doSave($id, $data, $lifeTime = 0)
 {
     $lifeTime = max(0, intval($lifeTime));
     if ($lifeTime) {
         $lifeTime += LC_START_TIME;
     }
     $lifeTime = strval($lifeTime);
     return \Includes\Utils\FileManager::write($this->getPathById($id), $this->header . str_repeat(' ', $this->ttlLength - strlen($lifeTime)) . $lifeTime . serialize($data));
 }
Пример #24
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;
 }
Пример #25
0
 /**
  * Return list of module directories which contain templates
  *
  * @return array
  */
 protected function getSkinDirs()
 {
     $result = array();
     foreach (\XLite\Core\Layout::getInstance()->getSkinsAll() as $interface => $tmp) {
         $result = array_merge($result, \XLite\Core\Layout::getInstance()->getSkinPaths($interface));
     }
     foreach ($result as $key => &$data) {
         $path = \Includes\Utils\ModulesManager::getRelativeDir($this->module->getAuthor(), $this->module->getName());
         $path = $data['fs'] . LC_DS . 'modules' . LC_DS . $path;
         if (\Includes\Utils\FileManager::isDirReadable($path)) {
             $data = $path;
         } else {
             unset($result[$key]);
         }
     }
     return array_values(array_unique($result));
 }
Пример #26
0
 /**
  * Restore database from common backup
  *
  * @return void
  * @access protected
  * @see    ____func_see____
  * @since  1.0.0
  */
 protected function doRestoreDb($path = null, $drop = true, $doNotAssert = false)
 {
     $message = '';
     $result = xlite_restore_sql_from_backup($path, false, $drop, $message);
     if (!$doNotAssert) {
         $this->assertTrue($result, $message);
     }
     \Includes\Utils\FileManager::copyRecursive(LC_DIR . '/.dev/tests/images', LC_DIR_IMAGES);
 }
Пример #27
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);
         }
     }
 }
Пример #28
0
 * DISCLAIMER
 *
 * Do not modify this file if you wish to upgrade X-Cart to newer versions
 * in the future. If you wish to customize X-Cart for your needs please
 * refer to http://www.x-cart.com/ for more information.
 *
 * @category  X-Cart 5
 * @author    Qualiteam software Ltd <*****@*****.**>
 * @copyright Copyright (c) 2011-2015 Qualiteam software Ltd <*****@*****.**>. All rights reserved
 * @license   http://www.x-cart.com/license-agreement.html X-Cart 5 License Agreement
 * @link      http://www.x-cart.com/
 */
return function () {
    // Loading data to the database from yaml file
    $yamlFile = __DIR__ . LC_DS . 'post_rebuild.yaml';
    if (\Includes\Utils\FileManager::isFileReadable($yamlFile)) {
        \XLite\Core\Database::getInstance()->loadFixturesFromYaml($yamlFile);
    }
    // Remove config
    $config = array('notifs', 'enable_init_order_notif', 'enable_init_order_notif_customer');
    foreach ($config as $name) {
        $model = \XLite\Core\Database::getRepo('XLite\\Model\\Config')->findOneBy(array('category' => 'Company', 'name' => $name));
        if ($model) {
            \XLite\Core\Database::getEM()->remove($model);
        }
    }
    $option = \XLite\Core\Database::getRepo('XLite\\Model\\Config')->findOneBy(array('category' => 'Company', 'name' => 'company_name'));
    if ($option) {
        $option->setOptionName('Company name');
        $option->setOptionComment('Changing the value of this or any other fields on this page will not affect the signature in your store\'s email notifications. The signature for notifications can be edited on the <a href="admin.php?target=notification_common">Headers & signatures</a> page.');
    }
Пример #29
0
 /**
  * Write PHP class to the files
  *
  * @param \Includes\Decorator\DataStructure\Graph\Classes $node   Current class node
  * @param \Includes\Decorator\DataStructure\Graph\Classes $parent Parent class node
  *
  * @return void
  */
 public static function writeClassFile(\Includes\Decorator\DataStructure\Graph\Classes $node, \Includes\Decorator\DataStructure\Graph\Classes $parent = null)
 {
     \Includes\Utils\FileManager::write(LC_DIR_CACHE_CLASSES . $node->getPath(), $node->getSource($parent));
 }
Пример #30
0
 /**
  * Get valid file system storage root
  *
  * @return string
  */
 protected function getStoreFileSystemRoot()
 {
     $path = parent::getStoreFileSystemRoot() . $this->getAttachment()->getProduct()->getProductId() . LC_DS;
     \Includes\Utils\FileManager::mkdirRecursive($path);
     return $path;
 }