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
paragraph.php
277 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @package Pods\Fields |
| 5 | */ |
| 6 | class PodsField_Paragraph extends PodsField { |
| 7 | |
| 8 | /** |
| 9 | * {@inheritdoc} |
| 10 | */ |
| 11 | public static $group = 'Paragraph'; |
| 12 | |
| 13 | |
| 14 | /** |
| 15 | * {@inheritdoc} |
| 16 | */ |
| 17 | public static $type = 'paragraph'; |
| 18 | |
| 19 | |
| 20 | /** |
| 21 | * {@inheritdoc} |
| 22 | */ |
| 23 | public static $label = 'Plain Paragraph Text'; |
| 24 | |
| 25 | |
| 26 | /** |
| 27 | * {@inheritdoc} |
| 28 | */ |
| 29 | public static $prepare = '%s'; |
| 30 | |
| 31 | |
| 32 | /** |
| 33 | * {@inheritdoc} |
| 34 | */ |
| 35 | public function setup() { |
| 36 | |
| 37 | static::$group = __( 'Paragraph', 'pods' ); |
| 38 | static::$label = __( 'Plain Paragraph Text', 'pods' ); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * {@inheritdoc} |
| 43 | */ |
| 44 | public function options() { |
| 45 | $options = [ |
| 46 | 'output_options' => [ |
| 47 | 'label' => __( 'Output Options', 'pods' ), |
| 48 | 'type' => 'boolean_group', |
| 49 | 'boolean_group' => [ |
| 50 | static::$type . '_trim' => [ |
| 51 | 'label' => __( 'Trim extra whitespace before/after contents', 'pods' ), |
| 52 | 'default' => 1, |
| 53 | 'type' => 'boolean', |
| 54 | ], |
| 55 | static::$type . '_trim_lines' => [ |
| 56 | 'label' => __( 'Trim whitespace at the end of lines', 'pods' ), |
| 57 | 'default' => 0, |
| 58 | 'type' => 'boolean', |
| 59 | ], |
| 60 | static::$type . '_trim_p_brs' => [ |
| 61 | 'label' => __( 'Remove blank lines including empty "p" tags and "br" tags', 'pods' ), |
| 62 | 'default' => 0, |
| 63 | 'type' => 'boolean', |
| 64 | ], |
| 65 | static::$type . '_trim_extra_lines' => [ |
| 66 | 'label' => __( 'Remove extra blank lines (when there are 3+ blank lines, replace with a maximum of 2)', 'pods' ), |
| 67 | 'default' => 0, |
| 68 | 'type' => 'boolean', |
| 69 | ], |
| 70 | static::$type . '_allow_html' => [ |
| 71 | 'label' => __( 'Allow HTML', 'pods' ), |
| 72 | 'default' => 1, |
| 73 | 'type' => 'boolean', |
| 74 | 'dependency' => true, |
| 75 | ], |
| 76 | static::$type . '_oembed' => [ |
| 77 | 'label' => __( 'Enable oEmbed', 'pods' ), |
| 78 | 'default' => 0, |
| 79 | 'type' => 'boolean', |
| 80 | 'help' => [ |
| 81 | __( 'Embed videos, images, tweets, and other content.', 'pods' ), |
| 82 | 'https://wordpress.org/support/article/embeds/', |
| 83 | ], |
| 84 | ], |
| 85 | static::$type . '_wptexturize' => [ |
| 86 | 'label' => __( 'Enable wptexturize', 'pods' ), |
| 87 | 'default' => 1, |
| 88 | 'type' => 'boolean', |
| 89 | 'help' => [ |
| 90 | __( 'Transforms less-beautiful text characters into stylized equivalents.', 'pods' ), |
| 91 | 'https://developer.wordpress.org/reference/functions/wptexturize/', |
| 92 | ], |
| 93 | ], |
| 94 | static::$type . '_convert_chars' => [ |
| 95 | 'label' => __( 'Enable convert_chars', 'pods' ), |
| 96 | 'default' => 1, |
| 97 | 'type' => 'boolean', |
| 98 | 'help' => [ |
| 99 | __( 'Converts text into valid XHTML and Unicode', 'pods' ), |
| 100 | 'https://developer.wordpress.org/reference/functions/convert_chars/', |
| 101 | ], |
| 102 | ], |
| 103 | static::$type . '_wpautop' => [ |
| 104 | 'label' => __( 'Enable wpautop', 'pods' ), |
| 105 | 'default' => 1, |
| 106 | 'type' => 'boolean', |
| 107 | 'help' => [ |
| 108 | __( 'Changes double line-breaks in the text into HTML paragraphs', 'pods' ), |
| 109 | 'https://developer.wordpress.org/reference/functions/wpautop/', |
| 110 | ], |
| 111 | ], |
| 112 | static::$type . '_allow_shortcode' => [ |
| 113 | 'label' => __( 'Allow Shortcodes', 'pods' ), |
| 114 | 'default' => 0, |
| 115 | 'type' => 'boolean', |
| 116 | 'dependency' => true, |
| 117 | 'help' => [ |
| 118 | __( 'Embed [shortcodes] that help transform your static content into dynamic content.', 'pods' ), |
| 119 | 'https://codex.wordpress.org/Shortcode_API', |
| 120 | ], |
| 121 | ], |
| 122 | ], |
| 123 | ], |
| 124 | static::$type . '_allowed_html_tags' => [ |
| 125 | 'label' => __( 'Allowed HTML Tags', 'pods' ), |
| 126 | 'depends-on' => [ static::$type . '_allow_html' => true ], |
| 127 | 'default' => 'strong em a ul ol li b i', |
| 128 | 'type' => 'text', |
| 129 | 'help' => __( 'Format: strong em a ul ol li b i', 'pods' ), |
| 130 | ], |
| 131 | static::$type . '_max_length' => [ |
| 132 | 'label' => __( 'Maximum Length', 'pods' ), |
| 133 | 'default' => - 1, |
| 134 | 'type' => 'number', |
| 135 | 'help' => __( 'Set to -1 for no limit', 'pods' ), |
| 136 | ], |
| 137 | static::$type . '_placeholder' => [ |
| 138 | 'label' => __( 'HTML Placeholder', 'pods' ), |
| 139 | 'default' => '', |
| 140 | 'type' => 'text', |
| 141 | 'help' => [ |
| 142 | __( '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' ), |
| 143 | 'https://www.w3.org/WAI/tutorials/forms/instructions/#placeholder-text', |
| 144 | ], |
| 145 | ], |
| 146 | ]; |
| 147 | |
| 148 | if ( function_exists( 'Markdown' ) ) { |
| 149 | $options['output_options']['boolean_group'][ static::$type . '_allow_markdown' ] = [ |
| 150 | 'label' => __( 'Allow Markdown Syntax', 'pods' ), |
| 151 | 'default' => 0, |
| 152 | 'type' => 'boolean', |
| 153 | ]; |
| 154 | } |
| 155 | |
| 156 | return $options; |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * {@inheritdoc} |
| 161 | */ |
| 162 | public function schema( $options = null ) { |
| 163 | |
| 164 | $length = (int) pods_v( static::$type . '_max_length', $options, 0 ); |
| 165 | |
| 166 | $schema = 'LONGTEXT'; |
| 167 | |
| 168 | if ( 0 < $length ) { |
| 169 | $schema = 'VARCHAR(' . $length . ')'; |
| 170 | } |
| 171 | |
| 172 | return $schema; |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * {@inheritdoc} |
| 177 | */ |
| 178 | public function display( $value = null, $name = null, $options = null, $pod = null, $id = null ) { |
| 179 | $value = $this->strip_html( $value, $options ); |
| 180 | $value = $this->strip_shortcodes( $value, $options ); |
| 181 | $value = $this->trim_whitespace( $value, $options ); |
| 182 | |
| 183 | if ( 1 === (int) pods_v( static::$type . '_oembed', $options, 0 ) ) { |
| 184 | $embed = $GLOBALS['wp_embed']; |
| 185 | $value = $embed->run_shortcode( $value ); |
| 186 | $value = $embed->autoembed( $value ); |
| 187 | } |
| 188 | |
| 189 | if ( 1 === (int) pods_v( static::$type . '_wptexturize', $options, 1 ) ) { |
| 190 | $value = wptexturize( $value ); |
| 191 | } |
| 192 | |
| 193 | if ( 1 === (int) pods_v( static::$type . '_convert_chars', $options, 1 ) ) { |
| 194 | $value = convert_chars( $value ); |
| 195 | } |
| 196 | |
| 197 | if ( 1 === (int) pods_v( static::$type . '_wpautop', $options, 1 ) ) { |
| 198 | $value = wpautop( $value ); |
| 199 | } |
| 200 | |
| 201 | if ( 1 === (int) pods_v( static::$type . '_allow_shortcode', $options, 0 ) ) { |
| 202 | if ( 1 === (int) pods_v( static::$type . '_wpautop', $options, 1 ) ) { |
| 203 | $value = shortcode_unautop( $value ); |
| 204 | } |
| 205 | |
| 206 | $value = do_shortcode( $value ); |
| 207 | } |
| 208 | |
| 209 | if ( function_exists( 'Markdown' ) && 1 === (int) pods_v( static::$type . '_allow_markdown', $options ) ) { |
| 210 | $value = Markdown( $value ); |
| 211 | } |
| 212 | |
| 213 | return $value; |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * {@inheritdoc} |
| 218 | */ |
| 219 | public function input( $name, $value = null, $options = null, $pod = null, $id = null ) { |
| 220 | |
| 221 | $options = ( is_array( $options ) || is_object( $options ) ) ? $options : (array) $options; |
| 222 | $form_field_type = PodsForm::$field_type; |
| 223 | |
| 224 | $value = $this->normalize_value_for_input( $value, $options, "\n" ); |
| 225 | |
| 226 | if ( isset( $options['name'] ) && ! pods_permission( $options ) ) { |
| 227 | if ( pods_v( 'read_only', $options, false ) ) { |
| 228 | $options['readonly'] = true; |
| 229 | } else { |
| 230 | return; |
| 231 | } |
| 232 | } elseif ( ! pods_has_permissions( $options ) && pods_v( 'read_only', $options, false ) ) { |
| 233 | $options['readonly'] = true; |
| 234 | } |
| 235 | |
| 236 | if ( ! empty( $options['disable_dfv'] ) ) { |
| 237 | return pods_view( PODS_DIR . 'ui/fields/textarea.php', compact( array_keys( get_defined_vars() ) ) ); |
| 238 | } |
| 239 | |
| 240 | $type = pods_v( 'type', $options, static::$type ); |
| 241 | |
| 242 | $args = compact( array_keys( get_defined_vars() ) ); |
| 243 | $args = (object) $args; |
| 244 | |
| 245 | $this->render_input_script( $args ); |
| 246 | |
| 247 | } |
| 248 | |
| 249 | /** |
| 250 | * {@inheritdoc} |
| 251 | */ |
| 252 | public function pre_save( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) { |
| 253 | $value = $this->strip_html( $value, $options ); |
| 254 | $value = $this->strip_shortcodes( $value, $options ); |
| 255 | $value = $this->trim_whitespace( $value, $options ); |
| 256 | |
| 257 | $length = (int) pods_v( static::$type . '_max_length', $options, 0 ); |
| 258 | |
| 259 | if ( 0 < $length && $length < pods_mb_strlen( $value ) ) { |
| 260 | $value = pods_mb_substr( $value, 0, $length ); |
| 261 | } |
| 262 | |
| 263 | return $value; |
| 264 | } |
| 265 | |
| 266 | /** |
| 267 | * {@inheritdoc} |
| 268 | */ |
| 269 | public function ui( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) { |
| 270 | $value = $this->strip_html( $value, $options ); |
| 271 | $value = $this->strip_shortcodes( $value, $options ); |
| 272 | $value = $this->trim_whitespace( $value, $options ); |
| 273 | |
| 274 | return wp_trim_words( $value ); |
| 275 | } |
| 276 | } |
| 277 |