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:
authormattab <matthieu.aubry@gmail.com>2013-03-28 03:42:39 +0400
committermattab <matthieu.aubry@gmail.com>2013-03-28 03:42:40 +0400
commitae4b03163792f0b6e933933e5d37df87dc3fd566 (patch)
treed1d7510a9728f587d3d63ebd03e4ecf3d904838b /plugins/ExampleUI
parent158c2150f5f2e13ece459b8d131244c11b763997 (diff)
Mass conversion of all files to the newly agreed coding standard: PSR 1/2
Converting Piwik core source files, PHP, JS, TPL, CSS More info: http://piwik.org/participate/coding-standards/
Diffstat (limited to 'plugins/ExampleUI')
-rw-r--r--plugins/ExampleUI/API.php174
-rw-r--r--plugins/ExampleUI/Controller.php234
-rw-r--r--plugins/ExampleUI/ExampleUI.php87
3 files changed, 247 insertions, 248 deletions
diff --git a/plugins/ExampleUI/API.php b/plugins/ExampleUI/API.php
index c88be1d598..91e29806be 100644
--- a/plugins/ExampleUI/API.php
+++ b/plugins/ExampleUI/API.php
@@ -1,109 +1,107 @@
<?php
/**
* Piwik - Open source web analytics
- *
+ *
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
- *
+ *
* @category Piwik_Plugins
* @package Piwik_ExampleUI
*/
/**
* ExampleUI API is also an example API useful if you are developing a Piwik plugin.
- *
- * The functions listed in this API are returning the data used in the Controller to draw graphs and
+ *
+ * The functions listed in this API are returning the data used in the Controller to draw graphs and
* display tables. See also the ExampleAPI plugin for an introduction to Piwik APIs.
- *
+ *
* @package Piwik_ExampleUI
*/
-class Piwik_ExampleUI_API
+class Piwik_ExampleUI_API
{
- static private $instance = null;
- static public function getInstance()
- {
- if (self::$instance == null)
- {
- self::$instance = new self;
- }
- return self::$instance;
- }
-
- public function getTemperaturesEvolution($date, $period)
- {
- $period = new Piwik_Period_Range($period, 'last30');
- $dateStart = $period->getDateStart()->toString('Y-m-d'); // eg. "2009-04-01"
- $dateEnd = $period->getDateEnd()->toString('Y-m-d'); // eg. "2009-04-30"
-
- // here you could select from your custom table in the database, eg.
- $query = "SELECT AVG(temperature)
+ static private $instance = null;
+
+ static public function getInstance()
+ {
+ if (self::$instance == null) {
+ self::$instance = new self;
+ }
+ return self::$instance;
+ }
+
+ public function getTemperaturesEvolution($date, $period)
+ {
+ $period = new Piwik_Period_Range($period, 'last30');
+ $dateStart = $period->getDateStart()->toString('Y-m-d'); // eg. "2009-04-01"
+ $dateEnd = $period->getDateEnd()->toString('Y-m-d'); // eg. "2009-04-30"
+
+ // here you could select from your custom table in the database, eg.
+ $query = "SELECT AVG(temperature)
FROM server_temperatures
WHERE date > ?
AND date < ?
GROUP BY date
ORDER BY date ASC";
- //$result = Piwik_FetchAll($query, array($dateStart, $dateEnd));
- // to keep things simple, we generate the data
- foreach($period->getSubperiods() as $subPeriod)
- {
- $server1 = mt_rand(50,90);
- $server2 = mt_rand(40, 110);
- $value = array('server1' => $server1, 'server2' => $server2);
- $temperatures[$subPeriod->getLocalizedShortString()] = $value;
- }
-
- // convert this array to a DataTable object
- $dataTable = new Piwik_DataTable();
- $dataTable->addRowsFromArrayWithIndexLabel($temperatures);
- return $dataTable;
- }
-
- // we generate an array of random server temperatures
- public function getTemperatures()
- {
- $xAxis = array(
- '0h', '1h', '2h', '3h', '4h', '5h', '6h', '7h', '8h', '9h', '10h', '11h',
- '12h', '13h', '14h', '15h', '16h', '17h', '18h', '19h', '20h', '21h', '22h', '23h',
- );
- $temperatureValues = array_slice(range(50,90), 0, count($xAxis));
- shuffle($temperatureValues);
- $temperatures = array();
- foreach($xAxis as $i => $xAxisLabel) {
- $temperatures[$xAxisLabel] = $temperatureValues[$i];
- }
-
- // convert this array to a DataTable object
- $dataTable = new Piwik_DataTable();
- $dataTable->addRowsFromArrayWithIndexLabel($temperatures);
- return $dataTable;
- }
-
- public function getPlanetRatios()
- {
- $planetRatios = array(
- 'Mercury' => 0.382,
- 'Venus' => 0.949,
- 'Earth' => 1.00,
- 'Mars' => 0.532,
- 'Jupiter' => 11.209,
- 'Saturn' => 9.449,
- 'Uranus' => 4.007,
- 'Neptune' => 3.883,
- );
- // convert this array to a DataTable object
- $dataTable = new Piwik_DataTable();
- $dataTable->addRowsFromArrayWithIndexLabel($planetRatios);
- return $dataTable;
- }
-
- public function getPlanetRatiosWithLogos()
- {
- $planetsDataTable = $this->getPlanetRatios();
- foreach($planetsDataTable->getRows() as $row)
- {
- $row->addMetadata('logo', "plugins/ExampleUI/images/icons-planet/".strtolower($row->getColumn('label').".png"));
- $row->addMetadata('url', "http://en.wikipedia.org/wiki/".$row->getColumn('label'));
- }
- return $planetsDataTable;
- }
+ //$result = Piwik_FetchAll($query, array($dateStart, $dateEnd));
+ // to keep things simple, we generate the data
+ foreach ($period->getSubperiods() as $subPeriod) {
+ $server1 = mt_rand(50, 90);
+ $server2 = mt_rand(40, 110);
+ $value = array('server1' => $server1, 'server2' => $server2);
+ $temperatures[$subPeriod->getLocalizedShortString()] = $value;
+ }
+
+ // convert this array to a DataTable object
+ $dataTable = new Piwik_DataTable();
+ $dataTable->addRowsFromArrayWithIndexLabel($temperatures);
+ return $dataTable;
+ }
+
+ // we generate an array of random server temperatures
+ public function getTemperatures()
+ {
+ $xAxis = array(
+ '0h', '1h', '2h', '3h', '4h', '5h', '6h', '7h', '8h', '9h', '10h', '11h',
+ '12h', '13h', '14h', '15h', '16h', '17h', '18h', '19h', '20h', '21h', '22h', '23h',
+ );
+ $temperatureValues = array_slice(range(50, 90), 0, count($xAxis));
+ shuffle($temperatureValues);
+ $temperatures = array();
+ foreach ($xAxis as $i => $xAxisLabel) {
+ $temperatures[$xAxisLabel] = $temperatureValues[$i];
+ }
+
+ // convert this array to a DataTable object
+ $dataTable = new Piwik_DataTable();
+ $dataTable->addRowsFromArrayWithIndexLabel($temperatures);
+ return $dataTable;
+ }
+
+ public function getPlanetRatios()
+ {
+ $planetRatios = array(
+ 'Mercury' => 0.382,
+ 'Venus' => 0.949,
+ 'Earth' => 1.00,
+ 'Mars' => 0.532,
+ 'Jupiter' => 11.209,
+ 'Saturn' => 9.449,
+ 'Uranus' => 4.007,
+ 'Neptune' => 3.883,
+ );
+ // convert this array to a DataTable object
+ $dataTable = new Piwik_DataTable();
+ $dataTable->addRowsFromArrayWithIndexLabel($planetRatios);
+ return $dataTable;
+ }
+
+ public function getPlanetRatiosWithLogos()
+ {
+ $planetsDataTable = $this->getPlanetRatios();
+ foreach ($planetsDataTable->getRows() as $row) {
+ $row->addMetadata('logo', "plugins/ExampleUI/images/icons-planet/" . strtolower($row->getColumn('label') . ".png"));
+ $row->addMetadata('url', "http://en.wikipedia.org/wiki/" . $row->getColumn('label'));
+ }
+ return $planetsDataTable;
+ }
}
diff --git a/plugins/ExampleUI/Controller.php b/plugins/ExampleUI/Controller.php
index c57bbeb19e..8a997a9e92 100644
--- a/plugins/ExampleUI/Controller.php
+++ b/plugins/ExampleUI/Controller.php
@@ -14,124 +14,126 @@
*/
class Piwik_ExampleUI_Controller extends Piwik_Controller
{
- function dataTables()
- {
- $view = Piwik_ViewDataTable::factory('table');
- $view->init( $this->pluginName, __FUNCTION__, 'ExampleUI.getTemperatures' );
- $view->setColumnTranslation('value', "Temperature in °C");
- $view->setColumnTranslation('label', "Hour of day");
- $view->setSortedColumn('label', 'asc');
- $view->setGraphLimit( 24 );
- $view->setLimit( 24 );
- $view->disableExcludeLowPopulation();
- $view->disableShowAllColumns();
- $view->disableRowEvolution();
- $view->setAxisYUnit('°C'); // useful if the user requests the bar graph
- return $this->renderView($view);
- }
-
- function evolutionGraph()
- {
- echo "<h2>Evolution of server temperatures over the last few days</h2>";
- $this->echoEvolutionGraph();
- }
-
- function echoEvolutionGraph()
- {
- $view = Piwik_ViewDataTable::factory('graphEvolution');
- $view->init( $this->pluginName, __FUNCTION__, 'ExampleUI.getTemperaturesEvolution' );
- $view->setColumnTranslation('server1', "Temperature server piwik.org");
- $view->setColumnTranslation('server2', "Temperature server dev.piwik.org");
- $view->setAxisYUnit('°C'); // useful if the user requests the bar graph
- return $this->renderView($view);
- }
-
- function barGraph()
- {
- $view = Piwik_ViewDataTable::factory('graphVerticalBar');
- $view->init( $this->pluginName, __FUNCTION__, 'ExampleUI.getTemperatures' );
- $view->setColumnTranslation('value', "Temperature");
- $view->setAxisYUnit('°C');
- $view->setGraphLimit( 24 );
- $view->disableFooter();
- return $this->renderView($view);
- }
-
- function pieGraph()
- {
- $view = Piwik_ViewDataTable::factory('graphPie');
- $view->init( $this->pluginName, __FUNCTION__, 'ExampleUI.getPlanetRatios' );
- $view->setColumnsToDisplay( 'value' );
- $view->setColumnTranslation('value', "times the diameter of Earth");
- $view->setGraphLimit( 10 );
- $view->disableFooterIcons();
- return $this->renderView($view);
- }
-
- function tagClouds()
- {
- echo "<h2>Simple tag cloud</h2>";
- $this->echoSimpleTagClouds();
-
- echo "<br /><br /><h2>Advanced tag cloud: with logos and links</h2>
+ function dataTables()
+ {
+ $view = Piwik_ViewDataTable::factory('table');
+ $view->init($this->pluginName, __FUNCTION__, 'ExampleUI.getTemperatures');
+ $view->setColumnTranslation('value', "Temperature in °C");
+ $view->setColumnTranslation('label', "Hour of day");
+ $view->setSortedColumn('label', 'asc');
+ $view->setGraphLimit(24);
+ $view->setLimit(24);
+ $view->disableExcludeLowPopulation();
+ $view->disableShowAllColumns();
+ $view->disableRowEvolution();
+ $view->setAxisYUnit('°C'); // useful if the user requests the bar graph
+ return $this->renderView($view);
+ }
+
+ function evolutionGraph()
+ {
+ echo "<h2>Evolution of server temperatures over the last few days</h2>";
+ $this->echoEvolutionGraph();
+ }
+
+ function echoEvolutionGraph()
+ {
+ $view = Piwik_ViewDataTable::factory('graphEvolution');
+ $view->init($this->pluginName, __FUNCTION__, 'ExampleUI.getTemperaturesEvolution');
+ $view->setColumnTranslation('server1', "Temperature server piwik.org");
+ $view->setColumnTranslation('server2', "Temperature server dev.piwik.org");
+ $view->setAxisYUnit('°C'); // useful if the user requests the bar graph
+ return $this->renderView($view);
+ }
+
+ function barGraph()
+ {
+ $view = Piwik_ViewDataTable::factory('graphVerticalBar');
+ $view->init($this->pluginName, __FUNCTION__, 'ExampleUI.getTemperatures');
+ $view->setColumnTranslation('value', "Temperature");
+ $view->setAxisYUnit('°C');
+ $view->setGraphLimit(24);
+ $view->disableFooter();
+ return $this->renderView($view);
+ }
+
+ function pieGraph()
+ {
+ $view = Piwik_ViewDataTable::factory('graphPie');
+ $view->init($this->pluginName, __FUNCTION__, 'ExampleUI.getPlanetRatios');
+ $view->setColumnsToDisplay('value');
+ $view->setColumnTranslation('value', "times the diameter of Earth");
+ $view->setGraphLimit(10);
+ $view->disableFooterIcons();
+ return $this->renderView($view);
+ }
+
+ function tagClouds()
+ {
+ echo "<h2>Simple tag cloud</h2>";
+ $this->echoSimpleTagClouds();
+
+ echo "<br /><br /><h2>Advanced tag cloud: with logos and links</h2>
<ul style='list-style-type:disc;margin-left:50px'>
<li>The logo size is proportional to the value returned by the API</li>
<li>The logo is linked to a specific URL</li>
</ul><br /><br />";
- $this->echoAdvancedTagClouds();
- }
- function echoSimpleTagClouds()
- {
- $view = Piwik_ViewDataTable::factory('cloud');
- $view->init( $this->pluginName, __FUNCTION__, 'ExampleUI.getPlanetRatios' );
- $view->setColumnsToDisplay( array('label','value') );
- $view->setColumnTranslation('value', "times the diameter of Earth");
- $view->disableFooter();
- $this->renderView($view);
- }
- function echoAdvancedTagClouds()
- {
- $view = Piwik_ViewDataTable::factory('cloud');
- $view->init( $this->pluginName, __FUNCTION__, 'ExampleUI.getPlanetRatiosWithLogos' );
- $view->setDisplayLogoInTagCloud(true);
- $view->disableFooterExceptExportIcons();
- $view->setColumnsToDisplay( array('label','value') );
- $view->setColumnTranslation('value', "times the diameter of Earth");
- $this->renderView($view);
- }
-
- function sparklines()
- {
- require_once PIWIK_INCLUDE_PATH . '/core/SmartyPlugins/function.sparkline.php';
- $srcSparkline1 = Piwik_Url::getCurrentQueryStringWithParametersModified(array('action'=>'generateSparkline', 'server' => 'server1', 'rand'=>mt_rand()));
- $htmlSparkline1 = smarty_function_sparkline(array('src' => $srcSparkline1));
- echo "<div class='sparkline'>$htmlSparkline1 Evolution of temperature for server piwik.org</div>";
-
- $srcSparkline2 = Piwik_Url::getCurrentQueryStringWithParametersModified(array('action'=>'generateSparkline', 'server' => 'server2', 'rand'=>mt_rand()));
- $htmlSparkline2 = smarty_function_sparkline(array('src' => $srcSparkline2));
- echo "<div class='sparkline'>$htmlSparkline2 Evolution of temperature for server dev.piwik.org</div>";
- }
-
- function generateSparkline()
- {
- $serverRequested = Piwik_Common::getRequestVar('server', '');
- $view = Piwik_ViewDataTable::factory('sparkline');
- $view->init( $this->pluginName, __FUNCTION__, 'ExampleUI.getTemperaturesEvolution' );
- $view->setColumnsToDisplay($serverRequested);
- $this->renderView($view);
- }
-
- function misc()
- {
- echo "<h2>Evolution graph filtered to Google and Yahoo!</h2>";
- $this->echoDataTableSearchEnginesFiltered();
- }
-
- function echoDataTableSearchEnginesFiltered()
- {
- $view = $this->getLastUnitGraph($this->pluginName, __FUNCTION__, 'Referers.getSearchEngines');
- $view->setColumnsToDisplay( 'nb_visits' );
- $view->setSearchPattern('^(Google|Yahoo!)$', 'label');
- return $this->renderView($view);
- }
+ $this->echoAdvancedTagClouds();
+ }
+
+ function echoSimpleTagClouds()
+ {
+ $view = Piwik_ViewDataTable::factory('cloud');
+ $view->init($this->pluginName, __FUNCTION__, 'ExampleUI.getPlanetRatios');
+ $view->setColumnsToDisplay(array('label', 'value'));
+ $view->setColumnTranslation('value', "times the diameter of Earth");
+ $view->disableFooter();
+ $this->renderView($view);
+ }
+
+ function echoAdvancedTagClouds()
+ {
+ $view = Piwik_ViewDataTable::factory('cloud');
+ $view->init($this->pluginName, __FUNCTION__, 'ExampleUI.getPlanetRatiosWithLogos');
+ $view->setDisplayLogoInTagCloud(true);
+ $view->disableFooterExceptExportIcons();
+ $view->setColumnsToDisplay(array('label', 'value'));
+ $view->setColumnTranslation('value', "times the diameter of Earth");
+ $this->renderView($view);
+ }
+
+ function sparklines()
+ {
+ require_once PIWIK_INCLUDE_PATH . '/core/SmartyPlugins/function.sparkline.php';
+ $srcSparkline1 = Piwik_Url::getCurrentQueryStringWithParametersModified(array('action' => 'generateSparkline', 'server' => 'server1', 'rand' => mt_rand()));
+ $htmlSparkline1 = smarty_function_sparkline(array('src' => $srcSparkline1));
+ echo "<div class='sparkline'>$htmlSparkline1 Evolution of temperature for server piwik.org</div>";
+
+ $srcSparkline2 = Piwik_Url::getCurrentQueryStringWithParametersModified(array('action' => 'generateSparkline', 'server' => 'server2', 'rand' => mt_rand()));
+ $htmlSparkline2 = smarty_function_sparkline(array('src' => $srcSparkline2));
+ echo "<div class='sparkline'>$htmlSparkline2 Evolution of temperature for server dev.piwik.org</div>";
+ }
+
+ function generateSparkline()
+ {
+ $serverRequested = Piwik_Common::getRequestVar('server', '');
+ $view = Piwik_ViewDataTable::factory('sparkline');
+ $view->init($this->pluginName, __FUNCTION__, 'ExampleUI.getTemperaturesEvolution');
+ $view->setColumnsToDisplay($serverRequested);
+ $this->renderView($view);
+ }
+
+ function misc()
+ {
+ echo "<h2>Evolution graph filtered to Google and Yahoo!</h2>";
+ $this->echoDataTableSearchEnginesFiltered();
+ }
+
+ function echoDataTableSearchEnginesFiltered()
+ {
+ $view = $this->getLastUnitGraph($this->pluginName, __FUNCTION__, 'Referers.getSearchEngines');
+ $view->setColumnsToDisplay('nb_visits');
+ $view->setSearchPattern('^(Google|Yahoo!)$', 'label');
+ return $this->renderView($view);
+ }
}
diff --git a/plugins/ExampleUI/ExampleUI.php b/plugins/ExampleUI/ExampleUI.php
index 0937269bb3..11be32f4bd 100644
--- a/plugins/ExampleUI/ExampleUI.php
+++ b/plugins/ExampleUI/ExampleUI.php
@@ -1,10 +1,10 @@
<?php
/**
* Piwik - Open source web analytics
- *
+ *
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
- *
+ *
* @category Piwik_Plugins
* @package Piwik_ExampleUI
*/
@@ -25,48 +25,47 @@
*/
class Piwik_ExampleUI extends Piwik_Plugin
{
- /**
- * Return information about this plugin.
- *
- * @see Piwik_Plugin
- *
- * @return array
- */
- public function getInformation()
- {
- return array(
- 'description' => Piwik_Translate('ExampleUI_PluginDescription'),
- 'author' => 'Piwik',
- 'author_homepage' => 'http://piwik.org/',
- 'version' => '0.1',
- );
- }
-
- function getListHooksRegistered()
- {
- $hooks = array(
- 'Menu.add' => 'addMenus',
- );
- return $hooks;
- }
+ /**
+ * Return information about this plugin.
+ *
+ * @see Piwik_Plugin
+ *
+ * @return array
+ */
+ public function getInformation()
+ {
+ return array(
+ 'description' => Piwik_Translate('ExampleUI_PluginDescription'),
+ 'author' => 'Piwik',
+ 'author_homepage' => 'http://piwik.org/',
+ 'version' => '0.1',
+ );
+ }
+
+ function getListHooksRegistered()
+ {
+ $hooks = array(
+ 'Menu.add' => 'addMenus',
+ );
+ return $hooks;
+ }
- function addMenus()
- {
- $menus = array(
- 'Data tables' => 'dataTables',
- 'Evolution graph' => 'evolutionGraph',
- 'Bar graph' => 'barGraph',
- 'Pie graph' => 'pieGraph',
- 'Tag clouds' => 'tagClouds',
- 'Sparklines' => 'sparklines',
- 'Misc' => 'misc',
- );
+ function addMenus()
+ {
+ $menus = array(
+ 'Data tables' => 'dataTables',
+ 'Evolution graph' => 'evolutionGraph',
+ 'Bar graph' => 'barGraph',
+ 'Pie graph' => 'pieGraph',
+ 'Tag clouds' => 'tagClouds',
+ 'Sparklines' => 'sparklines',
+ 'Misc' => 'misc',
+ );
- Piwik_AddMenu('UI Framework', '', array('module' => 'ExampleUI', 'action' => 'dataTables'), true, 30);
- $order = 1;
- foreach($menus as $subMenu => $action)
- {
- Piwik_AddMenu('UI Framework', $subMenu, array('module' => 'ExampleUI', 'action' => $action), true, $order++);
- }
- }
+ Piwik_AddMenu('UI Framework', '', array('module' => 'ExampleUI', 'action' => 'dataTables'), true, 30);
+ $order = 1;
+ foreach ($menus as $subMenu => $action) {
+ Piwik_AddMenu('UI Framework', $subMenu, array('module' => 'ExampleUI', 'action' => $action), true, $order++);
+ }
+ }
}