diff options
author | Thomas Steur <thomas.steur@gmail.com> | 2014-10-09 07:18:32 +0400 |
---|---|---|
committer | Thomas Steur <thomas.steur@gmail.com> | 2014-10-09 07:18:32 +0400 |
commit | c89189697b9cd17a5c2df0f3794b12f5cb681655 (patch) | |
tree | 083f6375b6a2005531effb42e053693d08c04f2f /core | |
parent | afb1cb7b7ec20bf3c0213e2fcd8680a85686c6ff (diff) | |
parent | cf2f71f36ffa139aec60a219aeb3748af66f477e (diff) |
Merge branch 'master' into 5940_testRenamingAndCorrectFolders
Conflicts:
tests/PHPUnit/phpunit.xml.dist
Diffstat (limited to 'core')
-rw-r--r-- | core/Config.php | 4 | ||||
-rwxr-xr-x | core/DataTable/Filter/GroupBy.php | 14 | ||||
-rw-r--r-- | core/DataTable/Renderer/Csv.php | 164 | ||||
-rw-r--r-- | core/EventDispatcher.php | 5 | ||||
-rw-r--r-- | core/Option.php | 11 | ||||
-rw-r--r-- | core/Piwik.php | 11 | ||||
-rw-r--r-- | core/ReportRenderer/Html.php | 3 | ||||
-rw-r--r-- | core/Tracker.php | 4 | ||||
-rw-r--r-- | core/testMinimumPhpVersion.php | 4 |
9 files changed, 140 insertions, 80 deletions
diff --git a/core/Config.php b/core/Config.php index 749c585647..7d0e9072e9 100644 --- a/core/Config.php +++ b/core/Config.php @@ -429,11 +429,11 @@ class Config extends Singleton : $this->configLocal[$name]; } - if ($section === null && $name = 'superuser') { + if ($section === null && $name == 'superuser') { $user = $this->getConfigSuperUserForBackwardCompatibility(); return $user; } else if ($section === null) { - throw new Exception("Error while trying to read a specific config file entry <strong>'$name'</strong> from your configuration files.</b>If you just completed a Piwik upgrade, please check that the file config/global.ini.php was overwritten by the latest Piwik version."); + $section = array(); } // cache merged section for later diff --git a/core/DataTable/Filter/GroupBy.php b/core/DataTable/Filter/GroupBy.php index b899bb9059..9391ccd95f 100755 --- a/core/DataTable/Filter/GroupBy.php +++ b/core/DataTable/Filter/GroupBy.php @@ -51,11 +51,11 @@ class GroupBy extends BaseFilter * @param DataTable $table The DataTable to filter. * @param string $groupByColumn The column name to reduce. * @param callable $reduceFunction The reduce function. This must alter the `$groupByColumn` - * columng in some way. + * columng in some way. If not set then the filter will group by the raw column value. * @param array $parameters deprecated - use an [anonymous function](http://php.net/manual/en/functions.anonymous.php) * instead. */ - public function __construct($table, $groupByColumn, $reduceFunction, $parameters = array()) + public function __construct($table, $groupByColumn, $reduceFunction = null, $parameters = array()) { parent::__construct($table); @@ -80,10 +80,14 @@ class GroupBy extends BaseFilter continue; } - // reduce the group by column of this row $groupByColumnValue = $row->getColumn($this->groupByColumn); - $parameters = array_merge(array($groupByColumnValue), $this->parameters); - $groupByValue = call_user_func_array($this->reduceFunction, $parameters); + $groupByValue = $groupByColumnValue; + + // reduce the group by column of this row + if($this->reduceFunction) { + $parameters = array_merge(array($groupByColumnValue), $this->parameters); + $groupByValue = call_user_func_array($this->reduceFunction, $parameters); + } if (!isset($groupByRows[$groupByValue])) { // if we haven't encountered this group by value before, we mark this row as a diff --git a/core/DataTable/Renderer/Csv.php b/core/DataTable/Renderer/Csv.php index f75ef8d215..6f37a660bd 100644 --- a/core/DataTable/Renderer/Csv.php +++ b/core/DataTable/Renderer/Csv.php @@ -84,11 +84,7 @@ class Csv extends Renderer $this->renderHeader(); - if ($this->convertToUnicode - && function_exists('mb_convert_encoding') - ) { - $str = chr(255) . chr(254) . mb_convert_encoding($str, 'UTF-16LE', 'UTF-8'); - } + $str = $this->convertToUnicode($str); return $str; } @@ -193,42 +189,7 @@ class Csv extends Renderer } } - $csv = array(); - foreach ($table->getRows() as $row) { - $csvRow = $this->flattenColumnArray($row->getColumns()); - - if ($this->exportMetadata) { - $metadata = $row->getMetadata(); - foreach ($metadata as $name => $value) { - if ($name == 'idsubdatatable_in_db') { - continue; - } - //if a metadata and a column have the same name make sure they dont overwrite - if ($this->translateColumnNames) { - $name = Piwik::translate('General_Metadata') . ': ' . $name; - } else { - $name = 'metadata_' . $name; - } - - $csvRow[$name] = $value; - } - } - - foreach ($csvRow as $name => $value) { - $allColumns[$name] = true; - } - - if ($this->exportIdSubtable) { - $idsubdatatable = $row->getIdSubDataTable(); - if ($idsubdatatable !== false - && $this->hideIdSubDatatable === false - ) { - $csvRow['idsubdatatable'] = $idsubdatatable; - } - } - - $csv[] = $csvRow; - } + $csv = $this->makeArrayFromDataTable($table, $allColumns); // now we make sure that all the rows in the CSV array have all the columns foreach ($csv as &$row) { @@ -239,31 +200,7 @@ class Csv extends Renderer } } - $str = ''; - - // specific case, we have only one column and this column wasn't named properly (indexed by a number) - // we don't print anything in the CSV file => an empty line - if (sizeof($allColumns) == 1 - && reset($allColumns) - && !is_string(key($allColumns)) - ) { - $str .= ''; - } else { - // render row names - $str .= $this->getHeaderLine(array_keys($allColumns)) . $this->lineEnd; - } - - // we render the CSV - foreach ($csv as $theRow) { - $rowStr = ''; - foreach ($allColumns as $columnName => $true) { - $rowStr .= $this->formatValue($theRow[$columnName]) . $this->separator; - } - // remove the last separator - $rowStr = substr_replace($rowStr, "", -strlen($this->separator)); - $str .= $rowStr . $this->lineEnd; - } - $str = substr($str, 0, -strlen($this->lineEnd)); + $str = $this->buildCsvString($allColumns, $csv); return $str; } @@ -392,4 +329,99 @@ class Csv extends Renderer return $name; } } + + /** + * @param $allColumns + * @param $csv + * @return array + */ + private function buildCsvString($allColumns, $csv) + { + $str = ''; + + // specific case, we have only one column and this column wasn't named properly (indexed by a number) + // we don't print anything in the CSV file => an empty line + if (sizeof($allColumns) == 1 + && reset($allColumns) + && !is_string(key($allColumns)) + ) { + $str .= ''; + } else { + // render row names + $str .= $this->getHeaderLine(array_keys($allColumns)) . $this->lineEnd; + } + + // we render the CSV + foreach ($csv as $theRow) { + $rowStr = ''; + foreach ($allColumns as $columnName => $true) { + $rowStr .= $this->formatValue($theRow[$columnName]) . $this->separator; + } + // remove the last separator + $rowStr = substr_replace($rowStr, "", -strlen($this->separator)); + $str .= $rowStr . $this->lineEnd; + } + $str = substr($str, 0, -strlen($this->lineEnd)); + return $str; + } + + /** + * @param $table + * @param $allColumns + * @return array of csv data + */ + private function makeArrayFromDataTable($table, &$allColumns) + { + $csv = array(); + foreach ($table->getRows() as $row) { + $csvRow = $this->flattenColumnArray($row->getColumns()); + + if ($this->exportMetadata) { + $metadata = $row->getMetadata(); + foreach ($metadata as $name => $value) { + if ($name == 'idsubdatatable_in_db') { + continue; + } + //if a metadata and a column have the same name make sure they dont overwrite + if ($this->translateColumnNames) { + $name = Piwik::translate('General_Metadata') . ': ' . $name; + } else { + $name = 'metadata_' . $name; + } + + $csvRow[$name] = $value; + } + } + + foreach ($csvRow as $name => $value) { + $allColumns[$name] = true; + } + + if ($this->exportIdSubtable) { + $idsubdatatable = $row->getIdSubDataTable(); + if ($idsubdatatable !== false + && $this->hideIdSubDatatable === false + ) { + $csvRow['idsubdatatable'] = $idsubdatatable; + } + } + + $csv[] = $csvRow; + } + return $csv; + } + + /** + * @param $str + * @return string + */ + private function convertToUnicode($str) + { + if ($this->convertToUnicode + && function_exists('mb_convert_encoding') + ) { + $str = chr(255) . chr(254) . mb_convert_encoding($str, 'UTF-16LE', 'UTF-8'); + } + return $str; + } } diff --git a/core/EventDispatcher.php b/core/EventDispatcher.php index d343da8beb..bdec8c1c7c 100644 --- a/core/EventDispatcher.php +++ b/core/EventDispatcher.php @@ -90,6 +90,11 @@ class EventDispatcher extends Singleton $plugin = $this->getPluginManager()->getLoadedPlugin($plugin); } + if (empty($plugin)) { + return; // may happen in unit tests + } + + $hooks = $plugin->getListHooksRegistered(); if (isset($hooks[$eventName])) { diff --git a/core/Option.php b/core/Option.php index d50e5c4235..d79df967ed 100644 --- a/core/Option.php +++ b/core/Option.php @@ -144,6 +144,17 @@ class Option } /** + * Sets the singleton instance. For testing purposes. + * + * @param mixed + * @ignore + */ + public static function setSingletonInstance($instance) + { + self::$instance = $instance; + } + + /** * Private Constructor */ private function __construct() diff --git a/core/Piwik.php b/core/Piwik.php index 16f50f387f..13124728f9 100644 --- a/core/Piwik.php +++ b/core/Piwik.php @@ -142,6 +142,7 @@ class Piwik // Build optional parameters to be added to text $options = ''; + $optionsBeforeTrackerUrl = ''; if ($groupPageTitlesByDomain) { $options .= ' _paq.push(["setDocumentTitle", document.domain + "/" + document.title]);' . PHP_EOL; } @@ -187,7 +188,9 @@ class Piwik $codeImpl = array( 'idSite' => $idSite, 'piwikUrl' => Common::sanitizeInputValue($piwikUrl), - 'options' => $options + 'options' => $options, + 'optionsBeforeTrackerUrl' => $optionsBeforeTrackerUrl, + 'protocol' => '//' ); $parameters = compact('mergeSubdomains', 'groupPageTitlesByDomain', 'mergeAliasUrls', 'visitorCustomVariables', 'pageCustomVariables', 'customCampaignNameQueryParam', 'customCampaignKeywordParam', @@ -205,6 +208,10 @@ class Piwik * - **piwikUrl**: The tracker URL to use. * - **options**: A string of JavaScript code that customises * the JavaScript tracker. + * - **optionsBeforeTrackerUrl**: A string of Javascript code that customises + * the JavaScript tracker inside of anonymous function before + * adding setTrackerUrl into paq. + * - **protocol**: Piwik url protocol. * * The **httpsPiwikUrl** element can be set if the HTTPS * domain is different from the normal domain. @@ -212,7 +219,7 @@ class Piwik */ self::postEvent('Piwik.getJavascriptCode', array(&$codeImpl, $parameters)); - $setTrackerUrl = 'var u="//{$piwikUrl}/";'; + $setTrackerUrl = 'var u="' . $codeImpl['protocol'] . '{$piwikUrl}/";'; if (!empty($codeImpl['httpsPiwikUrl'])) { $setTrackerUrl = 'var u=((document.location.protocol === "https:") ? "https://{$httpsPiwikUrl}/" : "http://{$piwikUrl}/");'; diff --git a/core/ReportRenderer/Html.php b/core/ReportRenderer/Html.php index c929c9a449..d8ff678bc8 100644 --- a/core/ReportRenderer/Html.php +++ b/core/ReportRenderer/Html.php @@ -189,10 +189,9 @@ class Html extends ReportRenderer $additionalFile['filename'] = sprintf( - '%s - %s - %s %d - %s %d%s.png', + '%s - %s - %d - %s %d%s.png', $processedReportMetadata['name'], $prettyDate, - Piwik::translate('General_Website'), $report['idsite'], Piwik::translate('General_Report'), $report['idreport'], diff --git a/core/Tracker.php b/core/Tracker.php index 3aa27237a1..72bd3cd289 100644 --- a/core/Tracker.php +++ b/core/Tracker.php @@ -452,6 +452,7 @@ class Tracker } Common::sendHeader('Content-Type: application/json'); echo Common::json_encode($result); + die(1); exit; } @@ -468,8 +469,9 @@ class Tracker Common::sendHeader('Content-Type: text/html; charset=utf-8'); echo $this->getMessageFromException($e); } else { - $this->outputTransparentGif (); + $this->outputTransparentGif(); } + die(1); exit; } diff --git a/core/testMinimumPhpVersion.php b/core/testMinimumPhpVersion.php index 3dd3defd3e..542279f872 100644 --- a/core/testMinimumPhpVersion.php +++ b/core/testMinimumPhpVersion.php @@ -15,8 +15,8 @@ $piwik_errorMessage = ''; -// Minimum requirement: stream_resolve_include_path in 5.3.2, namespaces in 5.3 -$piwik_minimumPHPVersion = '5.3.2'; +// Minimum requirement: stream_resolve_include_path, working json_encode in 5.3.3, namespaces in 5.3 +$piwik_minimumPHPVersion = '5.3.3'; $piwik_currentPHPVersion = PHP_VERSION; $minimumPhpInvalid = version_compare($piwik_minimumPHPVersion, $piwik_currentPHPVersion) > 0; if ($minimumPhpInvalid) { |