Beispiel #1
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;
 }
Beispiel #2
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;
 }
Beispiel #3
0
 /**
  * Get schema
  *
  * @return array
  */
 public static function getDBSchema()
 {
     if (!isset(static::$schema)) {
         $path = static::getDBSchemaFilePath();
         if (\Includes\Utils\FileManager::isFileReadable($path)) {
             $content = \Includes\Utils\FileManager::read($path);
             if ($content) {
                 static::$schema = explode(';', $content);
             }
         }
     }
     return static::$schema;
 }
Beispiel #4
0
 /**
  * Get fixtures paths list
  *
  * @return array
  */
 public static function getFixtures()
 {
     if (!isset(static::$fixtures)) {
         static::$fixtures = array();
         $path = static::getFixturesFilePath();
         if (\Includes\Utils\FileManager::isFileReadable($path)) {
             foreach (parse_ini_file($path, false) as $file) {
                 if (static::checkFile($file)) {
                     static::$fixtures[] = $file;
                 }
             }
         }
     }
     return static::$fixtures;
 }
Beispiel #5
0
 /**
  * Perform upgrade
  *
  * @param boolean    $isTestMode       Flag OPTIONAL
  * @param array|null $filesToOverwrite List of custom files to overwrite OPTIONAL
  *
  * @return void
  */
 public function upgrade($isTestMode = true, $filesToOverwrite = null)
 {
     parent::upgrade($isTestMode, $filesToOverwrite);
     if (!$isTestMode) {
         list($author, $name) = explode('\\', $this->getActualName());
         if (!$this->isValid()) {
             \Includes\SafeMode::markModuleAsUnsafe($author, $name);
         }
         // Load fixtures
         if (!$this->isInstalled()) {
             $yaml = \Includes\Utils\ModulesManager::getModuleYAMLFile($author, $name);
             if (\Includes\Utils\FileManager::isFileReadable($yaml)) {
                 \XLite\Core\Database::getInstance()->loadFixturesFromYaml($yaml);
             }
         }
         $this->updateDBRecords();
     }
 }
Beispiel #6
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);
 }
Beispiel #7
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;
}
Beispiel #8
0
 /**
  * Overloaded constructor
  *
  * @param string $path Path to the module package
  *
  * @return void
  */
 public function __construct($path)
 {
     if (!\Includes\Utils\FileManager::isFileReadable($path)) {
         \Includes\ErrorHandler::fireError('Unable to read module package: "' . $path . '"');
     }
     $this->setRepositoryPath($path);
     $module = new \PharData($this->getRepositoryPath());
     $this->metadata = $module->getMetaData();
     if (empty($this->metadata)) {
         \Includes\ErrorHandler::fireError('Unable to read module metadata: "' . $path . '"');
     }
     parent::__construct();
 }
Beispiel #9
0
 /**
  * Execute a set of SQL queries from file
  *
  * :FIXME: must be completely revised
  *
  * @param string  $fileName Name of SQL-file
  * @param boolean $verbose  Display uploading progress flag OPTIONAL
  *
  * @return boolean
  */
 public static function uploadSQLFromFile($fileName, $verbose = false)
 {
     $result = false;
     if (false == \Includes\Utils\FileManager::isFileReadable($fileName)) {
         throw new \InvalidArgumentException(sprintf('SQL file \'%s\' not found or is not readable', $fileName));
     } else {
         $fp = fopen($fileName, 'rb');
         $sql = '';
         $result = true;
         while ($result && !feof($fp)) {
             $c = '';
             // Read SQL statement from file
             do {
                 $c .= fgets($fp, 1024);
                 $endPos = strlen($c) - 1;
             } while (substr($c, $endPos) != PHP_EOL && !feof($fp));
             $c = rtrim($c);
             // Skip comments
             if (substr($c, 0, 1) == '#' || substr($c, 0, 2) == '--') {
                 continue;
             }
             // Parse SQL statement
             $sql .= $c;
             if (substr($sql, -1) == ';') {
                 $sql = substr($sql, 0, strlen($sql) - 1);
                 // Execute SQL query
                 try {
                     static::getHandler()->beginTransaction();
                     $result = false !== static::exec($sql);
                     if ($result) {
                         static::getHandler()->commit();
                     } else {
                         static::getHandler()->rollBack();
                     }
                     if ($verbose) {
                         echo '.';
                         flush();
                     }
                 } catch (\PDOException $e) {
                     static::getHandler()->rollBack();
                     $result = false;
                     echo '<br />' . $e->getMessage();
                 }
                 $sql = '';
             }
         }
         fclose($fp);
     }
     return $result;
 }
