/lib/OA/Admin/UI/component/decorator/HTMLTagDecorator.php

https://github.com/orchestra-io/sample-openx · PHP · 102 lines · 39 code · 16 blank · 47 comment · 8 complexity · 5698642ae0a666e6acced1f460531453 MD5 · raw file

  1. <?php
  2. /*
  3. +---------------------------------------------------------------------------+
  4. | OpenX v${RELEASE_MAJOR_MINOR} |
  5. | =======${RELEASE_MAJOR_MINOR_DOUBLE_UNDERLINE} |
  6. | |
  7. | Copyright (c) 2003-2009 OpenX Limited |
  8. | For contact details, see: http://www.openx.org/ |
  9. | |
  10. | This program is free software; you can redistribute it and/or modify |
  11. | it under the terms of the GNU General Public License as published by |
  12. | the Free Software Foundation; either version 2 of the License, or |
  13. | (at your option) any later version. |
  14. | |
  15. | This program is distributed in the hope that it will be useful, |
  16. | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  17. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  18. | GNU General Public License for more details. |
  19. | |
  20. | You should have received a copy of the GNU General Public License |
  21. | along with this program; if not, write to the Free Software |
  22. | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
  23. +---------------------------------------------------------------------------+
  24. $Id: HTMLTagDecorator.php 30820 2009-01-13 19:02:17Z andrew.hill $
  25. */
  26. require_once MAX_PATH.'/lib/OA/Admin/UI/component/decorator/AbstractDecorator.php';
  27. class OA_Admin_UI_HTMLTagDecorator
  28. extends OA_Admin_UI_AbstractDecorator
  29. {
  30. /**
  31. * HTML tag name
  32. * @var string
  33. */
  34. private $_tagName;
  35. /**
  36. * Attributes array for HTML tag
  37. *
  38. * @var array
  39. */
  40. private $_aAttributes;
  41. public function __construct($aParameters)
  42. {
  43. parent::__construct($aParameters);
  44. $this->_tagName = $aParameters['tag'] ? $aParameters['tag'] : 'span';
  45. $this->_aAttributes = $aParameters['attributes'] ? $aParameters['attributes'] :
  46. array();
  47. }
  48. /**
  49. *
  50. * @return text that should be prepended to element when rendered, empty string if none
  51. * or decorator mode is set to append mode only.
  52. * @see OA_Admin_UI_Decorator::prepend()
  53. */
  54. public function prepend()
  55. {
  56. $prepend = '';
  57. $renderMode = $this->getRenderMode();
  58. //only prepend if in applicable mode
  59. if ($renderMode == 'wrap' || $renderMode == 'prepend') {
  60. $prepend = "<".$this->_tagName;
  61. foreach ($this->_aAttributes as $name => $value) {
  62. $value = addslashes($value);
  63. $prepend .=' '.$name.'="'.$value.'"';
  64. }
  65. $prepend .= ">";
  66. }
  67. return $prepend;
  68. }
  69. /**
  70. *
  71. * @return text that should be appended to element when rendered, empty string if none
  72. * or decorator mode is set to prepend mode only.
  73. * @see OA_Admin_UI_Decorator::append()
  74. */
  75. public function append()
  76. {
  77. $append = '';
  78. $renderMode = $this->getRenderMode();
  79. //only append if in applicable mode
  80. if ($renderMode == 'wrap' || $renderMode == 'append') {
  81. $append = "</".$this->_tagName.">";
  82. }
  83. return $append;
  84. }
  85. }
  86. ?>