PluginProbe
Tagembed: Social Media Feeds and Customer Reviews Widget / 5.4
Tagembed: Social Media Feeds and Customer Reviews Widget v5.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 5.4, at helper/helper.php

96 lines 3.8 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 $header = (($header != NULL) ? $header : []);
4 $args = ['body' => $body, 'timeout' => '5', 'redirection' => '5', 'httpversion' => '1.0', 'blocking' => true, 'headers' => $header, 'cookies' => []];
5 $response = wp_remote_post($apiUrl, $args);
6 if ($breakResponse)
7 __tagembed__dd($response);
8 if (!is_wp_error($response)):
9 if (isset($response['body']) && !empty($response['body']))
10 return json_decode($response['body']);
11 return;
12 else:
13 __tagembed__wpApiCall($apiUrl, $body, $header = NULL, $breakResponse = false);
14 endif;
15 }
16 function __tagembed__manageApiResponse($response) {
17 if (empty($response->head))
18 return __tagembed__exitWithDanger();
19 $responseCode = $response->head->code;
20 switch ($responseCode) {
21 case 200:
22 if ($response->head->status):
23 if (!empty($response->body))
24 return $response->body;
25 if (!empty($response->head->message))
26 return __tagembed__exitWithSuccess($response->head->message);
27 return __tagembed__exitWithSuccess();
28 else :
29 if (!empty($response->head->message))
30 return __tagembed__exitWithDanger($response->head->message);
31 return __tagembed__exitWithDanger();
32 endif;
33 break;
34 case 412:
35 /* --Start-- Manage Validation Error */
36 if (empty($response->body))
37 return __tagembed__exitWithDanger();
38 return __tagembed__exitWithDanger("Validation Error", $response->body);
39 /* --End-- Manage Validation Error */
40 break;
41 default:
42 if (!empty($response->head->message)):
43 return __tagembed__exitWithDanger($response->head->message);
44 else:
45 return __tagembed__exitWithDanger();
46 endif;
47 }
48 }
49 function __tagembed__IsBase64($data) {
50 $decoded_data = base64_decode($data, true);
51 $encoded_data = base64_encode($decoded_data);
52 if ($encoded_data != $data)
53 return false;
54 else if (!ctype_print($decoded_data))
55 return false;
56 return true;
57 }
58 function __tagembed__exitWithSuccess($data = null) {
59 echo wp_json_encode(['status' => (bool) true, 'data' => (array) $data, 'message' => (string) 'OK']);
60 exit;
61 }
62 function __tagembed__exitWithDanger($error = null, $data = []) {
63 echo wp_json_encode(['status' => (bool) false, 'data' => (array) $data, 'message' => (string) (($error != '') ? $error : 'Oh snap! Something went wrong.')]);
64 exit;
65 }
66 function __tagembed__d($data = 'NONE') {
67 echo "<pre>";
68 print_r($data);
69 echo "</pre>";
70 }
71 function __tagembed__dd($data = 'NONE') {
72 echo "<pre>";
73 print_r($data);
74 echo "</pre>";
75 die;
76 }
77 function __tagembed__convertObjectToArray($data) {
78 $data = wp_json_encode($data);
79 return json_decode($data, true);
80 }
81 /* --Start__ Sanetize All Input */
82 function __tagembed__inputSanetize($data) {
83 $data = (string) $data;
84 if (preg_match("/<[^>]*>/", $data))
85 return __tagembed__exitWithDanger("Special characters are not allowed. Please remove them and try again.");
86 }
87 /* --End Sanetize All Input */
88 /* --Start-- Sanitize Request Data */
89 function __tagembed__sanitizeRequestData($__tagembed__request_input_data) {
90 $__tagembed__Input_return_data = [];
91 foreach ($__tagembed__request_input_data as $__tagembed__request_input_key => $__tagembed__request_input):
92 $__tagembed__Input_return_data[$__tagembed__request_input_key] = sanitize_text_field($__tagembed__request_input);
93 endforeach;
94 return $__tagembed__Input_return_data;
95 }
96 /*--End-- Sanitize Request Data*/