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 / code.php
pods / classes / fields Last commit date
avatar.php 4 days ago boolean.php 4 days ago code.php 4 days ago color.php 4 days ago comment.php 4 days ago currency.php 4 days ago date.php 4 days ago datetime.php 4 days ago email.php 4 days ago file.php 4 days ago html.php 4 days ago link.php 4 days ago number.php 4 days ago oembed.php 4 days ago paragraph.php 4 days ago password.php 4 days ago phone.php 4 days ago pick.php 4 days ago slug.php 4 days ago taxonomy.php 4 days ago text.php 4 days ago time.php 4 days ago website.php 4 days ago wysiwyg.php 4 days ago
code.php
136 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 self::$label = __( 'Code (Syntax Highlighting)', 'pods' );
36 }
37
38 /**
39 * {@inheritdoc}
40 */
41 public function options() {
42
43 $options = array(
44 static::$type . '_repeatable' => array(
45 'label' => __( 'Repeatable Field', 'pods' ),
46 'default' => 0,
47 'type' => 'boolean',
48 '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' ),
49 'boolean_yes_label' => '',
50 'dependency' => true,
51 'developer_mode' => true,
52 ),
53 'output_options' => array(
54 'label' => __( 'Output Options', 'pods' ),
55 'group' => array(
56 static::$type . '_allow_shortcode' => array(
57 'label' => __( 'Allow Shortcodes?', 'pods' ),
58 'default' => 0,
59 'type' => 'boolean',
60 'dependency' => true,
61 ),
62 ),
63 ),
64 static::$type . '_max_length' => array(
65 'label' => __( 'Maximum Length', 'pods' ),
66 'default' => 0,
67 'type' => 'number',
68 'help' => __( 'Set to -1 for no limit', 'pods' ),
69 ),
70 );
71
72 return $options;
73 }
74
75 /**
76 * {@inheritdoc}
77 */
78 public function schema( $options = null ) {
79
80 $length = (int) pods_v( static::$type . '_max_length', $options, 0 );
81
82 $schema = 'LONGTEXT';
83
84 if ( 0 < $length ) {
85 $schema = 'VARCHAR(' . $length . ')';
86 }
87
88 return $schema;
89 }
90
91 /**
92 * {@inheritdoc}
93 */
94 public function display( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
95 if ( 1 === (int) pods_v( static::$type . '_allow_shortcode', $options, 0 ) ) {
96 $value = do_shortcode( $value );
97 }
98
99 return $this->maybe_sanitize_output( $value, $options );
100 }
101
102 /**
103 * {@inheritdoc}
104 */
105 public function input( $name, $value = null, $options = null, $pod = null, $id = null ) {
106
107 $options = (array) $options;
108 $form_field_type = PodsForm::$field_type;
109
110 if ( is_array( $value ) ) {
111 $value = implode( "\n", $value );
112 }
113
114 $field_type = 'codemirror';
115
116 do_action( "pods_form_ui_field_code_{$field_type}", $name, $value, $options, $pod, $id );
117 do_action( 'pods_form_ui_field_code', $field_type, $name, $value, $options, $pod, $id );
118
119 pods_view( PODS_DIR . 'ui/fields/' . $field_type . '.php', compact( array_keys( get_defined_vars() ) ) );
120 }
121
122 /**
123 * {@inheritdoc}
124 */
125 public function pre_save( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
126
127 $length = (int) pods_v( static::$type . '_max_length', $options, 0 );
128
129 if ( 0 < $length && $length < pods_mb_strlen( $value ) ) {
130 $value = pods_mb_substr( $value, 0, $length );
131 }
132
133 return $value;
134 }
135 }
136