phpDocumentor page
[ class tree: page ] [ index: page ] [ all elements ]

Source for file Comment.php

Documentation is available at Comment.php

  1. <?
  2. /**
  3. * @package page
  4. * @filesource
  5. * @see HTML_PAGE_UTIL_PATH.'/Comment.php'
  6. * @copyright (c) http://Finn-Rasmussen.com
  7. * @license http://Finn-Rasmussen.com/license/ myPHP License conditions
  8. * @author http://Finn-Rasmussen.com
  9. * @version 1.9
  10. * @since 21-oct-2005
  11. */
  12.  
  13. /**
  14. * The required files
  15. */
  16. require_once(HTML_PATH.'/Html.php');
  17. if (defined('HTML_LOG_UTIL_PATH')) {
  18. require_once(HTML_LOG_UTIL_PATH.'/Log.php');
  19. }
  20.  
  21. /**
  22. * Generates a Comment object
  23. * <code>
  24. * Usage:
  25. * $comment = new Comment($text,$commmentStart,$commmentEnd);
  26. * print $comment->getHtml();
  27. * Or
  28. * Comment::display($text,$commmentStart,$commmentEnd);
  29. * </code>
  30. * @package page
  31. */
  32.  
  33. class Comment extends Html {
  34. /**
  35. * @var String $text The text to show in comment
  36. */
  37. var $text = '';
  38. /**
  39. * @var String $commmentStart The type of comment '<!-' or '//' or '/*'
  40. */
  41. var $commmentStart = '';
  42.  
  43. /**
  44. * @var String $commmentEnd The Comment end
  45. */
  46. var $commmentEnd = '';
  47.  
  48. /**
  49. * Constructor
  50. * @param String $text The text to show
  51. * @param String $commmentStart The comment start tag
  52. * @param String $commmentEnd The comment end tag
  53. */
  54. function Comment($text='',$commmentStart='',$commmentEnd='') {
  55. $this->Html();
  56. $this->text = $text;
  57. $this->commmentStart = $commmentStart!=''?$commmentStart:COMMENT_START_HTML;
  58. $this->commmentEnd = $commmentEnd !=''?$commmentEnd:COMMENT_END_HTML;
  59. if ($this->commmentStart!='') {
  60. switch ($this->commmentStart) {
  61. case COMMENT_START_HTML:
  62. break;
  63. default:
  64. $msg = $this->getClassName().' unsupported commmentStart, found='.$this->commmentStart;
  65. if (defined('HTML_LOG_UTIL_PATH')) {
  66. Log::fatal(__FILE__,__LINE__,$msg);
  67. } else {
  68. die($msg);
  69. }
  70. }
  71. }
  72. if ($this->commmentEnd!='') {
  73. switch ($this->commmentEnd) {
  74. case COMMENT_END_HTML:
  75. break;
  76. default:
  77. $msg = $this->getClassName().' unsupported commmentEnd, found='.$this->commmentEnd;
  78. if (defined('HTML_LOG_UTIL_PATH')) {
  79. Log::fatal(__FILE__,__LINE__,$msg);
  80. } else {
  81. die($msg);
  82. }
  83. }
  84. }
  85. }
  86.  
  87. /**
  88. * Returns the html for the text, optional surronded by the html element
  89. * @return String the complete html
  90. */
  91. function getHtml() {
  92. $html = '';
  93. if ($this->text!='') {
  94. $html .= $this->commmentStart;
  95. $html .= htmlspecialchars(stripslashes($this->text)); // Translate html special chars
  96. $html .= $this->commmentEnd."\r\n";
  97. }
  98. return $html;
  99. }
  100.  
  101. /**
  102. * Display html
  103. * <code>
  104. * Usage:
  105. * Comment::display($text,$commmentStart,$commmentEnd);
  106. * </code>
  107. * @static
  108. * @param String $text The text to show in comment
  109. * @param String $commmentStart The comment start tag
  110. * @param String $commmentEnd The comment end tag
  111. */
  112. function display($text='',$commmentStart='',$commmentEnd='') {
  113. $html = new Comment($text,$commmentStart,$commmentEnd);
  114. $html->addHtml();
  115. }
  116. }
  117. ?>

Documentation generated on Thu, 22 Dec 2005 17:03:23 +0100 by phpDocumentor 1.3.0RC3