示例#1
0
 /**
  * Retrieve the list of shipping methods of installed shipping modules
  *
  * @static
  * @return array
  */
 public static function getMethodNames()
 {
     if ($methods = Axis::cache()->load('shipping_methods_list')) {
         return $methods;
     }
     $prefix = 'Shipping';
     $modules = Axis::app()->getModules();
     $methods = array();
     foreach ($modules as $code => $path) {
         list($namespace, $moduleName) = explode('_', $code);
         if (substr($moduleName, 0, strlen($prefix)) != $prefix) {
             continue;
         }
         $dir = opendir($path . '/Model');
         while ($fname = readdir($dir)) {
             if (!is_file("{$path}/Model/{$fname}")) {
                 continue;
             }
             list($methodName, $ext) = explode('.', $fname, 2);
             if ($ext != 'php') {
                 continue;
             }
             $methods[$code . '/' . $methodName] = substr($moduleName, strlen($prefix)) . '_' . $methodName;
         }
         closedir($dir);
     }
     Axis::cache()->save($methods, 'shipping_methods_list', array('modules'));
     return $methods;
 }
示例#2
0
 /**
  * Retrieve the list of all boxes, including active cms boxes
  *
  * @param bool $includeCms
  * @return array
  */
 public function getList($includeCms = true)
 {
     $modules = Axis::single('core/module')->getList();
     if (!($boxes = Axis::cache()->load('boxes_list'))) {
         $boxes = array();
         foreach ($modules as $moduleCode => $values) {
             list($namespace, $module) = explode('_', $moduleCode, 2);
             $path = Axis::config()->system->path . '/app/code/' . $namespace . '/' . $module . '/Box';
             if (!is_readable($path)) {
                 continue;
             }
             $dir = opendir($path);
             while ($file = readdir($dir)) {
                 if (!is_readable($path . '/' . $file) || !is_file($path . '/' . $file)) {
                     continue;
                 }
                 $box = substr($file, 0, strpos($file, '.'));
                 if (in_array($box, array('Abstract', 'Block'))) {
                     continue;
                 }
                 $boxes[] = ucwords($namespace . '_' . $module . '_' . $box);
             }
         }
         Axis::cache()->save($boxes, 'boxes_list', array('modules'));
     }
     /* this part is not needed to be cached */
     if ($includeCms && in_array('Axis_Cms', array_keys($modules))) {
         $cmsBoxes = Axis::model('cms/block')->select('*')->where('is_active = 1')->fetchAll();
         foreach ($cmsBoxes as $box) {
             $boxes[] = 'Axis_Cms_Block_' . $box['name'];
         }
     }
     sort($boxes);
     return $boxes;
 }
示例#3
0
 /**
  *
  * @param string $methodName
  * @param array $arguments
  * @return mixed
  */
 public function __call($methodName, $arguments)
 {
     $cacheBool1 = $this->_cacheByDefault;
     $cacheBool2 = in_array($methodName, $this->_cachableMethods);
     $cacheBool3 = in_array($methodName, $this->_nonCachedMethods);
     $cache = ($cacheBool1 || $cacheBool2) && !$cacheBool3;
     $box = $this->_getBox();
     if (!$cache) {
         // We do not have not cache
         return call_user_func_array(array($box, $methodName), $arguments);
     }
     /** Get cache instance */
     $cache = Axis::cache();
     $id = $this->_makeId($methodName, $arguments);
     if ($cache->test($id)) {
         // A cache is available
         $result = $cache->load($id);
         $output = $result[0];
         $return = $result[1];
         $box->setFromArray($result[2]);
         //<---
     } else {
         // A cache is not available
         ob_start();
         ob_implicit_flush(false);
         $return = call_user_func_array(array($box, $methodName), $arguments);
         $output = ob_get_contents();
         ob_end_clean();
         $data = array($output, $return, $box->getCacheData());
         //<---
         $cache->save($data, $id, array_merge($this->_tags, array('boxes')), $this->_specificLifetime, $this->_priority);
     }
     echo $output;
     return $return;
 }
