PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 3.3.4
Pods – Custom Content Types and Fields v3.3.4
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 / html.php
pods / classes / fields Last commit date
avatar.php 3 years ago boolean.php 3 years ago code.php 2 years ago color.php 1 year ago comment.php 4 years ago currency.php 9 months ago date.php 2 years ago datetime.php 1 year ago email.php 1 year ago file.php 11 months ago heading.php 1 year ago html.php 2 years ago link.php 1 year ago number.php 9 months ago oembed.php 1 year ago paragraph.php 2 years ago password.php 1 year ago phone.php 1 year ago pick.php 11 months ago slug.php 3 years ago taxonomy.php 4 years ago text.php 2 years ago time.php 2 years ago website.php 11 months ago wysiwyg.php 1 year ago
html.php
221 lines
1 <?php
2
3 use Pods\Whatsit\Field;
4
5 /**
6 * @package Pods\Fields
7 */
8 class PodsField_HTML extends PodsField {
9
10 /**
11 * {@inheritdoc}
12 */
13 public static $group = 'Layout Elements';
14
15 /**
16 * {@inheritdoc}
17 */
18 public static $type = 'html';
19
20 /**
21 * {@inheritdoc}
22 */
23 public static $label = 'HTML Content';
24
25 /**
26 * {@inheritdoc}
27 */
28 public static $prepare = '%s';
29
30 /**
31 * {@inheritdoc}
32 */
33 public function setup() {
34 static::$group = __( 'Layout Elements', 'pods' );
35 static::$label = __( 'HTML Content', 'pods' );
36 }
37
38 /**
39 * {@inheritdoc}
40 */
41 public function options() {
42 return [
43 static::$type . '_content' => [
44 'label' => __( 'HTML Content', 'pods' ),
45 'type' => 'code',
46 ],
47 static::$type . '_no_label' => [
48 'label' => __( 'Disable the form label', 'pods' ),
49 'default' => 1,
50 'type' => 'boolean',
51 'help' => __( 'By disabling the form label, the HTML will show as full width without the label text. Only the HTML content will be displayed in the form.', 'pods' ),
52 ],
53 'output_options' => [
54 'label' => __( 'Output Options', 'pods' ),
55 'type' => 'boolean_group',
56 'boolean_group' => [
57 static::$type . '_trim' => [
58 'label' => __( 'Trim extra whitespace before/after contents', 'pods' ),
59 'default' => 1,
60 'type' => 'boolean',
61 ],
62 static::$type . '_trim_lines' => [
63 'label' => __( 'Trim whitespace at the end of lines', 'pods' ),
64 'default' => 0,
65 'type' => 'boolean',
66 ],
67 static::$type . '_trim_p_brs' => [
68 'label' => __( 'Remove blank lines including empty "p" tags and "br" tags', 'pods' ),
69 'default' => 0,
70 'type' => 'boolean',
71 ],
72 static::$type . '_trim_extra_lines' => [
73 'label' => __( 'Remove extra blank lines (when there are 3+ blank lines, replace with a maximum of 2)', 'pods' ),
74 'default' => 0,
75 'type' => 'boolean',
76 ],
77 static::$type . '_oembed' => [
78 'label' => __( 'Enable oEmbed', 'pods' ),
79 'default' => 0,
80 'type' => 'boolean',
81 'help' => [
82 __( 'Embed videos, images, tweets, and other content.', 'pods' ),
83 'http://codex.wordpress.org/Embeds',
84 ],
85 ],
86 static::$type . '_wptexturize' => [
87 'label' => __( 'Enable wptexturize', 'pods' ),
88 'default' => 1,
89 'type' => 'boolean',
90 'help' => [
91 __( 'Transforms less-beautiful text characters into stylized equivalents.', 'pods' ),
92 'http://codex.wordpress.org/Function_Reference/wptexturize',
93 ],
94 ],
95 static::$type . '_convert_chars' => [
96 'label' => __( 'Enable convert_chars', 'pods' ),
97 'default' => 1,
98 'type' => 'boolean',
99 'help' => [
100 __( 'Converts text into valid XHTML and Unicode', 'pods' ),
101 'http://codex.wordpress.org/Function_Reference/convert_chars',
102 ],
103 ],
104 static::$type . '_wpautop' => [
105 'label' => __( 'Enable wpautop', 'pods' ),
106 'default' => 1,
107 'type' => 'boolean',
108 'help' => [
109 __( 'Changes double line-breaks in the text into HTML paragraphs.', 'pods' ),
110 'http://codex.wordpress.org/Function_Reference/wpautop',
111 ],
112 ],
113 static::$type . '_allow_shortcode' => [
114 'label' => __( 'Allow Shortcodes', 'pods' ),
115 'default' => 0,
116 'type' => 'boolean',
117 'dependency' => true,
118 'help' => [
119 __( 'Embed [shortcodes] that help transform your static content into dynamic content.', 'pods' ),
120 'http://codex.wordpress.org/Shortcode_API',
121 ],
122 ],
123 ],
124 ],
125 ];
126 }
127
128 /**
129 * {@inheritdoc}
130 */
131 public function schema( $options = null ) {
132 return false;
133 }
134
135 /**
136 * {@inheritdoc}
137 */
138 public function input( $name, $value = null, $options = null, $pod = null, $id = null ) {
139 $options = ( is_array( $options ) || is_object( $options ) ) ? $options : (array) $options;
140
141 // Enforce boolean.
142 $options[ static::$type . '_no_label' ] = filter_var( pods_v( static::$type . '_no_label', $options, false ), FILTER_VALIDATE_BOOLEAN );
143
144 // Format content.
145 $options[ static::$type . '_content' ] = $this->display( $options[ static::$type . '_content' ], $name, $options, $pod, $id );
146
147 if ( isset( $options['_field_object'] ) && $options['_field_object'] instanceof Field ) {
148 $options['_field_object']->set_arg( static::$type . '_no_label', $options[ static::$type . '_no_label' ] );
149 $options['_field_object']->set_arg( static::$type . '_content', $options[ static::$type . '_content' ] );
150 }
151
152 $type = pods_v( 'type', $options, static::$type );
153
154 $args = compact( array_keys( get_defined_vars() ) );
155 $args = (object) $args;
156
157 $this->render_input_script( $args );
158 }
159
160 /**
161 * {@inheritdoc}
162 */
163 public function display( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
164 // Support passing html_content into the options for custom HTML option layouts.
165 if ( in_array( $value, [ '', null ], true ) ) {
166 $value = pods_v( static::$type . '_content', $options, '' );
167 }
168
169 if ( $options ) {
170 $options[ static::$type . '_allow_html' ] = 1;
171 }
172
173 $value = $this->strip_html( $value, $options );
174 $value = $this->strip_shortcodes( $value, $options );
175 $value = $this->trim_whitespace( $value, $options );
176
177 if ( 1 === (int) pods_v( static::$type . '_oembed', $options, 0 ) ) {
178 $embed = $GLOBALS['wp_embed'];
179 $value = $embed->run_shortcode( $value );
180 $value = $embed->autoembed( $value );
181 }
182
183 if ( 1 === (int) pods_v( static::$type . '_wptexturize', $options, 1 ) ) {
184 $value = wptexturize( $value );
185 }
186
187 if ( 1 === (int) pods_v( static::$type . '_convert_chars', $options, 1 ) ) {
188 $value = convert_chars( $value );
189 }
190
191 if ( 1 === (int) pods_v( static::$type . '_wpautop', $options, 1 ) ) {
192 $value = wpautop( $value );
193 }
194
195 if ( 1 === (int) pods_v( static::$type . '_allow_shortcode', $options, 0 ) ) {
196 if ( 1 === (int) pods_v( static::$type . '_wpautop', $options, 1 ) ) {
197 $value = shortcode_unautop( $value );
198 }
199
200 $value = do_shortcode( $value );
201 }
202
203 return $value;
204 }
205
206 /**
207 * {@inheritdoc}
208 */
209 public function ui( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) {
210 if ( $options ) {
211 $options[ static::$type . '_allow_html' ] = 1;
212 }
213
214 $value = $this->strip_html( $value, $options );
215 $value = $this->strip_shortcodes( $value, $options );
216 $value = $this->trim_whitespace( $value, $options );
217
218 return wp_trim_words( $value );
219 }
220 }
221