[Piwik-svn] r376 - in trunk: . modules plugins/API plugins/ExamplePlugin
svnmaster at piwik.org
svnmaster at piwik.org
Fri Mar 14 22:55:05 CET 2008
Author: matt
Date: 2008-03-14 22:55:04 +0100 (Fri, 14 Mar 2008)
New Revision: 376
Modified:
trunk/LICENSE
trunk/modules/Access.php
trunk/modules/Controller.php
trunk/modules/Piwik.php
trunk/modules/Site.php
trunk/plugins/API/Controller.php
trunk/plugins/ExamplePlugin/API.php
trunk/plugins/ExamplePlugin/ExamplePlugin.php
Log:
- adding documentation on http://dev.piwik.org/trac/wiki/Plugins/GlobalFunctions about plugins development
Modified: trunk/LICENSE
===================================================================
--- trunk/LICENSE 2008-03-14 20:12:41 UTC (rev 375)
+++ trunk/LICENSE 2008-03-14 21:55:04 UTC (rev 376)
@@ -1,2 +1,2 @@
-# GNU/GPL v2 or later
+# GNU/GPL v3 or later
see misc/license.txt
\ No newline at end of file
Modified: trunk/modules/Access.php
===================================================================
--- trunk/modules/Access.php 2008-03-14 20:12:41 UTC (rev 375)
+++ trunk/modules/Access.php 2008-03-14 21:55:04 UTC (rev 376)
@@ -30,6 +30,8 @@
* There is only one Super User ; he has ADMIN access to all the websites
* and he only can change the main configuration settings.
*
+ * TODO This class should be in the Login plugin
+ * This class should instead be an interface to be implemented by a Login plugin for other types of authentication (ldpa,openid,etc.)
* @package Piwik
*/
@@ -232,7 +234,7 @@
$idSites = array($idSites);
}
$idSitesAccessible = $this->getSitesIdWithAtLeastViewAccess();
-//var_dump($idSitesAccessible);exit;
+
foreach($idSites as $idsite)
{
if(!in_array($idsite, $idSitesAccessible))
Modified: trunk/modules/Controller.php
===================================================================
--- trunk/modules/Controller.php 2008-03-14 20:12:41 UTC (rev 375)
+++ trunk/modules/Controller.php 2008-03-14 21:55:04 UTC (rev 376)
@@ -26,7 +26,7 @@
$this->date = Piwik_Date::factory($this->strDate);
$this->strDate = $this->date->toString();
} catch(Exception $e){
- // the date looks like YYYY-MM-DD,YYYY-MM-DD or other format
+ // the date looks like YYYY-MM-DD,YYYY-MM-DD or other format
// case the date looks like a range
$this->date = null;
}
Modified: trunk/modules/Piwik.php
===================================================================
--- trunk/modules/Piwik.php 2008-03-14 20:12:41 UTC (rev 375)
+++ trunk/modules/Piwik.php 2008-03-14 21:55:04 UTC (rev 376)
@@ -539,6 +539,16 @@
return Zend_Registry::get('access')->getIdentity();
}
+ static public function isUserIsSuperUserOrTheUser( $theUser )
+ {
+ try{
+ self::checkUserIsSuperUserOrTheUser( $theUser );
+ return true;
+ } catch( Exception $e){
+ return false;
+ }
+ }
+
// Accessible either to the user itself
static public function checkUserIsSuperUserOrTheUser( $theUser )
{
@@ -548,8 +558,18 @@
// or to the super user
Piwik::checkUserIsSuperUser();
}
+ } catch( Piwik_Access_NoAccessException $e){
+ throw new Piwik_Access_NoAccessException("The user has to be either the Super User or the user '$theUser' itself.");
+ }
+ }
+
+ static public function isUserIsSuperUser()
+ {
+ try{
+ self::checkUserIsSuperUser();
+ return true;
} catch( Exception $e){
- throw new Exception("The user has to be either the Super User or the user '$theUser' itself.");
+ return false;
}
}
@@ -558,15 +578,46 @@
Zend_Registry::get('access')->checkUserIsSuperUser();
}
+ static public function isUserHasAdminAccess( $idSites )
+ {
+ try{
+ self::checkUserHasAdminAccess( $idSites );
+ return true;
+ } catch( Exception $e){
+ return false;
+ }
+ }
+
static public function checkUserHasAdminAccess( $idSites )
{
Zend_Registry::get('access')->checkUserHasAdminAccess( $idSites );
}
+
+ static public function isUserHasSomeAdminAccess()
+ {
+ try{
+ self::checkUserHasSomeAdminAccess();
+ return true;
+ } catch( Exception $e){
+ return false;
+ }
+ }
+
static public function checkUserHasSomeAdminAccess()
{
Zend_Registry::get('access')->checkUserHasSomeAdminAccess();
}
+ static public function isUserHasViewAccess( $idSites )
+ {
+ try{
+ self::checkUserHasViewAccess( $idSites );
+ return true;
+ } catch( Exception $e){
+ return false;
+ }
+ }
+
static public function checkUserHasViewAccess( $idSites )
{
Zend_Registry::get('access')->checkUserHasViewAccess( $idSites );
Modified: trunk/modules/Site.php
===================================================================
--- trunk/modules/Site.php 2008-03-14 20:12:41 UTC (rev 375)
+++ trunk/modules/Site.php 2008-03-14 21:55:04 UTC (rev 376)
@@ -6,12 +6,12 @@
* @license http://www.gnu.org/licenses/gpl-3.0.html Gpl v3 or later
* @version $Id$
*
- * @package Piwik
+ * @package Piwik_Site
*/
/**
*
- * @package Piwik
+ * @package Piwik_Site
*/
class Piwik_Site
{
Modified: trunk/plugins/API/Controller.php
===================================================================
--- trunk/plugins/API/Controller.php 2008-03-14 20:12:41 UTC (rev 375)
+++ trunk/plugins/API/Controller.php 2008-03-14 21:55:04 UTC (rev 376)
@@ -66,7 +66,7 @@
echo "<p><i> Loaded successfully $loaded APIs</i></p>\n";
echo Piwik_API_Proxy::getInstance()->getAllInterfaceString();
- echo "<p><a href='?module=Home&action=index&idSite=1&period=day&date=yesterday'>Back to Piwik homepage</a></p>";
+ echo "<p><a href='?module=Home'>Back to Piwik homepage</a></p>";
}
}
Modified: trunk/plugins/ExamplePlugin/API.php
===================================================================
--- trunk/plugins/ExamplePlugin/API.php 2008-03-14 20:12:41 UTC (rev 375)
+++ trunk/plugins/ExamplePlugin/API.php 2008-03-14 21:55:04 UTC (rev 376)
@@ -10,6 +10,8 @@
*/
/**
+ * HOW TO VIEW THE API IN ACTION
+ * =============================
* Go to the API page in the Piwik Interface
* And try the API of the plugin ExamplePlugin
*/
Modified: trunk/plugins/ExamplePlugin/ExamplePlugin.php
===================================================================
--- trunk/plugins/ExamplePlugin/ExamplePlugin.php 2008-03-14 20:12:41 UTC (rev 375)
+++ trunk/plugins/ExamplePlugin/ExamplePlugin.php 2008-03-14 21:55:04 UTC (rev 376)
@@ -39,11 +39,76 @@
{
function index()
{
- // invoke view
- // render view
- // do stuff...
+ $out = '';
+ // get the date
+ // get the period
+ // get the idSite
+ // execute SQL query FetchAll
+ // execute SQL query FetchOne
+
+ $out .= '<i>This page aims to list the different functions you can use when programming plugins for Piwik.</i><br>';
+ $out .= '<b>Be careful, the following APIs may change in the near future as Piwik is still in development.</b><br>';
+
+ $out .= '<h2>General</h2>';
+ $out .= '<h3>Accessible from your plugin controller</h3>';
+
+ $out .= '<code>$this->date</code> = current selected <b>Piwik_Date</b> object (<a href="http://piwik.org/documentation/Piwik_Helper/Piwik_Date.html">documentation</a>)<br/>';
+ $out .= '<code>$period = Piwik_Common::getRequestVar("period");</code> - Get the current selected period<br/>';
+ $out .= '<code>$idSite = Piwik_Common::getRequestVar("idSite");</code> - Get the selected idSite<br/>';
+ $out .= '<code>$site = new Piwik_Site($idSite);</code> - Build the Piwik_Site object (<a href="http://piwik.org/documentation/Piwik_Site/Piwik_Site.html">documentation</a>)<br/>';
+ $out .= '<code>$this->str_date</code> = current selected date in YYYY-MM-DD format<br/>';
+
+ $out .= '<h3>Misc</h3>';
+ $out .= '<code>Piwik_AddMenu( $mainMenuName, $subMenuName, $url );</code> - Adds an entry to the menu in the Piwik interface (See the example in the <a href="http://dev.piwik.org/trac/browser/trunk/plugins/UserCountry/UserCountry.php#L146">UserCountry Plugin file</a>)<br/>';
+ $out .= '<code>Piwik_AddWidget( $pluginName, $controllerMethodToCall, $widgetTitle );</code> - Adds an entry to the menu in the Piwik interface (See the example in the <a href="http://dev.piwik.org/trac/browser/trunk/plugins/UserCountry/UserCountry.php#L143">UserCountry Plugin file</a>)<br/>';
+ $out .= '<code>Piwik::prefixTable("site")</code> = <b>' . Piwik::prefixTable("site") . '</b><br/>';
+
+
+ $out .= '<h2>User access</h2>';
+ $out .= '<code>Piwik::getCurrentUserLogin()</code> = <b>' . Piwik::getCurrentUserLogin() . '</b><br/>';
+ $out .= '<code>Piwik::isUserHasSomeAdminAccess()</code> = <b>' . self::boolToString(Piwik::isUserHasSomeAdminAccess()) . '</b><br/>';
+ $out .= '<code>Piwik::isUserHasAdminAccess( array $idSites = array(1,2) )</code> = <b>' . self::boolToString(Piwik::isUserHasAdminAccess(array(1,2) )) . '</b><br/>';
+ $out .= '<code>Piwik::isUserHasViewAccess( array $idSites = array(1) ) </code> = <b>' . self::boolToString(Piwik::isUserHasSomeAdminAccess(array(1))) . '</b><br/>';
+ $out .= '<code>Piwik::isUserIsSuperUser()</code> = <b>' . self::boolToString(Piwik::isUserHasSomeAdminAccess()) . '</b><br/>';
+
+ $out .= '<h2>Execute SQL queries</h2>';
+ $query = "SELECT token_auth FROM ".Piwik::prefixTable('user')." WHERE login = ?";
+ $result = Piwik_FetchOne($query, array('anonymous'));
+ $out .= '<code>Piwik_FetchOne("'.$query.'", array("anonymous"))</code> = <b>' . var_export($result,true) . '</b><br/>';
+
+ $out .= '<h2>Example Sites information API</h2>';
+ $out .= '<code>Piwik_SitesManager_API::getSitesWithViewAccess()</code> = <b><pre>' .var_export(Piwik_SitesManager_API::getSitesWithViewAccess(),true) . '</pre></b><br/>';
+ $out .= '<code>Piwik_SitesManager_API::getSitesWithAdminAccess()</code> = <b><pre>' .var_export(Piwik_SitesManager_API::getSitesWithAdminAccess(),true) . '</pre></b><br/>';
+
+ $out .= '<h2>Example API Users information</h2>';
+ $out .= 'View the list of API methods you can call on <a href="http://dev.piwik.org/trac/wiki/API/Reference#Methods">API reference</a><br/>';
+ $out .= 'For example you can try <code>Piwik_UsersManager_API::getUsersSitesFromAccess("view");</code> or <code>Piwik_UsersManager_API::deleteUser("userToDelete");</code><br/>';
+
+ $out .= '<h2>Smarty plugins</h2>';
+ $out .= 'There are some builtin plugins for Smarty especially developped for Piwik. <br>
+ You can find them on the <a href="http://dev.piwik.org/trac/browser/trunk/modules/SmartyPlugins">SVN at /trunk/modules/SmartyPlugins</a>. <br>
+ More documentation to come about smarty plugins.<br/>';
+
+ echo $out;
}
+
+ static private function boolToString($bool)
+ {
+ if($bool)
+ {
+ return "true";
+ }
+ else
+ {
+ return "false";
+ }
+ }
+ /**
+ * See the result on piwik/?module=ExamplePlugin&action=exampleWidget
+ * or in the dashboard > Add a new widget
+ *
+ */
function exampleWidget()
{
echo "Hello world! <br> You can output whatever you want in widgets, and put them on dashboard or everywhere on the web (in your blog, website, etc.).
@@ -52,6 +117,10 @@
<br><i>Happy coding!</i>";
}
+ /**
+ * Embed Matthieu's blog using widgetbox.com widget code
+ *
+ */
function blogMatthieu()
{
echo '
@@ -65,6 +134,10 @@
';
}
+ /**
+ * Simple feedburner statistics output
+ *
+ */
function feedburner()
{
$view = new Piwik_View('ExamplePlugin/feedburner.tpl');
@@ -78,8 +151,13 @@
echo $view->render();
}
+ /**
+ * Function called to save the Feedburner ID entered in the form
+ *
+ */
function saveFeedburnerName()
{
+ // we save the value in the DB for an authenticated user
if(Piwik::getCurrentUserLogin() != 'anonymous')
{
Piwik_Query('UPDATE '.Piwik::prefixTable('site').' SET feedburnerName = ?',
@@ -88,6 +166,7 @@
}
}
+// we register the widgets so they appear in the "Add a new widget" window in the dashboard
Piwik_AddWidget('ExamplePlugin', 'exampleWidget', 'Example widget');
Piwik_AddWidget('ExamplePlugin', 'feedburner', 'Feedburner statistics');
Piwik_AddWidget('ExamplePlugin', 'blogMatthieu', 'Blog matthieu RSS');
\ No newline at end of file
More information about the Piwik-svn
mailing list