- <?
- /**
- * @package page
- * @filesource
- * @see HTML_PAGE_UTIL_PATH.'/Comment.php'
- * @copyright (c) http://Finn-Rasmussen.com
- * @license http://Finn-Rasmussen.com/license/ myPHP License conditions
- * @author http://Finn-Rasmussen.com
- * @version 1.9
- * @since 21-oct-2005
- */
-
- /**
- * The required files
- */
- require_once(HTML_PATH.'/Html.php');
- if (defined('HTML_LOG_UTIL_PATH')) {
- require_once(HTML_LOG_UTIL_PATH.'/Log.php');
- }
-
- /**
- * Generates a Comment object
- * <code>
- * Usage:
- * $comment = new Comment($text,$commmentStart,$commmentEnd);
- * print $comment->getHtml();
- * Or
- * Comment::display($text,$commmentStart,$commmentEnd);
- * </code>
- * @package page
- */
-
- class Comment extends Html {
- /**
- * @var String $text The text to show in comment
- */
- var $text = '';
- /**
- * @var String $commmentStart The type of comment '<!-' or '//' or '/*'
- */
- var $commmentStart = '';
-
- /**
- * @var String $commmentEnd The Comment end
- */
- var $commmentEnd = '';
-
- /**
- * Constructor
- * @param String $text The text to show
- * @param String $commmentStart The comment start tag
- * @param String $commmentEnd The comment end tag
- */
- function Comment($text='',$commmentStart='',$commmentEnd='') {
- $this->Html();
- $this->text = $text;
- $this->commmentStart = $commmentStart!=''?$commmentStart:COMMENT_START_HTML;
- $this->commmentEnd = $commmentEnd !=''?$commmentEnd:COMMENT_END_HTML;
- if ($this->commmentStart!='') {
- switch ($this->commmentStart) {
- case COMMENT_START_HTML:
- break;
- default:
- $msg = $this->getClassName().' unsupported commmentStart, found='.$this->commmentStart;
- if (defined('HTML_LOG_UTIL_PATH')) {
- Log::fatal(__FILE__,__LINE__,$msg);
- } else {
- die($msg);
- }
- }
- }
- if ($this->commmentEnd!='') {
- switch ($this->commmentEnd) {
- case COMMENT_END_HTML:
- break;
- default:
- $msg = $this->getClassName().' unsupported commmentEnd, found='.$this->commmentEnd;
- if (defined('HTML_LOG_UTIL_PATH')) {
- Log::fatal(__FILE__,__LINE__,$msg);
- } else {
- die($msg);
- }
- }
- }
- }
-
- /**
- * Returns the html for the text, optional surronded by the html element
- * @return String the complete html
- */
- function getHtml() {
- $html = '';
- if ($this->text!='') {
- $html .= $this->commmentStart;
- $html .= htmlspecialchars(stripslashes($this->text)); // Translate html special chars
- $html .= $this->commmentEnd."\r\n";
- }
- return $html;
- }
-
- /**
- * Display html
- * <code>
- * Usage:
- * Comment::display($text,$commmentStart,$commmentEnd);
- * </code>
- * @static
- * @param String $text The text to show in comment
- * @param String $commmentStart The comment start tag
- * @param String $commmentEnd The comment end tag
- */
- function display($text='',$commmentStart='',$commmentEnd='') {
- $html = new Comment($text,$commmentStart,$commmentEnd);
- $html->addHtml();
- }
- }
- ?>