- <?
- /**
- * @package page
- * @filesource
- * @see HTML_PAGE_UTIL_PATH.'/Text.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 plain Text object, surronded by a html element
- * <code>
- * Usage:
- * $text = new Text($text,$element,$class,$name);
- * print $text->getHtml();
- * Or
- * Text::display($text,$element,$class,$name);
- * </code>
- * @package page
- */
-
- class Text extends Html {
- var $text = ''; // The text to show
-
- var $element = ''; // The html element
-
- var $class = ''; // The class name
-
- var $name = ''; // The name/id for a link identifier
-
-
-
- /**
- * Constructor
- * @param String $text The text to show
- * @param String $element The html element, if any
- * @param String $class The css class name
- * @param String $name The name/id attribute for a link identifier
- */
- function Text($text='',$element='',$class='',$name='') {
- $this->Html();
- $this->text = $text;
- $this->element = $element;
- $this->class = $class;
- $this->name = $name;
- if ($this->element!='') {
- switch ($this->element) {
- case 'pre':
- case 'div':
- case 'p':
- case 'hr':
- case 'br':
- case 'ol':
- case 'ul':
- case 'li':
- case 'b':
- case 'h1':
- case 'h2':
- case 'h3':
- case 'h4':
- case 'h5':
- case 'h6':
- // Ok
- break;
- default:
- $msg = $this->getClassName().' unsupported html element, found='.$this->element;
- if (defined('HTML_LOG_UTIL_PATH')) {
- Log::fatal(__FILE__,__LINE__,$msg);
- } else {
- // TODO what ?
- die($this->getMsg(LOG_LEVEL_FATAL, $msg));
- }
- }
- }
- }
-
- /**
- * Returns the start html for the text, optional surronded by the html element
- * @return String the complete html
- */
- function getStart() {
- $html = '';
- if ($this->element!='') {
- if ($this->element!='br' && $this->element!='hr') {
- $html .= $this->html;
- $html .= '<'.$this->element;
- $html .= $this->getAttribute('class');
- $html .= ">";
- switch ($this->element) {
- case 'h1':
- case 'h2':
- case 'h3':
- case 'h4':
- case 'h5':
- case 'h6':
- case 'p':
- case 'li':
- break;
- default:
- $html .= "\r\n";
- break;
- }
- } else {
- // <br />, <hr /> See getEnd()
- }
- }
- return $html;
- }
-
- /**
- * Returns the end html for the text, optional surronded by the html element
- * @return String the complete html
- */
- function getEnd() {
- $html = '';
- if ($this->element!='') {
- if ($this->element!='br' && $this->element!='hr') {
- $html .= '</'.$this->element.">\r\n";
- } else {
- $html .= '<'.$this->element." />\r\n"; // <br />
- }
- }
- return $html;
- }
-
- /**
- * Returns the html for the text, optional surronded by the html element
- * @return String the complete html
- */
- function getHtml() {
- $html = '';
- if ($this->text=='' && $this->element=='' && $this->getSizeof()==0) {
- $msg = $this->getClassName().'->getHtml(), no text or elements found';
- if (defined('HTML_LOG_UTIL_PATH')) {
- Log::warn(__FILE__,__LINE__,$msg);
- $html .= TEXT_NO_DATA.'<!-- '.$this->getMsg(LOG_LEVEL_ERROR, $msg)." -->\r\n";
- } else {
- $html .= TEXT_NO_DATA.'<!-- '.$msg." -->\r\n";
- }
- }
- $elem = '';
- if ($this->getSizeof ()>0) {
- $elem .= $this->getElements();
- }
- if ($this->text!='' || $elem !='' && $this->getSizeof ()>0) {
- $html .= $this->getStart();
- }
- if ($this->text!='') {
- if ($this->name!='') {
- switch ($this->element) {
- case 'h1':
- case 'h2':
- case 'h3':
- case 'h4':
- case 'h5':
- case 'h6':
- // i.e. <h1><a name=""name>text</a></h1>
- $link = new Link($this->text,'','','','','',$this->name);
- $html .= $link->getHtml();
- break;
- default:
- // Ignore, Use standard
- $html .= htmlspecialchars(stripslashes($this->text)); // Translate html special chars
- break;
- }
- } else {
- $html .= htmlspecialchars(stripslashes($this->text)); // Translate html special chars
- }
- }
- if ($elem !='') {
- $html .= $elem;
- }
- if ($this->text!='' || $elem !='' || $this->element!='') { // Removed && $this->getSizeof ()>0
- $html .= $this->getEnd();
- }
- return $html;
- }
-
- /**
- * Display start
- * <code>
- * Usage:
- * Text::start($element,$class);
- * </code>
- * @static
- * @param String $element The html element, if any
- * @param String $class The css class name
- */
- function start($element='',$class='') {
- $html = new Text('',$element,$class);
- $html->addHtml($html->getStart());
- }
-
- /**
- * Display end
- * <code>
- * Usage:
- * Text::end($element);
- * </code>
- * @static
- * @param String $element The html element, if any
- */
- function end($element='') {
- $html = new Text('',$element);
- $html->addHtml($html->getEnd());
- }
-
- /**
- * Display html
- * <code>
- * Usage:
- * Text::display($text,$element,$class,$name);
- * </code>
- * @static
- * @param String $text The text to show
- * @param String $element The html element, if any
- * @param String $class The css class name
- * @param String $name The name/id attribute for a link identifier
- */
- function display($text='',$element='',$class='',$name='') {
- $html = new Text($text,$element,$class,$name);
- $html->addHtml();
- }
- }
- ?>