예제 #1
0
 /**
  * Loading ClassLoader, EventManager, Env, DB, API and InitCMS
  * (Env, API and InitCMS are deprecated)
  * @todo Remove deprecated elements
  * @todo Remove usage of globals
  * @global array $_CONFIG
  * @global type $_FTPCONFIG
  * @global type $objDatabase
  * @global type $objInit
  */
 protected function init()
 {
     global $objDatabase, $objInit, $_DBCONFIG, $_CONFIG;
     $this->tryToSetMemoryLimit();
     /**
      * Include all the required files.
      * @todo Remove API.php, it should be unnecessary
      */
     $this->cl->loadFile($this->codeBaseCorePath . '/API.php');
     // Temporary fix until all GET operation requests will be replaced by POSTs
     if ($this->mode != self::MODE_BACKEND) {
         \Cx\Core\Csrf\Controller\Csrf::setFrontendMode();
     }
     // Set database connection details
     $objDb = new \Cx\Core\Model\Model\Entity\Db();
     $objDb->setHost($_DBCONFIG['host']);
     $objDb->setName($_DBCONFIG['database']);
     $objDb->setTablePrefix($_DBCONFIG['tablePrefix']);
     $objDb->setDbType($_DBCONFIG['dbType']);
     $objDb->setCharset($_DBCONFIG['charset']);
     $objDb->setCollation($_DBCONFIG['collation']);
     $objDb->setTimezone($_DBCONFIG['timezone']);
     // Set database user details
     $objDbUser = new \Cx\Core\Model\Model\Entity\DbUser();
     $objDbUser->setName($_DBCONFIG['user']);
     $objDbUser->setPassword($_DBCONFIG['password']);
     // Initialize database connection
     $this->db = new \Cx\Core\Model\Db($objDb, $objDbUser, $this->getComponent('Cache')->getCacheDriver());
     $objDatabase = $this->db->getAdoDb();
     \Env::set('db', $objDatabase);
     $em = $this->db->getEntityManager();
     \Env::set('pageguard', new \PageGuard($this->db->getAdoDb()));
     \DBG::set_adodb_debug_mode();
     $this->eventManager = new \Cx\Core\Event\Controller\EventManager($this);
     new \Cx\Core\Event\Controller\ModelEventWrapper($this);
     $this->eventManager->addEvent('preComponent');
     $this->eventManager->addEvent('postComponent');
     // Initialize base system
     // TODO: Get rid of InitCMS class, merge it with this class instead
     $objInit = new \InitCMS($this->mode == self::MODE_FRONTEND ? 'frontend' : 'backend', \Env::get('em'));
     \Env::set('init', $objInit);
     //$bla = $em->getRepository('Cx\Core\ContentManager\Model\Entity\Page');
     //$bla->findAll();
 }
