PluginProbe
WP Directory Kit / 1.3.6
WP Directory Kit v1.3.6
1.5.9 1.5.7 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 All 37 releases
wpdirectorykit / vendor / Winter_MVC / core / helpers.php

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

1,577 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 $data = preg_replace("/alert\(/", "", $data);
1155
1156 do
1157 {
1158 // Remove really unwanted tags
1159 $old_data = $data;
1160 $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);
1161 }
1162 while ($old_data !== $data);
1163
1164 //$data = sanitize_textarea_field($data);
1165
1166 // we are done...
1167 return $data;
1168 }
1169
1170 function wmvc_xss_clean_array($array)
1171 {
1172 if(!is_array($array))return array();
1173
1174 $arr_cleaned = array();
1175 foreach($array as $key=>$val)
1176 {
1177 if($key == 'newcontent')
1178 {
1179 $arr_cleaned[wmvc_xss_clean($key)] = $val;
1180 }
1181 else
1182 {
1183 $arr_cleaned[wmvc_xss_clean($key)] = wmvc_xss_clean($val);
1184 }
1185
1186 }
1187
1188 //dump($arr_cleaned);
1189
1190 return $arr_cleaned;
1191 }
1192
1193 function wmvc_xss_clean_object($object)
1194 {
1195 if(!is_object($object))return NULL;
1196
1197 $array = get_object_vars($object);
1198 foreach($array as $key=>$val)
1199 {
1200 $object->{$key} = wmvc_xss_clean($object->{$key});
1201 }
1202
1203 return $object;
1204 }
1205
1206 function wmvc_roles_array() {
1207 $editable_roles = get_editable_roles();
1208 foreach ($editable_roles as $role => $details) {
1209 $sub['role'] = esc_attr($role);
1210 $sub['name'] = translate_user_role($details['name']);
1211 $roles[] = $sub;
1212 }
1213 return $roles;
1214 }
1215
1216 function wmvc_seconds_to_hms($seconds, $show_days=true) {
1217 $t = round($seconds);
1218 $days = floor($t/86400);
1219 $day_sec = $days*86400;
1220 $hours = floor( ($t-$day_sec) / (60 * 60) );
1221 $hour_sec = $hours*3600;
1222 $minutes = floor((($t-$day_sec)-$hour_sec)/60);
1223 $min_sec = $minutes*60;
1224 $sec = (($t-$day_sec)-$hour_sec)-$min_sec;
1225
1226 if($show_days)
1227 {
1228 return sprintf('%02d:%02d:%02d:%02d', $days, $hours, $minutes, $sec);
1229 }
1230
1231 // to show only hours, no days
1232 $hours = floor( ($t) / (60 * 60) );
1233 return sprintf('%02d:%02d:%02d', $hours, $minutes, $sec);
1234 }
1235
1236 function wmvc_xml_encode($array)
1237 {
1238
1239 if (is_null($DOMDocument)) {
1240 $DOMDocument =new DOMDocument;
1241 $DOMDocument->formatOutput = true;
1242 wmvc_xml_encode($mixed, $DOMDocument, $DOMDocument);
1243 echo $DOMDocument->saveXML();
1244 }
1245 else {
1246 // To cope with embedded objects
1247 if (is_object($mixed)) {
1248 $mixed = get_object_vars($mixed);
1249 }
1250 if (is_array($mixed)) {
1251 foreach ($mixed as $index => $mixedElement) {
1252 if (is_int($index)) {
1253 if ($index === 0) {
1254 $node = $domElement;
1255 }
1256 else {
1257 $node = $DOMDocument->createElement($domElement->tagName);
1258 $domElement->parentNode->appendChild($node);
1259 }
1260 }
1261 else {
1262 $plural = $DOMDocument->createElement($index);
1263 $domElement->appendChild($plural);
1264 $node = $plural;
1265 if (!(rtrim($index, 's') === $index)) {
1266 $singular = $DOMDocument->createElement(rtrim($index, 's'));
1267 $plural->appendChild($singular);
1268 $node = $singular;
1269 }
1270 }
1271
1272 wmvc_xml_encode($mixedElement, $node, $DOMDocument);
1273 }
1274 }
1275 else {
1276 $mixed = is_bool($mixed) ? ($mixed ? 'true' : 'false') : $mixed;
1277 $domElement->appendChild($DOMDocument->createTextNode($mixed));
1278 }
1279 }
1280 }
1281
1282 function wmvc_add_wp_image($filename_source, $parent_post_id = 0)
1283 {
1284 $file = $filename_source;
1285 $filename = basename($file);
1286
1287 $upload_file = wp_upload_bits($filename, null, file_get_contents($file));
1288 if (!$upload_file['error']) {
1289 $wp_filetype = wp_check_filetype($filename, null );
1290 $attachment = array(
1291 'post_mime_type' => $wp_filetype['type'],
1292 'post_parent' => $parent_post_id,
1293 'post_title' => preg_replace('/\.[^.]+$/', '', $filename),
1294 'post_content' => '',
1295 'post_status' => 'inherit'
1296 );
1297 $attachment_id = wp_insert_attachment( $attachment, $upload_file['file'], $parent_post_id );
1298 if (!is_wp_error($attachment_id)) {
1299 require_once(ABSPATH . "wp-admin" . '/includes/image.php');
1300 $attachment_data = wp_generate_attachment_metadata( $attachment_id, $upload_file['file'] );
1301 wp_update_attachment_metadata( $attachment_id, $attachment_data );
1302
1303 return $attachment_id;
1304 }
1305 }
1306
1307 return NULL;
1308 }
1309
1310 function wmvc_wp_paginate($total_items, $per_page = 10, $page_var = 'paged', $texts = array())
1311 {
1312 $current_page = 1;
1313
1314 if(isset($_GET[$page_var]))
1315 $current_page = intval(wmvc_xss_clean($_GET[$page_var]));
1316
1317 if(!isset($texts['previous_page']))$texts['previous_page'] = 'Previous page';
1318 if(!isset($texts['next_page']))$texts['next_page'] = 'Next page';
1319 if(!isset($texts['first_page']))$texts['first_page'] = 'First page';
1320 if(!isset($texts['last_page']))$texts['last_page'] = 'Last page';
1321 if(!isset($texts['items']))$texts['items'] = 'items';
1322
1323 if(empty($current_page))$current_page = 1;
1324
1325 // get url
1326 $url = strtok($_SERVER["REQUEST_URI"], '?');
1327 $qs_parameters = wmvc_xss_clean( $_GET );
1328 unset($qs_parameters[$page_var]);
1329
1330 $qs_part = http_build_query($qs_parameters);
1331 $url.='?'.$qs_part;
1332
1333 // total pages
1334 $total_pages = intval($total_items/$per_page+0.99);
1335 $output = '';
1336
1337 $output.= '<div class="tablenav-pages"><span class="displaying-num">'.esc_html($total_items).' '.esc_html($texts['items']).'</span>';
1338 $output.= '<span class="pagination-links">';
1339
1340 if($current_page != 1)
1341 $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>';
1342
1343 if($current_page-1 > 0)
1344 {
1345 $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>';
1346 }
1347 else
1348 {
1349 $output.= '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">‹</span>';
1350 }
1351
1352 $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>';
1353
1354 if($current_page+1 <= $total_pages)
1355 {
1356 $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>';
1357
1358 }
1359 else
1360 {
1361 $output.= '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">›</span>';
1362 }
1363
1364 if($current_page != $total_pages)
1365 $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>';
1366
1367 $output.= '</span></div>';
1368
1369 return $output;
1370 }
1371
1372 function wmvc_download_file($url, $save_file_loc, $data = array())
1373 {
1374 // Initialize the cURL session
1375 $ch = curl_init($url);
1376
1377 // Use basename() function to return
1378 // the base name of file
1379 $file_name = basename($url);
1380
1381 if(!file_exists(dirname($save_file_loc)))
1382 mkdir(dirname($save_file_loc));
1383
1384 // Open file
1385 $fp = fopen($save_file_loc, 'wb');
1386
1387 // It set an option for a cURL transfer
1388 curl_setopt($ch, CURLOPT_FILE, $fp);
1389 curl_setopt($ch, CURLOPT_HEADER, 0);
1390
1391 curl_setopt($ch, CURLOPT_POST, 1);
1392 curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
1393
1394 curl_setopt($ch, CURLOPT_HTTPHEADER, array(
1395 'Content-Type: multipart/form-data',
1396 ));
1397
1398 //Disable CURLOPT_SSL_VERIFYHOST and CURLOPT_SSL_VERIFYPEER by
1399 //setting them to false.
1400 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
1401 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
1402
1403 // Perform a cURL session
1404 $result = curl_exec($ch);
1405
1406 if(curl_errno($ch))
1407 {
1408 //exit(curl_error($ch));
1409 }
1410
1411 // Closes a cURL session and frees all resources
1412 curl_close($ch);
1413
1414 // Close file
1415 fclose($fp);
1416
1417 return $result;
1418 }
1419
1420 function wmvc_api_call($method, $url, $data, $headers = false){
1421 $curl = curl_init();
1422
1423 //$data = 'email=test';
1424
1425 switch ($method){
1426 case "POST":
1427 curl_setopt($curl, CURLOPT_POST, 1);
1428 if ($data)
1429 {
1430 curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
1431
1432 if($headers === FALSE)
1433 $headers = array('Content-Type: multipart/form-data');
1434 }
1435
1436 break;
1437 case "PUT":
1438 curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
1439 if ($data)
1440 curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
1441 break;
1442 default:
1443 if ($data)
1444 $url = sprintf("%s?%s", $url, http_build_query($data));
1445 }
1446 // OPTIONS:
1447 curl_setopt($curl, CURLOPT_URL, $url);
1448 if(!$headers){
1449 curl_setopt($curl, CURLOPT_HTTPHEADER, array(
1450 'Content-Type: application/json',
1451 ));
1452 }else{
1453 curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
1454 }
1455 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
1456 curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
1457
1458 //Disable CURLOPT_SSL_VERIFYHOST and CURLOPT_SSL_VERIFYPEER by
1459 //setting them to false.
1460 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
1461 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
1462
1463 // EXECUTE:
1464 $result = curl_exec($curl);
1465 if(!$result){return FALSE;}
1466 curl_close($curl);
1467 return $result;
1468 }
1469
1470 function wmvc_current_edit_url()
1471 {
1472 $query_string_array = wmvc_xss_clean( $_GET );
1473 unset($query_string_array['is_updated']);
1474
1475 return admin_url("admin.php?".http_build_query($query_string_array));
1476 }
1477
1478 function wmvc_stripslashes_deep($value)
1479 {
1480 $value = is_array($value) ?
1481 array_map('stripslashes_deep', $value) :
1482 stripslashes($value);
1483
1484 return $value;
1485 }
1486
1487 function wmvc_get_date($datetime = NULL, $default='timestamp')
1488 {
1489 if(is_null($datetime))
1490 {
1491 if($default == 'timestamp')
1492 {
1493 $datetime = current_time('timestamp');
1494 }
1495 else
1496 {
1497 return $default;
1498 }
1499 }
1500 else if(!is_numeric($datetime))
1501 {
1502 $datetime = strtotime($datetime);
1503 }
1504
1505 $date_format = get_option('date_format');
1506 $time_format = get_option('time_format');
1507 $date = date("{$date_format} {$time_format}", $datetime);
1508 return $date;
1509 }
1510
1511 if ( ! function_exists('wmvc_url_suffix'))
1512 {
1513 function wmvc_url_suffix($base_url, $extension_url="")
1514 {
1515 if(strpos($base_url,'?') !== FALSE){
1516 $base_url .='&';
1517 } else {
1518 $base_url .='?';
1519 }
1520 return $base_url.$extension_url;
1521 }
1522 }
1523
1524
1525 if ( ! function_exists('wmvc_filter_decimal'))
1526 {
1527 function wmvc_filter_decimal($string = '')
1528 {
1529 if(substr($string, -3, 3) == '.00') {
1530 return substr($string, 0, -3);
1531 }
1532
1533 return $string;
1534 }
1535 }
1536
1537 if(!function_exists('wmvc_get_option')) {
1538 /**
1539 * Cached and get wp options
1540 *
1541 * @param string option Option key
1542 * @return string alt or title
1543 */
1544
1545 function wmvc_get_option($option_key = '') {
1546 return get_option($option_key);
1547
1548 if(isset($options[$option_key])) {
1549 return $options[$option_key];
1550 }
1551
1552 $options[$option_key] = get_option($option_key);
1553
1554 return $options[$option_key];
1555 }
1556 }
1557
1558 if ( ! function_exists('wmvc_is_phone'))
1559 {
1560 // Validation phone "-+()0123456789"
1561 /**
1562 * @param string $value phone in string
1563 * @return bool
1564 */
1565
1566
1567 function wmvc_is_phone($value = '') {
1568 if(preg_match("/^[.+]{0,1}[0-9-)(]{0,25}$/", $value)) {
1569 return true;
1570 }
1571
1572 return false;
1573 }
1574 }
1575
1576
1577 ?>