Subversion-Projekte lars-tiefland.ci

Revision

Revision 2257 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
68 lars 1
<?php
2
/**
3
 * CodeIgniter
4
 *
5
 * An open source application development framework for PHP
6
 *
7
 * This content is released under the MIT License (MIT)
8
 *
2414 lars 9
 * Copyright (c) 2014 - 2019, British Columbia Institute of Technology
68 lars 10
 *
11
 * Permission is hereby granted, free of charge, to any person obtaining a copy
12
 * of this software and associated documentation files (the "Software"), to deal
13
 * in the Software without restriction, including without limitation the rights
14
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
 * copies of the Software, and to permit persons to whom the Software is
16
 * furnished to do so, subject to the following conditions:
17
 *
18
 * The above copyright notice and this permission notice shall be included in
19
 * all copies or substantial portions of the Software.
20
 *
21
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27
 * THE SOFTWARE.
28
 *
29
 * @package	CodeIgniter
30
 * @author	EllisLab Dev Team
31
 * @copyright	Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
2414 lars 32
 * @copyright	Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/)
33
 * @license	https://opensource.org/licenses/MIT	MIT License
68 lars 34
 * @link	https://codeigniter.com
35
 * @since	Version 1.0.0
36
 * @filesource
37
 */
38
defined('BASEPATH') OR exit('No direct script access allowed');
39
 
40
/**
41
 * CodeIgniter Profiler Class
42
 *
43
 * This class enables you to display benchmark, query, and other data
44
 * in order to help with debugging and optimization.
45
 *
46
 * Note: At some point it would be good to move all the HTML in this class
47
 * into a set of template files in order to allow customization.
48
 *
49
 * @package		CodeIgniter
50
 * @subpackage	Libraries
51
 * @category	Libraries
52
 * @author		EllisLab Dev Team
53
 * @link		https://codeigniter.com/user_guide/general/profiling.html
54
 */
55
class CI_Profiler {
56
 
57
	/**
58
	 * List of profiler sections available to show
59
	 *
60
	 * @var array
61
	 */
62
	protected $_available_sections = array(
63
		'benchmarks',
64
		'get',
65
		'memory_usage',
66
		'post',
67
		'uri_string',
68
		'controller_info',
69
		'queries',
70
		'http_headers',
71
		'session_data',
72
		'config'
73
	);
74
 
75
	/**
76
	 * Number of queries to show before making the additional queries togglable
77
	 *
78
	 * @var int
79
	 */
80
	protected $_query_toggle_count = 25;
81
 
82
	/**
83
	 * Reference to the CodeIgniter singleton
84
	 *
85
	 * @var object
86
	 */
87
	protected $CI;
88
 
89
	// --------------------------------------------------------------------
90
 
91
	/**
92
	 * Class constructor
93
	 *
94
	 * Initialize Profiler
95
	 *
96
	 * @param	array	$config	Parameters
97
	 */
98
	public function __construct($config = array())
99
	{
100
		$this->CI =& get_instance();
101
		$this->CI->load->language('profiler');
102
 
103
		// default all sections to display
104
		foreach ($this->_available_sections as $section)
105
		{
106
			if ( ! isset($config[$section]))
107
			{
108
				$this->_compile_{$section} = TRUE;
109
			}
110
		}
111
 
112
		$this->set_sections($config);
113
		log_message('info', 'Profiler Class Initialized');
114
	}
115
 
116
	// --------------------------------------------------------------------
117
 
118
	/**
119
	 * Set Sections
120
	 *
121
	 * Sets the private _compile_* properties to enable/disable Profiler sections
122
	 *
123
	 * @param	mixed	$config
124
	 * @return	void
125
	 */
126
	public function set_sections($config)
127
	{
128
		if (isset($config['query_toggle_count']))
129
		{
130
			$this->_query_toggle_count = (int) $config['query_toggle_count'];
131
			unset($config['query_toggle_count']);
132
		}
133
 
134
		foreach ($config as $method => $enable)
135
		{
136
			if (in_array($method, $this->_available_sections))
137
			{
138
				$this->_compile_{$method} = ($enable !== FALSE);
139
			}
140
		}
141
	}
142
 
143
	// --------------------------------------------------------------------
144
 
145
	/**
146
	 * Auto Profiler
147
	 *
148
	 * This function cycles through the entire array of mark points and
149
	 * matches any two points that are named identically (ending in "_start"
150
	 * and "_end" respectively).  It then compiles the execution times for
151
	 * all points and returns it as an array
152
	 *
153
	 * @return	array
154
	 */
155
	protected function _compile_benchmarks()
156
	{
157
		$profile = array();
158
		foreach ($this->CI->benchmark->marker as $key => $val)
159
		{
160
			// We match the "end" marker so that the list ends
161
			// up in the order that it was defined
162
			if (preg_match('/(.+?)_end$/i', $key, $match)
163
				&& isset($this->CI->benchmark->marker[$match[1].'_end'], $this->CI->benchmark->marker[$match[1].'_start']))
164
			{
165
				$profile[$match[1]] = $this->CI->benchmark->elapsed_time($match[1].'_start', $key);
166
			}
167
		}
168
 
169
		// Build a table containing the profile data.
170
		// Note: At some point we should turn this into a template that can
171
		// be modified. We also might want to make this data available to be logged
172
 
173
		$output = "\n\n"
174
			.'<fieldset id="ci_profiler_benchmarks" style="border:1px solid #900;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">'
175
			."\n"
176
			.'<legend style="color:#900;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_benchmarks')."&nbsp;&nbsp;</legend>"
177
			."\n\n\n<table style=\"width:100%;\">\n";
178
 
179
		foreach ($profile as $key => $val)
180
		{
181
			$key = ucwords(str_replace(array('_', '-'), ' ', $key));
182
			$output .= '<tr><td style="padding:5px;width:50%;color:#000;font-weight:bold;background-color:#ddd;">'
183
					.$key.'&nbsp;&nbsp;</td><td style="padding:5px;width:50%;color:#900;font-weight:normal;background-color:#ddd;">'
184
					.$val."</td></tr>\n";
185
		}
186
 
187
		return $output."</table>\n</fieldset>";
188
	}
