Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/FrontController.php80
-rw-r--r--core/Plugin/Widgets.php108
-rw-r--r--core/WidgetsList.php32
-rw-r--r--lang/en.json1
-rw-r--r--plugins/CoreConsole/Commands/GenerateWidget.php53
-rw-r--r--plugins/CoreHome/Controller.php41
-rw-r--r--plugins/CoreHome/Widgets.php40
-rw-r--r--plugins/ExamplePlugin/Widgets.php41
-rw-r--r--plugins/ExampleRssWidget/Controller.php53
-rw-r--r--plugins/ExampleRssWidget/Widgets.php51
-rw-r--r--plugins/Goals/Widgets.php40
-rw-r--r--plugins/Insights/Widgets.php14
-rw-r--r--plugins/Live/Widgets.php13
-rw-r--r--plugins/Referrers/Widgets.php7
-rw-r--r--plugins/SEO/Controller.php47
-rw-r--r--plugins/SEO/Widgets.php40
-rw-r--r--plugins/VisitFrequency/Widgets.php14
-rw-r--r--plugins/VisitsSummary/Widgets.php15
-rw-r--r--plugins/Widgetize/Widgetize.php5
19 files changed, 445 insertions, 250 deletions
diff --git a/core/FrontController.php b/core/FrontController.php
index 3753980f24..2861e3cb0b 100644
--- a/core/FrontController.php
+++ b/core/FrontController.php
@@ -14,7 +14,9 @@ use Piwik\API\Request;
use Piwik\API\ResponseBuilder;
use Piwik\Plugin\Controller;
use Piwik\Plugin\Report;
+use Piwik\Plugin\Widgets;
use Piwik\Session;
+use \Piwik\Plugins\CoreHome\Controller as CoreHomeController;
/**
* This singleton dispatches requests to the appropriate plugin Controller.
@@ -105,45 +107,69 @@ class FrontController extends Singleton
{
$controllerClassName = $this->getClassNameController($module);
- // FrontController's autoloader
- if (!class_exists($controllerClassName, false)) {
- $moduleController = PIWIK_INCLUDE_PATH . '/plugins/' . $module . '/Controller.php';
- if (!is_readable($moduleController)) {
- throw new Exception("Module controller $moduleController not found!");
- }
- require_once $moduleController; // prefixed by PIWIK_INCLUDE_PATH
- }
+ // TRY TO FIND ACTION IN CONTROLLER
+ if (class_exists($controllerClassName)) {
- $class = $this->getClassNameController($module);
- /** @var $controller Controller */
- $controller = new $class;
- if ($action === false) {
- $action = $controller->getDefaultAction();
- }
+ $class = $this->getClassNameController($module);
+ /** @var $controller Controller */
+ $controller = new $class;
- if (!is_callable(array($controller, $action))) {
+ $controllerAction = $action;
+ if ($controllerAction === false) {
+ $controllerAction = $controller->getDefaultAction();
+ }
- $report = Report::factory($module, $action);
- $actionToCall = 'renderReportWidget';
- $actionToCheck = $action;
+ if (is_callable(array($controller, $controllerAction))) {
- if (empty($report) && !empty($action) && 'menu' === substr($action, 0, 4)) {
- $actionToCheck = lcfirst(substr($action, 4));
- $report = Report::factory($module, $actionToCheck);
- $actionToCall = 'renderReportMenu';
+ return array($controller, $controllerAction);
}
- if (empty($report)) {
- throw new Exception("Action '$action' not found in the controller '$controllerClassName'.");
+ if ($action === false) {
+ $this->triggerControllerActionNotFoundError($controller, $controllerAction);
}
+ }
+
+ // TRY TO FIND ACTION IN WIDGET
+ $widget = Widgets::factory($module, $action);
+
+ if (!empty($widget)) {
+
+ $parameters['widgetModule'] = $module;
+ $parameters['widgetMethod'] = $action;
+
+ return array(new CoreHomeController(), 'renderWidget');
+ }
+
+ // TRY TO FIND ACTION IN REPORT
+ $report = Report::factory($module, $action);
+
+ if (!empty($report)) {
+
$parameters['reportModule'] = $module;
- $parameters['reportAction'] = $actionToCheck;
+ $parameters['reportAction'] = $action;
+
+ return array(new CoreHomeController(), 'renderReportWidget');
+ }
+
+ if (!empty($action) && 'menu' === substr($action, 0, 4)) {
+ $reportAction = lcfirst(substr($action, 4)); // menuGetPageUrls => getPageUrls
+ $report = Report::factory($module, $reportAction);
- return $this->makeController('CoreHome', $actionToCall, $parameters);
+ if (!empty($report)) {
+ $parameters['reportModule'] = $module;
+ $parameters['reportAction'] = $reportAction;
+
+ return array(new CoreHomeController(), 'renderReportMenu');
+ }
}
- return array($controller, $action);
+ $this->triggerControllerActionNotFoundError($module, $action);
+ }
+
+ protected function triggerControllerActionNotFoundError($module, $action)
+ {
+ throw new Exception("Action '$action' not found in the module '$module'.");
}
protected function getClassNameController($module)
diff --git a/core/Plugin/Widgets.php b/core/Plugin/Widgets.php
index 201fe743f6..db69c6e794 100644
--- a/core/Plugin/Widgets.php
+++ b/core/Plugin/Widgets.php
@@ -8,6 +8,7 @@
*/
namespace Piwik\Plugin;
+use Piwik\Plugin\Manager as PluginManager;
use Piwik\WidgetsList;
/**
@@ -20,10 +21,113 @@ use Piwik\WidgetsList;
*/
class Widgets
{
+ protected $category = '';
+ protected $widgets = array();
+
+ private $module = '';
+
+ public function __construct()
+ {
+ $this->module = $this->getModule();
+ }
+
+ public function getCategory()
+ {
+ return $this->category;
+ }
+
+ private function getModule()
+ {
+ $className = get_class($this);
+ $className = explode('\\', $className);
+
+ return $className[2];
+ }
+
/**
- * Configures the widgets. Here you can for instance add or remove widgets.
+ * @api
*/
- public function configure(WidgetsList $widgetsList)
+ protected function addWidget($name, $method, $parameters = array())
+ {
+ // to be developer friendly we could check whether such a method exists (in controller or widget) and if
+ // not throw an exception so the developer does not have to handle with typos etc. I do not want to do this
+ // right now because of performance but if we add a development setting in config we could do such check
+ $this->addWidgetWithCustomCategory($this->category, $name, $method, $parameters);
+ }
+
+ protected function addWidgetWithCustomCategory($category, $name, $method, $parameters = array())
+ {
+ $this->widgets[] = array('category' => $category,
+ 'name' => $name,
+ 'params' => $parameters,
+ 'method' => $method,
+ 'module' => $this->module);
+ }
+
+ /**
+ * @api
+ */
+ protected function init()
+ {
+ }
+
+ public function getWidgets()
{
+ $this->widgets = array();
+
+ $this->init();
+
+ return $this->widgets;
+ }
+
+ /**
+ * Configures the widgets. Here you can for instance remove widgets.
+ */
+ public function configureWidgetsList(WidgetsList $widgetsList)
+ {
+
+ }
+
+ /**
+ * @return \Piwik\Plugin\Widgets[]
+ */
+ public static function getAllWidgets()
+ {
+ return PluginManager::getInstance()->findComponents('Widgets', 'Piwik\\Plugin\\Widgets');
+ }
+
+ public static function factory($module, $action)
+ {
+ if (empty($module) || empty($action)) {
+ return;
+ }
+
+ try {
+ $plugin = PluginManager::getInstance()->getLoadedPlugin($module);
+ } catch (\Exception $e) {
+ // we are not allowed to use possible widgets, plugin is not active
+ return;
+ }
+
+ /** @var Widgets $widgetContainer */
+ $widgetContainer = $plugin->findComponent('Widgets', 'Piwik\\Plugin\\Widgets');
+
+ if (empty($widgetContainer)) {
+ // plugin does not define any widgets, we cannot do anything
+ return;
+ }
+
+ if (!is_callable(array($widgetContainer, $action))) {
+ // widget does not implement such a method, we cannot do anything
+ return;
+ }
+
+ // the widget class implements such an action, but we have to check whether it is actually exposed and whether
+ // it was maybe disabled by another plugin, this is only possible by checking the widgetslist, unfortunately
+ if (!WidgetsList::isDefined($module, $action)) {
+ return;
+ }
+
+ return $widgetContainer;
}
}
diff --git a/core/WidgetsList.php b/core/WidgetsList.php
index 420f5f76b6..531d802405 100644
--- a/core/WidgetsList.php
+++ b/core/WidgetsList.php
@@ -8,8 +8,8 @@
*/
namespace Piwik;
-use Piwik\Plugin\Manager as PluginManager;
use Piwik\Plugin\Report;
+use Piwik\Plugin\Widgets;
/**
* Manages the global list of reports that can be displayed as dashboard widgets.
@@ -61,11 +61,15 @@ class WidgetsList extends Singleton
$widgets = array();
foreach (self::$widgets as $key => $v) {
- if (isset($widgets[Piwik::translate($key)])) {
- $v = array_merge($widgets[Piwik::translate($key)], $v);
+ $category = Piwik::translate($key);
+
+ if (isset($widgets[$category])) {
+ $v = array_merge($widgets[$category], $v);
}
- $widgets[Piwik::translate($key)] = $v;
+
+ $widgets[$category] = $v;
}
+
return $widgets;
}
@@ -80,8 +84,6 @@ class WidgetsList extends Singleton
*/
Piwik::postEvent('WidgetsList.addWidgets');
- /** @var \Piwik\Plugin\Widgets[] $widgets */
- $widgets = PluginManager::getInstance()->findComponents('Widgets', 'Piwik\\Plugin\\Widgets');
$widgetsList = self::getInstance();
foreach (Report::getAllReports() as $report) {
@@ -90,8 +92,17 @@ class WidgetsList extends Singleton
}
}
- foreach ($widgets as $widget) {
- $widget->configure($widgetsList);
+ $widgetContainers = Widgets::getAllWidgets();
+ foreach ($widgetContainers as $widgetContainer) {
+ $widgets = $widgetContainer->getWidgets();
+
+ foreach ($widgets as $widget) {
+ $widgetsList->add($widget['category'], $widget['name'], $widget['module'], $widget['method'], $widget['params']);
+ }
+ }
+
+ foreach ($widgetContainers as $widgetContainer) {
+ $widgetContainer->configureWidgetsList($widgetsList);
}
}
}
@@ -143,8 +154,9 @@ class WidgetsList extends Singleton
*/
static public function add($widgetCategory, $widgetName, $controllerName, $controllerAction, $customParameters = array())
{
- $widgetName = Piwik::translate($widgetName);
+ $widgetName = Piwik::translate($widgetName);
$widgetUniqueId = 'widget' . $controllerName . $controllerAction;
+
foreach ($customParameters as $name => $value) {
if (is_array($value)) {
// use 'Array' for backward compatibility;
@@ -203,7 +215,7 @@ class WidgetsList extends Singleton
static public function isDefined($controllerName, $controllerAction)
{
$widgetsList = self::get();
- foreach ($widgetsList as $widgetCategory => $widgets) {
+ foreach ($widgetsList as $widgets) {
foreach ($widgets as $widget) {
if ($widget['parameters']['module'] == $controllerName
&& $widget['parameters']['action'] == $controllerAction
diff --git a/lang/en.json b/lang/en.json
index 7726cbc9d5..9d45aeb686 100644
--- a/lang/en.json
+++ b/lang/en.json
@@ -637,6 +637,7 @@
"ExceptionUndeletableFile": "Unable to delete %s",
"ExceptionUnreadableFileDisabledMethod": "The configuration file {%s} could not be read. Your host may have disabled %s.",
"ExceptionReportNotFound": "The requested report does not exist.",
+ "ExceptionWidgetNotFound": "The requested widget does not exist.",
"ExceptionReportNotEnabled": "The requested report is not enabled. This means usually either the plugin that defines the report is deactivated or you do not have enough permission to access this report.",
"ExpandDataTableFooter": "Change the visualization or configure the report",
"Export": "Export",
diff --git a/plugins/CoreConsole/Commands/GenerateWidget.php b/plugins/CoreConsole/Commands/GenerateWidget.php
index c3360e10fe..605b336a23 100644
--- a/plugins/CoreConsole/Commands/GenerateWidget.php
+++ b/plugins/CoreConsole/Commands/GenerateWidget.php
@@ -9,6 +9,9 @@
namespace Piwik\Plugins\CoreConsole\Commands;
+use Piwik\Piwik;
+use Piwik\Plugin\Widgets;
+use Piwik\Translate;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
@@ -21,15 +24,18 @@ class GenerateWidget extends GeneratePluginBase
{
$this->setName('generate:widget')
->setDescription('Adds a plugin widget class to an existing plugin')
- ->addOption('pluginname', null, InputOption::VALUE_REQUIRED, 'The name of an existing plugin which does not have any widgets defined yet');
+ ->addOption('pluginname', null, InputOption::VALUE_REQUIRED, 'The name of an existing plugin which does not have any widgets defined yet')
+ ->addOption('category', null, InputOption::VALUE_REQUIRED, 'The name of the category the widget should belong to');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$pluginName = $this->getPluginName($input, $output);
+ $category = $this->getCategory($input, $output);
$exampleFolder = PIWIK_INCLUDE_PATH . '/plugins/ExamplePlugin';
- $replace = array('ExampleRssWidget' => $pluginName);
+ $replace = array('ExampleRssWidget' => $pluginName,
+ 'Example Category' => $category);
$whitelistFiles = array('/Widgets.php');
$this->copyTemplateToPlugin($exampleFolder, $pluginName, $replace, $whitelistFiles);
@@ -47,6 +53,49 @@ class GenerateWidget extends GeneratePluginBase
* @return array
* @throws \RunTimeException
*/
+ protected function getCategory(InputInterface $input, OutputInterface $output)
+ {
+ $validate = function ($category) {
+ if (empty($category)) {
+ throw new \InvalidArgumentException('Please enter the name of the category your widget should belong to');
+ }
+
+ return $category;
+ };
+
+ $category = $input->getOption('category');
+
+ $categories = array();
+ foreach (Widgets::getAllWidgets() as $widget) {
+ if ($widget->getCategory()) {
+ $categories[] = Piwik::translate($widget->getCategory());
+ }
+ }
+ $categories = array_values(array_unique($categories));
+
+ if (empty($category)) {
+ $dialog = $this->getHelperSet()->get('dialog');
+ $category = $dialog->askAndValidate($output, 'Enter the widget category, for instance "Visitor" (you can reuse any existing category or define a new one): ', $validate, false, null, $categories);
+ } else {
+ $validate($category);
+ }
+
+ $translationKey = Translate::findTranslationKeyForTranslation($category);
+ if (!empty($translationKey)) {
+ return $translationKey;
+ }
+
+ $category = ucfirst($category);
+
+ return $category;
+ }
+
+ /**
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ * @return array
+ * @throws \RunTimeException
+ */
protected function getPluginName(InputInterface $input, OutputInterface $output)
{
$pluginNames = $this->getPluginNamesHavingNotSpecificFile('Widgets.php');
diff --git a/plugins/CoreHome/Controller.php b/plugins/CoreHome/Controller.php
index 3766cbdce4..dae18b3ddf 100644
--- a/plugins/CoreHome/Controller.php
+++ b/plugins/CoreHome/Controller.php
@@ -27,7 +27,7 @@ use Piwik\UpdateCheck;
use Piwik\Url;
use Piwik\View;
use Piwik\ViewDataTable\Manager as ViewDataTableManager;
-use Piwik\WidgetsList;
+use Piwik\Plugin\Widgets as PluginWidgets;
class Controller extends \Piwik\Plugin\Controller
{
@@ -77,6 +77,19 @@ class Controller extends \Piwik\Plugin\Controller
return $report->render();
}
+ public function renderWidget($widgetModule = null, $widgetAction = null)
+ {
+ Piwik::checkUserHasSomeViewAccess();
+
+ $widget = PluginWidgets::factory($widgetModule, $widgetAction);
+
+ if (!empty($widget)) {
+ return $widget->$widgetAction();
+ }
+
+ throw new Exception(Piwik::translate('General_ExceptionWidgetNotFound'));
+ }
+
function redirectToCoreHomeIndex()
{
$defaultReport = API::getInstance()->getUserPreference(Piwik::getCurrentUserLogin(), API::PREFERENCE_DEFAULT_REPORT);
@@ -223,32 +236,6 @@ class Controller extends \Piwik\Plugin\Controller
}
/**
- * Renders and echo's the in-app donate form w/ slider.
- */
- public function getDonateForm()
- {
- $view = new View('@CoreHome/getDonateForm');
- if (Common::getRequestVar('widget', false)
- && Piwik::hasUserSuperUserAccess()
- ) {
- $view->footerMessage = Piwik::translate('CoreHome_OnlyForSuperUserAccess');
- }
- return $view->render();
- }
-
- /**
- * Renders and echo's HTML that displays the Piwik promo video.
- */
- public function getPromoVideo()
- {
- $view = new View('@CoreHome/getPromoVideo');
- $view->shareText = Piwik::translate('CoreHome_SharePiwikShort');
- $view->shareTextLong = Piwik::translate('CoreHome_SharePiwikLong');
- $view->promoVideoUrl = 'https://www.youtube.com/watch?v=OslfF_EH81g';
- return $view->render();
- }
-
- /**
* Redirects the user to a paypal so they can donate to Piwik.
*/
public function redirectToPaypal()
diff --git a/plugins/CoreHome/Widgets.php b/plugins/CoreHome/Widgets.php
index c2bfc76448..68812f0749 100644
--- a/plugins/CoreHome/Widgets.php
+++ b/plugins/CoreHome/Widgets.php
@@ -8,17 +8,45 @@
*/
namespace Piwik\Plugins\CoreHome;
-use Piwik\WidgetsList;
+use Piwik\Common;
+use Piwik\Piwik;
+use Piwik\View;
class Widgets extends \Piwik\Plugin\Widgets
{
- public function configure(WidgetsList $widgetsList)
+ protected $category = 'Example Widgets';
+
+ protected function init()
+ {
+ $this->addWidget('CoreHome_SupportPiwik', 'getDonateForm');
+ $this->addWidget('Installation_Welcome', 'getPromoVideo');
+ }
+
+ /**
+ * Renders and echo's the in-app donate form w/ slider.
+ */
+ public function getDonateForm()
{
- $category = 'Example Widgets';
- $controller = 'CoreHome';
+ $view = new View('@CoreHome/getDonateForm');
- $widgetsList->add($category, 'CoreHome_SupportPiwik', $controller, 'getDonateForm');
- $widgetsList->add($category, 'Installation_Welcome', $controller, 'getPromoVideo');
+ if (Common::getRequestVar('widget', false)
+ && Piwik::hasUserSuperUserAccess()) {
+ $view->footerMessage = Piwik::translate('CoreHome_OnlyForSuperUserAccess');
+ }
+
+ return $view->render();
}
+ /**
+ * Renders and echo's HTML that displays the Piwik promo video.
+ */
+ public function getPromoVideo()
+ {
+ $view = new View('@CoreHome/getPromoVideo');
+ $view->shareText = Piwik::translate('CoreHome_SharePiwikShort');
+ $view->shareTextLong = Piwik::translate('CoreHome_SharePiwikLong');
+ $view->promoVideoUrl = 'https://www.youtube.com/watch?v=OslfF_EH81g';
+
+ return $view->render();
+ }
}
diff --git a/plugins/ExamplePlugin/Widgets.php b/plugins/ExamplePlugin/Widgets.php
index c213d91ee8..2d0e607fa8 100644
--- a/plugins/ExamplePlugin/Widgets.php
+++ b/plugins/ExamplePlugin/Widgets.php
@@ -8,18 +8,49 @@
*/
namespace Piwik\Plugins\ExamplePlugin;
-use Piwik\WidgetsList;
+use Piwik\View;
/**
- * This class allows you to add or remove widgets.
+ * 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/WidgetsList
+ * http://developer.piwik.org/api-reference/Piwik/Plugin\Widgets
*/
class Widgets extends \Piwik\Plugin\Widgets
{
- public function configure(WidgetsList $widgetsList)
+ /**
+ * 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 = 'Example Category';
+
+ /**
+ * Here you can add one or multiple widgets. You can add a widget by calling the method "addWidget" and pass the
+ * name of the widget as well as a method name that should be called to render the widget. The method can be
+ * defined either directly here in this widget class or in the controller in case you want to reuse the same action
+ * for instance in the menu etc.
+ */
+ protected function init()
{
- // $widgetsList->add('Example Category', 'Example Widget Name', $controller = 'ExamplePlugin', $action = 'index');
+ // $this->addWidget('Example Widget Name', $method = 'myExampleWidget');
+ // $this->addWidget('Example Widget 2', $method = 'myExampleWidget', $params = array('myparam' => 'myvalue'));
+ }
+
+ /**
+ * This method renders a widget as defined in "init()". It's on you how to generate the content of the
+ * widget. As long as you return a string everything is fine. You can use for instance a "Piwik\View" to render a
+ * twig template. In such a case don't forget to create a twig template (eg. myViewTemplate.twig) in the
+ * "templates" directory of your plugin.
+ *
+ * @return string
+ */
+ public function myExampleWidget()
+ {
+ // $view = new View('@ExamplePlugin/myViewTemplate');
+ // return $view->render();
+
+ return 'My Widget Text';
}
}
diff --git a/plugins/ExampleRssWidget/Controller.php b/plugins/ExampleRssWidget/Controller.php
deleted file mode 100644
index 8255c0fd51..0000000000
--- a/plugins/ExampleRssWidget/Controller.php
+++ /dev/null
@@ -1,53 +0,0 @@
-<?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\ExampleRssWidget;
-
-use Exception;
-use Piwik\Piwik;
-
-/**
- *
- */
-class Controller extends \Piwik\Plugin\Controller
-{
- public function rssPiwik()
- {
- try {
- $rss = new RssRenderer('http://feeds.feedburner.com/Piwik');
- $rss->showDescription(true);
- return $rss->get();
- } catch (Exception $e) {
- return $this->error($e);
- }
- }
-
- public function rssChangelog()
- {
- try {
- $rss = new RssRenderer('http://feeds.feedburner.com/PiwikReleases');
- $rss->setCountPosts(1);
- $rss->showDescription(true);
- $rss->showContent(false);
- return $rss->get();
- } catch (Exception $e) {
- return $this->error($e);
- }
- }
-
- /**
- * @param \Exception $e
- */
- protected function error($e)
- {
- return '<div class="pk-emptyDataTable">'
- . Piwik::translate('General_ErrorRequest')
- . ' - ' . $e->getMessage() . '</div>';
- }
-}
diff --git a/plugins/ExampleRssWidget/Widgets.php b/plugins/ExampleRssWidget/Widgets.php
index cd31ef95e0..ec2b55141a 100644
--- a/plugins/ExampleRssWidget/Widgets.php
+++ b/plugins/ExampleRssWidget/Widgets.php
@@ -8,17 +8,56 @@
*/
namespace Piwik\Plugins\ExampleRssWidget;
-use Piwik\WidgetsList;
+use Piwik\Piwik;
class Widgets extends \Piwik\Plugin\Widgets
{
- public function configure(WidgetsList $widgetsList)
+ protected $category = 'Example Widgets';
+
+ protected function init()
+ {
+ $this->addWidget('Piwik.org Blog', 'rssPiwik');
+ $this->addWidget('Piwik Changelog', 'rssChangelog');
+ }
+
+ public function rssPiwik()
+ {
+ try {
+ $rss = new RssRenderer('http://feeds.feedburner.com/Piwik');
+ $rss->showDescription(true);
+
+ return $rss->get();
+
+ } catch (\Exception $e) {
+
+ return $this->error($e);
+ }
+ }
+
+ public function rssChangelog()
{
- $category = 'Example Widgets';
- $controller = 'ExampleRssWidget';
+ try {
+ $rss = new RssRenderer('http://feeds.feedburner.com/PiwikReleases');
+ $rss->setCountPosts(1);
+ $rss->showDescription(true);
+ $rss->showContent(false);
+
+ return $rss->get();
- $widgetsList->add($category, 'Piwik.org Blog', $controller, 'rssPiwik');
- $widgetsList->add($category, 'Piwik Changelog', $controller, 'rssChangelog');
+ } catch (\Exception $e) {
+
+ return $this->error($e);
+ }
}
+ /**
+ * @param \Exception $e
+ * @return string
+ */
+ private function error($e)
+ {
+ return '<div class="pk-emptyDataTable">'
+ . Piwik::translate('General_ErrorRequest')
+ . ' - ' . $e->getMessage() . '</div>';
+ }
}
diff --git a/plugins/Goals/Widgets.php b/plugins/Goals/Widgets.php
index ae62cc1c45..f0dfddde43 100644
--- a/plugins/Goals/Widgets.php
+++ b/plugins/Goals/Widgets.php
@@ -15,34 +15,34 @@ use Piwik\Piwik;
class Widgets extends \Piwik\Plugin\Widgets
{
- public function configure(WidgetsList $widgetsList)
- {
- $idSite = Common::getRequestVar('idSite', null, 'int');
-
- $site = new Site($idSite);
- if ($site->isEcommerceEnabled()) {
- $this->addEcommerceWidgets($widgetsList);
- }
+ protected $category = 'Goals_Goals';
- $this->addGoalsWidgets($widgetsList, $idSite);
- }
-
- private function addEcommerceWidgets(WidgetsList $widgetsList)
+ protected function init()
{
- $widgetsList->add('Goals_Ecommerce', 'Goals_EcommerceOverview', 'Goals', 'widgetGoalReport', array('idGoal' => Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER));
- $widgetsList->add('Goals_Ecommerce', 'Goals_EcommerceLog', 'Goals', 'getEcommerceLog');
- }
+ $this->addWidget('Goals_GoalsOverview', 'widgetGoalsOverview');
- private function addGoalsWidgets(WidgetsList $widgetsList, $idSite)
- {
- $widgetsList->add('Goals_Goals', 'Goals_GoalsOverview', 'Goals', 'widgetGoalsOverview');
+ $idSite = $this->getIdSite();
+ $goals = API::getInstance()->getGoals($idSite);
- $goals = API::getInstance()->getGoals($idSite);
if (count($goals) > 0) {
foreach ($goals as $goal) {
- $widgetsList->add('Goals_Goals', Common::sanitizeInputValue($goal['name']), 'Goals', 'widgetGoalReport', array('idGoal' => $goal['idgoal']));
+ $name = Common::sanitizeInputValue($goal['name']);
+ $params = array('idGoal' => $goal['idgoal']);
+
+ $this->addWidget($name, 'widgetGoalReport', $params);
}
}
+
+ $site = new Site($idSite);
+ if ($site->isEcommerceEnabled()) {
+ $this->addWidgetWithCustomCategory('Goals_Ecommerce', 'Goals_EcommerceOverview', 'widgetGoalReport', array('idGoal' => Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER));
+ $this->addWidgetWithCustomCategory('Goals_Ecommerce', 'Goals_EcommerceLog', 'getEcommerceLog');
+ }
+ }
+
+ private function getIdSite()
+ {
+ return Common::getRequestVar('idSite', null, 'int');
}
}
diff --git a/plugins/Insights/Widgets.php b/plugins/Insights/Widgets.php
index 6ce632d8bc..799662deb5 100644
--- a/plugins/Insights/Widgets.php
+++ b/plugins/Insights/Widgets.php
@@ -8,17 +8,13 @@
*/
namespace Piwik\Plugins\Insights;
-use Piwik\WidgetsList;
-
class Widgets extends \Piwik\Plugin\Widgets
{
- public function configure(WidgetsList $widgetsList)
- {
- $category = 'Insights_WidgetCategory';
- $controller = 'Insights';
+ protected $category = 'Insights_WidgetCategory';
- $widgetsList->add($category, 'Insights_OverviewWidgetTitle', $controller, 'getInsightsOverview');
- $widgetsList->add($category, 'Insights_MoversAndShakersWidgetTitle', $controller, 'getOverallMoversAndShakers');
+ public function init()
+ {
+ $this->addWidget('Insights_OverviewWidgetTitle', 'getInsightsOverview');
+ $this->addWidget('Insights_MoversAndShakersWidgetTitle', 'getOverallMoversAndShakers');
}
-
}
diff --git a/plugins/Live/Widgets.php b/plugins/Live/Widgets.php
index 101f7f4e77..2fcb98ad29 100644
--- a/plugins/Live/Widgets.php
+++ b/plugins/Live/Widgets.php
@@ -8,17 +8,14 @@
*/
namespace Piwik\Plugins\Live;
-use Piwik\WidgetsList;
-
class Widgets extends \Piwik\Plugin\Widgets
{
- public function configure(WidgetsList $widgetsList)
- {
- $category = 'Live!';
- $controller = 'Live';
+ protected $category = 'Live!';
- $widgetsList->add($category, 'Live_VisitorsInRealTime', $controller, 'widget');
- $widgetsList->add($category, 'Live_VisitorProfile', $controller, 'getVisitorProfilePopup');
+ public function init()
+ {
+ $this->addWidget('Live_VisitorsInRealTime', 'widget');
+ $this->addWidget('Live_VisitorProfile', 'getVisitorProfilePopup');
}
}
diff --git a/plugins/Referrers/Widgets.php b/plugins/Referrers/Widgets.php
index 0a565ddb8c..4e23c9f746 100644
--- a/plugins/Referrers/Widgets.php
+++ b/plugins/Referrers/Widgets.php
@@ -9,14 +9,15 @@
namespace Piwik\Plugins\Referrers;
use Piwik\SettingsPiwik;
-use Piwik\WidgetsList;
class Widgets extends \Piwik\Plugin\Widgets
{
- public function configure(WidgetsList $widgetsList)
+ protected $category = 'SEO';
+
+ public function init()
{
if (SettingsPiwik::isSegmentationEnabled()) {
- $widgetsList->add('SEO', 'Referrers_WidgetTopKeywordsForPages', 'Referrers', 'getKeywordsForPage');
+ $this->addWidget('Referrers_WidgetTopKeywordsForPages', 'getKeywordsForPage');
}
}
diff --git a/plugins/SEO/Controller.php b/plugins/SEO/Controller.php
deleted file mode 100644
index d9a3f45731..0000000000
--- a/plugins/SEO/Controller.php
+++ /dev/null
@@ -1,47 +0,0 @@
-<?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\SEO;
-
-use Piwik\Common;
-use Piwik\DataTable\Renderer;
-use Piwik\Site;
-use Piwik\UrlHelper;
-use Piwik\View;
-
-/**
- */
-class Controller extends \Piwik\Plugin\Controller
-{
- function getRank()
- {
- $idSite = Common::getRequestVar('idSite');
- $site = new Site($idSite);
-
- $url = urldecode(Common::getRequestVar('url', '', 'string'));
-
- if (!empty($url) && strpos($url, 'http://') !== 0 && strpos($url, 'https://') !== 0) {
- $url = 'http://' . $url;
- }
-
- if (empty($url) || !UrlHelper::isLookLikeUrl($url)) {
- $url = $site->getMainUrl();
- }
-
- $dataTable = API::getInstance()->getRank($url);
-
- $view = new View('@SEO/getRank');
- $view->urlToRank = RankChecker::extractDomainFromUrl($url);
-
- /** @var \Piwik\DataTable\Renderer\Php $renderer */
- $renderer = Renderer::factory('php');
- $renderer->setSerialize(false);
- $view->ranks = $renderer->render($dataTable);
- return $view->render();
- }
-}
diff --git a/plugins/SEO/Widgets.php b/plugins/SEO/Widgets.php
index 969c918eb3..bf2e95e0a7 100644
--- a/plugins/SEO/Widgets.php
+++ b/plugins/SEO/Widgets.php
@@ -8,13 +8,47 @@
*/
namespace Piwik\Plugins\SEO;
-use Piwik\WidgetsList;
+use Piwik\Common;
+use Piwik\DataTable\Renderer;
+use Piwik\Site;
+use Piwik\UrlHelper;
+use Piwik\View;
class Widgets extends \Piwik\Plugin\Widgets
{
- public function configure(WidgetsList $widgetsList)
+ protected $category = 'SEO';
+
+ public function init()
+ {
+ $this->addWidget('SEO_SeoRankings', 'getRank');
+ }
+
+ public function getRank()
{
- $widgetsList->add('SEO', 'SEO_SeoRankings', 'SEO', 'getRank');
+ $idSite = Common::getRequestVar('idSite');
+ $site = new Site($idSite);
+
+ $url = urldecode(Common::getRequestVar('url', '', 'string'));
+
+ if (!empty($url) && strpos($url, 'http://') !== 0 && strpos($url, 'https://') !== 0) {
+ $url = 'http://' . $url;
+ }
+
+ if (empty($url) || !UrlHelper::isLookLikeUrl($url)) {
+ $url = $site->getMainUrl();
+ }
+
+ $dataTable = API::getInstance()->getRank($url);
+
+ $view = new View('@SEO/getRank');
+ $view->urlToRank = RankChecker::extractDomainFromUrl($url);
+
+ /** @var \Piwik\DataTable\Renderer\Php $renderer */
+ $renderer = Renderer::factory('php');
+ $renderer->setSerialize(false);
+ $view->ranks = $renderer->render($dataTable);
+
+ return $view->render();
}
}
diff --git a/plugins/VisitFrequency/Widgets.php b/plugins/VisitFrequency/Widgets.php
index 1b132c9f45..53a5ddcd47 100644
--- a/plugins/VisitFrequency/Widgets.php
+++ b/plugins/VisitFrequency/Widgets.php
@@ -8,17 +8,15 @@
*/
namespace Piwik\Plugins\VisitFrequency;
-use Piwik\WidgetsList;
-
class Widgets extends \Piwik\Plugin\Widgets
{
- public function configure(WidgetsList $widgetsList)
- {
- $category = 'General_Visitors';
- $controller = 'VisitFrequency';
+ protected $category = 'General_Visitors';
- $widgetsList->add($category, 'VisitFrequency_WidgetOverview', $controller, 'getSparklines');
- $widgetsList->add($category, 'VisitFrequency_WidgetGraphReturning', $controller, 'getEvolutionGraph',
+ public function init()
+ {
+ $this->addWidget('VisitFrequency_WidgetOverview', 'getSparklines');
+ $this->addWidget('VisitFrequency_WidgetGraphReturning',
+ 'getEvolutionGraph',
array('columns' => array('nb_visits_returning')));
}
diff --git a/plugins/VisitsSummary/Widgets.php b/plugins/VisitsSummary/Widgets.php
index 3e1b5cfbfe..5ec7eef56e 100644
--- a/plugins/VisitsSummary/Widgets.php
+++ b/plugins/VisitsSummary/Widgets.php
@@ -8,18 +8,15 @@
*/
namespace Piwik\Plugins\VisitsSummary;
-use Piwik\WidgetsList;
-
class Widgets extends \Piwik\Plugin\Widgets
{
- public function configure(WidgetsList $widgetsList)
- {
- $category = 'VisitsSummary_VisitsSummary';
- $controller = 'VisitsSummary';
+ protected $category = 'VisitsSummary_VisitsSummary';
- $widgetsList->add($category, 'VisitsSummary_WidgetLastVisits', $controller, 'getEvolutionGraph', array('columns' => array('nb_visits')));
- $widgetsList->add($category, 'VisitsSummary_WidgetVisits', $controller, 'getSparklines');
- $widgetsList->add($category, 'VisitsSummary_WidgetOverviewGraph', $controller, 'index');
+ public function init()
+ {
+ $this->addWidget('VisitsSummary_WidgetLastVisits', 'getEvolutionGraph', array('columns' => array('nb_visits')));
+ $this->addWidget('VisitsSummary_WidgetVisits', 'getSparklines');
+ $this->addWidget('VisitsSummary_WidgetOverviewGraph', 'index');
}
}
diff --git a/plugins/Widgetize/Widgetize.php b/plugins/Widgetize/Widgetize.php
index 992155a061..c01c8638be 100644
--- a/plugins/Widgetize/Widgetize.php
+++ b/plugins/Widgetize/Widgetize.php
@@ -9,12 +9,7 @@
*/
namespace Piwik\Plugins\Widgetize;
-use Piwik\Menu\MenuTop;
-use Piwik\Piwik;
-/**
- *
- */
class Widgetize extends \Piwik\Plugin
{
/**