File indexing completed on 2025-03-02 05:29:09

0001 <?php
0002 
0003 /**
0004  *  ocs-apiserver
0005  *
0006  *  Copyright 2016 by pling GmbH.
0007  *
0008  *    This file is part of ocs-apiserver.
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     /**
0027      * Zend_Controller_Request_Abstract object wrapping the request environment
0028      * @var Zend_Controller_Request_Http
0029      */
0030     protected $_request = null;
0031 
0032     /** @var  object */
0033     protected $_authMember;
0034     protected $templateConfigData;
0035     protected $defaultConfigName;
0036 
0037     public function init()
0038     {
0039         $this->initDefaultConfigName();
0040 //        $this->initAuth();
0041         //$this->setLayout();
0042         //$this->_initResponseHeader();
0043         //$this->_initAdminDbLogger();
0044     }
0045 
0046     protected function initDefaultConfigName()
0047     {
0048         $config = Zend_Registry::get('config');
0049         $this->defaultConfigName = $config->settings->client->default->name;
0050     }
0051 
0052     protected function initAuth()
0053     {
0054         $auth = Zend_Auth::getInstance();
0055 
0056         // Design issue: getStorage()->read() should return an empty member object for unknown user. This is a workaround for the moment.
0057         if ($auth->hasIdentity()) {
0058             $this->_authMember = $auth->getStorage()->read();
0059         } else {
0060             $tableMember = new Application_Model_Member();
0061             $this->_authMember = $tableMember->createRow();
0062         }
0063     }
0064 
0065     /**
0066      * @return string
0067      */
0068     protected function getDomainPostfix()
0069     {
0070         return '_' . $this->getNameForStoreClient();
0071     }
0072 
0073     /**
0074      * Returns the name for the emporium client. If no name were found, the name for the standard client will be returned.
0075      *
0076      * @return string
0077      */
0078     public function getNameForStoreClient()
0079     {
0080         $clientName = 'pling'; // set to default
0081 
0082         if (Zend_Registry::isRegistered('store_config_name')) {
0083             $clientName = Zend_Registry::get('store_config_name');
0084         }
0085 
0086         return $clientName;
0087     }
0088 
0089     protected function setLayout()
0090     {
0091         $layoutName = 'flat_ui_template';
0092 
0093         $this->_helper->layout()->setLayout($layoutName);
0094     }
0095 
0096     protected function _initResponseHeader()
0097     {
0098         $duration = 1800; // in seconds
0099         $expires = gmdate("D, d M Y H:i:s", time() + $duration) . " GMT";
0100 
0101         $this->getResponse()
0102             ->setHeader('X-FRAME-OPTIONS', 'SAMEORIGIN', true)
0103 //            ->setHeader('Last-Modified', $modifiedTime, true)
0104             ->setHeader('Expires', $expires, true)
0105             ->setHeader('Pragma', 'no-cache', true)
0106             ->setHeader('Cache-Control', 'private, no-store, no-cache, must-revalidate, post-check=0, pre-check=0',
0107                 true)
0108         ;
0109    }
0110 
0111     private function _initAdminDbLogger()
0112     {
0113         if (Zend_Auth::getInstance()->hasIdentity() AND Zend_Auth::getInstance()->getIdentity()->roleName == 'admin') {
0114             $profiler = new Zend_Db_Profiler();
0115             $profiler->setEnabled(true);
0116 
0117             // Attach the profiler to your db adapter
0118             Zend_Db_Table::getDefaultAdapter()->setProfiler($profiler);
0119             /** @var Zend_Db_Adapter_Abstract $db */
0120             $db =  Zend_Registry::get('db');
0121             $db->setProfiler($profiler);
0122             Zend_Registry::set('db', $db);
0123         }
0124     }
0125 
0126 }