Esempio n. 1
0
 /**
  * Processing of template, substituting of content, preparing for the output
  *
  * @return Page
  */
 protected function prepare()
 {
     $Config = Config::instance(true);
     /**
      * Loading of template
      * Loading of CSS and JavaScript
      * Getting user information
      */
     $this->get_template()->add_includes_on_page()->get_header_info();
     /**
      * Forming page title
      */
     foreach ($this->Title as $i => $v) {
         if (!trim($v)) {
             unset($this->Title[$i]);
         } else {
             $this->Title[$i] = trim($v);
         }
     }
     if ($Config) {
         $this->Title = $Config->core['title_reverse'] ? array_reverse($this->Title) : $this->Title;
         $this->Title = implode($Config->core['title_delimiter'], $this->Title);
     } else {
         $this->Title = $this->Title[0];
     }
     /**
      * Core JS
      */
     if ($Config) {
         $Index = Index::instance();
         $User = User::instance();
         $this->js_internal('window.cs	= ' . _json_encode(['base_url' => $Config->base_url(), 'current_base_url' => $Config->base_url() . '/' . (defined('IN_ADMIN') && IN_ADMIN ? 'admin/' : '') . MODULE, 'public_key' => Core::instance()->public_key, 'module' => MODULE, 'in_admin' => (int) (defined('IN_ADMIN') && IN_ADMIN), 'is_admin' => (int) $User->admin(), 'is_user' => (int) $User->user(), 'is_guest' => (int) $User->guest(), 'debug' => (int) $User->guest(), 'cookie_prefix' => $Config->core['cookie_prefix'], 'cookie_domain' => $Config->core['cookie_domain'][$Config->server['mirror_index']], 'cookie_path' => $Config->core['cookie_path'][$Config->server['mirror_index']], 'protocol' => $Config->server['protocol'], 'route' => $Config->route, 'route_path' => $Index->route_path, 'route_ids' => $Index->route_ids]) . ';', 'code', true);
         if ($User->guest()) {
             $this->js('cs.rules_text = ' . _json_encode(get_core_ml_text('rules')) . ';', 'code');
         }
         if (!$Config->core['cache_compress_js_css']) {
             $this->js('cs.Language = ' . _json_encode(Language::instance()) . ';', 'code');
         }
     }
     /**
      * Forming <head> content
      */
     $this->core_css[0] = implode('', array_unique($this->core_css[0]));
     $this->core_css[1] = implode('', array_unique($this->core_css[1]));
     $this->css[0] = implode('', array_unique($this->css[0]));
     $this->css[1] = implode('', array_unique($this->css[1]));
     $this->core_js[0] = implode('', array_unique($this->core_js[0]));
     $this->core_js[1] = implode('', array_unique($this->core_js[1]));
     $this->js[0] = implode('', array_unique($this->js[0]));
     $this->js[1] = implode('', array_unique($this->js[1]));
     if (file_exists(THEMES . "/{$this->theme}/{$this->color_scheme}/img/favicon.png")) {
         $favicon = "themes/{$this->theme}/{$this->color_scheme}/img/favicon.png";
     } elseif (file_exists(THEMES . "/{$this->theme}/{$this->color_scheme}/img/favicon.ico")) {
         $favicon = "themes/{$this->theme}/{$this->color_scheme}/img/favicon.ico";
     } elseif (file_exists(THEMES . "/{$this->theme}/img/favicon.png")) {
         $favicon = "themes/{$this->theme}/img/favicon.png";
     } elseif (file_exists(THEMES . "/{$this->theme}/img/favicon.ico")) {
         $favicon = "themes/{$this->theme}/img/favicon.ico";
     } else {
         $favicon = 'favicon.ico';
     }
     $this->Head = h::title($this->Title) . h::meta(['charset' => 'utf-8'], $this->Description ? ['name' => 'description', 'content' => $this->Description] : false, ['name' => 'generator', 'content' => base64_decode('Q2xldmVyU3R5bGUgQ01TIGJ5IE1va3J5bnNreWkgTmF6YXI=')], defined('ADMIN') && ADMIN || defined('API') && API ? ['name' => 'robots', 'content' => 'noindex,nofollow'] : false) . h::base($Config ? ['href' => $Config->base_url() . '/'] : false) . $this->Head . h::link([['rel' => 'shortcut icon', 'href' => $favicon]], $this->link ?: false) . $this->core_css[0] . $this->css[0] . h::style($this->core_css[1] . $this->css[1] ?: false) . h::script($this->core_js[1] . $this->js[1]);
     if ($Config->core['put_js_after_body']) {
         $this->post_Body .= $this->core_js[0] . $this->js[0];
     } else {
         $this->Head .= $this->core_js[0] . $this->js[0];
     }
     /**
      * Generation of Open Graph protocol information
      */
     $this->og_generation();
     /**
      * Getting footer information
      */
     $this->get_footer();
     /**
      * Menu generation
      */
     $Index = Index::instance();
     if (!$this->main_menu && $Index->main_menu) {
         $this->main_menu = h::{'li| a'}($Index->main_menu);
     }
     if ($Index->main_sub_menu) {
         if (!$this->main_sub_menu) {
             foreach ($Index->main_sub_menu as $item) {
                 if (isset($item[1], $item[1]['class']) && $item[1]['class'] == 'uk-active') {
                     if ($Index->main_menu_more) {
                         $item[0] .= ' ' . h::icon('caret-down');
                     }
                     $item[1]['class'] = trim(str_replace('uk-active', '', $item[1]['class']));
                     $this->main_sub_menu .= h::{'li.uk-active[data-uk-dropdown=]'}(h::a($item) . ($Index->main_menu_more ? h::{'div.uk-dropdown.uk-dropdown-small ul.uk-nav.uk-nav-dropdown li| a'}($Index->main_menu_more) : ''));
                 } else {
                     $this->main_sub_menu .= h::{'li a'}($item);
                 }
             }
         }
     } elseif (!$this->main_menu && $Index->main_menu_more) {
         $this->main_menu = h::{'li| a'}($Index->main_menu_more);
     }
     /**
      * Substitution of information into template
      */
     $this->Html = str_replace(['<!--pre_Html-->', '<!--head-->', '<!--pre_Body-->', '<!--header-->', '<!--main-menu-->', '<!--main-sub-menu-->', '<!--main-menu-more-->', '<!--user-avatar-image-->', '<!--header_info-->', '<!--left_blocks-->', '<!--top_blocks-->', '<!--content-->', '<!--bottom_blocks-->', '<!--right_blocks-->', '<!--footer-->', '<!--post_Body-->', '<!--post_Html-->'], [$this->pre_Html, h::level($this->Head, $this->level['Head']), h::level($this->pre_Body, $this->level['pre_Body']), h::level($this->Header, $this->level['Header']), h::level($this->main_menu, $this->level['main_menu']), h::level($this->main_sub_menu, $this->level['main_sub_menu']), h::level($this->main_menu_more, $this->level['main_menu_more']), $this->user_avatar_image, h::level($this->header_info, $this->level['header_info']), h::level($this->Left, $this->level['Left']), h::level($this->Top, $this->level['Top']), h::level($this->Content, $this->level['Content']), h::level($this->Bottom, $this->level['Bottom']), h::level($this->Right, $this->level['Right']), h::level($this->Footer, $this->level['Footer']), h::level($this->post_Body, $this->level['post_Body']), $this->post_Html], $this->Html);
     return $this;
 }