- <?
- /**
- * @package page
- * @filesource
- * @see HTML_PAGE_UTIL_PATH.'/Paragraph.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');
- require_once(HTML_PAGE_UTIL_PATH.'/Text.php');
-
- /**
- * Generates a plain Paragraph object, surronded by a the '<p>' html element
- * <code>
- * Usage:
- * $text = new Paragraph($text,$class);
- * print $text->getHtml();
- * Or
- * Paragraph::display($text,$class);
- * </code>
- * @package page
- */
-
- class Paragraph extends Html {
- /**
- * @var String $text The paragraph text
- */
- var $text = '';
-
- /**
- * @var String $class The css class name
- */
- var $class = '';
-
- /**
- * Constructor
- * @param String $text The paragraph text
- * @param String $class The CSS class name
- */
- function Paragraph($text='',$class='') {
- $this->Html();
- if ($text!='') {
- $this->addText($text);
- }
- $this->class = $class;
- }
- /**
- * Add a paragraph element
- * @param $object Plain Text or a paragraph object
- */
- function addText($object) {
- if (is_object($object)) {
- $textobject = new Text('',''); // Dummy text object
- $textobject->add($object); // Add link object to text object
- $this->add($textobject); // Add text object to this
- } else {
- $this->add(new Text($object,'')); // Add text surronded by <p></p> tags
- }
- }
-
- /**
- * Returns the html for a paragraph
- * including the html for the added <p></p> elements
- * @return String the complete html
- */
- function getHtml() {
- $html = $this->html;
- if ($this->text!='') {
- $html .='<p';
- $html .= $this->getAttribute('class');
- $html .= '>'.htmlspecialchars(stripslashes($this->text))."</p>\r\n"; // Translate html special chars
- }
- if ($this->getSizeof()>0) {
- $html .= '<p';
- $html .= $this->getAttribute('class').'>';
- $html .= $this->getElements(); // as html
- $html .= "</p>\r\n";
- }
- if ($this->text=='' && $this->getSizeof()==0) {
- $html .= "<!-- Paragraph->getHtml(), no paragraph elements or text found -->\r\n";
- }
- return $html;
- }
-
- /**
- * Display html
- * <code>
- * Usage:
- * Paragraph::display($text,$class);
- * </code>
- * @static
- * @param String $text The paragraph text
- * @param String $class The CSS class name
- */
- function display($text='',$class='') {
- $html = new Paragraph($text,$class);
- $html->addHtml();
- }
- }
- ?>