Exemplo n.º 1
0
 /**
  * Execute certain hook handler
  *
  * @return void
  */
 public function executeHookHandler()
 {
     \XLite\Core\Translation::getInstance()->reset();
     \XLite\Core\Database::getEM()->flush();
     \XLite\Core\Translation::getInstance()->resetDriver();
     \XLite\Core\Translation::getInstance()->translateByString('label');
     \XLite\Core\Database::getRepo('XLite\\Model\\TmpVar')->setVar(\XLite::CACHE_TIMESTAMP, intval(microtime(true)));
 }
Exemplo n.º 2
0
 /**
  * Return list of product labels
  *
  * @param \XLite\Model\Product $product The product to look for
  *
  * @return array
  */
 protected function getLabels(\XLite\Model\Product $product)
 {
     $labels = parent::getLabels($product);
     if ($this->participateSale($product)) {
         $label = intval($product->getSalePercent()) . '% ' . \XLite\Core\Translation::getInstance()->translate('off');
         $labels += array('orange sale-price' => $label);
     }
     return $labels;
 }
Exemplo n.º 3
0
 /**
  * Constructor
  *
  * @return void
  */
 public function __construct()
 {
     $this->em = \XLite\Core\Database::getEM();
     $this->translation = \XLite\Core\Translation::getInstance();
     $entities = \XLite\Core\Database::getCacheDriver()->fetch('quickEntities');
     if (!is_array($entities) || !$entities) {
         foreach ($this->em->getMetadataFactory()->getAllMetadata() as $md) {
             if (!$md->isMappedSuperclass && preg_match('/^XLite\\\\(?:Module\\\\([a-z0-9]+)\\\\)?Model\\\\(.+)$/iSs', $md->name, $m)) {
                 $key = ($m[1] ? $m[1] . '\\' : '') . $m[2];
                 $entities[$key] = $md->name;
             }
         }
         \XLite\Core\Database::getCacheDriver()->save('quickEntities', $entities);
     }
     $this->entities = $entities;
 }
Exemplo n.º 4
0
 /**
  * Translate label 'X modules will be disabled'
  *
  * @param array $arguments Arguments
  *
  * @return string
  */
 public function translateLabelXModulesWillBeDisabled(array $arguments)
 {
     return 1 == $arguments['count'] ? \XLite\Core\Translation::getInstance()->translateByString('X module will be disabled', $arguments) : \XLite\Core\Translation::getInstance()->translateByString('X modules will be disabled', $arguments);
 }
Exemplo n.º 5
0
 /**
  * Get content of Free shipping label
  *
  * @return array
  */
 protected static function getLabelContent()
 {
     return array('blue free-shipping' => \XLite\Core\Translation::getInstance()->translate('FREE'));
 }
Exemplo n.º 6
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;
 }
Exemplo n.º 7
0
 /**
  * Language label translation short method
  *
  * @param string $name      Label name
  * @param array  $arguments Substitution arguments OPTIONAL
  * @param string $code      Language code OPTIONAL
  *
  * @return string
  */
 protected static function t($name, array $arguments = array(), $code = null)
 {
     return \XLite\Core\Translation::getInstance()->translate($name, $arguments, $code);
 }
Exemplo n.º 8
0
 /**
  * Get translation driver identifier
  *
  * @return string
  */
 public function getTranslationDriver()
 {
     return \XLite\Core\Translation::getInstance()->getDriver()->getName();
 }
Exemplo n.º 9
0
 /**
  * Get the "New!" label
  *
  * @param \XLite\Model\Product $product Current product
  *
  * @return array
  */
 public static function getLabels(\XLite\Model\Product $product)
 {
     $result = array();
     if ($product->isNewProduct() && \XLite\Core\Config::getInstance()->CDev->ProductAdvisor->na_mark_with_label) {
         $result[self::PA_MODULE_PRODUCT_LABEL_NEW] = \XLite\Core\Translation::getInstance()->translate('New!');
     }
     if ($product->isUpcomingProduct() && \XLite\Core\Config::getInstance()->CDev->ProductAdvisor->cs_mark_with_label) {
         $result[self::PA_MODULE_PRODUCT_LABEL_SOON] = \XLite\Core\Translation::getInstance()->translate('Coming soon');
     }
     return $result;
 }
Exemplo n.º 10
0
 /**
  * Perform certain action for the model object
  *
  * @return boolean
  */
 protected function performActionUpdate()
 {
     \XLite\Core\Database::getEM()->flush();
     \XLite\Core\Translation::getInstance()->reset();
     return true;
 }
