PluginProbe
Tagembed: Social Media Feeds and Customer Reviews Widget / 7.4
Tagembed: Social Media Feeds and Customer Reviews Widget v7.4
7.8 7.5 7.6 7.7 7.4 trunk 3.10 3.9 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5.0 5.1 5.2 5.3 5.4 5.5 5.6 All 43 releases
tagembed-widget / helper / helper.php

helper.php in Tagembed: Social Media Feeds and Customer Reviews Widget 7.4, at helper/helper.php

121 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 function ___tagembed__wpApiCall($apiUrl, $body, $header = null, $breakResponse = false)
3 {
4 $header = (null != $header ? $header : []);
5 $args = ['body' => $body, 'timeout' => '30', 'redirection' => '5', 'httpversion' => '1.0', 'blocking' => true, 'headers' => $header, 'cookies' => []];
6 $response = wp_remote_post($apiUrl, $args);
7 if ($breakResponse) :
8 ___tagembed__dd($response);
9 endif;
10 if (!is_wp_error($response)) :
11 if (isset($response['body']) && !empty($response['body'])) :
12 return json_decode($response['body']);
13 else :
14 return;
15 endif;
16 else :
17 ___tagembed__wpApiCall($apiUrl, $body, $header = null, $breakResponse = false);
18 endif;
19 }
20 function ___tagembed__manageApiResponse($response)
21 {
22 if (empty($response->head)) :
23 return ___tagembed__exitWithDanger();
24 endif;
25 $responseCode = $response->head->code;
26 switch ($responseCode) {
27 case 200:
28 if ($response->head->status) :
29 if (!empty($response->body)) :
30 return $response->body;
31 endif;
32 if (!empty($response->head->message)) :
33 return ___tagembed__exitWithSuccess($response->head->message);
34 else :
35 return ___tagembed__exitWithSuccess();
36 endif;
37 else :
38 if (!empty($response->head->message)) :
39 return ___tagembed__exitWithDanger($response->head->message);
40 else :
41 return ___tagembed__exitWithDanger();
42 endif;
43 endif;
44 break;
45 case 412:
46 /* --Start-- Manage Validation Error */
47 if (empty($response->body)) :
48 return ___tagembed__exitWithDanger();
49 else :
50 return ___tagembed__exitWithDanger('Validation Error', $response->body);
51 endif;
52 /* --End-- Manage Validation Error */
53 break;
54 default:
55 if (!empty($response->head->message)) :
56 return ___tagembed__exitWithDanger($response->head->message);
57 else :
58 return ___tagembed__exitWithDanger();
59 endif;
60 }
61 }
62 function ___tagembed__IsBase64($data)
63 {
64 $decoded_data = base64_decode($data, true);
65 $encoded_data = base64_encode($decoded_data);
66 if ($encoded_data != $data) :
67 return false;
68 elseif (!ctype_print($decoded_data)) :
69 return false;
70 else :
71 return true;
72 endif;
73 }
74 function ___tagembed__exitWithSuccess($data = null)
75 {
76 echo wp_json_encode(['status' => (bool)true, 'data' => (array)$data, 'message' => (string)'OK']);
77 exit;
78 }
79 function ___tagembed__exitWithDanger($error = null, $data = [])
80 {
81 echo wp_json_encode(['status' => (bool)false, 'data' => (array)$data, 'message' => (string)('' != $error ? $error : 'Oh snap! Something went wrong.')]);
82 exit;
83 }
84 function ___tagembed__d($data = 'NONE')
85 {
86 echo '<pre>';
87 print_r($data);
88 echo '</pre>';
89 }
90 function ___tagembed__dd($data = 'NONE')
91 {
92 echo '<pre>';
93 print_r($data);
94 echo '</pre>';
95 die;
96 }
97 function ___tagembed__convertObjectToArray($data)
98 {
99 $data = wp_json_encode($data);
100 return json_decode($data, true);
101 }
102 /* --Start__ Sanetize All Input */
103 function ___tagembed__inputSanetize($data)
104 {
105 $data = (string)$data;
106 if (preg_match('/<[^>]*>/', $data)) :
107 return ___tagembed__exitWithDanger('Special characters are not allowed. Please remove them and try again.');
108 endif;
109 }
110 /* --End Sanetize All Input */
111 /* --Start-- Sanitize Request Data */
112 function ___tagembed__sanitizeRequestData($__tagembed__request_input_data)
113 {
114 $__tagembed__Input_return_data = [];
115 foreach ($__tagembed__request_input_data as $__tagembed__request_input_key => $__tagembed__request_input) :
116 $__tagembed__Input_return_data[$__tagembed__request_input_key] = sanitize_text_field($__tagembed__request_input);
117 endforeach;
118 return $__tagembed__Input_return_data;
119 }
120 /*--End-- Sanitize Request Data*/
121