添加 Piwik 到代码库中。

+YUCHENG HU+

git-svn-id: https://svn.code.sf.net/p/hawebs/svn@427 a2543c7e-f6e9-4f8a-8bff-1ffc34733512
This commit is contained in:
YuCheng Hu
2010-07-10 01:20:47 +00:00
parent 3d62b254bc
commit bc5b8001cb
49 changed files with 7442 additions and 0 deletions
+188
View File
@@ -0,0 +1,188 @@
<?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: Array.php 1420 2009-08-22 13:23:16Z vipsoft $
*
* @category Piwik
* @package Piwik
*/
/**
* Piwik_Archive_Array is used to store multiple archives,
* for example one archive for a given day for each Piwik website
*
* @package Piwik
* @subpackage Piwik_Archive
*/
abstract class Piwik_Archive_Array extends Piwik_Archive
{
/**
* This array contains one Piwik_Archive per entry in the period
*
* @var array
*/
protected $archives = array();
abstract protected function getIndexName();
abstract protected function getDataTableLabelValue( $archive );
public function __destruct()
{
foreach($this->archives as $archive)
{
destroy($archive);
}
$this->archives = array();
}
public function prepareArchive()
{
foreach($this->archives as $archive)
{
$archive->prepareArchive();
}
}
/**
* Returns a newly created Piwik_DataTable_Array.
*
* @return Piwik_DataTable_Array
*/
protected function getNewDataTableArray()
{
$table = new Piwik_DataTable_Array();
$table->setKeyName($this->getIndexName());
return $table;
}
/**
* Adds metadata information to the Piwik_DataTable_Array
* using the information given by the Archive
*
* @param Piwik_DataTable_Array $table
* @param unknown_type $archive
*/
protected function loadMetadata(Piwik_DataTable_Array $table, $archive)
{
}
/**
* Returns a DataTable_Array containing numeric values
* of the element $name from the archives in this Archive_Array.
*
* @param string $name Name of the mysql table field to load eg. Referers_distinctKeywords
*
* @return Piwik_DataTable_Array containing the requested numeric value for each Archive
*/
public function getNumeric( $name )
{
$table = $this->getNewDataTableArray();
foreach($this->archives as $archive)
{
$numeric = $archive->getNumeric( $name ) ;
$subTable = new Piwik_DataTable_Simple();
$subTable->addRowsFromArray( array( $numeric ) );
$table->addTable($subTable, $this->getDataTableLabelValue($archive));
$this->loadMetadata($table, $archive);
}
return $table;
}
/**
* Returns a DataTable_Array containing values
* of the element $name from the archives in this Archive_Array.
*
* The value to be returned are blob values (stored in the archive_numeric_* tables in the DB). *
* It can return anything from strings, to serialized PHP arrays or PHP objects, etc.
*
* @param string $name Name of the mysql table field to load eg. Referers_keywordBySearchEngine
*
* @return Piwik_DataTable_Array containing the requested blob values for each Archive
*/
public function getBlob( $name )
{
$table = $this->getNewDataTableArray();
foreach($this->archives as $archive)
{
$blob = $archive->getBlob( $name ) ;
$subTable = new Piwik_DataTable_Simple();
$subTable->addRowsFromArray( array('blob' => $blob));
$table->addTable($subTable, $this->getDataTableLabelValue($archive));
$this->loadMetadata($table, $archive);
}
return $table;
}
/**
* Given a BLOB field name (eg. 'Referers_searchEngineByKeyword'), it will return a Piwik_DataTable_Array
* which is an array of Piwik_DataTable, ordered by chronological order
*
* @param string $name Name of the mysql table field to load
* @param int $idSubTable optional idSubDataTable
* @return Piwik_DataTable_Array
* @throws exception If the value cannot be found
*/
public function getDataTable( $name, $idSubTable = null )
{
$table = $this->getNewDataTableArray();
foreach($this->archives as $archive)
{
$subTable = $archive->getDataTable( $name, $idSubTable ) ;
$table->addTable($subTable, $this->getDataTableLabelValue($archive));
$this->loadMetadata($table, $archive);
}
return $table;
}
/**
* Same as getDataTable() except that it will also load in memory
* all the subtables for the DataTable $name.
* You can then access the subtables by using the Piwik_DataTable_Manager::getInstance()->getTable($idSubTable);
*
* @param string $name Name of the mysql table field to load
* @param int $idSubTable optional idSubDataTable
* @return Piwik_DataTable_Array
*/
public function getDataTableExpanded($name, $idSubTable = null)
{
$table = $this->getNewDataTableArray();
foreach($this->archives as $archive)
{
$subTable = $archive->getDataTableExpanded( $name, $idSubTable ) ;
$table->addTable($subTable, $this->getDataTableLabelValue($archive));
$this->loadMetadata($table, $archive);
}
return $table;
}
/**
* Takes a list of fields defining numeric values and returns a quoted string
* of the field names fit to be used in the where clause of a SQL Query
*
* @param array|string $fields array( fieldName1, fieldName2, ...) Names of the mysql table fields to load
* @return String
*/
public static function getSqlStringFieldsArray( $fields )
{
if(!is_array($fields))
{
return "'$fields'";
}
return "'" . implode("', '",$fields) . "'";
}
}
@@ -0,0 +1,144 @@
<?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: IndexedByDate.php 2261 2010-06-03 11:45:06Z vipsoft $
*
* @category Piwik
* @package Piwik
*/
/**
* @package Piwik
* @subpackage Piwik_Archive
*/
class Piwik_Archive_Array_IndexedByDate extends Piwik_Archive_Array
{
/**
* Builds an array of Piwik_Archive of a given date range
*
* @param Piwik_Site $oSite
* @param string $strPeriod eg. 'day' 'week' etc.
* @param string $strDate A date range, eg. 'last10', 'previous5' or 'YYYY-MM-DD,YYYY-MM-DD'
*/
function __construct(Piwik_Site $oSite, $strPeriod, $strDate)
{
$rangePeriod = new Piwik_Period_Range($strPeriod, $strDate, $oSite->getTimezone());
foreach($rangePeriod->getSubperiods() as $subPeriod)
{
$startDate = $subPeriod->getDateStart();
$archive = Piwik_Archive::build($oSite->getId(), $strPeriod, $startDate );
$archive->prepareArchive();
$timestamp = $archive->getTimestampStartDate();
$this->archives[$timestamp] = $archive;
}
ksort( $this->archives );
}
protected function getIndexName()
{
return 'date';
}
/**
* Adds metadata information to the Piwik_DataTable_Array
* using the information given by the Archive
*
* @param Piwik_DataTable_Array $table
* @param Piwik_Archive $archive
*/
protected function loadMetadata(Piwik_DataTable_Array $table, $archive)
{
$table->metadata[$archive->getPrettyDate()] = array(
'timestamp' => $archive->getTimestampStartDate(),
'site' => $archive->getSite(),
'period' => $archive->getPeriod(),
);
}
protected function getDataTableLabelValue( $archive )
{
return $archive->getPrettyDate();
}
/**
* Given a list of fields defining numeric values, it will return a Piwik_DataTable_Array
* which is an array of Piwik_DataTable_Simple, ordered by chronological order
*
* @param array|string $fields array( fieldName1, fieldName2, ...) Names of the mysql table fields to load
* @return Piwik_DataTable_Array
*/
public function getDataTableFromNumeric( $fields )
{
$inNames = $this->getSqlStringFieldsArray($fields);
// we select in different shots
// one per distinct table (case we select last 300 days, maybe we will select from 10 different tables)
$queries = array();
foreach($this->archives as $archive)
{
if(!$archive->isThereSomeVisits)
{
continue;
}
$table = $archive->archiveProcessing->getTableArchiveNumericName();
// for every query store IDs
$queries[$table][] = $archive->getIdArchive();
}
// we select the requested value
$db = Zend_Registry::get('db');
// date => array( 'field1' =>X, 'field2'=>Y)
// date2 => array( 'field1' =>X2, 'field2'=>Y2)
$arrayValues = array();
foreach($queries as $table => $aIds)
{
$inIds = implode(', ', array_filter($aIds));
if(empty($inIds))
{
// Probable timezone configuration error, i.e., mismatch between PHP and MySQL server.
continue;
}
$sql = "SELECT value, name, date1 as startDate
FROM $table
WHERE idarchive IN ( $inIds )
AND name IN ( $inNames )";
$values = $db->fetchAll($sql);
foreach($values as $value)
{
$timestamp = Piwik_Date::factory($value['startDate'])->getTimestamp();
$arrayValues[$timestamp][$value['name']] = (float)$value['value'];
}
}
$contentArray = array();
// we add empty tables so that every requested date has an entry, even if there is nothing
// example: <result date="2007-01-01" />
foreach($this->archives as $timestamp => $archive)
{
$strDate = $this->archives[$timestamp]->getPrettyDate();
$contentArray[$timestamp]['table'] = new Piwik_DataTable_Simple();
$contentArray[$timestamp]['prettyDate'] = $strDate;
}
foreach($arrayValues as $timestamp => $aNameValues)
{
$contentArray[$timestamp]['table']->addRowsFromArray($aNameValues);
}
ksort( $contentArray );
$tableArray = $this->getNewDataTableArray();
foreach($contentArray as $timestamp => $aData)
{
$tableArray->addTable($aData['table'], $aData['prettyDate']);
$this->loadMetadata($tableArray, $this->archives[$timestamp]);
}
return $tableArray;
}
}
@@ -0,0 +1,122 @@
<?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: IndexedBySite.php 1959 2010-03-19 21:38:51Z vipsoft $
*
* @category Piwik
* @package Piwik
*/
/**
* @package Piwik
* @subpackage Piwik_Archive
*/
class Piwik_Archive_Array_IndexedBySite extends Piwik_Archive_Array
{
/**
* @param Piwik_Site $oSite
* @param string $strPeriod eg. 'day' 'week' etc.
* @param string $strDate A date range, eg. 'last10', 'previous5' or 'YYYY-MM-DD,YYYY-MM-DD'
*/
function __construct($sites, $strPeriod, $strDate)
{
foreach($sites as $idSite)
{
$archive = Piwik_Archive::build($idSite, $strPeriod, $strDate );
$archive->setSite(new Piwik_Site($idSite));
$archive->prepareArchive();
$this->archives[$idSite] = $archive;
}
ksort( $this->archives );
}
protected function getIndexName()
{
return 'idSite';
}
protected function getDataTableLabelValue( $archive )
{
return $archive->getIdSite();
}
/**
* Given a list of fields defining numeric values, it will return a Piwik_DataTable_Array
* ordered by idsite
*
* @param array|string $fields array( fieldName1, fieldName2, ...) Names of the mysql table fields to load
* @return Piwik_DataTable_Array
*/
public function getDataTableFromNumeric( $fields )
{
$tableArray = $this->getNewDataTableArray();
if ($this->getFirstArchive() instanceof Piwik_Archive_Single)
{
$values = $this->getValues($fields);
foreach($this->archives as $idSite => $archive)
{
$table = new Piwik_DataTable_Simple();
if (array_key_exists($idSite, $values))
{
$table->addRowsFromArray($values[$idSite]);
}
$tableArray->addTable($table, $idSite);
}
}
elseif ($this->getFirstArchive() instanceof Piwik_Archive_Array)
{
foreach($this->archives as $idSite => $archive)
{
$tableArray->addTable($archive->getDataTableFromNumeric($fields), $idSite);
}
}
return $tableArray;
}
private function getValues($fields)
{
$arrayValues = array();
foreach($this->loadValuesFromDB($fields) as $value)
{
$arrayValues[$value['idsite']][$value['name']] = $value['value'];
}
return $arrayValues;
}
private function loadValuesFromDB($fields)
{
$sql = "SELECT value, name, idarchive, idsite
FROM {$this->getNumericTableName()}
WHERE idarchive IN ( {$this->getArchiveIds()} )
AND name IN ( {$this->getSqlStringFieldsArray($fields)} )";
return Piwik_FetchAll($sql);
}
private function getFirstArchive()
{
reset($this->archives);
return current($this->archives);
}
private function getArchiveIds()
{
foreach($this->archives as $archive)
{
if( $this->getNumericTableName() != $archive->archiveProcessing->getTableArchiveNumericName())
{
throw new Exception("Piwik_Archive_Array_IndexedBySite::getDataTableFromNumeric() algorithm won't work if data is stored in different tables");
}
$archiveIds[] = $archive->getIdArchive();
}
return implode(', ', array_filter($archiveIds));
}
private function getNumericTableName()
{
return $this->getFirstArchive()->archiveProcessing->getTableArchiveNumericName();
}
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,42 @@
<?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: Record.php 1420 2009-08-22 13:23:16Z vipsoft $
*
* @category Piwik
* @package Piwik
*/
/**
* A Record is a tuple (name, value) to be saved in the database.
* At its creation, the record registers itself to the RecordManager.
* The record will then be automatically saved in the DB once the Archiving process is finished.
*
* We have two record types available:
* - numeric ; the value will be saved as float in the DB.
* It should be used for INTEGER, FLOAT
* - blob ; the value will be saved in a binary field in the DB
* It should be used for all the other types: PHP variables, STRING, serialized OBJECTS or ARRAYS, etc.
*
* @package Piwik
* @subpackage Piwik_ArchiveProcessing
*/
abstract class Piwik_ArchiveProcessing_Record
{
public $name;
public $value;
function __construct( $name, $value)
{
$this->name = $name;
$this->value = $value;
}
function __destruct()
{
destroy($this->value);
}
}
@@ -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: Blob.php 1420 2009-08-22 13:23:16Z vipsoft $
*
* @category Piwik
* @package Piwik
*/
/**
* Blob record.
* Example: $record = new Piwik_ArchiveProcessing_Record_Blob('visitor_names', serialize(array('piwik-fan', 'php', 'stevie-vibes')));
* The value will be compressed before being saved in the DB.
*
* @package Piwik
* @subpackage Piwik_ArchiveProcessing
*/
class Piwik_ArchiveProcessing_Record_Blob extends Piwik_ArchiveProcessing_Record
{
public $name;
public $value;
function __construct( $name, $value)
{
$value = gzcompress($value);
parent::__construct( $name, $value );
}
function __destruct()
{
destroy($this->value);
}
public function __toString()
{
return $this->name ." = BLOB";//". gzuncompress($this->value);
}
}
@@ -0,0 +1,31 @@
<?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: Numeric.php 1420 2009-08-22 13:23:16Z vipsoft $
*
* @category Piwik
* @package Piwik
*/
/**
* Numeric record.
* Example: $record = new Piwik_ArchiveProcessing_Record_Numeric('nb_visitors_live', 15);
*
* @package Piwik
* @subpackage Piwik_ArchiveProcessing
*/
class Piwik_ArchiveProcessing_Record_Numeric extends Piwik_ArchiveProcessing_Record
{
function __construct( $name, $value)
{
parent::__construct( $name, $value );
}
public function __toString()
{
return $this->name ." = ". $this->value;
}
}
@@ -0,0 +1,70 @@
<?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: RecordArray.php 1420 2009-08-22 13:23:16Z vipsoft $
*
* @category Piwik
* @package Piwik
*/
/**
* Array of blob records.
* Useful for easily saving splited data in the DB.
*
* Example: $record = new Piwik_ArchiveProcessing_RecordArray(
* 'veryLongBook',
* 0 => serialize( array( '1st chapter very long, 6MB of data we dont want to save' )),
* 1 => serialize( array( '2nd chapter very long, 8MB of data we dont want to save' )),
* 2 => serialize( array( '3rd chapter very long, 7MB of data we dont want to save' )),
* 3 => serialize( array( '4th chapter very long, 10MB of data we dont want to save' )),
* );
*
* Will be saved in the DB as
* veryLongBook => X
* veryLongBook_1 => Y
* veryLongBook_2 => Z
* veryLongBook_3 => M
*
* @package Piwik
* @subpackage Piwik_ArchiveProcessing
*/
class Piwik_ArchiveProcessing_RecordArray extends Piwik_ArchiveProcessing_Record
{
protected $records = array();
function __construct( $name, $aValue)
{
foreach($aValue as $id => $value)
{
// for the parent Table we keep the name
// for example for the Table of searchEngines we keep the name 'referer_search_engine'
// but for the child table of 'Google' which has the ID = 9 the name would be 'referer_search_engine_9'
if($id == 0)
{
$newName = $name;
}
else
{
$newName = $name . '_' . $id;
}
$this->records[] = new Piwik_ArchiveProcessing_Record_Blob( $newName, $value );
}
}
public function __destruct()
{
foreach($this->records as $record)
{
destroy($record);
}
$this->records = array();
}
public function get()
{
return $this->records;
}
}
@@ -0,0 +1,290 @@
<?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: Countries.php 1528 2009-10-22 17:45:23Z vipsoft $
*
* @category Piwik
* @package DataFiles
*/
/**
* Country code and continent database.
* If you want to add a new entry, please email us at hello at piwik.org
*/
if(!isset($GLOBALS['Piwik_CountryList']))
{
// Reference: ISO 3166-1 alpha-2
$GLOBALS['Piwik_CountryList'] = array(
'xx' => 'unk',
'ad' => 'eur',
'ae' => 'asi',
'af' => 'asi',
'ag' => 'ams',
'ai' => 'ams',
'al' => 'eur',
'am' => 'asi',
'an' => 'ams',
'ao' => 'afr',
'aq' => 'oce',
'ar' => 'ams',
'as' => 'oce',
'at' => 'eur',
'au' => 'oce',
'aw' => 'ams',
'ax' => 'eur',
'az' => 'asi',
'ba' => 'eur',
'bb' => 'ams',
'bd' => 'asi',
'be' => 'eur',
'bf' => 'afr',
'bg' => 'eur',
'bh' => 'asi',
'bi' => 'afr',
'bj' => 'afr',
'bl' => 'ams',
'bm' => 'ams',
'bn' => 'asi',
'bo' => 'ams',
'br' => 'ams',
'bs' => 'ams',
'bt' => 'asi',
'bv' => 'oce',
'bw' => 'afr',
'by' => 'eur',
'bz' => 'ams',
'ca' => 'amn',
'cc' => 'oce',
'cd' => 'afr',
'cf' => 'afr',
'cg' => 'afr',
'ch' => 'eur',
'ci' => 'afr',
'ck' => 'asi',
'cl' => 'ams',
'cm' => 'afr',
'cn' => 'asi',
'co' => 'ams',
'cr' => 'ams',
'cu' => 'ams',
'cv' => 'afr',
'cx' => 'oce',
'cy' => 'eur',
'cz' => 'eur',
'de' => 'eur',
'dj' => 'afr',
'dk' => 'eur',
'dm' => 'ams',
'do' => 'ams',
'dz' => 'afr',
'ec' => 'ams',
'ee' => 'eur',
'eg' => 'afr',
'eh' => 'afr',
'er' => 'afr',
'es' => 'eur',
'et' => 'afr',
'fi' => 'eur',
'fj' => 'oce',
'fk' => 'ams',
'fm' => 'oce',
'fo' => 'eur',
'fr' => 'eur',
'ga' => 'afr',
'gb' => 'eur',
'gd' => 'ams',
'ge' => 'asi',
'gf' => 'ams',
'gg' => 'eur',
'gh' => 'afr',
'gi' => 'afr',
'gl' => 'amn',
'gm' => 'afr',
'gn' => 'afr',
'gp' => 'ams',
'gq' => 'afr',
'gr' => 'eur',
'gs' => 'eur',
'gt' => 'ams',
'gu' => 'asi',
'gw' => 'afr',
'gy' => 'ams',
'hk' => 'asi',
'hm' => 'oce',
'hn' => 'ams',
'hr' => 'eur',
'ht' => 'ams',
'hu' => 'eur',
'id' => 'asi',
'ie' => 'eur',
'il' => 'asi',
'im' => 'eur',
'in' => 'asi',
'io' => 'asi',
'iq' => 'asi',
'ir' => 'asi',
'is' => 'eur',
'it' => 'eur',
'je' => 'eur',
'jm' => 'ams',
'jo' => 'asi',
'jp' => 'asi',
'ke' => 'afr',
'kg' => 'asi',
'kh' => 'asi',
'ki' => 'oce',
'km' => 'afr',
'kn' => 'ams',
'kp' => 'asi',
'kr' => 'asi',
'kw' => 'asi',
'ky' => 'ams',
'kz' => 'asi',
'la' => 'asi',
'lb' => 'asi',
'lc' => 'ams',
'li' => 'eur',
'lk' => 'asi',
'lr' => 'afr',
'ls' => 'afr',
'lt' => 'eur',
'lu' => 'eur',
'lv' => 'eur',
'ly' => 'afr',
'ma' => 'afr',
'mc' => 'eur',
'md' => 'eur',
'me' => 'eur',
'mf' => 'ams',
'mg' => 'afr',
'mh' => 'oce',
'mk' => 'eur',
'ml' => 'afr',
'mm' => 'asi',
'mn' => 'asi',
'mo' => 'asi',
'mp' => 'asi',
'mq' => 'ams',
'mr' => 'afr',
'ms' => 'ams',
'mt' => 'eur',
'mu' => 'afr',
'mv' => 'asi',
'mw' => 'afr',
'mx' => 'ams',
'my' => 'asi',
'mz' => 'afr',
'na' => 'afr',
'nc' => 'oce',
'ne' => 'afr',
'nf' => 'oce',
'ng' => 'afr',
'ni' => 'ams',
'nl' => 'eur',
'no' => 'eur',
'np' => 'asi',
'nr' => 'oce',
'nu' => 'oce',
'nz' => 'oce',
'om' => 'asi',
'pa' => 'ams',
'pe' => 'ams',
'pf' => 'oce',
'pg' => 'oce',
'ph' => 'asi',
'pk' => 'asi',
'pl' => 'eur',
'pm' => 'amn',
'pn' => 'oce',
'pr' => 'ams',
'ps' => 'asi',
'pt' => 'eur',
'pw' => 'oce',
'py' => 'ams',
'qa' => 'asi',
're' => 'afr',
'ro' => 'eur',
'rs' => 'eur',
'ru' => 'eur',
'rw' => 'afr',
'sa' => 'asi',
'sb' => 'oce',
'sc' => 'afr',
'sd' => 'afr',
'se' => 'eur',
'sg' => 'asi',
'sh' => 'afr',
'si' => 'eur',
'sj' => 'eur',
'sk' => 'eur',
'sl' => 'afr',
'sm' => 'eur',
'sn' => 'afr',
'so' => 'afr',
'sr' => 'ams',
'st' => 'afr',
'sv' => 'ams',
'sy' => 'asi',
'sz' => 'afr',
'tc' => 'ams',
'td' => 'afr',
'tf' => 'oce',
'tg' => 'afr',
'th' => 'asi',
'tj' => 'asi',
'tk' => 'oce',
'tl' => 'asi',
'tm' => 'asi',
'tn' => 'afr',
'to' => 'oce',
'tr' => 'eur',
'tt' => 'ams',
'tv' => 'asi',
'tw' => 'asi',
'tz' => 'afr',
'ua' => 'eur',
'ug' => 'afr',
'um' => 'oce',
'us' => 'amn',
'uy' => 'ams',
'uz' => 'asi',
'va' => 'eur',
'vc' => 'ams',
've' => 'ams',
'vg' => 'ams',
'vi' => 'ams',
'vn' => 'asi',
'vu' => 'oce',
'wf' => 'oce',
'ws' => 'asi',
'ye' => 'asi',
'yt' => 'afr',
'za' => 'afr',
'zm' => 'afr',
'zw' => 'afr',
// exceptionally reserved
'ac' => 'afr', // .ac TLD
'cp' => 'ams',
'dg' => 'asi',
'ea' => 'afr',
'eu' => 'eur', // .eu TLD
'fx' => 'eur',
'ic' => 'afr',
'su' => 'eur', // .su TLD
'ta' => 'afr',
'uk' => 'eur', // .uk TLD
// transitionally reserved
'bu' => 'asi',
'cs' => 'eur', // former Serbia and Montenegro
'nt' => 'asi',
'sf' => 'eur',
'tp' => 'oce', // .tp TLD
'yu' => 'eur', // .yu TLD
'zr' => 'afr',
);
}
@@ -0,0 +1,66 @@
<?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: LanguageToCountry.php 1420 2009-08-22 13:23:16Z vipsoft $
*
* @category Piwik
* @package DataFiles
*/
/**
* Language to Country mapping
*
* This list is used to guess the visitor's country when the region is
* not specified in the first language tag. Inclusion/exclusion is
* based on Piwik.org visitor statistics and probability of disambiguation.
* (Notably, "en" and "zh" are excluded.)
*
* If you want to add a new entry, please email us at hello at piwik.org
*/
if(!isset($GLOBALS['Piwik_LanguageToCountry']))
{
$GLOBALS['Piwik_LanguageToCountry'] = array(
'bg' => 'bg', // Bulgarian => Bulgaria
'ca' => 'es', // Catalan => Spain
'cs' => 'cz', // Czech => Czech Republic
'da' => 'dk', // Danish => Denmark
'de' => 'de', // German => Germany
'el' => 'gr', // Greek => Greece
'es' => 'es', // Spanish => Spain
'et' => 'ee', // Estonian => Estonia
'fa' => 'ir', // Farsi => Iran
'fi' => 'fi', // Finnish => Finland
'fr' => 'fr', // French => France
'he' => 'il', // Hebrew => Israel
'hr' => 'hr', // Croatian => Croatia
'hu' => 'hu', // Hungarian => Hungary
'id' => 'id', // Indonesian => Indonesia
'is' => 'is', // Icelandic => Iceland
'it' => 'it', // Italian => Italy
'ja' => 'jp', // Japanese => Japan
'ko' => 'kr', // Korean => South Korea
'lt' => 'lt', // Lithuanian => Lithuania
'lv' => 'lv', // Latvian => Latvia
'mk' => 'mk', // Macedonian => Macedonia
'ms' => 'my', // Malay => Malaysia
'nb' => 'no', // Bokmål => Norway
'nl' => 'nl', // Dutch => Netherlands
'nn' => 'no', // Nynorsk => Norway
'no' => 'no', // Norwegian => Norway
'pl' => 'pl', // Polish => Poland
'pt' => 'pt', // Portugese => Portugal
'ro' => 'ro', // Romanian => Romania
'ru' => 'ru', // Russian => Russia
'sk' => 'sk', // Slovak => Slovakia
'sl' => 'si', // Slovene => Slovenia
'sq' => 'al', // Albanian => Albania
'sr' => 'rs', // Serbian => Serbia
'sv' => 'se', // Swedish => Sweden
'th' => 'th', // Thai => Thailand
'tr' => 'tr', // Turkish => Turkey
'uk' => 'ua', // Ukrainian => Ukraine
);
}
File diff suppressed because it is too large Load Diff
+170
View File
@@ -0,0 +1,170 @@
<?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: Array.php 1420 2009-08-22 13:23:16Z vipsoft $
*
* @category Piwik
* @package Piwik
*/
/**
* The DataTable_Array is a way to store an array of dataTable.
* The Piwik_DataTable_Array implements some of the features of the Piwik_DataTable such as queueFilter, getRowsCount.
*
* @package Piwik
* @subpackage Piwik_DataTable
*/
class Piwik_DataTable_Array
{
/**
* Used to store additional information about the DataTable Array.
* For example if the Array is used to store multiple DataTable of UserCountry,
* we can add the metadata of the 'idSite' they refer to, so we can access it later if necessary.
*
* @var array of mixed
*/
public $metadata = array();
/**
* Array containing the DataTable withing this Piwik_DataTable_Array
*
* @var array of Piwik_DataTable
*/
protected $array = array();
/**
* This is the label used to index the tables.
* For example if the tables are indexed using the timestamp of each period
* eg. $this->array[1045886960] = new Piwik_DataTable();
* the keyName would be 'timestamp'.
*
* This label is used in the Renderer (it becomes a column name or the XML description tag)
*
* @var string
*/
protected $keyName = 'defaultKeyName';
/**
* Returns the keyName string @see self::$keyName
*
* @return string
*/
public function getKeyName()
{
return $this->keyName;
}
/**
* Set the keyName @see self::$keyName
*
* @param string $name
*/
public function setKeyName($name)
{
$this->keyName = $name;
}
/**
* Returns the number of DataTable in this DataTable_Array
*
* @return int
*/
public function getRowsCount()
{
return count($this->array);
}
/**
* Queue a filter to the DataTable_Array will queue this filter to every DataTable of the DataTable_Array.
*
* @param string $className Filter name, eg. Piwik_DataTable_Filter_Limit
* @param array $parameters Filter parameters, eg. array( 50, 10 )
*/
public function queueFilter( $className, $parameters = array() )
{
foreach($this->array as $table)
{
$table->queueFilter($className, $parameters);
}
}
/**
* Apply the filters previously queued to each of the DataTable of this DataTable_Array.
*/
public function applyQueuedFilters()
{
foreach($this->array as $table)
{
$table->applyQueuedFilters();
}
}
/**
* Apply a filter to all tables in the array
* @param $className
* @param $parameters
*/
public function filter($className, $parameters = array())
{
foreach($this->array as $id => $table)
{
$table->filter($className, $parameters);
}
}
/**
* Returns the array of DataTable
*
* @return array of Piwik_DataTable
*/
public function getArray()
{
return $this->array;
}
/**
* Adds a new DataTable to the DataTable_Array
*
* @param Piwik_DataTable $table
* @param string $label Label used to index this table in the array
*/
public function addTable( $table, $label )
{
$this->array[$label] = $table;
}
/**
* Returns a string output of this DataTable_Array (applying the default renderer to every DataTable
* of this DataTable_Array).
*
* @return string
*/
public function __toString()
{
$renderer = new Piwik_DataTable_Renderer_Console();
$renderer->setTable($this);
return (string)$renderer;
}
/**
* @see Piwik_DataTable::enableRecursiveSort()
*/
public function enableRecursiveSort()
{
foreach($this->array as $table)
{
$table->enableRecursiveSort();
}
}
public function deleteColumns($columns)
{
foreach($this->array as $table)
{
$table->deleteColumns($columns);
}
}
}
+44
View File
@@ -0,0 +1,44 @@
<?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: Filter.php 1420 2009-08-22 13:23:16Z vipsoft $
*
* @category Piwik
* @package Piwik
*/
/**
* A filter is applied instantly to a given DataTable and can
* - remove rows
* - change columns values (lowercase the strings, truncate, etc.)
* - add/remove columns or metadata (compute percentage values, add an 'icon' metadata based on the label, etc.)
* - add/remove/edit sub DataTable associated to some rows
* - whatever you can imagine
*
* The concept is very simple: the filter is given the DataTable
* and can do whatever is necessary on the data (in the filter() method).
*
* @package Piwik
* @subpackage Piwik_DataTable
*/
abstract class Piwik_DataTable_Filter
{
/*
* @var Piwik_DataTable
*/
protected $table;
public function __construct($table)
{
if(!($table instanceof Piwik_DataTable))
{
throw new Exception("The filter accepts only a Piwik_DataTable object.");
}
$this->table = $table;
}
abstract protected function filter();
}
@@ -0,0 +1,58 @@
<?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: AddColumnsWhenShowAllColumns.php 2308 2010-06-16 13:47:41Z matt $
*
* @category Piwik
* @package Piwik
*/
/**
* @package Piwik
* @subpackage Piwik_DataTable
*/
class Piwik_DataTable_Filter_AddColumnsWhenShowAllColumns extends Piwik_DataTable_Filter
{
protected $roundPrecision = 1;
/**
* @param $table
* @param $enable Automatically set to true when filter_add_columns_when_show_all_columns is found in the API request
* @return void
*/
public function __construct( $table, $enable = true )
{
parent::__construct($table);
$this->filter();
}
protected function filter()
{
$rowsIdToDelete = array();
foreach($this->table->getRows() as $key => $row)
{
$nbVisits = $row->getColumn(Piwik_Archive::INDEX_NB_VISITS);
if($nbVisits == 0)
{
// case of keyword/website/campaign with a conversion for this day,
// but no visit, we don't show it
$rowsIdToDelete[] = $key;
continue;
}
// nb_actions / nb_visits => Actions/visit
// sum_visit_length / nb_visits => Avg. Time on Site
// bounce_count=> Bounce Rate
$actionsPerVisit = round($row->getColumn(Piwik_Archive::INDEX_NB_ACTIONS) / $nbVisits, $this->roundPrecision);
$averageTimeOnSite = round($row->getColumn(Piwik_Archive::INDEX_SUM_VISIT_LENGTH) / $nbVisits, $this->roundPrecision);
$bounceRate = round(100 * $row->getColumn(Piwik_Archive::INDEX_BOUNCE_COUNT) / $nbVisits, $this->roundPrecision);
$row->addColumn('nb_actions_per_visit', $actionsPerVisit);
$row->addColumn('avg_time_on_site', $averageTimeOnSite);
$row->addColumn('bounce_rate', $bounceRate);
}
$this->table->deleteRows($rowsIdToDelete);
}
}
@@ -0,0 +1,43 @@
<?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: AddConstantMetadata.php 1420 2009-08-22 13:23:16Z vipsoft $
*
* @category Piwik
* @package Piwik
*/
/**
* Add a new metadata column to the table.
*
* This is used to add a column containing the logo width and height of the countries flag icons.
* This value is fixed for all icons so we simply add the same value for all rows.
*
* @package Piwik
* @subpackage Piwik_DataTable
*/
class Piwik_DataTable_Filter_AddConstantMetadata extends Piwik_DataTable_Filter
{
private $metadataToRead;
private $functionToApply;
private $metadataToAdd;
public function __construct( $table, $metadataName, $metadataValue )
{
parent::__construct($table);
$this->name = $metadataName;
$this->value = $metadataValue;
$this->filter();
}
protected function filter()
{
foreach($this->table->getRows() as $row)
{
$row->addMetadata($this->name, $this->value);
}
}
}
@@ -0,0 +1,74 @@
<?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: AddSummaryRow.php 1420 2009-08-22 13:23:16Z vipsoft $
*
* @category Piwik
* @package Piwik
*/
/**
* Add a new row to the table containing a summary
* of the rows from StartRowToSummarize to EndRowToSummarize.
* It then deletes the rows from StartRowToSummarize to EndRowToSummarize.
* The new row created has a label = 'other'
*
* This filter is useful to build a more compact view of a table,
* keeping the first records unchanged.
*
* For example we use this for the pie chart, to build the last pie part
* which is the sum of all the remaining data after the top 5 data.
* This row is assigned a label of 'Others'.
*
* @package Piwik
* @subpackage Piwik_DataTable
*/
class Piwik_DataTable_Filter_AddSummaryRow extends Piwik_DataTable_Filter
{
public function __construct( $table,
$startRowToSummarize,
$labelSummaryRow = Piwik_DataTable::LABEL_SUMMARY_ROW,
$columnToSortByBeforeTruncating = null )
{
parent::__construct($table);
$this->startRowToSummarize = $startRowToSummarize;
$this->labelSummaryRow = $labelSummaryRow;
$this->columnToSortByBeforeTruncating = $columnToSortByBeforeTruncating;
if($table->getRowsCount() > $startRowToSummarize + 1)
{
$this->filter();
}
}
protected function filter()
{
$this->table->filter('Sort',
array( $this->columnToSortByBeforeTruncating, 'desc'));
$rows = $this->table->getRows();
$count = $this->table->getRowsCount();
$newRow = new Piwik_DataTable_Row();
for($i = $this->startRowToSummarize; $i < $count; $i++)
{
if(!isset($rows[$i]))
{
// case when the last row is a summary row, it is not indexed by $cout but by Piwik_DataTable::ID_SUMMARY_ROW
$summaryRow = $this->table->getRowFromId(Piwik_DataTable::ID_SUMMARY_ROW);
$newRow->sumRow($summaryRow);
}
else
{
$newRow->sumRow($rows[$i]);
}
}
$newRow->setColumns(array('label' => $this->labelSummaryRow) + $newRow->getColumns());
$this->table->filter('Limit', array(0, $this->startRowToSummarize));
$this->table->addSummaryRow($newRow);
unset($rows);
}
}
@@ -0,0 +1,34 @@
<?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: ColumnCallbackAddColumnPercentage.php 2202 2010-05-20 08:49:42Z matt $
*
* @category Piwik
* @package Piwik
*/
/**
* Add a new column to the table which is a percentage based on the value resulting
* from a callback function with the parameter being another column's value
*
* For example in the keywords table, we can create a "nb_visits_percentage" column
* from the "nb_visits" column that will be nb_visits / $totalValueUsedToComputePercentage
* You can also specify the precision of the percentage value to be displayed (defaults to 0, eg "11%")
*
* Usage:
* $nbVisits = Piwik_VisitsSummary_API::getInstance()->getVisits($idSite, $period, $date);
* $dataTable->queueFilter('ColumnCallbackAddColumnPercentage', array('nb_visits', 'nb_visits_percentage', $nbVisits, 1));
*
* @package Piwik
* @subpackage Piwik_DataTable
*/
class Piwik_DataTable_Filter_ColumnCallbackAddColumnPercentage extends Piwik_DataTable_Filter_ColumnCallbackAddColumnQuotient
{
protected function formatValue($value, $divisor)
{
return Piwik::getPercentageSafe($value, $divisor, $this->quotientPrecision) . '%';
}
}
@@ -0,0 +1,80 @@
<?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: ColumnCallbackAddColumnQuotient.php 2202 2010-05-20 08:49:42Z matt $
*
* @category Piwik
* @package Piwik
*/
/**
* Adds a new column that is a division of two columns of the current row.
* Useful to process bounce rates, exit rates, average time on page, etc.
*
* @package Piwik
* @subpackage Piwik_DataTable
*/
class Piwik_DataTable_Filter_ColumnCallbackAddColumnQuotient extends Piwik_DataTable_Filter
{
protected $columnValueToRead;
protected $columnNameToAdd;
protected $columnNameUsedAsDivisor;
protected $totalValueUsedAsDivisor;
protected $quotientPrecision;
/**
* @param Piwik_DataTable $table
* @param string $columnValueToRead
* @param string $columnNameToAdd
* @param numeric|string $divisorValueOrDivisorColumnName
* if a numeric value is given, we use this value as the divisor to process the percentage.
* if a string is given, this string is the column name's value used as the divisor.
* @param numeric $quotientPrecision Division precision
*/
public function __construct( $table, $columnNameToAdd, $columnValueToRead, $divisorValueOrDivisorColumnName, $quotientPrecision = 0)
{
parent::__construct($table);
$this->columnValueToRead = $columnValueToRead;
$this->columnNameToAdd = $columnNameToAdd;
if(is_numeric($divisorValueOrDivisorColumnName))
{
$this->totalValueUsedAsDivisor = $divisorValueOrDivisorColumnName;
}
else
{
$this->columnNameUsedAsDivisor = $divisorValueOrDivisorColumnName;
}
$this->filter();
}
protected function filter()
{
foreach($this->table->getRows() as $key => $row)
{
$value = $row->getColumn($this->columnValueToRead);
if(!is_null($this->totalValueUsedAsDivisor))
{
$divisor = $this->totalValueUsedAsDivisor;
}
else
{
$divisor = $row->getColumn($this->columnNameUsedAsDivisor);
}
$formattedValue = $this->formatValue($value, $divisor);
$row->addColumn($this->columnNameToAdd, $formattedValue);
}
}
protected function formatValue($value, $divisor)
{
$quotient = 0;
if($divisor > 0 && $value > 0)
{
$quotient = round($value / $divisor, $this->quotientPrecision);
}
return $quotient;
}
}
@@ -0,0 +1,61 @@
<?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: ColumnCallbackAddMetadata.php 1601 2009-11-17 19:18:54Z vipsoft $
*
* @category Piwik
* @package Piwik
*/
/**
* Add a new 'metadata' column to the table based on the value resulting
* from a callback function with the parameter being another column's value
*
* For example from the "label" column we can to create an "icon" 'metadata' column
* with the icon URI built from the label (LINUX => UserSettings/icons/linux.png)
*
* @package Piwik
* @subpackage Piwik_DataTable
*/
class Piwik_DataTable_Filter_ColumnCallbackAddMetadata extends Piwik_DataTable_Filter
{
private $columnToRead;
private $functionToApply;
private $functionParameters;
private $metadataToAdd;
public function __construct( $table, $columnToRead, $metadataToAdd, $functionToApply = null, $functionParameters = null )
{
parent::__construct($table);
$this->functionToApply = $functionToApply;
$this->functionParameters = $functionParameters;
$this->columnToRead = $columnToRead;
$this->metadataToAdd = $metadataToAdd;
$this->filter();
}
protected function filter()
{
foreach($this->table->getRows() as $key => $row)
{
$oldValue = $row->getColumn($this->columnToRead);
$parameters = array($oldValue);
if(!is_null($this->functionParameters))
{
$parameters = array_merge($parameters, $this->functionParameters);
}
if(!is_null($this->functionToApply))
{
$newValue = call_user_func_array( $this->functionToApply, $parameters);
}
else
{
$newValue = $oldValue;
}
$row->addMetadata($this->metadataToAdd, $newValue);
}
}
}
@@ -0,0 +1,43 @@
<?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: ColumnCallbackDeleteRow.php 2202 2010-05-20 08:49:42Z matt $
*
* @category Piwik
* @package Piwik
*/
/**
* Delete all rows for which a given function returns false for a given column.
*
* @package Piwik
* @subpackage Piwik_DataTable
*/
class Piwik_DataTable_Filter_ColumnCallbackDeleteRow extends Piwik_DataTable_Filter
{
private $columnToFilter;
private $function;
public function __construct( $table, $columnToFilter, $function )
{
parent::__construct($table);
$this->function = $function;
$this->columnToFilter = $columnToFilter;
$this->filter();
}
protected function filter()
{
foreach($this->table->getRows() as $key => $row)
{
$columnValue = $row->getColumn($this->columnToFilter);
if( !call_user_func( $this->function, $columnValue))
{
$this->table->deleteRow($key);
}
}
}
}
@@ -0,0 +1,62 @@
<?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: ColumnCallbackReplace.php 2303 2010-06-14 17:31:41Z matt $
*
* @category Piwik
* @package Piwik
*/
/**
* Replace a column value with a new value resulting
* from the function called with the column's value
*
* @package Piwik
* @subpackage Piwik_DataTable
*/
class Piwik_DataTable_Filter_ColumnCallbackReplace extends Piwik_DataTable_Filter
{
private $columnToFilter;
private $functionToApply;
public function __construct( $table, $columnToFilter, $functionToApply, $functionParameters = null )
{
parent::__construct($table);
$this->functionToApply = $functionToApply;
$this->functionParameters = $functionParameters;
$this->columnToFilter = $columnToFilter;
$this->filter();
}
protected function filter()
{
foreach($this->table->getRows() as $key => $row)
{
// when a value is not defined, we set it to zero by default (rather than displaying '-')
$value = $this->getElementToReplace($row, $this->columnToFilter);
if($value === false)
{
$value = 0;
}
$parameters = array($value);
if(!is_null($this->functionParameters))
{
$parameters = array_merge($parameters, $this->functionParameters);
}
$newValue = call_user_func_array( $this->functionToApply, $parameters);
$this->setElementToReplace($row, $this->columnToFilter, $newValue);
}
}
protected function setElementToReplace($row, $columnToFilter, $newValue)
{
$row->setColumn($columnToFilter, $newValue);
}
protected function getElementToReplace($row, $columnToFilter)
{
return $row->getColumn($columnToFilter);
}
}
@@ -0,0 +1,36 @@
<?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: ColumnDelete.php 1600 2009-11-17 17:57:06Z matt $
*
* @category Piwik
* @package Piwik
*/
/**
* Deletes a column from a datatable
*
* @package Piwik
* @subpackage Piwik_DataTable
*/
class Piwik_DataTable_Filter_ColumnDelete extends Piwik_DataTable_Filter
{
private $columnToFilter;
private $functionToApply;
public function __construct( $table, $columnToDelete )
{
parent::__construct($table);
$this->columnToDelete = $columnToDelete;
$this->filter();
}
protected function filter()
{
$this->table->deleteColumn($this->columnToDelete);
}
}
@@ -0,0 +1,59 @@
<?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: ExcludeLowPopulation.php 1420 2009-08-22 13:23:16Z vipsoft $
*
* @category Piwik
* @package Piwik
*/
/**
* Delete all rows that have a $columnToFilter value less than the $minimumValue
*
* For example we delete from the countries report table all countries that have less than 3 visits.
* It is very useful to exclude noise from the reports.
* You can obviously apply this filter on a percentaged column, eg. remove all countries with the column 'percent_visits' less than 0.05
*
* @package Piwik
* @subpackage Piwik_DataTable
*/
class Piwik_DataTable_Filter_ExcludeLowPopulation extends Piwik_DataTable_Filter
{
static public $minimumValue;
const MINIMUM_SIGNIFICANT_PERCENTAGE_THRESHOLD = 0.02;
public function __construct( $table, $columnToFilter, $minimumValue, $minimumPercentageThreshold = false )
{
parent::__construct($table);
$this->columnToFilter = $columnToFilter;
if($minimumValue == 0)
{
if($minimumPercentageThreshold === false)
{
$minimumPercentageThreshold = self::MINIMUM_SIGNIFICANT_PERCENTAGE_THRESHOLD;
}
$allValues = $this->table->getColumn($this->columnToFilter);
$sumValues = array_sum($allValues);
$minimumValue = $sumValues * $minimumPercentageThreshold;
}
self::$minimumValue = $minimumValue;
$this->filter();
}
function filter()
{
$this->table->filter('ColumnCallbackDeleteRow',
array($this->columnToFilter,
array("Piwik_DataTable_Filter_ExcludeLowPopulation", "excludeLowPopulation")
)
);
}
static public function excludeLowPopulation($value)
{
return $value >= self::$minimumValue;
}
}
@@ -0,0 +1,57 @@
<?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: Limit.php 1420 2009-08-22 13:23:16Z vipsoft $
*
* @category Piwik
* @package Piwik
*/
/**
* Delete all rows from the table that are not in the offset,offset+limit range
*
* @package Piwik
* @subpackage Piwik_DataTable
*/
class Piwik_DataTable_Filter_Limit extends Piwik_DataTable_Filter
{
/**
* Filter constructor.
*
* @param Piwik_DataTable $table
* @param int $offset Starting row (indexed from 0)
* @param int $limit Number of rows to keep (specify -1 to keep all rows)
*/
public function __construct( $table, $offset, $limit = null )
{
parent::__construct($table);
$this->offset = $offset;
if(is_null($limit))
{
$limit = -1;
}
$this->limit = $limit;
$this->filter();
}
protected function filter()
{
$table = $this->table;
$rowsCount = $table->getRowsCount();
// we delete from 0 to offset
if($this->offset > 0)
{
$table->deleteRowsOffset( 0, $this->offset );
}
// at this point the array has offset less elements. We delete from limit to the end
if( $this->limit >= 0 )
{
$table->deleteRowsOffset( $this->limit );
}
}
}
@@ -0,0 +1,48 @@
<?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: MetadataCallbackAddMetadata.php 1420 2009-08-22 13:23:16Z vipsoft $
*
* @category Piwik
* @package Piwik
*/
/**
* Add a new metadata to the table based on the value resulting
* from a callback function with the parameter being another metadata value
*
* For example for the searchEngine we have a "metadata" information that gives
* the URL of the search engine. We use this URL to add a new "metadata" that gives
* the path of the logo for this search engine URL (which has the format URL.png).
*
* @package Piwik
* @subpackage Piwik_DataTable
*/
class Piwik_DataTable_Filter_MetadataCallbackAddMetadata extends Piwik_DataTable_Filter
{
private $metadataToRead;
private $functionToApply;
private $metadataToAdd;
public function __construct( $table, $metadataToRead, $metadataToAdd, $functionToApply )
{
parent::__construct($table);
$this->functionToApply = $functionToApply;
$this->metadataToRead = $metadataToRead;
$this->metadataToAdd = $metadataToAdd;
$this->filter();
}
protected function filter()
{
foreach($this->table->getRows() as $key => $row)
{
$oldValue = $row->getMetadata($this->metadataToRead);
$newValue = call_user_func( $this->functionToApply, $oldValue);
$row->addMetadata($this->metadataToAdd, $newValue);
}
}
}
@@ -0,0 +1,36 @@
<?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: MetadataCallbackReplace.php 1420 2009-08-22 13:23:16Z vipsoft $
*
* @category Piwik
* @package Piwik
*/
/**
* Replace a metadata value with a new value resulting
* from the function called with the metadata's value
*
* @package Piwik
* @subpackage Piwik_DataTable
*/
class Piwik_DataTable_Filter_MetadataCallbackReplace extends Piwik_DataTable_Filter_ColumnCallbackReplace
{
public function __construct( $table, $metadataToFilter, $functionToApply, $functionParameters = null )
{
parent::__construct($table, $metadataToFilter, $functionToApply, $functionParameters);
}
protected function setElementToReplace($row, $metadataToFilter, $newValue)
{
$row->setMetadata($metadataToFilter, $newValue);
}
protected function getElementToReplace($row, $metadataToFilter)
{
return $row->getMetadata($metadataToFilter);
}
}
@@ -0,0 +1,35 @@
<?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: Null.php 1420 2009-08-22 13:23:16Z vipsoft $
*
* @category Piwik
* @package Piwik
*/
/**
* Filter template.
* You can use it if you want to create a new filter.
*
* @package Piwik
* @subpackage Piwik_DataTable
*/
class Piwik_DataTable_Filter_Null extends Piwik_DataTable_Filter
{
public function __construct( $table )
{
parent::__construct($table);
$this->filter();
}
protected function filter()
{
foreach($this->table->getRows() as $key => $row)
{
}
}
}
@@ -0,0 +1,63 @@
<?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: Pattern.php 1420 2009-08-22 13:23:16Z vipsoft $
*
* @category Piwik
* @package Piwik
*/
/**
* Delete all rows for which the given $columnToFilter do not contain the $patternToSearch
* This filter is to be used on columns containing strings.
* Exemple: fron the keyword report, keep only the rows for which the label contains "piwik"
*
* @package Piwik
* @subpackage Piwik_DataTable
*/
class Piwik_DataTable_Filter_Pattern extends Piwik_DataTable_Filter
{
private $columnToFilter;
private $patternToSearch;
private $patternToSearchQuoted;
public function __construct( $table, $columnToFilter, $patternToSearch )
{
parent::__construct($table);
$this->patternToSearch = $patternToSearch;
$this->patternToSearchQuoted = self::getPatternQuoted($patternToSearch);
$this->columnToFilter = $columnToFilter;
$this->filter();
}
static public function getPatternQuoted( $pattern )
{
return '/'. str_replace('/', '\/', $pattern) .'/';
}
/*
* Performs case insensitive match
*/
static public function match($pattern, $patternQuoted, $string)
{
return @preg_match($patternQuoted . "i", $string) == 1;
}
protected function filter()
{
foreach($this->table->getRows() as $key => $row)
{
//instead search must handle
// - negative search with -piwik
// - exact match with ""
// see (?!pattern) A subexpression that performs a negative lookahead search, which matches the search string at any point where a string not matching pattern begins.
if( !self::match($this->patternToSearch, $this->patternToSearchQuoted, $row->getColumn($this->columnToFilter)))
{
$this->table->deleteRow($key);
}
}
}
}

Some files were not shown because too many files have changed in this diff Show More