Exemplo n.º 11
0
 /**
  * Get title
  *
  * @return string
  */
 protected function getHead()
 {
     return \XLite\Core\Translation::getInstance()->translate('Coming soon');
 }
Exemplo n.º 12
0
Arquivo: Main.php Projeto: kingsj/core
 /**
  * Get the "X% less" label
  *
  * @param \XLite\Model\Product $product Current product
  *
  * @return array
  */
 public static function getLabels(\XLite\Model\Product $product)
 {
     $result = array();
     $percent = static::getSaveDifferenceInPercents($product);
     if (0 < $percent) {
         $result['orange market-price'] = $percent . '% ' . \XLite\Core\Translation::getInstance()->translate('less');
     }
     return $result;
 }
Exemplo n.º 13
0
 /**
  * Get title
  *
  * @return string
  */
 protected function getHead()
 {
     return \XLite\Core\Translation::getInstance()->translate('New arrivals');
 }
Exemplo n.º 14
0
Arquivo: Rest.php Projeto: kingsj/core
 /**
  * Define REST repository classes
  *
  * @return array
  */
 protected function defineRESTClasses()
 {
     return array(\XLite\Core\Translation::getInstance(), 'XLite\\Model\\Product');
 }
Exemplo n.º 15
0
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the software license agreement
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.x-cart.com/license-agreement.html
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to licensing@x-cart.com so we can send you a copy immediately.
 *
 * 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-2014 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 new labels
    $yamlFile = __DIR__ . LC_DS . 'new_labels.yaml';
    if (\Includes\Utils\FileManager::isFileReadable($yamlFile)) {
        \XLite\Core\Translation::getInstance()->loadLabelsFromYaml($yamlFile);
    }
    \XLite\Core\Translation::getInstance()->reset();
};
Exemplo n.º 16
0
 /**
  * Define REST repository classes
  *
  * @return array
  */
 protected function defineRESTClasses()
 {
     return array(\XLite\Core\Translation::getInstance());
 }
Exemplo n.º 17
0
 /**
  * Active (add) language
  *
  * @return void
  */
 protected function doActionActive()
 {
     $id = intval(\XLite\Core\Request::getInstance()->lng_id);
     $language = \XLite\Core\Database::getRepo('\\XLite\\Model\\Language')->find($id);
     if (!$language) {
         \XLite\Core\TopMessage::addError('The language you want to add has not been found');
     } elseif ($language->added) {
         \XLite\Core\TopMessage::addError('The language you want to add has already been added');
     } else {
         $language->added = true;
         \XLite\Core\Database::getEM()->persist($language);
         \XLite\Core\Database::getEM()->flush();
         \XLite\Core\TopMessage::addInfo('The X language has been added successfully', array('language' => $language->name));
         \XLite\Core\Translation::getInstance()->reset();
     }
     $this->setReturnURL($this->buildURL('languages'));
 }
Exemplo n.º 18
0
 /**
  * Check if there is enough disk free space.
  * Return message on error
  *
  * @return string
  */
 protected function checkDiskFreeSpace()
 {
     $message = null;
     $totalSize = \Includes\Utils\ArrayManager::sumObjectsArrayFieldValues($this->getEntries(), 'getPackSize');
     $freeSpaceRaw = \Includes\Utils\FileManager::getDiskFreeSpace(LC_DIR_TMP);
     $freeSpace = null !== $freeSpaceRaw ? max(0, $freeSpaceRaw - self::FREE_SPACE_RESERVE) : null;
     if (null !== $freeSpace && $totalSize > $freeSpace) {
         $message = \XLite\Core\Translation::getInstance()->translate('Not enough disk space. Required: {{req}} (+{{reserve}} reserve). Available: {{avail}}', array('req' => \XLite\Core\Converter::formatFileSize($totalSize), 'reserve' => \XLite\Core\Converter::formatFileSize(self::FREE_SPACE_RESERVE), 'avail' => \XLite\Core\Converter::formatFileSize($freeSpace)));
     }
     return $message;
 }
