PluginProbe ʕ •ᴥ•ʔ
Rich Showcase for Google Reviews / 6.4
Rich Showcase for Google Reviews v6.4
6.9.8 6.9.7 6.9.6 trunk 1.4 1.42 1.43 1.44 1.45 1.46 1.47 1.48 1.49 1.5 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.7 1.6.8 1.6.9 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9 1.9.1 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3 2.4 2.4.1 2.4.2 2.5 2.5.1 2.6 2.6.1 2.6.2 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.6.1 3.7 3.8 3.9 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.8.1 4.8.2 5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.7.1 5.8 5.9 5.9.1 5.9.2 5.9.3 5.9.7 6.0 6.1 6.2 6.3 6.4 6.4.1 6.5 6.6 6.6.1 6.6.2 6.7 6.8 6.8.1 6.8.2 6.9 6.9.1 6.9.2 6.9.3 6.9.4 6.9.4.1 6.9.4.2 6.9.4.3 6.9.4.4 6.9.5
widget-google-reviews / includes / core / class-google-connect.php
widget-google-reviews / includes / core Last commit date
class-connect-helper.php 1 year ago class-core.php 11 months ago class-database.php 11 months ago class-google-api-new.php 1 year ago class-google-api-old.php 11 months ago class-google-connect.php 11 months ago class-google-dao.php 11 months ago class-google-utils.php 1 year ago
class-google-connect.php
210 lines
1 <?php
2
3 namespace WP_Rplg_Google_Reviews\Includes\Core;
4
5 class Google_Connect {
6
7 private $api_old;
8 private $api_new;
9
10 public function __construct(Google_Api_Old $api_old, Google_Api_New $api_new) {
11 $this->api_old = $api_old;
12 $this->api_new = $api_new;
13
14 add_action('wp_ajax_grw_hide_review', array($this, 'hide_review'));
15 add_action('wp_ajax_grw_connect_google', array($this, 'connect_google'));
16 add_action('wp_ajax_grw_place_autocomplete', array($this, 'place_autocomplete'));
17 add_action('wp_ajax_grw_get_place', array($this, 'get_place'));
18 }
19
20 public function hide_review() {
21 global $wpdb;
22
23 if (current_user_can('editor') || current_user_can('administrator')) {
24 if (isset($_POST['grw_wpnonce']) === false) {
25 $error = __('Unable to call request. Make sure you are accessing this page from the Wordpress dashboard.', 'widget-google-reviews');
26 $response = compact('error');
27 } else {
28 check_admin_referer('grw_wpnonce', 'grw_wpnonce');
29
30 $review = $wpdb->get_row(
31 $wpdb->prepare(
32 "SELECT * FROM " . $wpdb->prefix . Database::REVIEW_TABLE .
33 " WHERE id = %d", $_POST['id']
34 )
35 );
36
37 $hide = $review->hide == '' ? 'y' : '';
38 $wpdb->update($wpdb->prefix . Database::REVIEW_TABLE, array('hide' => $hide), array('id' => $_POST['id']));
39
40 // Cache clear
41 if (isset($_POST['feed_id'])) {
42 delete_transient('grw_feed_' . GRW_VERSION . '_' . $_POST['feed_id'] . '_reviews', false);
43 } else {
44 $feed_ids = get_option('grw_feed_ids');
45 if (!empty($feed_ids)) {
46 $ids = explode(",", $feed_ids);
47 foreach ($ids as $id) {
48 delete_transient('grw_feed_' . GRW_VERSION . '_' . $id . '_reviews', false);
49 }
50 }
51 }
52
53 $response = array('hide' => $hide);
54 }
55 header('Content-type: text/javascript');
56 echo json_encode($response);
57 die();
58 }
59 }
60
61 public function connect_google() {
62 if (current_user_can('manage_options')) {
63
64 $response = null;
65
66 if (isset($_POST['grw_wpnonce']) === false) {
67 $error = __('Unable to call request. Make sure you are accessing this page from the Wordpress dashboard.', 'widget-google-reviews');
68 $response = compact('error');
69 } else {
70 check_admin_referer('grw_wpnonce', 'grw_wpnonce');
71
72 if (isset($_POST['key'])) {
73 $key = sanitize_text_field(wp_unslash($_POST['key']));
74 if (strlen($key) > 0) {
75 update_option('grw_google_api_key', $key);
76 }
77 }
78
79 $pid = sanitize_text_field(wp_unslash($_POST['id']));
80 $lang = sanitize_text_field(wp_unslash($_POST['lang']));
81 $local_img = sanitize_text_field(wp_unslash($_POST['local_img']));
82 $key = get_option('grw_google_api_key');
83
84 if ($key && strlen($key) > 0) {
85
86 $gpa_old = get_option('grw_gpa_old');
87 if ($gpa_old === 'true') {
88 $response = $this->api_old->connect($pid, $lang, $key, $local_img);
89 } else {
90 $response = $this->api_new->connect($pid, $lang, $key, $local_img);
91 }
92
93 } else {
94 $token = isset($_POST['token']) ? sanitize_text_field(wp_unslash($_POST['token'])) : null;
95 if (strlen($token) > 0) {
96 $siteurl = get_option('siteurl');
97 $authcode = get_option('grw_auth_code');
98 $url = 'https://app.richplugins.com/gpaw2/get/json?' .
99 'pid=' . $pid . '&token=' . $token .
100 '&siteurl=' . $siteurl . '&authcode=' . $authcode .
101 ($lang && strlen($lang) > 0 ? '&lang=' . $lang : '');
102
103 if (isset($_POST['map_url'])) {
104 $map_url = sanitize_text_field(wp_unslash($_POST['map_url']));
105 $url .= ('&map_url=' . rawurlencode($map_url));
106 }
107
108 $response = $this->api_old->call($url, null, $local_img);
109 }
110 }
111
112 if (isset($_POST['feed_id'])) {
113 delete_transient('grw_feed_' . GRW_VERSION . '_' . $_POST['feed_id'] . '_reviews', false);
114 }
115 }
116
117 header('Content-type: text/javascript');
118 echo json_encode($response);
119 die();
120 }
121 }
122
123 public function place_autocomplete() {
124 if (current_user_can('manage_options')) {
125 if (isset($_POST['grw_nonce']) === false) {
126 $error = __('Unable to call request. Make sure you are accessing this page from the Wordpress dashboard.', 'widget-google-reviews');
127 $result = compact('error');
128 } else {
129 check_admin_referer('grw_wpnonce', 'grw_nonce');
130
131 $key = get_option('grw_google_api_key');
132 if (strlen($key) > 0) {
133 $input = sanitize_text_field(wp_unslash($_POST['input']));
134 $url = GRW_GOOGLE_PLACE_API . 'autocomplete/json?input=' . $input . '&types=establishment&key=' . $key;
135 $res = wp_remote_get($url);
136 $body = wp_remote_retrieve_body($res);
137 $result = json_decode($body);
138 }
139 }
140
141 header('Content-type: text/json');
142 echo json_encode($result);
143 wp_die();
144 }
145 }
146
147 public function get_place() {
148 if (current_user_can('manage_options')) {
149
150 $response = null;
151
152 if (isset($_POST['grw_nonce']) === false) {
153 $error = __('Unable to call request. Make sure you are accessing this page from the Wordpress dashboard.', 'widget-google-reviews');
154 $response = compact('error');
155 } else {
156 check_admin_referer('grw_wpnonce', 'grw_nonce');
157
158 $pid = sanitize_text_field(wp_unslash($_POST['pid']));
159 $lang = isset($_POST['lang']) ? sanitize_text_field(wp_unslash($_POST['lang'])) : null;
160 $key = get_option('grw_google_api_key');
161
162 if ($key && strlen($key) > 0) {
163
164 $gpa_old = get_option('grw_gpa_old');
165 if ($gpa_old === 'true') {
166 $response = $this->api_old->place($pid, $lang, $key);
167 } else {
168 $response = $this->api_new->place($pid, $lang, $key);
169 }
170
171 } else {
172 $token = isset($_POST['token']) ? sanitize_text_field(wp_unslash($_POST['token'])) : null;
173 if (strlen($token) > 0) {
174 $siteurl = get_option('siteurl');
175 $authcode = get_option('grw_auth_code');
176
177 $url = 'https://app.richplugins.com/gpaw2/place/json?' .
178 'pid=' . $pid . '&token=' . $token .
179 '&siteurl=' . $siteurl . '&authcode=' . $authcode .
180 ($lang && strlen($lang) > 0 ? '&lang=' . $lang : '');
181
182 $response = $this->api_old->call($url, null, $local_img, false);
183 }
184 }
185 }
186
187 header('Content-type: text/json');
188 echo json_encode($response);
189 wp_die();
190 }
191 }
192
193 public function refresh($args) {
194 $pid = $args[0];
195 $lang = $args[1];
196 $local_img = isset($args[2]) ? $args[2] : 'false';
197
198 $key = get_option('grw_google_api_key');
199 if ($key && strlen($key) > 0) {
200
201 $gpa_old = get_option('grw_gpa_old');
202 if ($gpa_old === 'true') {
203 $response = $this->api_old->refresh($pid, $lang, $key, $local_img);
204 } else {
205 $response = $this->api_new->connect($pid, $lang, $key, $local_img);
206 }
207 }
208 }
209
210 }