示例#1
0
/**
 * nv_change_buffer()
 *
 * @param mixed $buffer
 * @return
 */
function nv_change_buffer($buffer)
{
    global $db, $sys_info, $global_config;
    $buffer = $db->unfixdb($buffer);
    $buffer = nv_url_rewrite($buffer);
    if (defined("NV_ANTI_IFRAME") and NV_ANTI_IFRAME) {
        $buffer = preg_replace("/(<body[^>]*>)/", "\$1\r\n<script type=\"text/javascript\">if(window.top!==window.self){document.write=\"\";window.top.location=window.self.location;setTimeout(function(){document.body.innerHTML=\"\"},1);window.self.onload=function(){document.body.innerHTML=\"\"}};</script>", $buffer, 1);
    }
    if (!empty($global_config['googleAnalyticsID']) and preg_match('/^UA-\\d{4,}-\\d+$/', $global_config['googleAnalyticsID'])) {
        $dp = "";
        if ($global_config['googleAnalyticsSetDomainName'] == 1) {
            $dp .= "_gaq.push([\"_setDomainName\",\"" . $global_config['cookie_domain'] . "\"]);";
        } elseif ($global_config['googleAnalyticsSetDomainName'] == 2) {
            $dp .= "_gaq.push([\"_setDomainName\",\"none\"]);_gaq.push([\"_setAllowLinker\",true]);";
        }
        $googleAnalytics = "<script type=\"text/javascript\">\r\n";
        $googleAnalytics .= "//<![CDATA[\r\n";
        $googleAnalytics .= "var _gaq=_gaq||[];_gaq.push([\"_setAccount\",\"" . $global_config['googleAnalyticsID'] . "\"]);" . $dp . "_gaq.push([\"_trackPageview\"]);(function(){var a=document.createElement(\"script\");a.type=\"text/javascript\";a.async=true;a.src=(\"https:\"==document.location.protocol?\"https://ssl\":\"http://www\")+\".google-analytics.com/ga.js\";var b=document.getElementsByTagName(\"script\")[0];b.parentNode.insertBefore(a,b)})();\r\n";
        $googleAnalytics .= "//]]>\r\n";
        $googleAnalytics .= "</script>\r\n";
        $buffer = preg_replace('/(<\\/head>)/i', $googleAnalytics . "\\1", $buffer, 1);
    }
    if ($global_config['optActive'] == 1 || (!defined('NV_ADMIN') and $global_config['optActive'] == 2) || (defined('NV_ADMIN') and $global_config['optActive'] == 3)) {
        include_once NV_ROOTDIR . '/includes/class/optimizer.class.php';
        $optimezer = new optimezer($buffer, $sys_info['supports_tidy']);
        $buffer = $optimezer->process();
        //http://tidy.sourceforge.net/docs/quickref.html
        $config = array('doctype' => 'transitional', 'input-encoding' => 'utf8', 'output-encoding' => 'utf8', 'output-xhtml' => true, 'drop-empty-paras' => true, 'drop-proprietary-attributes' => true, 'word-2000' => true, 'enclose-block-text' => true, 'enclose-text' => true, 'hide-comments' => false, 'hide-endtags' => true, 'indent' => false, 'indent-spaces' => 4, 'logical-emphasis' => true, 'lower-literals' => true, 'markup' => true, 'preserve-entities' => true, 'quote-ampersand' => true, 'quote-marks' => true, 'quote-nbsp' => true, 'show-warnings' => false, 'wrap' => 0, 'alt-text' => true);
        $buffer = nv_valid_html($buffer, $config);
    }
    if (!$sys_info['supports_rewrite']) {
        $buffer = preg_replace("/\\<(script|link)(.*?)(src|href)=['\"]((?!http(s?)|ftp\\:\\/\\/).*?\\.(js|css))['\"](.*?)\\>/", "<\\1\\2\\3=\"" . NV_BASE_SITEURL . "CJzip.php?file=\\4&amp;r=" . $global_config['timestamp'] . "\"\\7>", $buffer);
    } else {
        $buffer = preg_replace("/\\<(script|link)(.*?)(src|href)=['\"]((?!http(s?)|ftp\\:\\/\\/).*?\\.(js|css))['\"](.*?)\\>/", "<\\1\\2\\3=\"\\4?t=" . $global_config['timestamp'] . "\"\\7>", $buffer);
    }
    return $buffer;
}
示例#2
0
/**
 * nv_change_buffer()
 *
 * @param mixed $buffer
 * @return
 */
