diff --git a/lib/gplace.php b/lib/gplace.php
index eadf3b8..57f4281 100644
--- a/lib/gplace.php
+++ b/lib/gplace.php
@@ -7,17 +7,32 @@
*/
class gplace
{
+
+
/**
- * Bindet die Vendors ein - als Funktion, weil es sonst in der boot.php immer geladen werden müsste und das ist nicht nötig
- * @author Daniel Springer
+ * @return array
+ * https://developers.google.com/maps/documentation/places/web-service/details?hl=de
*/
- public static function includeVendors()
- {
- include_once rex_path::addon('mf_googleplaces', 'vendor/guzzlehttp/guzzle/src/functions.php');
- include_once rex_path::addon('mf_googleplaces', 'vendor/guzzlehttp/psr7/src/functions.php');
- include_once rex_path::addon('mf_googleplaces', 'vendor/guzzlehttp/promises/src/functions.php');
+ public static function gapi() {
+ $curl = curl_init();
+
+ curl_setopt_array($curl, array(
+ CURLOPT_URL => 'https://maps.googleapis.com/maps/api/place/details/json?place_id='.rex_addon::get('mf_googleplaces')->getConfig('gmaps-location-id').'&key='.rex_addon::get('mf_googleplaces')->getConfig('gmaps-api-key').'&reviews_no_translations=true&reviews_sort=newest',
+ CURLOPT_RETURNTRANSFER => true,
+ CURLOPT_ENCODING => '',
+ CURLOPT_MAXREDIRS => 10,
+ CURLOPT_TIMEOUT => 0,
+ CURLOPT_FOLLOWLOCATION => true,
+ CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
+ CURLOPT_CUSTOMREQUEST => 'GET',
+ ));
+ $response = curl_exec($curl);
+ $response = json_decode($response);
+ $response = json_decode(json_encode($response->result), true);
+ curl_close($curl);
+ return $response;
+ }
- } // EoF
/**
* Ruft Details zu einem Google Place direkt über die Google-PLaces-API ab.
@@ -27,19 +42,7 @@ public static function includeVendors()
*/
public static function get(string $qry = "")
{
- gplace::includeVendors();
- $place = new gplace;
- $place->apiKey = rex_addon::get('mf_googleplaces')->getConfig('gmaps-api-key');
- $place->placeId = rex_addon::get('mf_googleplaces')->getConfig('gmaps-location-id');
-
- $client = new \GooglePlaces\Client($place->apiKey);
- $response = $client->placeDetails($place->placeId)->request();
- if ($qry == "") {
- return $response['result'];
- } else {
- return $response['result'][$qry];
- }
-
+ return self::getFromGoogle($qry);
} // EoF
/**
@@ -50,17 +53,11 @@ public static function get(string $qry = "")
*/
public static function getFromGoogle(string $qry = "")
{
- gplace::includeVendors();
- $place = new gplace;
- $place->apiKey = rex_addon::get('mf_googleplaces')->getConfig('gmaps-api-key');
- $place->placeId = rex_addon::get('mf_googleplaces')->getConfig('gmaps-location-id');
-
- $client = new \GooglePlaces\Client($place->apiKey);
- $response = $client->placeDetails($place->placeId)->request('DE');
+ $response = self::gapi();
if ($qry == "") {
return $response;
} else {
- return $response['result'][$qry];
+ return $response[$qry];
}
} // EoF
@@ -70,14 +67,18 @@ public static function getFromGoogle(string $qry = "")
* @return array | false
* @author Daniel Springer
*/
- public static function getPlaceDetails()
+ public static function getPlaceDetails($qry = "")
{
$sql = rex_sql::factory();
$sql->setQuery('SELECT api_response_json FROM mf_googleplaces_place_details WHERE place_id = :place_id', ["place_id" => rex_addon::get('mf_googleplaces')->getConfig('gmaps-location-id')]);
if($sql->getRows() > 0) {
$response = $sql->getArray();
$response = rex_var::toArray($response[0]['api_response_json']);
- return $response['result'];
+ if ($qry == "") {
+ return $response;
+ } else {
+ return $response[$qry];
+ }
}
return false;
} // EoF getPlaceDetails
@@ -89,15 +90,8 @@ public static function getPlaceDetails()
*/
public static function getAllReviewsFromGoogle()
{
- gplace::includeVendors();
$qry = 'reviews';
- $place = new gplace;
- $place->apiKey = rex_addon::get('mf_googleplaces')->getConfig('gmaps-api-key');
- $place->placeId = rex_addon::get('mf_googleplaces')->getConfig('gmaps-location-id');
-
- $client = new \GooglePlaces\Client($place->apiKey);
- $response = $client->placeDetails($place->placeId)->request();
-
+ $response = self::gapi();
return $response['result'][$qry];
} // EoF
@@ -176,9 +170,8 @@ public static function getTotalRatings()
*/
public static function updateReviewsDB()
{
- gplace::includeVendors();
- $googleReviews = gplace::getAllReviewsFromGoogle();
$googlePlace = gplace::getFromGoogle();
+ $googleReviews = $googlePlace['reviews'];
$googlePlaceId = rex_addon::get('mf_googleplaces')->getConfig('gmaps-location-id');
foreach ($googleReviews as $gr) {
diff --git a/package.yml b/package.yml
index a10b01b..1e6d7b0 100644
--- a/package.yml
+++ b/package.yml
@@ -1,7 +1,7 @@
# Alle hier gesetzten Werte können über $addon->getProperty($key) abgefragt werden
package: mf_googleplaces
-version: '2.2'
+version: '2.3'
author: 'Medienfeuer, Daniel Springer'
compile: 0
diff --git a/pages/config.php b/pages/config.php
index 865234a..caba589 100644
--- a/pages/config.php
+++ b/pages/config.php
@@ -2,7 +2,7 @@
$content = '';
$buttons = '';
-
+dump(gplace::getPlaceDetails());
// Einstellungen speichern
if (rex_post('formsubmit', 'string') == '1') {
$this->setConfig(rex_post('baseconfig', [
@@ -12,8 +12,7 @@
]));
echo rex_view::success('Einstellungen gespeichert');
-}
-
+}
$content .= '