Source for file HtmlDiv.php

Documentation is available at HtmlDiv.php

  1. <?php
  2. /*
  3. * This file is part of Sylar.
  4. *
  5. * Sylar is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * Sylar is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public License
  16. * along with Sylar. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * @copyright Copyright Sylar Development Team
  19. * @license http://www.gnu.org/licenses/ GNU Public License V2.0
  20. * @see https://launchpad.net/sylar/
  21. * @see http://www.giano-solutions.com
  22. */
  23.  
  24. import('sylar.presentation.html.Html');
  25.  
  26.  
  27. /**
  28. * Html DIV
  29. *
  30. * Manage html tag <DIV>, its attributes and content
  31. *
  32. * <div id="globalheader" name="globalheader" class="header" style="width:100%;">
  33. *
  34. * @package Sylar
  35. * @version 1.0
  36. * @since 31/mar/08
  37. * @author Gianluca Giusti [brdp] <g.giusti@giano-solutions.com>
  38. * @copyright Sylar Development Team
  39. */
  40. class Sylar_HtmlDiv extends Sylar_Html{
  41. private $sId;
  42. private $sName;
  43. private $sClass;
  44. private $sStyle;
  45. private $sContent;
  46. /**
  47. * Constructor
  48. *
  49. * @param string $sId Div ID in Sylar and in HTML tag. If not setted Sylar generate it
  50. * @param string $nName Name o html tag
  51. * @param string $sClass css class for tag div
  52. * @param string $sStyle style attribute for tag Div
  53. */
  54. function __construct($sId=null, $sName=null, $sClass=null, $sStyle=null){
  55. if(is_null($sId)){
  56. $this->setId( uniqid('SylarId_', true) );
  57. }else{
  58. $this->setId( $sId );
  59. }
  60. $this->setName($sName);
  61. $this->setClass($sClass);
  62. $this->setStyle($sStyle);
  63. }
  64. function __destruct(){
  65. // nothing to do at the moment
  66. }
  67.  
  68. // Setter and Getter
  69. //__________________________________________________________________________
  70. public function setId($sId){
  71. $this->sId=$sId;
  72. }
  73. public function getId(){
  74. return $this->sId;
  75. }
  76. public function setName($sName){
  77. $this->sName=$sName;
  78. }
  79. public function getName(){
  80. return $this->sName;
  81. }
  82. public function setClass($sClass){
  83. $this->sClass=$sClass;
  84. }
  85. public function getClass(){
  86. return $this->sClass;
  87. }
  88. public function setStyle($sStyle){
  89. $this->sStyle=$sStyle;
  90. }
  91. public function getStyle(){
  92. return $this->sStyle;
  93. }
  94. public function setContent($sContent){
  95. $this->sContent=$sContent;
  96. }
  97. public function getContent(){
  98. return $this->sContent;
  99. }
  100. // Public Methods
  101. //__________________________________________________________________________
  102. /**
  103. * Append text into DIV
  104. *
  105. * @return void
  106. *
  107. * @param string $sContent Text to append
  108. * @param boolean $bNewLine
  109. */
  110. public function appendContent($sContent, $bNewLine=false){
  111. $newLine = "";
  112. if($bNewLine){ $newLine = "\n";}
  113. $this->setContent($this->getContent().$bNewLine.$sContent);
  114. }
  115. /**
  116. * return the Html source
  117. * it return html code of entire object
  118. *
  119. * @return string
  120. */
  121. public function getHtmlSource(){
  122. return $this->render();
  123. }
  124. /**
  125. * Display the page
  126. * it prints the object Html source on screen
  127. *
  128. * @return void
  129. */
  130. public function show(){
  131. echo $this->render();
  132. }
  133. // Protected Methods
  134. //__________________________________________________________________________
  135. /**
  136. * Format Html Tag DIV
  137. * It prepare the tag html <DIV> with all attributes and content.
  138. * It return a string that contains the div html code
  139. *
  140. * @return string
  141. *
  142. * @param string $sContent
  143. */
  144. protected function render($sContent=null){
  145. if(!is_null($sContent)){
  146. $this->setContent($sContent);
  147. }
  148.  
  149. $aAttributes = array( "id"=>$this->getId(),
  150. "name"=>$this->getName(),
  151. "class"=>$this->getClass(),
  152. "style"=>$this->getStyle()
  153. );
  154.  
  155. $sTag = parent::fillTagAttributes("div", $aAttributes);
  156. $sTag .= $this->getContent();
  157. $sTag .= "</div>";
  158. return $sTag;
  159. }
  160. }
  161. ?>

Documentation generated on Thu, 24 Apr 2008 16:14:15 +0200 by phpDocumentor 1.3.0RC3