Ejemplo n.º 1
0
 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());
 }
Ejemplo n.º 2
0
/**
 * @param string $component
 * @param bool $class
 * @return null
 */
function c($component, $class = false)
{
    return Components::get($component, $class);
}