diff --git a/oss/piwik/trunk/plugins/DBStats/API.php b/oss/piwik/trunk/plugins/DBStats/API.php new file mode 100644 index 00000000..7076f8c0 --- /dev/null +++ b/oss/piwik/trunk/plugins/DBStats/API.php @@ -0,0 +1,97 @@ +database->toArray(); + // we decode the password. Password is html encoded because it's enclosed between " double quotes + $configDb['password'] = htmlspecialchars_decode($configDb['password']); + if(!isset($configDb['port'])) + { + // before 0.2.4 there is no port specified in config file + $configDb['port'] = '3306'; + } + + $link = mysql_connect($configDb['host'], $configDb['username'], $configDb['password']); + $status = mysql_stat($link); + mysql_close($link); + return $status; + } + + public function getTableStatus($table, $field = '') + { + Piwik::checkUserIsSuperUser(); + $db = Zend_Registry::get('db'); + // http://dev.mysql.com/doc/refman/5.1/en/show-table-status.html + $tables = $db->fetchAll("SHOW TABLE STATUS LIKE ". $db->quote($table)); + + if(!isset($tables[0])) { + throw new Exception('Error, table or field not found'); + } + if ($field == '') + { + return $tables[0]; + } + else + { + return $tables[0][$field]; + } + } + + public function getAllTablesStatus() + { + Piwik::checkUserIsSuperUser(); + $db = Zend_Registry::get('db'); + // http://dev.mysql.com/doc/refman/5.1/en/show-table-status.html + $tablesPiwik = Piwik::getTablesInstalled(); + $total = array('Name' => 'Total', 'Data_length' => 0, 'Index_length' => 0, 'Rows' => 0); + $table = array(); + foreach($tablesPiwik as $tableName) + { + $t = $this->getTableStatus($tableName); + $total['Data_length'] += $t['Data_length']; + $total['Index_length'] += $t['Index_length']; + $total['Rows'] += $t['Rows']; + + $t['Total_length'] = Piwik::getPrettySizeFromBytes($t['Index_length']+$t['Data_length']); + $t['Data_length'] = Piwik::getPrettySizeFromBytes($t['Data_length']); + $t['Index_length'] = Piwik::getPrettySizeFromBytes($t['Index_length']); + $t['Rows'] = Piwik::getPrettySizeFromBytes($t['Rows']); + $table[] = $t; + } + $total['Total_length'] = Piwik::getPrettySizeFromBytes($total['Data_length']+$total['Index_length']); + $total['Data_length'] = Piwik::getPrettySizeFromBytes($total['Data_length']); + $total['Index_length'] = Piwik::getPrettySizeFromBytes($total['Index_length']); + $total['TotalRows'] = Piwik::getPrettySizeFromBytes($total['Rows']); + $table['Total'] = $total; + + return $table; + } +} diff --git a/oss/piwik/trunk/plugins/DBStats/Controller.php b/oss/piwik/trunk/plugins/DBStats/Controller.php new file mode 100644 index 00000000..af48a380 --- /dev/null +++ b/oss/piwik/trunk/plugins/DBStats/Controller.php @@ -0,0 +1,28 @@ +tablesStatus = Piwik_DBStats_API::getInstance()->getAllTablesStatus(); + $this->setGeneralVariablesView($view); + $view->menu = Piwik_GetAdminMenu(); + echo $view->render(); + } +} diff --git a/oss/piwik/trunk/plugins/DBStats/DBStats.php b/oss/piwik/trunk/plugins/DBStats/DBStats.php new file mode 100644 index 00000000..56b5d8a8 --- /dev/null +++ b/oss/piwik/trunk/plugins/DBStats/DBStats.php @@ -0,0 +1,41 @@ + Piwik_Translate('DBStats_PluginDescription'), + 'author' => 'Piwik', + 'author_homepage' => 'http://piwik.org/', + 'version' => Piwik_Version::VERSION, + ); + } + + function getListHooksRegistered() + { + return array('AdminMenu.add' => 'addMenu'); + } + + function addMenu() + { + Piwik_AddAdminMenu('DBStats_DatabaseUsage', + array('module' => 'DBStats', 'action' => 'index'), + Piwik::isUserIsSuperUser(), + $order = 9); + } +} diff --git a/oss/piwik/trunk/plugins/DBStats/templates/DBStats.tpl b/oss/piwik/trunk/plugins/DBStats/templates/DBStats.tpl new file mode 100644 index 00000000..e5f054d6 --- /dev/null +++ b/oss/piwik/trunk/plugins/DBStats/templates/DBStats.tpl @@ -0,0 +1,44 @@ +{assign var=showSitesSelection value=false} +{assign var=showPeriodSelection value=false} +{include file="CoreAdminHome/templates/header.tpl"} +
+ +

