Пример #1
0
 public function init()
 {
     if (null === $this->_cache) {
         $options = $this->getOptions();
         if (!isset($options[0]) && $options) {
             if (!isset($options['frontend']['adapter'])) {
                 $options['frontend']['adapter'] = 'Core';
             }
             if (!isset($options['backend']['adapter'])) {
                 $options['backend']['adapter'] = 'Memcached';
             }
             if (!isset($options['frontend']['params'])) {
                 $options['frontend']['params'] = array();
             }
             if (!isset($options['backend']['params'])) {
                 $options['backend']['params'] = array();
             }
             $this->_cache = Zend_Cache::factory($options['frontend']['adapter'], $options['backend']['adapter'], $options['frontend']['params'], $options['backend']['params']);
             if (isset($options['metadata']) && true === (bool) $options['metadata']) {
                 Zend_Db_Table_Abstract::setDefaultMetadataCache($this->_cache);
             }
             if (isset($options['translate']) && true === (bool) $options['translate']) {
                 Zend_Translate::setCache($this->_cache);
             }
             if (isset($options['locale']) && true === (bool) $options['locale']) {
                 Zend_Locale::setCache($this->_cache);
             }
         } else {
             $this->_cache = false;
         }
         $key = isset($options['registry']) && !is_numeric($options['registry']) ? $options['registry'] : self::DEFAULT_REGISTRY_KEY;
         Zend_Registry::set($key, $this->_cache);
     }
     return $this->_cache;
 }
Пример #2
0
 /**
  * @param \HumusMvc\MvcEvent $e
  * @return void
  */
 public function __invoke(MvcEvent $e)
 {
     $serviceManager = $e->getApplication()->getServiceManager();
     $config = $serviceManager->get('Config');
     if (!isset($config['locale'])) {
         // no locale config found, return
         return;
     }
     // set cache in locale to speed up application
     if ($serviceManager->has('CacheManager')) {
         $cacheManager = $serviceManager->get('CacheManager');
         Locale::setCache($cacheManager->getCache('default'));
     }
     $options = $config['locale'];
     if (!isset($options['default'])) {
         $locale = new Locale();
     } elseif (!isset($options['force']) || (bool) $options['force'] == false) {
         // Don't force any locale, just go for auto detection
         Locale::setDefault($options['default']);
         $locale = new Locale();
     } else {
         $locale = new Locale($options['default']);
     }
     $key = isset($options['registry_key']) && !is_numeric($options['registry_key']) ? $options['registry_key'] : self::DEFAULT_REGISTRY_KEY;
     Registry::set($key, $locale);
 }
Пример #3
0
 public function setUp()
 {
     require_once 'Zend/Cache.php';
     $cache = Zend_Cache::factory('Core', 'File',
              array('lifetime' => 120, 'automatic_serialization' => true),
              array('cache_dir' => dirname(__FILE__) . '/_files/'));
     Zend_Locale::setCache($cache);
 }
Пример #4
0
 protected function _initCache()
 {
     $aFrontendConf = array('lifetime' => 345600, 'automatic_seralization' => true);
     $aBackendConf = array('cache_dir' => APPLICATION_PATH . '/../tmp/');
     $oCache = Zend_Cache::factory('Core', 'File', $aFrontendConf, $aBackendConf);
     $oCache->setOption('automatic_serialization', true);
     Zend_Locale::setCache($oCache);
 }
Пример #5
0
 protected function _initCache()
 {
     $frontendOptions = array('lifetime' => 7200, 'automatic_serialization' => true);
     $backendOptions = array('cache_dir' => APPLICATION_PATH . '/tmp/');
     $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
     Zend_Registry::set('cache', $cache);
     // DON'T KNOW WHY: zend locale is having trouble finding it's default cache directory
     // so using our zite cache as a quick fix
     Zend_Locale::setCache($cache);
     return $cache;
 }
Пример #6
0
 public function _initCache()
 {
     mb_internal_encoding("UTF-8");
     $frontend = array('lifetime' => 7200, 'automatic_serialization' => true);
     $cachedir = realpath(APPLICATION_PATH . '/data/cache');
     $backend = array('cache_dir' => $cachedir);
     $cache = Zend_Cache::factory('Core', 'File', $frontend, $backend);
     Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
     Zend_Registry::set('cache', $cache);
     // Cache dos Objetos Date. Utilize sempre. A não utilizaçao causa erros no zend cache.
     Zend_Locale::setCache($cache);
 }
Пример #7
0
 /**
  * Setup zend cache directory.
  *
  * @return void
  */
 protected function _initZendCache()
 {
     $this->bootstrap('Configuration');
     $config = $this->getResource('Configuration');
     $frontendOptions = array('lifetime' => 600, 'automatic_serialization' => true);
     $backendOptions = array('cache_dir' => $config->workspacePath . '/cache/');
     $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
     Zend_Translate::setCache($cache);
     Zend_Locale::setCache($cache);
     Zend_Locale_Data::setCache($cache);
     Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
     return $cache;
 }