189
 
190
	// --------------------------------------------------------------------
191
 
192
	/**
193
	 * Compile Queries
194
	 *
195
	 * @return	string
196
	 */
197
	protected function _compile_queries()
198
	{
199
		$dbs = array();
200
 
201
		// Let's determine which databases are currently connected to
202
		foreach (get_object_vars($this->CI) as $name => $cobject)
203
		{
204
			if (is_object($cobject))
205
			{
206
				if ($cobject instanceof CI_DB)
207
				{
208
					$dbs[get_class($this->CI).':$'.$name] = $cobject;
209
				}
210
				elseif ($cobject instanceof CI_Model)
211
				{
212
					foreach (get_object_vars($cobject) as $mname => $mobject)
213
					{
214
						if ($mobject instanceof CI_DB)
215
						{
216
							$dbs[get_class($cobject).':$'.$mname] = $mobject;
217
						}
218
					}
219
				}
220
			}
221
		}
222
 
223
		if (count($dbs) === 0)
224
		{
225
			return "\n\n"
226
				.'<fieldset id="ci_profiler_queries" style="border:1px solid #0000FF;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">'
227
				."\n"
228
				.'<legend style="color:#0000FF;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_queries').'&nbsp;&nbsp;</legend>'
229
				."\n\n\n<table style=\"border:none; width:100%;\">\n"
230
				.'<tr><td style="width:100%;color:#0000FF;font-weight:normal;background-color:#eee;padding:5px;">'
231
				.$this->CI->lang->line('profiler_no_db')
232
				."</td></tr>\n</table>\n</fieldset>";
233
		}
234
 
235
		// Load the text helper so we can highlight the SQL
236
		$this->CI->load->helper('text');
237
 
238
		// Key words we want bolded
239
		$highlight = array('SELECT', 'DISTINCT', 'FROM', 'WHERE', 'AND', 'LEFT&nbsp;JOIN', 'ORDER&nbsp;BY', 'GROUP&nbsp;BY', 'LIMIT', 'INSERT', 'INTO', 'VALUES', 'UPDATE', 'OR&nbsp;', 'HAVING', 'OFFSET', 'NOT&nbsp;IN', 'IN', 'LIKE', 'NOT&nbsp;LIKE', 'COUNT', 'MAX', 'MIN', 'ON', 'AS', 'AVG', 'SUM', '(', ')');
240
 
241
		$output  = "\n\n";
