FileElement.class.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * Creates a file field to be added to the form. Class is incomplete.
  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_FileElement extends Staple_Form_Element
  24. {
  25. /**
  26. * Holds the MIME for the HTML Accept property
  27. * @var string
  28. */
  29. protected $accept;
  30. /**
  31. * @return the $accept
  32. */
  33. public function getAccept()
  34. {
  35. return $this->accept;
  36. }
  37. /**
  38. * @param string $accept
  39. * @return Staple_Form_FileElement
  40. */
  41. public function setAccept($accept)
  42. {
  43. $this->accept = $accept;
  44. return $this;
  45. }
  46. /**
  47. *
  48. * @see Staple_Form_Element::field()
  49. */
  50. public function field()
  51. {
  52. $accept = '';
  53. if(isset($this->accept))
  54. {
  55. $accept = ' accept="'.htmlentities($this->accept).'"';
  56. }
  57. return ' <input type="file" id="'.$this->escape($this->id).'" name="'.$this->escape($this->name).'" value=""'.$accept.$this->getAttribString().'>'."\n";
  58. }
  59. /**
  60. *
  61. * @see Staple_Form_Element::label()
  62. */
  63. public function label()
  64. {
  65. return ' <label for="'.$this->escape($this->id).'"'.$this->getClassString().'>'.$this->label."</label>\n";
  66. }
  67. /**
  68. *
  69. * @see Staple_Form_Element::build()
  70. */
  71. public function build()
  72. {
  73. $buf = '';
  74. $view = FORMS_ROOT.'/fields/FileElement.phtml';
  75. if(file_exists($view))
  76. {
  77. ob_start();
  78. include $view;
  79. $buf = ob_get_contents();
  80. ob_end_clean();
  81. }
  82. else
  83. {
  84. $this->addClass('form_element');
  85. $this->addClass('element_file');
  86. $classes = $this->getClassString();
  87. $buf .= "<div$classes id=\"".$this->escape($this->id)."_element\">\n";
  88. $buf .= $this->label();
  89. $buf .= $this->field();
  90. $buf .= $this->instructions();
  91. $buf .= "</div>\n";
  92. }
  93. return $buf;
  94. }
  95. }
  96. ?>