Пример #8
0
 /**
  * Set caching
  *
  * @return void
  */
 public function _initCache()
 {
     if (!Zend_Registry::isRegistered('cachemanager')) {
         return false;
     }
     $cache = HCMS_Cache::getInstance()->getCoreCache();
     //set cache for table metadata
     Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
     //set cache for locale
     Zend_Locale::setCache($cache);
     //set cache for translate
     Zend_Translate::setCache($cache);
     //plugin loader cache
     $classFileIncCache = APPLICATION_PATH . '/../cache/file/pluginLoaderCache.php';
     if (file_exists($classFileIncCache)) {
         include_once $classFileIncCache;
     }
     Zend_Loader_PluginLoader::setIncludeFileCache($classFileIncCache);
 }
Пример #9
0
 /**
  * Sets the locale cache
  *
  * @return void
  */
 protected function _setCache()
 {
     $options = $this->getOptions();
     // Disable cache? If not defined, cache will be active
     if (isset($options['cache']['active']) && !$options['cache']['active']) {
         // Zend by default creates a cache for Zend_Locale, due to performance
         // considerations. Manually disable cache to override that behaviour.
         Zend_Locale::disableCache(true);
         return;
     }
     // Get the cache using the config settings as input
     $this->_bootstrap->bootstrap('CacheManager');
     $manager = $this->_bootstrap->getResource('CacheManager');
     $cache = $manager->getCache('locale');
     // Write caching errors to log file (if activated in the config)
     $this->_bootstrap->bootstrap('Log');
     $logger = $this->_bootstrap->getResource('Log');
     $cache->setOption('logger', $logger);
     Zend_Locale::setCache($cache);
 }
Пример #10
0
 /**
  * Constructor
  *
  * Initialize application. Potentially initializes include_paths, PHP
  * settings, and bootstrap class.
  *
  * It also loads the default config file for the HausDesign CMS.
  *
  * @param  string                   $environment
  * @param  string|array|Zend_Config $options String path to configuration file, or array/Zend_Config
  *                                  of configuration options
  * @throws Zend_Application_Exception When invalid options are provided
  * @throws HausDesign_Application_Exception When invalid general options are provided
  * @return void
  */
 public function __construct($environment, $options = null)
 {
     parent::__construct($environment, $options);
     $this->_parseUrl();
     define('CUR_APPLICATION_PATH', realpath(APPLICATION_PATH . '' . DIRECTORY_SEPARATOR . '' . $this->_application . '' . DIRECTORY_SEPARATOR));
     // Get the application specific file
     // Normally located at /application/*application name*/configs/application.ini
     $applicationOptions = array();
     $applicationConfigFile = CUR_APPLICATION_PATH . '' . DIRECTORY_SEPARATOR . 'configs' . DIRECTORY_SEPARATOR . 'application.ini';
     if (file_exists($applicationConfigFile)) {
         $applicationOptions = $this->_loadConfig($applicationConfigFile);
     }
     // Merge the options and force them into Zend_Application
     $this->setOptions($this->mergeOptions($this->getOptions(), $applicationOptions));
     // Add the options to the Zend Registry
     Zend_Registry::set('config', $this->getOptions());
     // FIX FOR IIS CACHE FOLDER START
     $config = new Zend_Config_Ini($applicationConfigFile, $environment);
     $cache = Zend_Cache::factory('Core', 'File', $config->resources->cachemanager->administrator->frontend->options->toArray(), $config->resources->cachemanager->administrator->backend->options->toArray());
     Zend_Locale::setCache($cache);
 }
Пример #11
0
 /**
  * Init translation services and locale.
  *
  * @return void
  */
 protected function _initTranslationService()
 {
     // Build the path for the languages folder in the current module
     $languagesPath = APPLICATION_PATH . '/languages';
     // Setup a cache
     $frontendOptions = array();
     $backendOptions = array();
     $frontendOptions['automatic_serialization'] = true;
     $frontendOptions['lifetime'] = '604800';
     $frontendOptions['write_control'] = false;
     $frontendOptions['master_files'] = array($languagesPath . '/en/messages.mo');
     $backendOptions['cache_dir'] = APPLICATION_PATH . '/../zendCache';
     $backendOptions['hashed_directory_level'] = 1;
     $cache = Zend_Cache::factory('File', 'File', $frontendOptions, $backendOptions);
     Zend_Translate::setCache($cache);
     Zend_Locale::setCache($cache);
     // Register the locale for system-wide use
     Zend_Registry::set('Zend_Locale', new Zend_Locale('en'));
     // Create a translator
     $translator = new Zend_Translate(array('adapter' => 'gettext', 'content' => $languagesPath . '/en/messages.mo', 'locale' => 'en'));
     // Register the translator for system-wide use
     Zend_Registry::set('Zend_Translate', $translator);
 }