242
		$count = 0;
243
 
244
		foreach ($dbs as $name => $db)
245
		{
246
			$hide_queries = (count($db->queries) > $this->_query_toggle_count) ? ' display:none' : '';
247
			$total_time = number_format(array_sum($db->query_times), 4).' '.$this->CI->lang->line('profiler_seconds');
248
 
249
			$show_hide_js = '(<span style="cursor: pointer;" onclick="var s=document.getElementById(\'ci_profiler_queries_db_'.$count.'\').style;s.display=s.display==\'none\'?\'\':\'none\';this.innerHTML=this.innerHTML==\''.$this->CI->lang->line('profiler_section_hide').'\'?\''.$this->CI->lang->line('profiler_section_show').'\':\''.$this->CI->lang->line('profiler_section_hide').'\';">'.$this->CI->lang->line('profiler_section_hide').'</span>)';
250
 
251
			if ($hide_queries !== '')
252
			{
253
				$show_hide_js = '(<span style="cursor: pointer;" onclick="var s=document.getElementById(\'ci_profiler_queries_db_'.$count.'\').style;s.display=s.display==\'none\'?\'\':\'none\';this.innerHTML=this.innerHTML==\''.$this->CI->lang->line('profiler_section_show').'\'?\''.$this->CI->lang->line('profiler_section_hide').'\':\''.$this->CI->lang->line('profiler_section_show').'\';">'.$this->CI->lang->line('profiler_section_show').'</span>)';
254
			}
255
 
256
			$output .= '<fieldset style="border:1px solid #0000FF;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">'
257
				."\n"
258
				.'<legend style="color:#0000FF;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_database')
259
				.':&nbsp; '.$db->database.' ('.$name.')&nbsp;&nbsp;&nbsp;'.$this->CI->lang->line('profiler_queries')
260
				.': '.count($db->queries).' ('.$total_time.')&nbsp;&nbsp;'.$show_hide_js."</legend>\n\n\n"
261
				.'<table style="width:100%;'.$hide_queries.'" id="ci_profiler_queries_db_'.$count."\">\n";
262
 
263
			if (count($db->queries) === 0)
264
			{
265
				$output .= '<tr><td style="width:100%;color:#0000FF;font-weight:normal;background-color:#eee;padding:5px;">'
266
						.$this->CI->lang->line('profiler_no_queries')."</td></tr>\n";
267
			}
268
			else
269
			{
270
				foreach ($db->queries as $key => $val)
271
				{
272
					$time = number_format($db->query_times[$key], 4);
273
					$val = highlight_code($val);
274
 
275
					foreach ($highlight as $bold)
276
					{
277
						$val = str_replace($bold, '<strong>'.$bold.'</strong>', $val);
278
					}
279
 
280
					$output .= '<tr><td style="padding:5px;vertical-align:top;width:1%;color:#900;font-weight:normal;background-color:#ddd;">'
281
							.$time.'&nbsp;&nbsp;</td><td style="padding:5px;color:#000;font-weight:normal;background-color:#ddd;">'
282
							.$val."</td></tr>\n";
283
				}
284
			}
285
 
286
			$output .= "</table>\n</fieldset>";
287
			$count++;
288
		}
289
 
290
		return $output;
291
	}
292
 
293
	// --------------------------------------------------------------------
294
 
295
	/**
296
	 * Compile $_GET Data
297
	 *
298
	 * @return	string
299
	 */
300
	protected function _compile_get()
301
	{
302
		$output = "\n\n"
303
			.'<fieldset id="ci_profiler_get" style="border:1px solid #cd6e00;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">'
304
			."\n"
305
			.'<legend style="color:#cd6e00;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_get_data')."&nbsp;&nbsp;</legend>\n";
306
 
307
		if (count($_GET) === 0)
308
		{
309
			$output .= '<div style="color:#cd6e00;font-weight:normal;padding:4px 0 4px 0;">'.$this->CI->lang->line('profiler_no_get').'</div>';
310
		}
311
		else
