diff options
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | plugins/CoreHome/SystemSummary/Item.php | 94 | ||||
-rw-r--r-- | plugins/CoreHome/Widgets/GetSystemSummary.php | 79 | ||||
-rw-r--r-- | plugins/CoreHome/templates/getSystemSummary.twig | 48 | ||||
-rw-r--r-- | plugins/CorePluginsAdmin/CorePluginsAdmin.php | 9 | ||||
-rw-r--r-- | plugins/SegmentEditor/SegmentEditor.php | 13 | ||||
-rw-r--r-- | plugins/SitesManager/SitesManager.php | 16 | ||||
-rw-r--r-- | plugins/UsersManager/UsersManager.php | 15 | ||||
-rw-r--r-- | tests/resources/screenshot-override/override.css | 1 |
9 files changed, 222 insertions, 54 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 2048c4b838..ce9011186d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The Product Changelog at **[piwik.org/changelog](http://piwik.org/changelog)** l ### New APIs * A new event `Db.getActionReferenceColumnsByTable` has been added in case a plugin defines a custom log table which references data to the log_action table +* The event `System.addSystemSummaryItems` and `System.filterSystemSummaryItems` have been added so plugins can add items and filter items of the system summary widget * A new JavaScript tracker method `getPiwikUrl` has been added to retrieve the URL of where the Piwik instance is located * A new JavaScript tracker method `getCurrentUrl` has been added to retrieve the current URL of the website. * A new JavaScript tracker method `getNumTrackedPageViews` has been added to retrieve the number of tracked page views within the currently loaded page or web application. diff --git a/plugins/CoreHome/SystemSummary/Item.php b/plugins/CoreHome/SystemSummary/Item.php new file mode 100644 index 0000000000..7664b84124 --- /dev/null +++ b/plugins/CoreHome/SystemSummary/Item.php @@ -0,0 +1,94 @@ +<?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\CoreHome\SystemSummary; + +/** + * This class can be used to add a new entry / item to the system summary widget. + * + * @api + */ +class Item +{ + private $key; + private $label; + private $value; + private $urlParams; + private $icon; + private $order; + + /** + * Item constructor. + * @param string $key The key or ID for this item. The entry in the widget will have this class so it is possible + * to style it individually and other plugins can use this key to for example remove this item + * from the list of system summary items. + * @param string $label The label that will be displayed for this item. The label may already include the value such as "5 segments" + * @param string|null $value Optional label. If given, the value will be displayed after the label separated by a colon, eg: "Segments: 5" + * @param array|null $urlParams Optional URL to make the item clickable. Accepts an array of URL parameters that need to be modfified. + * @param string $icon Optional icon css class, eg "icon-user". + * @param int $order Optional sort order. The lower the value, the higher up the entry will be shown + */ + public function __construct($key, $label, $value = null, $urlParams = null, $icon = '', $order = 99) + { + $this->key = $key; + $this->label = $label; + $this->value = $value; + $this->urlParams = $urlParams; + $this->icon = $icon; + $this->order = $order; + } + + /** + * @return string + */ + public function getKey() + { + return $this->key; + } + + /** + * @return string + */ + public function getLabel() + { + return $this->label; + } + + /** + * @return mixed + */ + public function getValue() + { + return $this->value; + } + + /** + * @return array|null + */ + public function getUrlParams() + { + return $this->urlParams; + } + + /** + * @return string + */ + public function getIcon() + { + return $this->icon; + } + + /** + * @return int + */ + public function getOrder() + { + return $this->order; + } + +} diff --git a/plugins/CoreHome/Widgets/GetSystemSummary.php b/plugins/CoreHome/Widgets/GetSystemSummary.php index f68ce36d4f..a90d7b0586 100644 --- a/plugins/CoreHome/Widgets/GetSystemSummary.php +++ b/plugins/CoreHome/Widgets/GetSystemSummary.php @@ -12,11 +12,11 @@ use Piwik\API\Request; use Piwik\Db; use Piwik\Piwik; use Piwik\Plugin; +use Piwik\Plugins\CoreHome\SystemSummary\Item; use Piwik\Plugins\SegmentEditor\Services\StoredSegmentService; use Piwik\Version; use Piwik\Widget\Widget; use Piwik\Widget\WidgetConfig; -use Piwik\View; class GetSystemSummary extends Widget { @@ -46,39 +46,70 @@ class GetSystemSummary extends Widget public function render() { - $userLogins = Request::processRequest('UsersManager.getUsersLogin', array('filter_limit' => '-1')); - $websites = Request::processRequest('SitesManager.getAllSites', array('filter_limit' => '-1')); + $mysqlVersion = $this->getMySqlVersion(); - $numUsers = count($userLogins); - if (in_array('anonymous', $userLogins)) { - $numUsers--; - } + $systemSummary = array(); + + /** + * Triggered to add system summary items that are shown in the System Summary widget. + * + * **Example** + * + * public function addSystemSummaryItem(&$systemSummary) + * { + * $numUsers = 5; + * $systemSummary[] = new SystemSummary\Item($key = 'users', Piwik::translate('General_NUsers', $numUsers), $value = null, array('module' => 'UsersManager', 'action' => 'index'), $icon = 'icon-user'); + * } + * + * @param Item[] &$systemSummary An array containing system summary items. + */ + Piwik::postEvent('System.addSystemSummaryItems', array(&$systemSummary)); + + $systemSummary[] = new Item($key = 'piwik-version', Piwik::translate('CoreHome_SystemSummaryPiwikVersion'), Version::VERSION, $url = null, $icon = '', $order = 21); + $systemSummary[] = new Item($key = 'php-version', Piwik::translate('CoreHome_SystemSummaryMysqlVersion'), $mysqlVersion, $url = null, $icon = '', $order = 22); + $systemSummary[] = new Item($key = 'mysql-version', Piwik::translate('CoreHome_SystemSummaryPhpVersion'), phpversion(), $url = null, $icon = '', $order = 23); + + $systemSummary = array_filter($systemSummary); + usort($systemSummary, function ($itemA, $itemB) { + if ($itemA->getOrder() == $itemB->getOrder()) { + return 0; + } + if ($itemA->getOrder() > $itemB->getOrder()) { + return 1; + } + return -1; + }); + + /** + * Triggered to filter system summary items that are shown in the System Summary widget. A plugin might also + * sort the system summary items differently. + * + * **Example** + * + * public function filterSystemSummaryItems(&$systemSummary) + * { + * foreach ($systemSummaryItems as $index => $item) { + * if ($item && $item->getKey() === 'users') { + * $systemSummaryItems[$index] = null; + * } + * } + * } + * + * @param Item[] &$systemSummary An array containing system summary items. + */ + Piwik::postEvent('System.filterSystemSummaryItems', array(&$systemSummary)); + + $systemSummary = array_filter($systemSummary); return $this->renderTemplate('getSystemSummary', array( - 'numWebsites' => count($websites), - 'numUsers' => $numUsers, - 'numSegments' => $this->getNumSegments(), - 'numPlugins' => $this->getNumActivatedPlugins(), - 'piwikVersion' => Version::VERSION, - 'mySqlVersion' => $this->getMySqlVersion(), - 'phpVersion' => phpversion() + 'items' => $systemSummary )); } - private function getNumSegments() - { - $segments = $this->storedSegmentService->getAllSegmentsAndIgnoreVisibility(); - return count($segments); - } - private function getMySqlVersion() { $db = Db::get(); return $db->getServerVersion(); } - private function getNumActivatedPlugins() - { - return $this->pluginManager->getNumberOfActivatedPluginsExcludingAlwaysActivated(); - } }
\ No newline at end of file diff --git a/plugins/CoreHome/templates/getSystemSummary.twig b/plugins/CoreHome/templates/getSystemSummary.twig index 264162c180..aeaa07caed 100644 --- a/plugins/CoreHome/templates/getSystemSummary.twig +++ b/plugins/CoreHome/templates/getSystemSummary.twig @@ -1,28 +1,26 @@ <div class="widgetBody systemSummary"> - <div> - <span class="icon icon-user"></span> - <a href="{{ linkTo({'module': 'UsersManager', 'action': 'index'}) }}">{{ 'General_NUsers'|translate(numUsers) }}</a> - </div> - <div> - <span><span class="icon icon-segment"></span> {{ 'CoreHome_SystemSummaryNSegments'|translate(numSegments) }}</span> - </div> - <div> - <a href="{{ linkTo({'module': 'SitesManager', 'action': 'index'}) }}">{{ 'CoreHome_SystemSummaryNWebsites'|translate(numWebsites) }}</a> - </div> - <div> - <a href="{{ linkTo({'module': 'CorePluginsAdmin', 'action': 'plugins'}) }}">{{ 'CoreHome_SystemSummaryNActivatedPlugins'|translate(numPlugins) }}</a> - </div> - <div> - <span>{{ 'CoreHome_SystemSummaryPiwikVersion'|translate }}:</span> - <span class="piwik-version">{{ piwikVersion }}</span> - </div> - <div> - <span>{{ 'CoreHome_SystemSummaryMysqlVersion'|translate }}:</span> - <span>{{ mySqlVersion }}</span> - </div> - <div> - <span>{{ 'CoreHome_SystemSummaryPhpVersion'|translate }}:</span> - <span>{{ phpVersion }}</span> - </div> + {% for item in items %} + {% if item is not empty %} + <div class="systemSummaryItem {% if item.getKey %}{{ item.getKey }}{% endif %}"> + {% if item.getIcon %}<span class="icon {{ item.getIcon }}"></span>{% endif %} + + {% if item.getUrlParams -%} + <a href="{{ linkTo(item.getUrlParams) }}" class="itemLabel"> + {% else -%} + <span class="itemLabel"> + {% endif -%} + + {{ item.getLabel }}{% if item.getValue %}:{% endif %} + + {%- if item.getUrlParams %} + </a> + {%- else %} + </span> + {%- endif %} + + {% if item.getValue %}<span class="itemValue">{{ item.getValue }}</span>{% endif %} + </div> + {% endif %} + {% endfor %} <br /> </div>
\ No newline at end of file diff --git a/plugins/CorePluginsAdmin/CorePluginsAdmin.php b/plugins/CorePluginsAdmin/CorePluginsAdmin.php index d1c0a3fee1..8008fe529c 100644 --- a/plugins/CorePluginsAdmin/CorePluginsAdmin.php +++ b/plugins/CorePluginsAdmin/CorePluginsAdmin.php @@ -9,7 +9,9 @@ namespace Piwik\Plugins\CorePluginsAdmin; use Piwik\Config; +use Piwik\Piwik; use Piwik\Plugin; +use Piwik\Plugins\CoreHome\SystemSummary; class CorePluginsAdmin extends Plugin { @@ -21,10 +23,17 @@ class CorePluginsAdmin extends Plugin return array( 'AssetManager.getJavaScriptFiles' => 'getJsFiles', 'AssetManager.getStylesheetFiles' => 'getStylesheetFiles', + 'System.addSystemSummaryItems' => 'addSystemSummaryItems', 'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys' ); } + public function addSystemSummaryItems(&$systemSummary) + { + $numPlugins = Plugin\Manager::getInstance()->getNumberOfActivatedPluginsExcludingAlwaysActivated(); + $systemSummary[] = new SystemSummary\Item($key = 'plugins', Piwik::translate('CoreHome_SystemSummaryNActivatedPlugins', $numPlugins), $value = null, $url = array('module' => 'CorePluginsAdmin', 'action' => 'plugins'), $icon = '', $order = 11); + } + public function getStylesheetFiles(&$stylesheets) { $stylesheets[] = "plugins/CorePluginsAdmin/stylesheets/plugins_admin.less"; diff --git a/plugins/SegmentEditor/SegmentEditor.php b/plugins/SegmentEditor/SegmentEditor.php index f3ea172a54..63cee53c30 100644 --- a/plugins/SegmentEditor/SegmentEditor.php +++ b/plugins/SegmentEditor/SegmentEditor.php @@ -9,7 +9,9 @@ namespace Piwik\Plugins\SegmentEditor; use Piwik\Config; -use Piwik\Db; +use Piwik\Container\StaticContainer; +use Piwik\Piwik; +use Piwik\Plugins\CoreHome\SystemSummary; /** */ @@ -26,10 +28,19 @@ class SegmentEditor extends \Piwik\Plugin 'AssetManager.getJavaScriptFiles' => 'getJsFiles', 'AssetManager.getStylesheetFiles' => 'getStylesheetFiles', 'Template.nextToCalendar' => 'getSegmentEditorHtml', + 'System.addSystemSummaryItems' => 'addSystemSummaryItems', 'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys', ); } + public function addSystemSummaryItems(&$systemSummary) + { + $storedSegments = StaticContainer::get('Piwik\Plugins\SegmentEditor\Services\StoredSegmentService'); + $segments = $storedSegments->getAllSegmentsAndIgnoreVisibility(); + $numSegments = count($segments); + $systemSummary[] = new SystemSummary\Item($key = 'segments', Piwik::translate('CoreHome_SystemSummaryNSegments', $numSegments), $value = null, $url = null, $icon = 'icon-segment', $order = 6); + } + function getSegmentEditorHtml(&$out) { $selector = new SegmentSelectorControl(); diff --git a/plugins/SitesManager/SitesManager.php b/plugins/SitesManager/SitesManager.php index 514f0f426d..1154e2cc10 100644 --- a/plugins/SitesManager/SitesManager.php +++ b/plugins/SitesManager/SitesManager.php @@ -8,12 +8,12 @@ */ namespace Piwik\Plugins\SitesManager; +use Piwik\API\Request; use Piwik\Common; -use Piwik\Archive\ArchiveInvalidator; use Piwik\Container\StaticContainer; -use Piwik\Db; +use Piwik\Piwik; +use Piwik\Plugins\CoreHome\SystemSummary; use Piwik\Plugins\PrivacyManager\PrivacyManager; -use Piwik\Measurable\Settings\Storage; use Piwik\Settings\Storage\Backend\MeasurableSettingsTable; use Piwik\Tracker\Cache; use Piwik\Tracker\Model as TrackerModel; @@ -28,7 +28,7 @@ class SitesManager extends \Piwik\Plugin const KEEP_URL_FRAGMENT_NO = 2; /** - * @see Piwik\Plugin::registerEvents + * @see \Piwik\Plugin::registerEvents */ public function registerEvents() { @@ -38,10 +38,18 @@ class SitesManager extends \Piwik\Plugin 'Tracker.Cache.getSiteAttributes' => 'recordWebsiteDataInCache', 'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys', 'SitesManager.deleteSite.end' => 'onSiteDeleted', + 'System.addSystemSummaryItems' => 'addSystemSummaryItems', 'Request.dispatch' => 'redirectDashboardToWelcomePage', ); } + public function addSystemSummaryItems(&$systemSummary) + { + $websites = Request::processRequest('SitesManager.getAllSites', array('filter_limit' => '-1')); + $numWebsites = count($websites); + $systemSummary[] = new SystemSummary\Item($key = 'websites', Piwik::translate('CoreHome_SystemSummaryNWebsites', $numWebsites), $value = null, $url = array('module' => 'SitesManager', 'action' => 'index'), $icon = '', $order = 10); + } + public function redirectDashboardToWelcomePage(&$module, &$action) { if ($module !== 'CoreHome' || $action !== 'index') { diff --git a/plugins/UsersManager/UsersManager.php b/plugins/UsersManager/UsersManager.php index f22d2b63ed..95620a6182 100644 --- a/plugins/UsersManager/UsersManager.php +++ b/plugins/UsersManager/UsersManager.php @@ -9,8 +9,10 @@ namespace Piwik\Plugins\UsersManager; use Exception; +use Piwik\API\Request; use Piwik\Option; use Piwik\Piwik; +use Piwik\Plugins\CoreHome\SystemSummary; use Piwik\SettingsPiwik; /** @@ -33,10 +35,23 @@ class UsersManager extends \Piwik\Plugin 'Tracker.Cache.getSiteAttributes' => 'recordAdminUsersInCache', 'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys', 'Platform.initialized' => 'onPlatformInitialized', + 'System.addSystemSummaryItems' => 'addSystemSummaryItems', 'CronArchive.getTokenAuth' => 'getCronArchiveTokenAuth' ); } + public function addSystemSummaryItems(&$systemSummary) + { + $userLogins = Request::processRequest('UsersManager.getUsersLogin', array('filter_limit' => '-1')); + + $numUsers = count($userLogins); + if (in_array('anonymous', $userLogins)) { + $numUsers--; + } + + $systemSummary[] = new SystemSummary\Item($key = 'users', Piwik::translate('General_NUsers', $numUsers), $value = null, array('module' => 'UsersManager', 'action' => 'index'), $icon = 'icon-user', $order = 5); + } + public function onPlatformInitialized() { $lastSeenTimeLogger = new LastSeenTimeLogger(); diff --git a/tests/resources/screenshot-override/override.css b/tests/resources/screenshot-override/override.css index a38e0ed84d..bda7f2a260 100644 --- a/tests/resources/screenshot-override/override.css +++ b/tests/resources/screenshot-override/override.css @@ -10,6 +10,7 @@ display:none; } +.piwik-version .itemValue, span.piwik-version, span.plugin-version { visibility:hidden; |