diff options
author | mattpiwik <matthieu.aubry@gmail.com> | 2008-07-21 03:10:38 +0400 |
---|---|---|
committer | mattpiwik <matthieu.aubry@gmail.com> | 2008-07-21 03:10:38 +0400 |
commit | cc161e7df6b27101c6c1de12385f27c5027f2306 (patch) | |
tree | c47ef6e7904b19abe48401aca6d6324f4cdb5a95 /modules | |
parent | 6205e3be65830093b7ad4b92247271d022260bf0 (diff) |
- some cleanup and random small fixes
git-svn-id: http://dev.piwik.org/svn/trunk@558 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'modules')
-rw-r--r-- | modules/Auth.php | 1 | ||||
-rw-r--r-- | modules/DataTable.php | 66 | ||||
-rw-r--r-- | modules/DataTable/Renderer/Csv.php | 24 | ||||
-rw-r--r-- | modules/DataTable/Renderer/Xml.php | 19 | ||||
-rwxr-xr-x | modules/Log.php | 11 | ||||
-rw-r--r-- | modules/LogStats/Action.php | 2 | ||||
-rw-r--r-- | modules/LogStats/Visit.php | 5 |
7 files changed, 79 insertions, 49 deletions
diff --git a/modules/Auth.php b/modules/Auth.php index c521fe11b5..a466a145c9 100644 --- a/modules/Auth.php +++ b/modules/Auth.php @@ -31,6 +31,7 @@ class Piwik_Auth_Result extends Zend_Auth_Result { public function __construct($code, $identity, array $messages = array()) { + // Piwik_Auth::SUCCESS_SUPERUSER_AUTH_CODE, Zend_Auth_Result::SUCCESS, Zend_Auth_Result::FAILURE $this->_code = (int)$code; $this->_identity = $identity; $this->_messages = $messages; diff --git a/modules/DataTable.php b/modules/DataTable.php index bcd7f86581..f8345ca5c3 100644 --- a/modules/DataTable.php +++ b/modules/DataTable.php @@ -118,7 +118,7 @@ require_once "DataTable/Manager.php"; * * * ---- Other (ideas) - * We can also imagine building a DataTable_Compare which would take 2 DataTable that have the same + * We can also imagine building a DataTable_Compare which would take N DataTable that have the same * structure and would compare them, by computing the percentages of differences, etc. * * For example @@ -189,22 +189,22 @@ class Piwik_DataTable * @var bool */ protected $enableRecursiveSort = false; - + /* * @var Piwik_DataTable_Row */ protected $summaryRow = null; - + const ID_SUMMARY_ROW = -1; //TODO check that not possible adding a row with this ID normally const LABEL_SUMMARY_ROW = -1; - + /** * Maximum nesting level * * @var int */ const MAXIMUM_DEPTH_LEVEL_ALLOWED = 20; - + /** * Builds the DataTable, registers itself to the manager * @@ -213,7 +213,7 @@ class Piwik_DataTable { $this->currentId = Piwik_DataTable_Manager::getInstance()->addTable($this); } - + /** * Sort the dataTable rows using the php callback function * @@ -237,7 +237,7 @@ class Piwik_DataTable } } } - + /** * Enables the recursive sort. Means that when using $table->sort() * it will also sort all subtables using the same callback @@ -248,7 +248,7 @@ class Piwik_DataTable { $this->enableRecursiveSort = true; } - + /** * Returns the number of rows before we applied the limit filter * @@ -263,7 +263,7 @@ class Piwik_DataTable } return $toReturn; } - + /** * Saves the current number of rows * @@ -274,7 +274,7 @@ class Piwik_DataTable { $this->rowsCountBeforeLimitFilter = $this->getRowsCount(); } - + /** * Queue a DataTable_Filter that will be applied at the end of the process * (just before sending the datatable back to the browser (or API, etc.) @@ -290,7 +290,7 @@ class Piwik_DataTable } $this->queuedFilters[] = array('className' => $className, 'parameters' => $parameters); } - + /** * Apply all filters that were previously queued to this table * @see queueFilter() @@ -315,7 +315,7 @@ class Piwik_DataTable } $this->queuedFilters = array(); } - + /** * Adds a new DataTable to this DataTable * Go through all the rows of the new DataTable and applies the algorithm: @@ -359,7 +359,7 @@ class Piwik_DataTable } } } - + /** * Returns the Piwik_DataTable_Row that has a column 'label' with the value $label * @@ -405,7 +405,7 @@ class Piwik_DataTable } $this->indexNotUpToDate = false; } - + /** * Returns the ith row in the array * @@ -436,7 +436,7 @@ class Piwik_DataTable $this->rows[] = $row; $this->indexNotUpToDate = true; } - + /** * Sets the summary row (a dataTable can have only one summary row) * @@ -446,7 +446,7 @@ class Piwik_DataTable { $this->summaryRow = $row; } - + /** * Returns the dataTable ID * @@ -456,7 +456,7 @@ class Piwik_DataTable { return $this->currentId; } - + /** * Adds a new row from a PHP array data structure * You should use loadFromArray for performance! @@ -467,7 +467,7 @@ class Piwik_DataTable { $this->loadFromArray(array($row)); } - + /** * Adds a new row a PHP array data structure * You should use loadFromSimpleArray for performance! @@ -478,7 +478,7 @@ class Piwik_DataTable { $this->loadFromSimpleArray(array($row)); } - + /** * Returns the array of Piwik_DataTable_Row * @@ -495,7 +495,7 @@ class Piwik_DataTable return $this->rows + array(self::ID_SUMMARY_ROW => $this->summaryRow); } } - + /** * Returns the number of rows in the table * @@ -533,7 +533,7 @@ class Piwik_DataTable $row = array_slice($this->rows, 0, 1); return $row[0]; } - + /** * Returns the last row of the DataTable * @@ -553,7 +553,7 @@ class Piwik_DataTable $row = array_slice($this->rows, -1); return $row[0]; } - + /** * Returns the sum of the number of rows of all the subtables * + the number of rows in the parent table @@ -576,7 +576,7 @@ class Piwik_DataTable $totalCount += $this->getRowsCount(); return $totalCount; } - + /** * Delete a given column $name in all the rows * @@ -593,7 +593,7 @@ class Piwik_DataTable $this->summaryRow->deleteColumn($name); } } - + /** * Deletes the ith row * @@ -613,7 +613,7 @@ class Piwik_DataTable } unset($this->rows[$id]); } - + /** * Deletes all row from offset, offset + limit. * If limit is null then limit = $table->getRowsCount() @@ -664,7 +664,7 @@ class Piwik_DataTable $this->deleteRow($key); } } - + /** * Returns a simple output of the DataTable for easy visualization * Example: echo $datatable; @@ -676,7 +676,7 @@ class Piwik_DataTable $renderer = new Piwik_DataTable_Renderer_Console($this); return (string)$renderer; } - + /** * Returns true if both DataTable are exactly the same. * Used in unit tests. @@ -716,7 +716,7 @@ class Piwik_DataTable return true; } - + /** * The serialization returns a one dimension array containing all the * serialized DataTable contained in this DataTable. @@ -793,7 +793,7 @@ class Piwik_DataTable return $aSerializedDataTable; } - + /** * Load a serialized string of a datatable. * @@ -814,7 +814,7 @@ class Piwik_DataTable } $this->loadFromArray($serialized); } - + /** * Loads the DataTable from a PHP array data structure * @@ -851,7 +851,7 @@ class Piwik_DataTable } } } - + /** * Loads the data from a simple php array. * Basically maps a simple multidimensional php array to a DataTable. @@ -947,7 +947,7 @@ class Piwik_DataTable $this->addRow($row); } } - + /** * Rewrites the input $array * array ( @@ -1004,7 +1004,7 @@ class Piwik_DataTable $this->addRow( new Piwik_DataTable_Row($cleanRow) ); } } - + /** * At destruction we try to free memory * But php doesn't give us much control on this diff --git a/modules/DataTable/Renderer/Csv.php b/modules/DataTable/Renderer/Csv.php index b87831a457..4f2e5a97b2 100644 --- a/modules/DataTable/Renderer/Csv.php +++ b/modules/DataTable/Renderer/Csv.php @@ -50,6 +50,13 @@ class Piwik_DataTable_Renderer_Csv extends Piwik_DataTable_Renderer public $exportMetadata = true; /** + * Converts the content to unicode so that UTF8 characters (eg. chinese) can be imported in Excel + * + * @var bool + */ + public $convertToUnicode = true; + + /** * idSubtable will be exported in a column called 'idsubdatatable' * * @var bool @@ -191,7 +198,7 @@ class Piwik_DataTable_Renderer_Csv extends Piwik_DataTable_Renderer $rowStr = ''; foreach($allColumns as $columnName => $true) { - $rowStr .= $theRow[$columnName] . $this->separator; + $rowStr .= $this->formatValue($theRow[$columnName]) . $this->separator; } // remove the last separator $rowStr = substr_replace($rowStr,"",-strlen($this->separator)); @@ -200,6 +207,16 @@ class Piwik_DataTable_Renderer_Csv extends Piwik_DataTable_Renderer $str = substr($str, 0, -strlen($this->lineEnd)); return $str; } + + protected function formatValue($value) + { + if(is_string($value) + && !is_numeric($value)) + { + $value = html_entity_decode($value, ENT_COMPAT, 'UTF-8'); + } + return $value; + } protected function output( $str ) { @@ -208,9 +225,10 @@ class Piwik_DataTable_Renderer_Csv extends Piwik_DataTable_Renderer return 'No data available'; } // silent fail otherwise unit tests fail - @header("Content-type: application/vnd.ms-excel;charset=utf-8"); + @header("Content-type: application/vnd.ms-excel"); @header("Content-Disposition: attachment; filename=piwik-report-export.csv"); - if(function_exists('mb_convert_encoding')) + if($this->convertToUnicode + && function_exists('mb_convert_encoding')) { $str = chr(255) . chr(254) . mb_convert_encoding($str, 'UTF-16LE', 'UTF-8'); } diff --git a/modules/DataTable/Renderer/Xml.php b/modules/DataTable/Renderer/Xml.php index 49521fd5bd..c958f5283d 100644 --- a/modules/DataTable/Renderer/Xml.php +++ b/modules/DataTable/Renderer/Xml.php @@ -256,7 +256,11 @@ class Piwik_DataTable_Renderer_Xml extends Piwik_DataTable_Renderer $value = "\n".$this->renderDataTable($value, $prefixLine."\t\t"); $value .= $prefixLine."\t\t"; } - $out .= $prefixLine."\t\t<$name>$value</$name>\n"; + else + { + $value = $this->formatValue($value); + } + $out .= $prefixLine."\t\t<$name>".$value."</$name>\n"; } $out .= "\t"; } @@ -270,11 +274,22 @@ class Piwik_DataTable_Renderer_Xml extends Piwik_DataTable_Renderer $out = ''; foreach($array as $keyName => $value) { - $out .= $prefixLine."\t<$keyName>$value</$keyName>\n"; + $out .= $prefixLine."\t<$keyName>".$this->formatValue($value)."</$keyName>\n"; } return $out; } + protected function formatValue($value) + { + if(is_string($value) + && !is_numeric($value)) + { + $value = html_entity_decode($value, ENT_COMPAT, 'UTF-8'); + $value = htmlspecialchars($value); + } + return $value; + } + protected function output( $xml ) { // silent fail because otherwise it throws an exception in the unit tests diff --git a/modules/Log.php b/modules/Log.php index f973edd502..c793d6d2db 100755 --- a/modules/Log.php +++ b/modules/Log.php @@ -9,16 +9,15 @@ * @package Piwik_Log */ -Zend_Loader::loadClass('Zend_Log'); -Zend_Loader::loadClass('Zend_Log_Formatter_Interface'); -Zend_Loader::loadClass('Zend_Log_Writer_Stream'); -Zend_Loader::loadClass('Zend_Log_Writer_Db'); +require_once "Zend/Log.php"; +require_once "Zend/Log/Formatter/Interface.php"; +require_once "Zend/Log/Writer/Stream.php"; +require_once "Zend/Log/Writer/Db.php"; -Zend_Loader::loadClass('Piwik_Common'); +require_once "Common.php"; /** * - * * @package Piwik_Log */ abstract class Piwik_Log extends Zend_Log diff --git a/modules/LogStats/Action.php b/modules/LogStats/Action.php index 6c484681a3..ae15594d78 100644 --- a/modules/LogStats/Action.php +++ b/modules/LogStats/Action.php @@ -78,7 +78,6 @@ class Piwik_LogStats_Action implements Piwik_LogStats_Action_Interface } - /** * Returns the idaction of the current action name. * This idaction is used in the visitor logging table to link the visit information @@ -205,6 +204,7 @@ class Piwik_LogStats_Action implements Piwik_LogStats_Action_Interface $this->finalActionName = $actionName; } + /** * Sets the attribute $idAction based on $finalActionName and $actionType. * diff --git a/modules/LogStats/Visit.php b/modules/LogStats/Visit.php index 8b1fee8738..c5b96a42c3 100644 --- a/modules/LogStats/Visit.php +++ b/modules/LogStats/Visit.php @@ -692,13 +692,11 @@ class Piwik_LogStats_Visit implements Piwik_LogStats_Visit_Interface $key = htmlspecialchars( @iconv( $charset, 'utf-8//TRANSLIT', - //TODO testthis fnction exists!! use upgrade.php htmlspecialchars_decode($key, Piwik_Common::HTML_ENCODING_QUOTE_STYLE)) , Piwik_Common::HTML_ENCODING_QUOTE_STYLE); } } - if(!empty($key)) { $this->typeRefererAnalyzed = Piwik_Common::REFERER_TYPE_SEARCH_ENGINE; @@ -800,6 +798,7 @@ class Piwik_LogStats_Visit implements Piwik_LogStats_Visit_Interface } } + /** * Returns a MD5 of all the configuration settings * @return string @@ -825,6 +824,4 @@ class Piwik_LogStats_Visit implements Piwik_LogStats_Visit_Interface return Piwik_Common::generateUniqId(); } } - } - |