Beispiel #10
0
 /**
  * Uninstall module
  *
  * @param \XLite\Model\Module $module    Module object
  * @param array               &$messages Messages list
  *
  * @return boolean
  */
 public function uninstallModule(\XLite\Model\Module $module, &$messages)
 {
     $result = false;
     // Get module pack
     $pack = new \XLite\Core\Pack\Module($module);
     $dirs = $pack->getDirs();
     $nonWritableDirs = array();
     // Check module directories permissions
     foreach ($dirs as $dir) {
         if (\Includes\Utils\FileManager::isExists($dir) && !\Includes\Utils\FileManager::isDirWriteable($dir)) {
             $nonWritableDirs[] = \Includes\Utils\FileManager::getRelativePath($dir, LC_DIR_ROOT);
         }
     }
     $params = array('name' => sprintf('%s v%s (%s)', $module->getModuleName(), $module->getVersion(), $module->getAuthorName()));
     if (empty($nonWritableDirs)) {
         $yamlData = array();
         $yamlFiles = \Includes\Utils\ModulesManager::getModuleYAMLFiles($module->getAuthor(), $module->getName());
         foreach ($yamlFiles as $yamlFile) {
             $yamlData[] = \Includes\Utils\FileManager::read($yamlFile);
         }
         if (!$module->checkModuleMainClass()) {
             $classFile = LC_DIR_CLASSES . \Includes\Utils\Converter::getClassFile($module->getMainClass());
             if (\Includes\Utils\FileManager::isFileReadable($classFile)) {
                 require_once $classFile;
             }
         }
         // Call uninstall event method
         $r = $module->callModuleMethod('callUninstallEvent', 111);
         if (111 == $r) {
             \XLite\Logger::getInstance()->log($module->getActualName() . ': Method callUninstallEvent() was not called');
         }
         // Remove from FS
         foreach ($dirs as $dir) {
             \Includes\Utils\FileManager::unlinkRecursive($dir);
         }
         \Includes\Utils\ModulesManager::disableModule($module->getActualName());
         \Includes\Utils\ModulesManager::removeModuleFromDisabledStructure($module->getActualName());
         // Remove module from DB
         try {
             // Refresh module entity as it was changed by disableModule() method above
             $module = $this->find($module->getModuleID());
             $this->delete($module);
         } catch (\Exception $e) {
             $messages[] = $e->getMessage();
         }
         if ($module->getModuleID()) {
             $messages[] = \XLite\Core\Translation::getInstance()->translate('A DB error occured while uninstalling the module X', $params);
         } else {
             if (!empty($yamlData)) {
                 foreach ($yamlData as $yaml) {
                     \XLite\Core\Database::getInstance()->unloadFixturesFromYaml($yaml);
                 }
             }
             $messages[] = \XLite\Core\Translation::getInstance()->translate('The module X has been uninstalled successfully', $params);
             $result = true;
         }
     } else {
         $messages[] = \XLite\Core\Translation::getInstance()->translate('Unable to delete module X files: some dirs have no writable permissions: Y', $params + array('dirs' => implode(', ', $nonWritableDirs)));
     }
     return $result;
 }
