コード例 #1
0
ファイル: builder.php プロジェクト: viking2000/web-antarix
    public static function build_page()
    {
        $is_mobile = (bool) config('web', 'is_mobile');
        $header_css =& self::$_header_css;
        $header_js =& self::$_header_js;
        $footer_js =& self::$_footer_js;
        $plugin_header =& self::$_plugin_header;
        $noscript =& self::$_noscript;
        $js_constants = implode(' ', self::$_js_constants);
        $doctype = $is_mobile ? config('web', 'doctype_mobile') : config('web', 'doctype_pc');
        $favicon_path = config('settings', 'base_url') . "modules/images/favicon.ico";
        $body_page = Buffer::get_output();
        $lang = Buffer::get(URL_LANG) ? Buffer::get(URL_LANG) : config('settings', 'default_lang');
        $meta = '';
        $title = self::$_title;
        //если включено кеширование стилей, то собираем стили страницы в один файл
        if (config(URL_AP, 'cache', 'page_header')) {
            $key = Cache::generate_key();
            $compiled_web = Cache::get_link($key, 'styles');
            //собираем CCS стили
            if (empty($compiled_web)) {
                $cache_content = '';
                foreach (self::$_attach_css as $item) {
                    $cache_content .= file_get_contents(FCPATH . 'modules/styles/' . $item . '.css');
                }
                Cache::set($key, $cache_content, config(URL_AP, 'cache', 'web_lifetime'), 'styles');
                $compiled_web = "./modules/styles/cache/{$key}.css";
            }
            $header_css = attach_css($compiled_web);
            $compiled_web = Cache::get_link($key, 'scripts');
            //собираем JS файлы
            if (empty($compiled_web)) {
                $cache_content = '';
                foreach (self::$_attach_js as $item) {
                    $cache_content .= file_get_contents(FCPATH . 'modules/scripts/' . $item . '.js');
                }
                Cache::set($key, $cache_content, config(URL_AP, 'cache', 'web_lifetime'), 'scripts');
                $compiled_web = "./modules/scripts/cache/{$key}.js";
            }
            $header_js = attach_js($compiled_web);
        }
        //Формируем метатеги
        foreach (self::$_meta_data as $key => &$value) {
            $meta .= "<meta name=\"{$key}\" content=\"{$value}\">";
        }
        $final_page = <<<HTML
        {$doctype}
        <html lang="{$lang}">
            <head>
                <script>
                    {$js_constants}
                </script>
                <title>{$title}</title>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
                {$meta}
                <link rel="icon" type="image/x-icon" href="{$favicon_path}">
\t\t\t\t<link rel="shortcut icon" href="{$favicon_path}" type="image/x-icon"> 
                {$header_css}
                {$header_js}
                {$plugin_header}
                <noscript>
                    {$noscript}
                </noscript>
            </head>
            <body>
                {$body_page}
                <!-- system lib-->
                {$footer_js}
            </body>
        </html>
HTML;
        return $final_page;
    }