PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 3.3.7
Pods – Custom Content Types and Fields v3.3.7
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 / code.php
pods / classes / fields Last commit date
avatar.php 4 months ago boolean.php 4 months ago code.php 4 months ago color.php 4 months ago comment.php 4 months ago currency.php 4 months ago date.php 4 months ago datetime.php 4 months ago email.php 4 months ago file.php 4 months ago heading.php 4 months ago html.php 4 months ago link.php 4 months ago number.php 4 months ago oembed.php 4 months ago paragraph.php 4 months ago password.php 4 months ago phone.php 4 months ago pick.php 4 months ago slug.php 4 months ago taxonomy.php 4 months ago text.php 4 months ago time.php 4 months ago website.php 4 months ago wysiwyg.php 4 months ago
code.php
167 lines
1 <?php
2
3 // Don't load directly.
4 if ( ! defined( 'ABSPATH' ) ) {
5 die( '-1' );
6 }
7
8 /**
9 * Handles code field data and operations
10 *
11 * @package Pods\Fields
12 */
13 class PodsField_Code extends PodsField {
14
15 /**
16 * {@inheritdoc}
17 */
18 public static $group = 'Paragraph';
19
20 /**
21 * {@inheritdoc}
22 */
23 public static $type = 'code';
24
25 /**
26 * {@inheritdoc}
27 */
28 public static $label = 'Code (Syntax Highlighting)';
29
30 /**
31 * {@inheritdoc}
32 */
33 public static $prepare = '%s';
34
35 /**
36 * {@inheritdoc}
37 */
38 public function setup() {
39
40 static::$group = __( 'Paragraph', 'pods' );
41 static::$label = __( 'Code (Syntax Highlighting)', 'pods' );
42 }
43
44 /**
45 * {@inheritdoc}
46 */
47 public function options() {
48 return [
49 'output_options' => [
50 'label' => __( 'Output Options', 'pods' ),
51 'type' => 'boolean_group',
52 'boolean_group' => [
53 static::$type . '_trim' => [
54 'label' => __( 'Trim extra whitespace before/after contents', 'pods' ),
55 'default' => 1,
56 'type' => 'boolean',
57 ],
58 static::$type . '_trim_lines' => [
59 'label' => __( 'Trim whitespace at the end of lines', 'pods' ),
60 'default' => 0,
61 'type' => 'boolean',
62 ],
63 static::$type . '_trim_p_brs' => [
64 'label' => __( 'Remove blank lines including empty "p" tags and "br" tags', 'pods' ),
65 'default' => 0,
66 'type' => 'boolean',
67 ],
68 static::$type . '_trim_extra_lines' => [
69 'label' => __( 'Remove extra blank lines (when there are 3+ blank lines, replace with a maximum of 2)', 'pods' ),
70 'default' => 0,
71 'type' => 'boolean',
72 ],
73 static::$type . '_sanitize_html' => [
74 'label' => __( 'Sanitize HTML', 'pods' ),
75 'default' => 1,
76 'help' => __( 'This sanitizes things like script tags and other content not normally allowed in WordPress content. Disable this only if you trust users who will have access to enter content into this field.', 'pods' ),
77 'type' => 'boolean',
78 'dependency' => true,
79 ],
80 static::$type . '_allow_shortcode' => [
81 'label' => __( 'Allow Shortcodes', 'pods' ),
82 'default' => 0,
83 'type' => 'boolean',
84 'dependency' => true,
85 ],
86 ],
87 ],
88 static::$type . '_max_length' => [
89 'label' => __( 'Maximum Length', 'pods' ),
90 'default' => - 1,
91 'type' => 'number',
92 'help' => __( 'Set to -1 for no limit', 'pods' ),
93 ],
94 ];
95 }
96
97 /**
98 * {@inheritdoc}
99 */
100 public function schema( $options = null ) {
101
102 $length = (int) pods_v( static::$type . '_max_length', $options, 0 );
103
104 $schema = 'LONGTEXT';
105
106 if ( 0 < $length ) {
107 $schema = 'VARCHAR(' . $length . ')';
108 }
109
110 return $schema;
111 }
112
113 /**
114 * {@inheritdoc}
115 */
116 public function display( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
117 if ( 1 === (int) pods_v( static::$type . '_allow_shortcode', $options, 0 ) ) {
118 $value = do_shortcode( $value );
119 }
120
121 return $this->maybe_sanitize_output( $value, $options );
122 }
123
124 /**
125 * {@inheritdoc}
126 */
127 public function input( $name, $value = null, $options = null, $pod = null, $id = null ) {
128
129 $options = ( is_array( $options ) || is_object( $options ) ) ? $options : (array) $options;
130 $form_field_type = PodsForm::$field_type;
131
132 $value = $this->maybe_sanitize_output( $value, $options );
133 $value = $this->normalize_value_for_input( $value, $options, "\n" );
134
135 $field_type = 'codemirror';
136
137 do_action( "pods_form_ui_field_code_{$field_type}", $name, $value, $options, $pod, $id );
138 do_action( 'pods_form_ui_field_code', $field_type, $name, $value, $options, $pod, $id );
139
140 if ( ! empty( $options['disable_dfv'] ) ) {
141 return pods_view( PODS_DIR . 'ui/fields/' . $field_type . '.php', compact( array_keys( get_defined_vars() ) ) );
142 }
143
144 $type = pods_v( 'type', $options, static::$type );
145
146 $args = compact( array_keys( get_defined_vars() ) );
147 $args = (object) $args;
148
149 $this->render_input_script( $args );
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 $value = $this->trim_whitespace( $value, $options );
157
158 $length = (int) pods_v( static::$type . '_max_length', $options, 0 );
159
160 if ( 0 < $length && $length < pods_mb_strlen( $value ) ) {
161 $value = pods_mb_substr( $value, 0, $length );
162 }
163
164 return $value;
165 }
166 }
167