| 1: | <?php |
| 2: | /** |
| 3: | * Password form element |
| 4: | * |
| 5: | * You may not change or alter any portion of this comment or credits |
| 6: | * of supporting developers from this source code or any supporting source code |
| 7: | * which is considered copyrighted (c) material of the original comment or credit authors. |
| 8: | * This program is distributed in the hope that it will be useful, |
| 9: | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10: | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 11: | * |
| 12: | * @copyright (c) 2000-2017 XOOPS Project (www.xoops.org) |
| 13: | * @license GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html) |
| 14: | * @package kernel |
| 15: | * @subpackage form |
| 16: | * @since 2.0.0 |
| 17: | * @author Kazumi Ono (AKA onokazu) http://www.myweb.ne.jp/, http://jp.xoops.org/ |
| 18: | * @author Taiwen Jiang <phppp@users.sourceforge.net> |
| 19: | */ |
| 20: | defined('XOOPS_ROOT_PATH') || exit('Restricted access'); |
| 21: | |
| 22: | /** |
| 23: | * Password Field |
| 24: | */ |
| 25: | class XoopsFormPassword extends XoopsFormElement |
| 26: | { |
| 27: | /** |
| 28: | * Size of the field. |
| 29: | * |
| 30: | * @var int |
| 31: | * @access private |
| 32: | */ |
| 33: | public $_size; |
| 34: | |
| 35: | /** |
| 36: | * Maximum length of the text |
| 37: | * |
| 38: | * @var int |
| 39: | * @access private |
| 40: | */ |
| 41: | public $_maxlength; |
| 42: | |
| 43: | /** |
| 44: | * Initial content of the field. |
| 45: | * |
| 46: | * @var string |
| 47: | * @access private |
| 48: | */ |
| 49: | public $_value; |
| 50: | |
| 51: | /** |
| 52: | * Cache password with browser. Disabled by default for security consideration |
| 53: | * Added in 2.3.1 |
| 54: | * |
| 55: | * @var boolean |
| 56: | * @access public |
| 57: | */ |
| 58: | public $autoComplete = false; |
| 59: | |
| 60: | /** |
| 61: | * Constructor |
| 62: | * |
| 63: | * @param string $caption Caption |
| 64: | * @param string $name "name" attribute |
| 65: | * @param int $size Size of the field |
| 66: | * @param int $maxlength Maximum length of the text |
| 67: | * @param string $value Initial value of the field. |
| 68: | * <strong>Warning:</strong> this is readable in cleartext in the page's source! |
| 69: | * @param bool $autoComplete To enable autoComplete or browser cache |
| 70: | */ |
| 71: | public function __construct($caption, $name, $size, $maxlength, $value = '', $autoComplete = false) |
| 72: | { |
| 73: | $this->setCaption($caption); |
| 74: | $this->setName($name); |
| 75: | $this->_size = (int)$size; |
| 76: | $this->_maxlength = (int)$maxlength; |
| 77: | $this->setValue($value); |
| 78: | $this->autoComplete = !empty($autoComplete); |
| 79: | } |
| 80: | |
| 81: | /** |
| 82: | * Get the field size |
| 83: | * |
| 84: | * @return int |
| 85: | */ |
| 86: | public function getSize() |
| 87: | { |
| 88: | return $this->_size; |
| 89: | } |
| 90: | |
| 91: | /** |
| 92: | * Get the max length |
| 93: | * |
| 94: | * @return int |
| 95: | */ |
| 96: | public function getMaxlength() |
| 97: | { |
| 98: | return $this->_maxlength; |
| 99: | } |
| 100: | |
| 101: | /** |
| 102: | * Get the "value" attribute |
| 103: | * |
| 104: | * @param bool $encode To sanitizer the text? |
| 105: | * @return string |
| 106: | */ |
| 107: | public function getValue($encode = false) |
| 108: | { |
| 109: | return $encode ? htmlspecialchars($this->_value, ENT_QUOTES) : $this->_value; |
| 110: | } |
| 111: | |
| 112: | /** |
| 113: | * Set the initial value |
| 114: | * |
| 115: | * @patam $value string |
| 116: | * @param $value |
| 117: | */ |
| 118: | public function setValue($value) |
| 119: | { |
| 120: | $this->_value = $value; |
| 121: | } |
| 122: | |
| 123: | /** |
| 124: | * Prepare HTML for output |
| 125: | * |
| 126: | * @return string HTML |
| 127: | */ |
| 128: | public function render() |
| 129: | { |
| 130: | return XoopsFormRenderer::getInstance()->get()->renderFormPassword($this); |
| 131: | } |
| 132: | } |
| 133: |