Пример #12
0
 public function init()
 {
     parent::init();
     $this->_acl = Application_Model_Acl::getInstance();
     $isCron = 0 === strpos($_SERVER['REQUEST_URI'], '/cron');
     if (!$isCron) {
         $this->_session = Application_Service_Session::getInstance();
     }
     if ('index' === $this->getParam('controller') && 'unsupported' === $this->getParam('action')) {
         //            $this->redirect('index/unsupported');
     }
     $this->_mail = new Application_Service_Mail();
     $this->_userRepo = Application_Model_UserRepository::getInstance();
     $frontendOptions = ['lifetime' => 60, 'automatic_serialization' => true];
     $backendOptions = ['cache_dir' => substr(APPLICATION_PATH, 0, strrpos(APPLICATION_PATH, '/')) . '/data/cache/'];
     $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
     Zend_Registry::set('Zend_Locale', new Zend_Locale('de'));
     Zend_Locale::setCache($cache);
     if (!$isCron && $this->isLoggedin()) {
         if (is_null($this->_session->getColor())) {
             $this->_session->setColor(Application_Model_UserSettingRepository::getInstance()->getSetting()->getColor());
         }
         if (is_null($this->_session->getMenuStatic())) {
             $this->_session->setMenuStatic(Application_Model_UserSettingRepository::getInstance()->getSetting()->getMenuStatic());
         }
         if (is_null($this->_session->getLanguage())) {
             $this->_session->setLanguage(Application_Model_UserSettingRepository::getInstance()->getSetting()->getLanguage());
         }
     }
     $this->_translate = Application_Service_Language::getInstance();
     Zend_Registry::set('Zend_Translate', $this->_translate);
     $this->view->translate = $this->_translate;
     if (!$isCron) {
         $this->view->staticMenu = intval($this->_session->getMenuStatic());
         $this->view->color = $this->_session->getColor();
     }
 }
Пример #13
0
 protected function _initCache()
 {
     $cache_dir = Core_Model_Directory::getCacheDirectory(true);
     if (is_writable($cache_dir)) {
         $frontendConf = array('lifetime' => 345600, 'automatic_seralization' => true);
         $backendConf = array('cache_dir' => $cache_dir);
         $cache = Zend_Cache::factory('Core', 'File', $frontendConf, $backendConf);
         $cache->setOption('automatic_serialization', true);
         Zend_Locale::setCache($cache);
         Zend_Registry::set('cache', $cache);
     }
 }
Пример #14
0
    /**
     * Initializes a cache adapter in the following order of precedence:
     * 1) application/config/config.ini section if available:
     *    Example: cache.backend.* (see config for details)
     * 2) W3 Super Cache Memcache connection
     * 3) APC (if installed)
     * 4) SQLite (if installed) in cache/cache.sqlite.db
     * 5) File based, in cache/cache.obj
     *
     * It is recommended to configure your caching connection in the config
     * file.
     *
     * @return  Zend
     */
    protected function _initCache()
    {
        $config = $this->bootstrap('config')
                       ->getResource('config');

        if (isset($config->cache->backend->memcached)) {
            $adapterName = 'Libmemcached';
            $options = $config->cache->backend->memcached->toArray();
        } elseif (isset($config->cache->backend->memcache)) {
            $adapterName = 'Memcached';
            $options = $config->cache->backend->memcache->toArray();
        } elseif (isset($config->cache->backend->apc)) {
            $adapterName = 'Apc';
            $options = $config->cache->backend->apc->toArray();
        } elseif (isset($config->cache->backend->xcache)) {
            $adapterName = 'Xcache';
            $options = $config->cache->backend->xcache->toArray();
        } elseif (isset($config->cache->backend->sqlite)) {
            $adapterName = 'Sqlite';
            $options = $config->cache->backend->sqlite->toArray();
        } elseif (isset($config->cache->backend->file)) {
            $adapterName = 'File';
            $options = $config->cache->backend->file->toArray();
        } else {
            // Auto-detect best available option
            if (extension_loaded('apc')) {
                $adapterName = 'Apc';
                $options = array();
            } elseif (extension_loaded('sqlite')) {
                $adapterName = 'Sqlite';
                $options = array(
                    'cache_db_complete_path' => PROJECT_BASE_PATH . '/cache/cache.sqlite.db'
                );
            } else {
                $adapterName = 'File';
                $options = array(
                    'cache_dir'     => PROJECT_BASE_PATH . '/cache',
                    'file_locking'  => true
                );
            }
        }

        if (isset($config->cache->frontend)) {
            $frontendOptions = $config->cache->frontend->toArray();
        } else {
            $frontendOptions = array(
                'lifetime' => 3600,
                'logging' => false,
                'automatic_serialization' => true
            );
        }

        $cache = Zend_Cache::factory('Core', $adapterName, $frontendOptions, $options);

        Zend_Registry::set('cache', $cache);
        Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
        Zend_Date::setOptions(array('cache' => $cache));
        Zend_Locale::setCache($cache);

        return $cache;
    }
Пример #15
0
 protected function _initLocale()
 {
     $config = Application_Model_Mappers_ConfigMapper::getInstance()->getConfig();
     $name = Zend_Locale::getLocaleToTerritory($config['language']);
     if ($name !== null) {
         $locale = new Zend_Locale($name);
     } else {
         $locale = new Zend_Locale();
     }
     $locale->setCache(Zend_Registry::get('cache'));
     Zend_Registry::set('Zend_Locale', $locale);
 }
Пример #16
0
 /**
  * initialize cache
  *
  * @return void
  */
 protected function _initCache()
 {
     $optionsBackend = array('cache_dir' => Zend_Registry::get('config')->cache->path, 'file_locking' => true, 'read_control' => false);
     $optionsFrontend = array('caching' => Zend_Registry::get('config')->cache->enable == "1", 'automatic_serialization' => true);
     $this->cache = Zend_Cache::factory('Core', 'File', $optionsFrontend, $optionsBackend);
     // set cache for all locale and translate
     Zend_Locale::setCache($this->cache);
     Zend_Translate::setCache($this->cache);
     // save cache object for further use
     Zend_Registry::set('cache', $this->cache);
     return $this->cache;
 }
