| 12345 |
anikendra |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
|
|
4 |
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
5 |
*
|
|
|
6 |
* Licensed under The MIT License
|
|
|
7 |
* Redistributions of files must retain the above copyright notice.
|
|
|
8 |
*
|
|
|
9 |
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
10 |
* @link http://cakephp.org CakePHP(tm) Project
|
|
|
11 |
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
App::uses('DebugPanel', 'DebugKit.Lib');
|
|
|
15 |
|
|
|
16 |
/**
|
|
|
17 |
* Provides debug information on previous requests.
|
|
|
18 |
*
|
|
|
19 |
*/
|
|
|
20 |
class HistoryPanel extends DebugPanel {
|
|
|
21 |
|
|
|
22 |
/**
|
|
|
23 |
* Number of history elements to keep
|
|
|
24 |
*
|
|
|
25 |
* @var string
|
|
|
26 |
*/
|
|
|
27 |
public $history = 5;
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* Constructor
|
|
|
31 |
*
|
|
|
32 |
* @param array $settings Array of settings.
|
|
|
33 |
* @return \HistoryPanel
|
|
|
34 |
*/
|
|
|
35 |
public function __construct($settings) {
|
|
|
36 |
if (isset($settings['history'])) {
|
|
|
37 |
$this->history = $settings['history'];
|
|
|
38 |
}
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
/**
|
|
|
42 |
* beforeRender callback function
|
|
|
43 |
*
|
|
|
44 |
* @param Controller $controller
|
|
|
45 |
* @return array contents for panel
|
|
|
46 |
*/
|
|
|
47 |
public function beforeRender(Controller $controller) {
|
|
|
48 |
$cacheKey = $controller->Toolbar->cacheKey;
|
|
|
49 |
$toolbarHistory = Cache::read($cacheKey, 'debug_kit');
|
|
|
50 |
$historyStates = array();
|
|
|
51 |
if (is_array($toolbarHistory) && !empty($toolbarHistory)) {
|
|
|
52 |
$prefix = array();
|
|
|
53 |
if (!empty($controller->request->params['prefix'])) {
|
|
|
54 |
$prefix[$controller->request->params['prefix']] = false;
|
|
|
55 |
}
|
|
|
56 |
foreach ($toolbarHistory as $i => $state) {
|
|
|
57 |
if (!isset($state['request']['content']['url'])) {
|
|
|
58 |
continue;
|
|
|
59 |
}
|
|
|
60 |
$title = $state['request']['content']['url'];
|
|
|
61 |
$query = @$state['request']['content']['query'];
|
|
|
62 |
if (isset($query['url'])) {
|
|
|
63 |
unset($query['url']);
|
|
|
64 |
}
|
|
|
65 |
if (!empty($query)) {
|
|
|
66 |
$title .= '?' . urldecode(http_build_query($query));
|
|
|
67 |
}
|
|
|
68 |
$historyStates[] = array(
|
|
|
69 |
'title' => $title,
|
|
|
70 |
'url' => array_merge($prefix, array(
|
|
|
71 |
'plugin' => 'debug_kit',
|
|
|
72 |
'controller' => 'toolbar_access',
|
|
|
73 |
'action' => 'history_state',
|
|
|
74 |
$i + 1))
|
|
|
75 |
);
|
|
|
76 |
}
|
|
|
77 |
}
|
|
|
78 |
if (count($historyStates) >= $this->history) {
|
|
|
79 |
array_pop($historyStates);
|
|
|
80 |
}
|
|
|
81 |
return $historyStates;
|
|
|
82 |
}
|
|
|
83 |
}
|