PluginProbe
StreamCast – bring live radio to your site with a sleek player / 2.2.5
StreamCast – bring live radio to your site with a sleek player v2.2.5
2.4.5 2.4.4 trunk 1.0 1.1 2.0.0 2.1.10 2.1.2 2.1.4 2.1.5 2.1.8 2.2.1 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 All 29 releases
streamcast / admin / codestar-framework / classes / fields.class.php

fields.class.php in StreamCast – bring live radio to your site with a sleek player 2.2.5, at admin/codestar-framework/classes/fields.class.php

412 lines 11.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
2 /**
3 *
4 * Fields Class
5 *
6 * @since 1.0.0
7 * @version 1.0.0
8 *
9 */
10 if ( ! class_exists( 'CSF_Fields' ) ) {
11 abstract class CSF_Fields extends CSF_Abstract {
12
13 public $field = null;
14 public $value = null;
15 public $unique = null;
16 public $where = null;
17 public $parent = null;
18
19 public function __construct( $field = array(), $value = '', $unique = '', $where = '', $parent = '' ) {
20 $this->field = $field;
21 $this->value = $value;
22 $this->unique = $unique;
23 $this->where = $where;
24 $this->parent = $parent;
25 }
26
27 public function field_name( $nested_name = '' ) {
28
29 $field_id = ( ! empty( $this->field['id'] ) ) ? $this->field['id'] : '';
30 $unique_id = ( ! empty( $this->unique ) ) ? $this->unique .'['. $field_id .']' : $field_id;
31 $field_name = ( ! empty( $this->field['name'] ) ) ? $this->field['name'] : $unique_id;
32 $tag_prefix = ( ! empty( $this->field['tag_prefix'] ) ) ? $this->field['tag_prefix'] : '';
33
34 if ( ! empty( $tag_prefix ) ) {
35 $nested_name = str_replace( '[', '['. $tag_prefix, $nested_name );
36 }
37
38 return $field_name . $nested_name;
39
40 }
41
42 public function field_attributes( $custom_atts = array() ) {
43
44 $field_id = ( ! empty( $this->field['id'] ) ) ? $this->field['id'] : '';
45 $attributes = ( ! empty( $this->field['attributes'] ) ) ? $this->field['attributes'] : array();
46
47 if ( ! empty( $field_id ) && empty( $attributes['data-depend-id'] ) ) {
48 $attributes['data-depend-id'] = $field_id;
49 }
50
51 if ( ! empty( $this->field['placeholder'] ) ) {
52 $attributes['placeholder'] = $this->field['placeholder'];
53 }
54
55 $attributes = wp_parse_args( $attributes, $custom_atts );
56
57 $atts = '';
58
59 if ( ! empty( $attributes ) ) {
60 foreach ( $attributes as $key => $value ) {
61 if ( $value === 'only-key' ) {
62 $atts .= ' '. esc_attr( $key );
63 } else {
64 $atts .= ' '. esc_attr( $key ) . '="'. esc_attr( $value ) .'"';
65 }
66 }
67 }
68
69 return $atts;
70
71 }
72
73 public function field_before() {
74 return ( ! empty( $this->field['before'] ) ) ? '<div class="csf-before-text">'. $this->field['before'] .'</div>' : '';
75 }
76
77 public function field_after() {
78
79 $output = ( ! empty( $this->field['after'] ) ) ? '<div class="csf-after-text">'. $this->field['after'] .'</div>' : '';
80 $output .= ( ! empty( $this->field['desc'] ) ) ? '<div class="clear"></div><div class="csf-desc-text">'. $this->field['desc'] .'</div>' : '';
81 $output .= ( ! empty( $this->field['help'] ) ) ? '<div class="csf-help"><span class="csf-help-text">'. $this->field['help'] .'</span><i class="fas fa-question-circle"></i></div>' : '';
82 $output .= ( ! empty( $this->field['_error'] ) ) ? '<div class="csf-error-text">'. $this->field['_error'] .'</div>' : '';
83
84 return $output;
85
86 }
87
88 public static function field_data( $type = '', $term = false, $query_args = array() ) {
89
90 $options = array();
91 $array_search = false;
92
93 // sanitize type name
94 if ( in_array( $type, array( 'page', 'pages' ) ) ) {
95 $option = 'page';
96 } else if ( in_array( $type, array( 'post', 'posts' ) ) ) {
97 $option = 'post';
98 } else if ( in_array( $type, array( 'category', 'categories' ) ) ) {
99 $option = 'category';
100 } else if ( in_array( $type, array( 'tag', 'tags' ) ) ) {
101 $option = 'post_tag';
102 } else if ( in_array( $type, array( 'menu', 'menus' ) ) ) {
103 $option = 'nav_menu';
104 } else {
105 $option = '';
106 }
107
108 // switch type
109 switch( $type ) {
110
111 case 'page':
112 case 'pages':
113 case 'post':
114 case 'posts':
115
116 // term query required for ajax select
117 if ( ! empty( $term ) ) {
118
119 $query = new WP_Query( wp_parse_args( $query_args, array(
120 's' => $term,
121 'post_type' => $option,
122 'post_status' => 'publish',
123 'posts_per_page' => 25,
124 ) ) );
125
126 } else {
127
128 $query = new WP_Query( wp_parse_args( $query_args, array(
129 'post_type' => $option,
130 'post_status' => 'publish',
131 ) ) );
132
133 }
134
135 if ( ! is_wp_error( $query ) && ! empty( $query->posts ) ) {
136 foreach ( $query->posts as $item ) {
137 $options[$item->ID] = $item->post_title;
138 }
139 }
140
141 break;
142
143 case 'category':
144 case 'categories':
145 case 'tag':
146 case 'tags':
147 case 'menu':
148 case 'menus':
149
150 if ( ! empty( $term ) ) {
151
152 $query = new WP_Term_Query( wp_parse_args( $query_args, array(
153 'search' => $term,
154 'taxonomy' => $option,
155 'hide_empty' => false,
156 'number' => 25,
157 ) ) );
158
159 } else {
160
161 $query = new WP_Term_Query( wp_parse_args( $query_args, array(
162 'taxonomy' => $option,
163 'hide_empty' => false,
164 ) ) );
165
166 }
167
168 if ( ! is_wp_error( $query ) && ! empty( $query->terms ) ) {
169 foreach ( $query->terms as $item ) {
170 $options[$item->term_id] = $item->name;
171 }
172 }
173
174 break;
175
176 case 'user':
177 case 'users':
178
179 if ( ! empty( $term ) ) {
180
181 $query = new WP_User_Query( array(
182 'search' => '*'. $term .'*',
183 'number' => 25,
184 'orderby' => 'title',
185 'order' => 'ASC',
186 'fields' => array( 'display_name', 'ID' )
187 ) );
188
189 } else {
190
191 $query = new WP_User_Query( array( 'fields' => array( 'display_name', 'ID' ) ) );
192
193 }
194
195 if ( ! is_wp_error( $query ) && ! empty( $query->get_results() ) ) {
196 foreach ( $query->get_results() as $item ) {
197 $options[$item->ID] = $item->display_name;
198 }
199 }
200
201 break;
202
203 case 'sidebar':
204 case 'sidebars':
205
206 global $wp_registered_sidebars;
207
208 if ( ! empty( $wp_registered_sidebars ) ) {
209 foreach ( $wp_registered_sidebars as $sidebar ) {
210 $options[$sidebar['id']] = $sidebar['name'];
211 }
212 }
213
214 $array_search = true;
215
216 break;
217
218 case 'role':
219 case 'roles':
220
221 global $wp_roles;
222
223 if ( ! empty( $wp_roles ) ) {
224 if ( ! empty( $wp_roles->roles ) ) {
225 foreach ( $wp_roles->roles as $role_key => $role_value ) {
226 $options[$role_key] = $role_value['name'];
227 }
228 }
229 }
230
231 $array_search = true;
232
233 break;
234
235 case 'post_type':
236 case 'post_types':
237
238 $post_types = get_post_types( array( 'show_in_nav_menus' => true ), 'objects' );
239
240 if ( ! is_wp_error( $post_types ) && ! empty( $post_types ) ) {
241 foreach ( $post_types as $post_type ) {
242 $options[$post_type->name] = $post_type->labels->name;
243 }
244 }
245
246 $array_search = true;
247
248 break;
249
250 case 'location':
251 case 'locations':
252
253 $nav_menus = get_registered_nav_menus();
254
255 if ( ! is_wp_error( $nav_menus ) && ! empty( $nav_menus ) ) {
256 foreach ( $nav_menus as $nav_menu_key => $nav_menu_name ) {
257 $options[$nav_menu_key] = $nav_menu_name;
258 }
259 }
260
261 $array_search = true;
262
263 break;
264
265 default:
266
267 if ( is_callable( $type ) ) {
268 if ( ! empty( $term ) ) {
269 $options = call_user_func( $type, $query_args );
270 } else {
271 $options = call_user_func( $type, $term, $query_args );
272 }
273 }
274
275 break;
276
277 }
278
279 // Array search by "term"
280 if ( ! empty( $term ) && ! empty( $options ) && ! empty( $array_search ) ) {
281 $options = preg_grep( '/'. $term .'/i', $options );
282 }
283
284 // Make multidimensional array for ajax search
285 if ( ! empty( $term ) && ! empty( $options ) ) {
286 $arr = array();
287 foreach ( $options as $option_key => $option_value ) {
288 $arr[] = array( 'value' => $option_key, 'text' => $option_value );
289 }
290 $options = $arr;
291 }
292
293 return $options;
294
295 }
296
297 public function field_wp_query_data_title( $type, $values ) {
298
299 $options = array();
300
301 if ( ! empty( $values ) && is_array( $values ) ) {
302
303 foreach ( $values as $value ) {
304
305 $options[$value] = ucfirst( $value );
306
307 switch( $type ) {
308
309 case 'post':
310 case 'posts':
311 case 'page':
312 case 'pages':
313
314 $title = get_the_title( $value );
315
316 if ( ! is_wp_error( $title ) && ! empty( $title ) ) {
317 $options[$value] = $title;
318 }
319
320 break;
321
322 case 'category':
323 case 'categories':
324 case 'tag':
325 case 'tags':
326 case 'menu':
327 case 'menus':
328
329 $term = get_term( $value );
330
331 if ( ! is_wp_error( $term ) && ! empty( $term ) ) {
332 $options[$value] = $term->name;
333 }
334
335 break;
336
337 case 'user':
338 case 'users':
339
340 $user = get_user_by( 'id', $value );
341
342 if ( ! is_wp_error( $user ) && ! empty( $user ) ) {
343 $options[$value] = $user->display_name;
344 }
345
346 break;
347
348 case 'sidebar':
349 case 'sidebars':
350
351 global $wp_registered_sidebars;
352
353 if ( ! empty( $wp_registered_sidebars[$value] ) ) {
354 $options[$value] = $wp_registered_sidebars[$value]['name'];
355 }
356
357 break;
358
359 case 'role':
360 case 'roles':
361
362 global $wp_roles;
363
364 if ( ! empty( $wp_roles ) && ! empty( $wp_roles->roles ) && ! empty( $wp_roles->roles[$value] ) ) {
365 $options[$value] = $wp_roles->roles[$value]['name'];
366 }
367
368 break;
369
370 case 'post_type':
371 case 'post_types':
372
373 $post_types = get_post_types( array( 'show_in_nav_menus' => true ) );
374
375 if ( ! is_wp_error( $post_types ) && ! empty( $post_types ) && ! empty( $post_types[$value] ) ) {
376 $options[$value] = ucfirst( $value );
377 }
378
379 break;
380
381 case 'location':
382 case 'locations':
383
384 $nav_menus = get_registered_nav_menus();
385
386 if ( ! is_wp_error( $nav_menus ) && ! empty( $nav_menus ) && ! empty( $nav_menus[$value] ) ) {
387 $options[$value] = $nav_menus[$value];
388 }
389
390 break;
391
392 default:
393
394 if ( is_callable( $type .'_title' ) ) {
395 $options[$value] = call_user_func( $type .'_title', $value );
396 }
397
398 break;
399
400 }
401
402 }
403
404 }
405
406 return $options;
407
408 }
409
410 }
411 }
412