Browse Source

Backport Google API key for maps.

mscherer 7 years ago
parent
commit
533cb7086a
2 changed files with 22 additions and 8 deletions
  1. 4 8
      Controller/Component/Auth/AuthUserTrait.php
  2. 18 0
      View/Helper/GoogleMapV3Helper.php

+ 4 - 8
Controller/Component/Auth/AuthUserTrait.php

@@ -170,16 +170,12 @@ trait AuthUserTrait {
 	 * This can be set via Right model and stored in the Auth array upon login
 	 * This can be set via Right model and stored in the Auth array upon login
 	 * the same way the roles are.
 	 * the same way the roles are.
 	 *
 	 *
-	 * @param mixed $role
-	 * @param mixed $providedRights
+	 * @param int $expectedRight
 	 * @return bool Success
 	 * @return bool Success
 	 */
 	 */
-	public function hasRight($expectedRight, $providedRights = null) {
-		if ($providedRights !== null) {
-			$rights = $providedRights;
-		} else {
-			$rights = $this->user(USER_RIGHT_KEY);
-		}
+	public function hasRight($expectedRight) {
+		$rights = $this->user(USER_RIGHT_KEY);
+
 		$rights = (array)$rights;
 		$rights = (array)$rights;
 		if (array_key_exists($expectedRight, $rights) && !empty($rights[$expectedRight])) {
 		if (array_key_exists($expectedRight, $rights) && !empty($rights[$expectedRight])) {
 			return true;
 			return true;

+ 18 - 0
View/Helper/GoogleMapV3Helper.php

@@ -110,9 +110,12 @@ class GoogleMapV3Helper extends AppHelper {
 	/**
 	/**
 	 * Default settings
 	 * Default settings
 	 *
 	 *
+	 * Set the key via Configure Google.key in your private (not commited) config file.
+	 *
 	 * @var array
 	 * @var array
 	 */
 	 */
 	protected $_defaultOptions = [
 	protected $_defaultOptions = [
+		'key' => '', // API Key, required since 2018
 		'zoom' => null, // global, both map and staticMap
 		'zoom' => null, // global, both map and staticMap
 		'lat' => null, // global, both map and staticMap
 		'lat' => null, // global, both map and staticMap
 		'lng' => null, // global, both map and staticMap
 		'lng' => null, // global, both map and staticMap
@@ -210,9 +213,18 @@ class GoogleMapV3Helper extends AppHelper {
 
 
 	protected $_located = false;
 	protected $_located = false;
 
 
+	/**
+	 * @param View|null $View
+	 * @param array $config
+	 */
 	public function __construct($View = null, $config = []) {
 	public function __construct($View = null, $config = []) {
 		$google = (array)Configure::read('Google');
 		$google = (array)Configure::read('Google');
 		$defaults = $this->_defaultOptions;
 		$defaults = $this->_defaultOptions;
+
+		if (!empty($google['key'])) {
+			$defaults['key'] = $google['key'];
+		}
+
 		if (!empty($google['api'])) {
 		if (!empty($google['api'])) {
 			$defaults['map']['api'] = $google['api'];
 			$defaults['map']['api'] = $google['api'];
 		}
 		}
@@ -266,6 +278,7 @@ class GoogleMapV3Helper extends AppHelper {
 	 * - region
 	 * - region
 	 *
 	 *
 	 * @param bool $sensor
 	 * @param bool $sensor
+	 * @param string|null $api
 	 * @param string $language (iso2: en, de, ja, ...)
 	 * @param string $language (iso2: en, de, ja, ...)
 	 * @param string $append (more key-value-pairs to append)
 	 * @param string $append (more key-value-pairs to append)
 	 * @return string Full URL
 	 * @return string Full URL
@@ -277,6 +290,11 @@ class GoogleMapV3Helper extends AppHelper {
 		if (!empty($language)) {
 		if (!empty($language)) {
 			$url .= '&language=' . $language;
 			$url .= '&language=' . $language;
 		}
 		}
+
+		if (!empty($this->settings['key'])) {
+			$url .= '&key='.$this->settings['key'];
+		}
+
 		if (!empty($api)) {
 		if (!empty($api)) {
 			$this->settings['map']['api'] = $api;
 			$this->settings['map']['api'] = $api;
 		}
 		}