Emlog6.0.1版本全站源码无插件压缩代码教程

Emlog6.0.1版本全站源码无插件压缩代码教程无需插件直接将代码写在模版文件中就可以了。

代码完成Emlog全站源码紧缩次要步骤如下:

一、找到模版文件module.php,在里面添加如下代码

<?php //全站代码压缩
function slys($sheli){$initial=strlen($sheli);$sheli=explode("<!--slys-->",$sheli);$count=count($sheli); for($i=0;$i<=$count;$i++){if(stristr($sheli[$i], '<!--slys end-->')){$sheli[$i]=(str_replace("<!--slys end-->", " ", $sheli[$i]));}else{$sheli[$i]=(str_replace("\t", " ", $sheli[$i]));$sheli[$i]=(str_replace("\n\n", "\n", $sheli[$i]));$sheli[$i]=(str_replace("\n", "", $sheli[$i]));$sheli[$i]=(str_replace("\r", "", $sheli[$i]));while (stristr($sheli[$i], '  ')){$sheli[$i]=(str_replace("  ", " ", $sheli[$i]));}}$sheli_out.=$sheli[$i];}$final=strlen($sheli_out);$savings=($initial-$final)/$initial*100;$savings=round($savings,2);$sheli_out.="\n<!--压缩前的大小: $initial bytes; 压缩后的大小: $final bytes; 节约:$savings% -->";return $sheli_out;}?>

二、找到模版文件footer.php,在最末尾(即前面)添加下面的代码挂载点

<?php $html=ob_get_contents();ob_get_clean();echo slys($html);?>

为了文章页面拔出代码不被紧缩即不紧缩pre中的代码而作的扩展

三、不紧缩pre中的代码(即文章页的代码区域)要在模版文件module.php参加下面代码

<?php //不压缩pre
function slbys($content){if(preg_match_all('/(crayon-|<\/pre>)/i',$content,$matches)){$content = '<!--slys--><!--slys end-->'.$content;$content.= '<!--slys end--><!--slys-->';}return $content;}slbys($log_content);?>

四、找到模版文件echo_log.php(文章页模版)以及page.php(评论模版)
下面

$log_content

替换成

slbys($log_content)

完美结束