Source for file Html.php

Documentation is available at Html.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.Format');
  25.  
  26.  
  27. /**
  28. * Main Html Format Class
  29. *
  30. * This class is extended from various Html Sylar Classes and collect
  31. * common method uses to formato HTML source
  32. *
  33. * @package Sylar
  34. * @version 1.0
  35. * @since 03/apr/08
  36. * @author Gianluca Giusti [brdp] <g.giusti@giano-solutions.com>
  37. * @copyright Sylar Development Team
  38. */
  39. class Sylar_Html extends Sylar_Format{
  40. function __construct(){
  41. // nothing to do at the moment
  42. }
  43. function __destruct(){
  44. // nothing to do at the moment
  45. }
  46. // Public Methods
  47. /**
  48. * Fill Html Attributes in Tag
  49. * It generate the HTML tag $sTagStart with all attributes secified in the array $aAttributes
  50. * The array is formatted like Key=>Value, Key is the attribute name and Value is the value of attribute.
  51. * It ignores all null data contained in the attributes array.
  52. *
  53. * For example:
  54. * $sTagStart = "div";
  55. * $aAttributes = array("id"=>"My_ID", "class"=>"My_CSS_Class");
  56. *
  57. * calling the method:
  58. * fillTagAttributes($sTagStart, $aAttributes)
  59. * it returns a string thath contain: <div id="My_ID" class="My_CSS_Class">
  60. *
  61. * @return string
  62. * @param string $sTagStart The begin of the tag for example: <script or <div
  63. * @param array $aAttributes An array Key=>Value to insert as attributes in the Tag.
  64. */
  65. public static function fillTagAttributes($sTagStart, $aAttributes){
  66. if(is_null($sTagStart) || strlen(str_replace(" ", "",$sTagStart))==0){
  67. throw new ExceptionInSylar("HTML TAG is not declared. [Sylar_Html::fillTagAttributes]");
  68. return null;
  69. }
  70. $sTagStart = "<".$sTagStart;
  71. if(!is_null($aAttributes) && is_array($aAttributes)){
  72. foreach ($aAttributes as $k => $v) {
  73. if(!is_null($v)){
  74. $sTagStart .= " ".$k."=\"".$v."\"";
  75. }
  76. }
  77. }
  78. $sTagStart .= ">";
  79. return $sTagStart;
  80. }
  81. }
  82.  
  83.  
  84. ?>

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