예제 #2
0
 /**
  * Parses the main template in order to finish request
  * @todo Remove usage of globals
  * @global type $themesPages
  * @global null $moduleStyleFile
  * @global type $objCache
  * @global array $_CONFIG
  * @global type $subMenuTitle
  * @global type $_CORELANG
  * @global type $plainCmd
  * @global type $cmd
  */
 protected function finalize()
 {
     global $themesPages, $moduleStyleFile, $objCache, $_CONFIG, $subMenuTitle, $_CORELANG, $plainCmd, $cmd;
     if ($this->mode == self::MODE_FRONTEND) {
         // parse system
         $parsingTime = $this->stopTimer();
         $this->template->setVariable('PARSING_TIME', $parsingTime);
         $this->parseGlobalPlaceholders($themesPages['sidebar']);
         $this->template->setVariable(array('SIDEBAR_FILE' => $themesPages['sidebar'], 'JAVASCRIPT_FILE' => $themesPages['javascript'], 'BUILDIN_STYLE_FILE' => $themesPages['buildin_style'], 'DATE_YEAR' => date('Y'), 'DATE_MONTH' => date('m'), 'DATE_DAY' => date('d'), 'DATE_TIME' => date('H:i'), 'BUILDIN_STYLE_FILE' => $themesPages['buildin_style'], 'JAVASCRIPT_LIGHTBOX' => '<script type="text/javascript" src="lib/lightbox/javascript/mootools.js"></script>
                 <script type="text/javascript" src="lib/lightbox/javascript/slimbox.js"></script>', 'JAVASCRIPT_MOBILE_DETECTOR' => '<script type="text/javascript" src="lib/mobiledetector.js"></script>'));
         if (!empty($moduleStyleFile)) {
             $this->template->setVariable('STYLE_FILE', "<link rel=\"stylesheet\" href=\"{$moduleStyleFile}\" type=\"text/css\" media=\"screen, projection\" />");
         }
         if (!$this->resolvedPage->getUseSkinForAllChannels() && isset($_GET['pdfview']) && intval($_GET['pdfview']) == 1) {
             $this->cl->loadFile($this->codeBaseCorePath . '/pdf.class.php');
             $pageTitle = $this->resolvedPage->getTitle();
             $objPDF = new \PDF();
             $objPDF->title = $pageTitle . (empty($pageTitle) ? null : '.pdf');
             $objPDF->content = $this->template->get();
             $objPDF->Create();
             exit;
         }
         //enable gzip compressing of the output - up to 75% smaller responses!
         //commented out because of certain php.inis generating a
         //WARNING: ob_start(): output handler 'ob_gzhandler' cannot be used after 'URL-Rewriter
         //ob_start("ob_gzhandler");
         // fetch the parsed webpage
         $this->template->setVariable('JAVASCRIPT', 'javascript_inserting_here');
         $endcode = $this->template->get();
         /**
          * Get all javascripts in the code, replace them with nothing, and register the js file
          * to the javascript lib. This is because we don't want something twice, and there could be
          * a theme that requires a javascript, which then could be used by a module too and therefore would
          * be loaded twice.
          */
         /* Finds all uncommented script tags, strips them out of the HTML and
          * stores them internally so we can put them in the placeholder later
          * (see JS::getCode() below)
          */
         \JS::findJavascripts($endcode);
         /*
          * Proposal:  Use this
          *     $endcode = preg_replace_callback('/<script\s.*?src=(["\'])(.*?)(\1).*?\/?>(?:<\/script>)?/i', array('JS', 'registerFromRegex'), $endcode);
          * and change JS::registerFromRegex to use index 2
          */
         // i know this is ugly, but is there another way
         $endcode = str_replace('javascript_inserting_here', \JS::getCode(), $endcode);
         // do a final replacement of all those node-urls ({NODE_<ID>_<LANG>}- placeholders) that haven't been captured earlier
         $endcode = preg_replace('/\\[\\[([A-Z0-9_-]+)\\]\\]/', '{\\1}', $endcode);
         \LinkGenerator::parseTemplate($endcode);
         // remove the meta tag X-UA-Compatible if the user agent ist neighter internet explorer nor chromeframe
         if (!preg_match('/(msie|chromeframe)/i', $_SERVER['HTTP_USER_AGENT'])) {
             $endcode = preg_replace('/<meta.*?X-UA-Compatible.*?>/i', '', $endcode);
         }
         // replace links from before contrexx 3
         $ls = new \LinkSanitizer($this->codeBaseOffsetPath . \Env::get('virtualLanguageDirectory') . '/', $endcode);
         $endcode = $ls->replace();
         echo $endcode;
         $objCache->endContrexxCaching($this->resolvedPage);
     } else {
         // backend meta navigation
         if ($this->template->blockExists('backend_metanavigation')) {
             // parse language navigation
             if ($this->template->blockExists('backend_language_navigation') && $this->template->blockExists('backend_language_navigation_item')) {
                 $backendLanguage = \FWLanguage::getActiveBackendLanguages();
                 if (count($backendLanguage) > 1) {
                     $this->template->setVariable('TXT_LANGUAGE', $_CORELANG['TXT_LANGUAGE']);
                     foreach ($backendLanguage as $language) {
                         $languageUrl = \Env::get('init')->getUriBy('setLang', $language['id']);
                         $this->template->setVariable(array('LANGUAGE_URL' => $languageUrl, 'LANGUAGE_NAME' => $language['name'], 'LANGUAGE_CSS' => \Env::get('init')->getBackendLangId() == $language['id'] ? 'active' : ''));
                         $this->template->parse('backend_language_navigation_item');
                     }
                     $this->template->parse('backend_language_navigation');
                 } else {
                     $this->template->hideBlock('backend_language_navigation');
                 }
             }
             $this->template->touchBlock('backend_metanavigation');
         }
         // page parsing
         $parsingTime = $this->stopTimer();
         //                var_dump($parsingTime);
         /*echo ($finishTime[0] - $startTime[0]) . '<br />';
           if (!isset($_SESSION['asdf1']) || isset($_GET['reset'])) {
               $_SESSION['asdf1'] = 0;
               $_SESSION['asdf2'] = 0;
           }
           echo $_SESSION['asdf1'] . '<br />';
           if ($_SESSION['asdf1'] > 0) {
               echo $_SESSION['asdf2'] / $_SESSION['asdf1'];
           }
           $_SESSION['asdf1']++;
           $_SESSION['asdf2'] += ($finishTime[0] - $startTime[0]);//*/
         $objAdminNav = new \adminMenu($plainCmd);
         $objAdminNav->getAdminNavbar();
         $this->template->setVariable(array('SUB_MENU_TITLE' => $subMenuTitle, 'FRONTEND_LANG_MENU' => \Env::get('init')->getUserFrontendLangMenu(), 'TXT_GENERATED_IN' => $_CORELANG['TXT_GENERATED_IN'], 'TXT_SECONDS' => $_CORELANG['TXT_SECONDS'], 'TXT_LOGOUT_WARNING' => $_CORELANG['TXT_LOGOUT_WARNING'], 'PARSING_TIME' => $parsingTime, 'LOGGED_NAME' => htmlentities($this->getUser()->objUser->getProfileAttribute('firstname') . ' ' . $this->getUser()->objUser->getProfileAttribute('lastname'), ENT_QUOTES, CONTREXX_CHARSET), 'TXT_LOGGED_IN_AS' => $_CORELANG['TXT_LOGGED_IN_AS'], 'TXT_LOG_OUT' => $_CORELANG['TXT_LOG_OUT'], 'MODULE_INDEX' => MODULE_INDEX, 'JAVASCRIPT' => \JS::getCode(), 'CX_EDITION' => $_CONFIG['coreCmsEdition'], 'CX_VERSION' => $_CONFIG['coreCmsVersion'], 'CX_CODE_NAME' => $_CONFIG['coreCmsCodeName'], 'CX_STATUS' => $_CONFIG['coreCmsStatus'], 'CX_RELEASE_DATE' => date(ASCMS_DATE_FORMAT_DATE, $_CONFIG['coreCmsReleaseDate']), 'CX_NAME' => $_CONFIG['coreCmsName']));
         // Style parsing
         if (file_exists($this->codeBaseAdminTemplatePath . '/css/' . $cmd . '.css')) {
             // check if there's a css file in the core section
             $this->template->setVariable('ADD_STYLE_URL', $this->codeBaseAdminTemplateWebPath . '/css/' . $cmd . '.css');
             $this->template->parse('additional_style');
         } elseif (file_exists($this->codeBaseModulePath . '/' . $cmd . '/template/backend.css')) {
             // of maybe in the current module directory
             $this->template->setVariable('ADD_STYLE_URL', $this->codeBaseModuleWebPath . '/' . $cmd . '/template/backend.css');
             $this->template->parse('additional_style');
         } elseif (file_exists($this->codeBaseCoreModulePath . '/' . $cmd . '/template/backend.css')) {
             // or in the core module directory
             $this->template->setVariable('ADD_STYLE_URL', $this->codeBaseCoreModuleWebPath . '/' . $cmd . '/template/backend.css');
             $this->template->parse('additional_style');
         } else {
             $this->template->hideBlock('additional_style');
         }
         //enable gzip compressing of the output - up to 75% smaller responses!
         //commented out because of certain php.inis generating a
         //WARNING: ob_start(): output handler 'ob_gzhandler' cannot be used after 'URL-Rewriter
         //ob_start("ob_gzhandler");
         /*echo '<pre>';
           print_r($_SESSION);
           /*echo '<b>Overall time: ' . (microtime(true) - $timeAtStart) . 's<br />';
           echo 'Max RAM usage: ' . formatBytes(memory_get_peak_usage()) . '<br />';
           echo 'End RAM usage: ' . formatBytes(memory_get_usage()) . '<br /></b>';*/
         $endcode = $this->template->get();
         // replace links from before contrexx 3
         $ls = new \LinkSanitizer(ASCMS_PATH_OFFSET . ASCMS_BACKEND_PATH . '/', $endcode);
         $endcode = $ls->replace();
         echo $endcode;
     }
     \DBG::log("(Cx: {$this->id}) Request parsing completed after {$parsingTime}");
 }