function nv_change_buffer($buffer)
{
    global $db, $sys_info, $global_config, $client_info;
    if (NV_ANTI_IFRAME and !$client_info['is_myreferer']) {
        $buffer = preg_replace('/(<body[^>]*>)/', "\$1\r\n<script type=\"text/javascript\">if(window.top!==window.self){document.write=\"\";window.top.location=window.self.location;setTimeout(function(){document.body.innerHTML=\"\"},1);window.self.onload=function(){document.body.innerHTML=\"\"}};</script>", $buffer, 1);
    }
    if (defined('NV_SYSTEM') and preg_match('/^UA-\\d{4,}-\\d+$/', $global_config['googleAnalyticsID'])) {
        $googleAnalytics = "<script type=\"text/javascript\">\r\n";
        $googleAnalytics .= "//<![CDATA[\r\n";
        if ($global_config['googleAnalyticsMethod'] == 'universal') {
            $googleAnalytics .= "(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){\r\n";
            $googleAnalytics .= "(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),\r\n";
            $googleAnalytics .= "m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\r\n";
            $googleAnalytics .= "})(window,document,'script','//www.google-analytics.com/analytics.js','ga');\r\n";
            $googleAnalytics .= "ga('create', '" . $global_config['googleAnalyticsID'] . "', '" . $global_config['cookie_domain'] . "');\r\n";
            $googleAnalytics .= "ga('send', 'pageview');\r\n";
        } else {
            $dp = '';
            if ($global_config['googleAnalyticsSetDomainName'] == 1) {
                $dp .= "_gaq.push([\"_setDomainName\",\"" . $global_config['cookie_domain'] . "\"]);";
            } elseif ($global_config['googleAnalyticsSetDomainName'] == 2) {
                $dp .= "_gaq.push([\"_setDomainName\",\"none\"]);_gaq.push([\"_setAllowLinker\",true]);";
            }
            $googleAnalytics .= "var _gaq=_gaq||[];_gaq.push([\"_setAccount\",\"" . $global_config['googleAnalyticsID'] . "\"]);" . $dp . "_gaq.push([\"_trackPageview\"]);(function(){var a=document.createElement(\"script\");a.type=\"text/javascript\";a.async=true;a.src=(\"https:\"==document.location.protocol?\"https://ssl\":\"http://www\")+\".google-analytics.com/ga.js\";var b=document.getElementsByTagName(\"script\")[0];b.parentNode.insertBefore(a,b)})();\r\n";
        }
        $googleAnalytics .= "//]]>\r\n";
        $googleAnalytics .= "</script>\r\n";
        $buffer = preg_replace('/(<\\/head>)/i', $googleAnalytics . "\\1", $buffer, 1);
    }
    $body_replace = '';
    if (NV_CURRENTTIME > $global_config['cronjobs_next_time']) {
        $body_replace .= "<div id=\"run_cronjobs\" style=\"visibility:hidden;display:none;\"><img alt=\"\" src=\"" . NV_BASE_SITEURL . "index.php?second=cronjobs&amp;p=" . nv_genpass() . "\" width=\"1\" height=\"1\" /></div>\n";
    }
    if (NV_LANG_INTERFACE == 'vi' and ($global_config['mudim_active'] == 1 or $global_config['mudim_active'] == 2 and defined('NV_SYSTEM') or $global_config['mudim_active'] == 3 and defined('NV_ADMIN'))) {
        $body_replace .= "<script type=\"text/javascript\">\n\t\t\t\tvar mudim_showPanel = " . ($global_config['mudim_showpanel'] ? "true" : "false") . ";\n\t\t\t\tvar mudim_displayMode = " . $global_config['mudim_displaymode'] . ";\n\t\t\t\tvar mudim_method = " . $global_config['mudim_method'] . ";\n\t\t\t</script>\n";
        $body_replace .= "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "js/mudim.js\"></script>\n";
    }
    $buffer = preg_replace('/(<\\/body>)/i', $body_replace . '\\1', $buffer, 1);
    if ($global_config['optActive'] == 1 || (!defined('NV_ADMIN') and $global_config['optActive'] == 2) || (defined('NV_ADMIN') and $global_config['optActive'] == 3)) {
        include_once NV_ROOTDIR . '/includes/class/optimizer.class.php';
        $opt_css_file = empty($global_config['cdn_url']) ? true : false;
        $optimezer = new optimezer($buffer, $opt_css_file);
        $buffer = $optimezer->process();
    }
    if (!empty($global_config['cdn_url'])) {
        $buffer = preg_replace("/\\<(script|link)(.*?)(src|href)=['\"]((?!http(s?)|ftp\\:\\/\\/).*?\\.(js|css))['\"](.*?)\\>/", "<\\1\\2\\3=\"" . $global_config['cdn_url'] . "\\4?t=" . $global_config['timestamp'] . "\"\\7>", $buffer);
    } elseif (!$sys_info['supports_rewrite']) {
        $buffer = preg_replace("/\\<(script|link)(.*?)(src|href)=['\"]((?!http(s?)|ftp\\:\\/\\/).*?\\.(js|css))['\"](.*?)\\>/", "<\\1\\2\\3=\"" . NV_BASE_SITEURL . "CJzip.php?file=\\4&amp;r=" . $global_config['timestamp'] . "\"\\7>", $buffer);
    } else {
        $buffer = preg_replace("/\\<(script|link)(.*?)(src|href)=['\"]((?!http(s?)|ftp\\:\\/\\/).*?\\.(js|css))['\"](.*?)\\>/", "<\\1\\2\\3=\"\\4?t=" . $global_config['timestamp'] . "\"\\7>", $buffer);
    }
    return $buffer;
}