-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added API class and support for settings within YAML config
- Loading branch information
1 parent
06ba8e7
commit f1105af
Showing
3 changed files
with
110 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of SilverWare. | ||
* | ||
* PHP version >=5.6.0 | ||
* | ||
* For full copyright and license information, please view the | ||
* LICENSE.md file that was distributed with this source code. | ||
* | ||
* @package SilverWare\Google\API | ||
* @author Colin Tucker <[email protected]> | ||
* @copyright 2017 Praxis Interactive | ||
* @license https://opensource.org/licenses/BSD-3-Clause BSD-3-Clause | ||
* @link https://github.com/praxisnetau/silverware-google | ||
*/ | ||
|
||
namespace SilverWare\Google\API; | ||
|
||
use SilverStripe\Core\Config\Configurable; | ||
use SilverStripe\Core\Injector\Injectable; | ||
use SilverStripe\SiteConfig\SiteConfig; | ||
|
||
/** | ||
* An object to encapsulate Google API data and methods. | ||
* | ||
* @package SilverWare\Google\API | ||
* @author Colin Tucker <[email protected]> | ||
* @copyright 2017 Praxis Interactive | ||
* @license https://opensource.org/licenses/BSD-3-Clause BSD-3-Clause | ||
* @link https://github.com/praxisnetau/silverware-google | ||
*/ | ||
class GoogleAPI | ||
{ | ||
use Injectable; | ||
use Configurable; | ||
|
||
/** | ||
* Answers the API language from site or YAML configuration. | ||
* | ||
* @return string | ||
*/ | ||
public function getAPILanguage() | ||
{ | ||
$lang = SiteConfig::current_site_config()->GoogleAPILanguage; | ||
|
||
if (!$lang) { | ||
$lang = self::config()->api_language; | ||
} | ||
|
||
return $lang; | ||
} | ||
|
||
/** | ||
* Answers the analytics tracking ID from site or YAML configuration. | ||
* | ||
* @return string | ||
*/ | ||
public function getAnalyticsTrackingID() | ||
{ | ||
$id = SiteConfig::current_site_config()->GoogleAnalyticsTrackingID; | ||
|
||
if (!$id) { | ||
$id = self::config()->analytics_tracking_id; | ||
} | ||
|
||
return $id; | ||
} | ||
|
||
/** | ||
* Answers the site verification code from site or YAML configuration. | ||
* | ||
* @return string | ||
*/ | ||
public function getVerificationCode() | ||
{ | ||
$code = SiteConfig::current_site_config()->GoogleVerificationCode; | ||
|
||
if (!$code) { | ||
$code = self::config()->verification_code; | ||
} | ||
|
||
return $code; | ||
} | ||
|
||
/** | ||
* Answers true if analytics is enabled for the site. | ||
* | ||
* @return boolean | ||
*/ | ||
public function isAnalyticsEnabled() | ||
{ | ||
$enabled = SiteConfig::current_site_config()->GoogleAnalyticsEnabled; | ||
|
||
if (!$enabled) { | ||
$enabled = self::config()->analytics_enabled; | ||
} | ||
|
||
return (boolean) $enabled; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters