コード例 #1
0
ファイル: Base.php プロジェクト: wthielen/zf1e
 /**
  * Pre-dispatch routine
  *
  * This will replace the default pre-dispatch routine and call
  * the action-level pre-dispatch function, if it exists. This
  * gives us more flexibility in controlling the process flow.
  *
  * @return void
  */
 public function preDispatch()
 {
     // Get controller and action names
     $controller = $this->getRequest()->getControllerName();
     $action = $this->getRequest()->getActionName();
     // Automatically add CSS and JS
     $cssFiles = array('default.css', $controller . '.css', $controller . '/' . $action . '.css');
     $cssPrintFiles = array('default.print.css', $controller . '.print.css', $controller . '/' . $action . '.print.css');
     $headLink = $this->view->headLink();
     foreach ($cssFiles as $file) {
         if (!Zend_Loader::isReadable(ZFE_Environment::getFilePath('/css/' . $file))) {
             continue;
         }
         $headLink->appendStylesheet('/css/' . $file, 'screen, print');
     }
     foreach ($cssPrintFiles as $file) {
         if (!Zend_Loader::isReadable(ZFE_Environment::getFilePath('/css/' . $file))) {
             continue;
         }
         $headLink->appendStylesheet('/css/' . $file, 'print');
     }
     $jsFiles = array('default.js', $controller . '.js', $controller . '/' . $action . '.js');
     $headScript = $this->view->headScript();
     foreach ($jsFiles as $file) {
         if (!Zend_Loader::isReadable(ZFE_Environment::getFilePath('/js/' . $file))) {
             continue;
         }
         $headScript->appendFile('/js/' . $file);
     }
     // Call the action's pre-function
     $func = 'pre' . ucfirst(strtolower($action)) . 'Action';
     if (method_exists($this, $func)) {
         $this->{$func}();
     }
 }
コード例 #2
0
ファイル: Multilanguage.php プロジェクト: wthielen/zf1e
 public function init()
 {
     $this->resource = ZFE_Environment::getResource('Multilanguage');
     $front = Zend_Controller_Front::getInstance();
     if ($front) {
         $this->plugin = $front->getPlugin('ZFE_Plugin_Multilanguage');
     }
 }
コード例 #3
0
ファイル: HeadLink.php プロジェクト: wthielen/zf1e
 /**
  * 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;
     }
 }
コード例 #4
0
ファイル: Mongo.php プロジェクト: wthielen/zf1e
 /**
  * Returns the class name for the given collection name.
  * If it is mentioned in the mapping configuration, it will use
  * the mapping's setting for not-so-obvious mappings. This can be
  * configured in the application's configuration file.
  */
 public function getClass($collectionName)
 {
     if (isset($this->mapping[$collectionName])) {
         $cls = $this->mapping[$collectionName];
     } else {
         $cls = ZFE_Environment::getResourcePrefix('model') . '_' . ucfirst($collectionName);
     }
     return $cls;
 }
コード例 #5
0
ファイル: Jquery.php プロジェクト: wthielen/zf1e
 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());
     }
 }
コード例 #6
0
ファイル: Bootstrap.php プロジェクト: wthielen/zf1e
 private static function _initLibrary()
 {
     // Register the ZFE controller plugins as helpers
     Zend_Controller_Action_HelperBroker::addPath(ZFE_Environment::getLibraryPath() . '/Controller/Helpers', 'ZFE_Controller_Helper');
     // Load the ZFE_Plugin_ActiveModule plugin
     self::$bootstrap->bootstrap('FrontController');
     $front = self::$bootstrap->getResource('FrontController');
     $front->registerPlugin(new ZFE_Plugin_ActiveModule());
 }
コード例 #7
0
ファイル: Environment.php プロジェクト: wthielen/zf1e
 /**
  * Get the application autoloader
  *
  * This is the autoloader of class Zend_Application_Module_Autoloader.
  * In a default Zend application, there is one.
  * TODO I am not sure about modularized Zend applications - maybe there is
  * one per module, but I don't have a modularized example to test this with
  */
 public static function getApplicationAutoloader()
 {
     if (is_null(self::$autoloader)) {
         $autoloader = Zend_Loader_Autoloader::getInstance();
         $autoloaders = $autoloader->getAutoloaders();
         self::$autoloader = array_reduce($autoloader->getAutoloaders(), function ($u, $v) {
             return $u instanceof Zend_Application_Module_Autoloader ? $u : $v;
         });
     }
     return self::$autoloader;
 }
コード例 #8
0
ファイル: MultiLanguage.php プロジェクト: wthielen/zf1e
 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);
         }
     }
 }
コード例 #9
0
ファイル: Multilanguage.php プロジェクト: wthielen/zf1e
 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);
 }
コード例 #10
0
ファイル: Partial.php プロジェクト: wthielen/zf1e
 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);
 }
コード例 #11
0
ファイル: Mongo.php プロジェクト: wthielen/zf1e
 /**
  * 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;
 }
コード例 #12
0
ファイル: ActiveModule.php プロジェクト: wthielen/zf1e
 protected function _getActiveBootstrap($name)
 {
     $moduleList = ZFE_Environment::getResource('modules')->getExecutedBootstraps();
     return isset($moduleList[$name]) ? $moduleList[$name] : null;
 }
コード例 #13
0
ファイル: Core.php プロジェクト: wthielen/zf1e
 public static function halt()
 {
     $vars = func_get_args();
     self::dump(count($vars) == 1 ? array_shift($vars) : $vars);
     if (Zend_Registry::isRegistered('ZFE_DebugFilter')) {
         $debugFilter = Zend_Registry::get('ZFE_DebugFilter');
         if ($debugFilter->isAllowed()) {
             die("Halted");
         }
     }
     if (ZFE_Environment::isDevelopment()) {
         die("Halted");
     }
 }