Exemplo n.º 19
0
 /**
  * Common method to manage entry packages
  *
  * @param boolean $isUnpack Operation type
  *
  * @return boolean
  */
 protected function manageEntryPackages($isUnpack)
 {
     $cntProcessed = 0;
     $cntTotal = 0;
     $success = true;
     $entries = $this->getEntries();
     foreach ($entries as $entry) {
         $cntTotal++;
         $skip = $isUnpack ? $entry->isUnpacked() : $entry->isDownloaded();
         if (!$skip) {
             if ($isUnpack) {
                 $entry->unpack();
                 $success = $entry->isUnpacked();
                 \Includes\Utils\Operator::showMessage(\XLite\Core\Translation::getInstance()->translate('...Unpacking {{entry}}...{{status}}', array('entry' => addslashes($entry->getActualName()), 'status' => $success ? 'OK' : 'Failed')));
             } else {
                 $entry->download();
                 $success = $entry->isDownloaded();
                 \Includes\Utils\Operator::showMessage(\XLite\Core\Translation::getInstance()->translate('...Downloading {{entry}}...{{status}}', array('entry' => addslashes($entry->getActualName()), 'status' => $success ? 'OK' : 'Failed')));
             }
             if ($success) {
                 $cntProcessed++;
                 if ($this->isEntryOperationLimitReached($cntProcessed, $isUnpack)) {
                     break;
                 }
             } else {
                 break;
             }
         }
     }
     return $success && (count($entries) > $cntTotal || ($isUnpack ? $this->isUnpacked() : $this->isDownloaded()));
 }
Exemplo n.º 20
0
 /**
  * Add new error message
  *
  * @param string  $message Message to add
  * @param boolean $log     Flag
  * @param array   $args    Substitution arguments OPTIONAL
  *
  * @return void
  */
 protected function addErrorMessage($message, $log, array $args = array())
 {
     $this->addMessage('Error', $message, $log, $args);
     // Add message to the internal array
     $this->errorMessages[] = \XLite\Core\Translation::getInstance()->translate($message, $args);
 }
Exemplo n.º 21
0
 /**
  * Get 'More...' link text for New arrivals list
  *
  * @return string
  */
 protected function getMoreLinkText()
 {
     return \XLite\Core\Translation::getInstance()->translate('All upcoming products');
 }
Exemplo n.º 22
0
 /**
  * Get type name 
  * 
  * @return string
  */
 public function getTypeName()
 {
     return isset(static::$typeNames[$this->getType()]) ? \XLite\Core\Translation::getInstance()->translate(static::$typeNames[$this->getType()]) : null;
 }
Exemplo n.º 23
0
 /**
  * Save labels from array
  *
  * @param array  $values Array
  * @param string $code   Language code
  *
  * @return void
  */
 protected function saveLabels(array $values, $code)
 {
     $labels = \XLite\Core\Database::getRepo('\\XLite\\Model\\LanguageLabel')->findByIds(array_keys($values));
     $list = array();
     foreach ($labels as $label) {
         if (!empty($values[$label->getLabelId()])) {
             $label->setEditLanguage($code)->setLabel($values[$label->getLabelId()]);
             $list[] = $label;
         } elseif ($label->hasTranslation($code)) {
             $translation = $label->getTranslation($code);
             $label->getTranslations()->removeElement($translation);
             \XLite\Core\Database::getRepo('\\XLite\\Model\\LanguageLabelTranslation')->delete($translation, false);
             $list[] = $label;
         }
     }
     \XLite\Core\Translation::getInstance()->reset();
     \XLite\Core\Database::getRepo('\\XLite\\Model\\LanguageLabel')->updateInBatch($list);
 }
Exemplo n.º 24
0
 /**
  * Orders collect garbage
  *
  * @return void
  */
 public function collectGarbage()
 {
     // Remove old temporary orders
     $list = $this->findAllExpiredTemporaryOrders();
     if (count($list)) {
         foreach ($list as $order) {
             \XLite\Core\Database::getEM()->remove($order);
         }
         \XLite\Core\Database::getEM()->flush();
         // Log operation only in debug mode
         \XLite\Logger::getInstance()->log(\XLite\Core\Translation::getInstance()->translate('X expired shopping cart(s) have been successfully removed', array('count' => count($list))));
     }
 }
Exemplo n.º 25
0
Arquivo: Role.php Projeto: kingsj/core
 /**
  * Return the current page title (for the content area)
  *
  * @return string
  */
 public function getTitle()
 {
     $model = $this->getModelForm()->getModelObject();
     return $model && $model->getId() ? $model->getPublicName() : \XLite\Core\Translation::getInstance()->lbl('Role');
 }
