Debug.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. <?php
  2. /**
  3. * ZFDebug Zend Additions
  4. *
  5. * @category ZFDebug
  6. * @package ZFDebug_Controller
  7. * @subpackage Plugins
  8. * @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
  9. * @license http://code.google.com/p/zfdebug/wiki/License New BSD License
  10. * @version $Id$
  11. */
  12. /**
  13. * @see Zend_Controller_Exception
  14. */
  15. require_once 'Zend/Controller/Exception.php';
  16. /**
  17. * @see Zend_Version
  18. */
  19. require_once 'Zend/Version.php';
  20. /**
  21. * @see ZFDebug_Controller_Plugin_Debug_Plugin_Text
  22. */
  23. require_once 'ZFDebug/Controller/Plugin/Debug/Plugin/Text.php';
  24. /**
  25. * @category ZFDebug
  26. * @package ZFDebug_Controller
  27. * @subpackage Plugins
  28. * @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
  29. * @license http://code.google.com/p/zfdebug/wiki/License New BSD License
  30. */
  31. class ZFDebug_Controller_Plugin_Debug extends Zend_Controller_Plugin_Abstract
  32. {
  33. /**
  34. * Contains registered plugins
  35. *
  36. * @var array
  37. */
  38. protected $_plugins = array();
  39. /**
  40. * Contains options to change Debug Bar behavior
  41. */
  42. protected $_options = array(
  43. 'plugins' => array(
  44. 'Variables' => null,
  45. 'Time' => null,
  46. 'Memory' => null),
  47. 'z-index' => 255,
  48. 'jquery_path' => 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js',
  49. 'image_path' => null
  50. );
  51. /**
  52. * Standard plugins
  53. *
  54. * @var array
  55. */
  56. public static $standardPlugins = array('Cache', 'Html', 'Database', 'Exception', 'File', 'Memory', 'Registry', 'Time', 'Variables');
  57. /**
  58. * Debug Bar Version Number
  59. * for internal use only
  60. *
  61. * @var string
  62. */
  63. protected $_version = '1.5.4';
  64. /**
  65. * Creates a new instance of the Debug Bar
  66. *
  67. * @param array|Zend_Config $options
  68. * @throws Zend_Controller_Exception
  69. * @return void
  70. */
  71. protected $_closingBracket = null;
  72. public function __construct($options = null)
  73. {
  74. if (isset($options)) {
  75. if ($options instanceof Zend_Config) {
  76. $options = $options->toArray();
  77. }
  78. /*
  79. * Verify that adapter parameters are in an array.
  80. */
  81. if (!is_array($options)) {
  82. throw new Zend_Exception('Debug parameters must be in an array or a Zend_Config object');
  83. }
  84. $this->setOptions($options);
  85. }
  86. /**
  87. * Creating ZF Version Tab always shown
  88. */
  89. $version = new ZFDebug_Controller_Plugin_Debug_Plugin_Text();
  90. $version->setPanel($this->_getVersionPanel())
  91. ->setTab($this->_getVersionTab())
  92. ->setIdentifier('copyright')
  93. ->setIconData('data:image/gif;base64,R0lGODlhEAAQAPcAAPb7/ef2+VepAGKzAIC8SavSiYS9Stvt0uTx4fX6+ur1632+QMLgrGOuApDIZO738drs0Ofz5t7v2MfjtPP6+t7v12SzAcvnyX2+PaPRhH2+Qmy3H3K5LPP6+cXkwIHAR2+4JHi7NePz8YC/Rc3ozfH49XK5KXq9OrzdpNzu1YrEUqrVkdzw5uTw4d/v2dDow5zOeO3279Hq0m+4JqrUhpnMbeHw3N3w6Mflwm22HmazBODy7tfu3un06r7gsuXy4sTisIzGXvH59ny9PdPr1rXZpMzlu36/Q5bLb+Pw3tDnxNHr1Lfbm+b199/x62q1Fp3NcdjszqTPh/L599vt04/GWmazCPb7/LHZnW63I3W6MXa7MmGuAt/y7Gq1E2m0Eb7cp9frzZLJaO/489bu3HW3N7rerN/v2q7WjIjEVuLx343FVrDXj9nt0cTjvW2zIoPBSNjv4OT09IXDUpvLeeHw3dPqyNLpxs/nwHe8OIvFWrPaoGe0C5zMb83mvHm8Oen06a3Xl9XqyoC/Qr/htWe0DofDU4nFWbPYk7ndqZ/PfYPBTMPhrqHRgoLBSujz55PKadHpxfX6+6LNeqPQfNXt2pPIYH2+O7vcoHi4OOf2+PL5+NTs2N3u1mi1E7XZl4zEVJjLaZHGauby5KTShmSzBO/38s/oz3i7MtbrzMHiuYTCT4fDTtXqye327uDv3JDHXu328JnMcu738LLanvD49ZTJYpPKauX19tvv44jBWo7GWpfKZ+Dv27XcpcrluXu8ONTs16zXleT08qfUjKzUlc7pzm63HaTRfZXKZuj06HG4KavViGe0EcDfqcjmxaDQgZrNdOHz77/ep4/HYL3esnW6LobCS3S5K57OctDp0JXKbez17N7x6cbkwLTZlbXXmLrcnrvdodHr06PQe8jkt5jIa93v13m8OI7CW3O6L3a7Nb7gs6nUjmu2GqjTgZjKaKLQeZnMc4LAReL08rTbopbLbuTx4KDOdtbry7DYmrvfrrPaoXK5K5zOegAAACH5BAEAAAAALAAAAAAQABAAAAhMAAEIHEiwoMGDCBMOlCKgoUMuHghInEiggEOHAC5eJNhQ4UAuAjwIJLCR4AEBDQS2uHiAYLGOHjNqlCmgYAONApQ0jBGzp8+fQH8GBAA7');
  94. $this->registerPlugin($version);
  95. /**
  96. * Loading aready defined plugins
  97. */
  98. $this->_loadPlugins();
  99. }
  100. /**
  101. * Sets options of the Debug Bar
  102. *
  103. * @param array $options
  104. * @return ZFDebug_Controller_Plugin_Debug
  105. */
  106. public function setOptions(array $options = array())
  107. {
  108. if (isset($options['jquery_path'])) {
  109. $this->_options['jquery_path'] = $options['jquery_path'];
  110. }
  111. if (isset($options['z-index'])) {
  112. $this->_options['z-index'] = $options['z-index'];
  113. }
  114. if (isset($options['image_path'])) {
  115. $this->_options['image_path'] = $options['image_path'];
  116. }
  117. if (isset($options['plugins'])) {
  118. $this->_options['plugins'] = $options['plugins'];
  119. }
  120. return $this;
  121. }
  122. /**
  123. * Register a new plugin in the Debug Bar
  124. *
  125. * @param ZFDebug_Controller_Plugin_Debug_Plugin_Interface
  126. * @return ZFDebug_Controller_Plugin_Debug
  127. */
  128. public function registerPlugin(ZFDebug_Controller_Plugin_Debug_Plugin_Interface $plugin)
  129. {
  130. $this->_plugins[$plugin->getIdentifier()] = $plugin;
  131. return $this;
  132. }
  133. /**
  134. * Unregister a plugin in the Debug Bar
  135. *
  136. * @param string $plugin
  137. * @return ZFDebug_Controller_Plugin_Debug
  138. */
  139. public function unregisterPlugin($plugin)
  140. {
  141. if (false !== strpos($plugin, '_')) {
  142. foreach ($this->_plugins as $key => $_plugin) {
  143. if ($plugin == get_class($_plugin)) {
  144. unset($this->_plugins[$key]);
  145. }
  146. }
  147. } else {
  148. $plugin = strtolower($plugin);
  149. if (isset($this->_plugins[$plugin])) {
  150. unset($this->_plugins[$plugin]);
  151. }
  152. }
  153. return $this;
  154. }
  155. /**
  156. * Get a registered plugin in the Debug Bar
  157. *
  158. * @param string $identifier
  159. * @return ZFDebug_Controller_Plugin_Debug_Plugin_Interface
  160. */
  161. public function getPlugin($identifier)
  162. {
  163. $identifier = strtolower($identifier);
  164. if (isset($this->_plugins[$identifier])) {
  165. return $this->_plugins[$identifier];
  166. }
  167. return false;
  168. }
  169. /**
  170. * Defined by Zend_Controller_Plugin_Abstract
  171. */
  172. public function dispatchLoopShutdown()
  173. {
  174. if ($this->getRequest()->isXmlHttpRequest()) {
  175. return;
  176. }
  177. $disable = Zend_Controller_Front::getInstance()->getRequest()->getParam('ZFDEBUG_DISABLE');
  178. if (isset($disable)) {
  179. return;
  180. }
  181. $html = '';
  182. /**
  183. * Creating menu tab for all registered plugins
  184. */
  185. foreach ($this->_plugins as $plugin)
  186. {
  187. $panel = $plugin->getPanel();
  188. if ($panel == '') {
  189. continue;
  190. }
  191. /* @var $plugin ZFDebug_Controller_Plugin_Debug_Plugin_Interface */
  192. $html .= '<div id="ZFDebug_' . $plugin->getIdentifier()
  193. . '" class="ZFDebug_panel">' . $panel . '</div>';
  194. }
  195. $html .= '<div id="ZFDebug_info">';
  196. /**
  197. * Creating panel content for all registered plugins
  198. */
  199. foreach ($this->_plugins as $plugin)
  200. {
  201. $tab = $plugin->getTab();
  202. if ($tab == '') {
  203. continue;
  204. }
  205. if (null !== $this->_options['image_path'] && file_exists($this->_options['image_path'] .'/'. $plugin->getIdentifier() .'.png')) {
  206. $plugin_icon = $this->_options['image_path'] .'/'. $plugin->getIdentifier() .'.png';
  207. } else {
  208. $plugin_icon = $plugin->getIconData();
  209. }
  210. /* @var $plugin ZFDebug_Controller_Plugin_Debug_Plugin_Interface */
  211. $html .= '<span class="ZFDebug_span clickable" onclick="ZFDebugPanel(\'ZFDebug_' . $plugin->getIdentifier() . '\');">';
  212. $html .= '<img src="' . $plugin_icon . '" style="vertical-align:middle" alt="' . $plugin->getIdentifier() . '" title="' . $plugin->getIdentifier() . '"'. $this->getClosingBracket() .' ';
  213. $html .= $tab . '</span>';
  214. }
  215. $html .= '<span class="ZFDebug_span ZFDebug_last clickable" id="ZFDebug_toggler" onclick="ZFDebugSlideBar()">&#171;</span>';
  216. $html .= '</div>';
  217. $this->_output($html);
  218. }
  219. ### INTERNAL METHODS BELOW ###
  220. /**
  221. * Load plugins set in config option
  222. *
  223. * @return void;
  224. */
  225. protected function _loadPlugins()
  226. {
  227. foreach($this->_options['plugins'] as $plugin => $options) {
  228. if (is_numeric($plugin)) {
  229. # Plugin passed as array value instead of key
  230. $plugin = $options;
  231. $options = array();
  232. }
  233. // Register an instance
  234. if (is_object($plugin) && in_array('ZFDebug_Controller_Plugin_Debug_Plugin_Interface', class_implements($plugin))) {
  235. $this->registerPlugin($plugin);
  236. continue;
  237. }
  238. if (!is_string($plugin)) {
  239. throw new Exception("Invalid plugin name", 1);
  240. }
  241. $plugin = ucfirst($plugin);
  242. // Register a classname
  243. if (in_array($plugin, ZFDebug_Controller_Plugin_Debug::$standardPlugins)) {
  244. // standard plugin
  245. $pluginClass = 'ZFDebug_Controller_Plugin_Debug_Plugin_' . $plugin;
  246. } else {
  247. // we use a custom plugin
  248. if (!preg_match('~^[\w]+$~D', $plugin)) {
  249. throw new Zend_Exception("ZFDebug: Invalid plugin name [$plugin]");
  250. }
  251. $pluginClass = $plugin;
  252. }
  253. require_once str_replace('_', DIRECTORY_SEPARATOR, $pluginClass) . '.php';
  254. $object = new $pluginClass($options);
  255. $this->registerPlugin($object);
  256. }
  257. }
  258. /**
  259. * Return version tab
  260. *
  261. * @return string
  262. */
  263. protected function _getVersionTab()
  264. {
  265. return ' ' . Zend_Version::VERSION . '/'.phpversion();
  266. }
  267. /**
  268. * Returns version panel
  269. *
  270. * @return string
  271. */
  272. protected function _getVersionPanel()
  273. {
  274. $panel = '<h4>ZFDebug v'.$this->_version.'</h4>' .
  275. '<p>©2008-2009 <a href="http://jokke.dk">Joakim Nygård</a> &amp; <a href="http://www.bangal.de">Andreas Pankratz</a></p>' .
  276. '<p>The project is hosted at <a href="http://code.google.com/p/zfdebug/">http://zfdebug.googlecode.com</a> and released under the BSD License' . $this->getLinebreak() .
  277. 'Includes images from the <a href="http://www.famfamfam.com/lab/icons/silk/">Silk Icon set</a> by Mark James</p>'.
  278. '<p>Disable ZFDebug temporarily by sending ZFDEBUG_DISABLE as a GET/POST parameter</p>';
  279. // $panel .= '<h4>Zend Framework '.Zend_Version::VERSION.' / PHP '.phpversion().' with extensions:</h4>';
  280. // $extensions = get_loaded_extensions();
  281. // natcasesort($extensions);
  282. // $panel .= implode('<br>', $extensions);
  283. return $panel;
  284. }
  285. /**
  286. * Returns path to the specific icon
  287. *
  288. * @return string
  289. */
  290. protected function _icon($kind)
  291. {
  292. switch ($kind) {
  293. case 'database':
  294. if (null === $this->_options['image_path'])
  295. return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAEYSURBVBgZBcHPio5hGAfg6/2+R980k6wmJgsJ5U/ZOAqbSc2GnXOwUg7BESgLUeIQ1GSjLFnMwsKGGg1qxJRmPM97/1zXFAAAAEADdlfZzr26miup2svnelq7d2aYgt3rebl585wN6+K3I1/9fJe7O/uIePP2SypJkiRJ0vMhr55FLCA3zgIAOK9uQ4MS361ZOSX+OrTvkgINSjS/HIvhjxNNFGgQsbSmabohKDNoUGLohsls6BaiQIMSs2FYmnXdUsygQYmumy3Nhi6igwalDEOJEjPKP7CA2aFNK8Bkyy3fdNCg7r9/fW3jgpVJbDmy5+PB2IYp4MXFelQ7izPrhkPHB+P5/PjhD5gCgCenx+VR/dODEwD+A3T7nqbxwf1HAAAAAElFTkSuQmCC';
  296. return $this->_options['image_path'] . '/database.png';
  297. break;
  298. case 'exception':
  299. if (null === $this->_options['image_path'])
  300. return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAJPSURBVDjLpZPLS5RhFMYfv9QJlelTQZwRb2OKlKuINuHGLlBEBEOLxAu46oL0F0QQFdWizUCrWnjBaDHgThCMoiKkhUONTqmjmDp2GZ0UnWbmfc/ztrC+GbM2dXbv4ZzfeQ7vefKMMfifyP89IbevNNCYdkN2kawkCZKfSPZTOGTf6Y/m1uflKlC3LvsNTWArr9BT2LAf+W73dn5jHclIBFZyfYWU3or7T4K7AJmbl/yG7EtX1BQXNTVCYgtgbAEAYHlqYHlrsTEVQWr63RZFuqsfDAcdQPrGRR/JF5nKGm9xUxMyr0YBAEXXHgIANq/3ADQobD2J9fAkNiMTMSFb9z8ambMAQER3JC1XttkYGGZXoyZEGyTHRuBuPgBTUu7VSnUAgAUAWutOV2MjZGkehgYUA6O5A0AlkAyRnotiX3MLlFKduYCqAtuGXpyH0XQmOj+TIURt51OzURTYZdBKV2UBSsOIcRp/TVTT4ewK6idECAihtUKOArWcjq/B8tQ6UkUR31+OYXP4sTOdisivrkMyHodWejlXwcC38Fvs8dY5xaIId89VlJy7ACpCNCFCuOp8+BJ6A631gANQSg1mVmOxxGQYRW2nHMha4B5WA3chsv22T5/B13AIicWZmNZ6cMchTXUe81Okzz54pLi0uQWp+TmkZqMwxsBV74Or3od4OISPr0e3SHa3PX0f3HXKofNH/UIG9pZ5PeUth+CyS2EMkEqs4fPEOBJLsyske48/+xD8oxcAYPzs4QaS7RR2kbLTTOTQieczfzfTv8QPldGvTGoF6/8AAAAASUVORK5CYII=';
  301. return $this->_options['image_path'] . '/exception.png';
  302. break;
  303. case 'error':
  304. if (null === $this->_options['image_path'])
  305. return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAIsSURBVDjLpVNLSJQBEP7+h6uu62vLVAJDW1KQTMrINQ1vPQzq1GOpa9EppGOHLh0kCEKL7JBEhVCHihAsESyJiE4FWShGRmauu7KYiv6Pma+DGoFrBQ7MzGFmPr5vmDFIYj1mr1WYfrHPovA9VVOqbC7e/1rS9ZlrAVDYHig5WB0oPtBI0TNrUiC5yhP9jeF4X8NPcWfopoY48XT39PjjXeF0vWkZqOjd7LJYrmGasHPCCJbHwhS9/F8M4s8baid764Xi0Ilfp5voorpJfn2wwx/r3l77TwZUvR+qajXVn8PnvocYfXYH6k2ioOaCpaIdf11ivDcayyiMVudsOYqFb60gARJYHG9DbqQFmSVNjaO3K2NpAeK90ZCqtgcrjkP9aUCXp0moetDFEeRXnYCKXhm+uTW0CkBFu4JlxzZkFlbASz4CQGQVBFeEwZm8geyiMuRVntzsL3oXV+YMkvjRsydC1U+lhwZsWXgHb+oWVAEzIwvzyVlk5igsi7DymmHlHsFQR50rjl+981Jy1Fw6Gu0ObTtnU+cgs28AKgDiy+Awpj5OACBAhZ/qh2HOo6i+NeA73jUAML4/qWux8mt6NjW1w599CS9xb0mSEqQBEDAtwqALUmBaG5FV3oYPnTHMjAwetlWksyByaukxQg2wQ9FlccaK/OXA3/uAEUDp3rNIDQ1ctSk6kHh1/jRFoaL4M4snEMeD73gQx4M4PsT1IZ5AfYH68tZY7zv/ApRMY9mnuVMvAAAAAElFTkSuQmCC';
  306. return $this->_options['image_path'] . '/error.png';
  307. break;
  308. default:
  309. if (null === $this->_options['image_path'])
  310. return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAHhSURBVDjLpZI9SJVxFMZ/r2YFflw/kcQsiJt5b1ije0tDtbQ3GtFQYwVNFbQ1ujRFa1MUJKQ4VhYqd7K4gopK3UIly+57nnMaXjHjqotnOfDnnOd/nt85SURwkDi02+ODqbsldxUlD0mvHw09ubSXQF1t8512nGJ/Uz/5lnxi0tB+E9QI3D//+EfVqhtppGxUNzCzmf0Ekojg4fS9cBeSoyzHQNuZxNyYXp5ZM5Mk1ZkZT688b6thIBenG/N4OB5B4InciYBCVyGnEBHO+/LH3SFKQuF4OEs/51ndXMXC8Ajqknrcg1O5PGa2h4CJUqVES0OO7sYevv2qoFBmJ/4gF4boaOrg6rPLYWaYiVfDo0my8w5uj12PQleB0vcp5I6HsHAUoqUhR29zH+5B4IxNTvDmxljy3x2YCYUwZVlbzXJh9UKeQY6t2m0Lt94Oh5loPdqK3EkjzZi4MM/Y9Db3MTv/mYWVxaqkw9IOATNR7B5ABHPrZQrtg9sb8XDKa1+QOwsri4zeHD9SAzE1wxBTXz9xtvMc5ZU5lirLSKIz18nJnhOZjb22YKkhd4odg5icpcoyL669TAAujlyIvmPHSWXY1ti1AmZ8mJ3ElP1ips1/YM3H300g+W+51nc95YPEX8fEbdA2ReVYAAAAAElFTkSuQmCC';
  311. return $this->_options['image_path'] . '/unknown.png';
  312. break;
  313. }
  314. }
  315. /**
  316. * Returns html header for the Debug Bar
  317. *
  318. * @return string
  319. */
  320. protected function _headerOutput() {
  321. $collapsed = isset($_COOKIE['ZFDebugCollapsed']) ? $_COOKIE['ZFDebugCollapsed'] : 0;
  322. return ('
  323. <style type="text/css" media="screen">
  324. #ZFDebug_debug { font: 11px/1.4em Lucida Grande, Lucida Sans Unicode, sans-serif; position:fixed; bottom:5px; left:5px; color:#000; z-index: ' . $this->_options['z-index'] . ';}
  325. #ZFDebug_debug ol {margin:10px 0px; padding:0 25px}
  326. #ZFDebug_debug li {margin:0 0 10px 0;}
  327. #ZFDebug_debug .clickable {cursor:pointer}
  328. #ZFDebug_toggler { font-weight:bold; background:#BFBFBF; }
  329. .ZFDebug_span { border: 1px solid #999; border-right:0px; background:#DFDFDF; padding: 5px 5px; }
  330. .ZFDebug_last { border: 1px solid #999; }
  331. .ZFDebug_panel { text-align:left; position:absolute;bottom:21px;width:800px; max-height:400px; overflow:auto; display:none; background:#E8E8E8; padding:5px; border: 1px solid #999; }
  332. .ZFDebug_panel .pre {font: 11px/1.4em Monaco, Lucida Console, monospace; margin:0 0 0 22px}
  333. #ZFDebug_exception { border:1px solid #CD0A0A;display: block; }
  334. </style>
  335. <script type="text/javascript">
  336. if (typeof jQuery == "undefined") {
  337. var scriptObj = document.createElement("script");
  338. scriptObj.src = "'.$this->_options['jquery_path'].'";
  339. scriptObj.type = "text/javascript";
  340. var head=document.getElementsByTagName("head")[0];
  341. head.insertBefore(scriptObj,head.firstChild);
  342. jQuery.noConflict();
  343. }
  344. var ZFDebugLoad = window.onload;
  345. window.onload = function(){
  346. if (ZFDebugLoad) {
  347. ZFDebugLoad();
  348. }
  349. ZFDebugCollapsed();
  350. };
  351. function ZFDebugCollapsed() {
  352. if ('.$collapsed.' == 1) {
  353. ZFDebugPanel();
  354. jQuery("#ZFDebug_toggler").html("&#187;");
  355. return jQuery("#ZFDebug_debug").css("left", "-"+parseInt(jQuery("#ZFDebug_debug").outerWidth()-jQuery("#ZFDebug_toggler").outerWidth()+1)+"px");
  356. }
  357. }
  358. function ZFDebugPanel(name) {
  359. jQuery(".ZFDebug_panel").each(function(i){
  360. if(jQuery(this).css("display") == "block") {
  361. jQuery(this).slideUp();
  362. } else {
  363. if (jQuery(this).attr("id") == name)
  364. jQuery(this).slideDown();
  365. else
  366. jQuery(this).slideUp();
  367. }
  368. });
  369. }
  370. function ZFDebugSlideBar() {
  371. if (jQuery("#ZFDebug_debug").position().left > 0) {
  372. document.cookie = "ZFDebugCollapsed=1;expires=;path=/";
  373. ZFDebugPanel();
  374. jQuery("#ZFDebug_toggler").html("&#187;");
  375. return jQuery("#ZFDebug_debug").animate({left:"-"+parseInt(jQuery("#ZFDebug_debug").outerWidth()-jQuery("#ZFDebug_toggler").outerWidth()+1)+"px"}, "normal", "swing");
  376. } else {
  377. document.cookie = "ZFDebugCollapsed=0;expires=;path=/";
  378. jQuery("#ZFDebug_toggler").html("&#171;");
  379. return jQuery("#ZFDebug_debug").animate({left:"5px"}, "normal", "swing");
  380. }
  381. }
  382. function ZFDebugToggleElement(name, whenHidden, whenVisible){
  383. if(jQuery(name).css("display")=="none"){
  384. jQuery(whenVisible).show();
  385. jQuery(whenHidden).hide();
  386. } else {
  387. jQuery(whenVisible).hide();
  388. jQuery(whenHidden).show();
  389. }
  390. jQuery(name).slideToggle();
  391. }
  392. </script>');
  393. }
  394. /**
  395. * Appends Debug Bar html output to the original page
  396. *
  397. * @param string $html
  398. * @return void
  399. */
  400. protected function _output($html)
  401. {
  402. $response = $this->getResponse();
  403. $response->setBody(preg_replace('/(<\/head>)/i', $this->_headerOutput() . '$1', $response->getBody()));
  404. $response->setBody(str_ireplace('</body>', '<div id="ZFDebug_debug">'.$html.'</div></body>', $response->getBody()));
  405. }
  406. public function getLinebreak()
  407. {
  408. return '<br'.$this->getClosingBracket();
  409. }
  410. public function getClosingBracket()
  411. {
  412. if (!$this->_closingBracket) {
  413. if ($this->_isXhtml()) {
  414. $this->_closingBracket = ' />';
  415. } else {
  416. $this->_closingBracket = '>';
  417. }
  418. }
  419. return $this->_closingBracket;
  420. }
  421. protected function _isXhtml()
  422. {
  423. if ($view = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view) {
  424. $doctype = $view->doctype();
  425. return $doctype->isXhtml();
  426. }
  427. return false;
  428. }
  429. }