PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 1.0.3
JetFormBuilder — Dynamic Blocks Form Builder v1.0.3
3.6.4 3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / includes / classes / tools.php
jetformbuilder / includes / classes Last commit date
attributes-trait.php 5 years ago gallery.php 5 years ago get-icon-trait.php 5 years ago get-template-trait.php 5 years ago listing-filter-manager.php 5 years ago listing-filter.php 5 years ago messages-helper-trait.php 5 years ago tools.php 5 years ago
tools.php
286 lines
1 <?php
2
3 namespace Jet_Form_Builder\Classes;
4
5 // If this file is called directly, abort.
6 use Jet_Form_Builder\Plugin;
7
8 if ( ! defined( 'WPINC' ) ) {
9 die;
10 }
11
12
13 class Tools {
14
15 public static function is_editor() {
16 $action = ! empty( $_GET['context'] ) ? esc_attr( $_GET['context'] ) : '';
17
18 return in_array( $action, array( 'add', 'edit' ) );
19 }
20
21 /**
22 * Returns all post types list to use in JS components
23 *
24 * @param bool $placeholder
25 *
26 * @param array $args
27 * @param string $operator
28 *
29 * @return array [type] [description]
30 */
31 public static function get_post_types_for_js( $placeholder = false, $args = array(), $operator = 'and' ) {
32
33 $post_types = get_post_types( $args, 'objects', $operator );
34
35 $post_types_list = array();
36
37 if ( $placeholder && is_array( $placeholder ) ) {
38 $placeholder['value'] = isset( $placeholder['value'] ) ? $placeholder['value'] : '';
39 $post_types_list[] = $placeholder;
40 }
41
42 foreach ( $post_types as $post_type ) {
43 if ( $post_type->name !== Plugin::instance()->post_type->slug() ) {
44 $post_types_list[] = array(
45 'value' => $post_type->name,
46 'label' => $post_type->label,
47 );
48 }
49 }
50
51
52 return $post_types_list;
53 }
54
55 /**
56 * Get post types list for options.
57 *
58 * @return array
59 */
60 public static function get_post_types_for_options() {
61
62 return self::get_post_types_for_js(
63 array( 'label' => '--' ),
64 array( 'public' => true )
65 );
66
67 }
68
69 /**
70 * Sanitize WYSIWYG field
71 *
72 * @param $input
73 *
74 * @return string
75 */
76 public static function sanitize_wysiwyg( $input ) {
77 $input = wpautop( $input );
78
79 return wp_kses_post( $input );
80 }
81
82 /**
83 * Return all taxonomies list to use in JS components
84 *
85 * @return [type] [description]
86 */
87 public static function get_taxonomies_for_js() {
88 $taxonomies = get_taxonomies( array(), 'objects' );
89
90 return self::with_placeholder( self::prepare_list_for_js( $taxonomies, 'name', 'label' ) );
91 }
92
93 public static function get_generators_list_for_js() {
94 $generators = Plugin::instance()->form->get_generators_list();
95
96 return self::prepare_list_for_js( $generators );
97 }
98
99 public static function get_allowed_mimes_list_for_js() {
100 $mimes = get_allowed_mime_types();
101
102 $mimes_list = array();
103 foreach ( $mimes as $mime ) {
104 $mimes_list[] = array(
105 'label' => $mime,
106 'value' => $mime
107 );
108 }
109
110 return $mimes_list;
111 }
112
113 /**
114 * Returns all registeredroles for JS
115 */
116 public static function get_user_roles_for_js() {
117
118 $roles = self::get_user_roles();
119 $result = array();
120
121 foreach ( $roles as $role => $label ) {
122 $result[] = array(
123 'value' => $role,
124 'label' => $label,
125 );
126 }
127
128 return self::with_placeholder( $result );
129 }
130
131 public static function get_options_pages_for_js() {
132 $pages = array();
133
134 if ( function_exists( 'jet_engine' ) ) {
135 $pages = jet_engine()->options_pages->get_options_pages_for_select();
136 }
137
138 return self::prepare_list_for_js( $pages );
139 }
140
141 /**
142 * Returns pages list
143 * @return [type] [description]
144 */
145 public static function get_pages_list_for_js() {
146 $pages = get_pages();
147
148 return self::prepare_list_for_js( $pages, 'ID', 'post_title' );
149 }
150
151 /**
152 * Returns pages list
153 * @return [type] [description]
154 */
155 public static function get_forms_list_for_js() {
156 $posts = get_posts( array(
157 'post_status' => 'publish',
158 'posts_per_page' => - 1,
159 'post_type' => jet_form_builder()->post_type->slug(),
160 ) );
161
162 return self::prepare_list_for_js( $posts, 'ID', 'post_title' );
163 }
164
165 /**
166 * Returns all registered user roles
167 *
168 * @param string[] $exclude
169 *
170 * @return array [type] [description]
171 */
172 public static function get_user_roles( $exclude = array( 'administrator' ) ) {
173
174 if ( ! function_exists( 'get_editable_roles' ) ) {
175 return array();
176 } else {
177 $roles = get_editable_roles();
178 $result = array();
179
180 foreach ( $roles as $role => $data ) {
181 if ( ! in_array( $role, $exclude ) ) {
182 $result[ $role ] = $data['name'];
183 }
184 }
185 return $result;
186 }
187 }
188
189 /**
190 * Prepare passed array for using in JS options
191 *
192 * @return [type] [description]
193 */
194 public static function prepare_list_for_js( $array = array(), $value_key = null, $label_key = null ) {
195
196 $result = array();
197
198 if ( ! is_array( $array ) || empty( $array ) ) {
199 return $result;
200 }
201
202 foreach ( $array as $key => $item ) {
203
204 $value = null;
205 $label = null;
206
207 if ( is_object( $item ) ) {
208 $value = $item->$value_key;
209 $label = $item->$label_key;
210 } elseif ( is_array( $item ) ) {
211 $value = $item[ $value_key ];
212 $label = $item[ $label_key ];
213 } else {
214 $value = $key;
215 $label = $item;
216 }
217
218 $result[] = array(
219 'value' => $value,
220 'label' => $label,
221 );
222 }
223
224 return $result;
225
226 }
227
228 public static function with_placeholder( $array, $label = '--' ) {
229 return array_merge(
230 array(
231 array( 'label' => $label, 'value' => '' ),
232 ),
233 $array
234 );
235 }
236
237 /**
238 * Check if is valid timestamp
239 *
240 * @param mixed $timestamp
241 *
242 * @return boolean
243 */
244 public static function is_valid_timestamp( $timestamp ) {
245 return ( ( string ) ( int ) $timestamp === $timestamp || ( int ) $timestamp === $timestamp )
246 && ( $timestamp <= PHP_INT_MAX )
247 && ( $timestamp >= ~PHP_INT_MAX );
248 }
249
250 public static function maybe_recursive_sanitize( $source = null ) {
251 if ( ! is_array( $source ) ) {
252 return esc_attr( $source );
253 }
254
255 $result = array();
256 foreach ( $source as $key => $value ) {
257 $result[ $key ] = self::maybe_recursive_sanitize( $value );
258 }
259
260 return $result;
261 }
262
263 public static function sanitize_files( $source ) {
264 if ( ! is_array( $source ) ) {
265 return false;
266 }
267
268 $response = array();
269
270 foreach ( $source as $index => $item ) {
271 foreach ( $item as $key => $value ) {
272 switch ( $key ) {
273 case 'error':
274 case 'size':
275 $response[ $index ][ $key ] = absint( $value );
276 break;
277 default:
278 $response[ $index ][ $key ] = esc_attr( $value );
279 }
280 }
281 }
282
283 return $response;
284 }
285
286 }