Skip to content

Commit

Permalink
Merge branch 'master' of github.com:piwik/piwik
Browse files Browse the repository at this point in the history
  • Loading branch information
mattab committed Jun 10, 2014
2 parents 32e2342 + b8aa95f commit bb05000
Show file tree
Hide file tree
Showing 44 changed files with 673 additions and 252 deletions.
1 change: 1 addition & 0 deletions core/Menu/MenuAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function getMenu()

/**
* @ignore
* @deprecated
*/
Piwik::postEvent('Menu.Admin.addItems', array());

Expand Down
1 change: 1 addition & 0 deletions core/Menu/MenuReporting.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function getMenu()

/**
* @ignore
* @deprecated
*/
Piwik::postEvent('Menu.Reporting.addItems', array());

Expand Down
1 change: 1 addition & 0 deletions core/Menu/MenuTop.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public function getMenu()

/**
* @ignore
* @deprecated
*/
Piwik::postEvent('Menu.Top.addItems', array());

Expand Down
29 changes: 29 additions & 0 deletions core/Plugin/Widgets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugin;

use Piwik\WidgetsList;

/**
* Base class of all plugin widget providers. Plugins that define their own widgets can extend this class to easily
* add new widgets, to remove or to rename existing items.
*
* For an example, see the {@link https://github.com/piwik/piwik/blob/master/plugins/ExampleRssWidget/Widget.php} plugin.
*
* @api
*/
class Widgets
{
/**
* Configures the widgets. Here you can for instance add or remove widgets.
*/
public function configure(WidgetsList $widgetsList)
{
}
}
1 change: 1 addition & 0 deletions core/TaskScheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ private function collectTasksRegisteredViaEvent()

/**
* @ignore
* @deprecated
*/
Piwik::postEvent(self::GET_TASKS_EVENT, array(&$tasks));

Expand Down
36 changes: 21 additions & 15 deletions core/WidgetsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,25 @@
*/
namespace Piwik;

use Piwik\Plugin\Manager as PluginManager;

/**
* Manages the global list of reports that can be displayed as dashboard widgets.
*
* Reports are added as dashboard widgets through the {@hook WidgetsList.addWidgets}
* event. Observers for this event should call the {@link add()} method to add reports.
*
* @api
* @method static \Piwik\WidgetsList getInstance()
*/
class WidgetsList
class WidgetsList extends Singleton
{
/**
* List of widgets
*
* @var array
*/
static protected $widgets = null;
static protected $widgets = array();

/**
* Indicates whether the hook was posted or not
Expand Down Expand Up @@ -71,20 +74,18 @@ private static function addWidgets()
self::$hookCalled = true;

/**
* Used to collect all available dashboard widgets.
*
* Subscribe to this event to make your plugin's reports or other controller actions available
* as dashboard widgets. Event handlers should call the {@link WidgetsList::add()} method for each
* new dashboard widget.
*
* **Example**
*
* public function addWidgets()
* {
* WidgetsList::add('General_Actions', 'General_Pages', 'Actions', 'getPageUrls');
* }
* @ignore
* @deprecated
*/
Piwik::postEvent('WidgetsList.addWidgets');

/** @var \Piwik\Plugin\Widgets[] $widgets */
$widgets = PluginManager::getInstance()->findComponents('Widgets', 'Piwik\\Plugin\\Widgets');
$widgetsList = self::getInstance();

foreach ($widgets as $widget) {
$widget->configure($widgetsList);
}
}
}

Expand Down Expand Up @@ -145,6 +146,11 @@ static public function add($widgetCategory, $widgetName, $controllerName, $contr
}
$widgetUniqueId .= $name . $value;
}

if (!array_key_exists($widgetCategory, self::$widgets)) {
self::$widgets[$widgetCategory] = array();
}

self::$widgets[$widgetCategory][] = array(
'name' => $widgetName,
'uniqueId' => $widgetUniqueId,
Expand Down Expand Up @@ -209,7 +215,7 @@ static public function isDefined($controllerName, $controllerAction)
*/
public static function _reset()
{
self::$widgets = null;
self::$widgets = array();
self::$hookCalled = false;
}
}
30 changes: 1 addition & 29 deletions plugins/Actions/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@
use Piwik\ArchiveProcessor;
use Piwik\Common;
use Piwik\Db;
use Piwik\Menu\MenuAbstract;
use Piwik\Menu\MenuMain;
use Piwik\MetricsFormatter;
use Piwik\Piwik;
use Piwik\Plugin\ViewDataTable;
use Piwik\Plugins\CoreVisualizations\Visualizations\HtmlTable;
use Piwik\Site;
use Piwik\WidgetsList;

