PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.7.31.4
Pods – Custom Content Types and Fields v2.7.31.4
2.7.31.4 2.8.23.5 2.9.19.5 3.0.10.5 3.1.4.3 3.2.8.4 3.3.9.2 2.8.23.4 2.9.19.4 3.0.10.4 3.1.4.2 3.2.8.3 3.3.9.1 trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / classes / fields / wysiwyg.php
pods / classes / fields Last commit date
avatar.php 3 days ago boolean.php 3 days ago code.php 3 days ago color.php 3 days ago comment.php 3 days ago currency.php 3 days ago date.php 3 days ago datetime.php 3 days ago email.php 3 days ago file.php 3 days ago html.php 3 days ago link.php 3 days ago number.php 3 days ago oembed.php 3 days ago paragraph.php 3 days ago password.php 3 days ago phone.php 3 days ago pick.php 3 days ago slug.php 3 days ago taxonomy.php 3 days ago text.php 3 days ago time.php 3 days ago website.php 3 days ago wysiwyg.php 3 days ago
wysiwyg.php
302 lines
1 <?php
2
3 /**
4 * @package Pods\Fields
5 */
6 class PodsField_WYSIWYG extends PodsField {
7
8 /**
9 * {@inheritdoc}
10 */
11 public static $group = 'Paragraph';
12
13 /**
14 * {@inheritdoc}
15 */
16 public static $type = 'wysiwyg';
17
18 /**
19 * {@inheritdoc}
20 */
21 public static $label = 'WYSIWYG (Visual Editor)';
22
23 /**
24 * {@inheritdoc}
25 */
26 public static $prepare = '%s';
27
28 /**
29 * {@inheritdoc}
30 */
31 public function setup() {
32
33 self::$label = __( 'WYSIWYG (Visual Editor)', 'pods' );
34 }
35
36 /**
37 * {@inheritdoc}
38 */
39 public function options() {
40
41 $options = array(
42 static::$type . '_repeatable' => array(
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 . '_editor' => array(
52 'label' => __( 'Editor', 'pods' ),
53 'default' => 'tinymce',
54 'type' => 'pick',
55 'data' => apply_filters(
56 'pods_form_ui_field_wysiwyg_editors', array(
57 'tinymce' => __( 'TinyMCE (WP Default)', 'pods' ),
58 'cleditor' => __( 'CLEditor', 'pods' ),
59 )
60 ),
61 'dependency' => true,
62 ),
63 'editor_options' => array(
64 'label' => __( 'Editor Options', 'pods' ),
65 'depends-on' => array( static::$type . '_editor' => 'tinymce' ),
66 'group' => array(
67 static::$type . '_media_buttons' => array(
68 'label' => __( 'Enable Media Buttons?', 'pods' ),
69 'default' => 1,
70 'type' => 'boolean',
71 ),
72 ),
73 ),
74 static::$type . '_editor_height' => array(
75 'label' => __( 'Editor Height', 'pods' ),
76 'help' => __( 'Height in pixels', 'pods' ),
77 'default' => '',
78 'type' => 'number',
79 'depends-on' => array( static::$type . '_editor' => 'tinymce' ),
80 'number_decimals' => 0,
81 ),
82 'output_options' => array(
83 'label' => __( 'Output Options', 'pods' ),
84 'group' => array(
85 static::$type . '_oembed' => array(
86 'label' => __( 'Enable oEmbed?', 'pods' ),
87 'default' => 0,
88 'type' => 'boolean',
89 'help' => array(
90 __( 'Embed videos, images, tweets, and other content.', 'pods' ),
91 'http://codex.wordpress.org/Embeds',
92 ),
93 ),
94 static::$type . '_wptexturize' => array(
95 'label' => __( 'Enable wptexturize?', 'pods' ),
96 'default' => 1,
97 'type' => 'boolean',
98 'help' => array(
99 __( 'Transforms less-beautfiul text characters into stylized equivalents.', 'pods' ),
100 'http://codex.wordpress.org/Function_Reference/wptexturize',
101 ),
102 ),
103 static::$type . '_convert_chars' => array(
104 'label' => __( 'Enable convert_chars?', 'pods' ),
105 'default' => 1,
106 'type' => 'boolean',
107 'help' => array(
108 __( 'Converts text into valid XHTML and Unicode', 'pods' ),
109 'http://codex.wordpress.org/Function_Reference/convert_chars',
110 ),
111 ),
112 static::$type . '_wpautop' => array(
113 'label' => __( 'Enable wpautop?', 'pods' ),
114 'default' => 1,
115 'type' => 'boolean',
116 'help' => array(
117 __( 'Changes double line-breaks in the text into HTML paragraphs', 'pods' ),
118 'http://codex.wordpress.org/Function_Reference/wpautop',
119 ),
120 ),
121 static::$type . '_allow_shortcode' => array(
122 'label' => __( 'Allow Shortcodes?', 'pods' ),
123 'default' => 0,
124 'type' => 'boolean',
125 'dependency' => true,
126 'help' => array(
127 __( 'Embed [shortcodes] that help transform your static content into dynamic content.', 'pods' ),
128 'http://codex.wordpress.org/Shortcode_API',
129 ),
130 ),
131 ),
132 ),
133 static::$type . '_allowed_html_tags' => array(
134 'label' => __( 'Allowed HTML Tags', 'pods' ),
135 'default' => '',
136 'type' => 'text',
137 'help' => __( 'Format: strong em a ul ol li b i', 'pods' ),
138 ),
139 );
140
141 if ( function_exists( 'Markdown' ) ) {
142 $options['output_options']['group'][ static::$type . '_allow_markdown' ] = array(
143 'label' => __( 'Allow Markdown Syntax?', 'pods' ),
144 'default' => 0,
145 'type' => 'boolean',
146 );
147 }
148
149 return $options;
150 }
151
152 /**
153 * {@inheritdoc}
154 */
155 public function schema( $options = null ) {
156
157 $schema = 'LONGTEXT';
158
159 return $schema;
160 }
161
162 /**
163 * {@inheritdoc}
164 */
165 public function display( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
166
167 $value = $this->strip_html( $value, $options );
168
169 if ( 1 === (int) pods_v( static::$type . '_oembed', $options, 0 ) ) {
170 $post_temp = false;
171
172 // Workaround for WP_Embed since it needs a $post to work from
173 if ( 'post_type' === pods_v( 'type', $pod ) && 0 < $id && ( ! isset( $GLOBALS['post'] ) || empty( $GLOBALS['post'] ) ) ) {
174 $post_temp = true;
175
176 // @codingStandardsIgnoreLine
177 $GLOBALS['post'] = get_post( $id );
178 }
179
180 /**
181 * @var $embed WP_Embed
182 */
183 $embed = $GLOBALS['wp_embed'];
184 $value = $embed->run_shortcode( $value );
185 $value = $embed->autoembed( $value );
186
187 // Cleanup after ourselves
188 if ( $post_temp ) {
189 // @codingStandardsIgnoreLine
190 $GLOBALS['post'] = null;
191 }
192 }//end if
193
194 if ( 1 === (int) pods_v( static::$type . '_wptexturize', $options, 1 ) ) {
195 $value = wptexturize( $value );
196 }
197
198 if ( 1 === (int) pods_v( static::$type . '_convert_chars', $options, 1 ) ) {
199 $value = convert_chars( $value );
200 }
201
202 if ( 1 === (int) pods_v( static::$type . '_wpautop', $options, 1 ) ) {
203 $value = wpautop( $value );
204 }
205
206 if ( 1 === (int) pods_v( static::$type . '_allow_shortcode', $options, 0 ) ) {
207 if ( 1 === (int) pods_v( static::$type . '_wpautop', $options, 1 ) ) {
208 $value = shortcode_unautop( $value );
209 }
210
211 $value = do_shortcode( $value );
212 }
213
214 if ( function_exists( 'Markdown' ) && 1 === (int) pods_v( static::$type . '_allow_markdown', $options ) ) {
215 $value = Markdown( $value );
216 }
217
218 return $value;
219 }
220
221 /**
222 * {@inheritdoc}
223 */
224 public function input( $name, $value = null, $options = null, $pod = null, $id = null ) {
225
226 $options = (array) $options;
227 $form_field_type = PodsForm::$field_type;
228
229 if ( is_array( $value ) ) {
230 $value = implode( "\n", $value );
231 }
232
233 if ( isset( $options['name'] ) && false === PodsForm::permission( static::$type, $options['name'], $options, null, $pod, $id ) ) {
234 if ( pods_v( 'read_only', $options, false ) ) {
235 $options['readonly'] = true;
236
237 $field_type = 'textarea';
238 } else {
239 return;
240 }
241 } elseif ( ! pods_has_permissions( $options ) && pods_v( 'read_only', $options, false ) ) {
242 $options['readonly'] = true;
243
244 $field_type = 'textarea';
245 } elseif ( 'tinymce' === pods_v( static::$type . '_editor', $options ) ) {
246 $field_type = 'tinymce';
247 } elseif ( 'cleditor' === pods_v( static::$type . '_editor', $options ) ) {
248 $field_type = 'cleditor';
249 } else {
250 // Support custom WYSIWYG integration
251 $editor_type = pods_v( static::$type . '_editor', $options );
252 do_action( "pods_form_ui_field_wysiwyg_{$editor_type}", $name, $value, $options, $pod, $id );
253 do_action( 'pods_form_ui_field_wysiwyg', pods_v( static::$type . '_editor', $options ), $name, $value, $options, $pod, $id );
254
255 return;
256 }//end if
257
258 pods_view( PODS_DIR . 'ui/fields/' . $field_type . '.php', compact( array_keys( get_defined_vars() ) ) );
259 }
260
261 /**
262 * {@inheritdoc}
263 */
264 public function pre_save( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
265
266 $value = $this->strip_html( $value, $options );
267
268 $length = (int) pods_v( static::$type . '_max_length', $options, 0 );
269
270 if ( 0 < $length && $length < pods_mb_strlen( $value ) ) {
271 $value = pods_mb_substr( $value, 0, $length );
272 }
273
274 return $value;
275 }
276
277 /**
278 * {@inheritdoc}
279 */
280 public function ui( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) {
281
282 $value = $this->strip_html( $value, $options );
283
284 $value = wp_trim_words( $value );
285
286 return $value;
287 }
288
289 /**
290 * {@inheritdoc}
291 */
292 public function strip_html( $value, $options = null ) {
293
294 $options = (array) $options;
295
296 // Allow HTML tags.
297 $options[ static::$type . '_allow_html' ] = 1;
298
299 return parent::strip_html( $value, $options );
300 }
301 }
302