{'DBStats_DatabaseUsage'|translate}

+{assign var=totalSize value=$tablesStatus.Total.Total_length} +

{'DBStats_MainDescription'|translate:$totalSize} +
+{'DBStats_LearnMore'|translate:"Piwik Auto Archiving"}

+ + + + + + + + + + {foreach from=$tablesStatus key=index item=table} + + + + + + + + {/foreach} + +
{'DBStats_Table'|translate}{'DBStats_RowCount'|translate}{'DBStats_DataSize'|translate}{'DBStats_IndexSize'|translate}{'DBStats_TotalSize'|translate}
+ {$table.Name} + + {$table.Rows} + + {$table.Data_length}b + + {$table.Index_length}b + + {$table.Total_length}b +
+ +
+ +{include file="CoreAdminHome/templates/footer.tpl"} diff --git a/oss/piwik/trunk/plugins/ExampleAPI/API.php b/oss/piwik/trunk/plugins/ExampleAPI/API.php new file mode 100644 index 00000000..d4ca7fa2 --- /dev/null +++ b/oss/piwik/trunk/plugins/ExampleAPI/API.php @@ -0,0 +1,133 @@ +HOW TO VIEW THE API IN ACTION

+ *

Go to the API page in the Piwik user interface + * and try the API of the plugin ExampleAPI

+ * + * @package Piwik_ExampleAPI + */ +class Piwik_ExampleAPI_API +{ + static private $instance = null; + + /** + * Singleton + * @return Piwik_ExampleAPI_API + */ + static public function getInstance() + { + if (self::$instance == null) + { + $c = __CLASS__; + self::$instance = new $c(); + } + return self::$instance; + } + + /** + * Get Piwik version + * @return string + */ + public function getPiwikVersion() + { + Piwik::checkUserHasSomeViewAccess(); + return Piwik_Version::VERSION; + } + + /** + * Get Answer to Life + * @return integer + */ + public function getAnswerToLife() + { + return 42; + } + + /** + * Get Golden Ratio + * @return float + */ + public function getGoldenRatio() + { + //http://en.wikipedia.org/wiki/Golden_ratio + return 1.618033988749894848204586834365; + } + + /** + * Get object + * @return Piwik_MagicObject + */ + public function getObject() + { + return new Piwik_MagicObject(); + } + + /** + * Get null + * @return null + */ + public function getNull() + { + return null; + } + + /** + * Get array of descriptive text + * @return array + */ + public function getDescriptionArray() + { + return array('piwik','open source','web analytics','free'); + } + + /** + * Get data table + * @return Piwik_DataTable + */ + public function getCompetitionDatatable() + { + $dataTable = new Piwik_DataTable(); + + $row1 = new Piwik_DataTable_Row(); + $row1->setColumns( array('name' => 'piwik', 'license' => 'GPL')); + $dataTable->addRow($row1); + + $dataTable->addRowFromSimpleArray( array('name' => 'google analytics', 'license' => 'commercial') ); + + return $dataTable; + } + + /** + * Get more information on the Answer to Life... + * @return string + */ + public function getMoreInformationAnswerToLife() + { + return "Check http://en.wikipedia.org/wiki/The_Answer_to_Life,_the_Universe,_and_Everything"; + } +} + +/** + * Magic Object + * + * @package Piwik_ExamplePlugin + */ +class Piwik_MagicObject +{ + function Incredible() { return 'Incroyable'; } + protected $wonderful = 'magnifique'; + public $great = 'formidable'; +} diff --git a/oss/piwik/trunk/plugins/ExampleAPI/ExampleAPI.php b/oss/piwik/trunk/plugins/ExampleAPI/ExampleAPI.php new file mode 100644 index 00000000..4f5e2f76 --- /dev/null +++ b/oss/piwik/trunk/plugins/ExampleAPI/ExampleAPI.php @@ -0,0 +1,37 @@ + Piwik_Translate('ExampleAPI_PluginDescription'), + 'homepage' => 'index.php?module=API&action=listAllAPI#ExampleAPI', + 'author' => 'Piwik', + 'author_homepage' => 'http://piwik.org/', + 'version' => '0.1', + ); + } +}