From b881b1dbebd3ca20e34c8ab3d252e6ab837cb41c Mon Sep 17 00:00:00 2001 From: Thomas Steur <thomas.steur@googlemail.com> Date: Mon, 25 Aug 2014 15:50:27 +0200 Subject: [PATCH] refs #6045 #6049 the UI should now work even when none of those reporting / tracker plugins is enabled --- .../CoreConsole/Commands/GenerateWidget.php | 2 +- plugins/DevicesDetection/DevicesDetection.php | 2 +- .../templates/insightsOverviewWidget.twig | 15 ++++++-- .../moversAndShakersOverviewWidget.twig | 13 +++++-- plugins/UserCountryMap/Menu.php | 8 +++- plugins/UserCountryMap/UserCountryMap.php | 3 -- plugins/UserCountryMap/Widgets.php | 38 +++++++++++++++++++ 7 files changed, 68 insertions(+), 13 deletions(-) create mode 100644 plugins/UserCountryMap/Widgets.php diff --git a/plugins/CoreConsole/Commands/GenerateWidget.php b/plugins/CoreConsole/Commands/GenerateWidget.php index c7fabb1c44..53552e6844 100644 --- a/plugins/CoreConsole/Commands/GenerateWidget.php +++ b/plugins/CoreConsole/Commands/GenerateWidget.php @@ -34,7 +34,7 @@ class GenerateWidget extends GeneratePluginBase $category = $this->getCategory($input, $output); $exampleFolder = PIWIK_INCLUDE_PATH . '/plugins/ExamplePlugin'; - $replace = array('ExampleRssWidget' => $pluginName, + $replace = array('ExamplePlugin' => $pluginName, 'Example Category' => $category); $whitelistFiles = array('/Widgets.php'); diff --git a/plugins/DevicesDetection/DevicesDetection.php b/plugins/DevicesDetection/DevicesDetection.php index e1b09be333..6e018d7712 100644 --- a/plugins/DevicesDetection/DevicesDetection.php +++ b/plugins/DevicesDetection/DevicesDetection.php @@ -50,7 +50,7 @@ class DevicesDetection extends \Piwik\Plugin if (!PluginManager::getInstance()->isPluginActivated('UserSettings')) { $instance = new UserSettings(); - $instance->extendVisitorDetails(&$visitor, $details); + $instance->extendVisitorDetails($visitor, $details); } } diff --git a/plugins/Insights/templates/insightsOverviewWidget.twig b/plugins/Insights/templates/insightsOverviewWidget.twig index cf8bfe166d..7a3ec6e1d1 100644 --- a/plugins/Insights/templates/insightsOverviewWidget.twig +++ b/plugins/Insights/templates/insightsOverviewWidget.twig @@ -1,5 +1,14 @@ -{% set allMetadata = reports.getFirstRow.getAllTableMetadata %} -{% set consideredGrowth = 'Insights_TitleConsideredInsightsGrowth'|translate(allMetadata.minGrowthPercentPositive, allMetadata.lastDate|prettyDate(allMetadata.period)) %} +{% if reports.getRowsCount %} + {% set allMetadata = reports.getFirstRow.getAllTableMetadata %} + {% set consideredGrowth = 'Insights_TitleConsideredInsightsGrowth'|translate(allMetadata.minGrowthPercentPositive, allMetadata.lastDate|prettyDate(allMetadata.period)) %} + +{% else %} + {% set allMetadata = {} %} + {% set consideredGrowth = '' %} +{% endif %} + {% set consideredChanges = '' %} -{% include "@Insights/overviewWidget.twig" %} \ No newline at end of file +{% include "@Insights/overviewWidget.twig" %} + + diff --git a/plugins/Insights/templates/moversAndShakersOverviewWidget.twig b/plugins/Insights/templates/moversAndShakersOverviewWidget.twig index f2326df1ea..bc79edcfb1 100644 --- a/plugins/Insights/templates/moversAndShakersOverviewWidget.twig +++ b/plugins/Insights/templates/moversAndShakersOverviewWidget.twig @@ -1,6 +1,13 @@ -{% set allMetadata = reports.getFirstRow.getAllTableMetadata %} +{% if reports.getRowsCount %} + {% set allMetadata = reports.getFirstRow.getAllTableMetadata %} -{% set consideredGrowth = 'Insights_TitleConsideredMoversAndShakersGrowth'|translate(allMetadata.metricName, allMetadata.lastTotalValue, allMetadata.totalValue, allMetadata.lastDate|prettyDate(allMetadata.period), allMetadata.evolutionTotal) %} -{% set consideredChanges = 'Insights_TitleConsideredMoversAndShakersChanges'|translate(allMetadata.minGrowthPercentPositive, allMetadata.minGrowthPercentNegative, allMetadata.minNewPercent, allMetadata.minIncreaseNew, allMetadata.minDisappearedPercent, allMetadata.minDecreaseDisappeared, allMetadata.totalValue) %} + {% set consideredGrowth = 'Insights_TitleConsideredMoversAndShakersGrowth'|translate(allMetadata.metricName, allMetadata.lastTotalValue, allMetadata.totalValue, allMetadata.lastDate|prettyDate(allMetadata.period), allMetadata.evolutionTotal) %} + {% set consideredChanges = 'Insights_TitleConsideredMoversAndShakersChanges'|translate(allMetadata.minGrowthPercentPositive, allMetadata.minGrowthPercentNegative, allMetadata.minNewPercent, allMetadata.minIncreaseNew, allMetadata.minDisappearedPercent, allMetadata.minDecreaseDisappeared, allMetadata.totalValue) %} +{% else %} + {% set allMetadata = {} %} + + {% set consideredGrowth = '' %} + {% set consideredChanges = '' %} +{% endif %} {% include "@Insights/overviewWidget.twig" %} \ No newline at end of file diff --git a/plugins/UserCountryMap/Menu.php b/plugins/UserCountryMap/Menu.php index 298eda1e17..fa32a8f9b7 100644 --- a/plugins/UserCountryMap/Menu.php +++ b/plugins/UserCountryMap/Menu.php @@ -9,12 +9,16 @@ namespace Piwik\Plugins\UserCountryMap; use Piwik\Menu\MenuReporting; +use Piwik\Plugin\Manager as PluginManager; class Menu extends \Piwik\Plugin\Menu { public function configureReportingMenu(MenuReporting $menu) { - $menu->addVisitorsItem('UserCountryMap_RealTimeMap', - array('module' => 'UserCountryMap', 'action' => 'realtimeWorldMap'), $order = 70); + if (PluginManager::getInstance()->isPluginActivated('UserCountry')) { + $menu->addVisitorsItem('UserCountryMap_RealTimeMap', + array('module' => 'UserCountryMap', 'action' => 'realtimeWorldMap'), + $order = 70); + } } } diff --git a/plugins/UserCountryMap/UserCountryMap.php b/plugins/UserCountryMap/UserCountryMap.php index 2ff43f1bbb..fdedc1085d 100644 --- a/plugins/UserCountryMap/UserCountryMap.php +++ b/plugins/UserCountryMap/UserCountryMap.php @@ -34,9 +34,6 @@ class UserCountryMap extends \Piwik\Plugin public function postLoad() { - WidgetsList::add('General_Visitors', Piwik::translate('UserCountryMap_VisitorMap'), 'UserCountryMap', 'visitorMap'); - WidgetsList::add('Live!', Piwik::translate('UserCountryMap_RealTimeMap'), 'UserCountryMap', 'realtimeMap'); - Piwik::addAction('Template.leftColumnUserCountry', array('Piwik\Plugins\UserCountryMap\UserCountryMap', 'insertMapInLocationReport')); } diff --git a/plugins/UserCountryMap/Widgets.php b/plugins/UserCountryMap/Widgets.php new file mode 100644 index 0000000000..b2142f4ee4 --- /dev/null +++ b/plugins/UserCountryMap/Widgets.php @@ -0,0 +1,38 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ +namespace Piwik\Plugins\UserCountryMap; + +use Piwik\Piwik; +use Piwik\View; +use Piwik\Plugin\Manager as PluginManager; + +/** + * This class allows you to add your own widgets to the Piwik platform. In case you want to remove widgets from another + * plugin please have a look at the "configureWidgetsList()" method. + * To configure a widget simply call the corresponding methods as described in the API-Reference: + * http://developer.piwik.org/api-reference/Piwik/Plugin\Widgets + */ +class Widgets extends \Piwik\Plugin\Widgets +{ + /** + * Here you can define the category the widget belongs to. You can reuse any existing widget category or define + * your own category. + * @var string + */ + protected $category = 'General_Visitor'; + + protected function init() + { + if (PluginManager::getInstance()->isPluginActivated('UserCountry')) { + $this->addWidget(Piwik::translate('UserCountryMap_VisitorMap'), 'visitorMap'); + $this->addWidgetWithCustomCategory('Live!', Piwik::translate('UserCountryMap_RealTimeMap'), 'realtimeMap'); + } + } + +} -- GitLab