getServiceLocator()->get('config'); $this->cfg = $conf; session_set_cookie_params( null , '/' , '.esculap.com' ); //$this->content_ignoreSpecValue = (int)@$this->cfg[ 'ignore_spec' ]; /** * Proteza jaksiemasz. * - zamienia wartość klucza SPEC_TYPES w \System\Content\Config na array() co powoduje, że niema filtrowania kontentu */ if( $this->content_ignoreSpecValue == 1 ) { Config::ignoreSpecs( true ); } $this->view = new ViewModel(); $this->getEventManager()->attach( '*' , function( $e ) { //GlobalObserver::setLogger( $this->logger ); GlobalObserver::notify( $e->getName(), $e->getParams(), $e->getTarget() ); }); //obiekt logowania $this->logger = $this->getServiceLocator()->get( 'logger' ); // inicializacja obiektu obsługującego cookie $cookieStorage = new CookieStorage(); $this->cookieLang = $cookieStorage->getLang(); // inicializacja obiektu Identity $this->identity = new \System\Authentication\AuthenticationIdentity( $cookieStorage ); // pobranie uchwytu dla bazy danych dla sesji $sessionDbHandle = $conf['database']['session']; $this->layout()->elogin_url = $conf[ 'elogin' ]; $this->layout()->productin = (bool)@$conf[ 'productin' ]; if( isset( $conf[ 'pivik' ] ) ) { $this->layout()->pivik_target1 = @$conf[ 'pivik' ][ 'target1' ]; $this->layout()->pivik_target2 = @$conf[ 'pivik' ][ 'target2' ]; } $this->auth = new AuthenticationService(); $this->auth->setStorage(new AuthenticationStorage(3600,$sessionDbHandle)); // przekazanie do layoutu długości trwamnia sesji w sekundach w celu odświerzenia strony po zakończeniu się sesji $this->layout()->sessionExpireSeconds = 3600; $storage = $this->auth->getStorage(); $this->readLanguage(); //trigger_error( $this->lang ); $this->_siteCode = $conf['site'][ $this->lang ]['code']; //exit( $this->_siteCode ); $siteCode = $this->_siteCode; $userCode = isset($_SESSION['AUTH']['user_code']) ? $_SESSION['AUTH']['user_code'] : null; $this->_userCode = $userCode; //trigger_error( $userCode ); $authAdapter = new AuthenticationAdapter( $siteCode, $userCode, false, true, $this->lang, $this->cfg[ 'sauth' ][ $this->lang ], $this->cfg[ 'elogin' ] ); $this->authAdapter = $authAdapter; // ustawienie domyślnego adaptera. Przeniesione tu żeby możliwe było debugowanie kontentu i banerów. $adapter = \System\Database\StandardAdapter::getInstance( $this->cfg['database']['adapter']['int_esculap'] ); $adapter->createStatement( 'SET search_path TO esculap_int , elearning, public, postfix, data_buff' )->execute(); $_SESSION['content_added'] = 1; if( !$this->preCheckContentDebug() && !$this->isBcViewMode() ) { // przed sprawdzeniem czy użytkownik jest zalogowany sprawdzam czy akcja nie wykonywana jest ajaxe. // jeśli tak to czy identyfikator routingu nie jest jednym z trzecz dostępnych na stronie głównej ładujących wiadomości z kraju, świata nauki z zagranicy if( $this->request->isXmlHttpRequest() ) { if( $this->getEvent()->getRouteMatch()->getMatchedRouteName() == 'news_from_home_list' || $this->getEvent()->getRouteMatch()->getMatchedRouteName() == 'news_from_abroad_list' || $this->getEvent()->getRouteMatch()->getMatchedRouteName() == 'news_from_sience_world_list' ) { $authAdapter->logRequire( false ); } } if( !$this->auth->hesIdentity( $authAdapter ) ) { $this->auth->clearIdentity(); $this->initLayout = false; $gate = false; if( $this->request->isPost() ) { $result = $this->auth->authenticate( $authAdapter ); if( !(bool)$result->getCode() ) { $_SESSION[ 'backurl' ] = $_SERVER[ 'REQUEST_URI' ]; exit( header( 'Location: /main' ) ); } else { $this->identity->setData( $this->auth->getIdentity() ); } } else { if( $isAuthRequire ) { $routeName = $this->getEvent()->getRouteMatch()->getMatchedRouteName(); if( 'main' !== $routeName && 'home' !== $routeName && 'login' !== $routeName ) { $_SESSION[ 'backurl' ] = $_SERVER[ 'REQUEST_URI' ]; //return $this->redirect()->toRoute(); exit( header( 'Location: /login' ) ); } exit( header( 'Location: /main' ) ); } $gate = true; } if( $this->auth->getIdentity() ) { $this->identity->setData( $this->auth->getIdentity() ); // zapisanie do cookisów specializacji w celu zpersonalizowania strony bramki $this->identity->cookie()->setSpec($this->identity->specs); $this->_userCode = $this->identity->user_code; //sprawdzam czy użytkownik zatwierdził regulamin //$MainUsers = new \Model\MainUsers; /* if( !$MainUsers->getAcceptRegulationsForUser( $this->identity->id ) && 'main_regulations' !== $this->getEvent()->getRouteMatch()->getMatchedRouteName() ) { $this->redirect()->toRoute( 'main_regulations' ); } */ } } else { $this->initLayout = false; if( $this->preCheckContentDebug() ) { /** / przykładowy input wykorzystujący plik contentPhrase.js: / / atrybut spec może być ustaiony na auto - wtedy automatycznie wybrane zostaną specializacje dla tego contentu */ $this->initLayout = true; $this->layout()->contentDebug = 1; $this->contentDebug = 1; $this->identity = new \System\Authentication\AuthenticationIdentity( array() ); $this->setContentDebug(); // ustawiam flagi unieważniające zliczanie odsłon kontentu i banerów \System\BannerCampaign\BannerObserver::$COUNT_STATISTICS = false; } elseif( $this->isBcViewMode() ) { $this->initLayout = true; $this->commentsAddPossybility = false; $this->contentEvaluationPossibility = false; $authAdapter->logRequire( false ); $this->contentDebug = 1; $UserImpersonate = new UserImpersonate( $this->identity ); $UserImpersonate->setSpect( array( '01' ) ); } } $this->view->identity = $this->identity; $this->layout()->identity = $this->identity; $this->view->lang = $this->lang; $this->layout()->lang = $this->lang; // ustawianie schematu kontentu $this->setSchema(); //\System\Database\AbstractTable::setContentSchema($lang.'_content'); // inicializacja translatora Registry::set('lang',$this->lang); Registry::set('system','e'); $this->view->translator = $this->translator(); $this->layout()->translator = $this->translator(); $this->layout()->keywords = $this->translator()->translate( 'main_meta_tag_keywords' ); $this->layout()->description = $this->translator()->translate( 'main_meta_tag_description ' ); $this->layout()->title = $this->translator()->translate( 'main_meta_tag_title' ); // obiekt przechwytujący niezłapane wyjątki i przekierowujący na inną stronę $controller = $this; $log = $this->logger; $this->getEventManager()->attach('error',function($e) use($log,$controller) { $log->crit('Nazwa '.$e->getName().",target ".(get_class($e->getTarget())).'. Dump: '.var_dump($e->getParams()),__METHOD__,__LINE__); $controller->redirect()->toUrl('/error'); }); //exit( (int)$this->bcViewMode ); // jeśli inicializacja nie została jeszcze wykonana i nie ustalo że inicializacja layoutu nie powinna sie odbyć inicializuję layout i kampanię banerową if( false == self::$isInit && !isset( $this->noLayout ) ) { // zmienione na potrzeby misca: na miscu niema layoutu ( prawej kolumny ) ale jest potrzeba wyświetlenie billboardu if( true === $this->initLayout ) { $this->initBannerCampaigns(); $this->initLayout(); } self::$isInit = true; } } protected function readLanguage() { if( null == $this->lang && null !== $this->cookieLang ) { $this->lang = $this->cookieLang; } elseif( null !== $this->lang ) { // zapisanie wartości lang jeśli jeest przekazana w gecie w celu utrzymania kompatybilności z poniższym sposobem wybierania języka. $lang = $this->lang; } elseif( preg_match('/^(www\.)?(pl|ru)\.(.*)/',$_SERVER['HTTP_HOST'],$matches) ) { $lang = $matches[2]; $this->lang = $lang; } elseif( null == $this->lang ) { $lang = $this->identity->cookie()->getLang(); if($lang == null) { // jeśli język nie został ustawiony wcześniej pobieram pierwszy język akceptowany w przeglądarce, jeśli ten język jest nieobsługiwany ustawiam domyślny język. if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && in_array(strtolower(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2)),array('pl','ru','ua'))) { $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2); } else { $lang = 'pl'; } } $this->lang = $lang; } } /** * Sprawdzam czy używam podglądu contentu * */ protected function isBcViewMode() { if( null !== $this->bcViewMode ) return $this->bcViewMode; if( $this->request->getQuery( 'bcvcode' , false ) ) { $this->readLanguage(); $this->setSchema(); $bcViewModeCode = $this->request->getQuery( 'bcvcode' ); $MainBcViewCode = new \Model\MainBcViewCode; try { if( ( $codeData = $MainBcViewCode->getCodeSettings( $bcViewModeCode , true ) ) ) { $this->bcViewModeElements = explode( ',' , $codeData[ 'elements' ] ); $this->bcViewModeCode = $bcViewModeCode; $this->bcViewMode = true; $this->bcViewModeUrl = '?bcvcode=' . $this->bcViewModeCode; $this->layout()->addToHrefs = $this->bcViewModeUrl; $this->getEventManager()->trigger( 'content_debug', $this, array( 'state' => true, 'namespace' => __NAMESPACE__, 'line' => __LINE__ ) ); return true; } } catch( \Exception $e ) { $this->logger()->err( $e->getMessage() , __METHOD__ , __LINE__ ); } } $this->bcViewMode = false; return false; } /** * Wyłączakonieczność logowania */ protected function preCheckContentDebug() { if( null !== $this->request->getQuery( 'content_debug' , null ) && ( 'news_content' == $this->getEvent()->getRouteMatch()->getMatchedRouteName() || 'news_contentnews_view_unsaved' == $this->getEvent()->getRouteMatch()->getMatchedRouteName() || 'event_content' == $this->getEvent()->getRouteMatch()->getMatchedRouteName() || 'event_contentnews_view_unsaved' == $this->getEvent()->getRouteMatch()->getMatchedRouteName() || 'publications_content' == $this->getEvent()->getRouteMatch()->getMatchedRouteName() || 'publications_content_view_unsaved' == $this->getEvent()->getRouteMatch()->getMatchedRouteName() ) ) { return true; } return false; } /** * Ustawia debugowanie kontentu */ protected function setContentDebug() { if( $this->preCheckContentDebug() ) { // ustawianie języka i schematu $lang = $this->request->getQuery('lang'); $this->lang = $lang; // pobranie listy specializacji przesłanych getem $specs = $this->request->getQuery( 'spec' ); $this->getEventManager()->trigger( 'content_debug', $this, array( 'state' => true, 'namespace' => __NAMESPACE__, 'line' => __LINE__ ) ); if( $specs == 'auto' ) { $this->setSchema(); $id = $this->getEvent()->getRouteMatch()->getParam('id'); $RelContentSpec = new \Model\RelContentSpec; $specs = $RelContentSpec->getSpecsForContent( $id ); $specsValid = false; foreach( $specs as $spec ) { if( strlen( $spec ) > 0 ) { $specsValid = true; break; } } // zabezpieczenie przed żuceniem wyjądku w przypadku gdy niema żadnej specializacji if( !count( $specs ) || !$specsValid ) { $specs = array( 1 ); } } elseif( strlen( $specs ) ) { $specs = explode( ',' , $this->request->getQuery( 'spec' , array() ) ); } else { $specs = array( 1 ); } $UserImpersonate = new UserImpersonate( $this->identity ); $UserImpersonate->setSpect( $specs ); } } /** * Ustawia debugowanie fraz */ protected function checkPhraseDebug() { $this->translator()->debug( true ); $this->layout()->phraseDebug = 1; } public function initTranslator($lang) { $translator = new \System\Translator\Translator($lang); return $translator; } protected function initLayout() { /*$newWidthComment = ContentFactory::factory(new Config(array( 'CONTENT_TYPE' => 'news', 'SPEC_TYPES' => $this->identity->spec_code, 'ROWS_NUMBER' => 1, 'ROWS_START' => 0, //'GET_COMMENTS' => 1, 'NOT_CONTENT_ID' => array( $this->currentWatchContentId ), )));*/ $news = ContentFactory::factory(new Config(array( 'CONTENT_TYPE' => 'news', 'SPEC_TYPES' => $this->identity->spec_code, 'ROWS_NUMBER' => 11, 'ROWS_START' => 0, 'NOT_CONTENT_ID' => array( $this->currentWatchContentId ), ))); if( isset( $news[ 0 ] ) ) { $newWidthComment = array( $news[ 0 ] ); } else { $newWidthComment = array(); } /*$mostRead_first = ContentFactory::factory(new Config(array( 'CONTENT_TYPE' => null, 'SPEC_TYPES' => $this->identity->spec_code, 'ROWS_NUMBER' => 1, 'ROWS_START' => 1, 'SEARCH_QUERY' => array( 'date_start_lt' => '1 day' ) ) , true ));*/ // mostRead //$this->layout()->mostRead = 1; /*$mostRead = array( '4 dni' => array( $mostReadFirst_Main, $mostReadFirst_Links, ) );*/ $publWidthomment = ContentFactory::factory(new Config(array( 'CONTENT_TYPE' => 'publication', 'SPEC_TYPES' => $this->identity->spec_code, 'ROWS_NUMBER' => 1, 'ROWS_START' => 0, 'GET_COMMENTS' => 1, 'NOT_CONTENT_ID' => array( $this->currentWatchContentId ), ))); $publ = ContentFactory::factory(new Config(array( 'CONTENT_TYPE' => 'publication', 'SPEC_TYPES' => $this->identity->spec_code, 'ROWS_NUMBER' => 10, 'ROWS_START' => 1, 'NOT_CONTENT_ID' => array( $this->currentWatchContentId ), ))); $events = ContentFactory::factory(new Config(array( 'CONTENT_TYPE' => 'event', 'SPEC_TYPES' => $this->identity->spec_code, 'ROWS_NUMBER' => 2, 'ROWS_START' => 0, 'NOT_CONTENT_ID' => array( $this->currentWatchContentId ), ))); $specialForYou = array(); /*$specialForYou = ContentFactory::factory(new Config(array( 'CONTENT_TYPE' => 'event', 'SPEC_TYPES' => $this->identity->spec_code, 'ROWS_NUMBER' => 1, 'ROWS_START' => 0, 'NOT_CONTENT_ID' => array( $this->currentWatchContentId ), )));*/ $this->layout()->contents = array( 'specialForYou' => $specialForYou, 'mainNews' => $newWidthComment, 'news' => $news, 'mainPubl' => $publWidthomment, 'publ' => $publ, 'events' => $events, ); } public function &translator() { $sm = $this->getServiceLocator(); $t = $sm->get('translatorEx'); return $t; } protected function initBannerCampaignEx() { if( !$this->bcViewMode ) { $bcElements = $this->getElementFormWbserv(); } else { $bcElements = $this->loadElementsFoCode(); } if( false == $bcElements ) { $this->logger()->err( 'The creation of the elements of the campaign was not possible' , __METHOD__ , __LINE__ ); } \System\View\Helper\BannerDisplayer::init( $bcElements ); } protected function getElementFormWbserv() { try { $this->wbServClient = new WbServClient( $this->_siteCode, $this->_userCode, $this->lang, $this->cfg[ 'wbserv_addr' ] ); } catch( \Exception $e ) { $this->logger()->err( $e->getMessage() , __NAMESPACE__ , __LINE__ ); $this->selectedBcElements = array(); return false; } if( true === $this->noBcInit ) { return false; } /*switch( $this->getEvent()->getRouteMatch()->getMatchedRouteName() ) { case 'misc': $setName = 'esc.com.misc'; break; case 'home': $setName = 'esc.com.main'; break; default: $setName = 'esc.com.sub'; }*/ $setName = $this->getEvent()->getRouteMatch()->getMatchedRouteName() == 'home' ? 'esc.com.main' : 'esc.com.sub'; $bcElements = $this->wbServClient->getElements( $setName ); foreach( $bcElements as $key => $bcElementData ) { $bcElements[ $key ] = \System\BannerCampaign\Element\ElementFactory::createElement( $bcElementData ); } return $bcElements; } protected function loadElementsFoCode() { try { $bcElements = \System\BannerCampaign\Element\ElementFactory::get( $this->bcViewModeElements ); $bcElements = \System\BannerCampaign\Element\ElementDecorator::decorateElement( $bcElements , $this->lang ); return $bcElements; } catch( \Exception $e ) { $this->logger()->err( $e->getMessage() , __METHOD__ , __LINE__ ); } return false; } public function initBannerCampaigns() { $this->initBannerCampaignEx(); } public function logger() { return $this->logger; } // ustawianie schematu kontentu public function setSchema() { \System\Database\AbstractTable::setContentSchema( $this->lang .'_content'); } } ?>