/** * Data for HTML <head> generation */ private function prepareHead() { $config = Configuration::getInstance(); // Favicon url $favicon = !empty($config->get('cms')['favicon']) ? $config->get('cms')['favicon'] : DIR_CMS_IMAGES_URL . 'logo_square.png'; // Prepare page HTML for head PageHead::getInstance()->addHtmlTagAttributes('lang="en" class="no-js"')->setTitle((P_DO !== '_default' ? Converter::symb2Ttl(P_DO) : 'Main') . ' / ' . Converter::symb2Ttl(P) . ' / ' . $config->get('site')['name'] . ' / ' . CMS_NAME . ' v. ' . CMS_VERSION)->setFavicon($favicon)->addMeta('name=' . CMS_NAME . ' - ' . $config->get('site')['name'] . '; action-uri=http://' . CFG_DOMAIN . '/cms/; icon-uri=http://' . DIR_CMS_IMAGES_URL . 'logo_square.png', 'msapplication-task')->addMeta('width=device-width, initial-scale=1', 'viewport')->addMeta('IE=edge', '', 'X-UA-Compatible')->addClassToBody('page-header-fixed')->addClassToBody('page-quick-sidebar-over-content')->addCssUrl('cms/fonts/open-sans.css')->addCssUrl('cms/plugins/font-awesome/font-awesome.css')->addCssUrl('cms/plugins/simple-line-icons/simple-line-icons.css')->addCssUrl('cms/plugins/bootstrap/css/bootstrap.css')->addCssUrl('cms/plugins/uniform/css/uniform.default.css')->addCssUrl('cms/plugins/bootstrap-switch/css/bootstrap-switch.css')->addCssUrl('cms/plugins/pace/pace-theme-minimal.css')->addCssUrl('cms/plugins/select2/select2.css')->addCssUrl('cms/css/components.css')->addCssUrl('cms/css/plugins.css')->addCssUrl('cms/layout/css/layout.css')->addCssUrl('cms/layout/css/themes/default.css')->addCssUrl('cms/layout/css/custom.css')->addCssUrl('plugins/toastr/toastr.min.css')->addJsUrl('cms/jquery-1.11.0.min.js')->addJsUrl(DIR_CMS_SCRIPTS_URL . 'jquery.form.min.js')->addJs('var cms_data = {};')->addJs('cms_data.cfg_domain="' . CFG_DOMAIN . '"')->addJs('cms_data.site_name="' . $config->get('site')['name'] . '"')->addJsUrl('cms_js.js')->addJsUrl('plupload/plupload.full.min.js'); // Script for sending JS errors 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 . '\');'); } PageTail::getInstance()->addJsUrl('cms/jquery-migrate-1.2.1.min.js')->addJsUrl('cms/plugins/jquery-ui/jquery-ui-1.10.3.custom.min.js')->addJsUrl('cms/plugins/bootstrap/js/bootstrap.min.js')->addJsUrl('cms/plugins/bootstrap-hover-dropdown/bootstrap-hover-dropdown.min.js')->addJsUrl('cms/plugins/jquery-slimscroll/jquery.slimscroll.min.js')->addJsUrl('cms/jquery.blockui.min.js')->addJsUrl('cms/jquery.cokie.min.js')->addJsUrl('cms/plugins/uniform/jquery.uniform.min.js')->addJsUrl('cms/plugins/bootstrap-switch/js/bootstrap-switch.min.js')->addCssUrl('cms/plugins/jquery-contextmenu/jquery.contextMenu.css')->addJsUrl('cms/plugins/jquery-contextmenu/jquery.contextMenu.js')->addJsUrl('cms/plugins/jquery-validation/js/jquery.validate.min.js')->addJsUrl('cms/plugins/backstretch/jquery.backstretch.min.js')->addJsUrl('cms/plugins/select2/select2.min.js')->addJsUrl('cms/metronic.js')->addJsUrl('cms/layout/scripts/layout.js')->addJsUrl('cms/layout/scripts/quick-sidebar.js')->addJsUrl('cms/plugins/pace/pace.js')->addCssUrl('cms/cms_css.css')->addJsUrl('plugins/toastr/toastr.min.js')->addJsUrl('plugins/parsley.min.js')->addJsUrl('cms/respond.min.js')->addJsUrl('cms/excanvas.min.js')->addJs('$(function() { $(".chosen").select2(); Metronic.init(); Layout.init(); QuickSidebar.init(); });'); // Search for custom css $custom_css_url = DIR_ASSETS_URL . 'cms.css'; if (file_exists(DIR_BASE . $custom_css_url)) { PageHead::getInstance()->addCssUrl($custom_css_url); } else { PageHead::getInstance()->addCustomString('<!--Create file "' . $custom_css_url . '" if you wish to use custom css file-->'); } // Set head for page Page::setHead(PageHead::getInstance()); }
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()); }