Skip to content

Commit

Permalink
V2.3
Browse files Browse the repository at this point in the history
- Vendors entfernt. Umbau auf CURL. Reduktion von Konflikten mit Guzzle-Versionen.
- Lokale Methoden ergänzt gplace::getPlaceDetails()
  • Loading branch information
danspringer committed May 30, 2023
1 parent 7272b79 commit b4c433f
Show file tree
Hide file tree
Showing 1,952 changed files with 47 additions and 178,038 deletions.
75 changes: 34 additions & 41 deletions lib/gplace.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

/**
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion package.yml
Original file line number Diff line number Diff line change
@@ -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

Expand Down
5 changes: 2 additions & 3 deletions pages/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
$content = '';
$buttons = '';


dump(gplace::getPlaceDetails());
// Einstellungen speichern
if (rex_post('formsubmit', 'string') == '1') {
$this->setConfig(rex_post('baseconfig', [
Expand All @@ -12,8 +12,7 @@
]));

echo rex_view::success('Einstellungen gespeichert');
}

}

$content .= '<fieldset>';

Expand Down
15 changes: 9 additions & 6 deletions pages/info.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<?php
$code = "";
$code .= "<?php" . PHP_EOL;
$code .= " //Ein Array mit dem gesamten Ergebnis zurückbekommen:" . PHP_EOL;
$code .= " dump( gplace::get() );" . PHP_EOL;
$code .= " //Ein Array mit dem gesamten Ergebnis aus der eigenen Datenbank zurückbekommen:" . PHP_EOL;
$code .= " dump( gplace::getPlaceDetails() );" . PHP_EOL;
$code .= PHP_EOL;
$code .= " //Den Namen des Place:" . PHP_EOL;
$code .= " echo gplace::get('name');" . PHP_EOL;
$code .= " echo gplace::getPlaceDetails('name');" . PHP_EOL;
$code .= PHP_EOL;
$code .= " //Anzahl User Bewertungen:" . PHP_EOL;
$code .= " echo gplace::get('user_rating_total');" . PHP_EOL;
$code .= " echo gplace::getPlaceDetails('user_rating_total');" . PHP_EOL;
$code .= PHP_EOL;
$code .= " //Ein Array mit dem gesamten Ergebnis direkt über die Google-API (kostenpflichtig) zurückbekommen:" . PHP_EOL;
$code .= " dump( gplace::get() );" . PHP_EOL;
$code .= PHP_EOL;
$code .= "?>";

Expand All @@ -21,8 +24,8 @@

if (rex_addon::get('mf_googleplaces')->getConfig('gmaps-api-key') && rex_addon::get('mf_googleplaces')->getConfig('gmaps-location-id')) {
echo '<h3>Array des konfigurierten Google Place</h3>
<p>Die einzelnen Werte können wie oben beschrieben über <code>gplace::get(\'name_des_wertes\')</code> geholt werden.</p>
<p>Die einzelnen Werte können wie oben beschrieben über <code>gplace::get(\'name_des_wertes\')</code> (kostenpflichtig über die Google-API) oder <code>gplace::getPlaceDetails(\'name_des_wertes\')</code> (gratis aus der eigenen DB) geholt werden.</p>
';
dump( gplace::get() );
dump( gplace::getPlaceDetails() );
}
?>
1 change: 1 addition & 0 deletions pages/reviews.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
$list->removeColumn('language');
$list->removeColumn('author_name');
$list->removeColumn('profile_photo_url');
$list->removeColumn('profile_photo_base64');
$list->removeColumn('author_url');
$list->removeColumn('createdate_addon');
$list->removeColumn('google_place_id');
Expand Down
7 changes: 0 additions & 7 deletions vendor/autoload.php

This file was deleted.

Loading

0 comments on commit b4c433f

Please sign in to comment.