Пример #17
0
 public function updateFead($id, $debug = null)
 {
     $frontendOptions = ['lifetime' => 60, 'automatic_serialization' => true];
     $backendOptions = ['cache_dir' => substr(APPLICATION_PATH, 0, strrpos(APPLICATION_PATH, '/')) . '/data/cache/'];
     $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
     $output = '';
     Zend_Registry::set('Zend_Locale', new Zend_Locale('de'));
     Zend_Locale::setCache($cache);
     $repository = Application_Model_ArticleRepository::getInstance();
     $feadData = Application_Model_FeadRepository::getInstance()->get($id);
     $date = $repository->getLatestDateForFead($id);
     // close db connections
     Application_Model_ArticleRepository::getInstance()->closeConnection();
     try {
         $fead = Application_Service_Fead::import(strtolower($feadData->getUrl()));
     } catch (Exception $e) {
         if ($debug) {
             $output .= $feadData->getTitle() . ': ' . $e->getMessage() . '<br>';
         }
         try {
             $curl = curl_init();
             curl_setopt($curl, CURLOPT_URL, $feadData->getUrl());
             curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
             curl_setopt($curl, CURLOPT_HEADER, false);
             $data = curl_exec($curl);
             curl_close($curl);
             $fead = Application_Service_Fead::importString($data);
         } catch (Exception $e) {
             $output .= $feadData->getTitle() . ': ' . $e->getMessage() . '<br>';
             echo $feadData->getTitle() . ': ' . $e->getMessage();
             return;
         }
     }
     if ($debug) {
         $output .= $feadData->getTitle() . '<br>';
     }
     $articles = [];
     foreach ($fead as $i => $article) {
         $articleDate = $article->getDateModified();
         $now = new Zend_Date();
         $now = $now->toString('YYYY-MM-dd HH:mm:ss');
         if (!is_null($articleDate) && $now > $articleDate->toString('YYYY-MM-dd HH:mm:ss')) {
             $articleDate = $articleDate->toString('YYYY-MM-dd HH:mm:ss');
         } else {
             $articleDate = $now;
         }
         if ($debug) {
             $output .= $articleDate . ' > ' . $date . '?<br>';
         }
         if ($articleDate <= $date) {
             break;
         }
         if ($debug) {
             $output .= '.';
         }
         $content = trim($article->getDescription(), ['script']);
         $preview = substr(trim(strip_tags($content, ['a', 'img', 'script'])), 0, 255);
         $url = $article->getLink();
         $thumb = strpos($article->getContent(), '<img');
         if ($thumb) {
             $thumb = strpos($article->getContent(), 'src="http', $thumb);
             $end = strpos($article->getContent(), '"', $thumb + 5);
             $thumb = substr($article->getContent(), $thumb + 5, $end - $thumb - 5);
         } else {
             $thumb = null;
         }
         $articles[$i] = new Application_Model_Entity_Article(['feadId' => $feadData->getId(), 'title' => substr($article->getTitle(), 0, 255), 'preview' => $preview, 'url' => $url, 'thumb' => $thumb, 'dateCreated' => $article->getDateCreated()->toString('YYYY-MM-dd HH:mm:ss'), 'dateModified' => $articleDate, 'content' => $content]);
     }
     Application_Model_ArticleRepository::getInstance()->openConnection();
     // import from oldest to youngest
     for ($i = sizeof($articles) - 1; $i >= 0; $i--) {
         Application_Model_ArticleRepository::getInstance()->addArticle($articles[$i]);
     }
     if ($debug) {
         echo $output;
     }
 }
Пример #18
0
 /**
  * Set locale and language if possible
  *
  * @static
  * @param string (locale or language) $locale
  */
 public static function setLocale($locale = 'auto')
 {
     if (Zend_Registry::isRegistered('Zend_Locale')) {
         $currentLocale = Zend_Registry::get('Zend_Locale');
         if ($locale === $currentLocale->toString()) {
             return;
         }
     }
     if (Axis_Area::isInstaller()) {
         $session = Axis::session('install');
         if (Zend_Registry::isRegistered('Zend_Locale')) {
             $currentLocale = Zend_Registry::get('Zend_Locale');
         } else {
             $currentLocale = new Zend_Locale();
             Zend_Locale::setCache(Axis::cache());
             Zend_Registry::set('Zend_Locale', $currentLocale);
         }
         if ($currentLocale->isLocale($locale)) {
             $currentLocale->setLocale($locale);
         }
         $session->current_locale = $locale;
         return;
     }
     $session = Axis::session();
     if (!strstr($locale, '_')) {
         $locale = self::_getLocaleFromLanguageCode($locale);
     }
     if (Zend_Registry::isRegistered('Zend_Locale')) {
         $currentLocale = Zend_Registry::get('Zend_Locale');
         $currentLocale->setLocale($locale);
     } else {
         try {
             $currentLocale = new Zend_Locale($locale);
         } catch (Zend_Locale_Exception $e) {
             $currentLocale = new Zend_Locale(self::DEFAULT_LOCALE);
         }
         Zend_Locale::setCache(Axis::cache());
         Zend_Registry::set('Zend_Locale', $currentLocale);
     }
     $availableLanguages = Axis::single('locale/language')->select(array('locale', 'id'))->fetchPairs();
     if (Axis_Area::isBackend()) {
         $session->locale = $locale;
         $defaultLanguage = Axis::config('locale/main/language_admin');
         if (array_search($defaultLanguage, $availableLanguages)) {
             $session->language = $defaultLanguage;
         } else {
             $session->language = current($availableLanguages);
         }
     } else {
         $localeCode = $currentLocale->toString();
         if (isset($availableLanguages[$localeCode])) {
             $session->language = $availableLanguages[$localeCode];
         } else {
             $defaultLanguage = Axis::config('locale/main/language_front');
             if (array_search($defaultLanguage, $availableLanguages)) {
                 $session->language = $defaultLanguage;
             } else {
                 $session->language = current($availableLanguages);
             }
         }
     }
     self::setTimezone();
 }
