avatar.php
2 days ago
boolean.php
2 days ago
code.php
2 days ago
color.php
2 days ago
comment.php
2 days ago
currency.php
2 days ago
date.php
2 days ago
datetime.php
2 days ago
email.php
2 days ago
file.php
2 days ago
heading.php
2 days ago
html.php
2 days ago
link.php
2 days ago
number.php
2 days ago
oembed.php
2 days ago
paragraph.php
2 days ago
password.php
2 days ago
phone.php
2 days ago
pick.php
2 days ago
slug.php
2 days ago
taxonomy.php
2 days ago
text.php
2 days ago
time.php
2 days ago
website.php
2 days ago
wysiwyg.php
2 days ago
password.php
166 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @package Pods\Fields |
| 5 | */ |
| 6 | class PodsField_Password extends PodsField { |
| 7 | |
| 8 | /** |
| 9 | * {@inheritdoc} |
| 10 | */ |
| 11 | public static $group = 'Text'; |
| 12 | |
| 13 | /** |
| 14 | * {@inheritdoc} |
| 15 | */ |
| 16 | public static $type = 'password'; |
| 17 | |
| 18 | /** |
| 19 | * {@inheritdoc} |
| 20 | */ |
| 21 | public static $label = 'Password'; |
| 22 | |
| 23 | /** |
| 24 | * {@inheritdoc} |
| 25 | */ |
| 26 | public static $prepare = '%s'; |
| 27 | |
| 28 | /** |
| 29 | * {@inheritdoc} |
| 30 | */ |
| 31 | public function setup() { |
| 32 | |
| 33 | static::$group = __( 'Text', 'pods' ); |
| 34 | static::$label = __( 'Password', 'pods' ); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * {@inheritdoc} |
| 39 | */ |
| 40 | public function options() { |
| 41 | $options = [ |
| 42 | static::$type . '_repeatable' => [ |
| 43 | 'label' => __( 'Repeatable Field', 'pods' ), |
| 44 | 'default' => 0, |
| 45 | 'type' => 'boolean', |
| 46 | 'help' => __( 'Making a field repeatable will add controls next to the field which allows users to Add/Remove/Reorder additional values. These values are saved in the database as an array, so searching and filtering by them may require further adjustments".', 'pods' ), |
| 47 | 'boolean_yes_label' => '', |
| 48 | 'dependency' => true, |
| 49 | 'developer_mode' => true, |
| 50 | ], |
| 51 | static::$type . '_max_length' => [ |
| 52 | 'label' => __( 'Maximum Length', 'pods' ), |
| 53 | 'default' => 255, |
| 54 | 'type' => 'number', |
| 55 | 'help' => __( 'Set to -1 for no limit', 'pods' ), |
| 56 | ], |
| 57 | static::$type . '_placeholder' => [ |
| 58 | 'label' => __( 'HTML Placeholder', 'pods' ), |
| 59 | 'default' => '', |
| 60 | 'type' => 'text', |
| 61 | 'help' => [ |
| 62 | __( 'Placeholders can provide instructions or an example of the required data format for a field. Please note: It is not a replacement for labels or description text, and it is less accessible for people using screen readers.', 'pods' ), |
| 63 | 'https://www.w3.org/WAI/tutorials/forms/instructions/#placeholder-text', |
| 64 | ], |
| 65 | ], |
| 66 | ]; |
| 67 | |
| 68 | return $options; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * {@inheritdoc} |
| 73 | */ |
| 74 | public function schema( $options = null ) { |
| 75 | |
| 76 | $length = (int) pods_v( static::$type . '_max_length', $options, 255 ); |
| 77 | |
| 78 | $schema = 'VARCHAR(' . $length . ')'; |
| 79 | |
| 80 | if ( 255 < $length || $length < 1 ) { |
| 81 | $schema = 'LONGTEXT'; |
| 82 | } |
| 83 | |
| 84 | return $schema; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * {@inheritdoc} |
| 89 | */ |
| 90 | public function input( $name, $value = null, $options = null, $pod = null, $id = null ) { |
| 91 | |
| 92 | $options = ( is_array( $options ) || is_object( $options ) ) ? $options : (array) $options; |
| 93 | $form_field_type = PodsForm::$field_type; |
| 94 | |
| 95 | if ( is_array( $value ) ) { |
| 96 | $value = implode( ' ', $value ); |
| 97 | } |
| 98 | |
| 99 | if ( isset( $options['name'] ) && ! pods_permission( $options ) ) { |
| 100 | if ( pods_v( 'read_only', $options, false ) ) { |
| 101 | $options['readonly'] = true; |
| 102 | } else { |
| 103 | return; |
| 104 | } |
| 105 | } elseif ( ! pods_has_permissions( $options ) && pods_v( 'read_only', $options, false ) ) { |
| 106 | $options['readonly'] = true; |
| 107 | } |
| 108 | |
| 109 | if ( ! empty( $options['disable_dfv'] ) ) { |
| 110 | return pods_view( PODS_DIR . 'ui/fields/password.php', compact( array_keys( get_defined_vars() ) ) ); |
| 111 | } |
| 112 | |
| 113 | $type = pods_v( 'type', $options, static::$type ); |
| 114 | |
| 115 | $args = compact( array_keys( get_defined_vars() ) ); |
| 116 | $args = (object) $args; |
| 117 | |
| 118 | $this->render_input_script( $args ); |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * {@inheritdoc} |
| 123 | */ |
| 124 | public function validate( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) { |
| 125 | $validate = parent::validate( $value, $name, $options, $fields, $pod, $id, $params ); |
| 126 | |
| 127 | $errors = array(); |
| 128 | |
| 129 | if ( is_array( $validate ) ) { |
| 130 | $errors = $validate; |
| 131 | } |
| 132 | |
| 133 | $check = $this->pre_save( $value, $id, $name, $options, $fields, $pod, $params ); |
| 134 | |
| 135 | if ( is_array( $check ) ) { |
| 136 | $errors = $check; |
| 137 | } else { |
| 138 | if ( 0 < strlen( $value ) && '' === $check ) { |
| 139 | if ( $this->is_required( $options ) ) { |
| 140 | $errors[] = __( 'This field is required.', 'pods' ); |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | if ( ! empty( $errors ) ) { |
| 146 | return $errors; |
| 147 | } |
| 148 | |
| 149 | return $validate; |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * {@inheritdoc} |
| 154 | */ |
| 155 | public function pre_save( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) { |
| 156 | |
| 157 | $length = (int) pods_v( static::$type . '_max_length', $options, 255 ); |
| 158 | |
| 159 | if ( 0 < $length && $length < pods_mb_strlen( $value ) ) { |
| 160 | $value = pods_mb_substr( $value, 0, $length ); |
| 161 | } |
| 162 | |
| 163 | return $value; |
| 164 | } |
| 165 | } |
| 166 |