supesite 旧版本的使用是很久以前, 整个华丽的感觉就像是看童话, 也显得康盛团队的水平很艺术。 童话不能成为现实, 新版本的supesite放弃了华丽的外观及复杂的结构, 而采用了简明及高效的方式来展示一个cms应该拥有的核心是什么。代码虽然没有uchome及discuz x那般完美, 但整体上来说,思想及结构还是可取的, 比如就debug功能。 第一次体验debug功能是在uchome上面, define('D_BUG', '0'); 那时看这一句时, 想了很久都没有明白,意义何在。 如今终于明白了, 这是给程序员的一块蛋糕。
当然, 如果你笨得跟牛一样, 那肯定是给你的一颗炸弹。
1:common.inc.php 中代码:
2: function/common.function.php中代码
此函数在footer.html模板中得到执行。 3: include/debug.inc.php中代码
当然, 如果你笨得跟牛一样, 那肯定是给你的一颗炸弹。
1:common.inc.php 中代码:
1 | // 设置debug是否开启,<1 为关闭,其它为开启 |
2 | define('D_BUG', '1'); |
3 | // 当开启D_BUG时, 打error的通用错误提示,否则打开致命错误提示 |
4 | D_BUG?error_reporting(7):error_reporting(E_ERROR); |
01 | function ob_out() { |
02 | // 引入一些全局的数组 |
03 | global $_SGLOBAL, $_SCONFIG, $_SC; |
04 | // 将当前的内容赋值给某键名 |
05 | $_SGLOBAL['content'] = ob_get_contents(); |
06 |
07 | // 初始化部分数组 |
08 | $preg_searchs = $preg_replaces = $str_searchs = $str_replaces = array(); |
09 |
10 | // 假如是ajax行为就对替换数组做前期赋值 |
11 | if($_SGLOBAL['inajax']) { |
12 | $preg_searchs[] = "/([\x01-\x09\x0b-\x0c\x0e-\x1f])+/"; |
13 | $preg_replaces[] = ' '; |
14 |
15 | $str_searchs[] = ']]>'; |
16 | $str_replaces[] = ']]>'; |
17 | } |
18 |
19 | // 如果系统配置中对url规范有要求的, 就增加新的替换规则,比如伪静态,或者生成html等等。 |
20 | if($_SCONFIG['urltype'] != 4 && $_SCONFIG['urltype'] != 5) { |
21 | $preg_searchs[] = "/href\=\"(\S*?)\/(index\.php)?\?uid\-([0-9]+)\-?(\S*?)\"/i"; |
22 | $preg_replaces[] = 'href="\\1/?\\3/\\4"'; |
23 | $preg_searchs[] = "/href\=\"\S*?\/(index\.php)?\?(\S+?)\"/ie"; |
24 | $preg_replaces[] = "url_replace('\\2')"; |
25 | } |
26 | |
27 | // 如果替换数组不为空, 就执行替换。 |
28 | if($preg_searchs) { |
29 | $_SGLOBAL['content'] = preg_replace($preg_searchs, $preg_replaces,$_SGLOBAL['content']); |
30 | } |
31 | // 如果字符替换数组不为空, 也执行替换 |
32 | if($str_searchs) { |
33 | $_SGLOBAL['content'] = trim(str_replace($str_searchs, $str_replaces,$_SGLOBAL['content'])); |
34 | } |
35 | |
36 | // 清除当前所有输入 |
37 | obclean(); |
38 | |
39 | // 如果是ajax行为,就执行header部分发送及xml规范控制 |
40 | if($_SGLOBAL['inajax']) { |
41 | @header("Expires: -1"); |
42 | @header("Cache-Control: no-store, private, post-check=0, pre-check=0, max-age=0", FALSE); |
43 | @header("Pragma: no-cache"); |
44 | @header("Content-type: application/xml; charset=$_SC[charset]"); |
45 | echo '<'."?xml version=\"1.0\" encoding=\"$_SC[charset]\"?>\n"; |
46 | echo "<root><![CDATA[".trim($_SGLOBAL['content'])."]]></root>"; |
47 | exit(); |
48 | } else{ //如果是普通行为,就到这一步 |
49 | // 设置字符输出编码 |
50 | if($_SCONFIG['headercharset']) { |
51 | @header('Content-Type: text/html; charset='.$_SC['charset']); |
52 | } |
53 | |
54 | // 再一次输出内容,print 是我改的, 原本是echo |
55 | print $_SGLOBAL['content']; |
56 | |
57 | // D_BUG 功能开启时, 并且在没有定义CREATEHTML常量的页中引入debug的应用页 |
58 | if(D_BUG && !defined('CREATEHTML')) { |
59 | @include_once(S_ROOT.'./include/debug.inc.php'); |
60 | } |
61 | } |
62 | } |
001 | <?php |
002 |
003 | /* |
004 | [SupeSite] (C) 2007-2009 Comsenz Inc. |
005 | $Id: debug.inc.php 10898 2008-12-31 02:58:50Z zhaofei $ |
006 | */ |
007 | // 门牌效应 |
008 | if(!defined('IN_SUPESITE')) { |
009 | exit('Access Denied'); |
010 | } |
011 |
012 | // 判断一下是否有开启此功能。很严苛的判断了。 |
013 | if(D_BUG) { |
014 | // 首页输出一个hr 及 css样式. |
015 | echo ' |
016 | <!-- |
017 | ***************************** debug ********************************************* |
018 | --> |
019 | <hr> |
020 | <style> |
021 | .tclass, .tclass2 { |
022 | text-align:left;width:760px;border:0;border-collapse:collapse;margin-bottom:5px;table-layout: fixed; word-wrap: break-word;background:#FFF;} |
023 | .tclass table, .tclass2 table {width:100%;border:0;table-layout: fixed; word-wrap: break-word;} |
024 | .tclass table td, .tclass2 table td {border-bottom:0;border-right:0;border-color: #ADADAD;} |
025 | .tclass th, .tclass2 th {border:1px solid #000;background:#CCC;padding: 2px;font-family: Courier New, Arial;font-size: 11px;} |
026 | .tclass td, .tclass2 td {border:1px solid #000;background:#FFFCCC;padding: 2px;font-family: Courier New, Arial;font-size: 11px;} |
027 | .tclass2 th {background:#D5EAEA;} |
028 | .tclass2 td {background:#FFFFFF;} |
029 | .firsttr td {border-top:0;} |
030 | .firsttd {border-left:none !important;} |
031 | .bold {font-weight:bold;} |
032 | </style> |
033 | '; |
034 | // 定义class的名字 |
035 | $class = 'tclass2'; |
036 | // 判断$_SGLOBAL['debug_query']为空,就将键名设置为空数组 |
037 | if(empty($_SGLOBAL['debug_query'])) $_SGLOBAL['debug_query'] = array(); |
038 | |
039 | /* |
040 | 循环数组, 无论它有没有内容. |
041 | 内容的主体是计算了一些mysql执行语句的时间及优化等等,在class/db_mysql.class.php文件中有这一段 |
042 | if(D_BUG) { |
043 | global $_SGLOBAL; |
044 | if(empty($_SGLOBAL['debug_query'])) $_SGLOBAL['debug_query'] = array(); |
045 | $mtime = explode(' ', microtime()); |
046 | $sqltime = number_format(($mtime[1] + $mtime[0] - $sqlstarttime), 6)*1000; |
047 | $explain = array(); |
048 | $info = mysql_info(); |
049 | if(strtolower(substr($sql,0,7)) == 'select ') { |
050 | $explain = mysql_fetch_assoc(mysql_query('EXPLAIN '.$sql, $this->link_identifier)); |
051 | } |
052 | $_SGLOBAL['debug_query'][] = array('sql'=>$sql, 'time'=>$sqltime, 'info'=>$info, 'explain'=>$explain); |
053 | } |
054 | 以上是对$_SGLOBAL['debug_query']数组写入了当前mysql执行的数据。 |
055 | */ |
056 | foreach ($_SGLOBAL['debug_query'] as $dkey => $debug) { |
057 | ($class == 'tclass')?$class = 'tclass2':$class = 'tclass'; |
058 | echo '<table cellspacing="0" class="'.$class.'"><tr><th rowspan="2" width="20">'.($dkey+1).'</th><td width="60">'.$debug['time'].' ms</td><td class="bold">'.shtmlspecialchars($debug['sql']).'</td></tr>'; |
059 | if(!empty($debug['info'])) { |
060 | echo '<tr><td>Info</th><td>'.$debug['info'].'</td></tr>'; |
061 | } |
062 | if(!empty($debug['explain'])) { |
063 | echo '<tr><td>Explain</td><td><table cellspacing="0"><tr class="firsttr"><td width="5%" class="firsttd">id</td><td width="10%">select_type</td><td width="12%">table</td><td width="5%">type</td><td width="20%">possible_keys</td><td width="10%">key</td><td width="8%">key_len</td><td width="5%">ref</td><td width="5%">rows</td><td width="20%">Extra</td></tr><tr>'; |
064 | foreach ($debug['explain'] as $ekey => $explain) { |
065 | ($ekey == 'id')?$tdclass = ' class="firsttd"':$tdclass=''; |
066 | if(empty($explain)) $explain = '-'; |
067 | echo '<td'.$tdclass.'>'.$explain.'</td>'; |
068 | } |
069 | echo '</tr></table></td></tr>'; |
070 | } |
071 | echo '</table>'; |
072 | } |
073 | |
074 | // 以下是取得当前页所有include的文件, 注意判断中的是=不是== |
075 | if($files = get_included_files()) { |
076 | ($class == 'tclass')?$class = 'tclass2':$class = 'tclass'; |
077 | echo '<table class="'.$class.'">'; |
078 | foreach ($files as $fkey => $file) { |
079 | echo '<tr><th width="20">'.($fkey+1).'</th><td>'.$file.'</td></tr>'; |
080 | } |
081 | echo '</table>'; |
082 | } |
083 | |
084 | // 以下是循环列表cookie的内容, 注意判断是赋值 |
085 | if($cookies = $_COOKIE) { |
086 | ($class == 'tclass')?$class = 'tclass2':$class = 'tclass'; |
087 | $i = 1; |
088 | echo '<table class="'.$class.'">'; |
089 | foreach ($cookies as $ckey => $cookie) { |
090 | echo '<tr><th width="20">'.$i.'</th><td width="250">$_COOKIE[\''.$ckey.'\']</td><td>'.$cookie.'</td></tr>'; |
091 | $i++; |
092 | } |
093 | echo '</table>'; |
094 | } |
095 | |
096 | // 以下是对_SERVER数组进行列表, 但事实上永远不会打开, 因为判断中写了个条件0 |
097 | if(0 && $server = $_SERVER) { |
098 | ($class == 'tclass')?$class = 'tclass2':$class = 'tclass'; |
099 | $i = 1; |
100 | echo '<table class="'.$class.'">'; |
101 | foreach ($server as $ckey => $value) { |
102 | echo '<tr><th width="20">'.$i.'</th><td width="250">$_SERVER[\''.$ckey.'\']</td><td>'.$value.'</td></tr>'; |
103 | $i++; |
104 | } |
105 | echo '</table>'; |
106 | } |
107 | |
108 | // 对字符数据流数组进行列表。 |
109 | if($values = $_REQUEST) { |
110 | ($class == 'tclass')?$class = 'tclass2':$class = 'tclass'; |
111 | $i = 1; |
112 | echo '<table class="'.$class.'">'; |
113 | foreach ($values as $ckey => $value) { |
114 | echo '<tr><th width="20">'.$i.'</th><td width="250">$_REQUEST[\''.$ckey.'\']</td><td>'.$value.'</td></tr>'; |
115 | $i++; |
116 | } |
117 | echo '</table>'; |
118 | } |
119 | } |
120 |
121 | ?>
|
浙公网安备 33010602011771号