设为首页 收藏本站
查看: 592|回复: 0

[经验分享] 对uchome2.0 的function_common.php的研究2

[复制链接]

尚未签到

发表于 2017-4-9 11:46:03 | 显示全部楼层 |阅读模式
  在common.php里,有这么一段代码

//启用GIP
if ($_SC['gzipcompress'] && function_exists('ob_gzhandler')) {
ob_start('ob_gzhandler');
} else {
ob_start();
}
  如果服务器支持gzip的话,那么就调用

ob_start('ob_gzhandler');
  ob_start的意思是开始数据缓冲,也就是服务器的echo的东西会放在缓冲区里不会直接发送给浏览器。ob_gzhandler是作为回调函数来调用的。关于此函数解释为

ob_gzhandler()

is intended to be
used as a callback
function for ob_start()

to help facilitate sending
gz-encoded data to web browsers that support compressed web pages.  
Before ob_gzhandler()

actually
sends compressed data,
it determines what type of content encoding the browser will accept
("gzip", "deflate" or none at all) and will return its output
accordingly.
All browsers are supported since it's up to the browser to send the
correct header saying that it accepts compressed web pages. If a
browser
doesn't support compressed pages this function returns FALSE

.

  而ob_start的那个callback参数的解释如下
  When
output_callback

is called, it
will receive the
contents of the output buffer as its parameter and is expected to
return a new output buffer as a result, which will be sent to the
browser.
  也即使说支持gzip的服务器会在把数据传到浏览器之前先把数据传给那个回调函数产生新的输出。ob_gzhandler一定就是压缩数据的方法了。
  在function_common里有这么一个函数
  ob_out

//调整输出
function ob_out() {
global $_SGLOBAL, $_SCONFIG, $_SC;
$content = ob_get_contents();
$preg_searchs = $preg_replaces = $str_searchs = $str_replaces = array();
if($_SCONFIG['allowrewrite']) {
$preg_searchs[] = "/\<a href\=\"space\.php\?(uid|do)+\=([a-z0-9\=\&]+?)\"/ie";
$preg_searchs[] = "/\<a href\=\"space.php\"/i";
$preg_searchs[] = "/\<a href\=\"network\.php\?ac\=([a-z0-9\=\&]+?)\"/ie";
$preg_searchs[] = "/\<a href\=\"network.php\"/i";
$preg_replaces[] = 'rewrite_url(\'space-\',\'\\2\')';
$preg_replaces[] = '<a href="space.html"';
$preg_replaces[] = 'rewrite_url(\'network-\',\'\\1\')';
$preg_replaces[] = '<a href="network.html"';
}
if($_SCONFIG['linkguide']) {
$preg_searchs[] = "/\<a href\=\"http\:\/\/(.+?)\"/ie";
$preg_replaces[] = 'iframe_url(\'\\1\')';
}
if($_SGLOBAL['inajax']) {
$preg_searchs[] = "/([\x01-\x09\x0b-\x0c\x0e-\x1f])+/";
$preg_replaces[] = ' ';
$str_searchs[] = ']]>';
$str_replaces[] = ']]&gt;';
}
if($preg_searchs) {
$content = preg_replace($preg_searchs, $preg_replaces, $content);
}
if($str_searchs) {
$content = trim(str_replace($str_searchs, $str_replaces, $content));
}
obclean();
if($_SGLOBAL['inajax']) {
xml_out($content);
} else{
if($_SCONFIG['headercharset']) {
@header('Content-Type: text/html; charset='.$_SC['charset']);
}
echo $content;
if(D_BUG) {
@include_once(S_ROOT.'./source/inc_debug.php');
}
}
}
   $content = ob_get_contents()为取得缓冲区的内容,在obclean之前都是在做字符串的替换,具体的我也不清楚是怎么搞的。
  调用ob_clean()把缓冲区里的数据清楚掉。
  如果是ajax请求,那么就返回一个数据的xml形式。
  其余情况则很正常地把结果echo出去。你会发现在每一个daat下的tpl缓存页面文件里都有一个ob_out()函数。
  贴一下相关函数的代码

function obclean() {
global $_SC;
ob_end_clean();
if ($_SC['gzipcompress'] && function_exists('ob_gzhandler')) {
ob_start('ob_gzhandler');
} else {
ob_start();
}
}
 
function xml_out($content) {
global $_SC;
@header("Expires: -1");
@header("Cache-Control: no-store, private, post-check=0, pre-check=0, max-age=0", FALSE);
@header("Pragma: no-cache");
@header("Content-type: application/xml; charset=$_SC[charset]");
echo '<'."?xml version=\"1.0\" encoding=\"$_SC[charset]\"?>\n";
echo "<root><![CDATA[".trim($content)."]]></root>";
exit();
}
   2、sstripslashes

//去掉slassh
function sstripslashes($string) {
if(is_array($string)) {
foreach($string as $key => $val) {
$string[$key] = sstripslashes($val);
}
} else {
$string = stripslashes($string);
}
return $string;
}
   这里就是递归地将数组里的字符串反转义,也就是原来是123\'123的现在变成123'123

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-362376-1-1.html 上篇帖子: 处理PHP字符串的10个简单方法 下篇帖子: (转) 网站性能-cgi fastcgi mod_php相关概念整理
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表