Beispiel #11
0
 /**
  * Make a css file compiled from the LESS files collection
  *
  * @param array $lessFiles LESS files structures array
  *
  * @return array
  */
 public function makeCSS($lessFiles)
 {
     $file = $this->makeLESSResourcePath($lessFiles);
     $path = $this->getCSSResource($lessFiles);
     $url = $this->getCSSResourceURL($path);
     $data = array('file' => $path, 'media' => 'screen', 'url' => $url);
     if ($this->needToCompileLessResource($lessFiles)) {
         try {
             $originalPath = $this->getCSSResource($lessFiles, true);
             if ($path != $originalPath && $this->getLESSResourceHash($lessFiles, true) && $this->getLESSResourceHash($lessFiles, true) == $this->calcLESSResourceHash($lessFiles) && \Includes\Utils\FileManager::isFileReadable($originalPath)) {
                 $content = \Includes\Utils\FileManager::read($originalPath);
             } else {
                 // Need recreate parser for every parseFile
                 $this->parser = new \Less_Parser($this->getLessParserOptions());
                 $this->parser->parseFile($file, '');
                 $this->parser->ModifyVars($this->getModifiedLESSVars($data));
                 $content = $this->prepareLESSContent($this->parser->getCss(), $path, $data);
                 $this->setLESSResourceHash($lessFiles);
             }
             \Includes\Utils\FileManager::mkdirRecursive(dirname($path));
             \Includes\Utils\FileManager::write($path, $content);
         } catch (\Exception $e) {
             \XLite\Logger::getInstance()->registerException($e);
             $data = null;
         }
     }
     return $data;
 }
Beispiel #12
0
 /**
  * Return current endpoint script
  *
  * @param boolean $check Check if file exists and readable (default: false)
  *s
  * @return string
  */
 public function getScript($check = false)
 {
     return static::isAdminZone() ? !$check || \Includes\Utils\FileManager::isFileReadable(static::getAdminScript()) ? static::getAdminScript() : self::ADMIN_SELF : (!$check || \Includes\Utils\FileManager::isFileReadable(static::getCustomerScript()) ? static::getCustomerScript() : self::CART_SELF);
 }
Beispiel #13
0
 /**
  * Check if class is already declared.
  * NOTE: this function does not use autoloader
  *
  * @param string $name Class name
  *
  * @return boolean
  */
 public static function checkIfClassExists($name)
 {
     $result = class_exists($name, false);
     if (!$result) {
         $result = \Includes\Utils\FileManager::isFileReadable(\Includes\Autoloader::getLCAutoloadDir() . \Includes\Utils\Converter::getClassFile($name));
     }
     return $result;
 }
Beispiel #14
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);
 }
Beispiel #15
0
 /**
  * Get unsafe modules list
  *
  * @param boolean $asPlainList Flag OPTIONAL
  *
  * @return array
  */
 public static function getUnsafeModulesList($asPlainList = true)
 {
     $list = array();
     $path = static::getUnsafeModulesFilePath();
     if (\Includes\Utils\FileManager::isFileReadable($path)) {
         foreach (parse_ini_file($path, true) as $author => $names) {
             foreach (array_filter($names) as $name => $flag) {
                 if ($asPlainList) {
                     $list[] = $author . '\\' . $name;
                 } else {
                     if (!isset($list[$author])) {
                         $list[$author] = array();
                     }
                     $list[$author][$name] = 1;
                 }
             }
         }
     }
     return $list;
 }
Beispiel #16
0
 /**
  * Add module's install.yaml file to the fixtures list file
  *
  * @param string $author Module author
  * @param string $name   Module name
  *
  * @return void
  */
 protected static function addModuleYamlFile($author, $name)
 {
     $dir = 'classes' . LC_DS . LC_NAMESPACE . LC_DS . 'Module' . LC_DS . $author . LC_DS . $name;
     $file = $dir . LC_DS . 'install.yaml';
     if (\Includes\Utils\FileManager::isFileReadable($file)) {
         \Includes\Decorator\Plugin\Doctrine\Utils\FixturesManager::addFixtureToList($file);
     }
     foreach ((array) glob($dir . LC_DS . 'install_*.yaml') as $translationFile) {
         if (\Includes\Utils\FileManager::isFileReadable($translationFile)) {
             \Includes\Decorator\Plugin\Doctrine\Utils\FixturesManager::addFixtureToList($translationFile);
         }
     }
 }