示例#4
0
 /**
  *
  * @param string $key
  * @param int $siteId[optional]
  * @return array
  */
 public function getFieldsByKey($key, $siteId = 1)
 {
     $hasCache = (bool) Zend_Registry::isRegistered('cache') ? Axis::cache() instanceof Zend_Cache_Core : false;
     if (!$hasCache || !($fields = Axis::cache()->load("config_{$key}_site_{$siteId}"))) {
         $fields = $this->select(array('path', 'config_type', 'model'))->joinInner('core_config_value', 'ccv.config_field_id = ccf.id', 'value')->where('ccf.path LIKE ?', $key . '/%')->where('ccv.site_id IN(?)', array(0, $siteId))->fetchAssoc();
         if ($hasCache) {
             Axis::cache()->save($fields, "config_{$key}_site_{$siteId}", array('config'));
         }
     }
     return $fields;
 }
示例#5
0
 public function render()
 {
     if (!($navigationHtml = Axis::cache()->load($this->getCacheKey()))) {
         $this->_items = array();
         // forward fix
         Axis::dispatch('admin_box_navigation_prepare', $this);
         $this->menu = new Zend_Navigation($this->_items);
         $navigationHtml = parent::render();
         Axis::cache()->save($navigationHtml, $this->getCacheKey(), array('modules'));
     }
     return $navigationHtml;
 }
示例#6
0
 protected function _initCache()
 {
     $frontendOptions = array('lifetime' => 864000, 'automatic_serialization' => true);
     $cacheDir = AXIS_ROOT . '/var/cache';
     if (!is_readable($cacheDir)) {
         mkdir($cacheDir, 0777);
     } elseif (!is_writable($cacheDir)) {
         chmod($cacheDir, 0777);
     }
     if (!is_writable($cacheDir)) {
         echo "Cache directory should be writable. Run 'chmod -R 0777 AXIS_ROOT/var'";
         exit;
     }
     $backendOptions = array('cache_dir' => $cacheDir, 'hashed_directory_level' => 1, 'file_name_prefix' => 'axis_cache', 'hashed_directory_umask' => 0777);
     Zend_Registry::set('cache', Zend_Cache::factory('Core', 'Zend_Cache_Backend_File', $frontendOptions, $backendOptions, false, true));
     return Axis::cache();
 }
示例#7
0
 /**
  * Current module
  *
  * @param  array $options
  */
 public function __construct($options = array())
 {
     if (Axis_Area::isInstaller() || !Axis::config('core/translation/autodetect')) {
         self::setCache(Axis::cache());
     }
     $this->_module = $options['module'];
     $locale = $this->getLocale();
     $filename = $this->_getFileName($locale);
     if (!is_readable($filename)) {
         $locale = Axis_Locale::DEFAULT_LOCALE;
         $filename = $this->_getFileName($locale);
     }
     // custom modules can be without translation for default locale
     if (!is_readable($filename)) {
         $filename = $this->_getSafeFileName();
     }
     parent::__construct(array('adapter' => self::AN_CSV, 'content' => $filename, 'locale' => $locale, 'delimiter' => ','));
 }
示例#8
0
 /**
  * Reads the event config from modules configuration
  * and cache it
  */
 private function __construct()
 {
     if ($result = Axis::cache()->load('module_event_list')) {
         $this->_events = $result;
     } else {
         foreach (Axis::single('core/module')->getConfig() as $code => $config) {
             if (isset($config['events']) && is_array($config['events'])) {
                 foreach ($config['events'] as $eventName => $action) {
                     foreach ($action as $key => $value) {
                         if (!is_array($value) || !count($value)) {
                             continue;
                         }
                         $this->_events[$eventName][] = $value;
                     }
                 }
             }
         }
         Axis::cache()->save($this->_events, 'module_event_list', array('modules'));
     }
 }
