Beispiel #1
0
 /**
  * Auto initialization of important params for sydney
  * @return void
  */
 public function init()
 {
     // register general sydney helpers
     $this->view->addHelperPath(Sydney_Tools_Paths::getCorePath() . '/library/Sydney/View/Helper', 'Sydney_View_Helper');
     $this->_initWebInstanceHelpers();
     // setup the basics
     $this->_registry = Zend_Registry::getInstance();
     $this->_config = $this->_registry->get('config');
     $this->_db = $this->_registry->get('db');
     $this->safinstancesId = $this->_config->db->safinstances_id;
     $this->_translate = $this->_registry->get('Zend_Translate');
     $this->view->translate = $this->_registry->get('Zend_Translate');
     $this->_auth = Sydney_Auth::getInstance();
     // Auto Login if identity and credentials stored in cookie
     $u = $this->getRequest()->getParam('username');
     $p = $this->getRequest()->getParam('password');
     if (!$this->_auth->hasIdentity() && $this->_getParam('action') != 'login' && $this->_getParam('action') != 'logout' && empty($u) && empty($p)) {
         $adapter = Sydney_Auth_Adaptater_DbTable::getAuthAdapter($this->getRequest());
         if ($adapter instanceof Zend_Auth_Adapter_Interface) {
             $auth = Sydney_Auth::getInstance();
             if ($auth->authenticate($adapter)->isValid()) {
                 $this->_helper->redirector->gotoUrl($this->getRequest()->getRequestUri());
                 exit;
             }
         }
     }
     // Init list secured pages
     $this->setAuthPagelist();
     // setup user
     $udata = new Zend_Session_Namespace('userdata');
     if (isset($udata->user)) {
         $this->usersData = $udata->user;
     }
     if (isset($this->usersData['users_id'])) {
         $this->usersId = $this->usersData['users_id'];
     }
     // sets some interesting vars in the view
     $this->view->config = $this->_config;
     $this->view->cdn = $this->_config->general->cdn;
     $this->view->users_data = $this->usersData;
     $this->view->safinstances_id = $this->safinstancesId;
     $this->view->auth = $this->_auth;
     $this->view->siteTitle = $this->_config->general->siteTitle;
     $this->view->printme = $this->_getParam('printme', 'no');
     // @todo TODO change this ...
     $llg = 'en';
     if (isset($this->_config->general->lang) && $this->_config->general->lang != '') {
         $llg = $this->_config->general->lang;
     }
     $this->view->headScript()->appendFile($this->view->cdn . '/sydneyassets/scripts/i18n/' . $llg . '.js', 'text/javascript');
     // setup some layout vars
     if ($this->layout !== null) {
         $this->layout->registry = $this->_registry;
         $this->layout->auth = $this->_auth;
         $this->layout->translate = $this->_registry->get('Zend_Translate');
         $this->layout->avmodules = $this->availableModules;
     }
     $this->view->moduleName = $this->_getParam('module');
     $this->view->controllerName = $this->_getParam('controller');
     $this->view->actionName = $this->_getParam('action');
     // set up the log
     $this->logger = new Sydney_Log();
     $this->logger->setEventItem('className', get_class($this));
     $this->logger->addFilterDatabase();
     if (isset($this->getRequest()->sydneylayout) && $this->getRequest()->sydneylayout == 'no') {
         $this->_helper->layout->disableLayout();
         $this->sydneyLayout = 'no';
     }
     if (isset($this->getRequest()->sydneylayout) && $this->getRequest()->sydneylayout != 'no' && $this->getRequest()->sydneylayout != 'yes') {
         $this->_helper->layout->setLayout('layout-' . $this->getRequest()->sydneylayout);
     }
     $this->view->sydneylayout = $this->sydneyLayout;
     /**
      * load structure if not exist
      */
     if (!is_array($this->view->structure) && $this->getRequest()->layout != 'no') {
         $this->structure = new Pagstructure();
         $this->view->adminmode = false;
         // if identified then get structure from database
         if (Sydney_Auth::getInstance()->hasIdentity()) {
             $this->structure->setFilter('status', 'published');
             $this->view->structure = $this->structure->toArray($this->safinstancesId);
         } else {
             // else use structure cached or build cache
             $cache = Zend_Registry::get('cache');
             $cn = PagstructureOp::getCacheNames($this->safinstancesId);
             $this->view->structure = $cache->load($cn[0]);
             //cn[0] > cachename
             $this->structure->stringNodes = $cache->load($cn[1]);
             //cn[1] > cachename2
             if (!is_array($this->view->structure)) {
                 $this->structure->setFilter('status', 'published');
                 $this->view->structure = $this->structure->toArray($this->safinstancesId);
                 $cache->save($this->view->structure, $cn[0]);
                 $cache->save($this->structure->getStringNodes(), $cn[1]);
             }
         }
         $r = $this->getRequest();
         if (isset($r->layout) && $r->layout == 'no') {
             Zend_Layout::getMvcInstance()->disableLayout(true);
         }
         $pages = $this->_getPageId();
         $this->view->breadCrumData = $this->structure->getBreadCrumData($this->safinstancesId, $pages[0]);
     }
     // change language if necessary
     $settingsNms = new Zend_Session_Namespace('appSettings');
     $curLang = $this->getCurrentLangCode();
     if ($settingsNms->ApplicationLanguage != $curLang) {
         $settingsNms->ApplicationLanguage = $curLang;
         $bootstrapper = Zend_Registry::get('bootstrapper');
         $bootstrapper->setRequestLang($curLang);
         $bootstrapper->setTranslationObject();
     }
     $this->view->lang = $settingsNms->ApplicationLanguage;
     $pages = isset($pages) ? $pages : $this->_getPageId();
     $this->_manageCanonicalLinks($pages[0]);
 }