コード例 #1
0
 /**
  * Returns the current 'base site' url, optionally with a subpath.
  *
  * @staticvar string $uri
  * @param string $subpath Optional string
  * @return string The Url + basePath plus the optional subpath
  */
 public function getCurrentURI($subpath = '')
 {
     static $uri;
     if (!$uri) {
         $uri = \MUtil_Https::on() || $this->project->isHttpsRequired() ? 'https' : 'http';
         $uri .= '://';
         $uri .= isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : $this->project->getConsoleUrl();
         $uri .= $this->basepath->getBasePath();
     }
     if ($subpath && $subpath[0] != '/') {
         $subpath = '/' . $subpath;
     }
     return $uri . $subpath;
 }
コード例 #2
0
ファイル: DatePicker.php プロジェクト: GemsTracker/MUtil
 /**
  * Set view object
  *
  * @param  \Zend_View_Interface $view
  * @return \Zend_Form_Element
  */
 public function setView(\Zend_View_Interface $view = null)
 {
     $element = parent::setView($view);
     if (null !== $view) {
         if (false === $view->getPluginLoader('helper')->getPaths('MUtil_JQuery_View_Helper')) {
             $view->addHelperPath('MUtil/JQuery/View/Helper', 'MUtil_JQuery_View_Helper');
         }
     }
     if ($locale = \Zend_Registry::get('Zend_Locale')) {
         $language = $locale->getLanguage();
         // We have a language, but only when not english
         if ($language && $language != 'en') {
             $jquery = $view->JQuery();
             if ($uiPath = $jquery->getUiLocalPath()) {
                 $baseUrl = dirname($uiPath);
             } else {
                 $baseUrl = \MUtil_Https::on() ? \ZendX_JQuery::CDN_BASE_GOOGLE_SSL : \ZendX_JQuery::CDN_BASE_GOOGLE;
                 $baseUrl .= \ZendX_JQuery::CDN_SUBFOLDER_JQUERYUI;
                 $baseUrl .= $jquery->getUiVersion();
             }
             // Option 1: download single language file
             if (version_compare($jquery->getUiVersion(), '1.11.0', '>=')) {
                 $jquery->addJavascriptFile($baseUrl . '/i18n/datepicker-' . $language . '.js');
             } else {
                 $jquery->addJavascriptFile($baseUrl . '/i18n/jquery.ui.datepicker-' . $language . '.js');
             }
             // Option 2: download all languages and select current
             // $jquery->addJavascriptFile($baseUrl . '/i18n/jquery-ui-i18n.min.js');
             // $jquery->addOnLoad("$.datepicker.setDefaults($.datepicker.regional['$language'])");
             // TODO: Option 3: enable language setting for each individual date
         }
     }
     return $element;
 }
コード例 #3
0
 /**
  * This function checks for the required project settings.
  *
  * Overrule this function or the $requiredParameters to add extra required settings.
  *
  * @see $requiredParameters
  *
  * @return void
  */
 public function checkRequiredValues()
 {
     $missing = array();
     foreach ($this->requiredKeys as $key => $names) {
         if (is_array($names)) {
             if (!($this->offsetExists($key) && $this->offsetGet($key))) {
                 $subarray = array();
             } else {
                 $subarray = $this->offsetGet($key);
             }
             foreach ($names as $name) {
                 if (!isset($subarray[$name])) {
                     $missing[] = $key . '.' . $name;
                 }
             }
         } else {
             if (!($this->offsetExists($names) && $this->offsetGet($names))) {
                 $missing[] = $names;
             }
         }
     }
     // Chek for https
     if (!\MUtil_Https::on()) {
         if ($this->isHttpsRequired()) {
             \MUtil_Https::enforce();
         }
     }
     if ($missing) {
         if (count($missing) == 1) {
             $error = sprintf("Missing required project setting: '%s'.", reset($missing));
         } else {
             $error = sprintf("Missing required project settings: '%s'.", implode("', '", $missing));
         }
         throw new \Gems_Exception_Coding($error);
     }
     $superPassword = $this->getSuperAdminPassword();
     if (('production' === APPLICATION_ENV || 'acceptance' === APPLICATION_ENV) && $this->getSuperAdminName() && $superPassword) {
         if (strlen($superPassword) < $this->minimumSuperPasswordLength) {
             $error = sprintf("Project setting 'admin.pwd' is shorter than %d characters. That is not allowed.", $this->minimumSuperPasswordLength);
             throw new \Gems_Exception_Coding($error);
         }
     }
 }
コード例 #4
0
 /**
  * Hook 3: Called in $this->setRequest.
  *
  * All resources have been loaded and the $request object is created.
  * Theoretically this event can be triggered multiple times, but this does
  * not happen in a standard Zend application.
  *
  * Not initialized are the $response and $controller objects.
  *
  * Previous hook: beforeRun()
  * Actions since: $this->request object created
  * Actions after: $this->response object created
  * Next hook: responseChanged()
  *
  * @param \Zend_Controller_Request_Abstract $request
  * @return void
  */
 public function requestChanged(\Zend_Controller_Request_Abstract $request)
 {
     if ($this->project->isMultiLocale()) {
         // Get the choosen language
         $localeId = \Gems_Cookies::getLocale($request);
         // Change when $localeId exists and is different from session
         if ($localeId && $this->locale->getLanguage() !== $localeId) {
             // \MUtil_Echo::r('On cookie ' . $localeId . ' <> ' . $this->locale->getLanguage());
             // Does the locale exist?
             if (isset($this->project->locales[$localeId])) {
                 // Add and implement the choosen locale
                 $this->session->user_locale = $localeId;
                 $this->locale->setLocale($localeId);
                 if (!$this->translate->isAvailable($localeId)) {
                     $languageFilename = APPLICATION_PATH . '/languages/default-' . $localeId . '.mo';
                     if (file_exists($languageFilename)) {
                         $this->translate->addTranslation($languageFilename, $localeId);
                     }
                 }
                 $this->translate->setLocale($localeId);
                 $this->translateAdapter = $this->translate->getAdapter();
             }
         }
     }
     // Set the base path, the route is now fixed
     $this->basepath->setBasePath($request->getBasePath());
     // Set the jQuery version and other information needed
     // by classes using jQuery
     $jquery = \MUtil_JQuery::jQuery();
     $jqueryVersion = '1.11.1';
     $jqueryUiVersion = '1.11.1';
     $jquery->setVersion($jqueryVersion);
     $jquery->setUiVersion($jqueryUiVersion);
     if ($this->project->isJQueryLocal()) {
         $jqueryDir = $request->getBasePath() . $this->project->getJQueryLocal();
         $jquery->setLocalPath($jqueryDir . 'jquery-' . $jqueryVersion . '.js');
         $jquery->setUiLocalPath($jqueryDir . 'jquery-ui-' . $jqueryUiVersion . '.js');
     } else {
         if (\MUtil_Https::on()) {
             $jquery->setCdnSsl(true);
         }
     }
     if (\MUtil_Bootstrap::enabled() && $this->project->isBootstrapLocal()) {
         $bootstrap = \MUtil_Bootstrap::bootstrap();
         $basePath = $request->getBasePath();
         $bootstrap->setBootstrapScriptPath($basePath . '/bootstrap/js/bootstrap.min.js');
         $bootstrap->setBootstrapStylePath($basePath . '/bootstrap/css/bootstrap.min.css');
         $bootstrap->setFontAwesomeStylePath($basePath . '/bootstrap/css/font-awesome.min.css');
     }
 }