Hello world!
"; echo "Happy coding with Piwik :)

"; } /** * See the result on piwik/?module=ExamplePlugin&action=exampleWidget * or in the dashboard > Add a new widget * */ public 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

"; } public function photostreamMatt() { echo ' '; } /** * this widgets shows how to make a remote API request to piwik.org * you find the main JS code in templates/piwikDownloads.twig */ public function piwikDownloads() { $view = new View('@ExamplePlugin/piwikDownloads'); $this->setGeneralVariablesView($view); echo $view->render(); } /** * This method displays a text containing an help about "How to build plugins for Piwik". * This help is then used on http://piwik.org/docs/plugins/functions * */ public 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 Date object (class)
'; $out .= '$period = Common::getRequestVar("period"); - Get the current selected period
'; $out .= '$idSite = Common::getRequestVar("idSite"); - Get the selected idSite
'; $out .= '$site = new Site($idSite); - Build the 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 .= 'WidgetsList::add( $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 .= 'Common::prefixTable("site") = ' . Common::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 " . Common::prefixTable('user') . " WHERE login = ?"; $result = Db::fetchOne($txtQuery, array('anonymous')); $out .= 'Db::fetchOne("' . $txtQuery . '", array("anonymous")) = ' . var_export($result, true) . '
'; $out .= '
'; $query = Db::query($txtQuery, array('anonymous')); $fetched = $query->fetch(); $token_auth = $fetched['token_auth']; $out .= '$query = Db::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 .= 'API::getInstance()->getSitesWithViewAccess() =
' . var_export(API::getInstance()->getSitesWithViewAccess(), true) . '

'; $out .= 'API::getInstance()->getSitesWithAdminAccess() =
' . var_export(API::getInstance()->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 API::getInstance()->getUsersSitesFromAccess("view"); or API::getInstance()->deleteUser("userToDelete");
'; $out .= '

Javascript in Piwik

'; $out .= '

i18n internationalization

'; $out .= 'In order to translate strings within Javascript code, you can use the javascript function _pk_translate( token );. '; $out .= '

Reload a widget in the dashboard

'; $out .= 'It is sometimes useful to reload one widget in the dashboard (for example, every 20 seconds for a real time widget, or after a setting change). You can easily force your widget to reload in the dashboard by calling the helper function $(this).parents(\'[widgetId]\').dashboardWidget(\'reload\');.'; $out .= '

Twig plugins

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