diff --git a/core/View.php b/core/View.php index bc8ccf075aac5ab2c8b00d2e9a5bac93f0cd12a5..615bf3092d4fd057bbc6505122b345f1ace0d1fb 100644 --- a/core/View.php +++ b/core/View.php @@ -226,13 +226,16 @@ class View implements ViewInterface $this->latest_version_available = UpdateCheck::isNewestVersionAvailable(); $this->disableLink = Common::getRequestVar('disableLink', 0, 'int'); $this->isWidget = Common::getRequestVar('widget', 0, 'int'); + + $developmentModeEnabled = Development::isEnabled(); - if (Development::isEnabled()) { + if ($developmentModeEnabled) { $cacheBuster = rand(0, 10000); } else { $cacheBuster = UIAssetCacheBuster::getInstance()->piwikVersionBasedCacheBuster(); } + $this->isDevelopmentModeEnabled = $developmentModeEnabled; $this->cacheBuster = $cacheBuster; $this->loginModule = Piwik::getLoginPluginName(); diff --git a/plugins/CoreHome/angularjs/common/services/piwik-api.js b/plugins/CoreHome/angularjs/common/services/piwik-api.js index 0b708a1c22757f1b07df7df68b8a766b35f0f954..f9e5b225a3be913f0db23ae2dc2c732e7f232384 100644 --- a/plugins/CoreHome/angularjs/common/services/piwik-api.js +++ b/plugins/CoreHome/angularjs/common/services/piwik-api.js @@ -4,6 +4,10 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ + +// see https://github.com/piwik/piwik/issues/5094 used to detect an ad blocker +var hasBlockedContent = false; + (function () { angular.module('piwikApp.service').factory('piwikApi', piwikApiService); diff --git a/plugins/CoreHome/lang/en.json b/plugins/CoreHome/lang/en.json index 300c6fe15b46cd4e553774ec72ddc9d2cf6e8f36..637122effc73a0a2a3f98296ab0403075598f6a5 100644 --- a/plugins/CoreHome/lang/en.json +++ b/plugins/CoreHome/lang/en.json @@ -50,6 +50,7 @@ "UndoPivotBySubtable": "This report has been pivoted %s Undo pivot", "PivotBySubtable": "This report is not pivoted %s Pivot by %s", "QuickAccessTitle": "Search for menu entries, segments and websites. Shortcut: Press 'f' to search.", - "Segments": "Segments" + "Segments": "Segments", + "AdblockIsMaybeUsed": "In case you are using an ad blocker, please disable it for this site to make sure Piwik works without any issues." } } diff --git a/plugins/CoreHome/templates/_adblockDetect.twig b/plugins/CoreHome/templates/_adblockDetect.twig new file mode 100644 index 0000000000000000000000000000000000000000..5b8273a5d761b49acd4b4726531642477a92c1f6 --- /dev/null +++ b/plugins/CoreHome/templates/_adblockDetect.twig @@ -0,0 +1,31 @@ +<script type="text/javascript"> + if ('undefined' === (typeof hasBlockedContent) || hasBlockedContent !== false) { + (function () { + {# most likely jQuery is not available, have to use vanilla JS here #} + + {% if not isDevelopmentModeEnabled %} + {# if development mode is disabled it is most likely blocked because having piwik in pathname #} + {# if development mode is enabled it might be as well blocked because of not loaded piwik-api.js #} + if (location && location.pathname && -1 === location.pathname.indexOf('piwik')) { + // it is most likely not an issue related to ad blocker, maybe failed to load from server + return; + } + {% endif %} + + var body = document.getElementsByTagName('body'); + + if (!body || !body[0]) { + return; + } + + var warning = document.createElement('h3'); + warning.innerHTML = '{{ 'CoreHome_AdblockIsMaybeUsed'|translate|e('js') }}'; + + body[0].appendChild(warning); + warning.style.color = 'red'; + warning.style.fontWeight = 'bold'; + warning.style.marginLeft = '16px'; + warning.style.marginBottom = '16px'; + })(); + } +</script> \ No newline at end of file diff --git a/plugins/Morpheus/templates/layout.twig b/plugins/Morpheus/templates/layout.twig index 1e9f1f0d5c5aaf24400011335b2ad8dc09d7f73b..fa2f480df5e6a6a0a64c230a6e0f325207f586f8 100644 --- a/plugins/Morpheus/templates/layout.twig +++ b/plugins/Morpheus/templates/layout.twig @@ -22,7 +22,6 @@ {% include "@CoreHome/_favicon.twig" %} {% include "_jsGlobalVariables.twig" %} - {% include "_piwikTag.twig" %} {% include "_jsCssIncludes.twig" %} <!--[if IE]> @@ -49,5 +48,6 @@ {% endblock %} + {% include "@CoreHome/_adblockDetect.twig" %} </body> </html>