public function __toString() { if (JO_Registry::isRegistered('static_cache_options') && JO_Registry::forceGet('static_cache_enable')) { $options = (array) unserialize(JO_Registry::get('static_cache_options')); $cache_object = new JO_Cache_Static($options); $cache_object->add(false, $this->data); } return $this->data; }
/** * __construct() - For concrete implementation of JO_Db_Table * * @param string|array $config string can reference a JO_Registry key for a db adapter * OR it can reference the name of a table * @param array|JO_Db_Table_Definition $definition */ public function __construct($config = array(), $definition = null) { if ($definition !== null && is_array($definition)) { $definition = new JO_Db_Table_Definition($definition); } if (is_string($config)) { if (JO_Registry::isRegistered($config)) { trigger_error(__CLASS__ . '::' . __METHOD__ . '(\'registryName\') is not valid usage of JO_Db_Table, ' . 'try extending JO_Db_Table_Abstract in your extending classes.', E_USER_NOTICE); $config = array(self::ADAPTER => $config); } else { // process this as table with or without a definition if ($definition instanceof JO_Db_Table_Definition && $definition->hasTableConfig($config)) { // this will have DEFINITION_CONFIG_NAME & DEFINITION $config = $definition->getTableConfig($config); } else { $config = array(self::NAME => $config); } } } parent::__construct($config); }
/** * @param string $string */ public function translate($string) { if (JO_Registry::isRegistered('JO_Translate')) { $translate = JO_Registry::get('JO_Translate'); if (!$translate instanceof JO_Translate) { require_once 'JO/Exception.php'; throw new JO_Exception('JO_Translate already registered in registry but is ' . 'no instance of JO_Translate'); } return $translate->translate($string); } return $string; }
public function _initLocale() { $request = JO_Request::getInstance(); if ($request->getModule() == 'install') { return ''; } $locale_get = JO_Locale::findLocale(); $loc = new WM_Locale(); $languages = $loc->getLanguages(); $detect = ''; $languages_tmp = array(); foreach ($languages as $language) { // $lang = explode(',', $language['locale']); // if(in_array($locale_get, $lang)) { // $detect = $language['language_id']; // } $languages_tmp[$language['language_id']] = $language; } $code = ''; if ($request->getRequest('language_id') && array_key_exists($request->getRequest('language_id'), $languages_tmp)) { $code = $request->getRequest('language_id'); } elseif (JO_Session::get('language_id') && array_key_exists(JO_Session::get('language_id'), $languages_tmp)) { $code = JO_Session::get('language_id'); } elseif ($request->getCookie('language_id') && array_key_exists($request->getCookie('language_id'), $languages_tmp)) { $code = $request->getCookie('language_id'); } elseif ($detect) { $code = $detect; } elseif (JO_Registry::isRegistered('config_language_id')) { $code = JO_Registry::get('config_language_id'); } // if($request->getModule() == 'admin') { // $code = JO_Registry::get('config_language_id'); // } if (!$code) { throw new JO_Exception("No default language found"); } if (JO_Session::get('language_id') != $code) { JO_Session::set('language_id', $code); } if ($request->getCookie('language_id') != $code) { setcookie('language_id', $code, time() + 60 * 60 * 24 * 30, '/', '.' . $request->getDomain()); } if (isset($languages_tmp[$code])) { JO_Registry::set('config_language_id', $languages_tmp[$code]['language_id']); JO_Registry::set('config_language', $languages_tmp[$code]['code']); JO_Registry::set('JO_Locale', new JO_Locale($languages_tmp[$code]['locale_territory'])); setlocale(LC_TIME, $languages_tmp[$code]['locale_territory'] . '.utf-8'); } }
/** * Finds the proper locale based on the input * Checks if it exists, degrades it when necessary * Detects registry locale and when all fails tries to detect a automatic locale * Returns the found locale as string * * @param string $locale * @throws JO_Locale_Exception When the given locale is no locale or the autodetection fails * @return string */ public static function findLocale($locale = null) { if ($locale === null) { require_once 'JO/Registry.php'; if (JO_Registry::isRegistered('JO_Locale')) { $locale = JO_Registry::get('JO_Locale'); } } if ($locale === null) { $locale = new JO_Locale(); } if (!JO_Locale::isLocale($locale, true, false)) { if (!JO_Locale::isLocale($locale, false, false)) { $locale = JO_Locale::getLocaleToTerritory($locale); if (empty($locale)) { require_once 'JO/Exception.php'; throw new JO_Exception("The locale '{$locale}' is no known locale"); } } else { $locale = new JO_Locale($locale); } } $locale = self::_prepareLocale($locale); return $locale; }