/**
* Actions plugin
Expand All @@ -37,7 +34,6 @@ class Actions extends \Piwik\Plugin
public function getListHooksRegistered()
{
$hooks = array(
'WidgetsList.addWidgets' => 'addWidgets',
'API.getReportMetadata' => 'getReportMetadata',
'API.getSegmentDimensionMetadata' => 'getSegmentsMetadata',
'ViewDataTable.configure' => 'configureViewDataTable',
Expand Down Expand Up @@ -462,29 +458,6 @@ public function getReportMetadata(&$reports)
}
}

function addWidgets()
{
WidgetsList::add('General_Actions', 'General_Pages', 'Actions', 'getPageUrls');
WidgetsList::add('General_Actions', 'Actions_WidgetPageTitles', 'Actions', 'getPageTitles');
WidgetsList::add('General_Actions', 'General_Outlinks', 'Actions', 'getOutlinks');
WidgetsList::add('General_Actions', 'General_Downloads', 'Actions', 'getDownloads');
WidgetsList::add('General_Actions', 'Actions_WidgetPagesEntry', 'Actions', 'getEntryPageUrls');
WidgetsList::add('General_Actions', 'Actions_WidgetPagesExit', 'Actions', 'getExitPageUrls');
WidgetsList::add('General_Actions', 'Actions_WidgetEntryPageTitles', 'Actions', 'getEntryPageTitles');
WidgetsList::add('General_Actions', 'Actions_WidgetExitPageTitles', 'Actions', 'getExitPageTitles');

if ($this->isSiteSearchEnabled()) {
WidgetsList::add('Actions_SubmenuSitesearch', 'Actions_WidgetSearchKeywords', 'Actions', 'getSiteSearchKeywords');

if (self::isCustomVariablesPluginsEnabled()) {
WidgetsList::add('Actions_SubmenuSitesearch', 'Actions_WidgetSearchCategories', 'Actions', 'getSiteSearchCategories');
}
WidgetsList::add('Actions_SubmenuSitesearch', 'Actions_WidgetSearchNoResultKeywords', 'Actions', 'getSiteSearchNoResultKeywords');
WidgetsList::add('Actions_SubmenuSitesearch', 'Actions_WidgetPageUrlsFollowingSearch', 'Actions', 'getPageUrlsFollowingSiteSearch');
WidgetsList::add('Actions_SubmenuSitesearch', 'Actions_WidgetPageTitlesFollowingSearch', 'Actions', 'getPageTitlesFollowingSiteSearch');
}
}

public function isSiteSearchEnabled()
{
$idSite = Common::getRequestVar('idSite', 0, 'int');
Expand Down Expand Up @@ -515,12 +488,11 @@ static public function checkCustomVariablesPluginEnabled()
}
}

static protected function isCustomVariablesPluginsEnabled()
static public function isCustomVariablesPluginsEnabled()
{
return \Piwik\Plugin\Manager::getInstance()->isPluginActivated('CustomVariables');
}


public function configureViewDataTable(ViewDataTable $view)
{
switch ($view->requestConfig->apiMethodToRequestDataTable) {
Expand Down
51 changes: 51 additions & 0 deletions plugins/Actions/Widgets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\Actions;

use Piwik\WidgetsList;

class Widgets extends \Piwik\Plugin\Widgets
{

public function configure(WidgetsList $widgetsList)
{
$category = 'General_Actions';
$controller = 'Actions';

$widgetsList->add($category, 'General_Pages', $controller, 'getPageUrls');
$widgetsList->add($category, 'Actions_WidgetPageTitles', $controller, 'getPageTitles');
$widgetsList->add($category, 'General_Outlinks', $controller, 'getOutlinks');
$widgetsList->add($category, 'General_Downloads', $controller, 'getDownloads');
$widgetsList->add($category, 'Actions_WidgetPagesEntry', $controller, 'getEntryPageUrls');
$widgetsList->add($category, 'Actions_WidgetPagesExit', $controller, 'getExitPageUrls');
$widgetsList->add($category, 'Actions_WidgetEntryPageTitles', $controller, 'getEntryPageTitles');
$widgetsList->add($category, 'Actions_WidgetExitPageTitles', $controller, 'getExitPageTitles');

$actions = new Actions();
if ($actions->isSiteSearchEnabled()) {
$this->addSearchWidgets($widgetsList, $controller);
}
}

private function addSearchWidgets(WidgetsList $widgetsList, $controller)
{
$category = 'Actions_SubmenuSitesearch';

$widgetsList->add($category, 'Actions_WidgetSearchKeywords', $controller, 'getSiteSearchKeywords');

if (Actions::isCustomVariablesPluginsEnabled()) {
$widgetsList->add($category, 'Actions_WidgetSearchCategories', $controller, 'getSiteSearchCategories');
}

$widgetsList->add($category, 'Actions_WidgetSearchNoResultKeywords', $controller, 'getSiteSearchNoResultKeywords');
$widgetsList->add($category, 'Actions_WidgetPageUrlsFollowingSearch', $controller, 'getPageUrlsFollowingSiteSearch');
$widgetsList->add($category, 'Actions_WidgetPageTitlesFollowingSearch', $controller, 'getPageTitlesFollowingSiteSearch');
}

}
58 changes: 58 additions & 0 deletions plugins/CoreConsole/Commands/GenerateWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/

namespace Piwik\Plugins\CoreConsole\Commands;

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
*/
class GenerateWidget extends GeneratePluginBase
{
protected function configure()
{
$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');
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$pluginName = $this->getPluginName($input, $output);

$exampleFolder = PIWIK_INCLUDE_PATH . '/plugins/ExamplePlugin';
$replace = array('ExampleRssWidget' => $pluginName);
$whitelistFiles = array('/Widgets.php');

$this->copyTemplateToPlugin($exampleFolder, $pluginName, $replace, $whitelistFiles);

$this->writeSuccessMessage($output, array(
sprintf('Widgets.php for %s generated.', $pluginName),
'You can now start defining your plugin widgets',
'Enjoy!'
));
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return array
* @throws \RunTimeException
*/
protected function getPluginName(InputInterface $input, OutputInterface $output)
{
$pluginNames = $this->getPluginNamesHavingNotSpecificFile('Widgets.php');
$invalidName = 'You have to enter the name of an existing plugin which does not already have any widgets defined';

return $this->askPluginNameAndValidate($input, $output, $pluginNames, $invalidName);
}

}
12 changes: 0 additions & 12 deletions plugins/CoreHome/CoreHome.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
*/
namespace Piwik\Plugins\CoreHome;

use Piwik\WidgetsList;

/**
*
*/
Expand All @@ -23,20 +21,10 @@ public function getListHooksRegistered()
return array(
'AssetManager.getStylesheetFiles' => 'getStylesheetFiles',
'AssetManager.getJavaScriptFiles' => 'getJsFiles',
'WidgetsList.addWidgets' => 'addWidgets',
'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys'
);
}

/**
* Adds the donate form widget.
*/
public function addWidgets()
{
WidgetsList::add('Example Widgets', 'CoreHome_SupportPiwik', 'CoreHome', 'getDonateForm');
WidgetsList::add('Example Widgets', 'Installation_Welcome', 'CoreHome', 'getPromoVideo');
}

public function getStylesheetFiles(&$stylesheets)
{
$stylesheets[] = "libs/jquery/themes/base/jquery-ui.css";
Expand Down
24 changes: 24 additions & 0 deletions plugins/CoreHome/Widgets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\CoreHome;

use Piwik\WidgetsList;

class Widgets extends \Piwik\Plugin\Widgets
{
public function configure(WidgetsList $widgetsList)
{
$category = 'Example Widgets';
$controller = 'CoreHome';

$widgetsList->add($category, 'CoreHome_SupportPiwik', $controller, 'getDonateForm');
$widgetsList->add($category, 'Installation_Welcome', $controller, 'getPromoVideo');
}

}
Loading

0 comments on commit bb05000

Please sign in to comment.