Exemplo n.º 26
0
Arquivo: Main.php Projeto: kingsj/core
 /**
  * Decorator run this method at the end of cache rebuild
  *
  * @return void
  */
 public static function runBuildCacheHandler()
 {
     $language = \XLite\Core\Database::getRepo('\\XLite\\Model\\Language')->findOneByCode(static::LANG_CODE);
     if (isset($language)) {
         if (!$language->getEnabled()) {
             $language->setEnabled(true);
             \XLite\Core\Database::getRepo('\\XLite\\Model\\Language')->update($language);
             \XLite\Core\TopMessage::addInfo('The X language has been added and enabled successfully', array('language' => $language->getName()), $language->getCode());
         }
         \XLite\Core\Translation::getInstance()->reset();
     } else {
         \XLite\Core\TopMessage::addError('The language you want to add has not been found');
     }
 }
Exemplo n.º 27
0
 /**
  * Parse import CSV file and return array of the parsing result
  *
  * @param string $path Import file path
  *
  * @return array
  */
 public function parseImportFile($path, $forceImport = false)
 {
     set_time_limit(0);
     $startTime = microtime(true);
     if ($forceImport || !isset(static::$importData[$path])) {
         $codes = array();
         $ignored = 0;
         $isUpdated = false;
         $languages = array();
         $rows = array();
         $f = fopen($path, 'r');
         if ($f) {
             $fields = static::getImportLanguageFields();
             while (false !== ($data = fgetcsv($f, 0, ','))) {
                 $row = array();
                 $error = false;
                 // Generate associative array of the row data
                 foreach ($data as $id => $col) {
                     $row[$fields[$id]] = $col;
                 }
                 if (empty($row) || count($row) != count($fields)) {
                     // Increase the counter of ignored rows
                     $error = true;
                 } elseif (2 != strlen($row[static::LNG_IMPORT_FIELD_CODE])) {
                     // Wrong language code format
                     $error = true;
                 } elseif (empty($row[static::LNG_IMPORT_FIELD_NAME])) {
                     // Empty label name
                     $error = true;
                 } else {
                     // Cast language code to the lower case
                     $row[static::LNG_IMPORT_FIELD_CODE] = strtolower($row[static::LNG_IMPORT_FIELD_CODE]);
                     // Check if language with specified code exists
                     if (!isset($languages[$row[static::LNG_IMPORT_FIELD_CODE]])) {
                         $lng = \XLite\Core\Database::getRepo('XLite\\Model\\Language')->findOneBy(array('code' => $row[static::LNG_IMPORT_FIELD_CODE]));
                         $languages[$row[static::LNG_IMPORT_FIELD_CODE]] = $lng;
                         if ($forceImport && $lng && !$lng->getAdded()) {
                             // Activate inactive language
                             $lng->setAdded(true);
                         }
                     }
                 }
                 if (!$error && $languages[$row[static::LNG_IMPORT_FIELD_CODE]]) {
                     if (!isset($codes[$row[static::LNG_IMPORT_FIELD_CODE]]['language'])) {
                         $codes[$row[static::LNG_IMPORT_FIELD_CODE]] = array('language' => $languages[$row[static::LNG_IMPORT_FIELD_CODE]]->getName(), 'count' => 0);
                     }
                     // Count labels by specific language code
                     $codes[$row[static::LNG_IMPORT_FIELD_CODE]]['count']++;
                     if ($forceImport) {
                         // Import row data
                         if (static::LNG_IMPORT_BATCH_LIMIT == count($rows)) {
                             $this->updateLanguageLabel($rows);
                             $rows = array();
                         } else {
                             $rows[] = $row;
                         }
                         $isUpdated = true;
                     }
                 } else {
                     // Unknown language code - ignore row
                     $ignored++;
                 }
             }
             // while (...
             if (!empty($rows)) {
                 $this->updateLanguageLabel($rows);
                 $isUpdated = true;
             }
             if ($isUpdated) {
                 \XLite\Core\Translation::getInstance()->reset();
             }
         }
         fclose($f);
         $s = microtime(true) - $startTime;
         $si = intval($s);
         $sf = substr((string) $s - $si, 1, 4);
         $elapsed = sprintf("%d:%02d:%02d%s", $s1 = intval($si / 3600), $s2 = intval(($si - $s1 * 3600) / 60), $si - $s1 * 3600 - $s2 * 60, $sf);
         static::$importData[$path] = array('codes' => $codes, 'ignored' => $ignored, 'elapsed' => $elapsed);
     }
     return static::$importData[$path];
 }
Exemplo n.º 28
0
 /**
  * Get title
  *
  * @return string
  */
 protected function getHead()
 {
     return \XLite\Core\Translation::getInstance()->translate('Customers who bought this product also bought');
 }
Exemplo n.º 29
0
 /**
  * Get title
  *
  * @return string
  */
 protected function getHead()
 {
     return \XLite\Core\Translation::getInstance()->translate('Recently viewed');
 }