添加 Piwik 到代码库中。
+YUCHENG HU+ git-svn-id: https://svn.code.sf.net/p/hawebs/svn@481 a2543c7e-f6e9-4f8a-8bff-1ffc34733512
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html Gpl v3 or later
|
||||
* @version $Id: API.php 1832 2010-02-10 08:14:15Z vipsoft $
|
||||
*
|
||||
* @category Piwik_Plugins
|
||||
* @package Piwik_DBStats
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package Piwik_DBStats
|
||||
*/
|
||||
class Piwik_DBStats_API
|
||||
{
|
||||
static private $instance = null;
|
||||
static public function getInstance()
|
||||
{
|
||||
if (self::$instance == null)
|
||||
{
|
||||
$c = __CLASS__;
|
||||
self::$instance = new $c();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function getDBStatus()
|
||||
{
|
||||
Piwik::checkUserIsSuperUser();
|
||||
$configDb = Zend_Registry::get('config')->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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html Gpl v3 or later
|
||||
* @version $Id: Controller.php 2036 2010-04-01 21:08:24Z matt $
|
||||
*
|
||||
* @category Piwik_Plugins
|
||||
* @package Piwik_DBStats
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package Piwik_DBStats
|
||||
*/
|
||||
class Piwik_DBStats_Controller extends Piwik_Controller
|
||||
{
|
||||
function index()
|
||||
{
|
||||
Piwik::checkUserIsSuperUser();
|
||||
$view = Piwik_View::factory('DBStats');
|
||||
$view->tablesStatus = Piwik_DBStats_API::getInstance()->getAllTablesStatus();
|
||||
$this->setGeneralVariablesView($view);
|
||||
$view->menu = Piwik_GetAdminMenu();
|
||||
echo $view->render();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html Gpl v3 or later
|
||||
* @version $Id: DBStats.php 2264 2010-06-03 16:53:43Z vipsoft $
|
||||
*
|
||||
* @category Piwik_Plugins
|
||||
* @package Piwik_DBStats
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package Piwik_DBStats
|
||||
*/
|
||||
class Piwik_DBStats extends Piwik_Plugin
|
||||
{
|
||||
public function getInformation()
|
||||
{
|
||||
return array(
|
||||
'description' => 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
{assign var=showSitesSelection value=false}
|
||||
{assign var=showPeriodSelection value=false}
|
||||
{include file="CoreAdminHome/templates/header.tpl"}
|
||||
<div style="max-width:980px;">
|
||||
|
||||
<h2>{'DBStats_DatabaseUsage'|translate}</h2>
|
||||
{assign var=totalSize value=$tablesStatus.Total.Total_length}
|
||||
<p>{'DBStats_MainDescription'|translate:$totalSize}
|
||||
<br />
|
||||
{'DBStats_LearnMore'|translate:"<a href='misc/redirectToUrl.php?url=http://piwik.org/docs/setup-auto-archiving/' target='_blank'>Piwik Auto Archiving</a>"}</p>
|
||||
<table class="adminTable">
|
||||
<thead>
|
||||
<th>{'DBStats_Table'|translate}</th>
|
||||
<th>{'DBStats_RowCount'|translate}</th>
|
||||
<th>{'DBStats_DataSize'|translate}</th>
|
||||
<th>{'DBStats_IndexSize'|translate}</th>
|
||||
<th>{'DBStats_TotalSize'|translate}</th>
|
||||
</thead>
|
||||
<tbody id="tables">
|
||||
{foreach from=$tablesStatus key=index item=table}
|
||||
<tr {if $table.Name == 'Total'}class="active" style="font-weight:bold;"{/if}>
|
||||
<td>
|
||||
{$table.Name}
|
||||
</td>
|
||||
<td>
|
||||
{$table.Rows}
|
||||
</td>
|
||||
<td>
|
||||
{$table.Data_length}b
|
||||
</td>
|
||||
<td>
|
||||
{$table.Index_length}b
|
||||
</td>
|
||||
<td>
|
||||
{$table.Total_length}b
|
||||
</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
|
||||
{include file="CoreAdminHome/templates/footer.tpl"}
|
||||
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html Gpl v3 or later
|
||||
* @version $Id: API.php 1832 2010-02-10 08:14:15Z vipsoft $
|
||||
*
|
||||
* @category Piwik_Plugins
|
||||
* @package Piwik_ExampleAPI
|
||||
*/
|
||||
|
||||
/**
|
||||
* ExampleAPI API
|
||||
*
|
||||
* <p><b>HOW TO VIEW THE API IN ACTION</b></p>
|
||||
* <p>Go to the API page in the Piwik user interface
|
||||
* and try the API of the plugin ExampleAPI</p>
|
||||
*
|
||||
* @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';
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html Gpl v3 or later
|
||||
* @version $Id: ExampleAPI.php 2264 2010-06-03 16:53:43Z vipsoft $
|
||||
*
|
||||
* @category Piwik_Plugins
|
||||
* @package Piwik_ExampleAPI
|
||||
*/
|
||||
|
||||
/**
|
||||
* ExampleAPI plugin
|
||||
*
|
||||
* @package Piwik_ExampleAPI
|
||||
*/
|
||||
class Piwik_ExampleAPI extends Piwik_Plugin
|
||||
{
|
||||
/**
|
||||
* Return information about this plugin.
|
||||
*
|
||||
* @see Piwik_Plugin
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getInformation()
|
||||
{
|
||||
return array(
|
||||
'description' => Piwik_Translate('ExampleAPI_PluginDescription'),
|
||||
'homepage' => 'index.php?module=API&action=listAllAPI#ExampleAPI',
|
||||
'author' => 'Piwik',
|
||||
'author_homepage' => 'http://piwik.org/',
|
||||
'version' => '0.1',
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user