示例#9
0
 private function _load($key, $siteId, $default)
 {
     if (null === $siteId) {
         $siteId = Axis::getSiteId();
     }
     $hasCache = (bool) Zend_Registry::isRegistered('cache') ? Axis::cache() instanceof Zend_Cache_Core : false;
     if (!$hasCache || !($dataset = Axis::cache()->load("config_{$key}_site_{$siteId}"))) {
         $dataset = Axis::single('core/config_field')->select(array('path', 'model'))->joinInner('core_config_value', 'ccv.config_field_id = ccf.id', 'value')->where('ccf.path LIKE ?', $key . '/%')->where('ccv.site_id IN(?)', array(0, $siteId))->fetchAssoc();
         if ($hasCache) {
             Axis::cache()->save($dataset, "config_{$key}_site_{$siteId}", array('config'));
         }
     }
     if (!sizeof($dataset)) {
         $this->_data[$key] = $default;
         return;
     }
     $values = array();
     foreach ($dataset as $path => $data) {
         $parts = explode('/', $path);
         $value = $data['value'];
         if (!empty($data['model'])) {
             $class = Axis::getClass($data['model']);
             if (class_exists($class) && in_array('Axis_Config_Option_Encodable_Interface', class_implements($class))) {
                 $value = Axis::single($data['model'])->decode($value);
             }
         }
         $values[$parts[0]][$parts[1]][$parts[2]] = $value;
     }
     foreach ($values as $key => $value) {
         if (is_array($value)) {
             $this->_data[$key] = new self($value, $this->_allowModifications);
         } else {
             $this->_data[$key] = $value;
         }
     }
 }
示例#10
0
 /**
  * Retrieve the list of paymetns methods of installed payment modules
  * @return array
  */
 public static function getMethodNames()
 {
     if ($methods = Axis::cache()->load('payment_methods_list')) {
         return $methods;
     }
     $prefix = 'Payment';
     $modules = Axis::app()->getModules();
     $methods = array();
     foreach ($modules as $code => $path) {
         list($namespace, $moduleName) = explode('_', $code);
         if (substr($moduleName, 0, strlen($prefix)) != $prefix) {
             continue;
         }
         if (!is_dir($path . '/Model')) {
             continue;
         }
         $dir = opendir($path . '/Model');
         while ($fname = readdir($dir)) {
             if (!is_file("{$path}/Model/{$fname}")) {
                 continue;
             }
             list($methodName, $ext) = explode('.', $fname, 2);
             if ($ext != 'php' || $methodName == 'Abstract') {
                 continue;
             }
             $className = $code . '_Model_' . $methodName;
             if (!in_array('Axis_Method_Payment_Model_Abstract', class_parents($className))) {
                 continue;
             }
             $methods[$code . '/' . $methodName] = substr($moduleName, strlen($prefix)) . '_' . $methodName;
         }
         closedir($dir);
     }
     Axis::cache()->save($methods, 'payment_methods_list', array('modules'));
     return $methods;
 }
示例#11
0
 /**
  * Return list of order totals
  *
  * @return array
  */
 protected function _getMethodNames()
 {
     if ($methods = Axis::cache()->load('order_total_methods')) {
         return $methods;
     }
     $dirPath = realpath(Axis::config()->system->path . '/app/code/Axis/Checkout/Model/Total');
     $methods = array();
     $skip = array('Abstract');
     $dp = opendir($dirPath);
     while ($fname = readdir($dp)) {
         if (!is_file("{$dirPath}/{$fname}")) {
             continue;
         }
         list($name, $ext) = explode('.', $fname, 2);
         if (in_array($name, $skip) || $ext != 'php') {
             continue;
         }
         $methods[] = $name;
     }
     closedir($dp);
     Axis::cache()->save($methods, 'order_total_methods', array('modules'));
     return $methods;
 }