Пример #19
0
 /**
  * @param null $cache
  */
 public static function setZendFrameworkCaches($cache = null)
 {
     \Zend_Locale::setCache($cache);
     \Zend_Locale_Data::setCache($cache);
     \Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
 }
 /**
  * setup the cache and add it to zend registry
  *
  * @param bool $_enabled disabled cache regardless what's configured in config.inc.php
  * 
  * @todo use the same config keys as Zend_Cache (backend + frontend) to simplify this
  */
 public static function setupCache($_enabled = true)
 {
     if (self::$cacheStatus !== NULL && self::$cacheStatus === $_enabled) {
         return;
     }
     $config = self::getConfig();
     if ($config->caching && $config->caching->active) {
         if (isset($config->caching->shared) && $config->caching->shared === true) {
             self::set(self::SHAREDCACHE, true);
         } else {
             self::set(self::SHAREDCACHE, false);
         }
     }
     // create zend cache
     if ($_enabled === true && $config->caching && $config->caching->active) {
         $logging = $config->caching->logging ? $config->caching->logging : false;
         $logger = self::getLogger();
         $frontendOptions = array('lifetime' => $config->caching->lifetime ? $config->caching->lifetime : 7200, 'automatic_serialization' => true, 'caching' => true, 'automatic_cleaning_factor' => 0, 'write_control' => false, 'logging' => $logging, 'logger' => $logger);
         $backendType = $config->caching->backend ? ucfirst($config->caching->backend) : 'File';
         $backendOptions = $config->caching->backendOptions ? $config->caching->backendOptions->toArray() : false;
         if (!$backendOptions) {
             switch ($backendType) {
                 case 'File':
                     $backendOptions = array('cache_dir' => $config->caching->path ? $config->caching->path : Tinebase_Core::getTempDir(), 'hashed_directory_level' => $config->caching->dirlevel ? $config->caching->dirlevel : 4, 'logging' => $logging, 'logger' => $logger);
                     break;
                 case 'Memcached':
                     $host = $config->caching->host ? $config->caching->host : (isset($config->caching->memcached->host) ? $config->caching->memcached->host : 'localhost');
                     $port = $config->caching->port ? $config->caching->port : (isset($config->caching->memcached->port) ? $config->caching->memcached->port : 11211);
                     $backendOptions = array('servers' => array('host' => $host, 'port' => $port, 'persistent' => TRUE));
                     break;
                 case 'Redis':
                     $host = $config->caching->host ? $config->caching->host : ($config->caching->redis->host ? $config->caching->redis->host : 'localhost');
                     $port = $config->caching->port ? $config->caching->port : ($config->caching->redis->port ? $config->caching->redis->port : 6379);
                     if ($config->caching && $config->caching->prefix) {
                         $prefix = $config->caching->prefix;
                     } else {
                         if ($config->caching && $config->caching->redis && $config->caching->redis->prefix) {
                             $prefix = $config->caching->redis->prefix;
                         } else {
                             $prefix = $config->database && $config->database->tableprefix ? $config->database->tableprefix : 'tine20';
                         }
                     }
                     $prefix .= '_CACHE_';
                     $backendOptions = array('servers' => array('host' => $host, 'port' => $port, 'prefix' => $prefix));
                     break;
                 default:
                     $backendOptions = array();
                     break;
             }
         }
         Tinebase_Core::getLogger()->INFO(__METHOD__ . '::' . __LINE__ . " cache of backend type '{$backendType}' enabled");
         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
             // logger is an object, that makes ugly traces :)
             $backendOptionsWithoutLogger = $backendOptions;
             if (isset($backendOptionsWithoutLogger['logger'])) {
                 unset($backendOptionsWithoutLogger['logger']);
             }
             Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . " backend options: " . print_r($backendOptionsWithoutLogger, TRUE));
         }
     } else {
         Tinebase_Core::getLogger()->INFO(__METHOD__ . '::' . __LINE__ . ' Cache disabled');
         $backendType = 'Test';
         $frontendOptions = array('caching' => false);
         $backendOptions = array();
     }
     // getting a Zend_Cache_Core object
     try {
         $cache = Zend_Cache::factory('Core', $backendType, $frontendOptions, $backendOptions);
     } catch (Exception $e) {
         Tinebase_Exception::log($e);
         $enabled = false;
         if ('File' === $backendType && !is_dir($backendOptions['cache_dir'])) {
             Tinebase_Core::getLogger()->INFO(__METHOD__ . '::' . __LINE__ . ' Create cache directory and re-try');
             if (mkdir($backendOptions['cache_dir'], 0770, true)) {
                 $enabled = $_enabled;
             }
         }
         self::setupCache($enabled);
         return;
     }
     // some important caches
     Zend_Locale::setCache($cache);
     Zend_Translate::setCache($cache);
     Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
     self::set(self::CACHE, $cache);
     self::$cacheStatus = $_enabled;
 }
