public function init() { $this->resource = ZFE_Environment::getResource('Multilanguage'); $front = Zend_Controller_Front::getInstance(); if ($front) { $this->plugin = $front->getPlugin('ZFE_Plugin_Multilanguage'); } }
/** * The constructor checks if the minifier resource has been set up, and gets the * CSS minifier from the resource. */ public function __construct() { parent::__construct(); $resource = ZFE_Environment::getResource('minifier'); if ($resource) { $this->_minifier = $resource->css; } }
private static function _setDefault() { self::$options = array('enableUi' => true, 'useCdn' => false, 'cdnHost' => 'code.jquery.com', 'coreVersion' => null, 'uiVersion' => null, 'uiTheme' => 'smoothness', 'jsPath' => '/js/jquery', 'cssPath' => '/css/jquery'); // Fetch options from the application's configuration $resource = ZFE_Environment::getResource('Jquery'); if ($resource) { self::$options = array_merge(self::$options, $resource->getOptions()); } }
public function postDispatch() { parent::postDispatch(); $front = Zend_Controller_Front::getInstance(); $mlPlugin = $front->getPlugin('ZFE_Plugin_Multilanguage'); $resource = ZFE_Environment::getResource('Multilanguage'); $lang = $resource->getLanguage(); $default = $resource->getDefault(); // Add alternate URLs for the translations $languages = $resource->getLanguages(); unset($languages[$lang]); foreach ($languages as $it_lang => $language) { // Allowing override, since translated pages might have different URLs (slug, ID) if (isset($this->customAlternateURL) && isset($this->customAlternateURL[$it_lang])) { $url = $this->customAlternateURL[$it_lang]; } else { $url = $mlPlugin->composeUrl($it_lang); } $alt_lang = $it_lang; //https://support.google.com/webmasters/answer/189077?hl=en if ($it_lang == 'zh_Hans') { $alt_lang = 'zh-Hans'; } if ($it_lang == 'zh_Hant') { $alt_lang = 'zh-Hant'; } $this->view->headLink()->appendAlternate($url, 'text/html', '', array('hreflang' => $alt_lang)); } // If the action is in the i18nActions variable, update the script name to render $action = $this->getRequest()->getActionName(); if (in_array($action, $this->i18nActions)) { $viewRenderer = $this->getHelper('ViewRenderer'); // Update the script with the current language $viewRenderer->setScriptAction($action . "-" . $lang); // Check if the script exists $paths = $this->view->getScriptPaths(); $script = $viewRenderer->getViewScript(); $exists = array_reduce($paths, function ($ret, $path) use($script) { return $ret || file_exists($path . $script); }, false); // If the script does not exist, fallback to the default language // Its existence will be taken care of by the View class if (!$exists && $lang !== $default) { $viewRenderer->setScriptAction($action . "-" . $default); } } }
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); }
public function partial($origname = null, $module = null, $model = null) { if (0 == func_num_args()) { return $this; } $resource = ZFE_Environment::getResource('Multilanguage'); if (null !== $resource) { $paths = $this->view->getScriptPaths(); // Use the view's language if set, otherwise the resource's language $lang = isset($this->view->language) ? $this->view->language : $resource->getLanguage(); $default = $resource->getDefault(); // To support multiple extensions, gather the extensions in an array // This supports e.g. .ajax.phtml and .html.phtml, etc. $ext_array = array(); $name = $origname; while (($x = pathinfo($name, PATHINFO_EXTENSION)) != "") { array_unshift($ext_array, $x); $name = pathinfo($name, PATHINFO_FILENAME); } $ext = implode(".", $ext_array); $name = substr_replace($origname, "-" . $lang, strrpos($origname, $ext) - 1, 0); $exists = array_reduce($paths, function ($ret, $path) use($name) { return $ret || file_exists($path . $name); }, false); if (!$exists && $lang !== $default) { $name = substr_replace($origname, "-" . $default, strrpos($origname, $ext) - 1, 0); $exists = array_reduce($paths, function ($ret, $path) use($name) { return $ret || file_exists($path . $name); }, false); } if (!$exists) { $name = $origname; } } else { $name = $origname; } return parent::partial($name, $module, $model); }
/** * Registers the MongoDB application plugin resource and initializes it, when a * connection is requested. It stores the plugin resource as a static entry in * the model. */ public static final function getResource() { if (null === self::$resource) { self::$resource = ZFE_Environment::getResource('Mongo'); } return self::$resource; }
protected function _getActiveBootstrap($name) { $moduleList = ZFE_Environment::getResource('modules')->getExecutedBootstraps(); return isset($moduleList[$name]) ? $moduleList[$name] : null; }