312
		{
313
			$output .= "\n\n<table style=\"width:100%;border:none;\">\n";
314
 
315
			foreach ($_GET as $key => $val)
316
			{
317
				is_int($key) OR $key = "'".htmlspecialchars($key, ENT_QUOTES, config_item('charset'))."'";
318
				$val = (is_array($val) OR is_object($val))
2107 lars 319
					? '<pre>'.htmlspecialchars(print_r($val, TRUE), ENT_QUOTES, config_item('charset')).'</pre>'
68 lars 320
					: htmlspecialchars($val, ENT_QUOTES, config_item('charset'));
321
 
322
				$output .= '<tr><td style="width:50%;color:#000;background-color:#ddd;padding:5px;">&#36;_GET['
323
					.$key.']&nbsp;&nbsp; </td><td style="width:50%;padding:5px;color:#cd6e00;font-weight:normal;background-color:#ddd;">'
324
					.$val."</td></tr>\n";
325
			}
326
 
327
			$output .= "</table>\n";
328
		}
329
 
330
		return $output.'</fieldset>';
331
	}
332
 
333
	// --------------------------------------------------------------------
334
 
335
	/**
336
	 * Compile $_POST Data
337
	 *
338
	 * @return	string
339
	 */
340
	protected function _compile_post()
341
	{
342
		$output = "\n\n"
343
			.'<fieldset id="ci_profiler_post" style="border:1px solid #009900;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">'
344
			."\n"
345
			.'<legend style="color:#009900;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_post_data')."&nbsp;&nbsp;</legend>\n";
346
 
347
		if (count($_POST) === 0 && count($_FILES) === 0)
348
		{
349
			$output .= '<div style="color:#009900;font-weight:normal;padding:4px 0 4px 0;">'.$this->CI->lang->line('profiler_no_post').'</div>';
350
		}
351
		else
352
		{
353
			$output .= "\n\n<table style=\"width:100%;\">\n";
354
 
355
			foreach ($_POST as $key => $val)
356
			{
357
				is_int($key) OR $key = "'".htmlspecialchars($key, ENT_QUOTES, config_item('charset'))."'";
358
				$val = (is_array($val) OR is_object($val))
2107 lars 359
					? '<pre>'.htmlspecialchars(print_r($val, TRUE), ENT_QUOTES, config_item('charset')).'</pre>'
68 lars 360
					: htmlspecialchars($val, ENT_QUOTES, config_item('charset'));
361
 
362
				$output .= '<tr><td style="width:50%;padding:5px;color:#000;background-color:#ddd;">&#36;_POST['
363
					.$key.']&nbsp;&nbsp; </td><td style="width:50%;padding:5px;color:#009900;font-weight:normal;background-color:#ddd;">'
364
					.$val."</td></tr>\n";
365
			}
366
 
367
			foreach ($_FILES as $key => $val)
368
			{
369
				is_int($key) OR $key = "'".htmlspecialchars($key, ENT_QUOTES, config_item('charset'))."'";
370
				$val = (is_array($val) OR is_object($val))
2107 lars 371
					? '<pre>'.htmlspecialchars(print_r($val, TRUE), ENT_QUOTES, config_item('charset')).'</pre>'
68 lars 372
					: htmlspecialchars($val, ENT_QUOTES, config_item('charset'));
373
 
374
				$output .= '<tr><td style="width:50%;padding:5px;color:#000;background-color:#ddd;">&#36;_FILES['
375
					.$key.']&nbsp;&nbsp; </td><td style="width:50%;padding:5px;color:#009900;font-weight:normal;background-color:#ddd;">'
376
					.$val."</td></tr>\n";
377
			}
378
 
379
			$output .= "</table>\n";
380
		}
381
 
382
		return $output.'</fieldset>';
383
	}
384
 
385
	// --------------------------------------------------------------------
386
 
387
	/**
388
	 * Show query string
389
	 *
390
	 * @return	string
391
	 */
392
	protected function _compile_uri_string()
393
	{
394
		return "\n\n"
395
			.'<fieldset id="ci_profiler_uri_string" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">'
396
			."\n"
397
			.'<legend style="color:#000;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_uri_string')."&nbsp;&nbsp;</legend>\n"
398
			.'<div style="color:#000;font-weight:normal;padding:4px 0 4px 0;">'
399
			.($this->CI->uri->uri_string === '' ? $this->CI->lang->line('profiler_no_uri') : $this->CI->uri->uri_string)
400
			.'</div></fieldset>';
401
	}
402
 
403
	// --------------------------------------------------------------------
404
 
405
	/**
406
	 * Show the controller and function that were called
407
	 *
408
	 * @return	string
409
	 */
