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

Source for file Paragraph.php

Documentation is available at Paragraph.php

  1. <?
  2. /**
  3. * @package page
  4. * @filesource
  5. * @see HTML_PAGE_UTIL_PATH.'/Paragraph.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. require_once(HTML_PAGE_UTIL_PATH.'/Text.php');
  18.  
  19. /**
  20. * Generates a plain Paragraph object, surronded by a the '<p>' html element
  21. * <code>
  22. * Usage:
  23. * $text = new Paragraph($text,$class);
  24. * print $text->getHtml();
  25. * Or
  26. * Paragraph::display($text,$class);
  27. * </code>
  28. * @package page
  29. */
  30.  
  31. class Paragraph extends Html {
  32. /**
  33. * @var String $text The paragraph text
  34. */
  35. var $text = '';
  36.  
  37. /**
  38. * @var String $class The css class name
  39. */
  40. var $class = '';
  41.  
  42. /**
  43. * Constructor
  44. * @param String $text The paragraph text
  45. * @param String $class The CSS class name
  46. */
  47. function Paragraph($text='',$class='') {
  48. $this->Html();
  49. if ($text!='') {
  50. $this->addText($text);
  51. }
  52. $this->class = $class;
  53. }
  54. /**
  55. * Add a paragraph element
  56. * @param $object Plain Text or a paragraph object
  57. */
  58. function addText($object) {
  59. if (is_object($object)) {
  60. $textobject = new Text('',''); // Dummy text object
  61. $textobject->add($object); // Add link object to text object
  62. $this->add($textobject); // Add text object to this
  63. } else {
  64. $this->add(new Text($object,'')); // Add text surronded by <p></p> tags
  65. }
  66. }
  67.  
  68. /**
  69. * Returns the html for a paragraph
  70. * including the html for the added <p></p> elements
  71. * @return String the complete html
  72. */
  73. function getHtml() {
  74. $html = $this->html;
  75. if ($this->text!='') {
  76. $html .='<p';
  77. $html .= $this->getAttribute('class');
  78. $html .= '>'.htmlspecialchars(stripslashes($this->text))."</p>\r\n"; // Translate html special chars
  79. }
  80. if ($this->getSizeof()>0) {
  81. $html .= '<p';
  82. $html .= $this->getAttribute('class').'>';
  83. $html .= $this->getElements(); // as html
  84. $html .= "</p>\r\n";
  85. }
  86. if ($this->text=='' && $this->getSizeof()==0) {
  87. $html .= "<!-- Paragraph->getHtml(), no paragraph elements or text found -->\r\n";
  88. }
  89. return $html;
  90. }
  91.  
  92. /**
  93. * Display html
  94. * <code>
  95. * Usage:
  96. * Paragraph::display($text,$class);
  97. * </code>
  98. * @static
  99. * @param String $text The paragraph text
  100. * @param String $class The CSS class name
  101. */
  102. function display($text='',$class='') {
  103. $html = new Paragraph($text,$class);
  104. $html->addHtml();
  105. }
  106. }
  107. ?>

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