|
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 __construct() { |
|
36
|
|
|
|
|
37
|
|
|
self::$label = __( 'Plain Paragraph Text', 'pods' ); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* {@inheritdoc} |
|
42
|
|
|
*/ |
|
43
|
|
|
public function options() { |
|
44
|
|
|
|
|
45
|
|
|
$options = array( |
|
46
|
|
|
static::$type . '_repeatable' => array( |
|
47
|
|
|
'label' => __( 'Repeatable Field', 'pods' ), |
|
48
|
|
|
'default' => 0, |
|
49
|
|
|
'type' => 'boolean', |
|
50
|
|
|
'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' ), |
|
51
|
|
|
'boolean_yes_label' => '', |
|
52
|
|
|
'dependency' => true, |
|
53
|
|
|
'developer_mode' => true, |
|
54
|
|
|
), |
|
55
|
|
|
'output_options' => array( |
|
56
|
|
|
'label' => __( 'Output Options', 'pods' ), |
|
57
|
|
|
'group' => array( |
|
58
|
|
|
static::$type . '_allow_html' => array( |
|
59
|
|
|
'label' => __( 'Allow HTML?', 'pods' ), |
|
60
|
|
|
'default' => 1, |
|
61
|
|
|
'type' => 'boolean', |
|
62
|
|
|
'dependency' => true, |
|
63
|
|
|
), |
|
64
|
|
|
static::$type . '_oembed' => array( |
|
65
|
|
|
'label' => __( 'Enable oEmbed?', 'pods' ), |
|
66
|
|
|
'default' => 0, |
|
67
|
|
|
'type' => 'boolean', |
|
68
|
|
|
'help' => array( |
|
69
|
|
|
__( 'Embed videos, images, tweets, and other content.', 'pods' ), |
|
70
|
|
|
'http://codex.wordpress.org/Embeds', |
|
71
|
|
|
), |
|
72
|
|
|
), |
|
73
|
|
|
static::$type . '_wptexturize' => array( |
|
74
|
|
|
'label' => __( 'Enable wptexturize?', 'pods' ), |
|
75
|
|
|
'default' => 1, |
|
76
|
|
|
'type' => 'boolean', |
|
77
|
|
|
'help' => array( |
|
78
|
|
|
__( 'Transforms less-beautfiul text characters into stylized equivalents.', 'pods' ), |
|
79
|
|
|
'http://codex.wordpress.org/Function_Reference/wptexturize', |
|
80
|
|
|
), |
|
81
|
|
|
), |
|
82
|
|
|
static::$type . '_convert_chars' => array( |
|
83
|
|
|
'label' => __( 'Enable convert_chars?', 'pods' ), |
|
84
|
|
|
'default' => 1, |
|
85
|
|
|
'type' => 'boolean', |
|
86
|
|
|
'help' => array( |
|
87
|
|
|
__( 'Converts text into valid XHTML and Unicode', 'pods' ), |
|
88
|
|
|
'http://codex.wordpress.org/Function_Reference/convert_chars', |
|
89
|
|
|
), |
|
90
|
|
|
), |
|
91
|
|
|
static::$type . '_wpautop' => array( |
|
92
|
|
|
'label' => __( 'Enable wpautop?', 'pods' ), |
|
93
|
|
|
'default' => 1, |
|
94
|
|
|
'type' => 'boolean', |
|
95
|
|
|
'help' => array( |
|
96
|
|
|
__( 'Changes double line-breaks in the text into HTML paragraphs', 'pods' ), |
|
97
|
|
|
'http://codex.wordpress.org/Function_Reference/wpautop', |
|
98
|
|
|
), |
|
99
|
|
|
), |
|
100
|
|
|
static::$type . '_allow_shortcode' => array( |
|
101
|
|
|
'label' => __( 'Allow Shortcodes?', 'pods' ), |
|
102
|
|
|
'default' => 0, |
|
103
|
|
|
'type' => 'boolean', |
|
104
|
|
|
'dependency' => true, |
|
105
|
|
|
'help' => array( |
|
106
|
|
|
__( 'Embed [shortcodes] that help transform your static content into dynamic content.', 'pods' ), |
|
107
|
|
|
'http://codex.wordpress.org/Shortcode_API', |
|
108
|
|
|
), |
|
109
|
|
|
), |
|
110
|
|
|
), |
|
111
|
|
|
), |
|
112
|
|
|
static::$type . '_allowed_html_tags' => array( |
|
113
|
|
|
'label' => __( 'Allowed HTML Tags', 'pods' ), |
|
114
|
|
|
'depends-on' => array( static::$type . '_allow_html' => true ), |
|
115
|
|
|
'default' => 'strong em a ul ol li b i', |
|
116
|
|
|
'type' => 'text', |
|
117
|
|
|
'help' => __( 'Format: strong em a ul ol li b i', 'pods' ), |
|
118
|
|
|
), |
|
119
|
|
|
static::$type . '_max_length' => array( |
|
120
|
|
|
'label' => __( 'Maximum Length', 'pods' ), |
|
121
|
|
|
'default' => 0, |
|
122
|
|
|
'type' => 'number', |
|
123
|
|
|
'help' => __( 'Set to -1 for no limit', 'pods' ), |
|
124
|
|
|
), |
|
125
|
|
|
static::$type . '_placeholder' => array( |
|
126
|
|
|
'label' => __( 'HTML Placeholder', 'pods' ), |
|
127
|
|
|
'default' => '', |
|
128
|
|
|
'type' => 'text', |
|
129
|
|
|
'help' => array( |
|
130
|
|
|
__( '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' ), |
|
131
|
|
|
'https://www.w3.org/WAI/tutorials/forms/instructions/#placeholder-text', |
|
132
|
|
|
), |
|
133
|
|
|
), |
|
134
|
|
|
); |
|
135
|
|
|
|
|
136
|
|
View Code Duplication |
if ( function_exists( 'Markdown' ) ) { |
|
137
|
|
|
$options['output_options']['group'][ static::$type . '_allow_markdown' ] = array( |
|
138
|
|
|
'label' => __( 'Allow Markdown Syntax?', 'pods' ), |
|
139
|
|
|
'default' => 0, |
|
140
|
|
|
'type' => 'boolean', |
|
141
|
|
|
); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
return $options; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* {@inheritdoc} |
|
149
|
|
|
*/ |
|
150
|
|
|
public function schema( $options = null ) { |
|
151
|
|
|
|
|
152
|
|
|
$length = (int) pods_v( static::$type . '_max_length', $options, 0 ); |
|
153
|
|
|
|
|
154
|
|
|
$schema = 'LONGTEXT'; |
|
155
|
|
|
|
|
156
|
|
|
if ( 0 < $length ) { |
|
157
|
|
|
$schema = 'VARCHAR(' . $length . ')'; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
return $schema; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* {@inheritdoc} |
|
165
|
|
|
*/ |
|
166
|
|
|
public function display( $value = null, $name = null, $options = null, $pod = null, $id = null ) { |
|
167
|
|
|
|
|
168
|
|
|
$value = $this->strip_html( $value, $options ); |
|
169
|
|
|
|
|
170
|
|
View Code Duplication |
if ( 1 === (int) pods_v( static::$type . '_oembed', $options, 0 ) ) { |
|
171
|
|
|
$embed = $GLOBALS['wp_embed']; |
|
172
|
|
|
$value = $embed->run_shortcode( $value ); |
|
173
|
|
|
$value = $embed->autoembed( $value ); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
View Code Duplication |
if ( 1 === (int) pods_v( static::$type . '_wptexturize', $options, 1 ) ) { |
|
177
|
|
|
$value = wptexturize( $value ); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
View Code Duplication |
if ( 1 === (int) pods_v( static::$type . '_convert_chars', $options, 1 ) ) { |
|
181
|
|
|
$value = convert_chars( $value ); |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
if ( 1 === (int) pods_v( static::$type . '_wpautop', $options, 1 ) ) { |
|
185
|
|
|
$value = wpautop( $value ); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
View Code Duplication |
if ( 1 === (int) pods_v( static::$type . '_allow_shortcode', $options, 0 ) ) { |
|
189
|
|
|
if ( 1 === (int) pods_v( static::$type . '_wpautop', $options, 1 ) ) { |
|
190
|
|
|
$value = shortcode_unautop( $value ); |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
$value = do_shortcode( $value ); |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
View Code Duplication |
if ( function_exists( 'Markdown' ) && 1 === (int) pods_v( static::$type . '_allow_markdown', $options ) ) { |
|
197
|
|
|
$value = Markdown( $value ); |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
return $value; |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
/** |
|
204
|
|
|
* {@inheritdoc} |
|
205
|
|
|
*/ |
|
206
|
|
View Code Duplication |
public function input( $name, $value = null, $options = null, $pod = null, $id = null ) { |
|
|
|
|
|
|
207
|
|
|
|
|
208
|
|
|
$options = (array) $options; |
|
209
|
|
|
$form_field_type = PodsForm::$field_type; |
|
210
|
|
|
|
|
211
|
|
|
if ( is_array( $value ) ) { |
|
212
|
|
|
$value = implode( "\n", $value ); |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
if ( isset( $options['name'] ) && false === PodsForm::permission( static::$type, $options['name'], $options, null, $pod, $id ) ) { |
|
216
|
|
|
if ( pods_v( 'read_only', $options, false ) ) { |
|
217
|
|
|
$options['readonly'] = true; |
|
218
|
|
|
} else { |
|
219
|
|
|
return; |
|
220
|
|
|
} |
|
221
|
|
|
} elseif ( ! pods_has_permissions( $options ) && pods_v( 'read_only', $options, false ) ) { |
|
222
|
|
|
$options['readonly'] = true; |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
pods_view( PODS_DIR . 'ui/fields/textarea.php', compact( array_keys( get_defined_vars() ) ) ); |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
/** |
|
229
|
|
|
* {@inheritdoc} |
|
230
|
|
|
*/ |
|
231
|
|
View Code Duplication |
public function pre_save( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) { |
|
|
|
|
|
|
232
|
|
|
|
|
233
|
|
|
$value = $this->strip_html( $value, $options ); |
|
234
|
|
|
|
|
235
|
|
|
$length = (int) pods_v( static::$type . '_max_length', $options, 0 ); |
|
236
|
|
|
|
|
237
|
|
|
if ( 0 < $length && $length < pods_mb_strlen( $value ) ) { |
|
238
|
|
|
$value = pods_mb_substr( $value, 0, $length ); |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
return $value; |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* {@inheritdoc} |
|
246
|
|
|
*/ |
|
247
|
|
View Code Duplication |
public function ui( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) { |
|
|
|
|
|
|
248
|
|
|
|
|
249
|
|
|
$value = $this->strip_html( $value, $options ); |
|
250
|
|
|
|
|
251
|
|
|
$value = wp_trim_words( $value ); |
|
252
|
|
|
|
|
253
|
|
|
return $value; |
|
254
|
|
|
} |
|
255
|
|
|
} |
|
256
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.