410
	protected function _compile_controller_info()
411
	{
412
		return "\n\n"
413
			.'<fieldset id="ci_profiler_controller_info" style="border:1px solid #995300;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">'
414
			."\n"
415
			.'<legend style="color:#995300;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_controller_info')."&nbsp;&nbsp;</legend>\n"
416
			.'<div style="color:#995300;font-weight:normal;padding:4px 0 4px 0;">'.$this->CI->router->class.'/'.$this->CI->router->method
417
			.'</div></fieldset>';
418
	}
419
 
420
	// --------------------------------------------------------------------
421
 
422
	/**
423
	 * Compile memory usage
424
	 *
425
	 * Display total used memory
426
	 *
427
	 * @return	string
428
	 */
429
	protected function _compile_memory_usage()
430
	{
431
		return "\n\n"
432
			.'<fieldset id="ci_profiler_memory_usage" style="border:1px solid #5a0099;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">'
433
			."\n"
434
			.'<legend style="color:#5a0099;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_memory_usage')."&nbsp;&nbsp;</legend>\n"
435
			.'<div style="color:#5a0099;font-weight:normal;padding:4px 0 4px 0;">'
436
			.(($usage = memory_get_usage()) != '' ? number_format($usage).' bytes' : $this->CI->lang->line('profiler_no_memory'))
437
			.'</div></fieldset>';
438
	}
439
 
440
	// --------------------------------------------------------------------
441
 
442
	/**
443
	 * Compile header information
444
	 *
445
	 * Lists HTTP headers
446
	 *
447
	 * @return	string
448
	 */
449
	protected function _compile_http_headers()
450
	{
451
		$output = "\n\n"
452
			.'<fieldset id="ci_profiler_http_headers" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">'
453
			."\n"
454
			.'<legend style="color:#000;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_headers')
455
			.'&nbsp;&nbsp;(<span style="cursor: pointer;" onclick="var s=document.getElementById(\'ci_profiler_httpheaders_table\').style;s.display=s.display==\'none\'?\'\':\'none\';this.innerHTML=this.innerHTML==\''.$this->CI->lang->line('profiler_section_show').'\'?\''.$this->CI->lang->line('profiler_section_hide').'\':\''.$this->CI->lang->line('profiler_section_show').'\';">'.$this->CI->lang->line('profiler_section_show')."</span>)</legend>\n\n\n"
456
			.'<table style="width:100%;display:none;" id="ci_profiler_httpheaders_table">'."\n";
457
 
458
		foreach (array('HTTP_ACCEPT', 'HTTP_USER_AGENT', 'HTTP_CONNECTION', 'SERVER_PORT', 'SERVER_NAME', 'REMOTE_ADDR', 'SERVER_SOFTWARE', 'HTTP_ACCEPT_LANGUAGE', 'SCRIPT_NAME', 'REQUEST_METHOD',' HTTP_HOST', 'REMOTE_HOST', 'CONTENT_TYPE', 'SERVER_PROTOCOL', 'QUERY_STRING', 'HTTP_ACCEPT_ENCODING', 'HTTP_X_FORWARDED_FOR', 'HTTP_DNT') as $header)
459
		{
460
			$val = isset($_SERVER[$header]) ? htmlspecialchars($_SERVER[$header], ENT_QUOTES, config_item('charset')) : '';
461
			$output .= '<tr><td style="vertical-align:top;width:50%;padding:5px;color:#900;background-color:#ddd;">'
462
				.$header.'&nbsp;&nbsp;</td><td style="width:50%;padding:5px;color:#000;background-color:#ddd;">'.$val."</td></tr>\n";
463
		}
464
 
465
		return $output."</table>\n</fieldset>";
466
	}
467
 
468
	// --------------------------------------------------------------------
469
 
470
	/**
471
	 * Compile config information
472
	 *
473
	 * Lists developer config variables
474
	 *
475
	 * @return	string
476
	 */
477
	protected function _compile_config()
