PageRenderTime 51ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/xampp/php/PEAR/PHP/CompatInfo/Renderer/Html.php

https://github.com/edmondscommerce/XAMPP-Magento-Demo-Site
PHP | 453 lines | 297 code | 28 blank | 128 comment | 43 complexity | c059f6e9115d26ad96c310893647e466 MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright (c) 2008, Laurent Laville <pear@laurent-laville.org>
  4. *
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * * Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * * Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * * Neither the name of the authors nor the names of its contributors
  17. * may be used to endorse or promote products derived from this software
  18. * without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
  24. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  25. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  26. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  27. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  28. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  30. * POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. * PHP versions 4 and 5
  33. *
  34. * @category PHP
  35. * @package PHP_CompatInfo
  36. * @author Laurent Laville <pear@laurent-laville.org>
  37. * @license http://www.opensource.org/licenses/bsd-license.php BSD
  38. * @version CVS: $Id: Html.php,v 1.12 2008/07/22 20:26:19 farell Exp $
  39. * @link http://pear.php.net/package/PHP_CompatInfo
  40. * @since File available since Release 1.8.0b4
  41. */
  42. require_once 'HTML/Table.php';
  43. require_once 'HTML/CSS.php';
  44. /**
  45. * Html renderer for PHP_CompatInfo component.
  46. *
  47. * The PHP_CompatInfo_Renderer_Html class is a concrete implementation
  48. * of PHP_CompatInfo_Renderer abstract class. It simply display results
  49. * as web/html content with help of PEAR::Html_Table
  50. *
  51. * @category PHP
  52. * @package PHP_CompatInfo
  53. * @author Laurent Laville <pear@laurent-laville.org>
  54. * @license http://www.opensource.org/licenses/bsd-license.php BSD
  55. * @version Release: 1.8.1
  56. * @link http://pear.php.net/package/PHP_CompatInfo
  57. * @since Class available since Release 1.8.0b4
  58. */
  59. class PHP_CompatInfo_Renderer_Html extends PHP_CompatInfo_Renderer
  60. {
  61. /**
  62. * Style sheet for the custom layout
  63. *
  64. * @var string
  65. * @access public
  66. * @since 1.8.0b4
  67. */
  68. var $css;
  69. /**
  70. * Html Renderer Class constructor (ZE1) for PHP4
  71. *
  72. * @param object &$parser Instance of the parser (model of MVC pattern)
  73. * @param array $conf A hash containing any additional configuration
  74. *
  75. * @access public
  76. * @since version 1.8.0b4 (2008-06-18)
  77. */
  78. function PHP_CompatInfo_Renderer_Html(&$parser, $conf)
  79. {
  80. $this->__construct($parser, $conf);
  81. }
  82. /**
  83. * Html Renderer Class constructor (ZE2) for PHP5+
  84. *
  85. * @param object &$parser Instance of the parser (model of MVC pattern)
  86. * @param array $conf A hash containing any additional configuration
  87. *
  88. * @access public
  89. * @since version 1.8.0b4 (2008-06-18)
  90. */
  91. function __construct(&$parser, $conf)
  92. {
  93. $defaults = array('tdwidth' => array(18, 4, 2, 7, 13));
  94. $conf = array_merge($defaults, $conf);
  95. parent::PHP_CompatInfo_Renderer($parser, $conf);
  96. }
  97. /**
  98. * Display final results
  99. *
  100. * Display final results, when data source parsing is over.
  101. *
  102. * @access public
  103. * @return void
  104. * @since version 1.8.0b4 (2008-06-18)
  105. */
  106. function display()
  107. {
  108. $o = $this->args['output-level'];
  109. $info = $this->parseData;
  110. if ($info == false) {
  111. // protect against invalid data source
  112. print 'Invalid data source';
  113. return;
  114. }
  115. $src = $this->_parser->dataSource;
  116. if ($src['dataType'] == 'directory') {
  117. $dir = $src['dataSource'];
  118. $hdr_col1 = 'Directory';
  119. } elseif ($src['dataType'] == 'file') {
  120. $file = $src['dataSource'];
  121. $hdr_col1 = 'File';
  122. } else {
  123. $string = $src['dataSource'];
  124. $hdr_col1 = 'Source code';
  125. }
  126. $dataTable = new HTML_Table();
  127. $thead =& $dataTable->getHeader();
  128. $tbody =& $dataTable->getBody();
  129. $tfoot =& $dataTable->getFooter();
  130. $hdr = array($hdr_col1);
  131. $atr = array('scope="col"');
  132. if ($o & 16) {
  133. $hdr[] = 'Version';
  134. $atr[] = 'scope="col"';
  135. }
  136. if ($o & 1) {
  137. $hdr[] = 'C';
  138. $atr[] = 'scope="col"';
  139. }
  140. if ($o & 2) {
  141. $hdr[] = 'Extensions';
  142. $atr[] = 'scope="col"';
  143. }
  144. if ($o & 4) {
  145. if ($o & 8) {
  146. $hdr[] = 'Constants/Tokens';
  147. $atr[] = 'scope="col"';
  148. } else {
  149. $hdr[] = 'Constants';
  150. $atr[] = 'scope="col"';
  151. }
  152. } else {
  153. if ($o & 8) {
  154. $hdr[] = 'Tokens';
  155. $atr[] = 'scope="col"';
  156. }
  157. }
  158. $thead->addRow($hdr, $atr);
  159. $ext = implode("<br/>", $info['extensions']);
  160. $const = implode("<br/>", array_merge($info['constants'], $info['tokens']));
  161. if (isset($dir)) {
  162. $ds = DIRECTORY_SEPARATOR;
  163. $dir = str_replace(array('\\', '/'), $ds, $dir);
  164. $title = $src['dataCount'] . ' file';
  165. if ($src['dataCount'] > 1) {
  166. $title .= 's'; // plural
  167. }
  168. } elseif (isset($file)) {
  169. $title = '1 file';
  170. } else {
  171. $title = '1 chunk of code';
  172. }
  173. $data = array('Summary: '. $title . ' parsed');
  174. if ($o & 16) {
  175. if (empty($info['max_version'])) {
  176. $data[] = $info['version'];
  177. } else {
  178. $data[] = implode("<br/>", array($info['version'],
  179. $info['max_version']));
  180. }
  181. }
  182. if ($o & 1) {
  183. $data[] = $info['cond_code'][0];
  184. }
  185. if ($o & 2) {
  186. $data[] = $ext;
  187. }
  188. if ($o & 4) {
  189. if ($o & 8) {
  190. $data[] = $const;
  191. } else {
  192. $data[] = implode("<br/>", $info['constants']);
  193. }
  194. } else {
  195. if ($o & 8) {
  196. $data[] = implode("<br/>", $info['tokens']);
  197. }
  198. }
  199. // summary informations
  200. $tfoot->addRow($data);
  201. // summarize : print only summary for directory without files details
  202. if ($this->args['summarize'] === false && isset($dir)) {
  203. // display result of parsing multiple files
  204. unset($info['max_version']);
  205. unset($info['version']);
  206. unset($info['functions']);
  207. unset($info['extensions']);
  208. unset($info['constants']);
  209. unset($info['tokens']);
  210. unset($info['cond_code']);
  211. $ignored = $info['ignored_files'];
  212. unset($info['ignored_files']);
  213. unset($info['ignored_functions']);
  214. unset($info['ignored_extensions']);
  215. unset($info['ignored_constants']);
  216. foreach ($info as $file => $info) {
  217. if ($info === false) {
  218. continue; // skip this (invalid) file
  219. }
  220. $ext = implode("<br/>", $info['extensions']);
  221. $const = implode("<br/>", array_merge($info['constants'],
  222. $info['tokens']));
  223. $file = str_replace(array('\\', '/'), $ds, $file);
  224. $path = dirname($file);
  225. $tbody->addRow(array($path), array('class' => 'dirname',
  226. 'colspan' => count($hdr)));
  227. $data = array(basename($file));
  228. if ($o & 16) {
  229. if (empty($info['max_version'])) {
  230. $data[] = $info['version'];
  231. } else {
  232. $data[] = implode("<br/>", array($info['version'],
  233. $info['max_version']));
  234. }
  235. }
  236. if ($o & 1) {
  237. $data[] = $info['cond_code'][0];
  238. }
  239. if ($o & 2) {
  240. $data[] = $ext;
  241. }
  242. if ($o & 4) {
  243. if ($o & 8) {
  244. $data[] = $const;
  245. } else {
  246. $data[] = implode("<br/>", $info['constants']);
  247. }
  248. } else {
  249. if ($o & 8) {
  250. $data[] = implode("<br/>", $info['tokens']);
  251. }
  252. }
  253. $tbody->addRow($data);
  254. }
  255. } elseif ($this->args['summarize'] === false && !isset($dir)) {
  256. // display result of parsing a single file, or a chunk of code
  257. if (isset($file)) {
  258. $path = dirname($file);
  259. } else {
  260. $path = '.';
  261. }
  262. $tbody->addRow(array($path), array('class' => 'dirname',
  263. 'colspan' => count($hdr)));
  264. if (isset($file)) {
  265. $data[0] = basename($file);
  266. } else {
  267. $data[0] = htmlspecialchars('<?php ... ?>');
  268. }
  269. $tbody->addRow($data);
  270. } else {
  271. // display only result summary of parsing a data source
  272. if (isset($dir)) {
  273. $path = dirname($dir[0]);
  274. } elseif (isset($file)) {
  275. $path = dirname($file);
  276. } else {
  277. $path = '.';
  278. }
  279. $tbody->addRow(array($path), array('class' => 'dirname',
  280. 'colspan' => count($hdr)));
  281. }
  282. $evenRow = array('class' => 'even');
  283. $oddRow = null;
  284. $tbody->altRowAttributes(1, $evenRow, $oddRow, true);
  285. echo $this->toHtml($dataTable);
  286. }
  287. /**
  288. * Returns the custom style sheet
  289. *
  290. * Returns the custom style sheet to use for layout
  291. *
  292. * @param int $destination (optional) Destination of css content
  293. * @param mixed $extra (optional) Additional data depending of destination
  294. *
  295. * @return mixed
  296. * @access public
  297. * @since version 1.8.0b4 (2008-06-18)
  298. */
  299. function getStyleSheet($destination = 1, $extra = null)
  300. {
  301. $css = new HTML_CSS();
  302. $css->parseFile($this->css);
  303. $tdw = $this->conf['tdwidth'];
  304. $em = array_sum($tdw);
  305. $td = 'td';
  306. $o = $this->args['output-level'];
  307. $css->setStyle('.outer td.dirname', 'width', $em.'em');
  308. if ($o & 16) {
  309. $td .= '+td';
  310. $css->setStyle('.outer '.$td, 'width', $tdw[1].'em');
  311. $em = $em - $tdw[1];
  312. }
  313. if ($o & 1) {
  314. $td .= '+td';
  315. $css->setStyle('.outer '.$td, 'width', $tdw[2].'em');
  316. $em = $em - $tdw[2];
  317. }
  318. if ($o & 2) {
  319. $td .= '+td';
  320. $css->setStyle('.outer '.$td, 'width', $tdw[3].'em');
  321. $em = $em - $tdw[3];
  322. }
  323. if ($o & 12) {
  324. $td .= '+td';
  325. $css->setStyle('.outer '.$td, 'width', $tdw[4].'em');
  326. $em = $em - $tdw[4];
  327. }
  328. $css->setStyle('.outer td', 'width', $em .'em');
  329. $styles = '';
  330. switch ($destination) {
  331. case 1: // embedded styles
  332. $styles = $css->toString();
  333. break;
  334. case 2: // save only to file
  335. $css->toFile($extra);
  336. $styles = $extra;
  337. break;
  338. case 3: // apply a user function
  339. if (is_callable($extra)) {
  340. $styles = call_user_func_array($extra, array($css));
  341. }
  342. break;
  343. default:
  344. break;
  345. }
  346. return $styles;
  347. }
  348. /**
  349. * Set a custom style sheet
  350. *
  351. * Set a custom style sheet to use your own styles
  352. *
  353. * @param string $css (optional) File to read user-defined styles from
  354. *
  355. * @return bool True if custom styles, false if default styles applied
  356. * @access public
  357. * @since version 1.8.0b4 (2008-06-18)
  358. */
  359. function setStyleSheet($css = null)
  360. {
  361. // default stylesheet is into package data directory
  362. if (!isset($css)) {
  363. $css = 'C:\php5\pear\data' . DIRECTORY_SEPARATOR
  364. . 'PHP_CompatInfo' . DIRECTORY_SEPARATOR
  365. . 'pci.css';
  366. }
  367. $res = isset($css) && file_exists($css);
  368. if ($res) {
  369. $this->css = $css;
  370. }
  371. return $res;
  372. }
  373. /**
  374. * Returns HTML code
  375. *
  376. * Returns HTML code of parsing result
  377. *
  378. * @param object $obj instance of HTML_Table
  379. *
  380. * @access public
  381. * @return string
  382. * @since version 1.8.0b4 (2008-06-18)
  383. */
  384. function toHtml($obj)
  385. {
  386. if (!isset($this->css)) {
  387. // when no user-styles defined, used the default values
  388. $this->setStyleSheet();
  389. }
  390. $styles = $this->getStyleSheet();
  391. $body = $obj->toHtml();
  392. $html = <<<HTML
  393. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  394. "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  395. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  396. <head>
  397. <title>PHP_CompatInfo</title>
  398. <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  399. <style type="text/css">
  400. <!--
  401. $styles
  402. -->
  403. </style>
  404. </head>
  405. <body>
  406. <div class="outer">
  407. <div class="inner">
  408. $body
  409. </div>
  410. </div>
  411. </body>
  412. </html>
  413. HTML;
  414. return $html;
  415. }
  416. }
  417. ?>