Base for a static organization website

HistoryPanel.php 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. App::uses('DebugPanel', 'DebugKit.Lib');
  14. /**
  15. * Provides debug information on previous requests.
  16. *
  17. */
  18. class HistoryPanel extends DebugPanel {
  19. /**
  20. * Number of history elements to keep
  21. *
  22. * @var string
  23. */
  24. public $history = 5;
  25. /**
  26. * Constructor
  27. *
  28. * @param array $settings Array of settings.
  29. * @return \HistoryPanel
  30. */
  31. public function __construct($settings) {
  32. if (isset($settings['history'])) {
  33. $this->history = $settings['history'];
  34. }
  35. }
  36. /**
  37. * beforeRender callback function
  38. *
  39. * @param Controller $controller
  40. * @return array contents for panel
  41. */
  42. public function beforeRender(Controller $controller) {
  43. $cacheKey = $controller->Toolbar->cacheKey;
  44. $toolbarHistory = Cache::read($cacheKey, 'debug_kit');
  45. $historyStates = array();
  46. if (is_array($toolbarHistory) && !empty($toolbarHistory)) {
  47. $prefix = array();
  48. if (!empty($controller->request->params['prefix'])) {
  49. $prefix[$controller->request->params['prefix']] = false;
  50. }
  51. foreach ($toolbarHistory as $i => $state) {
  52. if (!isset($state['request']['content']['url'])) {
  53. continue;
  54. }
  55. $title = $state['request']['content']['url'];
  56. $query = @$state['request']['content']['query'];
  57. if (isset($query['url'])) {
  58. unset($query['url']);
  59. }
  60. if (!empty($query)) {
  61. $title .= '?' . urldecode(http_build_query($query));
  62. }
  63. $historyStates[] = array(
  64. 'title' => $title,
  65. 'url' => array_merge($prefix, array(
  66. 'plugin' => 'debug_kit',
  67. 'controller' => 'toolbar_access',
  68. 'action' => 'history_state',
  69. $i + 1))
  70. );
  71. }
  72. }
  73. if (count($historyStates) >= $this->history) {
  74. array_pop($historyStates);
  75. }
  76. return $historyStates;
  77. }
  78. }