Beispiel #17
0
 * 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);
    }
    $statesFile = __DIR__ . LC_DS . 'regionForUkStates.yaml';
    if (\Includes\Utils\FileManager::isFileReadable($statesFile)) {
        $data = \Symfony\Component\Yaml\Yaml::parse($statesFile);
        $repo = \XLite\Core\Database::getRepo('XLite\\Model\\Country');
        if ($repo) {
            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);
                    }
                }
            }
        }
    }
Beispiel #18
0
 /**
  * Get public image URL
  *
  * @param string $image Image name
  *
  * @return string
  */
 public function getPublicImageURL($image)
 {
     if (!isset($this->imageURLCached[$image])) {
         $path = \Includes\Utils\ModulesManager::getModuleImageFile($this->getAuthor(), $this->getName(), $image);
         if (\Includes\Utils\FileManager::isFileReadable($path)) {
             $this->imageURLCached[$image] = \XLite\Core\Converter::buildURL('module', null, array('author' => $this->getAuthor(), 'name' => $this->getName(), 'image' => $image), 'image.php');
         } else {
             $this->imageURLCached[$image] = false;
         }
     }
     return $this->imageURLCached[$image];
 }
Beispiel #19
0
 /**
  * Check if file exists
  *
  * @param string  $path      Path to check OPTIONAL
  * @param boolean $forceFile Flag OPTIONAL
  *
  * @return boolean
  */
 public function isFileExists($path = null, $forceFile = false)
 {
     if ($this->isURL($path) && !$forceFile) {
         $request = new \XLite\Core\HTTP\Request($path ?: $this->getPath());
         $response = $request->sendRequest();
         $exists = 200 == $response->code && !empty($response->headers->ContentLength);
     } else {
         $exists = \Includes\Utils\FileManager::isFileReadable($path ?: $this->getStoragePath());
     }
     return $exists;
 }
Beispiel #20
0
 /**
  * Return file hashes for the currently installed version
  *
  * @param boolean $isTestMode Flag
  *
  * @return array
  */
 protected function getHashesForInstalledFiles($isTestMode)
 {
     if ($this->isInstalled()) {
         $path = $this->getCurrentVersionHashesFilePath();
         if (!\Includes\Utils\FileManager::isFileReadable($path)) {
             $message = 'Hash file for installed entry "{{entry}}" doesn\'t exist or is not readable';
         } else {
             require_once $path;
         }
         if (!empty($message)) {
             $this->addFileErrorMessage($message, $path, !$isTestMode);
         }
     }
     return empty($data) || !is_array($data) ? array() : $data;
 }
Beispiel #21
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.');
    }
 /**
  * Prepares JS cache to use
  *
  * @param array $resource Array with JS file data
  *
  * @return string
  */
 protected function prepareJSCache($resource)
 {
     $filePath = $resource['file'];
     $minFilePath = str_replace(LC_DIR_SKINS, static::getMinifiedCacheDir(static::RESOURCE_JS), $filePath);
     $minFilePath = dirname($minFilePath) . LC_DS . basename($minFilePath, '.js') . '.min.js';
     $minified = false;
     // Get file content
     if (\Includes\Utils\FileManager::isFileReadable($minFilePath)) {
         $data = \Includes\Utils\FileManager::read($minFilePath);
         $minified = true;
     } else {
         $data = \Includes\Utils\FileManager::read($filePath);
     }
     $noMinify = !empty($resource['no_minify']) || !empty($resource['no-minify']);
     if (!$minified && !$noMinify && strpos(basename($filePath), '.min.js') == false) {
         // Minify js content
         $data = $this->minifyJS($data, $filePath);
         \Includes\Utils\FileManager::write($minFilePath, $data);
     }
     $data = trim($data);
     $data = preg_replace('/\\)$/S', ');', $data);
     return $data ? PHP_EOL . '/* AUTOGENERATED: ' . basename($filePath) . ' */' . PHP_EOL . $data . ';' : '';
 }