File indexing completed on 2025-03-09 05:25:33

0001 <?php
0002 
0003 /**
0004  *  ocs-webserver
0005  *
0006  *  Copyright 2016 by pling GmbH.
0007  *
0008  *    This file is part of ocs-webserver.
0009  *
0010  *    This program is free software: you can redistribute it and/or modify
0011  *    it under the terms of the GNU Affero General Public License as
0012  *    published by the Free Software Foundation, either version 3 of the
0013  *    License, or (at your option) any later version.
0014  *
0015  *    This program is distributed in the hope that it will be useful,
0016  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
0017  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0018  *    GNU Affero General Public License for more details.
0019  *
0020  *    You should have received a copy of the GNU Affero General Public License
0021  *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0022  **/
0023 class Local_Controller_Action_DomainSwitch extends Zend_Controller_Action
0024 {
0025 
0026     const METAHEADER_DEFAULT = 'meta_keywords';
0027     const METAHEADER_DEFAULT_TITLE = 'opendesktop.org';
0028     const METAHEADER_DEFAULT_DESCRIPTION = 'A community where developers and artists share applications, themes and other content';
0029     const METAHEADER_DEFAULT_KEYWORDS = 'opendesktop,linux,kde,gnome,themes,apps,desktops,applications,addons,artwork,wallpapers';
0030     /**
0031      * Zend_Controller_Request_Abstract object wrapping the request environment
0032      * @var Zend_Controller_Request_Http
0033      */
0034     protected $_request = null;
0035     /** @var  object */
0036     protected $_authMember;
0037     protected $templateConfigData;
0038     protected $defaultConfigName;
0039 
0040     public function init()
0041     {
0042         $this->initDefaultConfigName();
0043         $this->initAuth();
0044         $this->initTemplateData();
0045         $this->initView();
0046         $this->setLayout();
0047         $this->_initResponseHeader();
0048         $this->_initAdminDbLogger();
0049     }
0050 
0051     protected function initDefaultConfigName()
0052     {
0053         $config = Zend_Registry::get('config');
0054         $this->defaultConfigName = $config->settings->client->default->name;
0055     }
0056 
0057     protected function initAuth()
0058     {
0059         $auth = Zend_Auth::getInstance();
0060 
0061         // Design issue: getStorage()->read() should return an empty member object for unknown user. This is a workaround for the moment.
0062         if ($auth->hasIdentity()) {
0063             $this->_authMember = $auth->getStorage()->read();
0064         } else {
0065             $tableMember = new Default_Model_Member();
0066             $this->_authMember = $tableMember->createRow();
0067         }
0068     }
0069 
0070     /**
0071      * @throws Zend_Exception
0072      */
0073     private function initTemplateData()
0074     {
0075         if (Zend_Registry::isRegistered('store_template')) {
0076             $this->templateConfigData = Zend_Registry::get('store_template');
0077 
0078             return;
0079         }
0080 
0081         $this->templateConfigData = Default_Model_StoreTemplate::getStoreTemplate($this->getNameForStoreClient());
0082     }
0083 
0084     /**
0085      * Returns the name for the client. If no name were found, the name for the standard client will be returned.
0086      *
0087      * @return string
0088      * @throws Zend_Exception
0089      */
0090     public function getNameForStoreClient()
0091     {
0092         $clientName = $this->defaultConfigName; //set to default
0093 
0094         if (Zend_Registry::isRegistered('store_config_name')) {
0095             $clientName = Zend_Registry::get('store_config_name');
0096         }
0097 
0098         return $clientName;
0099     }
0100 
0101     public function initView()
0102     {
0103         if (!Zend_Registry::isRegistered('headMetaSet')) {
0104 
0105             $headTitle = $this->getHeadTitle();
0106             $headDesc = $this->templateConfigData['head']['meta_description'];
0107             $headKeywords = $this->templateConfigData['head']['meta_keywords'];
0108             //set default site-title
0109             $this->view->headTitle($headTitle, Zend_View_Helper_Placeholder_Container_Abstract::SET);
0110             if ($headDesc == $this::METAHEADER_DEFAULT) {
0111                 $headDesc = $this::METAHEADER_DEFAULT_DESCRIPTION;
0112             }
0113             if ($headKeywords == $this::METAHEADER_DEFAULT) {
0114                 $headKeywords = $this::METAHEADER_DEFAULT_KEYWORDS;
0115             }
0116 
0117             $this->view->headMeta()
0118                        ->appendName('author', $this->templateConfigData['head']['meta_author'])
0119                        ->appendName('robots', 'all')
0120                        ->appendName('robots', 'index')
0121                        ->appendName('robots', 'follow')
0122                        ->appendName('revisit-after', '3 days')
0123                        ->appendName('title', $headTitle)
0124                        ->appendName('description', $headDesc, array('lang' => 'en-US'))
0125                        ->appendName('keywords', $headKeywords, array('lang' => 'en-US'));
0126 
0127             Zend_Registry::set('headMetaSet', true);
0128         }
0129 
0130         $this->view->template = $this->templateConfigData;
0131     }
0132 
0133     public function getHeadTitle()
0134     {
0135         $headTitle = $this->templateConfigData['head']['browser_title'];
0136         if ($headTitle == $this::METAHEADER_DEFAULT) {
0137             $headTitle = $this::METAHEADER_DEFAULT_TITLE;
0138         }
0139 
0140         return $headTitle;
0141     }
0142 
0143     protected function setLayout()
0144     {
0145         $layoutName = 'flat_ui_template';
0146         $storeConfig = Zend_Registry::isRegistered('store_config') ? Zend_Registry::get('store_config') : null;
0147         if ($storeConfig && $storeConfig->layout) {
0148             $this->_helper->layout()->setLayout($storeConfig->layout);
0149         } else {
0150             $this->_helper->layout()->setLayout($layoutName);
0151         }
0152     }
0153 
0154     protected function _initResponseHeader()
0155     {
0156         $duration = 1800; // in seconds
0157         $expires = gmdate("D, d M Y H:i:s", time() + $duration) . " GMT";
0158 
0159         $this->getResponse()
0160              ->setHeader('X-FRAME-OPTIONS', 'ALLOWALL', true)
0161 //            ->setHeader('Last-Modified', $modifiedTime, true)
0162              ->setHeader('Expires', $expires, true)
0163              ->setHeader('Pragma', 'no-cache', true)
0164              ->setHeader('Cache-Control', 'private, no-store, no-cache, must-revalidate, post-check=0, pre-check=0',true);
0165     }
0166 
0167     private function _initAdminDbLogger()
0168     {
0169         if (Zend_Auth::getInstance()->hasIdentity() AND Zend_Auth::getInstance()->getIdentity()->roleName == 'admin') {
0170             $profiler = new Zend_Db_Profiler();
0171             $profiler->setEnabled(true);
0172 
0173             // Attach the profiler to your db adapter
0174             Zend_Db_Table::getDefaultAdapter()->setProfiler($profiler);
0175             /** @var Zend_Db_Adapter_Abstract $db */
0176             $db = Zend_Registry::get('db');
0177             $db->setProfiler($profiler);
0178             Zend_Registry::set('db', $db);
0179         }
0180     }
0181 
0182 }