PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.9.19.5
Pods – Custom Content Types and Fields v2.9.19.5
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 / code.php
pods / classes / fields Last commit date
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
code.php
143 lines
1 <?php
2
3 /**
4 * Handles code field data and operations
5 *
6 * @package Pods\Fields
7 */
8 class PodsField_Code extends PodsField {
9
10 /**
11 * {@inheritdoc}
12 */
13 public static $group = 'Paragraph';
14
15 /**
16 * {@inheritdoc}
17 */
18 public static $type = 'code';
19
20 /**
21 * {@inheritdoc}
22 */
23 public static $label = 'Code (Syntax Highlighting)';
24
25 /**
26 * {@inheritdoc}
27 */
28 public static $prepare = '%s';
29
30 /**
31 * {@inheritdoc}
32 */
33 public function setup() {
34
35 static::$group = __( 'Paragraph', 'pods' );
36 static::$label = __( 'Code (Syntax Highlighting)', 'pods' );
37 }
38
39 /**
40 * {@inheritdoc}
41 */
42 public function options() {
43
44 $options = array(
45 'output_options' => array(
46 'label' => __( 'Output Options', 'pods' ),
47 'type' => 'boolean_group',
48 'boolean_group' => array(
49 static::$type . '_trim' => array(
50 'label' => __( 'Trim extra whitespace before/after contents', 'pods' ),
51 'default' => 1,
52 'type' => 'boolean',
53 'dependency' => true,
54 ),
55 static::$type . '_allow_shortcode' => array(
56 'label' => __( 'Allow Shortcodes', 'pods' ),
57 'default' => 0,
58 'type' => 'boolean',
59 'dependency' => true,
60 ),
61 ),
62 ),
63 static::$type . '_max_length' => array(
64 'label' => __( 'Maximum Length', 'pods' ),
65 'default' => -1,
66 'type' => 'number',
67 'help' => __( 'Set to -1 for no limit', 'pods' ),
68 ),
69 );
70
71 return $options;
72 }
73
74 /**
75 * {@inheritdoc}
76 */
77 public function schema( $options = null ) {
78
79 $length = (int) pods_v( static::$type . '_max_length', $options, 0 );
80
81 $schema = 'LONGTEXT';
82
83 if ( 0 < $length ) {
84 $schema = 'VARCHAR(' . $length . ')';
85 }
86
87 return $schema;
88 }
89
90 /**
91 * {@inheritdoc}
92 */
93 public function display( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
94 if ( 1 === (int) pods_v( static::$type . '_allow_shortcode', $options, 0 ) ) {
95 $value = do_shortcode( $value );
96 }
97
98 return $this->maybe_sanitize_output( $value, $options );
99 }
100
101 /**
102 * {@inheritdoc}
103 */
104 public function input( $name, $value = null, $options = null, $pod = null, $id = null ) {
105
106 $options = ( is_array( $options ) || is_object( $options ) ) ? $options : (array) $options;
107 $form_field_type = PodsForm::$field_type;
108
109 $value = $this->normalize_value_for_input( $value, $options, "\n" );
110
111 $field_type = 'codemirror';
112
113 do_action( "pods_form_ui_field_code_{$field_type}", $name, $value, $options, $pod, $id );
114 do_action( 'pods_form_ui_field_code', $field_type, $name, $value, $options, $pod, $id );
115
116 if ( ! empty( $options['disable_dfv'] ) ) {
117 return pods_view( PODS_DIR . 'ui/fields/' . $field_type . '.php', compact( array_keys( get_defined_vars() ) ) );
118 }
119
120 $type = pods_v( 'type', $options, static::$type );
121
122 $args = compact( array_keys( get_defined_vars() ) );
123 $args = (object) $args;
124
125 $this->render_input_script( $args );
126 }
127
128 /**
129 * {@inheritdoc}
130 */
131 public function pre_save( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
132 $value = $this->trim_whitespace( $value, $options );
133
134 $length = (int) pods_v( static::$type . '_max_length', $options, 0 );
135
136 if ( 0 < $length && $length < pods_mb_strlen( $value ) ) {
137 $value = pods_mb_substr( $value, 0, $length );
138 }
139
140 return $value;
141 }
142 }
143