PluginProbe
Tagembed: Social Media Feeds and Customer Reviews Widget / 4.5
Tagembed: Social Media Feeds and Customer Reviews Widget v4.5
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 5.7 All 42 releases
tagembed-widget / helper / helper.php

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

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