Пример #21
0
 /**
  * setup the cache and add it to zend registry
  *
  * @param bool $_enabled disabled cache regardless what's configured in config.inc.php
  * 
  * @todo use the same config keys as Zend_Cache (backend + frontend) to simplify this
  */
 public static function setupCache($_enabled = true)
 {
     $config = self::getConfig();
     // create zend cache
     if ($_enabled === true && $config->caching && $config->caching->active) {
         $frontendOptions = array('lifetime' => $config->caching->lifetime ? $config->caching->lifetime : 7200, 'automatic_serialization' => true, 'caching' => true, 'automatic_cleaning_factor' => 0, 'write_control' => false, 'logging' => Tinebase_Core::isLogLevel(Zend_Log::DEBUG), 'logger' => self::getLogger());
         $backendType = $config->caching->backend ? ucfirst($config->caching->backend) : 'File';
         $backendOptions = $config->caching->backendOptions ? $config->caching->backendOptions->toArray() : false;
         if (!$backendOptions) {
             switch ($backendType) {
                 case 'File':
                     $backendOptions = array('cache_dir' => $config->caching->path ? $config->caching->path : Tinebase_Core::getTempDir(), 'hashed_directory_level' => $config->caching->dirlevel ? $config->caching->dirlevel : 4, 'logging' => Tinebase_Core::isLogLevel(Zend_Log::DEBUG), 'logger' => self::getLogger());
                     break;
                 case 'Memcached':
                     $backendOptions = array('servers' => array('host' => $config->caching->host ? $config->caching->host : 'localhost', 'port' => $config->caching->port ? $config->caching->port : 11211, 'persistent' => TRUE));
                     break;
                 case 'Redis':
                     $backendOptions = array('servers' => array('host' => $config->caching->host ? $config->caching->host : 'localhost', 'port' => $config->caching->port ? $config->caching->port : 6379, 'prefix' => Tinebase_Application::getInstance()->getApplicationByName('Tinebase')->getId() . '_CACHE_'));
                     break;
                 default:
                     $backendOptions = array();
                     break;
             }
         }
         Tinebase_Core::getLogger()->INFO(__METHOD__ . '::' . __LINE__ . " cache of backend type '{$backendType}' enabled");
         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
             // logger is an object, that makes ugly traces :)
             $backendOptionsWithoutLogger = $backendOptions;
             if (isset($backendOptionsWithoutLogger['logger'])) {
                 unset($backendOptionsWithoutLogger['logger']);
             }
             Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . " backend options: " . print_r($backendOptionsWithoutLogger, TRUE));
         }
     } else {
         Tinebase_Core::getLogger()->INFO(__METHOD__ . '::' . __LINE__ . ' cache disabled');
         $backendType = 'Test';
         $frontendOptions = array('caching' => false);
         $backendOptions = array();
     }
     // getting a Zend_Cache_Core object
     try {
         $cache = Zend_Cache::factory('Core', $backendType, $frontendOptions, $backendOptions);
     } catch (Zend_Cache_Exception $e) {
         $enabled = FALSE;
         if ('File' === $backendType && !is_dir($backendOptions['cache_dir'])) {
             // create cache directory and re-try
             if (mkdir($backendOptions['cache_dir'], 0770, true)) {
                 $enabled = $_enabled;
             }
         }
         Tinebase_Core::getLogger()->WARN(__METHOD__ . '::' . __LINE__ . ' Cache error: ' . $e->getMessage());
         self::setupCache($enabled);
         return;
     }
     // some important caches
     Zend_Locale::setCache($cache);
     Zend_Translate::setCache($cache);
     self::set(self::CACHE, $cache);
 }
Пример #22
0
 /**
  * Initialize the site's locale
  *
  * @return Zend_Locale
  */
 protected function _initLocale()
 {
     $this->bootstrap('config');
     // Get config resource
     $config = $this->getResource('config');
     $this->bootstrap('cache');
     // Get cache object
     $cache = $this->getResource('cache');
     Zend_Locale::setCache($cache);
     $this->bootstrap('siteSettings');
     // Get siteSettings object
     $siteSettings = $this->getResource('siteSettings');
     // Set default locale
     setlocale(LC_ALL, $config->language->defaultLocale);
     $locale = new Zend_Locale($config->language->defaultLocale);
     // Set default timezone
     $timezone = $siteSettings->get('default_timezone');
     date_default_timezone_set($timezone);
     // Return it, so that it can be stored by the bootstrap
     return $locale;
 }