478
	{
479
		$output = "\n\n"
480
			.'<fieldset id="ci_profiler_config" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">'
481
			."\n"
482
			.'<legend style="color:#000;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_config').'&nbsp;&nbsp;(<span style="cursor: pointer;" onclick="var s=document.getElementById(\'ci_profiler_config_table\').style;s.display=s.display==\'none\'?\'\':\'none\';this.innerHTML=this.innerHTML==\''.$this->CI->lang->line('profiler_section_show').'\'?\''.$this->CI->lang->line('profiler_section_hide').'\':\''.$this->CI->lang->line('profiler_section_show').'\';">'.$this->CI->lang->line('profiler_section_show')."</span>)</legend>\n\n\n"
483
			.'<table style="width:100%;display:none;" id="ci_profiler_config_table">'."\n";
484
 
485
		foreach ($this->CI->config->config as $config => $val)
486
		{
2107 lars 487
			$pre       = '';
488
			$pre_close = '';
489
 
68 lars 490
			if (is_array($val) OR is_object($val))
491
			{
492
				$val = print_r($val, TRUE);
2107 lars 493
 
494
				$pre       = '<pre>' ;
495
 				$pre_close = '</pre>';
68 lars 496
			}
497
 
498
			$output .= '<tr><td style="padding:5px;vertical-align:top;color:#900;background-color:#ddd;">'
2107 lars 499
				.$config.'&nbsp;&nbsp;</td><td style="padding:5px;color:#000;background-color:#ddd;">'.$pre.htmlspecialchars($val, ENT_QUOTES, config_item('charset')).$pre_close."</td></tr>\n";
68 lars 500
		}
501
 
502
		return $output."</table>\n</fieldset>";
503
	}
504
 
505
	// --------------------------------------------------------------------
506
 
507
	/**
508
	 * Compile session userdata
509
	 *
510
	 * @return 	string
511
	 */
512
	protected function _compile_session_data()
513
	{
514
		if ( ! isset($this->CI->session))
515
		{
516
			return;
517
		}
518
 
519
		$output = '<fieldset id="ci_profiler_csession" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">'
520
			.'<legend style="color:#000;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_session_data').'&nbsp;&nbsp;(<span style="cursor: pointer;" onclick="var s=document.getElementById(\'ci_profiler_session_data\').style;s.display=s.display==\'none\'?\'\':\'none\';this.innerHTML=this.innerHTML==\''.$this->CI->lang->line('profiler_section_show').'\'?\''.$this->CI->lang->line('profiler_section_hide').'\':\''.$this->CI->lang->line('profiler_section_show').'\';">'.$this->CI->lang->line('profiler_section_show').'</span>)</legend>'
521
			.'<table style="width:100%;display:none;" id="ci_profiler_session_data">';
522
 
523
		foreach ($this->CI->session->userdata() as $key => $val)
524
		{
2107 lars 525
			$pre       = '';
526
			$pre_close = '';
527
 
68 lars 528
			if (is_array($val) OR is_object($val))
529
			{
530
				$val = print_r($val, TRUE);
2107 lars 531
 
532
				$pre       = '<pre>' ;
533
 				$pre_close = '</pre>';
68 lars 534
			}
535
 
536
			$output .= '<tr><td style="padding:5px;vertical-align:top;color:#900;background-color:#ddd;">'
2107 lars 537
				.$key.'&nbsp;&nbsp;</td><td style="padding:5px;color:#000;background-color:#ddd;">'.$pre.htmlspecialchars($val, ENT_QUOTES, config_item('charset')).$pre_close."</td></tr>\n";
68 lars 538
		}
539
 
540
		return $output."</table>\n</fieldset>";
541
	}
542
 
543
	// --------------------------------------------------------------------
544
 
545
	/**
546
	 * Run the Profiler
547
	 *
548
	 * @return	string
549
	 */
550
	public function run()
551
	{
552
		$output = '<div id="codeigniter_profiler" style="clear:both;background-color:#fff;padding:10px;">';
553
		$fields_displayed = 0;
554
 
555
		foreach ($this->_available_sections as $section)
556
		{
557
			if ($this->_compile_{$section} !== FALSE)
558
			{
559
				$func = '_compile_'.$section;
560
				$output .= $this->{$func}();
561
				$fields_displayed++;
562
			}
563
		}
564
 
565
		if ($fields_displayed === 0)
566
		{
567
			$output .= '<p style="border:1px solid #5a0099;padding:10px;margin:20px 0;background-color:#eee;">'
568
				.$this->CI->lang->line('profiler_no_profiles').'</p>';
569
		}
570
 
571
		return $output.'</div>';
572
	}
573
 
574
}