public function __construct() { // Check background services if (isset($_GET['cms_is_running_background']) && $_GET['cms_is_running_background'] == 1) { ServiceManager::checkNeeded(); exit; } // Try updating CMS if (isset($_GET['key']) && $_GET['key'] == Configuration::getInstance()->get('cms')['unique_key'] && count($_GET) === 2) { $updater = Updater::getInstance(); // Update files from repo $updater->updateSourceCode(isset($_GET['branch']) ? $_GET['branch'] : NULL); // Update composer only if required if (isset($_GET['composer'])) { $updater->updateComposerVendors(); } // Update database $updater->runMigrations(); // Run PHPUnit tests $updater->runTests(); // Output $out = $updater->getResult(); $text = json_encode($out, JSON_FORCE_OBJECT); echo $text; if (stripos($text, 'Code Coverage Report') === false) { Mailer::getInstance()->setMessage('Did not find "Code Coverage Report" in updater response:<br><br>' . $text)->setRecipient(CMS_SUPPORT_EMAIL)->setSender(Settings::getCommonEmail(), Configuration::getInstance()->get('site')['name'] . ' - AutoUpdater')->setSubject('Error found during update')->send(); } exit; } // Else - running usual Admin panel // Proceed with request $this->parseUrl(); // Save log if (Users::getInstance()->isLogged() && Settings::get('save_back_access_log') && !IS_AJAX_REQUEST) { $users_log = new UserLog(); $users_log->save(); } // Init page data if (Users::getInstance()->isLogged()) { define('LNG', Users::getInstance()->getUserLng()); } $this->sendHeaders(); $this->prepareHead(); $this->parseMenu(); // Post-scripts Page::setTail(PageTail::getInstance()); // Flush application log App::flushLog(); $this->generateContent(); }
private function parse() { // If file is cached - return alredy generated HTML if (Settings::isCacheEnabled() && Settings::get('use_file_cache_for_all_pages')) { // Find in cache if (Settings::isCacheEnabled()) { $this->cached_page_html = Cacher::getInstance()->getDefaultCacher()->get('html_' . PATH_INTERNAL_MD5); } if ($this->cached_page_html) { if (Settings::isFrontendLogEnabled()) { FrontendLogger::getInstance()->log('Loading cached HTML'); } return; } } /* Prepare page for composing */ // Read main template file content $this->readTemplateContent(); // If we have external template engine like Twig or Smarty $this->processExternalTemplater(); // If enabled parsing only HTML without system components if ($this->use_html_file_without_parse) { // No parse required return; } // Start Visual edit for drawing editable fields around system components - if enabled VisualEdit::getInstance()->init(); /* Start composing HTML page */ // Prepend <head> Page::setHead(PageHead::getInstance()->setTitle($this->router_instance->getPageData()['title'])->setMetaKeywords($this->router_instance->getPageData()['keywords'])->setMetaDescription($this->router_instance->getPageData()['description'])); // Script for sending JS errors if not disabled. System sends JS error to support email if (CFG_MAIL_ERRORS && Settings::isProductionState() && !Settings::get('do_not_send_js_errors')) { PageHead::getInstance()->addJsUrl('send_error.js')->addJS('register_js_error.ini(\'' . DIR_CMS_URL . '\');'); } /* Start replacing template vars with appropriate component content */ if (Settings::isCacheEnabled()) { if (Settings::isFrontendLogEnabled()) { FrontendLogger::getInstance()->log('Loading cached replaceable elements'); } $cached_replaces = Cacher::getInstance()->getDefaultCacher()->get('template_elements_' . PATH_INTERNAL_MD5); } else { $cached_replaces = []; } // We need iteration to call all components called in components $template_base_name = pathinfo(Router::getInstance()->getPageData()['template_file'], PATHINFO_FILENAME); $no_more_elements = false; while (!$no_more_elements) { // Component replaces in templates from template ... if (!Settings::isProductionState() || !$cached_replaces || !isset($cached_replaces['elements'], $cached_replaces['replaces'])) { // Find which components are used in template $res = Components::parseForComponents($this->html); $so = count($res[0]); $elements = []; // Get elements for every component for ($i = 0; $i < $so; ++$i) { if ($res[1][$i] == 'index') { $res[1][$i] = $template_base_name; } $file = $res[1][$i]; // File with elements $class = $file; // Class in file with elements $method = $res[3][$i] ? $res[3][$i] : $res[2][$i]; // Method with element in class // If method is not defined - call index if (!$method) { $method = 'index'; } // Component may have modifier params in template that are farther pushed in elements $modifiers = []; if ($res[4][$i]) { $modifiers = explode('|', $res[4][$i]); } $elements[] = ['file' => $file, 'class' => $class, 'method' => $method, 'modifiers' => $modifiers]; } // Save in cache to prevent future parsing of the same template if (Settings::isCacheEnabled()) { Cacher::getInstance()->getDefaultCacher()->set('template_elements_' . PATH_INTERNAL_MD5, ['elements' => $elements, 'replaces' => $res]); } } else { // ... or set from cache $elements = $cached_replaces['elements']; $res = $cached_replaces['replaces']; } // No more elements found in HTML if (!$elements) { $no_more_elements = true; } // Replace component values in template $this->replaceElements($elements, $res); } // Append post-scripts before ending body tag Page::setTail(PageTail::getInstance()); }