Пример #23
0
 /**
  * Initialise the translation adapter with a locale setting.
  *
  * @param string|null $locale If no locale specified, choose one automatically
  *
  * @return string $string
  */
 public static function init($locale = null)
 {
     global $WT_SESSION;
     // The translation libraries only work with a cache.
     $cache_options = array('automatic_serialization' => true, 'cache_id_prefix' => md5(WT_SERVER_NAME . WT_SCRIPT_PATH));
     if (ini_get('apc.enabled')) {
         self::$cache = Zend_Cache::factory('Core', 'Apc', $cache_options, array());
     } elseif (WT_File::mkdir(WT_DATA_DIR . 'cache')) {
         self::$cache = Zend_Cache::factory('Core', 'File', $cache_options, array('cache_dir' => WT_DATA_DIR . 'cache'));
     } else {
         self::$cache = Zend_Cache::factory('Core', 'Zend_Cache_Backend_BlackHole', $cache_options, array(), false, true);
     }
     Zend_Locale::setCache(self::$cache);
     Zend_Translate::setCache(self::$cache);
     $installed_languages = self::installed_languages();
     if (is_null($locale) || !array_key_exists($locale, $installed_languages)) {
         // Automatic locale selection.
         $locale = WT_Filter::get('lang');
         if ($locale && array_key_exists($locale, $installed_languages)) {
             // Requested in the URL?
             if (Auth::id()) {
                 Auth::user()->setSetting('language', $locale);
             }
         } elseif (array_key_exists($WT_SESSION->locale, $installed_languages)) {
             // Rembered from a previous visit?
             $locale = $WT_SESSION->locale;
         } else {
             // Browser preference takes priority over gedcom default
             if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
                 $prefs = explode(',', str_replace(' ', '', $_SERVER['HTTP_ACCEPT_LANGUAGE']));
             } else {
                 $prefs = array();
             }
             if (WT_GED_ID) {
                 // Add the tree’s default language as a low-priority
                 $locale = get_gedcom_setting(WT_GED_ID, 'LANGUAGE');
                 $prefs[] = $locale . ';q=0.2';
             }
             $prefs2 = array();
             foreach ($prefs as $pref) {
                 list($l, $q) = explode(';q=', $pref . ';q=1.0');
                 $l = preg_replace_callback('/_[a-z][a-z]$/', function ($x) {
                     return strtoupper($x[0]);
                 }, str_replace('-', '_', $l));
                 // en-gb => en_GB
                 if (array_key_exists($l, $prefs2)) {
                     $prefs2[$l] = max((double) $q, $prefs2[$l]);
                 } else {
                     $prefs2[$l] = (double) $q;
                 }
             }
             // Ensure there is a fallback.
             if (!array_key_exists('en_US', $prefs2)) {
                 $prefs2['en_US'] = 0.01;
             }
             arsort($prefs2);
             foreach (array_keys($prefs2) as $pref) {
                 if (array_key_exists($pref, $installed_languages)) {
                     $locale = $pref;
                     break;
                 }
             }
         }
     }
     // Load the translation file
     self::$translation_adapter = new Zend_Translate('gettext', WT_ROOT . 'language/' . $locale . '.mo', $locale);
     // Deprecated - some custom modules use this to add translations
     Zend_Registry::set('Zend_Translate', self::$translation_adapter);
     // Load any local user translations
     if (is_dir(WT_DATA_DIR . 'language')) {
         if (file_exists(WT_DATA_DIR . 'language/' . $locale . '.mo')) {
             self::addTranslation(new Zend_Translate('gettext', WT_DATA_DIR . 'language/' . $locale . '.mo', $locale));
         }
         if (file_exists(WT_DATA_DIR . 'language/' . $locale . '.php')) {
             self::addTranslation(new Zend_Translate('array', WT_DATA_DIR . 'language/' . $locale . '.php', $locale));
         }
         if (file_exists(WT_DATA_DIR . 'language/' . $locale . '.csv')) {
             self::addTranslation(new Zend_Translate('csv', WT_DATA_DIR . 'language/' . $locale . '.csv', $locale));
         }
     }
     // Extract language settings from the translation file
     global $DATE_FORMAT;
     // I18N: This is the format string for full dates.  See http://php.net/date for codes
     $DATE_FORMAT = self::noop('%j %F %Y');
     global $TIME_FORMAT;
     // I18N: This is the format string for the time-of-day.  See http://php.net/date for codes
     $TIME_FORMAT = self::noop('%H:%i:%s');
     // Alphabetic sorting sequence (upper-case letters), used by webtrees to sort strings
     list(, self::$alphabet_upper) = explode('=', self::noop('ALPHABET_upper=ABCDEFGHIJKLMNOPQRSTUVWXYZ'));
     // Alphabetic sorting sequence (lower-case letters), used by webtrees to sort strings
     list(, self::$alphabet_lower) = explode('=', self::noop('ALPHABET_lower=abcdefghijklmnopqrstuvwxyz'));
     global $WEEK_START;
     // I18N: This is the first day of the week on calendars. 0=Sunday, 1=Monday...
     list(, $WEEK_START) = explode('=', self::noop('WEEK_START=0'));
     global $TEXT_DIRECTION;
     $TEXT_DIRECTION = self::scriptDirection(self::languageScript($locale));
     self::$locale = $locale;
     self::$dir = $TEXT_DIRECTION;
     // I18N: This punctuation is used to separate lists of items.
     self::$list_separator = self::translate(', ');
     // I18N: This is the name of the MySQL collation that applies to your language.  A list is available at http://dev.mysql.com/doc/refman/5.0/en/charset-unicode-sets.html
     self::$collation = self::translate('utf8_unicode_ci');
     // Non-latin numbers may require non-latin digits
     try {
         self::$numbering_system = Zend_Locale_Data::getContent($locale, 'defaultnumberingsystem');
     } catch (Zend_Locale_Exception $ex) {
         // The latest CLDR database omits some languges such as Tatar (tt)
         self::$numbering_system = 'latin';
     }
     return $locale;
 }
