ImageElement.class.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * Image button element for use on forms.
  4. *
  5. * @author Ironpilot
  6. * @copyright Copywrite (c) 2011, STAPLE CODE
  7. *
  8. * This file is part of the STAPLE Framework.
  9. *
  10. * The STAPLE Framework is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Lesser General Public License as published by the
  12. * Free Software Foundation, either version 3 of the License, or (at your option)
  13. * any later version.
  14. *
  15. * The STAPLE Framework is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  17. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
  18. * more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public License
  21. * along with the STAPLE Framework. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. class Staple_Form_ImageElement extends Staple_Form_Element
  24. {
  25. protected $src;
  26. public function setSrc($insert)
  27. {
  28. $this->Image = $insert;
  29. return $this;
  30. }
  31. public function getSrc()
  32. {
  33. return $this->Image;
  34. }
  35. /* (non-PHPdoc)
  36. * @see Staple_Form_Element::field()
  37. */
  38. public function field()
  39. {
  40. return ' <input type="image" src="'.$this->link($this->src).'" id="'.$this->escape($this->id).'" name="'.$this->escape($this->name).'" value="'.$this->escape($this->value).'">';
  41. }
  42. /* (non-PHPdoc)
  43. * @see Staple_Form_Element::label()
  44. */
  45. public function label()
  46. {
  47. return ' <label for="'.$this->escape($this->id).'"'.$this->getClassString().'>'.$this->label.'</label>';
  48. }
  49. public function build()
  50. {
  51. $buf = '';
  52. $view = FORMS_ROOT.'/fields/ImageElement.phtml';
  53. if(file_exists($view))
  54. {
  55. ob_start();
  56. include $view;
  57. $buf = ob_get_contents();
  58. ob_end_clean();
  59. }
  60. else
  61. {
  62. $this->addClass('form_element');
  63. $this->addClass('element_image');
  64. $classes = $this->getClassString();
  65. $buf .= "<div$classes id=\"".$this->escape($this->id)."_element\">\n";
  66. if(isset($this->label))
  67. {
  68. $buf .= $this->label();
  69. }
  70. $buf .= $this->field();
  71. $buf .= '</div>';
  72. }
  73. return $buf;
  74. }
  75. }