[eluser]kunitsuji From Japan[/eluser]
I'm sorry. I am not good at English.
This code does Profiler in popup.
MY_Log.php
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* @category
* @package MYNETS_LOg Class
* @author KUNIHARU Tsujioka <[email protected]>
*/
class MYNETS_Log extends CI_Log
{
private $_logmessage = array();
function __construct()
{
parent::__construct();
}
/**
* Write Log File
*
* Generally this function will be called using the global log_message() function
*
* @access public
* @param string the error level
* @param string the error message
* @param bool whether the error is a native PHP error
* @return bool
*/
//2008-09-05 KUNIHARU Tsujioka UPDATE
function write_log($level = 'error', $msg, $php_error = FALSE)
{
if ($this->_enabled === FALSE)
{
return FALSE;
}
$level = strtoupper($level);
if ( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold))
{
return FALSE;
}
$filepath = $this->log_path.'log-'.date('Y-m-d').EXT;
$message = '';
if ( ! file_exists($filepath))
{
$message .= "<"."?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n";
}
if ( ! $fp = @fopen($filepath, FOPEN_WRITE_CREATE))
{
return FALSE;
}
$message .= $level.' '.(($level == 'INFO') ? ' -' : '-').' '.date($this->_date_fmt). ' --> '.$msg."\n";
flock($fp, LOCK_EX);
fwrite($fp, $message);
flock($fp, LOCK_UN);
fclose($fp);
$this->_logmessage[] = $message; //add logmessage array
@chmod($filepath, FILE_WRITE_MODE);
return TRUE;
}
public function getLog()
{
return $this->_logmessage;
}
}
Code:
MY_Profiler.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* @package MYNETS_Profiler Class
* @author KUNIHARU Tsujioka <[email protected]>
*/
class MYNETS_Profiler extends CI_Profiler {
function __construct()
{
parent::__construct();
}
/**
* Run the Profiler
*
* @access private
* @return string
*/
function _runStr()
{
$output = '';
$CI =& get_instance();
$output = '<br clear="all" />';
$output .= "<div style='background-color:#fff;padding:10px;'>";
$output .= $this->_compile_memory_usage();
$output .= $this->_compile_benchmarks();
$output .= $this->_compile_uri_string();
$output .= $this->_compile_get();
$output .= $this->_compile_post();
$output .= $this->_compile_queries();
$output .= '</div>';
$output = $CI->db->escape($output);
return $output;
}
function _getLog()
{
$log = '';
$LOG =& load_class('Log');
$log = $LOG->getLog();
if (! $log)
{
return '';
}
$CI =& get_instance();
$logstr = '';
foreach($log as $val)
{
$logstr .= "" . $val . "<br />";
}
return $CI->db->escape($logstr);
}
/**
* Run the Profiler
*
* @access private
* @return string
*/
function run()
{
$win = <<< EOT
[removed]
var win = window.open('', 'profiler', 'toolbar=no,scrollbars,width=750,height=500');
win.[removed]ln('<html>');
win.[removed]ln('<head>');
win.[removed]ln('<title>Profiler Window</title>');
win.[removed]ln('<style type="text/css">');
win.[removed]ln('body { font-family: monospace; font-size: 8pt; width:90%}');
win.[removed]ln('td,th { font-size: 10pt; }');
win.[removed]ln('td,th { border-bottom: #999999 solid 1px; }');
win.[removed]ln('td,th { border-right: #999999 solid 1px; }');
win.[removed]ln('tr { text-align: left; vertical-align: top; }');
win.[removed]ln('</style>');
win.[removed]ln('</head>');
win.[removed]ln('<body>');
win.[removed]ln({$this->_runStr()});
win.[removed]ln('<div>');
win.[removed]ln({$this->_getLog()});
win.[removed]ln('</div>');
win.[removed]ln('<a >close</a>');
win.[removed]ln('</body></html>');
[removed]
EOT;
return $win;
}
}
It is a little clumsy.
>$CI->db->escape($logstr);
>$CI->db->escape($output);
please teach me