示例#12
0
 /**
  * Return Zend_Currency object
  *
  * @param string $code
  * @return Zend_Currency
  */
 public function getCurrency($code = '')
 {
     if (empty($code)) {
         $code = $this->getCode();
     }
     if (!isset($this->_currency[$code])) {
         $options = $this->_getCurrencyOptions($code);
         Zend_Currency::setCache(Axis::cache());
         try {
             $currency = new Zend_Currency($options['currency'], $options['format'] === null ? Axis_Locale::getLocale() : $options['format']);
         } catch (Zend_Currency_Exception $e) {
             Axis::message()->addError($e->getMessage() . ": " . Axis::translate('locale')->__("Try to change the format of this currency to English (United States) - en_US"));
             $options = $this->_getSystemSafeCurrencyOptions();
             $currency = new Zend_Currency($options['currency'], $options['format']);
         }
         $currency->setFormat($options);
         $this->_currency[$code] = $currency;
     }
     return $this->_currency[$code];
 }
示例#13
0
 public function __construct()
 {
     if ($this->_resources = Axis::cache()->load('axis_acl_resources')) {
         return;
     }
     foreach (Axis::app()->getModules() as $moduleName => $path) {
         if ('Axis_Admin' === $moduleName) {
             $path = $path . '/controllers';
         } else {
             $path = $path . '/controllers/Admin';
         }
         if (!is_dir($path)) {
             continue;
         }
         foreach ($this->_scanDirectory($path) as $file) {
             if (strstr($file, "Controller.php") == false) {
                 continue;
             }
             include_once $file;
         }
     }
     $resource = 'admin';
     $resources = array($resource);
     $camelCaseToDash = new Zend_Filter_Word_CamelCaseToDash();
     foreach (get_declared_classes() as $class) {
         if (!is_subclass_of($class, 'Axis_Admin_Controller_Back')) {
             continue;
         }
         list($module, $controller) = explode('Admin_', $class, 2);
         $module = rtrim($module, '_');
         if (empty($module)) {
             $module = 'Axis_Core';
         } elseif ('Axis' === $module) {
             $module = 'Axis_Admin';
         }
         $module = strtolower($camelCaseToDash->filter($module));
         list($namespace, $module) = explode('_', $module, 2);
         $resource .= '/' . $namespace;
         $resources[$resource] = $resource;
         $resource .= '/' . $module;
         $resources[$resource] = $resource;
         $controller = substr($controller, 0, strpos($controller, "Controller"));
         $controller = strtolower($camelCaseToDash->filter($controller));
         $resource .= '/' . $controller;
         $resources[$resource] = $resource;
         foreach (get_class_methods($class) as $action) {
             if (false == strstr($action, "Action")) {
                 continue;
             }
             $action = substr($action, 0, strpos($action, 'Action'));
             $action = strtolower($camelCaseToDash->filter($action));
             //                $resources[$namespace][$module][$controller][] = $action;
             $resources[$resource . '/' . $action] = $resource . '/' . $action;
         }
         $resource = 'admin';
     }
     asort($resources);
     Axis::cache()->save($resources, 'axis_acl_resources', array('modules'));
     $this->_resources = $resources;
 }
示例#14
0
 /**
  * Retrieve array of paths to route files
  *
  * @return array
  */
 public function getRoutes()
 {
     if (!($routes = Axis::cache()->load('routes_list'))) {
         $modules = $this->getModules();
         $routes = array();
         foreach ($modules as $moduleCode => $path) {
             if (file_exists($path . '/etc/routes.php') && is_readable($path . '/etc/routes.php')) {
                 $routes[] = $path . '/etc/routes.php';
             }
         }
         Axis::cache()->save($routes, 'routes_list', array('modules'));
     }
     return $routes;
 }
