PluginProbe
WP Directory Kit / 1.3.4
WP Directory Kit v1.3.4
1.5.6 1.5.5 1.5.4 1.5.3 trunk 1.1.0 1.1.6 1.1.8 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.8 1.4.0 1.4.1 All 35 releases
wpdirectorykit / vendor / Winter_MVC / core / helpers.php

helpers.php in WP Directory Kit 1.3.4, at vendor/Winter_MVC/core/helpers.php

1,576 lines 46.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! function_exists('hmvc_download_file'))
4 {
5 /**
6 * @deprecated 2.0 Use wmvc_download_file()
7 * @see wmvc_download_file()
8 */
9 function hmvc_download_file($url, $save_file_loc, $data = array())
10 {
11 return wmvc_download_file($url, $save_file_loc, $data);
12 }
13 }
14
15 if ( ! function_exists('hmvc_current_edit_url'))
16 {
17 /**
18 * @deprecated 2.0 Use wmvc_current_edit_url()
19 * @see wmvc_current_edit_url()
20 */
21 function hmvc_current_edit_url()
22 {
23 return wmvc_current_edit_url();
24 }
25 }
26
27 if ( ! function_exists('hmvc_api_call'))
28 {
29 /**
30 * @deprecated 2.0 Use wmvc_api_call()
31 * @see wmvc_api_call()
32 */
33 function hmvc_api_call($method, $url, $data, $headers = false)
34 {
35 return wmvc_api_call($method, $url, $data, $headers);
36 }
37 }
38
39
40 if ( ! function_exists('echo_js'))
41 {
42 /**
43 * @deprecated 2.0 Use wmvc_echo_js()
44 * @see wmvc_echo_js()
45 */
46 function echo_js($str)
47 {
48 $str = str_replace("'", "\'", trim($str));
49 $str = str_replace('"', '\"', $str);
50
51 echo $str;
52 }
53 }
54
55 if ( ! function_exists('_js'))
56 {
57 /**
58 * @deprecated 2.0 Use wmvc_js()
59 * @see wmvc_js()
60 */
61 function _js($str)
62 {
63 $str = str_replace("\\", "", trim($str));
64 $str = str_replace("'", "\'", trim($str));
65 $str = str_replace('"', '\"', $str);
66
67 return $str;
68 }
69 }
70
71 if ( ! function_exists('dump'))
72 {
73 /**
74 * @deprecated 2.0 Use wmvc_dump()
75 * @see wmvc_dump()
76 */
77 function dump($var)
78 {
79 echo '<pre>';
80 var_dump($var);
81 echo '</pre>';
82 }
83 }
84
85 if ( ! function_exists('resolve_ip'))
86 {
87 /**
88 * @deprecated 2.0 Use wmvc_resolve_ip()
89 * @see wmvc_resolve_ip()
90 */
91 function resolve_ip($ip)
92 {
93 if($ip == 'DISABLED')
94 return $ip;
95
96 if (filter_var($ip, FILTER_VALIDATE_IP)) {
97 // $ip is a valid IP address"
98 } else {
99 return '';
100 }
101
102 if($ip == '::1')
103 {
104 return $ip.', local';
105 }
106
107 $str = '<a target="_blank" href="https://whatismyipaddress.com/ip/'.$ip.'">'.$ip.'</a>';
108
109 return $str;
110 }
111 }
112
113 if ( ! function_exists('stringify_attributes'))
114 {
115 /**
116 * Stringify attributes for use in html tags.
117 *
118 * @since 1.0
119 * @deprecated 2.0 Use wmvc_stringify_attributes()
120 * @see wmvc_stringify_attributes()
121 *
122 * Helper function used to convert an array or object of
123 * attributes to a string
124 *
125 * @param mixed
126 * @return string
127 */
128 function stringify_attributes($attributes, $js = FALSE)
129 {
130 if (is_object($attributes) && count($attributes) > 0)
131 {
132 $attributes = (array) $attributes;
133 }
134
135 if (is_array($attributes))
136 {
137 $atts = '';
138 if (count($attributes) === 0)
139 {
140 return $atts;
141 }
142 foreach ($attributes as $key => $val)
143 {
144 if ($js)
145 {
146 $atts .= $key.'='.$val.',';
147 }
148 else
149 {
150 $atts .= ' '.$key.'="'.$val.'"';
151 }
152 }
153 return rtrim($atts, ',');
154 }
155 elseif (is_string($attributes) && strlen($attributes) > 0)
156 {
157 return ' '.$attributes;
158 }
159
160 return $attributes;
161 }
162 }
163
164 if ( ! function_exists('anchor'))
165 {
166 /**
167 * Anchor Link
168 *
169 * Creates an anchor based on the local URL.
170 *
171 * @deprecated 2.0 Use wmvc_anchor()
172 * @see wmvc_anchor()
173 *
174 * @param string the URL
175 * @param string the link title
176 * @param mixed any attributes
177 * @return string
178 */
179 function anchor($uri = '', $title = '', $attributes = '')
180 {
181 $title = (string) $title;
182
183 $site_url = is_array($uri)
184 ? site_url($uri)
185 : (preg_match('#^(\w+:)?//#i', $uri) ? $uri : site_url($uri));
186
187 if ($title === '')
188 {
189 $title = $site_url;
190 }
191
192 if ($attributes !== '')
193 {
194 $attributes = stringify_attributes($attributes);
195 }
196
197 return '<a href="'.$site_url.'"'.$attributes.'>'.$title.'</a>';
198 }
199 }
200
201 if ( ! function_exists('btn_edit'))
202 {
203 /**
204 * @deprecated 2.0 Use wmvc_btn_edit()
205 * @see wmvc_btn_edit()
206 */
207 function btn_edit($uri)
208 {
209 return anchor($uri, '<i class="glyphicon glyphicon-pencil"></i>', array('class'=>'btn btn-success btn-xs'));
210 }
211 }
212
213
214 if ( ! function_exists('btn_read'))
215 {
216 /**
217 * @deprecated 2.0 Use wmvc_btn_read()
218 * @see wmvc_btn_read()
219 */
220 function btn_read($uri, $title=NULL)
221 {
222 if(empty($title))$title=__('Read', 'wmvc_win');
223
224 return anchor($uri, '<i class="glyphicon glyphicon-search"></i> '.$title, array('class'=>'btn btn-primary btn-xs'));
225 }
226 }
227
228 if ( ! function_exists('btn_open'))
229 {
230 /**
231 * @deprecated 2.0 Use wmvc_btn_open()
232 * @see wmvc_btn_open()
233 */
234 function btn_open($uri, $target=NULL)
235 {
236 if($target === NULL)
237 $target = '_blank';
238
239 return anchor($uri, '<i class="glyphicon glyphicon-search"></i>', array('class'=>'btn btn-primary btn-xs', 'target'=>$target, 'title'=>__('Open details', 'wmvc_win')));
240 }
241 }
242
243 if ( ! function_exists('btn_open_ajax'))
244 {
245 /**
246 * @deprecated 2.0 Use wmvc_btn_open_ajax()
247 * @see wmvc_btn_open_ajax()
248 */
249 function btn_open_ajax($uri, $target=NULL)
250 {
251 if($target === NULL)
252 $target = '_blank';
253
254 return anchor($uri, '<i class="glyphicon glyphicon-search"></i>', array('class'=>'btn btn-primary btn-xs popup-with-form-ajax', 'target'=>$target, 'title'=>__('Open details', 'wmvc_win')));
255 }
256 }
257
258 if ( ! function_exists('btn_delete_noconfirm'))
259 {
260 /**
261 * @deprecated 2.0 Use wmvc_btn_delete_noconfirm()
262 * @see wmvc_btn_delete_noconfirm()
263 */
264 function btn_delete_noconfirm($uri)
265 {
266 return anchor($uri, '<i class="glyphicon glyphicon-remove"></i> ', array('class'=>'btn btn-danger btn-xs delete_button'));
267 }
268 }
269
270
271 if ( ! function_exists('btn_delete'))
272 {
273 /**
274 * @deprecated 2.0 Use wmvc_btn_delete()
275 * @see wmvc_btn_delete()
276 */
277 function btn_delete($uri, $confirm_question = TRUE, $title='')
278 {
279 $target = '';
280 if(isset($_GET['popup']))
281 {
282 $target = '';
283 }
284
285 if($confirm_question)
286 {
287 return anchor($uri, '<i class="glyphicon glyphicon-remove"></i> ', array( 'target' => $target, 'title' => $title, 'onclick' => 'return confirm(\''.__('Are you sure?', 'wmvc_win').'\')', 'class'=>'btn btn-danger btn-xs delete_button'));
288 }
289 else
290 {
291 return anchor($uri, '<i class="glyphicon glyphicon-remove"></i> ', array( 'target' => $target, 'title' => $title, 'class'=>'btn btn-danger btn-xs delete_button'));
292 }
293 }
294 }
295
296
297 if ( ! function_exists('btn_save'))
298 {
299 /**
300 * @deprecated 2.0 Use wmvc_btn_save()
301 * @see wmvc_btn_save()
302 */
303 function btn_save($uri, $empty = '-empty')
304 {
305 $target = '';
306 if(isset($_GET['popup']))
307 {
308 $target = '';
309 }
310
311 return anchor($uri, '<i class="glyphicon glyphicon-heart'.$empty.'"></i> ', array( 'target' => $target, 'class'=>'btn btn-danger btn-xs save_button', 'title'=>__('Save as Favourite for further analysis', 'wmvc_win')));
312 }
313 }
314
315 if ( ! function_exists('btn_block'))
316 {
317 /**
318 * @deprecated 2.0 Use wmvc_btn_block()
319 * @see wmvc_btn_block()
320 */
321 function btn_block($uri, $confirm_question = FALSE, $title='')
322 {
323 $target = '';
324 if(isset($_GET['popup']))
325 {
326 $target = '_blank';
327 }
328
329 if($confirm_question)
330 {
331 return anchor($uri, '<i class="glyphicon glyphicon-lock"></i> ', array( 'target' => $target, 'title' => $title, 'onclick' => 'return confirm(\''.__('Are you sure?', 'wmvc_win').'\')', 'class'=>'btn btn-warning btn-xs block_button'));
332 }
333 else
334 {
335 return anchor($uri, '<i class="glyphicon glyphicon-lock"></i> ', array( 'target' => $target, 'title' => $title, 'class'=>'btn btn-warning btn-xs block_button'));
336 }
337 }
338 }
339
340 if ( ! function_exists('btn_view'))
341 {
342 /**
343 * @deprecated 2.0 Use wmvc_btn_view()
344 * @see wmvc_btn_view()
345 */
346 function btn_view($uri, $confirm_question = FALSE, $title='')
347 {
348 if($confirm_question)
349 {
350 return anchor($uri, '<i class="glyphicon glyphicon-search"></i> ', array( 'title' => $title, 'onclick' => 'return confirm(\''.__('Are you sure?', 'wmvc_win').'\')', 'class'=>'btn btn-info btn-xs'));
351 }
352 else
353 {
354 return anchor($uri, '<i class="glyphicon glyphicon-search"></i> ', array( 'title' => $title, 'class'=>'btn btn-info btn-xs'));
355 }
356 }
357 }
358
359 if ( ! function_exists('btn_hide'))
360 {
361 /**
362 * @deprecated 2.0 Use wmvc_btn_hide()
363 * @see wmvc_btn_hide()
364 */
365 function btn_hide($uri)
366 {
367 $target = '';
368 if(isset($_GET['popup']))
369 {
370 $target = '_blank';
371 }
372
373 return anchor($uri, '<i class="glyphicon glyphicon-eye-close"></i> ', array( 'target' => $target, 'class'=>'btn btn-default btn-xs', 'title'=>__('Define hide rules', 'wmvc_win')));
374 }
375 }
376
377
378 if ( ! function_exists('get_file_extension'))
379 {
380 /**
381 * @deprecated 2.0 Use wmvc_get_file_extension()
382 * @see wmvc_get_file_extension()
383 */
384 function get_file_extension($filepath)
385 {
386 return substr($filepath, strrpos($filepath, '.')+1);
387 }
388 }
389
390 if ( ! function_exists('character_hard_limiter'))
391 {
392 /**
393 * @deprecated 2.0 Use wmvc_character_hard_limiter()
394 * @see wmvc_character_hard_limiter()
395 */
396 function character_hard_limiter($string, $max_len)
397 {
398 if(strlen($string)>$max_len)
399 {
400 return substr($string, 0, $max_len-3).'...';
401 }
402
403 return $string;
404 }
405 }
406
407 if ( ! function_exists('wmvc_echo_js'))
408 {
409 function wmvc_echo_js($str)
410 {
411 $str = str_replace("'", "\'", trim($str));
412 $str = str_replace('"', '\"', $str);
413
414 echo $str;
415 }
416 }
417
418 if ( ! function_exists('wmvc_js'))
419 {
420 function wmvc_js($str)
421 {
422 $str = str_replace("\\", "", trim($str));
423 $str = str_replace("'", "\'", trim($str));
424 $str = str_replace('"', '\"', $str);
425
426 return $str;
427 }
428 }
429
430 if ( ! function_exists('wmvc_dump'))
431 {
432 function wmvc_dump($var)
433 {
434 echo '<pre>';
435 var_dump($var);
436 echo '</pre>';
437 }
438 }
439
440
441 if ( ! function_exists('wmvc_resolve_ip'))
442 {
443 function wmvc_resolve_ip($ip)
444 {
445 if($ip == 'DISABLED')
446 return $ip;
447
448 if (filter_var($ip, FILTER_VALIDATE_IP)) {
449 // $ip is a valid IP address"
450 } else {
451 return '';
452 }
453
454 if($ip == '::1')
455 {
456 return $ip.', local';
457 }
458
459 $str = '<a target="_blank" href="https://whatismyipaddress.com/ip/'.$ip.'">'.$ip.'</a>';
460
461 return $str;
462 }
463 }
464
465 /**
466 * Stringify attributes for use in html tags.
467 *
468 * Helper function used to convert an array or object of
469 * attributes to a string
470 *
471 * @param mixed
472 * @return string
473 */
474 if ( ! function_exists('wmvc_stringify_attributes'))
475 {
476 function wmvc_stringify_attributes($attributes, $js = FALSE)
477 {
478 if (is_object($attributes) && count($attributes) > 0)
479 {
480 $attributes = (array) $attributes;
481 }
482
483 if (is_array($attributes))
484 {
485 $atts = '';
486 if (count($attributes) === 0)
487 {
488 return $atts;
489 }
490 foreach ($attributes as $key => $val)
491 {
492 if ($js)
493 {
494 $atts .= $key.'='.$val.',';
495 }
496 else
497 {
498 $atts .= ' '.$key.'="'.$val.'"';
499 }
500 }
501 return rtrim($atts, ',');
502 }
503 elseif (is_string($attributes) && strlen($attributes) > 0)
504 {
505 return ' '.$attributes;
506 }
507
508 return $attributes;
509 }
510 }
511
512 if ( ! function_exists('wmvc_anchor'))
513 {
514 /**
515 * Anchor Link
516 *
517 * Creates an anchor based on the local URL.
518 *
519 * @param string the URL
520 * @param string the link title
521 * @param mixed any attributes
522 * @return string
523 */
524 function wmvc_anchor($uri = '', $title = '', $attributes = '')
525 {
526 $title = (string) $title;
527
528 $site_url = is_array($uri)
529 ? site_url($uri)
530 : (preg_match('#^(\w+:)?//#i', $uri) ? $uri : site_url($uri));
531
532 if ($title === '')
533 {
534 $title = $site_url;
535 }
536
537 if ($attributes !== '')
538 {
539 $attributes = wmvc_stringify_attributes($attributes);
540 }
541
542 return '<a href="'.esc_url($site_url).'"'.wp_kses_post($attributes).'>'.wp_kses_post($title).'</a>';
543 }
544 }
545
546
547 if ( ! function_exists('wmvc_btn_edit'))
548 {
549 function wmvc_btn_edit($uri)
550 {
551 return wmvc_anchor($uri, '<i class="glyphicon glyphicon-pencil"></i>', array('class'=>'btn btn-success btn-xs'));
552 }
553 }
554
555 if ( ! function_exists('wmvc_btn_read'))
556 {
557 function wmvc_btn_read($uri, $title=NULL)
558 {
559 if(empty($title))$title=__('Read', 'wmvc_win');
560
561 return wmvc_anchor($uri, '<i class="glyphicon glyphicon-search"></i> '.esc_html($title), array('class'=>'btn btn-primary btn-xs'));
562 }
563 }
564
565 if ( ! function_exists('wmvc_btn_open'))
566 {
567 function wmvc_btn_open($uri, $target=NULL)
568 {
569 if($target === NULL)
570 $target = '_blank';
571
572 return wmvc_anchor($uri, '<i class="glyphicon glyphicon-search"></i>', array('class'=>'btn btn-primary btn-xs', 'target'=>esc_html($target), 'title'=>esc_html__('Open details', 'wmvc_win')));
573 }
574 }
575
576 if ( ! function_exists('wmvc_btn_open_ajax'))
577 {
578 function wmvc_btn_open_ajax($uri, $target=NULL)
579 {
580 if($target === NULL)
581 $target = '_blank';
582
583 return wmvc_anchor($uri, '<i class="glyphicon glyphicon-search"></i>', array('class'=>'btn btn-primary btn-xs popup-with-form-ajax', 'target'=>esc_html($target), 'title'=>esc_html__('Open details', 'wmvc_win')));
584 }
585 }
586
587 if ( ! function_exists('wmvc_btn_delete_noconfirm'))
588 {
589 function wmvc_btn_delete_noconfirm($uri)
590 {
591 return wmvc_anchor($uri, '<i class="glyphicon glyphicon-remove"></i> ', array('class'=>'btn btn-danger btn-xs delete_button'));
592 }
593 }
594
595
596 if ( ! function_exists('wmvc_btn_delete'))
597 {
598 function wmvc_btn_delete($uri, $confirm_question = TRUE, $title='')
599 {
600 $target = '';
601 if(isset($_GET['popup']))
602 {
603 $target = '';
604 }
605
606 if($confirm_question)
607 {
608 return wmvc_anchor($uri, '<i class="glyphicon glyphicon-remove"></i> ', array( 'target' => esc_html($target), 'title' => esc_html($title), 'onclick' => 'return confirm(\''.__('Are you sure?', 'wmvc_win').'\')', 'class'=>'btn btn-danger btn-xs delete_button action_confirm'));
609 }
610 else
611 {
612 return wmvc_anchor($uri, '<i class="glyphicon glyphicon-remove"></i> ', array( 'target' => esc_html($target), 'title' => esc_html($title), 'class'=>'btn btn-danger btn-xs delete_button'));
613 }
614 }
615 }
616
617 if ( ! function_exists('wmvc_btn_save'))
618 {
619 function wmvc_btn_save($uri, $empty = '-empty')
620 {
621 $target = '';
622 if(isset($_GET['popup']))
623 {
624 $target = '';
625 }
626
627 return wmvc_anchor($uri, '<i class="glyphicon glyphicon-heart'.esc_attr($empty).'"></i> ', array( 'target' => esc_html($target), 'class'=>'btn btn-danger btn-xs save_button', 'title'=>esc_html__('Save', 'wmvc_win')));
628 }
629 }
630
631 if ( ! function_exists('wmvc_btn_block'))
632 {
633 function wmvc_btn_block($uri, $confirm_question = FALSE, $title='')
634 {
635 $target = '';
636 if(isset($_GET['popup']))
637 {
638 $target = '_blank';
639 }
640
641 if($confirm_question)
642 {
643 return wmvc_anchor($uri, '<i class="glyphicon glyphicon-lock"></i> ', array( 'target' => esc_attr($target), 'title' => esc_html($title), 'onclick' => 'return confirm(\''.__('Are you sure?', 'wmvc_win').'\')', 'class'=>'btn btn-warning btn-xs block_button action_block'));
644 }
645 else
646 {
647 return wmvc_anchor($uri, '<i class="glyphicon glyphicon-lock"></i> ', array( 'target' => esc_attr($target), 'title' => esc_html($title), 'class'=>'btn btn-warning btn-xs block_button'));
648 }
649 }
650 }
651
652 if ( ! function_exists('wmvc_btn_view'))
653 {
654 function wmvc_btn_view($uri, $confirm_question = FALSE, $title='')
655 {
656 if($confirm_question)
657 {
658 return wmvc_anchor($uri, '<i class="glyphicon glyphicon-search"></i> ', array( 'title' => esc_html($title), 'onclick' => 'return confirm(\''.__('Are you sure?', 'wmvc_win').'\')', 'class'=>'btn btn-info btn-xs'));
659 }
660 else
661 {
662 return wmvc_anchor($uri, '<i class="glyphicon glyphicon-search"></i> ', array( 'title' => esc_html($title), 'class'=>'btn btn-info btn-xs'));
663 }
664 }
665 }
666
667 if ( ! function_exists('wmvc_btn_hide'))
668 {
669 function wmvc_btn_hide($uri)
670 {
671 $target = '';
672 if(isset($_GET['popup']))
673 {
674 $target = '_blank';
675 }
676
677 return wmvc_anchor($uri, '<i class="glyphicon glyphicon-eye-close"></i> ', array( 'target' => esc_attr($target), 'class'=>'btn btn-default btn-xs', 'title'=>esc_html__('Define hide rules', 'wmvc_win')));
678 }
679 }
680
681 if ( ! function_exists('wmvc_get_file_extension'))
682 {
683 function wmvc_get_file_extension($filepath)
684 {
685 return substr($filepath, strrpos($filepath, '.')+1);
686 }
687 }
688
689
690 if ( ! function_exists('wmvc_character_hard_limiter'))
691 {
692 function wmvc_character_hard_limiter($string, $max_len)
693 {
694 if(strlen($string)>$max_len)
695 {
696 return substr($string, 0, $max_len-3).'...';
697 }
698
699 return $string;
700 }
701 }
702
703
704 if(!function_exists('wmvc_count')) {
705 function wmvc_count($mixed='') {
706 $count = 0;
707
708 if(!empty($mixed) && (is_array($mixed))) {
709 $count = count($mixed);
710 } else if(!empty($mixed) && function_exists('is_countable') && version_compare(PHP_VERSION, '7.3', '<') && is_countable($mixed)) {
711 $count = count($mixed);
712 }
713 else if(!empty($mixed) && is_object($mixed)) {
714 $count = 1;
715 }
716 return $count;
717 }
718 }
719
720 function wmvc_is_user_in_role( $user, $role ) {
721 return in_array( $role, $user->roles );
722 }
723
724 function wmvc_is_logged_user()
725 {
726 $current_user = wp_get_current_user();
727 if ( 0 == $current_user->ID ) {
728 return false;
729 } else {
730 // Logged in.
731 return true;
732 }
733 }
734
735 function wmvc_get_current_user_role() {
736 if( is_user_logged_in() ) {
737 $user = wp_get_current_user();
738 $role = ( array ) $user->roles;
739 return $role[0];
740 } else {
741 return '';
742 }
743 }
744
745 function wmvc_user_in_role($role)
746 {
747 if(!wmvc_is_logged_user())
748 return false;
749
750 $current_user = wp_get_current_user();
751
752 return wmvc_is_user_in_role( $current_user, $role );
753 }
754
755 function wmvc_character_limiter($text, $limit)
756 {
757 if(is_array($text))
758 $text = 'Array( '. join(', ', $text).' )';
759
760 if(strlen($text) > $limit)
761 {
762 return substr($text, 0, $limit-4).'...';
763 }
764
765 return $text;
766 }
767
768 function wmvc_show_data($field_name, &$db_value = NULL, $default = '', $xss_clean = TRUE, $skip_post = FALSE)
769 {
770 if(!$skip_post && isset($_POST[$field_name]))
771 {
772 if($xss_clean === FALSE)
773 return stripslashes($_POST[$field_name]);
774
775 return wmvc_xss_clean(stripslashes($_POST[$field_name]));
776 }
777
778 if(is_array($db_value))
779 {
780 if(isset($db_value[$field_name]))
781 {
782 if($xss_clean === FALSE)
783 return $db_value[$field_name];
784
785 return wmvc_xss_clean($db_value[$field_name]);
786 }
787 else
788 {
789 return $default;
790 }
791 }
792
793 if(is_object($db_value))
794 {
795 if(isset($db_value->$field_name))
796 {
797 if($xss_clean === FALSE)
798 return $db_value->$field_name;
799
800 return wmvc_xss_clean($db_value->$field_name);
801 }
802 else
803 {
804 return $default;
805 }
806 }
807
808 if(!empty($db_value))
809 {
810 if($xss_clean === FALSE)
811 return $db_value;
812
813 return wmvc_xss_clean($db_value);
814 }
815
816 if($xss_clean === FALSE)
817 return $default;
818
819 return wmvc_xss_clean($default);
820 }
821
822
823 /*
824 <select class="form-control" name="<?php echo 'control_operator_'.$i_fieldnum; ?>">
825 <option value="CONTAINS">CONTAINS</option>
826 <option value="NOT_CONTAINS">NOT_CONTAINS</option>
827 </select>
828 */
829 function wmvc_select_option($field_name, $options = array(), $selected = NULL, $extra=NULL, $empty_text = NULL, $empty_val = '')
830 {
831 $output = '<select name="'.$field_name.'" '.$extra.' >';
832
833 if(!is_null($empty_text))
834 $output.= '<option value="'.esc_attr($empty_val).'">'.esc_html($empty_text).'</option>';
835
836 if(is_array($options) && count($options) > 0)
837 foreach($options as $key=>$val)
838 {
839 $output.= '<option value="'.$key.'" '.($selected==$key&&$selected != ''?'selected':'').'>'.$val.'</option>';
840 }
841
842 $output.= '</select>';
843
844 return $output;
845 }
846
847 function wmvc_upload_media($field_name, $image_id)
848 {
849 static $media_element_counter = 0;
850
851 $media_element_counter++;
852
853 $img_field = $field_name.'_'.$media_element_counter;
854
855 wp_enqueue_script( 'wpmediaelement' );
856 wp_enqueue_media();
857
858 ?>
859 <div id="<?php echo esc_attr($field_name); ?>meta-box-id" class="postbox-upload">
860 <?php
861 // Get WordPress' media upload URL
862 $upload_link = '#';
863
864 // Get the image src
865 $your_img_src = wp_get_attachment_image_src( $image_id, 'full' );
866
867 // For convenience, see if the array is valid
868 $you_have_img = is_array( $your_img_src );
869 ?>
870
871 <!-- Your image container, which can be manipulated with js -->
872 <div class="custom-img-container">
873 <?php if ( $you_have_img ) : ?>
874 <img src="<?php echo esc_html($your_img_src[0]); ?>" alt="<?php echo esc_attr__('thumb', 'wmvc_win');?>" style="max-width:100%;" class="thumbnail"/>
875 <?php endif; ?>
876 </div>
877
878 <?php //if(sw_user_in_role('administrator')): ?>
879 <!-- Your add & remove image links -->
880 <p class="hide-if-no-js">
881 <a class="button button-primary upload-custom-img <?php if ( $you_have_img ) { echo 'hidden'; } ?>"
882 href="<?php echo esc_url($upload_link) ?>">
883 <?php echo esc_html__('Select image','wmvc_win') ?>
884 </a>
885 <a class="button button-secondary delete-custom-img <?php if ( ! $you_have_img ) { echo 'hidden'; } ?>"
886 href="#">
887 <?php echo esc_html__('Remove image','wmvc_win') ?>
888 </a>
889 </p>
890 <?php //endif; ?>
891
892 <!-- A hidden input to set and post the chosen image id -->
893 <input class="logo_image_id" type="hidden" id="<?php echo esc_html(esc_html($field_name)); ?>" name="<?php echo esc_html($field_name); ?>" value="<?php echo esc_html($image_id); ?>" />
894 </div>
895
896 <?php
897 $custom_js ='';
898 $custom_js .=" jQuery(function($) {
899 if( typeof jQuery.fn.wpMediaElement == 'function')
900 $('#".esc_js($field_name)."meta-box-id.postbox-upload').wpMediaElement();
901 });";
902
903 echo "<script>".$custom_js."</script>";
904
905 ?>
906
907 <?php
908 }
909
910 function wmvc_upload_file($field_name, $file_id)
911 {
912 static $media_element_counter = 0;
913
914 $media_element_counter++;
915
916 $img_field = $field_name.'_'.$media_element_counter;
917
918 wp_enqueue_script( 'wpmediaelement' );
919 wp_enqueue_media();
920
921 ?>
922 <div id="<?php echo esc_attr($field_name); ?>meta-box-id" class="postbox-upload">
923 <?php
924 // Get WordPress' media upload URL
925 $upload_link = '#';
926
927 // Get the file src
928
929 // Get the file src
930 $your_file_src = get_attached_file(intval( $file_id));
931
932 // For convenience, see if the array is valid
933 $you_have_file = false;
934 if($your_file_src)
935 $you_have_file = basename($your_file_src);
936
937 ?>
938
939 <!-- Your file container, which can be manipulated with js -->
940 <div class="custom-img-container">
941 <?php if ( $you_have_file ) : ?>
942 <?php echo esc_html($you_have_file); ?>
943 <?php endif; ?>
944 </div>
945
946 <?php //if(sw_user_in_role('administrator')): ?>
947 <!-- Your add & remove file links -->
948 <p class="hide-if-no-js">
949 <a class="upload-custom-img <?php if ( $you_have_file ) { echo 'hidden'; } ?>"
950 href="<?php echo esc_url($upload_link) ?>">
951 <?php echo esc_html__('Select file','wmvc_win') ?>
952 </a>
953 <a class="delete-custom-img <?php if ( ! $you_have_file ) { echo 'hidden'; } ?>"
954 href="#">
955 <?php echo esc_html__('Remove file','wmvc_win') ?>
956 </a>
957 </p>
958 <?php //endif; ?>
959
960 <!-- A hidden input to set and post the chosen file id -->
961 <input class="file_id" type="hidden" id="<?php echo esc_html($field_name); ?>" name="<?php echo esc_html($field_name); ?>" value="<?php echo esc_html($file_id); ?>" />
962 </div>
963
964 <?php
965 $custom_js ='';
966 $custom_js .=" jQuery(function($) {
967 if( typeof jQuery.fn.wpMediaElement == 'function')
968 $('#".esc_js($field_name)."meta-box-id.postbox-upload').wpMediaElement({'imgIdInputSelector':'.file_id','isfileUpload':'true'});
969 });";
970
971 echo "<script>".$custom_js."</script>";
972
973 ?>
974
975 <?php
976 }
977
978 function wmvc_upload_multiple($field_name, $image_ids='')
979 {
980 static $media_element_counter = 0;
981
982 $media_element_counter++;
983
984 $img_field = $field_name.'_'.$media_element_counter;
985
986 wp_enqueue_script( 'wpmediamultiple' );
987 wp_enqueue_script( 'jquery-ui-mouse' );
988 wp_enqueue_media();
989
990 ?>
991 <div id="<?php echo esc_attr($field_name); ?>meta-box-id" class="postbox-upload-multiple">
992 <?php
993 // Get WordPress' media upload URL
994 $upload_link = '#';
995
996
997 // Get the image src
998
999 $your_img_src = array();
1000
1001 foreach(explode(',', $image_ids) as $image_id)
1002 {
1003 if(is_numeric($image_id)){
1004 if(false)
1005 $your_img_src[$image_id] = wp_get_attachment_image_src( $image_id, 'full' );
1006
1007 $your_img_src[$image_id] = wp_get_attachment_url( $image_id, 'full' );
1008 }
1009 }
1010
1011
1012 // For convenience, see if the array is valid
1013 $you_have_img = count($your_img_src) > 0;
1014 ?>
1015
1016 <!-- Your image container, which can be manipulated with js -->
1017 <div class="custom-img-container winter_mvc-media">
1018 <?php if($you_have_img)foreach($your_img_src as $image_id => $img_src) : ?>
1019 <?php
1020
1021 $filetype = wp_check_filetype(str_replace(WP_CONTENT_URL, WP_CONTENT_DIR, $img_src));
1022 if(strpos($filetype['type'], 'video') !== FALSE):?>
1023 <div class="winter_mvc-media-card" data-media-id="<?php echo esc_attr($image_id);?>">
1024 <video src="<?php echo esc_html($img_src); ?>" controls alt="<?php echo esc_attr__('thumb', 'wmvc_win');?>" style="max-width:100%;" class="thumbnail"></video>
1025 <a href="#" class="remove"></a>
1026 <span href="#" class="move"><span class="dashicons dashicons-editor-expand"></span></span>
1027 </div>
1028 <?php else:?>
1029 <div class="winter_mvc-media-card" data-media-id="<?php echo esc_attr($image_id);?>">
1030 <img src="<?php echo esc_html($img_src); ?>" alt="<?php echo esc_attr__('thumb', 'wmvc_win');?>" style="max-width:100%;" class="thumbnail"/>
1031 <a href="#" class="remove"></a>
1032 </div>
1033 <?php endif;?>
1034
1035
1036 <?php endforeach; ?>
1037 </div>
1038 <br style="clear:both;" />
1039
1040 <?php //if(sw_user_in_role('administrator')): ?>
1041 <!-- Your add & remove image links -->
1042 <p class="hide-if-no-js">
1043 <a class="button button-primary upload-custom-img <?php if ( $you_have_img ) { echo ''; } ?>"
1044 href="<?php echo esc_url($upload_link) ?>">
1045 <?php echo esc_html__('Add images','wmvc_win') ?>
1046 </a>
1047 <a class="button button-secondary delete-custom-img <?php if ( ! $you_have_img ) { echo 'hidden'; } ?>"
1048 href="#">
1049 <?php echo esc_html__('Remove images','wmvc_win') ?>
1050 </a>
1051 </p>
1052 <?php //endif; ?>
1053
1054 <!-- A hidden input to set and post the chosen image id -->
1055 <input class="logo_image_id" type="hidden" id="<?php echo esc_html(esc_html($field_name)); ?>" name="<?php echo esc_html($field_name); ?>" value="<?php echo esc_html($image_ids); ?>" />
1056 </div>
1057 <?php
1058 $custom_js ='';
1059 $custom_js .=" jQuery(function($) {
1060 if( typeof jQuery.fn.wpMediaMultiple == 'function')
1061 $('#".esc_js($field_name)."meta-box-id.postbox-upload-multiple').wpMediaMultiple();
1062 /* order */
1063 var re_order = function(media_element){
1064 var list_media = '';
1065 media_element.find('.winter_mvc-media-card').each(function(){
1066 if(list_media !='')
1067 list_media +=',';
1068
1069 list_media += $(this).attr('data-media-id');
1070 })
1071 media_element.closest('.postbox-upload-multiple').find('.logo_image_id').val(list_media);
1072 }
1073 /* Sort table */
1074 $( '.winter_mvc-media' ).sortable({
1075 update: function(event, ui) {
1076 re_order($(this));
1077 }
1078 });
1079 /* remove media */
1080 $( '.winter_mvc-media' ).find('.winter_mvc-media-card .remove').on('click', function(e){
1081 e.preventDefault();
1082 var media = $(this).closest('.winter_mvc-media')
1083 $(this).closest('.winter_mvc-media-card').remove();
1084 re_order(media)
1085 })
1086 });
1087 ";
1088
1089 echo "<script>".$custom_js."</script>";
1090
1091 ?>
1092
1093 <?php
1094 }
1095
1096 function wmvc_select_radio($field_name, $options = array(), $selected = NULL)
1097 {
1098 $output = ''; //'<div class="radio"> <select name="'.$field_name.'" '.$extra.' >';
1099
1100 if(is_array($options) && count($options) > 0)
1101 foreach($options as $key=>$val)
1102 {
1103 $output.= '<div class="radio">';
1104 $output.= '<label>';
1105 $output.= '<input type="radio" name="'.esc_attr($field_name).'" id="optionsRadios1_format" value="'.esc_attr($key).'" '.($selected==$key?'checked':'').' />';
1106 $output.= esc_html($val);
1107 $output.= '</label>';
1108 $output.= '</div>';
1109 }
1110
1111 return $output;
1112 }
1113
1114
1115 function wmvc_form_messages()
1116 {
1117 echo 'ok';
1118 }
1119
1120 function wmvc_xss_clean($data)
1121 {
1122 //if($data == '0000-00-00 00:00:00')return '';
1123 if(is_array($data))
1124 return wmvc_xss_clean_array($data);
1125
1126 if(is_object($data))
1127 return wmvc_xss_clean_object($data);
1128
1129 if($data === NULL)
1130 return '';
1131
1132 // Fix &entity\n;
1133 $data = str_replace(array('&amp;','&lt;','&gt;'), array('&amp;amp;','&amp;lt;','&amp;gt;'), $data);
1134 $data = preg_replace('/(&#*\w+)[\x00-\x20]+;/u', '$1;', $data);
1135 $data = preg_replace('/(&#x*[0-9A-F]+);*/iu', '$1;', $data);
1136 $data = html_entity_decode($data, ENT_COMPAT, 'UTF-8');
1137
1138 // Remove any attribute starting with "on" or xmlns
1139 $data = preg_replace('#(<[^>]+?[\x00-\x20"\'])(?:on|xmlns)[^>]*+>#iu', '$1>', $data);
1140
1141 // Remove javascript: and vbscript: protocols
1142 $data = preg_replace('#([a-z]*)[\x00-\x20]*=[\x00-\x20]*([`\'"]*)[\x00-\x20]*j[\x00-\x20]*a[\x00-\x20]*v[\x00-\x20]*a[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iu', '$1=$2nojavascript...', $data);
1143 $data = preg_replace('#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*v[\x00-\x20]*b[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iu', '$1=$2novbscript...', $data);
1144 $data = preg_replace('#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*-moz-binding[\x00-\x20]*:#u', '$1=$2nomozbinding...', $data);
1145
1146 // Only works in IE: <span style="width: expression(alert('Ping!'));"></span>
1147 $data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?expression[\x00-\x20]*\([^>]*+>#i', '$1>', $data);
1148 $data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?behaviour[\x00-\x20]*\([^>]*+>#i', '$1>', $data);
1149 $data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:*[^>]*+>#iu', '$1>', $data);
1150
1151 // Remove namespaced elements (we do not need them)
1152 $data = preg_replace('#</*\w+:\w[^>]*+>#i', '', $data);
1153 $data = preg_replace("/(\b1=1\b|\) OR\b)/", "", $data);
1154
1155 do
1156 {
1157 // Remove really unwanted tags
1158 $old_data = $data;
1159 $data = preg_replace('#</*(?:applet|b(?:ase|gsound|link)|embed|frame(?:set)?|i(?:framXe|layer)|l(?:ayer|ink)|meta|object|s(?:cript|tyle)|title|xml)[^>]*+>#i', '', $data);
1160 }
1161 while ($old_data !== $data);
1162
1163 //$data = sanitize_textarea_field($data);
1164
1165 // we are done...
1166 return $data;
1167 }
1168
1169 function wmvc_xss_clean_array($array)
1170 {
1171 if(!is_array($array))return array();
1172
1173 $arr_cleaned = array();
1174 foreach($array as $key=>$val)
1175 {
1176 if($key == 'newcontent')
1177 {
1178 $arr_cleaned[wmvc_xss_clean($key)] = $val;
1179 }
1180 else
1181 {
1182 $arr_cleaned[wmvc_xss_clean($key)] = wmvc_xss_clean($val);
1183 }
1184
1185 }
1186
1187 //dump($arr_cleaned);
1188
1189 return $arr_cleaned;
1190 }
1191
1192 function wmvc_xss_clean_object($object)
1193 {
1194 if(!is_object($object))return NULL;
1195
1196 $array = get_object_vars($object);
1197 foreach($array as $key=>$val)
1198 {
1199 $object->{$key} = wmvc_xss_clean($object->{$key});
1200 }
1201
1202 return $object;
1203 }
1204
1205 function wmvc_roles_array() {
1206 $editable_roles = get_editable_roles();
1207 foreach ($editable_roles as $role => $details) {
1208 $sub['role'] = esc_attr($role);
1209 $sub['name'] = translate_user_role($details['name']);
1210 $roles[] = $sub;
1211 }
1212 return $roles;
1213 }
1214
1215 function wmvc_seconds_to_hms($seconds, $show_days=true) {
1216 $t = round($seconds);
1217 $days = floor($t/86400);
1218 $day_sec = $days*86400;
1219 $hours = floor( ($t-$day_sec) / (60 * 60) );
1220 $hour_sec = $hours*3600;
1221 $minutes = floor((($t-$day_sec)-$hour_sec)/60);
1222 $min_sec = $minutes*60;
1223 $sec = (($t-$day_sec)-$hour_sec)-$min_sec;
1224
1225 if($show_days)
1226 {
1227 return sprintf('%02d:%02d:%02d:%02d', $days, $hours, $minutes, $sec);
1228 }
1229
1230 // to show only hours, no days
1231 $hours = floor( ($t) / (60 * 60) );
1232 return sprintf('%02d:%02d:%02d', $hours, $minutes, $sec);
1233 }
1234
1235 function wmvc_xml_encode($array)
1236 {
1237
1238 if (is_null($DOMDocument)) {
1239 $DOMDocument =new DOMDocument;
1240 $DOMDocument->formatOutput = true;
1241 wmvc_xml_encode($mixed, $DOMDocument, $DOMDocument);
1242 echo $DOMDocument->saveXML();
1243 }
1244 else {
1245 // To cope with embedded objects
1246 if (is_object($mixed)) {
1247 $mixed = get_object_vars($mixed);
1248 }
1249 if (is_array($mixed)) {
1250 foreach ($mixed as $index => $mixedElement) {
1251 if (is_int($index)) {
1252 if ($index === 0) {
1253 $node = $domElement;
1254 }
1255 else {
1256 $node = $DOMDocument->createElement($domElement->tagName);
1257 $domElement->parentNode->appendChild($node);
1258 }
1259 }
1260 else {
1261 $plural = $DOMDocument->createElement($index);
1262 $domElement->appendChild($plural);
1263 $node = $plural;
1264 if (!(rtrim($index, 's') === $index)) {
1265 $singular = $DOMDocument->createElement(rtrim($index, 's'));
1266 $plural->appendChild($singular);
1267 $node = $singular;
1268 }
1269 }
1270
1271 wmvc_xml_encode($mixedElement, $node, $DOMDocument);
1272 }
1273 }
1274 else {
1275 $mixed = is_bool($mixed) ? ($mixed ? 'true' : 'false') : $mixed;
1276 $domElement->appendChild($DOMDocument->createTextNode($mixed));
1277 }
1278 }
1279 }
1280
1281 function wmvc_add_wp_image($filename_source, $parent_post_id = 0)
1282 {
1283 $file = $filename_source;
1284 $filename = basename($file);
1285
1286 $upload_file = wp_upload_bits($filename, null, file_get_contents($file));
1287 if (!$upload_file['error']) {
1288 $wp_filetype = wp_check_filetype($filename, null );
1289 $attachment = array(
1290 'post_mime_type' => $wp_filetype['type'],
1291 'post_parent' => $parent_post_id,
1292 'post_title' => preg_replace('/\.[^.]+$/', '', $filename),
1293 'post_content' => '',
1294 'post_status' => 'inherit'
1295 );
1296 $attachment_id = wp_insert_attachment( $attachment, $upload_file['file'], $parent_post_id );
1297 if (!is_wp_error($attachment_id)) {
1298 require_once(ABSPATH . "wp-admin" . '/includes/image.php');
1299 $attachment_data = wp_generate_attachment_metadata( $attachment_id, $upload_file['file'] );
1300 wp_update_attachment_metadata( $attachment_id, $attachment_data );
1301
1302 return $attachment_id;
1303 }
1304 }
1305
1306 return NULL;
1307 }
1308
1309 function wmvc_wp_paginate($total_items, $per_page = 10, $page_var = 'paged', $texts = array())
1310 {
1311 $current_page = 1;
1312
1313 if(isset($_GET[$page_var]))
1314 $current_page = intval(wmvc_xss_clean($_GET[$page_var]));
1315
1316 if(!isset($texts['previous_page']))$texts['previous_page'] = 'Previous page';
1317 if(!isset($texts['next_page']))$texts['next_page'] = 'Next page';
1318 if(!isset($texts['first_page']))$texts['first_page'] = 'First page';
1319 if(!isset($texts['last_page']))$texts['last_page'] = 'Last page';
1320 if(!isset($texts['items']))$texts['items'] = 'items';
1321
1322 if(empty($current_page))$current_page = 1;
1323
1324 // get url
1325 $url = strtok($_SERVER["REQUEST_URI"], '?');
1326 $qs_parameters = wmvc_xss_clean( $_GET );
1327 unset($qs_parameters[$page_var]);
1328
1329 $qs_part = http_build_query($qs_parameters);
1330 $url.='?'.$qs_part;
1331
1332 // total pages
1333 $total_pages = intval($total_items/$per_page+0.99);
1334 $output = '';
1335
1336 $output.= '<div class="tablenav-pages"><span class="displaying-num">'.esc_html($total_items).' '.esc_html($texts['items']).'</span>';
1337 $output.= '<span class="pagination-links">';
1338
1339 if($current_page != 1)
1340 $output.= '<a class="first-page button" href="'.esc_url($url).'"><span class="screen-reader-text">'.esc_html($texts['first_page']).'</span><span aria-hidden="true">«</span></a>';
1341
1342 if($current_page-1 > 0)
1343 {
1344 $output.= '<a class="prev-page button" href="'.esc_url($url).'&amp;'.esc_attr($page_var).'='.esc_attr(($current_page-1)).'"><span class="screen-reader-text">'.esc_html($texts['previous_page']).'</span><span aria-hidden="true">‹</span></a>';
1345 }
1346 else
1347 {
1348 $output.= '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">‹</span>';
1349 }
1350
1351 $output.= '<span class="screen-reader-text">Current Page</span><span id="table-paging" class="paging-input"><span class="tablenav-paging-text">'.esc_html($current_page).' of <span class="total-pages">'.esc_html(($total_pages) ? $total_pages : 1).'</span></span></span>';
1352
1353 if($current_page+1 <= $total_pages)
1354 {
1355 $output.= '<a class="next-page button" href="'.esc_url($url).'&amp;'.esc_attr($page_var).'='.esc_attr(($current_page+1)).'"><span class="screen-reader-text">'.esc_html($texts['next_page']).'</span><span aria-hidden="true">›</span></a>';
1356
1357 }
1358 else
1359 {
1360 $output.= '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">›</span>';
1361 }
1362
1363 if($current_page != $total_pages)
1364 $output.= '<a class="last-page button" href="'.esc_url($url).'&amp;'.esc_attr($page_var).'='.esc_attr($total_pages).'"><span class="screen-reader-text">'.esc_html($texts['last_page']).'</span><span aria-hidden="true">»</span></a>';
1365
1366 $output.= '</span></div>';
1367
1368 return $output;
1369 }
1370
1371 function wmvc_download_file($url, $save_file_loc, $data = array())
1372 {
1373 // Initialize the cURL session
1374 $ch = curl_init($url);
1375
1376 // Use basename() function to return
1377 // the base name of file
1378 $file_name = basename($url);
1379
1380 if(!file_exists(dirname($save_file_loc)))
1381 mkdir(dirname($save_file_loc));
1382
1383 // Open file
1384 $fp = fopen($save_file_loc, 'wb');
1385
1386 // It set an option for a cURL transfer
1387 curl_setopt($ch, CURLOPT_FILE, $fp);
1388 curl_setopt($ch, CURLOPT_HEADER, 0);
1389
1390 curl_setopt($ch, CURLOPT_POST, 1);
1391 curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
1392
1393 curl_setopt($ch, CURLOPT_HTTPHEADER, array(
1394 'Content-Type: multipart/form-data',
1395 ));
1396
1397 //Disable CURLOPT_SSL_VERIFYHOST and CURLOPT_SSL_VERIFYPEER by
1398 //setting them to false.
1399 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
1400 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
1401
1402 // Perform a cURL session
1403 $result = curl_exec($ch);
1404
1405 if(curl_errno($ch))
1406 {
1407 //exit(curl_error($ch));
1408 }
1409
1410 // Closes a cURL session and frees all resources
1411 curl_close($ch);
1412
1413 // Close file
1414 fclose($fp);
1415
1416 return $result;
1417 }
1418
1419 function wmvc_api_call($method, $url, $data, $headers = false){
1420 $curl = curl_init();
1421
1422 //$data = 'email=test';
1423
1424 switch ($method){
1425 case "POST":
1426 curl_setopt($curl, CURLOPT_POST, 1);
1427 if ($data)
1428 {
1429 curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
1430
1431 if($headers === FALSE)
1432 $headers = array('Content-Type: multipart/form-data');
1433 }
1434
1435 break;
1436 case "PUT":
1437 curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
1438 if ($data)
1439 curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
1440 break;
1441 default:
1442 if ($data)
1443 $url = sprintf("%s?%s", $url, http_build_query($data));
1444 }
1445 // OPTIONS:
1446 curl_setopt($curl, CURLOPT_URL, $url);
1447 if(!$headers){
1448 curl_setopt($curl, CURLOPT_HTTPHEADER, array(
1449 'Content-Type: application/json',
1450 ));
1451 }else{
1452 curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
1453 }
1454 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
1455 curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
1456
1457 //Disable CURLOPT_SSL_VERIFYHOST and CURLOPT_SSL_VERIFYPEER by
1458 //setting them to false.
1459 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
1460 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
1461
1462 // EXECUTE:
1463 $result = curl_exec($curl);
1464 if(!$result){return FALSE;}
1465 curl_close($curl);
1466 return $result;
1467 }
1468
1469 function wmvc_current_edit_url()
1470 {
1471 $query_string_array = wmvc_xss_clean( $_GET );
1472 unset($query_string_array['is_updated']);
1473
1474 return admin_url("admin.php?".http_build_query($query_string_array));
1475 }
1476
1477 function wmvc_stripslashes_deep($value)
1478 {
1479 $value = is_array($value) ?
1480 array_map('stripslashes_deep', $value) :
1481 stripslashes($value);
1482
1483 return $value;
1484 }
1485
1486 function wmvc_get_date($datetime = NULL, $default='timestamp')
1487 {
1488 if(is_null($datetime))
1489 {
1490 if($default == 'timestamp')
1491 {
1492 $datetime = current_time('timestamp');
1493 }
1494 else
1495 {
1496 return $default;
1497 }
1498 }
1499 else if(!is_numeric($datetime))
1500 {
1501 $datetime = strtotime($datetime);
1502 }
1503
1504 $date_format = get_option('date_format');
1505 $time_format = get_option('time_format');
1506 $date = date("{$date_format} {$time_format}", $datetime);
1507 return $date;
1508 }
1509
1510 if ( ! function_exists('wmvc_url_suffix'))
1511 {
1512 function wmvc_url_suffix($base_url, $extension_url="")
1513 {
1514 if(strpos($base_url,'?') !== FALSE){
1515 $base_url .='&';
1516 } else {
1517 $base_url .='?';
1518 }
1519 return $base_url.$extension_url;
1520 }
1521 }
1522
1523
1524 if ( ! function_exists('wmvc_filter_decimal'))
1525 {
1526 function wmvc_filter_decimal($string = '')
1527 {
1528 if(substr($string, -3, 3) == '.00') {
1529 return substr($string, 0, -3);
1530 }
1531
1532 return $string;
1533 }
1534 }
1535
1536 if(!function_exists('wmvc_get_option')) {
1537 /**
1538 * Cached and get wp options
1539 *
1540 * @param string option Option key
1541 * @return string alt or title
1542 */
1543
1544 function wmvc_get_option($option_key = '') {
1545 return get_option($option_key);
1546
1547 if(isset($options[$option_key])) {
1548 return $options[$option_key];
1549 }
1550
1551 $options[$option_key] = get_option($option_key);
1552
1553 return $options[$option_key];
1554 }
1555 }
1556
1557 if ( ! function_exists('wmvc_is_phone'))
1558 {
1559 // Validation phone "-+()0123456789"
1560 /**
1561 * @param string $value phone in string
1562 * @return bool
1563 */
1564
1565
1566 function wmvc_is_phone($value = '') {
1567 if(preg_match("/^[.+]{0,1}[0-9-)(]{0,25}$/", $value)) {
1568 return true;
1569 }
1570
1571 return false;
1572 }
1573 }
1574
1575
1576 ?>