Пример #24
0
// we do not unset the $database variable
// as it is historically referenced in many places from the global namespace
$database = new Kimai_Database_Mysql($kga, true);
if (!$database->isConnected()) {
    die('Kimai could not connect to database. Check your autoconf.php.');
}
Kimai_Registry::setDatabase($database);
// ============ setup authenticator ============
$authClass = 'Kimai_Auth_' . ucfirst($kga->getAuthenticator());
if (!class_exists($authClass)) {
    $authClass = 'Kimai_Auth_Kimai';
}
$authPlugin = new $authClass($database, $kga);
Kimai_Registry::setAuthenticator($authPlugin);
unset($authPlugin);
// ============ load global configurations ============
$database->initializeConfig($kga);
// ============ setup translation object ============
$service = new Kimai_Translation_Service();
Kimai_Registry::setTranslation($service->load($kga->getLanguage()));
unset($service);
$tmpDir = WEBROOT . 'temporary/';
if (!file_exists($tmpDir) || !is_dir($tmpDir) || !is_writable($tmpDir)) {
    die('Kimai needs write permissions for: temporary/');
}
$frontendOptions = array('lifetime' => 7200, 'automatic_serialization' => true);
$backendOptions = array('cache_dir' => $tmpDir);
$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
Kimai_Registry::setCache($cache);
Zend_Locale::setCache($cache);
Пример #25
0
 /**
  * Create a default file cache for the Translate and DB adapters to speed up execution
  *
  * @return \Zend_Cache_Core
  */
 protected function _initCache()
 {
     $this->bootstrap('project');
     $useCache = $this->getResource('project')->getCache();
     $cache = null;
     $exists = false;
     $cachePrefix = GEMS_PROJECT_NAME . '_';
     // Check if APC extension is loaded and enabled
     if (\MUtil_Console::isConsole() && !ini_get('apc.enable_cli') && $useCache === 'apc') {
         // To keep the rest readable, we just fall back to File when apc is disabled on cli
         $useCache = "File";
     }
     if ($useCache === 'apc' && extension_loaded('apc') && ini_get('apc.enabled')) {
         $cacheBackend = 'Apc';
         $cacheBackendOptions = array();
         //Add path to the prefix as APC is a SHARED cache
         $cachePrefix .= md5(APPLICATION_PATH);
         $exists = true;
     } else {
         $cacheBackend = 'File';
         $cacheDir = GEMS_ROOT_DIR . "/var/cache/";
         $cacheBackendOptions = array('cache_dir' => $cacheDir);
         if (!file_exists($cacheDir)) {
             if (@mkdir($cacheDir, 0777, true)) {
                 $exists = true;
             }
         } else {
             $exists = true;
         }
     }
     if ($exists && $useCache != 'none') {
         /**
          * automatic_cleaning_factor disables automatic cleaning of the cache and should get rid of
          *                           random delays on heavy traffic sites with File cache. Apc does
          *                           not support automatic cleaning.
          */
         $cacheFrontendOptions = array('automatic_serialization' => true, 'cache_id_prefix' => $cachePrefix, 'automatic_cleaning_factor' => 0);
         $cache = \Zend_Cache::factory('Core', $cacheBackend, $cacheFrontendOptions, $cacheBackendOptions);
     } else {
         $cache = \Zend_Cache::factory('Core', 'Static', array('caching' => false), array('disable_caching' => true));
     }
     \Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
     \Zend_Translate::setCache($cache);
     \Zend_Locale::setCache($cache);
     return $cache;
 }
Пример #26
0
    /**
     * Set the cache
     *
     * @param string|Zend_Cache_Core $cache
     * @return Zend_Application_Resource_Locale
     */
    public function setCache($cache)
    {
        if (is_string($cache)) {
            $bootstrap = $this->getBootstrap();
            if ($bootstrap instanceof Zend_Application_Bootstrap_ResourceBootstrapper
                && $bootstrap->hasPluginResource('CacheManager')
            ) {
                $cacheManager = $bootstrap->bootstrap('CacheManager')
                    ->getResource('CacheManager');
                if (null !== $cacheManager && $cacheManager->hasCache($cache)) {
                    $cache = $cacheManager->getCache($cache);
                }
            }
        }

        if ($cache instanceof Zend_Cache_Core) {
            Zend_Locale::setCache($cache);
        }

        return $this;
    }
Пример #27
0
 /**
  * Shares the cache instance
  * to all Zend objects that accept one statically
  * 
  * @return Zend_Application_Resource_Cache
  */
 protected function _shareToZendObjects()
 {
     Zend_Paginator::setCache($this->_cache);
     Zend_Db_Table::setDefaultMetadataCache($this->_cache);
     Zend_Date::setOptions(array('cache' => $this->_cache));
     Zend_Translate::setCache($this->_cache);
     Zend_Locale::setCache($this->_cache);
     return $this;
 }