示例#15
0
 protected function _initCache()
 {
     $this->bootstrap('DbAdapter');
     //create default cache
     $cache = Axis_Core_Model_Cache::getCache();
     //create database metacache
     Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
     //        /**
     //         * Zend_View acceleration
     //         * http://www.web-blog.org.ua/articles/uskoryaem-zend-view
     //         */
     //        $cacheDir = Axis::config()->system->path . '/var/PluginLoader/';
     //        if (!is_readable($cacheDir)) {
     //            mkdir($cacheDir, 0777);
     //        } elseif(!is_writable($cacheDir)) {
     //            chmod($cacheDir, 0777);
     //        }
     //        require_once 'Zend/Loader/PluginLoader.php';
     //        $classFileIncCache = $cacheDir . 'cache.php';
     //        if (file_exists($classFileIncCache))  {
     //            include_once $classFileIncCache;
     //        } else {
     //            file_put_contents($classFileIncCache, "<?php\n");
     //        }
     //        Zend_Loader_PluginLoader::setIncludeFileCache($classFileIncCache);
     return Axis::cache();
 }
示例#16
0
 /**
  * Retrieve the list of available admin intrerface tranlations
  *
  * @static
  * @return array
  */
 public static function getAdminLocales()
 {
     if (!($locales = Axis::cache()->load('locales_list'))) {
         $path = Axis::config()->system->path . '/app/locale';
         try {
             $locales_dir = new DirectoryIterator($path);
         } catch (Exception $e) {
             throw new Axis_Exception("Directory {$path} not readable");
         }
         $locale = Axis_Locale::getLocale();
         $locales = array();
         foreach ($locales_dir as $localeDir) {
             $localeCode = $localeDir->getFilename();
             if ($localeCode[0] == '.' || !strstr($localeCode, '_')) {
                 continue;
             }
             list($language, $country) = explode('_', $localeCode, 2);
             $language = $locale->getTranslation($language, 'language', $localeCode);
             $country = $locale->getTranslation($country, 'country', $localeCode);
             if (!$language) {
                 $language = $locale->getTranslation($language, 'language', Axis_Locale::DEFAULT_LOCALE);
             }
             if (!$country) {
                 $country = $locale->getTranslation($country, 'country', Axis_Locale::DEFAULT_LOCALE);
             }
             $locales[$localeCode] = ucfirst($language) . ' (' . $country . ')';
         }
         ksort($locales);
         Axis::cache()->save($locales, 'locales_list', array('locales'));
     }
     return $locales;
 }
示例#17
0
 /**
  * Retrieve the config of all modules, or one of module if required
  *
  * @param string $module [optional]
  * @return mixed(array|boolean)
  */
 public function getConfig($module = null)
 {
     if (null === $module) {
         if (!($result = Axis::cache()->load('axis_modules_config'))) {
             $modules = Axis::app()->getModules();
             $result = array();
             foreach ($modules as $moduleCode => $path) {
                 if (file_exists($path . '/etc/config.php') && is_readable($path . '/etc/config.php')) {
                     include_once $path . '/etc/config.php';
                     if (!isset($config)) {
                         continue;
                     }
                     $result += $config;
                 }
             }
             Axis::cache()->save($result, 'axis_modules_config', array('modules'));
         }
         $config = $result;
     } else {
         list($namespace, $module) = explode('_', $module, 2);
         $configFile = Axis::config()->system->path . '/app/code/' . $namespace . '/' . $module . '/etc/config.php';
         if (!is_file($configFile)) {
             return false;
         }
         include $configFile;
         if (!isset($config)) {
             return false;
         }
     }
     return $config;
 }
示例#18
0
 /**
  * Saves output to the cache
  *
  * @return void
  */
 protected function _setCachedOutput($data)
 {
     if (0 === $this->_getCacheLifetime()) {
         return false;
     }
     Axis::cache()->save($data, $this->_getCacheKey(), $this->_getCacheTags(), $this->_getCacheLifetime());
 }