Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Giehl <stefan@piwik.org>2017-09-26 01:28:40 +0300
committerMatthieu Aubry <mattab@users.noreply.github.com>2017-09-26 01:28:40 +0300
commit9c8980844fbdd101975915597b72765e0ef2c7a2 (patch)
treede0968973e178de75835cb540444ece81392e0ce
parentda6e68b04ff532d125e2c1e38be23814c5b8ecd9 (diff)
Use mbstring proxy methods (#12104)
* Use mbstring proxy methods * Avoid using strtolower/strtoupper if mbstring is not available to prevent possible unicode problems
-rw-r--r--core/Common.php22
-rw-r--r--plugins/API/ProcessedReport.php9
-rw-r--r--plugins/Intl/Commands/GenerateIntl.php3
-rw-r--r--plugins/MobileMessaging/SMSProvider.php3
-rw-r--r--plugins/ScheduledReports/Controller.php5
5 files changed, 33 insertions, 9 deletions
diff --git a/core/Common.php b/core/Common.php
index f884d9fe2f..7430cc6662 100644
--- a/core/Common.php
+++ b/core/Common.php
@@ -232,7 +232,27 @@ class Common
return mb_strtolower($string, 'UTF-8');
}
- return strtolower($string);
+ // return unchanged string as using `strtolower` might cause unicode problems
+ return $string;
+ }
+
+ /**
+ * Multi-byte strtoupper() - works with UTF-8.
+ *
+ * Calls `mb_strtoupper` if available and falls back to `strtoupper` if not.
+ *
+ * @param string $string
+ * @return string
+ * @api
+ */
+ public static function mb_strtoupper($string)
+ {
+ if (function_exists('mb_strtoupper')) {
+ return mb_strtoupper($string, 'UTF-8');
+ }
+
+ // return unchanged string as using `strtoupper` might cause unicode problems
+ return $string;
}
/*
diff --git a/plugins/API/ProcessedReport.php b/plugins/API/ProcessedReport.php
index f498aa1432..360d6b7ddf 100644
--- a/plugins/API/ProcessedReport.php
+++ b/plugins/API/ProcessedReport.php
@@ -363,13 +363,14 @@ class ProcessedReport
list($newReport, $columns, $rowsMetadata, $totals) = $this->handleTableReport($idSite, $dataTable, $reportMetadata, $showRawMetrics, $formatMetrics);
- if (function_exists('mb_substr')) {
+ if (function_exists('mb_substr')) {
foreach ($columns as &$name) {
if (substr($name, 0, 1) === mb_substr($name, 0, 1)) {
- $name = ucfirst($name);
- }
+ $name = ucfirst($name);
+ }
}
- }
+ }
+
$website = new Site($idSite);
$period = Period\Factory::build($period, $date);
diff --git a/plugins/Intl/Commands/GenerateIntl.php b/plugins/Intl/Commands/GenerateIntl.php
index 59b79ae30e..b525dda770 100644
--- a/plugins/Intl/Commands/GenerateIntl.php
+++ b/plugins/Intl/Commands/GenerateIntl.php
@@ -9,6 +9,7 @@
namespace Piwik\Plugins\Intl\Commands;
+use Piwik\Common;
use Piwik\Container\StaticContainer;
use Piwik\Development;
use Piwik\Filesystem;
@@ -51,7 +52,7 @@ class GenerateIntl extends ConsoleCommand
}
preg_match_all("~^(.)(.*)$~u", $str, $arr);
- return mb_strtoupper($arr[1][0], 'UTF-8').$arr[2][0];
+ return Common::mb_strtoupper($arr[1][0]).$arr[2][0];
}
protected function execute(InputInterface $input, OutputInterface $output)
diff --git a/plugins/MobileMessaging/SMSProvider.php b/plugins/MobileMessaging/SMSProvider.php
index 8d6818f6e5..0675212fdc 100644
--- a/plugins/MobileMessaging/SMSProvider.php
+++ b/plugins/MobileMessaging/SMSProvider.php
@@ -8,6 +8,7 @@
*/
namespace Piwik\Plugins\MobileMessaging;
+use Piwik\Common;
use Piwik\Container\StaticContainer;
use Piwik\Plugin;
use Piwik\Piwik;
@@ -213,7 +214,7 @@ abstract class SMSProvider
private static function sizeOfSMSContent($smsContent, $containsUCS2Chars)
{
- if ($containsUCS2Chars) return mb_strlen($smsContent, 'UTF-8');
+ if ($containsUCS2Chars) return Common::mb_strlen($smsContent);
$sizeOfSMSContent = 0;
foreach (self::mb_str_split($smsContent) as $char) {
diff --git a/plugins/ScheduledReports/Controller.php b/plugins/ScheduledReports/Controller.php
index 789b30fbc4..b41159f907 100644
--- a/plugins/ScheduledReports/Controller.php
+++ b/plugins/ScheduledReports/Controller.php
@@ -8,6 +8,7 @@
*/
namespace Piwik\Plugins\ScheduledReports;
+use Piwik\Common;
use Piwik\Date;
use Piwik\Piwik;
use Piwik\Plugins\LanguagesManager\LanguagesManager;
@@ -36,7 +37,7 @@ class Controller extends \Piwik\Plugin\Controller
$reportTypes = API::getReportTypes();
$reportTypeOptions = array();
foreach ($reportTypes as $reportType => $icon) {
- $reportTypeOptions[$reportType] = mb_strtoupper($reportType);
+ $reportTypeOptions[$reportType] = Common::mb_strtoupper($reportType);
}
$view->reportTypes = $reportTypes;
$view->reportTypeOptions = $reportTypeOptions;
@@ -53,7 +54,7 @@ class Controller extends \Piwik\Plugin\Controller
$reportFormatsByReportType[$reportType] = API::getReportFormats($reportType);
$reportFormatsByReportTypeOptions[$reportType] = $reportFormatsByReportType[$reportType];
foreach ($reportFormatsByReportTypeOptions[$reportType] as $type => $icon) {
- $reportFormatsByReportTypeOptions[$reportType][$type] = mb_strtoupper($type);
+ $reportFormatsByReportTypeOptions[$reportType][$type] = Common::mb_strtoupper($type);
}
$allowMultipleReportsByReportType[$reportType] = API::allowMultipleReports($reportType);