PluginProbe
Tagembed: Social Media Feeds and Customer Reviews Widget / 7.8
Tagembed: Social Media Feeds and Customer Reviews Widget v7.8
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
← All changes | helper/helper.php +88 -86 5.47.8 View file →
@@ -1,96 +1,98 @@
1 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;
2 +if (!defined('ABSPATH')) :
3 + exit;
4 +endif;
5 +function ___tagembed__wpApiCall($apiUrl, $body, $header = null)
6 +{
7 + $header = (null != $header ? $header : []);
8 + $args = ['body' => $body, 'timeout' => '30', 'redirection' => '5', 'httpversion' => '1.0', 'blocking' => true, 'headers' => $header, 'cookies' => []];
9 + $response = wp_remote_post($apiUrl, $args);
10 + if (is_wp_error($response)) :
11 + return;
12 + endif;
13 + if (isset($response['body']) && !empty($response['body'])) :
14 + return json_decode($response['body']);
15 + endif;
16 + return;
15 17 }
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 - }
18 +function ___tagembed__manageApiResponse($response)
19 +{
20 + if (empty($response->head)) :
21 + return ___tagembed__exitWithDanger();
22 + endif;
23 + $responseCode = $response->head->code;
24 + switch ($responseCode) {
25 + case 200:
26 + if ($response->head->status) :
27 + if (!empty($response->body)) :
28 + return $response->body;
29 + endif;
30 + if (!empty($response->head->message)) :
31 + return ___tagembed__exitWithSuccess($response->head->message);
32 + else :
33 + return ___tagembed__exitWithSuccess();
34 + endif;
35 + else :
36 + if (!empty($response->head->message)) :
37 + return ___tagembed__exitWithDanger($response->head->message);
38 + else :
39 + return ___tagembed__exitWithDanger();
40 + endif;
41 + endif;
42 + break;
43 + case 412:
44 + /* --Start-- Manage Validation Error */
45 + if (empty($response->body)) :
46 + return ___tagembed__exitWithDanger();
47 + else :
48 + return ___tagembed__exitWithDanger('Validation Error', $response->body);
49 + endif;
50 + /* --End-- Manage Validation Error */
51 + break;
52 + default:
53 + if (!empty($response->head->message)) :
54 + return ___tagembed__exitWithDanger($response->head->message);
55 + else :
56 + return ___tagembed__exitWithDanger();
57 + endif;
58 + }
48 59 }
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;
60 +
61 +function ___tagembed__exitWithSuccess($data = null)
62 +{
63 + wp_send_json(['status' => (bool)true, 'data' => (array)$data, 'message' => (string)'OK']);
57 64 }
58 -function __tagembed__exitWithSuccess($data = null) {
59 - echo wp_json_encode(['status' => (bool) true, 'data' => (array) $data, 'message' => (string) 'OK']);
60 - exit;
65 +function ___tagembed__exitWithDanger($error = null, $data = [])
66 +{
67 + wp_send_json(['status' => (bool)false, 'data' => (array)$data, 'message' => (string)('' != $error ? $error : 'Oh snap! Something went wrong.')]);
61 68 }
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 -}
69 +
81 70 /* --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.");
71 +function ___tagembed__inputSanetize($data)
72 +{
73 + if (is_array($data)) :
74 + foreach ($data as $__tagembed__input_sanetize_item) :
75 + ___tagembed__inputSanetize($__tagembed__input_sanetize_item);
76 + endforeach;
77 + return;
78 + endif;
79 + $data = (string)$data;
80 + if (preg_match('/<[^>]*>/', $data)) :
81 + return ___tagembed__exitWithDanger('Special characters are not allowed. Please remove them and try again.');
82 + endif;
86 83 }
87 84 /* --End Sanetize All Input */
88 85 /* --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;
86 +function ___tagembed__sanitizeRequestData($__tagembed__request_input_data)
87 +{
88 + $__tagembed__Input_return_data = [];
89 + foreach ($__tagembed__request_input_data as $__tagembed__request_input_key => $__tagembed__request_input) :
90 + if (is_array($__tagembed__request_input)) :
91 + $__tagembed__Input_return_data[$__tagembed__request_input_key] = ___tagembed__sanitizeRequestData($__tagembed__request_input);
92 + else :
93 + $__tagembed__Input_return_data[$__tagembed__request_input_key] = sanitize_text_field($__tagembed__request_input);
94 + endif;
95 + endforeach;
96 + return $__tagembed__Input_return_data;
95 97 }
96 -/*--End-- Sanitize Request Data*/
98 +/*--End-- Sanitize Request Data*/