Automatically exported from code.google.com/p/planningalerts
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

91 wiersze
2.8 KiB

  1. <?php
  2. /**
  3. * Smarty plugin
  4. * @package Smarty
  5. * @subpackage plugins
  6. */
  7. /**
  8. * Smarty debug_print_var modifier plugin
  9. *
  10. * Type: modifier<br>
  11. * Name: debug_print_var<br>
  12. * Purpose: formats variable contents for display in the console
  13. * @link http://smarty.php.net/manual/en/language.modifier.debug.print.var.php
  14. * debug_print_var (Smarty online manual)
  15. * @author Monte Ohrt <monte at ohrt dot com>
  16. * @param array|object
  17. * @param integer
  18. * @param integer
  19. * @return string
  20. */
  21. function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40)
  22. {
  23. $_replace = array(
  24. "\n" => '<i>\n</i>',
  25. "\r" => '<i>\r</i>',
  26. "\t" => '<i>\t</i>'
  27. );
  28. switch (gettype($var)) {
  29. case 'array' :
  30. $results = '<b>Array (' . count($var) . ')</b>';
  31. foreach ($var as $curr_key => $curr_val) {
  32. $results .= '<br>' . str_repeat('&nbsp;', $depth * 2)
  33. . '<b>' . strtr($curr_key, $_replace) . '</b> =&gt; '
  34. . smarty_modifier_debug_print_var($curr_val, ++$depth, $length);
  35. $depth--;
  36. }
  37. break;
  38. case 'object' :
  39. $object_vars = get_object_vars($var);
  40. $results = '<b>' . get_class($var) . ' Object (' . count($object_vars) . ')</b>';
  41. foreach ($object_vars as $curr_key => $curr_val) {
  42. $results .= '<br>' . str_repeat('&nbsp;', $depth * 2)
  43. . '<b> -&gt;' . strtr($curr_key, $_replace) . '</b> = '
  44. . smarty_modifier_debug_print_var($curr_val, ++$depth, $length);
  45. $depth--;
  46. }
  47. break;
  48. case 'boolean' :
  49. case 'NULL' :
  50. case 'resource' :
  51. if (true === $var) {
  52. $results = 'true';
  53. } elseif (false === $var) {
  54. $results = 'false';
  55. } elseif (null === $var) {
  56. $results = 'null';
  57. } else {
  58. $results = htmlspecialchars((string) $var);
  59. }
  60. $results = '<i>' . $results . '</i>';
  61. break;
  62. case 'integer' :
  63. case 'float' :
  64. $results = htmlspecialchars((string) $var);
  65. break;
  66. case 'string' :
  67. $results = strtr($var, $_replace);
  68. if (strlen($var) > $length ) {
  69. $results = substr($var, 0, $length - 3) . '...';
  70. }
  71. $results = htmlspecialchars('"' . $results . '"');
  72. break;
  73. case 'unknown type' :
  74. default :
  75. $results = strtr((string) $var, $_replace);
  76. if (strlen($results) > $length ) {
  77. $results = substr($results, 0, $length - 3) . '...';
  78. }
  79. $results = htmlspecialchars($results);
  80. }
  81. return $results;
  82. }
  83. /* vim: set expandtab: */
  84. ?>