求个mhp3 hd iso攻击力x128的cmf

项目语言:PHP
权限:read-only(如需更高权限请先加入项目)
Index: UpgradeNoticeBehavior.class.php
===================================================================
--- UpgradeNoticeBehavior.class.php (revision 0)
+++ UpgradeNoticeBehavior.class.php (revision 2)
@@ -0,0 +1,117 @@
+// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
+// | Copyright (c)
http://thinkphp.cn All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
+// +----------------------------------------------------------------------
+// | Author: luofei614&www.3g4k.com&
+// +----------------------------------------------------------------------
+namespace B
+ * 升级短信通知, 如果有ThinkPHP新版升级,或者重要的更新,会发送短信通知你。
+ * 需要使用SAE的短信服务。请先找一个SAE的应用开通短信服务。
+ * 使用步骤如下:
+ * 1,在项目的Conf目录下建立tags.php配置文件,内容如下:
+ * &code&
+ * return array(
'app_init' =&
array('UpgradeNotice')
+ * &/code&
+ * 2,将此文件放在应用的Lib/Behavior文件夹下。
+ *注:在SAE上面使用时,以上两步可以省略
+ * 3,在config.php中配置:
'UPGRADE_NOTICE_ON'=&true,//开启短信升级提醒功能
+ * 'UPGRADE_NOTICE_AKEY'=&'your akey',//SAE应用的AKEY,如果在SAE上使用可以不填
+ * 'UPGRADE_NOTICE_SKEY'=&'your skey',//SAE应用的SKEY,如果在SAE上使用可以不填
+ *'UPGRADE_NOTICE_MOBILE'=&'',//接受短信的手机号
+ *'UPGRADE_NOTICE_CHECK_INTERVAL' =& 604800,//检测频率,单位秒,默认是一周
+ *'UPGRADE_CURRENT_VERSION'=&'0',//升级后的版本号,会在短信中告诉你填写什么
+ *UPGRADE_NOTICE_DEBUG=&true, //调试默认,如果为true,UPGRADE_NOTICE_CHECK_INTERVAL配置不起作用,每次都会进行版本检查,此时用于调试,调试完毕后请设置次配置为false
+class UpgradeNoticeBehavior {
protected $header_ = '';
protected $httpCode_;
protected $httpDesc_;
protected $accesskey_;
protected $secretkey_;
public function run(&$params) {
if (C('UPGRADE_NOTICE_ON') && (!S('think_upgrade_interval') || C('UPGRADE_NOTICE_DEBUG'))) {
if(IS_SAE && C('UPGRADE_NOTICE_QUEUE') && !isset($_POST['think_upgrade_queque'])){
$queue=new SaeTaskQueue(C('UPGRADE_NOTICE_QUEUE'));
$queue-&addTask('http://'.$_SERVER['HTTP_HOST'].__APP__,'think_upgrade_queque=1');
if(!$queue-&push()){
trace('升级提醒队列执行失败,错误原因:'.$queue-&errmsg(), '升级通知出错', 'NOTIC', true);
$akey = C('UPGRADE_NOTICE_AKEY',null,'');
$skey = C('UPGRADE_NOTICE_SKEY',null,'');
$this-&accesskey_ = $akey ? $akey : (defined('SAE_ACCESSKEY') ? SAE_ACCESSKEY : '');
$this-&secretkey_ = $skey ? $skey : (defined('SAE_SECRETKEY') ? SAE_SECRETKEY : '');
$current_version = C('UPGRADE_CURRENT_VERSION',null,0);
//读取接口
$info = $this-&send('http://sinaclouds.sinaapp.com/thinkapi/upgrade.php?v=' . $current_version);
if ($info['version'] != $current_version) {
if($this-&send_sms($info['msg']))
trace($info['msg'], '升级通知成功', 'NOTIC', true); //发送升级短信
S('think_upgrade_interval', true, C('UPGRADE_NOTICE_CHECK_INTERVAL',null,604800));
private function send_sms($msg) {
$timestamp=time();
$url = 'http://inno.smsinter.sina.com.cn/sae_sms_service/sendsms.php'; //发送短信的接口地址
$content = &FetchUrl& . $url . &TimeStamp& . $timestamp . &AccessKey& . $this-&accesskey_;
$signature = (base64_encode(hash_hmac('sha256', $content, $this-&secretkey_, true)));
$headers = array(
&FetchUrl: $url&,
&AccessKey: &.$this-&accesskey_,
&TimeStamp: & . $timestamp,
&Signature: $signature&
$data = array(
'mobile' =& C('UPGRADE_NOTICE_MOBILE',null,'') ,
'msg' =& $msg,
'encoding' =& 'UTF-8'
if(!$ret = $this-&send('http://g.apibus.io', $data, $headers)){
if (isset($ret['ApiBusError'])) {
trace('errno:' . $ret['ApiBusError']['errcode'] . ',errmsg:' . $ret['ApiBusError']['errdesc'], '升级通知出错', 'NOTIC', true);
private function send($url, $params = array() , $headers = array()) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
if (!empty($params)) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
if (!empty($headers)) curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$txt = curl_exec($ch);
if (curl_errno($ch)) {
trace(curl_error($ch) , '升级通知出错', 'NOTIC', true);
curl_close($ch);
$ret = json_decode($txt, true);
if (!$ret) {
trace('接口[' . $url . ']返回格式不正确', '升级通知出错', 'NOTIC', true);
Index: CheckActionRouteBehavior.class.php
===================================================================
--- CheckActionRouteBehavior.class.php (revision 0)
+++ CheckActionRouteBehavior.class.php (revision 2)
@@ -0,0 +1,194 @@
+// +----------------------------------------------------------------------
+// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
+// +----------------------------------------------------------------------
+// | Copyright (c)
http://thinkphp.cn All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
+// +----------------------------------------------------------------------
+// | Author: liu21st &&
+// +----------------------------------------------------------------------
+namespace B
+ * 系统行为扩展:操作路由检测
+class CheckActionRouteBehavior {
// 行为扩展的执行入口必须是run
public function run(&$config){
// 优先检测是否存在PATH_INFO
trim($_SERVER['PATH_INFO'],'/');
if(empty($regx))
// 路由定义文件优先于config中的配置定义
// 路由处理
$config['routes'];
if(!empty($routes)) {
$depr = C('URL_PATHINFO_DEPR');
// 分隔符替换 确保路由定义使用统一的分隔符
$regx = str_replace($depr,'/',$regx);
$regx = substr_replace($regx,'',0,strlen(__URL__));
foreach ($routes as $rule=&$route){
if(0===strpos($rule,'/') && preg_match($rule,$regx,$matches)) { // 正则路由
return C('ACTION_NAME',$this-&parseRegex($matches,$route,$regx));
}else{ // 规则路由
substr_count($regx,'/');
substr_count($rule,'/');
if($len1&=$len2) {
if('$' == substr($rule,-1,1)) {// 完整匹配
if($len1 != $len2) {
substr($rule,0,-1);
$this-&checkUrlMatch($regx,$rule);
if($match)
return C('ACTION_NAME',$this-&parseRule($rule,$route,$regx));
// 检测URL和规则路由是否匹配
private function checkUrlMatch($regx,$rule) {
explode('/',$regx);
explode('/',$rule);
= // 是否匹配
foreach ($m2 as $key=&$val){
if(':' == substr($val,0,1)) {// 动态变量
if(strpos($val,'\\')) {
$type = substr($val,-1);
if('d'==$type && !is_numeric($m1[$key])) {
}elseif(strpos($val,'^')){
explode('|',substr(strstr($val,'^'),1));
if(in_array($m1[$key],$array)) {
}elseif(0 !== strcasecmp($val,$m1[$key])){
// 解析规范的路由地址
// 地址格式 操作?参数1=值1&参数2=值2...
private function parseUrl($url) {
if(false !== strpos($url,'?')) { // 操作?参数1=值1&参数2=值2...
parse_url($url);
$info['path'];
parse_str($info['query'],$var);
}else{ // 操作
$var[C('VAR_ACTION')] = $
// 解析规则路由
// '路由规则'=&'操作?额外参数1=值1&额外参数2=值2...'
// '路由规则'=&array('操作','额外参数1=值1&额外参数2=值2...')
// '路由规则'=&'外部地址'
// '路由规则'=&array('外部地址','重定向代码')
// 路由规则中 :开头 表示动态变量
// 外部地址中可以用动态变量 采用 :1 :2 的方式
// 'news/:month/:day/:id'=&array('News/read?cate=1','status=1'),
// 'new/:id'=&array('/new.php?id=:1',301), 重定向
private function parseRule($rule,$route,$regx) {
// 获取路由地址规则
is_array($route)?$route[0]:$
// 获取URL地址中的参数
explode('/',$regx);
// 解析路由规则
explode('/',$rule);
foreach ($rule as $item){
if(0===strpos($item,':')) { // 动态变量获取
if($pos = strpos($item,'^') ) {
substr($item,1,$pos-1);
}elseif(strpos($item,'\\')){
substr($item,1,-2);
substr($item,1);
$matches[$var] = array_shift($paths);
}else{ // 过滤URL中的静态变量
array_shift($paths);
if(0=== strpos($url,'/') || 0===strpos($url,'http')) { // 路由重定向跳转
if(strpos($url,':')) { // 传递动态参数
array_values($matches);
preg_replace('/:(\d+)/e','$values[\\1-1]',$url);
header(&Location: $url&, true,(is_array($route) && isset($route[1]))?$route[1]:301);
// 解析路由地址
$this-&parseUrl($url);
// 解析路由地址里面的动态参数
array_values($matches);
foreach ($var as $key=&$val){
if(0===strpos($val,':')) {
$var[$key] =
$values[substr($val,1)-1];
array_merge($matches,$var);
// 解析剩余的URL参数
if($paths) {
preg_replace('@(\w+)\/([^\/]+)@e', '$var[strtolower(\'\\1\')]=strip_tags(\'\\2\');', implode('/',$paths));
// 解析路由自动传入参数
if(is_array($route) && isset($route[1])) {
parse_str($route[1],$params);
array_merge($var,$params);
$var[C('VAR_ACTION')];
unset($var[C('VAR_ACTION')]);
array_merge($var,$_GET);
// 解析正则路由
// '路由正则'=&'[分组/模块/操作]?参数1=值1&参数2=值2...'
// '路由正则'=&array('[分组/模块/操作]?参数1=值1&参数2=值2...','额外参数1=值1&额外参数2=值2...')
// '路由正则'=&'外部地址'
// '路由正则'=&array('外部地址','重定向代码')
// 参数值和外部地址中可以用动态变量 采用 :1 :2 的方式
// '/new\/(\d+)\/(\d+)/'=&array('News/read?id=:1&page=:2&cate=1','status=1'),
// '/new\/(\d+)/'=&array('/new.php?id=:1&page=:2&status=1','301'), 重定向
private function parseRegex($matches,$route,$regx) {
// 获取路由地址规则
is_array($route)?$route[0]:$
preg_replace('/:(\d+)/e','$matches[\\1]',$url);
if(0=== strpos($url,'/') || 0===strpos($url,'http')) { // 路由重定向跳转
header(&Location: $url&, true,(is_array($route) && isset($route[1]))?$route[1]:301);
// 解析路由地址
$this-&parseUrl($url);
// 解析剩余的URL参数
substr_replace($regx,'',0,strlen($matches[0]));
if($regx) {
preg_replace('@(\w+)\/([^,\/]+)@e', '$var[strtolower(\'\\1\')]=strip_tags(\'\\2\');', $regx);
// 解析路由自动传入参数
if(is_array($route) && isset($route[1])) {
parse_str($route[1],$params);
array_merge($var,$params);
$var[C('VAR_ACTION')];
unset($var[C('VAR_ACTION')]);
array_merge($var,$_GET);
\ No newline at end of file
Index: ChromeShowPageTraceBehavior.class.php
===================================================================
--- ChromeShowPageTraceBehavior.class.php (revision 0)
+++ ChromeShowPageTraceBehavior.class.php (revision 2)
@@ -0,0 +1,610 @@
+// +----------------------------------------------------------------------
+// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
+// +----------------------------------------------------------------------
+// | Copyright (c)
http://thinkphp.cn All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
+// +----------------------------------------------------------------------
+// | Author: luofei614 &weibo.com/luofei614&
+// +----------------------------------------------------------------------
+ * 将Trace信息输出到chrome浏览器的控制器,从而不影响ajax效果和页面的布局。
+ * 使用前,你需要先安装 chrome log 这个插件: http://craig.is/writing/chrome-logger。
+ * 定义应用的tags.php文件 Application/Common/Conf/tags.php,
+ * &code&
+ * &?php return array(
'app_end'=&array(
'Behavior\ChromeShowPageTrace'
+ * &/code&
+ * 如果trace信息没有正常输出,请查看您的日志。
+ * 这是通过http headers和chrome通信,所以要保证在输出trace信息之前不能有
+ * headers输出,你可以在入口文件第一行加入代码 ob_start(); 或者配置output_buffering
+namespace B
+use Think\L
+ * 系统行为扩展 页面Trace显示输出
+class ChromeShowPageTraceBehavior {
protected $tracePageTabs =
array('BASE'=&'基本','FILE'=&'文件','INFO'=&'流程','ERR|NOTIC'=&'错误','SQL'=&'SQL','DEBUG'=&'调试');
// 行为扩展的执行入口必须是run
public function run(&$params){
if(C('SHOW_PAGE_TRACE')) $this-&showTrace();
* 显示页面Trace信息
* @access private
private function showTrace() {
// 系统默认显示信息
get_included_files();
foreach ($files as $key=&$file){
$info[] = $file.' ( '.number_format(filesize($file)/1024,2).' KB )';
'请求信息'
date('Y-m-d H:i:s',$_SERVER['REQUEST_TIME']).' '.$_SERVER['SERVER_PROTOCOL'].' '.$_SERVER['REQUEST_METHOD'].' : '.__SELF__,
'运行时间'
$this-&showTime(),
'吞吐率' =& number_format(1/G('beginTime','viewEndTime'),2).'req/s',
'内存开销'
MEMORY_LIMIT_ON?number_format((memory_get_usage() - $GLOBALS['_startUseMems'])/1024,2).' kb':'不支持',
'查询信息'
N('db_query').' queries '.N('db_write').' writes ',
'文件加载'
count(get_included_files()),
'缓存信息'
N('cache_read').' gets '.N('cache_write').' writes ',
'配置加载'
count(c()),
'会话信息'
'SESSION_ID='.session_id(),
// 读取应用定义的Trace文件
$traceFile
COMMON_PATH.'Conf/trace.php';
if(is_file($traceFile)) {
array_merge($base,include $traceFile);
C('TRACE_PAGE_TABS',null,$this-&tracePageTabs);
foreach ($tabs as $name=&$title){
switch(strtoupper($name)) {
case 'BASE':// 基本信息
$trace[$title]
case 'FILE': // 文件信息
$trace[$title]
default:// 调试信息
strtoupper($name);
if(strpos($name,'|')) {// 多组信息
explode('|',$name);
foreach($array as $name){
isset($debug[$name])?$debug[$name]:array();
$trace[$title]
$trace[$title]
isset($debug[$name])?$debug[$name]:'';
chrome_debug('TRACE信息:'.__SELF__,'group');
//输出日志
foreach($trace as $title=&$log){
'错误'==$title?chrome_debug($title,'group'):chrome_debug($title,'groupCollapsed');
foreach($log as $i=&$logstr){
chrome_debug($i.'.'.$logstr,'log');
chrome_debug('','groupEnd');
chrome_debug('','groupEnd');
if($save = C('PAGE_TRACE_SAVE')) { // 保存页面Trace日志
if(is_array($save)) {// 选择选项卡保存
C('TRACE_PAGE_TABS',null,$this-&tracePageTabs);
foreach ($save as $tab){
$array[] =
$tabs[$tab];
date('[ c ]').' '.get_client_ip().' '.$_SERVER['REQUEST_URI'].&\r\n&;
foreach ($trace as $key=&$val){
if(!isset($array) || in_array($key,$array)) {
'[ '.$key.& ]\r\n&;
if(is_array($val)) {
foreach ($val as $k=&$v){
$content .= (!is_numeric($k)?$k.':':'').print_r($v,true).&\r\n&;
$content .= print_r($val,true).&\r\n&;
$content .= &\r\n&;
error_log(str_replace('&br/&',&\r\n&,$content), 3,LOG_PATH.date('y_m_d').'_trace.log');
unset($files,$info,$base);
* 获取运行时间
private function showTime() {
// 显示运行时间
G('beginTime',$GLOBALS['_beginTime']);
G('viewEndTime');
// 显示详细运行时间
return G('beginTime','viewEndTime').'s ( Load:'.G('beginTime','loadTime').'s Init:'.G('loadTime','initTime').'s Exec:'.G('initTime','viewStartTime').'s Template:'.G('viewStartTime','viewEndTime').'s )';
+if(!function_exists('chrome_debug')){
+//ChromePhp 输出trace的函数
+function chrome_debug($msg,$type='trace',$trace_level=1){
if('trace'==$type){
ChromePhp::groupCollapsed($msg);
$traces=debug_backtrace(false);
$traces=array_reverse($traces);
$max=count($traces)-$trace_
for($i=0;$i&$$i++){
$trace=$traces[$i];
$fun=isset($trace['class'])?$trace['class'].'::'.$trace['function']:$trace['function'];
$file=isset($trace['file'])?$trace['file']:'unknown file';
$line=isset($trace['line'])?$trace['line']:'unknown line';
$trace_msg='#'.$i.'
'.$fun.' called at ['.$file.':'.$line.']';
if(!empty($trace['args'])){
ChromePhp::groupCollapsed($trace_msg);
ChromePhp::log($trace['args']);
ChromePhp::groupEnd();
ChromePhp::log($trace_msg);
ChromePhp::groupEnd();
if(method_exists('Behavior\ChromePhp',$type)){
//支持type trace,warn,log,error,group, groupCollapsed, groupEnd等
call_user_func(array('Behavior\ChromePhp',$type),$msg);
//如果type不为trace,warn,log等,则为log的标签
call_user_func_array(array('Behavior\ChromePhp','log'),func_get_args());
+ * Server Side Chrome PHP debugger class
+ * @package ChromePhp
+ * @author Craig Campbell &&
+class ChromePhp{
* @var string
const VERSION = '4.1.0';
* @var string
const HEADER_NAME = 'X-ChromeLogger-Data';
* @var string
const BACKTRACE_LEVEL = 'backtrace_level';
* @var string
const LOG = 'log';
* @var string
const WARN = 'warn';
* @var string
const ERROR = 'error';
* @var string
const GROUP = 'group';
* @var string
const INFO = 'info';
* @var string
const GROUP_END = 'groupEnd';
* @var string
const GROUP_COLLAPSED = 'groupCollapsed';
* @var string
const TABLE = 'table';
* @var string
protected $_php_
* @var int
protected $_
* @var array
protected $_json = array(
'version' =& self::VERSION,
'columns' =& array('log', 'backtrace', 'type'),
'rows' =& array()
* @var array
protected $_backtraces = array();
* @var bool
protected $_error_triggered =
* @var array
protected $_settings = array(
self::BACKTRACE_LEVEL =& 1
* @var ChromePhp
protected static $_
* Prevent recursion when working with objects referring to each other
* @var array
protected $_processed = array();
* constructor
private function __construct()
$this-&_php_version = phpversion();
$this-&_timestamp = $this-&_php_version &= 5.1 ? $_SERVER['REQUEST_TIME'] : time();
$this-&_json['request_uri'] = $_SERVER['REQUEST_URI'];
* gets instance of this class
* @return ChromePhp
public static function getInstance()
if (self::$_instance === null) {
self::$_instance = new self();
return self::$_
* logs a variable to the console
* @param mixed $data,... unlimited OPTIONAL number of additional logs [...]
* @return void
public static function log()
$args = func_get_args();
return self::_log('', $args);
* logs a warning to the console
* @param mixed $data,... unlimited OPTIONAL number of additional logs [...]
* @return void
public static function warn()
$args = func_get_args();
return self::_log(self::WARN, $args);
* logs an error to the console
* @param mixed $data,... unlimited OPTIONAL number of additional logs [...]
* @return void
public static function error()
$args = func_get_args();
return self::_log(self::ERROR, $args);
* sends a group log
* @param string value
public static function group()
$args = func_get_args();
return self::_log(self::GROUP, $args);
* sends an info log
* @param mixed $data,... unlimited OPTIONAL number of additional logs [...]
* @return void
public static function info()
$args = func_get_args();
return self::_log(self::INFO, $args);
* sends a collapsed group log
* @param string value
public static function groupCollapsed()
$args = func_get_args();
return self::_log(self::GROUP_COLLAPSED, $args);
* ends a group log
* @param string value
public static function groupEnd()
$args = func_get_args();
return self::_log(self::GROUP_END, $args);
* sends a table log
* @param string value
public static function table()
$args = func_get_args();
return self::_log(self::TABLE, $args);
* internal logging call
* @param string $type
* @return void
protected static function _log($type, array $args)
// nothing passed in, don't do anything
if (count($args) == 0 && $type != self::GROUP_END) {
$logger = self::getInstance();
$logger-&_processed = array();
$logs = array();
foreach ($args as $arg) {
$logs[] = $logger-&_convert($arg);
$backtrace = debug_backtrace(false);
$level = $logger-&getSetting(self::BACKTRACE_LEVEL);
$backtrace_message = 'unknown';
if (isset($backtrace[$level]['file']) && isset($backtrace[$level]['line'])) {
$backtrace_message = $backtrace[$level]['file'] . ' : ' . $backtrace[$level]['line'];
$logger-&_addRow($logs, $backtrace_message, $type);
* converts an object to a better format for logging
* @param Object
* @return array
protected function _convert($object)
// if this isn't an object then just return it
if (!is_object($object)) {
//Mark this object as processed so we don't convert it twice and it
//Also avoid recursion when objects refer to each other
$this-&_processed[] = $
$object_as_array = array();
// first add the class name
$object_as_array['___class_name'] = get_class($object);
// loop through object vars
$object_vars = get_object_vars($object);
foreach ($object_vars as $key =& $value) {
// same instance as parent object
if ($value === $object || in_array($value, $this-&_processed, true)) {
$value = 'recursion - parent object [' . get_class($value) . ']';
$object_as_array[$key] = $this-&_convert($value);
$reflection = new ReflectionClass($object);
// loop through the properties and add those
foreach ($reflection-&getProperties() as $property) {
// if one of these properties was already added above then ignore it
if (array_key_exists($property-&getName(), $object_vars)) {
$type = $this-&_getPropertyKey($property);
if ($this-&_php_version &= 5.3) {
$property-&setAccessible(true);
$value = $property-&getValue($object);
} catch (ReflectionException $e) {
$value = 'only PHP 5.3 can access private/protected properties';
// same instance as parent object
if ($value === $object || in_array($value, $this-&_processed, true)) {
$value = 'recursion - parent object [' . get_class($value) . ']';
$object_as_array[$type] = $this-&_convert($value);
return $object_as_
* takes a reflection property and returns a nicely formatted key of the property name
* @param ReflectionProperty
* @return string
protected function _getPropertyKey(ReflectionProperty $property)
$static = $property-&isStatic() ? ' static' : '';
if ($property-&isPublic()) {
return 'public' . $static . ' ' . $property-&getName();
if ($property-&isProtected()) {
return 'protected' . $static . ' ' . $property-&getName();
if ($property-&isPrivate()) {
return 'private' . $static . ' ' . $property-&getName();
* adds a value to the data array
* @var mixed
* @return void
protected function _addRow(array $logs, $backtrace, $type)
// if this is logged on the same line for example in a loop, set it to null to save space
if (in_array($backtrace, $this-&_backtraces)) {
$backtrace =
// for group, groupEnd, and groupCollapsed
// take out the backtrace since it is not useful
if ($type == self::GROUP || $type == self::GROUP_END || $type == self::GROUP_COLLAPSED) {
$backtrace =
if ($backtrace !== null) {
$this-&_backtraces[] = $
$row = array($logs, $backtrace, $type);
$this-&_json['rows'][] = $
$this-&_writeHeader($this-&_json);
protected function _writeHeader($data)
header(self::HEADER_NAME . ': ' . $this-&_encode($data));
* encodes the data to be sent along with the request
* @param array $data
* @return string
protected function _encode($data)
return base64_encode(utf8_encode(json_encode($data)));
* adds a setting
* @param string key
* @param mixed value
* @return void
public function addSetting($key, $value)
$this-&_settings[$key] = $
* add ability to set multiple settings in one call
* @param array $settings
* @return void
public function addSettings(array $settings)
foreach ($settings as $key =& $value) {
$this-&addSetting($key, $value);
* gets a setting
* @param string key
* @return mixed
public function getSetting($key)
if (!isset($this-&_settings[$key])) {
return $this-&_settings[$key];
Index: AgentCheckBehavior.class.php
===================================================================
--- AgentCheckBehavior.class.php (revision 0)
+++ AgentCheckBehavior.class.php (revision 2)
@@ -0,0 +1,24 @@
+// +----------------------------------------------------------------------
+// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2009 http://thinkphp.cn All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
+// +----------------------------------------------------------------------
+// | Author: liu21st &&
+// +----------------------------------------------------------------------
+namespace B
+ * 行为扩展:代理检测
+class AgentCheckBehavior {
public function run(&$params) {
// 代理访问检测
$limitProxyVisit =
C('LIMIT_PROXY_VISIT',null,true);
if($limitProxyVisit && ($_SERVER['HTTP_X_FORWARDED_FOR'] || $_SERVER['HTTP_VIA'] || $_SERVER['HTTP_PROXY_CONNECTION'] || $_SERVER['HTTP_USER_AGENT_VIA'])) {
// 禁止代理访问
exit('Access Denied');
Index: ShowPageTraceBehavior.class.php
===================================================================
--- ShowPageTraceBehavior.class.php (revision 0)
+++ ShowPageTraceBehavior.class.php (revision 2)
@@ -0,0 +1,119 @@
+// +----------------------------------------------------------------------
+// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
+// +----------------------------------------------------------------------
+// | Copyright (c)
http://thinkphp.cn All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
+// +----------------------------------------------------------------------
+// | Author: liu21st &&
+// +----------------------------------------------------------------------
+namespace B
+use Think\L
+ * 系统行为扩展:页面Trace显示输出
+class ShowPageTraceBehavior {
protected $tracePageTabs =
array('BASE'=&'基本','FILE'=&'文件','INFO'=&'流程','ERR|NOTIC'=&'错误','SQL'=&'SQL','DEBUG'=&'调试');
// 行为扩展的执行入口必须是run
public function run(&$params){
if(!IS_AJAX && !IS_CLI && C('SHOW_PAGE_TRACE')) {
echo $this-&showTrace();
* 显示页面Trace信息
* @access private
private function showTrace() {
// 系统默认显示信息
get_included_files();
foreach ($files as $key=&$file){
$info[] = $file.' ( '.number_format(filesize($file)/1024,2).' KB )';
'请求信息'
date('Y-m-d H:i:s',$_SERVER['REQUEST_TIME']).' '.$_SERVER['SERVER_PROTOCOL'].' '.$_SERVER['REQUEST_METHOD'].' : '.__SELF__,
'运行时间'
$this-&showTime(),
'吞吐率'
number_format(1/G('beginTime','viewEndTime'),2).'req/s',
'内存开销'
MEMORY_LIMIT_ON?number_format((memory_get_usage() - $GLOBALS['_startUseMems'])/1024,2).' kb':'不支持',
'查询信息'
N('db_query').' queries '.N('db_write').' writes ',
'文件加载'
count(get_included_files()),
'缓存信息'
N('cache_read').' gets '.N('cache_write').' writes ',
'配置加载'
count(C()),
'会话信息'
'SESSION_ID='.session_id(),
// 读取应用定义的Trace文件
$traceFile
COMMON_PATH.'Conf/trace.php';
if(is_file($traceFile)) {
array_merge($base,include $traceFile);
C('TRACE_PAGE_TABS',null,$this-&tracePageTabs);
foreach ($tabs as $name=&$title){
switch(strtoupper($name)) {
case 'BASE':// 基本信息
$trace[$title]
case 'FILE': // 文件信息
$trace[$title]
default:// 调试信息
strtoupper($name);
if(strpos($name,'|')) {// 多组信息
explode('|',$name);
foreach($names as $name){
isset($debug[$name])?$debug[$name]:array();
$trace[$title]
$trace[$title]
isset($debug[$name])?$debug[$name]:'';
if($save = C('PAGE_TRACE_SAVE')) { // 保存页面Trace日志
if(is_array($save)) {// 选择选项卡保存
C('TRACE_PAGE_TABS',null,$this-&tracePageTabs);
foreach ($save as $tab){
$array[] =
$tabs[$tab];
date('[ c ]').' '.get_client_ip().' '.$_SERVER['REQUEST_URI'].&\r\n&;
foreach ($trace as $key=&$val){
if(!isset($array) || in_array_case($key,$array)) {
'[ '.$key.& ]\r\n&;
if(is_array($val)) {
foreach ($val as $k=&$v){
$content .= (!is_numeric($k)?$k.':':'').print_r($v,true).&\r\n&;
$content .= print_r($val,true).&\r\n&;
$content .= &\r\n&;
error_log(str_replace('&br/&',&\r\n&,$content), 3,C('LOG_PATH').date('y_m_d').'_trace.log');
unset($files,$info,$base);
// 调用Trace页面模板
ob_start();
include C('TMPL_TRACE_FILE')?C('TMPL_TRACE_FILE'):THINK_PATH.'Tpl/page_trace.tpl';
return ob_get_clean();
* 获取运行时间
private function showTime() {
// 显示运行时间
G('beginTime',$GLOBALS['_beginTime']);
G('viewEndTime');
// 显示详细运行时间
return G('beginTime','viewEndTime').'s ( Load:'.G('beginTime','loadTime').'s Init:'.G('loadTime','initTime').'s Exec:'.G('initTime','viewStartTime').'s Template:'.G('viewStartTime','viewEndTime').'s )';
Index: TokenBuildBehavior.class.php
===================================================================
--- TokenBuildBehavior.class.php (revision 0)
+++ TokenBuildBehavior.class.php (revision 2)
@@ -0,0 +1,54 @@
+// +----------------------------------------------------------------------
+// | TOPThink [ WE CAN DO IT JUST THINK ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2010 http://topthink.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
+// +----------------------------------------------------------------------
+// | Author: liu21st &&
+// +----------------------------------------------------------------------
+namespace B
+ * 系统行为扩展:表单令牌生成
+class TokenBuildBehavior {
public function run(&$content){
if(C('TOKEN_ON')) {
list($tokenName,$tokenKey,$tokenValue)=$this-&getToken();
$input_token = '&input type=&hidden& name=&'.$tokenName.'& value=&'.$tokenKey.'_'.$tokenValue.'& /&';
$meta_token = '&meta name=&'.$tokenName.'& content=&'.$tokenKey.'_'.$tokenValue.'& /&';
if(strpos($content,'{__TOKEN__}')) {
// 指定表单令牌隐藏域位置
$content = str_replace('{__TOKEN__}',$input_token,$content);
}elseif(preg_match('/&\/form(\s*)&/is',$content,$match)) {
// 智能生成表单令牌隐藏域
$content = str_replace($match[0],$input_token.$match[0],$content);
$content = str_ireplace('&/head&',$meta_token.'&/head&',$content);
$content = str_replace('{__TOKEN__}','',$content);
//获得token
private function getToken(){
$tokenName
= C('TOKEN_NAME',null,'__hash__');
$tokenType
= C('TOKEN_TYPE',null,'md5');
if(!isset($_SESSION[$tokenName])) {
$_SESSION[$tokenName]
= array();
// 标识当前页面唯一性
md5($_SERVER['REQUEST_URI']);
if(isset($_SESSION[$tokenName][$tokenKey])) {// 相同页面不重复生成session
$tokenValue = $_SESSION[$tokenName][$tokenKey];
$tokenValue = is_callable($tokenType) ? $tokenType(microtime(true)) : md5(microtime(true));
$_SESSION[$tokenName][$tokenKey]
if(IS_AJAX && C('TOKEN_RESET',null,true))
header($tokenName.': '.$tokenKey.'_'.$tokenValue); //ajax需要获得这个header并替换页面中meta中的token值
return array($tokenName,$tokenKey,$tokenValue);
\ No newline at end of file
Index: FireShowPageTraceBehavior.class.php
===================================================================
--- FireShowPageTraceBehavior.class.php (revision 0)
+++ FireShowPageTraceBehavior.class.php (revision 2)
@@ -0,0 +1,2079 @@
+// +----------------------------------------------------------------------
+// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
+// +----------------------------------------------------------------------
+// | Copyright (c)
http://thinkphp.cn All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
+// +----------------------------------------------------------------------
+// | Author: luofei614 &weibo.com/luofei614&
+// +----------------------------------------------------------------------
+ * 将Trace信息输出到火狐的firebug,从而不影响ajax效果和页面的布局。
+ * 使用前,你需要先在火狐浏览器上安装firebug和firePHP两个插件。
+ * 定义应用的tags.php文件,
+ * &code&
+ * &?php return array(
'app_end'=&array(
'FireShowPageTrace'
+ * &/code&
+ * 再将此文件放到应用的Behavior文件夹中即可
+ * 如果trace信息没有正常输出,请查看您的日志。
+ * firePHP,是通过http headers和firebug通讯的,所以要保证在输出trace信息之前不能有
+ * headers输出,你可以在入口文件第一行加入代码 ob_start(); 或者配置output_buffering
+namespace B
+ * 系统行为扩展 页面Trace显示输出
+class FireShowPageTraceBehavior {
protected $tracePagTabs =
array('BASE'=&'基本','FILE'=&'文件','INFO'=&'流程','ERR|NOTIC'=&'错误','SQL'=&'SQL','DEBUG'=&'调试');
// 行为扩展的执行入口必须是run
public function run(&$params){
if(C('FIRE_SHOW_PAGE_TRACE',null,true)) $this-&showTrace();
* 显示页面Trace信息
* @access private
private function showTrace() {
// 系统默认显示信息
get_included_files();
foreach ($files as $key=&$file){
$info[] = $file.' ( '.number_format(filesize($file)/1024,2).' KB )';
'请求信息'=&
date('Y-m-d H:i:s',$_SERVER['REQUEST_TIME']).' '.$_SERVER['SERVER_PROTOCOL'].' '.$_SERVER['REQUEST_METHOD'].' : '.__SELF__,
'运行时间'=& $this-&showTime(),
'内存开销'=& MEMORY_LIMIT_ON?number_format((memory_get_usage() - $GLOBALS['_startUseMems'])/1024,2).' kb':'不支持',
'查询信息'=& N('db_query').' queries '.N('db_write').' writes ',
'文件加载'=& count(get_included_files()),
'缓存信息'=& N('cache_read').' gets '.N('cache_write').' writes ',
'配置加载'=& count(c()),
'会话信息'=& 'SESSION_ID='.session_id(),
// 读取应用定义的Trace文件
$traceFile
CONF_PATH.'trace.php';
if(is_file($traceFile)) {
array_merge($base,include $traceFile);
C('TRACE_PAGE_TABS',null,$this-&tracePagTabs);
foreach ($tabs as $name=&$title){
switch(strtoupper($name)) {
case 'BASE':// 基本信息
$trace[$title]
case 'FILE': // 文件信息
$trace[$title]
default:// 调试信息
if(strpos($name,'|')) {// 多组信息
explode('|',$name);
foreach($array as $name){
isset($debug[$name])?$debug[$name]:array();
$trace[$title]
$trace[$title]
isset($debug[$name])?$debug[$name]:'';
foreach ($trace as $key=&$val){
if(!is_array($val) && empty($val))
$val=array();
if(is_array($val)){
$fire=array(
array('','')
foreach($val as $k=&$v){
$fire[]=array($k,$v);
fb(array($key,$fire),FirePHP::TABLE);
fb($val,$key);
unset($files,$info,$log,$base);
* 获取运行时间
private function showTime() {
// 显示运行时间
G('beginTime',$GLOBALS['_beginTime']);
G('viewEndTime');
// 显示详细运行时间
return G('beginTime','viewEndTime').'s ( Load:'.G('beginTime','loadTime').'s Init:'.G('loadTime','initTime').'s Exec:'.G('initTime','viewStartTime').'s Template:'.G('viewStartTime','viewEndTime').'s )';
+function fb()
$instance = FirePHP::getInstance(true);
$args = func_get_args();
return call_user_func_array(array($instance,'fb'),$args);
* Enable and disable logging to Firebug
* @see FirePHP-&setEnabled()
* @param boolean $Enabled TRUE to enable, FALSE to disable
* @return void
public static function setEnabled($Enabled)
$instance = FirePHP::getInstance(true);
$instance-&setEnabled($Enabled);
* Check if logging is enabled
* @see FirePHP-&getEnabled()
* @return boolean TRUE if enabled
public static function getEnabled()
$instance = FirePHP::getInstance(true);
return $instance-&getEnabled();
* Specify a filter to be used when encoding an object
* Filters are used to exclude object members.
* @see FirePHP-&setObjectFilter()
* @param string $Class The class name of the object
* @param array $Filter An array or members to exclude
* @return void
public static function setObjectFilter($Class, $Filter)
$instance = FirePHP::getInstance(true);
$instance-&setObjectFilter($Class, $Filter);
* Set some options for the library
* @see FirePHP-&setOptions()
* @param array $Options The options to be set
* @return void
public static function setOptions($Options)
$instance = FirePHP::getInstance(true);
$instance-&setOptions($Options);
* Get options for the library
* @see FirePHP-&getOptions()
* @return array The options
public static function getOptions()
$instance = FirePHP::getInstance(true);
return $instance-&getOptions();
* Log object to firebug
* @see http://www.firephp.org/Wiki/Reference/Fb
* @param mixed $Object
* @return true
* @throws Exception
public static function send()
$instance = FirePHP::getInstance(true);
$args = func_get_args();
return call_user_func_array(array($instance,'fb'),$args);
* Start a group for following messages
* Options:
Collapsed: [true|false]
[#RRGGBB|ColorName]
* @param string $Name
* @param array $Options OPTIONAL Instructions on how to log the group
* @return true
public static function group($Name, $Options=null)
$instance = FirePHP::getInstance(true);
return $instance-&group($Name, $Options);
* Ends a group you have started before
* @return true
* @throws Exception
public static function groupEnd()
return self::send(null, null, FirePHP::GROUP_END);
* Log object with label to firebug console
* @see FirePHP::LOG
* @param mixes $Object
* @param string $Label
* @return true
* @throws Exception
public static function log($Object, $Label=null)
return self::send($Object, $Label, FirePHP::LOG);
* Log object with label to firebug console
* @see FirePHP::INFO
* @param mixes $Object
* @param string $Label
* @return true
* @throws Exception
public static function info($Object, $Label=null)
return self::send($Object, $Label, FirePHP::INFO);
* Log object with label to firebug console
* @see FirePHP::WARN
* @param mixes $Object
* @param string $Label
* @return true
* @throws Exception
public static function warn($Object, $Label=null)
return self::send($Object, $Label, FirePHP::WARN);
* Log object with label to firebug console
* @see FirePHP::ERROR
* @param mixes $Object
* @param string $Label
* @return true
* @throws Exception
public static function error($Object, $Label=null)
return self::send($Object, $Label, FirePHP::ERROR);
* Dumps key and variable to firebug server panel
* @see FirePHP::DUMP
* @param string $Key
* @param mixed $Variable
* @return true
* @throws Exception
public static function dump($Key, $Variable)
return self::send($Variable, $Key, FirePHP::DUMP);
* Log a trace in the firebug console
* @see FirePHP::TRACE
* @param string $Label
* @return true
* @throws Exception
public static function trace($Label)
return self::send($Label, FirePHP::TRACE);
* Log a table in the firebug console
* @see FirePHP::TABLE
* @param string $Label
* @param string $Table
* @return true
* @throws Exception
public static function table($Label, $Table)
return self::send($Table, $Label, FirePHP::TABLE);
+if (!defined('E_STRICT')) {
define('E_STRICT', 2048);
+if (!defined('E_RECOVERABLE_ERROR')) {
define('E_RECOVERABLE_ERROR', 4096);
+if (!defined('E_DEPRECATED')) {
define('E_DEPRECATED', 8192);
+if (!defined('E_USER_DEPRECATED')) {
define('E_USER_DEPRECATED', 16384);
+ * Sends the given data to the FirePHP Firefox Extension.
+ * The data can be displayed in the Firebug Console or in the
+ * &Server& request tab.
+ * For more information see: http://www.firephp.org/
+ * @copyright
Copyright (C)
Christoph Dorn
+ * @author
Christoph Dorn &&
+ * @license
http://www.opensource.org/licenses/bsd-license.php
+ * @package
FirePHPCore
+class FirePHP {
* FirePHP version
* @var string
const VERSION = '0.3';
// @pinf replace '0.3' with '%%package.version%%'
* Firebug LOG level
* Logs a message to firebug console.
* @var string
const LOG = 'LOG';
* Firebug INFO level
* Logs a message to firebug console and displays an info icon before the message.
* @var string
const INFO = 'INFO';
* Firebug WARN level
* Logs a message to firebug console, displays an warning icon before the message and colors the line turquoise.
* @var string
const WARN = 'WARN';
* Firebug ERROR level
* Logs a message to firebug console, displays an error icon before the message and colors the line yellow. Also increments the firebug error count.
* @var string
const ERROR = 'ERROR';
* Dumps a variable to firebug's server panel
* @var string
const DUMP = 'DUMP';
* Displays a stack trace in firebug console
* @var string
const TRACE = 'TRACE';
* Displays an exception in firebug console
* Increments the firebug error count.
* @var string
const EXCEPTION = 'EXCEPTION';
* Displays an table in firebug console
* @var string
const TABLE = 'TABLE';
* Starts a group in firebug console
* @var string
const GROUP_START = 'GROUP_START';
* Ends a group in firebug console
* @var string
const GROUP_END = 'GROUP_END';
* Singleton instance of FirePHP
* @var FirePHP
protected static $instance =
* Flag whether we are logging from within the exception handler
* @var boolean
protected $inExceptionHandler =
* Flag whether to throw PHP errors that have been converted to ErrorExceptions
* @var boolean
protected $throwErrorExceptions =
* Flag whether to convert PHP assertion errors to Exceptions
* @var boolean
protected $convertAssertionErrorsToExceptions =
* Flag whether to throw PHP assertion errors that have been converted to Exceptions
* @var boolean
protected $throwAssertionExceptions =
* Wildfire protocol message index
* @var int
protected $messageIndex = 1;
* Options for the library
* @var array
protected $options = array('maxDepth' =& 10,
'maxObjectDepth' =& 5,
'maxArrayDepth' =& 5,
'useNativeJsonEncode' =& true,
'includeLineNumbers' =& true);
* Filters used to exclude object members when encoding
* @var array
protected $objectFilters = array(
'firephp' =& array('objectStack', 'instance', 'json_objectStack'),
'firephp_test_class' =& array('objectStack', 'instance', 'json_objectStack')
* A stack of objects used to detect recursion during object encoding
* @var object
protected $objectStack = array();
* Flag to enable/disable logging
* @var boolean
protected $enabled =
* The insight console to log to if applicable
* @var object
protected $logToInsightConsole =
* When the object gets serialized only include specific object members.
* @return array
public function __sleep()
return array('options','objectFilters','enabled');
* Gets singleton instance of FirePHP
* @param boolean $AutoCreate
* @return FirePHP
public static function getInstance($AutoCreate = false)
if ($AutoCreate===true && !self::$instance) {
self::init();
return self::$
* Creates FirePHP object and stores it for singleton access
* @return FirePHP
public static function init()
return self::setInstance(new self());
* Set the instance of the FirePHP singleton
* @param FirePHP $instance The FirePHP object instance
* @return FirePHP
public static function setInstance($instance)
return self::$instance = $
* Set an Insight console to direct all logging calls to
* @param object $console The console object to log to
* @return void
public function setLogToInsightConsole($console)
if(is_string($console)) {
if(get_class($this)!='FirePHP_Insight' && !is_subclass_of($this, 'FirePHP_Insight')) {
throw new Exception('FirePHP instance not an instance or subclass of FirePHP_Insight!');
$this-&logToInsightConsole = $this-&to('request')-&console($console);
$this-&logToInsightConsole = $
* Enable and disable logging to Firebug
* @param boolean $Enabled TRUE to enable, FALSE to disable
* @return void
public function setEnabled($Enabled)
$this-&enabled = $E
* Check if logging is enabled
* @return boolean TRUE if enabled
public function getEnabled()
return $this-&
* Specify a filter to be used when encoding an object
* Filters are used to exclude object members.
* @param string $Class The class name of the object
* @param array $Filter An array of members to exclude
* @return void
public function setObjectFilter($Class, $Filter)
$this-&objectFilters[strtolower($Class)] = $F
* Set some options for the library
* Options:
- maxDepth: The maximum depth to traverse (default: 10)
- maxObjectDepth: The maximum depth to traverse objects (default: 5)
- maxArrayDepth: The maximum depth to traverse arrays (default: 5)
- useNativeJsonEncode: If true will use json_encode() (default: true)
- includeLineNumbers: If true will include line numbers and filenames (default: true)
* @param array $Options The options to be set
* @return void
public function setOptions($Options)
$this-&options = array_merge($this-&options,$Options);
* Get options from the library
* @return array The currently set options
public function getOptions()
return $this-&
* Set an option for the library
* @param string $Name
* @param mixed $Value
* @throws Exception
* @return void
public function setOption($Name, $Value)
if (!isset($this-&options[$Name])) {
throw $this-&newException('Unknown option: ' . $Name);
$this-&options[$Name] = $V
* Get an option from the library
* @param string $Name
* @throws Exception
* @return mixed
public function getOption($Name)
if (!isset($this-&options[$Name])) {
throw $this-&newException('Unknown option: ' . $Name);
return $this-&options[$Name];
* Register FirePHP as your error handler
* Will throw exceptions for each php error.
* @return mixed Returns a string containing the previously defined error handler (if any)
public function registerErrorHandler($throwErrorExceptions = false)
//NOTE: The following errors will not be caught by this error handler:
E_ERROR, E_PARSE, E_CORE_ERROR,
E_CORE_WARNING, E_COMPILE_ERROR,
E_COMPILE_WARNING, E_STRICT
$this-&throwErrorExceptions = $throwErrorE
return set_error_handler(array($this,'errorHandler'));
* FirePHP's error handler
* Throws exception for each php error that will occur.
* @param int $errno
* @param string $errstr
* @param string $errfile
* @param int $errline
* @param array $errcontext
public function errorHandler($errno, $errstr, $errfile, $errline, $errcontext)
// Don't throw exception if error reporting is switched off
if (error_reporting() == 0) {
// Only throw exceptions for errors we are asking for
if (error_reporting() & $errno) {
$exception = new ErrorException($errstr, 0, $errno, $errfile, $errline);
if ($this-&throwErrorExceptions) {
$this-&fb($exception);
* Register FirePHP as your exception handler
* @return mixed Returns the name of the previously defined exception handler,
or NULL on error.
If no previous handler was defined, NULL is also returned.
public function registerExceptionHandler()
return set_exception_handler(array($this,'exceptionHandler'));
* FirePHP's exception handler
* Logs all exceptions to your firebug console and then stops the script.
* @param Exception $Exception
* @throws Exception
function exceptionHandler($Exception)
$this-&inExceptionHandler =
header('HTTP/1.1 500 Internal Server Error');
$this-&fb($Exception);
} catch (Exception $e) {
echo 'We had an exception: ' . $e;
$this-&inExceptionHandler =
* Register FirePHP driver as your assert callback
* @param boolean $convertAssertionErrorsToExceptions
* @param boolean $throwAssertionExceptions
* @return mixed Returns the original setting or FALSE on errors
public function registerAssertionHandler($convertAssertionErrorsToExceptions = true, $throwAssertionExceptions = false)
$this-&convertAssertionErrorsToExceptions = $convertAssertionErrorsToE
$this-&throwAssertionExceptions = $throwAssertionE
if ($throwAssertionExceptions && !$convertAssertionErrorsToExceptions) {
throw $this-&newException('Cannot throw assertion exceptions as assertion errors are not being converted to exceptions!');
return assert_options(ASSERT_CALLBACK, array($this, 'assertionHandler'));
* FirePHP's assertion handler
* Logs all assertions to your firebug console and then stops the script.
* @param string $file File source of assertion
* @param int
$line Line source of assertion
* @param mixed
$code Assertion code
public function assertionHandler($file, $line, $code)
if ($this-&convertAssertionErrorsToExceptions) {
$exception = new ErrorException('Assertion Failed - Code[ '.$code.' ]', 0, null, $file, $line);
if ($this-&throwAssertionExceptions) {
$this-&fb($exception);
$this-&fb($code, 'Assertion Failed', FirePHP::ERROR, array('File'=&$file,'Line'=&$line));
* Start a group for following messages.
* Options:
Collapsed: [true|false]
[#RRGGBB|ColorName]
* @param string $Name
* @param array $Options OPTIONAL Instructions on how to log the group
* @return true
* @throws Exception
public function group($Name, $Options = null)
if (!$Name) {
throw $this-&newException('You must specify a label for the group!');
if ($Options) {
if (!is_array($Options)) {
throw $this-&newException('Options must be defined as an array!');
if (array_key_exists('Collapsed', $Options)) {
$Options['Collapsed'] = ($Options['Collapsed'])?'true':'false';
return $this-&fb(null, $Name, FirePHP::GROUP_START, $Options);
* Ends a group you have started before
* @return true
* @throws Exception
public function groupEnd()
return $this-&fb(null, null, FirePHP::GROUP_END);
* Log object with label to firebug console
* @see FirePHP::LOG
* @param mixes $Object
* @param string $Label
* @return true
* @throws Exception
public function log($Object, $Label = null, $Options = array())
return $this-&fb($Object, $Label, FirePHP::LOG, $Options);
* Log object with label to firebug console
* @see FirePHP::INFO
* @param mixes $Object
* @param string $Label
* @return true
* @throws Exception
public function info($Object, $Label = null, $Options = array())
return $this-&fb($Object, $Label, FirePHP::INFO, $Options);
* Log object with label to firebug console
* @see FirePHP::WARN
* @param mixes $Object
* @param string $Label
* @return true
* @throws Exception
public function warn($Object, $Label = null, $Options = array())
return $this-&fb($Object, $Label, FirePHP::WARN, $Options);
* Log object with label to firebug console
* @see FirePHP::ERROR
* @param mixes $Object
* @param string $Label
* @return true
* @throws Exception
public function error($Object, $Label = null, $Options = array())
return $this-&fb($Object, $Label, FirePHP::ERROR, $Options);
* Dumps key and variable to firebug server panel
* @see FirePHP::DUMP
* @param string $Key
* @param mixed $Variable
* @return true
* @throws Exception
public function dump($Key, $Variable, $Options = array())
if (!is_string($Key)) {
throw $this-&newException('Key passed to dump() is not a string');
if (strlen($Key)&100) {
throw $this-&newException('Key passed to dump() is longer than 100 characters');
if (!preg_match_all('/^[a-zA-Z0-9-_\.:]*$/', $Key, $m)) {
throw $this-&newException('Key passed to dump() contains invalid characters [a-zA-Z0-9-_\.:]');
return $this-&fb($Variable, $Key, FirePHP::DUMP, $Options);
* Log a trace in the firebug console
* @see FirePHP::TRACE
* @param string $Label
* @return true
* @throws Exception
public function trace($Label)
return $this-&fb($Label, FirePHP::TRACE);
* Log a table in the firebug console
* @see FirePHP::TABLE
* @param string $Label
* @param string $Table
* @return true
* @throws Exception
public function table($Label, $Table, $Options = array())
return $this-&fb($Table, $Label, FirePHP::TABLE, $Options);
* Insight API wrapper
* @see Insight_Helper::to()
public static function to()
$instance = self::getInstance();
if (!method_exists($instance, &_to&)) {
throw new Exception(&FirePHP::to() implementation not loaded&);
$args = func_get_args();
return call_user_func_array(array($instance, '_to'), $args);
* Insight API wrapper
* @see Insight_Helper::plugin()
public static function plugin()
$instance = self::getInstance();
if (!method_exists($instance, &_plugin&)) {
throw new Exception(&FirePHP::plugin() implementation not loaded&);
$args = func_get_args();
return call_user_func_array(array($instance, '_plugin'), $args);
* Check if FirePHP is installed on client
* @return boolean
public function detectClientExtension()
// Check if FirePHP is installed on client via User-Agent header
if (@preg_match_all('/\sFirePHP\/([\.\d]*)\s?/si',$this-&getUserAgent(),$m) &&
version_compare($m[1][0],'0.0.6','&=')) {
// Check if FirePHP is installed on client via X-FirePHP-Version header
if (@preg_match_all('/^([\.\d]*)$/si',$this-&getRequestHeader(&X-FirePHP-Version&),$m) &&
version_compare($m[1][0],'0.0.6','&=')) {
* Log varible to Firebug
* @see http://www.firephp.org/Wiki/Reference/Fb
* @param mixed $Object The variable to be logged
* @return true Return TRUE if message was added to headers, FALSE otherwise
* @throws Exception
public function fb($Object)
if($this instanceof FirePHP_Insight && method_exists($this, '_logUpgradeClientMessage')) {
if(!FirePHP_Insight::$upgradeClientMessageLogged) {
// avoid infinite recursion as _logUpgradeClientMessage() logs a message
$this-&_logUpgradeClientMessage();
static $insightGroupStack = array();
if (!$this-&getEnabled()) {
if ($this-&headersSent($filename, $linenum)) {
// If we are logging from within the exception handler we cannot throw another exception
if ($this-&inExceptionHandler) {
// Simply echo the error out to the page
echo '&div style=&border: 2 font-family: A font-size: 12 background-color: padding: 5&&&span style=&color: font-weight:&&FirePHP ERROR:&/span& Headers already sent in &b&'.$filename.'&/b& on line &b&'.$linenum.'&/b&. Cannot send log data to FirePHP. You must have Output Buffering enabled via ob_start() or output_buffering ini directive.&/div&';
throw $this-&newException('Headers already sent in '.$filename.' on line '.$linenum.'. Cannot send log data to FirePHP. You must have Output Buffering enabled via ob_start() or output_buffering ini directive.');
$Options = array();
if (func_num_args()==1) {
if (func_num_args()==2) {
switch(func_get_arg(1)) {
case self::LOG:
case self::INFO:
case self::WARN:
case self::ERROR:
case self::DUMP:
case self::TRACE:
case self::EXCEPTION:
case self::TABLE:
case self::GROUP_START:
case self::GROUP_END:
$Type = func_get_arg(1);
$Label = func_get_arg(1);
if (func_num_args()==3) {
$Type = func_get_arg(2);
$Label = func_get_arg(1);
if (func_num_args()==4) {
$Type = func_get_arg(2);
$Label = func_get_arg(1);
$Options = func_get_arg(3);
throw $this-&newException('Wrong number of arguments to fb() function!');
if($this-&logToInsightConsole!==null && (get_class($this)=='FirePHP_Insight' || is_subclass_of($this, 'FirePHP_Insight'))) {
$msg = $this-&logToInsightC
if ($Object instanceof Exception) {
$Type = self::EXCEPTION;
if($Label && $Type!=self::TABLE && $Type!=self::GROUP_START) {
$msg = $msg-&label($Label);
switch($Type) {
case self::DUMP:
case self::LOG:
return $msg-&log($Object);
case self::INFO:
return $msg-&info($Object);
case self::WARN:
return $msg-&warn($Object);
case self::ERROR:
return $msg-&error($Object);
case self::TRACE:
return $msg-&trace($Object);
case self::EXCEPTION:
return $this-&plugin('engine')-&handleException($Object, $msg);
case self::TABLE:
if (isset($Object[0]) && !is_string($Object[0]) && $Label) {
$Object = array($Label, $Object);
return $msg-&table($Object[0], array_slice($Object[1],1), $Object[1][0]);
case self::GROUP_START:
$insightGroupStack[] = $msg-&group(md5($Label))-&open();
return $msg-&log($Label);
case self::GROUP_END:
if(count($insightGroupStack)==0) {
throw new Error('Too many groupEnd() as opposed to group() calls!');
$group = array_pop($insightGroupStack);
return $group-&close();
return $msg-&log($Object);
if (!$this-&detectClientExtension()) {
$meta = array();
$skipFinalObjectEncode =
if ($Object instanceof Exception) {
$meta['file'] = $this-&_escapeTraceFile($Object-&getFile());
$meta['line'] = $Object-&getLine();
$trace = $Object-&getTrace();
if ($Object instanceof ErrorException
&& isset($trace[0]['function'])
&& $trace[0]['function']=='errorHandler'
&& isset($trace[0]['class'])
&& $trace[0]['class']=='FirePHP') {
$severity =
switch($Object-&getSeverity()) {
case E_WARNING: $severity = 'E_WARNING';
case E_NOTICE: $severity = 'E_NOTICE';
case E_USER_ERROR: $severity = 'E_USER_ERROR';
case E_USER_WARNING: $severity = 'E_USER_WARNING';
case E_USER_NOTICE: $severity = 'E_USER_NOTICE';
case E_STRICT: $severity = 'E_STRICT';
case E_RECOVERABLE_ERROR: $severity = 'E_RECOVERABLE_ERROR';
case E_DEPRECATED: $severity = 'E_DEPRECATED';
case E_USER_DEPRECATED: $severity = 'E_USER_DEPRECATED';
$Object = array('Class'=&get_class($Object),
'Message'=&$severity.': '.$Object-&getMessage(),
'File'=&$this-&_escapeTraceFile($Object-&getFile()),
'Line'=&$Object-&getLine(),
'Type'=&'trigger',
'Trace'=&$this-&_escapeTrace(array_splice($trace,2)));
$skipFinalObjectEncode =
$Object = array('Class'=&get_class($Object),
'Message'=&$Object-&getMessage(),
'File'=&$this-&_escapeTraceFile($Object-&getFile()),
'Line'=&$Object-&getLine(),
'Type'=&'throw',
'Trace'=&$this-&_escapeTrace($trace));
$skipFinalObjectEncode =
$Type = self::EXCEPTION;
if ($Type==self::TRACE) {
$trace = debug_backtrace();
if (!$trace)
for( $i=0 ; $i&sizeof($trace) ; $i++ ) {
if (isset($trace[$i]['class'])
&& isset($trace[$i]['file'])
&& ($trace[$i]['class']=='FirePHP'
|| $trace[$i]['class']=='FB')
&& (substr($this-&_standardizePath($trace[$i]['file']),-18,18)=='FirePHPCore/fb.php'
|| substr($this-&_standardizePath($trace[$i]['file']),-29,29)=='FirePHPCore/FirePHP.class.php')) {
/* Skip - FB::trace(), FB::send(), $firephp-&trace(), $firephp-&fb() */
if (isset($trace[$i]['class'])
&& isset($trace[$i+1]['file'])
&& $trace[$i]['class']=='FirePHP'
&& substr($this-&_standardizePath($trace[$i+1]['file']),-18,18)=='FirePHPCore/fb.php') {
/* Skip fb() */
if ($trace[$i]['function']=='fb'
|| $trace[$i]['function']=='trace'
|| $trace[$i]['function']=='send') {
$Object = array('Class'=&isset($trace[$i]['class'])?$trace[$i]['class']:'',
'Type'=&isset($trace[$i]['type'])?$trace[$i]['type']:'',
'Function'=&isset($trace[$i]['function'])?$trace[$i]['function']:'',
'Message'=&$trace[$i]['args'][0],
'File'=&isset($trace[$i]['file'])?$this-&_escapeTraceFile($trace[$i]['file']):'',
'Line'=&isset($trace[$i]['line'])?$trace[$i]['line']:'',
'Args'=&isset($trace[$i]['args'])?$this-&encodeObject($trace[$i]['args']):'',
'Trace'=&$this-&_escapeTrace(array_splice($trace,$i+1)));
$skipFinalObjectEncode =
$meta['file'] = isset($trace[$i]['file'])?$this-&_escapeTraceFile($trace[$i]['file']):'';
$meta['line'] = isset($trace[$i]['line'])?$trace[$i]['line']:'';
if ($Type==self::TABLE) {
if (isset($Object[0]) && is_string($Object[0])) {
$Object[1] = $this-&encodeTable($Object[1]);
$Object = $this-&encodeTable($Object);
$skipFinalObjectEncode =
if ($Type==self::GROUP_START) {
if (!$Label) {
throw $this-&newException('You must specify a label for the group!');
if ($Type===null) {
$Type = self::LOG;
if ($this-&options['includeLineNumbers']) {
if (!isset($meta['file']) || !isset($meta['line'])) {
$trace = debug_backtrace();
for( $i=0 ; $trace && $i&sizeof($trace) ; $i++ ) {
if (isset($trace[$i]['class'])
&& isset($trace[$i]['file'])
&& ($trace[$i]['class']=='FirePHP'
|| $trace[$i]['class']=='FB')
&& (substr($this-&_standardizePath($trace[$i]['file']),-18,18)=='FirePHPCore/fb.php'
|| substr($this-&_standardizePath($trace[$i]['file']),-29,29)=='FirePHPCore/FirePHP.class.php')) {
/* Skip - FB::trace(), FB::send(), $firephp-&trace(), $firephp-&fb() */
if (isset($trace[$i]['class'])
&& isset($trace[$i+1]['file'])
&& $trace[$i]['class']=='FirePHP'
&& substr($this-&_standardizePath($trace[$i+1]['file']),-18,18)=='FirePHPCore/fb.php') {
/* Skip fb() */
if (isset($trace[$i]['file'])
&& substr($this-&_standardizePath($trace[$i]['file']),-18,18)=='FirePHPCore/fb.php') {
/* Skip FB::fb() */
$meta['file'] = isset($trace[$i]['file'])?$this-&_escapeTraceFile($trace[$i]['file']):'';
$meta['line'] = isset($trace[$i]['line'])?$trace[$i]['line']:'';
unset($meta['file']);
unset($meta['line']);
$this-&setHeader('X-Wf-Protocol-1','http://meta.wildfirehq.org/Protocol/JsonStream/0.2');
$this-&setHeader('X-Wf-1-Plugin-1','http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/'.self::VERSION);
$structure_index = 1;
if ($Type==self::DUMP) {
$structure_index = 2;
$this-&setHeader('X-Wf-1-Structure-2','http://meta.firephp.org/Wildfire/Structure/FirePHP/Dump/0.1');
$this-&setHeader('X-Wf-1-Structure-1','http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1');
if ($Type==self::DUMP) {
$msg = '{&'.$Label.'&:'.$this-&jsonEncode($Object, $skipFinalObjectEncode).'}';
$msg_meta = $O
$msg_meta['Type'] = $T
if ($Label!==null) {
$msg_meta['Label'] = $L
if (isset($meta['file']) && !isset($msg_meta['File'])) {
$msg_meta['File'] = $meta['file'];
if (isset($meta['line']) && !isset($msg_meta['Line'])) {
$msg_meta['Line'] = $meta['line'];
$msg = '['.$this-&jsonEncode($msg_meta).','.$this-&jsonEncode($Object, $skipFinalObjectEncode).']';
$parts = explode(&\n&,chunk_split($msg, 5000, &\n&));
for( $i=0 ; $i&count($parts) ; $i++) {
$part = $parts[$i];
if ($part) {
if (count($parts)&2) {
// Message needs to be split into multiple parts
$this-&setHeader('X-Wf-1-'.$structure_index.'-'.'1-'.$this-&messageIndex,
(($i==0)?strlen($msg):'')
. '|' . $part . '|'
. (($i&count($parts)-2)?'\\':''));
$this-&setHeader('X-Wf-1-'.$structure_index.'-'.'1-'.$this-&messageIndex,
strlen($part) . '|' . $part . '|');
$this-&messageIndex++;
if ($this-&messageIndex & 99999) {
throw $this-&newException('Maximum number (99,999) of messages reached!');
$this-&setHeader('X-Wf-1-Index',$this-&messageIndex-1);
* Standardizes path for windows systems.
* @param string $Path
* @return string
protected function _standardizePath($Path)
return preg_replace('/\\\\+/','/',$Path);
* Escape trace path for windows systems
* @param array $Trace
* @return array
protected function _escapeTrace($Trace)
if (!$Trace) return $T
for( $i=0 ; $i&sizeof($Trace) ; $i++ ) {
if (isset($Trace[$i]['file'])) {
$Trace[$i]['file'] = $this-&_escapeTraceFile($Trace[$i]['file']);
if (isset($Trace[$i]['args'])) {
$Trace[$i]['args'] = $this-&encodeObject($Tra}

我要回帖

更多关于 怪物猎人x攻击力up 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信