Skip to content

Commit

Permalink
Merge pull request #4 from henkelund/1.2.0
Browse files Browse the repository at this point in the history
1.2.0
  • Loading branch information
henkelund authored Nov 7, 2016
2 parents e76de5c + 0047fde commit d1644ff
Show file tree
Hide file tree
Showing 10 changed files with 326 additions and 30 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 4

[*.md]
trim_trailing_whitespace = false

[.travis.yml]
indent_size = 2
12 changes: 8 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ language: php
php:
- 7.0
- 5.6
- 5.5
env:
- M2_VERSION=2.0.2
- M2_VERSION=2.0.1
- M2_VERSION=2.0.0
- M2_VERSION=2.1.2
- M2_VERSION=2.1.1
- M2_VERSION=2.1.0
- M2_VERSION=2.0.10
matrix:
include:
- php: 5.5
env: M2_VERSION=2.0.10
cache:
directories:
- $HOME/.composer/cache
Expand Down
4 changes: 2 additions & 2 deletions Block/Piwik.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function getJsOptions()
*/
public function getScriptUrl()
{
return $this->_dataHelper->getBaseUrl() . 'piwik.js';
return $this->_dataHelper->getJsScriptUrl();
}

/**
Expand All @@ -136,7 +136,7 @@ public function getScriptUrl()
*/
public function getTrackerUrl()
{
return $this->_dataHelper->getBaseUrl() . 'piwik.php';
return $this->_dataHelper->getPhpScriptUrl();
}

/**
Expand Down
117 changes: 110 additions & 7 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
*/
const XML_PATH_ENABLED = 'piwik/tracking/enabled';
const XML_PATH_HOSTNAME = 'piwik/tracking/hostname';
const XML_PATH_CDN_HOSTNAME = 'piwik/tracking/cdn_hostname';
const XML_PATH_JS_SCRIPT_PATH = 'piwik/tracking/js_script_path';
const XML_PATH_PHP_SCRIPT_PATH = 'piwik/tracking/php_script_path';
const XML_PATH_SITE_ID = 'piwik/tracking/site_id';
const XML_PATH_LINK_ENABLED = 'piwik/tracking/link_enabled';
const XML_PATH_LINK_DELAY = 'piwik/tracking/link_delay';
Expand Down Expand Up @@ -63,27 +66,127 @@ public function isTrackingEnabled($store = null)
*/
public function getHostname($store = null)
{
return $this->scopeConfig->getValue(
return trim($this->scopeConfig->getValue(
self::XML_PATH_HOSTNAME,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$store
);
));
}

/**
* Retrieve Piwik base URL
* Retrieve Piwik CDN hostname
*
* @param null|string|bool|int|Store $store
* @return string
*/
public function getCdnHostname($store = null)
{
return trim($this->scopeConfig->getValue(
self::XML_PATH_CDN_HOSTNAME,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$store
));
}

/**
* Retrieve base URL for given hostname
*
* @param string $host
* @param null|bool $secure
* @return string
*/
public function getBaseUrl($store = null, $secure = null)
protected function _getBaseUrl($host, $secure = null)
{
if (is_null($secure)) {
$secure = $this->_request->isSecure();
$secure = $this->_getRequest()->isSecure();
}
$host = rtrim($this->getHostname($store), '/');
return ($secure ? 'https://' : 'http://') . $host . '/';
if (false !== ($scheme = strpos($host, '://'))) {
$host = substr($host, $scheme + 3);
}
return ($secure ? 'https://' : 'http://') . rtrim($host, '/') . '/';
}

/**
* Retrieve Piwik base URL
*
* @param null|string|bool|int|Store $store
* @param null|bool $secure
* @return string
*/
public function getBaseUrl($store = null, $secure = null)
{
return $this->_getBaseUrl($this->getHostname($store), $secure);
}

/**
* Retrieve Piwik CDN URL
*
* @param null|string|bool|int|Store $store
* @param null|bool $secure
* @return string
*/
public function getCdnBaseUrl($store = null, $secure = null)
{
$host = $this->getCdnHostname($store);
return ('' !== $host)
? $this->_getBaseUrl($host, $secure)
: $this->getBaseUrl($store, $secure);
}

/**
* Retrieve Piwik tracker JS script path
*
* @param null|string|bool|int|Store $store
* @return string
*/
public function getJsScriptPath($store = null)
{
return trim($this->scopeConfig->getValue(
self::XML_PATH_JS_SCRIPT_PATH,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$store
), ' /') ?: 'piwik.js';
}

/**
* Retrieve Piwik tracker JS script URL
*
* @param null|string|bool|int|Store $store
* @param null|bool $secure
* @return string
*/
public function getJsScriptUrl($store = null, $secure = null)
{
return $this->getCdnBaseUrl($store, $secure)
. $this->getJsScriptPath($store);
}

/**
* Retrieve Piwik tracker PHP script path
*
* @param null|string|bool|int|Store $store
* @return string
*/
public function getPhpScriptPath($store = null)
{
return trim($this->scopeConfig->getValue(
self::XML_PATH_PHP_SCRIPT_PATH,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$store
), ' /') ?: 'piwik.php';
}

/**
* Retrieve Piwik tracker PHP script URL
*
* @param null|string|bool|int|Store $store
* @param null|bool $secure
* @return string
*/
public function getPhpScriptUrl($store = null, $secure = null)
{
return $this->getBaseUrl($store, $secure)
. $this->getPhpScriptPath($store);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ git clone https://github.com/henkelund/magento2-henhed-piwik.git app/code/Henhed
Or, if you prefer, install it using [Composer][composer].

```sh
composer config repositories.henhedpiwik git https://github.com/henkelund/magento2-henhed-piwik.git
composer require henhed/module-piwik:dev-master
composer require henhed/module-piwik
```

Finally, enable the module with the Magento CLI tool.
Expand Down
Loading

0 comments on commit d1644ff

Please sign in to comment.