public function localeDateTime($format, $locale) { if (is_null($lang)) { $lang = ZFE_Core::getLanguage(); } $dt = new Zend_Date($this->getTimestamp()); $formats = Zend_Locale_Data::getList($lang, 'datetime'); if (isset($formats[$format])) { $format = $formats[$format]; } return $dt->toString($format, null, $lang); }
public function routeStartup(Zend_Controller_Request_Abstract $request) { // Initialize the variables $front = Zend_Controller_Front::getInstance(); $bootstrap = $front->getParam('bootstrap'); $this->locale = $bootstrap->getResource('locale'); if (null === $this->locale) { $this->locale = new Zend_Locale(); } $this->resource = ZFE_Environment::getResource('Multilanguage'); $options = $this->resource->getOptions(); $language = $this->getBrowserLanguage(); // If a domain is given, perform subdomain-based language detection if (isset($options['domain'])) { $domain = $request->getHttpHost(); // If the main domain is accessed, use the browser language and // redirect to that subdomain if ($domain === $options['domain']) { // Perform 302 redirect header('HTTP/1.1 302'); header('Location: ' . $this->composeUrl($language)); exit; } // If it is not an IP address, extract the language from the domain, and store it if (!ZFE_Core::isIpAddress($domain)) { $subdomain = strtolower(str_replace('.' . $options['domain'], '', $domain)); $parts = explode('-', $subdomain); $language = $parts[0]; if (isset($parts[1])) { $language .= '_' . ucfirst($parts[1]); } } } // healthcheck: only use whitelisted languages if (!in_array($language, $options["languages"])) { $language = $options["languages"][0]; } // Store the language in the resource // This also initializes the translation resource $this->resource->setLanguage($language); }
protected static function _setupPdo() { // Check the DSN string if (!isset(static::$_dsn)) { $error = "No DSN specified in " . get_called_class(); $error .= ": please specify a 'protected static \$_dsn = ...;'"; throw new Exception($error); } $user = null; $password = null; $options = array(); // If it is MySQL, extract user and password from the DSN $dsn = explode(":", static::$_dsn); if ('mysql' == $dsn[0]) { $parts = explode(";", $dsn[1]); foreach ($parts as $i => $part) { $kv = explode('=', $part); $parts[$kv[0]] = $kv[1]; unset($parts[$i]); } $user = @ZFE_Core::value($parts['user']); $password = @ZFE_Core::value($parts['password']); unset($parts['user']); unset($parts['password']); $_parts = array(); foreach ($parts as $k => $v) { $_parts[] = "{$k}={$v}"; } $dsn[1] = implode(";", $_parts); // Update default fetch mode (maybe put this in the global // function scope) $options[PDO::ATTR_DEFAULT_FETCH_MODE] = PDO::FETCH_ASSOC; } $dsn = implode(":", $dsn); static::$_pdo = new PDO($dsn, $user, $password, $options); }
/** * When unserializing a cached object, reset the language * to the interface language */ public function __wakeup() { $this->_lang = ZFE_Core::getLanguage(); }
/** * A private function to check if the remote client is using a local IP address. * Maybe this function should become a public function in the Core class. */ private function isLocal() { $ipaddr = $_SERVER['REMOTE_ADDR']; return ZFE_Core::isLocal($ipaddr); }
public function __construct($options = array()) { // TODO remove these once we are passing these values in if (!isset($options['language'])) { $options['language'] = ZFE_Core::getLanguage(); } if (!isset($options['defaultLanguage'])) { // passes $ml = Zend_Registry::get('ZFE_MultiLanguage'); $options['defaultLanguage'] = $ml->getDefault(); } if (!isset($options['layoutPath'])) { $options['layoutPath'] = APPLICATION_PATH . '/emails/layouts'; } if (!isset($options['scriptPath'])) { $options['scriptPath'] = APPLICATION_PATH . '/emails/scripts'; } // set defaults // TODO remove layoutPath, scriptPath, defaultLayout as these strictly be passed in $options = array_merge(array('defaultLayout' => 'default', 'charset' => 'UTF-8'), $options); // check layoutPath has been set if (!isset($options['layoutPath'])) { throw new Exception('Layout path not set or not found'); } // check scriptPath has been set if (!isset($options['scriptPath'])) { throw new Exception('Script path not set or not found'); } // set the layout for the emails. this will be our lovely html header and // footers making our emails look warm and fuzzy :) $this->_layout = new Zend_Layout(); $this->_layout->setLayoutPath($options['layoutPath']); if (isset($options['defaultLayout'])) { // TODO is this optional? should it be? $this->_layoutScript = $options['defaultLayout']; $this->_layout->setLayout($this->_layoutScript); } // set View $this->_view = new Zend_View(); $this->_view->setScriptPath($options['scriptPath']); // set options $this->_options = $options; // $this->_view = new Zend_View(); // // // set the base directory of where our emails scripts are located // $this->_view->setScriptPath(APPLICATION_PATH . "/emails/scripts"); // // $this->_view->addHelperPath(ZFE_Environment::getLibraryPath() . "/View/Helper", 'ZFE_View_Helper'); // $this->_view->addHelperPath(ZFE_Environment::getLibraryPath() . "/View/Helper", 'ACQ_View_Helper'); // // $module = ZFE_Environment::getModuleName(); // if ($module !== 'default') { // $cls = ucfirst(strtolower($module)) . '_View_Helper'; // $this->_view->addHelperPath(ZFE_Environment::getModulePath() . "/views/helpers", $cls); // } // // $this->_layout = new Zend_Layout(); // $this->_layout->setLayoutPath(APPLICATION_PATH . "/emails/layouts"); // $this->_layoutScript = 'default'; // $this->_layout->setLayout($this->_layoutScript); // // $this->_version = self::$_defaultVersion; // // $this->_options['language'] = ZFE_Core::getLanguage(); }
private function doAssert($val) { $this->assertEquals($val, ZFE_Core::value($val)); }
/** * Gets the browser information and caches it in a static variable */ public static function getBrowser() { if (is_null(self::$browserinfo)) { if (!isset($_SESSION['browserinfo'])) { $info = @get_browser(); $_SESSION['browserinfo'] = $info; } self::$browserinfo = $_SESSION['browserinfo']; } return self::$browserinfo; }