'Example Plugin', 'description' => 'Example Plugin: This plugin shows how to create a very simple plugin, that exports two widgets in the Dashboard.', 'author' => 'Piwik', 'author_homepage' => 'http://piwik.org/', 'version' => '0.1', 'translationAvailable' => true, ); } public function getListHooksRegistered() { return array( // 'Controller.renderView' => 'addUniqueVisitorsColumnToGivenReport', ); } function addUniqueVisitorsColumnToGivenReport($notification) { $view = $notification->getNotificationInfo(); $view = $view['view']; if($view->getCurrentControllerName() == 'Referers' && $view->getCurrentControllerAction() == 'getWebsites') { $view->addColumnToDisplay('nb_uniq_visitors'); } } function postLoad() { // we register the widgets so they appear in the "Add a new widget" window in the dashboard // Note that the first two parameters can be either a normal string, or an index to a translation string Piwik_AddWidget('ExamplePlugin_exampleWidgets', 'ExamplePlugin_exampleWidget', 'ExamplePlugin', 'exampleWidget'); Piwik_AddWidget('ExamplePlugin_exampleWidgets', 'ExamplePlugin_blogPiwikRss', 'ExamplePlugin', 'blogPiwik'); Piwik_AddWidget('ExamplePlugin_exampleWidgets', 'ExamplePlugin_photostreamMatt', 'ExamplePlugin', 'photostreamMatt'); } } /** * * @package Piwik_ExamplePlugin */ class Piwik_ExamplePlugin_Controller extends Piwik_Controller { /** * Go to /piwik/?module=ExamplePlugin&action=helloWorld to execute this method * */ function helloWorld() { echo "Hello world!
"; echo "Happy coding with Piwik :)"; } /** * See the result on piwik/?module=ExamplePlugin&action=exampleWidget * or in the dashboard > Add a new widget * */ function exampleWidget() { echo "Hello world!
You can output whatever you want in widgets, and put them on dashboard or everywhere on the web (in your blog, website, etc.).
Widgets can include graphs, tables, flash, text, images, etc.
It's very easy to create a new plugin and widgets in Piwik. Have a look at this example file (/plugins/ExamplePlugin/ExamplePlugin.php).
Happy coding!
You can easily use Jquery in widgets
"; } /** * Embed Piwik.org blog using widgetbox.com widget code */ function blogPiwik() { echo ' '; } function photostreamMatt() { echo ' '; } /** * This method displays a text containing an help about "How to build plugins for Piwik". * This help is then used on http://dev.piwik.org/trac/wiki/Plugins/GlobalFunctions * */ function index() { $out = ''; $out .= 'This page aims to list the different functions you can use when programming plugins for Piwik.
'; $out .= 'Be careful, the following APIs may change in the near future as Piwik is still in development.
'; $out .= '

General

'; $out .= '

Accessible from your plugin controller

'; $out .= '$this->date = current selected Piwik_Date object (class)
'; $out .= '$period = Piwik_Common::getRequestVar("period"); - Get the current selected period
'; $out .= '$idSite = Piwik_Common::getRequestVar("idSite"); - Get the selected idSite
'; $out .= '$site = new Piwik_Site($idSite); - Build the Piwik_Site object (class)
'; $out .= '$this->str_date = current selected date in YYYY-MM-DD format
'; $out .= '

Misc

'; $out .= 'Piwik_AddMenu( $mainMenuName, $subMenuName, $url ); - Adds an entry to the menu in the Piwik interface (See the example in the UserCountry Plugin file)
'; $out .= 'Piwik_AddWidget( $widgetCategory, $widgetName, $controllerName, $controllerAction, $customParameters = array()); - Adds a widget that users can add in the dashboard, or export using the Widgets link at the top of the screen. See the example in the UserCountry Plugin file or any other plugin)
'; $out .= 'Piwik::prefixTable("site") = ' . Piwik::prefixTable("site") . '
'; $out .= '

User access

'; $out .= 'Piwik::getCurrentUserLogin() = ' . Piwik::getCurrentUserLogin() . '
'; $out .= 'Piwik::isUserHasSomeAdminAccess() = ' . self::boolToString(Piwik::isUserHasSomeAdminAccess()) . '
'; $out .= 'Piwik::isUserHasAdminAccess( array $idSites = array(1,2) ) = ' . self::boolToString(Piwik::isUserHasAdminAccess(array(1,2) )) . '
'; $out .= 'Piwik::isUserHasViewAccess( array $idSites = array(1) ) = ' . self::boolToString(Piwik::isUserHasViewAccess(array(1))) . '
'; $out .= 'Piwik::isUserIsSuperUser() = ' . self::boolToString(Piwik::isUserIsSuperUser()) . '
'; $out .= '

Execute SQL queries

'; $txtQuery = "SELECT token_auth FROM ".Piwik::prefixTable('user')." WHERE login = ?"; $result = Piwik_FetchOne($txtQuery, array('anonymous')); $out .= 'Piwik_FetchOne("'.$txtQuery.'", array("anonymous")) = ' . var_export($result,true) . '
'; $out .= '
'; $query = Piwik_Query($txtQuery, array('anonymous')); $fetched = $query->fetch(); $token_auth = $fetched['token_auth']; $out .= '$query = Piwik_Query("'.$txtQuery.'", array("anonymous"))
'; $out .= '$fetched = $query->fetch();
'; $out .= 'At this point, we have: $fetched[\'token_auth\'] == '.var_export($token_auth,true) . '
'; $out .= '

Example Sites information API

'; $out .= 'Piwik_SitesManager_API::getSitesWithViewAccess() =
' .var_export(Piwik_SitesManager_API::getSitesWithViewAccess(),true) . '

'; $out .= 'Piwik_SitesManager_API::getSitesWithAdminAccess() =
' .var_export(Piwik_SitesManager_API::getSitesWithAdminAccess(),true) . '

'; $out .= '

Example API Users information

'; $out .= 'View the list of API methods you can call on API reference
'; $out .= 'For example you can try Piwik_UsersManager_API::getUsersSitesFromAccess("view"); or Piwik_UsersManager_API::deleteUser("userToDelete");
'; $out .= '

Smarty plugins

'; $out .= 'There are some builtin plugins for Smarty especially developped for Piwik.
You can find them on the SVN at /trunk/core/SmartyPlugins.
More documentation to come about smarty plugins.
'; echo $out; } static private function boolToString($bool) { return $bool ? "true" : "false"; } }