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-api-old.php
widget-google-reviews / includes / core Last commit date
class-connect-helper.php 1 year ago class-core.php 10 months ago class-database.php 10 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 10 months ago class-google-utils.php 1 year ago
class-google-api-old.php
107 lines
1 <?php
2
3 namespace WP_Rplg_Google_Reviews\Includes\Core;
4
5 class Google_Api_Old {
6
7 private $dao;
8 private $helper;
9
10 public function __construct(Google_Dao $dao, Connect_Helper $helper) {
11 $this->dao = $dao;
12 $this->helper = $helper;
13 }
14
15 public function connect($pid, $lang, $key, $local_img = false) {
16 // First call with default sorting method
17 $url = $this->url($pid, $lang, $key);
18 $this->call($url, $key, $local_img);
19
20 // Second call with default 'newest' sorting method
21 $result = $this->refresh($pid, $lang, $key, $local_img);
22
23 return $result;
24 }
25
26 public function refresh($pid, $lang, $key, $local_img = false) {
27 // Second call with default 'newest' sorting method
28 $url = $this->url($pid, $lang, $key, 'newest');
29 $result = $this->call($url, $key, $local_img);
30
31 return $result;
32 }
33
34 public function place($pid, $lang, $key) {
35 $url = $this->url($pid, $lang, $key);
36 $result = $this->call($url, $key, false, false);
37
38 return $result;
39 }
40
41 public function call($url, $key = null, $local_img = false, $db_save = true) {
42 $res = wp_remote_get($url);
43 $body = wp_remote_retrieve_body($res);
44 $json = json_decode($body);
45
46 if ($json && isset($json->result) && isset($json->result->rating)) {
47 $data = $json->result;
48
49 if ($key) {
50 $photo = $this->photo($data, $key);
51 $data->business_photo = $photo;
52 }
53
54 if ($db_save) {
55 $this->dao->save($data, $local_img);
56 }
57
58 $result = array(
59 'id' => $data->place_id,
60 'name' => $data->name,
61 'rating' => $data->rating,
62 'user_ratings_total' => $data->user_ratings_total,
63 'photo' => isset($data->business_photo) && strlen($data->business_photo) ? $data->business_photo : GRW_GOOGLE_BIZ,
64 'reviews' => isset($data->reviews) ? $data->reviews : null
65 );
66 if (isset($data->map_url) && strlen($data->map_url) > 0) {
67 $result['map_url'] = $data->map_url;
68 }
69 $status = 'success';
70 } else {
71 if (isset($json->error_message)) {
72 $result = array('error_message' => $json->error_message);
73 } else {
74 $result = array('error_message' => 'The place you are trying to connect to does not have a rating yet.');
75 }
76 $status = 'failed';
77 }
78 return compact('status', 'result');
79 }
80
81 private function url($pid, $lang, $key = '', $reviews_sort = '') {
82 $url = GRW_GOOGLE_PLACE_API . 'details/json?placeid=' . $pid . '&key=' . $key;
83 if (strlen($lang) > 0) {
84 $url = $url . '&language=' . $lang;
85 }
86 if (strlen($reviews_sort) > 0) {
87 $url = $url . '&reviews_sort=' . $reviews_sort;
88 }
89 return $url;
90 }
91
92 private function photo($json, $key) {
93 if (isset($json->photos) && count($json->photos) > 0) {
94 $url = add_query_arg(
95 array(
96 'maxwidth' => '300',
97 'maxheight' => '300',
98 'photoreference' => $json->photos[0]->photo_reference,
99 'key' => $key
100 ),
101 'https://maps.googleapis.com/maps/api/place/photo'
102 );
103 return $this->helper->upload_image($url, $json->place_id);
104 }
105 return null;
106 }
107 }