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
path: root/core
diff options
context:
space:
mode:
authorsgiehl <stefan@piwik.org>2013-09-04 20:52:28 +0400
committersgiehl <stefan@piwik.org>2013-09-04 20:52:28 +0400
commit85ca53719a5219882ab60b2afe03676c0ab8a678 (patch)
tree14f4a243bfc214e875f2acb3ddec2f00cc2f4d26 /core
parentfdbeba31ff15c95633aa879d72f1ecc388ab83a0 (diff)
fixed coding style to be psr compatible
Diffstat (limited to 'core')
-rw-r--r--core/Translate/Filter/ByBaseTranslations.php14
-rw-r--r--core/Translate/Filter/ByParameterCount.php10
-rw-r--r--core/Translate/Filter/EmptyTranslations.php4
-rw-r--r--core/Translate/Filter/EncodedEntities.php2
-rw-r--r--core/Translate/Filter/FilterAbstract.php4
-rw-r--r--core/Translate/Filter/UnnecassaryWhitespaces.php10
-rw-r--r--core/Translate/Validate/CoreTranslations.php38
-rw-r--r--core/Translate/Validate/NoScripts.php4
-rw-r--r--core/Translate/Validate/ValidateAbstract.php4
-rw-r--r--core/Translate/Writer.php108
10 files changed, 104 insertions, 94 deletions
diff --git a/core/Translate/Filter/ByBaseTranslations.php b/core/Translate/Filter/ByBaseTranslations.php
index 001a293c2e..918274dad8 100644
--- a/core/Translate/Filter/ByBaseTranslations.php
+++ b/core/Translate/Filter/ByBaseTranslations.php
@@ -19,7 +19,7 @@ use Piwik\Translate\Filter\FilterAbstract;
*/
class ByBaseTranslations extends FilterAbstract
{
- protected $_baseTranslations = array();
+ protected $baseTranslations = array();
/**
* Sets base translations
@@ -28,7 +28,7 @@ class ByBaseTranslations extends FilterAbstract
*/
public function __construct($baseTranslations=array())
{
- $this->_baseTranslations = $baseTranslations;
+ $this->baseTranslations = $baseTranslations;
}
/**
@@ -44,13 +44,13 @@ class ByBaseTranslations extends FilterAbstract
foreach ($translations AS $pluginName => $pluginTranslations) {
- if (empty($this->_baseTranslations[$pluginName])) {
- $this->_filteredData[$pluginName] = $pluginTranslations;
+ if (empty($this->baseTranslations[$pluginName])) {
+ $this->filteredData[$pluginName] = $pluginTranslations;
continue;
}
foreach ($pluginTranslations as $key => $translation) {
- if (isset($this->_baseTranslations[$pluginName][$key])) {
+ if (isset($this->baseTranslations[$pluginName][$key])) {
$cleanedTranslations[$pluginName][$key] = $translation;
}
}
@@ -60,7 +60,9 @@ class ByBaseTranslations extends FilterAbstract
} else {
$diff = $translations[$pluginName];
}
- if (!empty($diff)) $this->_filteredData[$pluginName] = $diff;
+ if (!empty($diff)) {
+ $this->filteredData[$pluginName] = $diff;
+ }
}
return $cleanedTranslations;
diff --git a/core/Translate/Filter/ByParameterCount.php b/core/Translate/Filter/ByParameterCount.php
index 1a1e716294..174d51ccaf 100644
--- a/core/Translate/Filter/ByParameterCount.php
+++ b/core/Translate/Filter/ByParameterCount.php
@@ -19,7 +19,7 @@ use Piwik\Translate\Filter\FilterAbstract;
*/
class ByParameterCount extends FilterAbstract
{
- protected $_baseTranslations = array();
+ protected $baseTranslations = array();
/**
* Sets base translations
@@ -28,7 +28,7 @@ class ByParameterCount extends FilterAbstract
*/
public function __construct($baseTranslations=array())
{
- $this->_baseTranslations = $baseTranslations;
+ $this->baseTranslations = $baseTranslations;
}
/**
@@ -47,8 +47,8 @@ class ByParameterCount extends FilterAbstract
foreach ($pluginTranslations AS $key => $translation) {
- if (isset($this->_baseTranslations[$pluginName][$key])) {
- $baseTranslation = $this->_baseTranslations[$pluginName][$key];
+ if (isset($this->baseTranslations[$pluginName][$key])) {
+ $baseTranslation = $this->baseTranslations[$pluginName][$key];
} else {
$baseTranslation = '';
}
@@ -59,7 +59,7 @@ class ByParameterCount extends FilterAbstract
if ($baseCount != $translationCount) {
- $this->_filteredData[$pluginName][$key] = $translation;
+ $this->filteredData[$pluginName][$key] = $translation;
continue;
}
diff --git a/core/Translate/Filter/EmptyTranslations.php b/core/Translate/Filter/EmptyTranslations.php
index b5a6d17134..d5083a6fad 100644
--- a/core/Translate/Filter/EmptyTranslations.php
+++ b/core/Translate/Filter/EmptyTranslations.php
@@ -38,7 +38,9 @@ class EmptyTranslations extends FilterAbstract
});
$diff = array_diff($translationsBefore[$plugin], $pluginTranslations);
- if (!empty($diff)) $this->_filteredData[$plugin] = $diff;
+ if (!empty($diff)) {
+ $this->filteredData[$plugin] = $diff;
+ }
}
// remove plugins without translations
diff --git a/core/Translate/Filter/EncodedEntities.php b/core/Translate/Filter/EncodedEntities.php
index 4a8b757c1f..c5a8dcf0aa 100644
--- a/core/Translate/Filter/EncodedEntities.php
+++ b/core/Translate/Filter/EncodedEntities.php
@@ -36,7 +36,7 @@ class EncodedEntities extends FilterAbstract
// remove encoded entities
$decoded = Translate::clean($translation);
if ($translation != $decoded) {
- $this->_filteredData[$pluginName][$key] = $translation;
+ $this->filteredData[$pluginName][$key] = $translation;
$translations[$pluginName][$key] = $decoded;
continue;
}
diff --git a/core/Translate/Filter/FilterAbstract.php b/core/Translate/Filter/FilterAbstract.php
index eca3489bdf..d1600536bb 100644
--- a/core/Translate/Filter/FilterAbstract.php
+++ b/core/Translate/Filter/FilterAbstract.php
@@ -17,7 +17,7 @@ namespace Piwik\Translate\Filter;
*/
abstract class FilterAbstract
{
- protected $_filteredData = array();
+ protected $filteredData = array();
/**
* Filter the given translations
@@ -36,6 +36,6 @@ abstract class FilterAbstract
*/
public function getFilteredData()
{
- return $this->_filteredData;
+ return $this->filteredData;
}
} \ No newline at end of file
diff --git a/core/Translate/Filter/UnnecassaryWhitespaces.php b/core/Translate/Filter/UnnecassaryWhitespaces.php
index 1de5c50a1f..6dae9b267d 100644
--- a/core/Translate/Filter/UnnecassaryWhitespaces.php
+++ b/core/Translate/Filter/UnnecassaryWhitespaces.php
@@ -19,7 +19,7 @@ use Piwik\Translate\Filter\FilterAbstract;
*/
class UnnecassaryWhitespaces extends FilterAbstract
{
- protected $_baseTranslations = array();
+ protected $baseTranslations = array();
/**
* Sets base translations
@@ -28,7 +28,7 @@ class UnnecassaryWhitespaces extends FilterAbstract
*/
public function __construct($baseTranslations=array())
{
- $this->_baseTranslations = $baseTranslations;
+ $this->baseTranslations = $baseTranslations;
}
/**
@@ -45,8 +45,8 @@ class UnnecassaryWhitespaces extends FilterAbstract
foreach ($pluginTranslations AS $key => $translation) {
$baseTranslation = '';
- if (isset($this->_baseTranslations[$pluginName][$key])) {
- $baseTranslation = $this->_baseTranslations[$pluginName][$key];
+ if (isset($this->baseTranslations[$pluginName][$key])) {
+ $baseTranslation = $this->baseTranslations[$pluginName][$key];
}
// remove excessive line breaks (and leading/trailing whitespace) from translations
@@ -59,7 +59,7 @@ class UnnecassaryWhitespaces extends FilterAbstract
}
$stringNoLineBreak = preg_replace('/([ ]{2,})/', " ", $stringNoLineBreak); # remove excessive white spaces again as there might be any now, after removing line breaks
if ($translation !== $stringNoLineBreak) {
- $this->_filteredData[$pluginName][$key] = $translation;
+ $this->filteredData[$pluginName][$key] = $translation;
$translations[$pluginName][$key] = $stringNoLineBreak;
continue;
}
diff --git a/core/Translate/Validate/CoreTranslations.php b/core/Translate/Validate/CoreTranslations.php
index 068d1c3cbc..46648dedbe 100644
--- a/core/Translate/Validate/CoreTranslations.php
+++ b/core/Translate/Validate/CoreTranslations.php
@@ -23,16 +23,16 @@ class CoreTranslations extends ValidateAbstract
/**
* Error States
*/
- const __ERRORSTATE_MINIMUMTRANSLATIONS__ = 'At least 250 translations required';
- const __ERRORSTATE_LOCALEREQUIRED__ = 'Locale required';
- const __ERRORSTATE_TRANSLATORINFOREQUIRED__ = 'Translator info required';
- const __ERRORSTATE_TRANSLATOREMAILREQUIRED__ = 'Translator email required';
- const __ERRORSTATE_LAYOUTDIRECTIONINVALID__ = 'Layout direction must be rtl or ltr';
- const __ERRORSTATE_LOCALEINVALID__ = 'Locale is invalid';
- const __ERRORSTATE_LOCALEINVALIDLANGUAGE__ = 'Locale is invalid - invalid language code';
- const __ERRORSTATE_LOCALEINVALIDCOUNTRY__ = 'Locale is invalid - invalid country code';
+ const ERRORSTATE_MINIMUMTRANSLATIONS = 'At least 250 translations required';
+ const ERRORSTATE_LOCALEREQUIRED = 'Locale required';
+ const ERRORSTATE_TRANSLATORINFOREQUIRED = 'Translator info required';
+ const ERRORSTATE_TRANSLATOREMAILREQUIRED = 'Translator email required';
+ const ERRORSTATE_LAYOUTDIRECTIONINVALID = 'Layout direction must be rtl or ltr';
+ const ERRORSTATE_LOCALEINVALID = 'Locale is invalid';
+ const ERRORSTATE_LOCALEINVALIDLANGUAGE = 'Locale is invalid - invalid language code';
+ const ERRORSTATE_LOCALEINVALIDCOUNTRY = 'Locale is invalid - invalid country code';
- protected $_baseTranslations = array();
+ protected $baseTranslations = array();
/**
* Sets base translations
@@ -41,7 +41,7 @@ class CoreTranslations extends ValidateAbstract
*/
public function __construct($baseTranslations=array())
{
- $this->_baseTranslations = $baseTranslations;
+ $this->baseTranslations = $baseTranslations;
}
/**
@@ -58,32 +58,32 @@ class CoreTranslations extends ValidateAbstract
*/
public function isValid($translations)
{
- $this->_message = null;
+ $this->message = null;
if (250 > count($translations, COUNT_RECURSIVE)) {
- $this->_message = self::__ERRORSTATE_MINIMUMTRANSLATIONS__;
+ $this->message = self::ERRORSTATE_MINIMUMTRANSLATIONS;
return false;
}
if (empty($translations['General']['Locale'])) {
- $this->_message = self::__ERRORSTATE_LOCALEREQUIRED__;
+ $this->message = self::ERRORSTATE_LOCALEREQUIRED;
return false;
}
if (empty($translations['General']['TranslatorName'])) {
- $this->_message = self::__ERRORSTATE_TRANSLATORINFOREQUIRED__;
+ $this->message = self::ERRORSTATE_TRANSLATORINFOREQUIRED;
return false;
}
if (empty($translations['General']['TranslatorEmail'])) {
- $this->_message = self::__ERRORSTATE_TRANSLATOREMAILREQUIRED__;
+ $this->message = self::ERRORSTATE_TRANSLATOREMAILREQUIRED;
return false;
}
if (!empty($translations['General']['LayoutDirection']) &&
!in_array($translations['General']['LayoutDirection'], array('ltr', 'rtl'))
) {
- $this->_message = self::__ERRORSTATE_LAYOUTDIRECTIONINVALID__;
+ $this->message = self::ERRORSTATE_LAYOUTDIRECTIONINVALID;
return false;
}
@@ -91,13 +91,13 @@ class CoreTranslations extends ValidateAbstract
$allCountries = Common::getCountriesList();
if (!preg_match('/^([a-z]{2})_([A-Z]{2})\.UTF-8$/', $translations['General']['Locale'], $matches)) {
- $this->_message = self::__ERRORSTATE_LOCALEINVALID__;
+ $this->message = self::ERRORSTATE_LOCALEINVALID;
return false;
} else if (!array_key_exists($matches[1], $allLanguages)) {
- $this->_message = self::__ERRORSTATE_LOCALEINVALIDLANGUAGE__;
+ $this->message = self::ERRORSTATE_LOCALEINVALIDLANGUAGE;
return false;
} else if (!array_key_exists(strtolower($matches[2]), $allCountries)) {
- $this->_message = self::__ERRORSTATE_LOCALEINVALIDCOUNTRY__;
+ $this->message = self::ERRORSTATE_LOCALEINVALIDCOUNTRY;
return false;
}
diff --git a/core/Translate/Validate/NoScripts.php b/core/Translate/Validate/NoScripts.php
index 7116e409a8..9e8fc59592 100644
--- a/core/Translate/Validate/NoScripts.php
+++ b/core/Translate/Validate/NoScripts.php
@@ -31,14 +31,14 @@ class NoScripts extends ValidateAbstract
*/
public function isValid($translations)
{
- $this->_message = null;
+ $this->message = null;
// check if any translation contains restricted script tags
$serializedStrings = serialize($translations);
$invalids = array("<script", 'document.', 'javascript:', 'src=', 'background=', 'onload=');
foreach ($invalids as $invalid) {
if (stripos($serializedStrings, $invalid) !== false) {
- $this->_message = 'script tags restricted for language files';
+ $this->message = 'script tags restricted for language files';
return false;
}
}
diff --git a/core/Translate/Validate/ValidateAbstract.php b/core/Translate/Validate/ValidateAbstract.php
index ca71850ed3..b5b853b27a 100644
--- a/core/Translate/Validate/ValidateAbstract.php
+++ b/core/Translate/Validate/ValidateAbstract.php
@@ -17,7 +17,7 @@ namespace Piwik\Translate\Validate;
*/
abstract class ValidateAbstract
{
- protected $_message = null;
+ protected $message = null;
/**
* Returns if the given translations are valid
@@ -37,6 +37,6 @@ abstract class ValidateAbstract
*/
public function getMessage()
{
- return $this->_message;
+ return $this->message;
}
} \ No newline at end of file
diff --git a/core/Translate/Writer.php b/core/Translate/Writer.php
index dea88a7103..914914955e 100644
--- a/core/Translate/Writer.php
+++ b/core/Translate/Writer.php
@@ -30,54 +30,54 @@ class Writer
*
* @var string
*/
- protected $_language = '';
+ protected $language = '';
/**
* Name of a plugin (if set in contructor)
*
* @var string|null
*/
- protected $_pluginName = null;
+ protected $pluginName = null;
/**
* translations to write to file
*
* @var array
*/
- protected $_translations = array();
+ protected $translations = array();
/**
* Validators to check translations with
*
* @var ValidateAbstract[]
*/
- protected $_validators = array();
+ protected $validators = array();
/**
* Message why validation failed
*
* @var string|null
*/
- protected $_validationMessage = null;
+ protected $validationMessage = null;
/**
* Filters to to apply to translations
*
* @var FilterAbstract[]
*/
- protected $_filters = array();
+ protected $filters = array();
/**
* Messages which filter changed the data
*
* @var array
*/
- protected $_filterMessages = array();
+ protected $filterMessages = array();
- const __UNFILTERED__ = 'unfiltered';
- const __FILTERED__ = 'filtered';
+ const UNFILTERED = 'unfiltered';
+ const FILTERED = 'filtered';
- protected $_currentState = self::__UNFILTERED__;
+ protected $currentState = self::UNFILTERED;
/**
* If $pluginName is given, Writer will be initialized for the given plugin if it exists
@@ -99,7 +99,7 @@ class Writer
throw new Exception(Piwik_TranslateException('General_ExceptionLanguageFileNotFound', array($pluginName)));
}
- $this->_pluginName = $pluginName;
+ $this->pluginName = $pluginName;
}
}
@@ -114,7 +114,7 @@ class Writer
throw new Exception(Piwik_TranslateException('General_ExceptionLanguageFileNotFound', array($language)));
}
- $this->_language = strtolower($language);
+ $this->language = strtolower($language);
}
/**
@@ -122,7 +122,7 @@ class Writer
*/
public function getLanguage()
{
- return $this->_language;
+ return $this->language;
}
/**
@@ -131,7 +131,7 @@ class Writer
*/
public function hasTranslations()
{
- return !empty($this->_translations);
+ return !empty($this->translations);
}
/**
@@ -141,9 +141,9 @@ class Writer
*/
public function setTranslations($translations)
{
- $this->_currentState = self::__UNFILTERED__;
- $this->_translations = $translations;
- $this->_applyFilters();
+ $this->currentState = self::UNFILTERED;
+ $this->translations = $translations;
+ $this->applyFilters();
}
/**
@@ -155,7 +155,7 @@ class Writer
*/
public function getTranslations($lang)
{
- $path = $this->_getTranslationPath('lang', $lang);
+ $path = $this->getTranslationPathBaseDirectory('lang', $lang);
if (!is_readable($path)) {
return array();
}
@@ -172,7 +172,7 @@ class Writer
*/
public function getTemporaryTranslationPath()
{
- return $this->_getTranslationPath('tmp');
+ return $this->getTranslationPathBaseDirectory('tmp');
}
/**
@@ -182,7 +182,7 @@ class Writer
*/
public function getTranslationPath()
{
- return $this->_getTranslationPath('lang');
+ return $this->getTranslationPathBaseDirectory('lang');
}
/**
@@ -193,16 +193,18 @@ class Writer
* @throws \Exception
* @return string path
*/
- protected function _getTranslationPath($base, $lang=null)
+ protected function getTranslationPathBaseDirectory($base, $lang=null)
{
- if (empty($lang)) $lang = $this->getLanguage();
+ if (empty($lang)) {
+ $lang = $this->getLanguage();
+ }
- if (!empty($this->_pluginName)) {
+ if (!empty($this->pluginName)) {
if ($base == 'tmp') {
- return sprintf('%s/tmp/plugins/%s/lang/%s.json', PIWIK_INCLUDE_PATH, $this->_pluginName, $lang);
+ return sprintf('%s/tmp/plugins/%s/lang/%s.json', PIWIK_INCLUDE_PATH, $this->pluginName, $lang);
} else {
- return sprintf('%s/plugins/%s/lang/%s.json', PIWIK_INCLUDE_PATH, $this->_pluginName, $lang);
+ return sprintf('%s/plugins/%s/lang/%s.json', PIWIK_INCLUDE_PATH, $this->pluginName, $lang);
}
}
@@ -221,10 +223,14 @@ class Writer
* Use JSON_UNESCAPED_UNICODE and JSON_PRETTY_PRINT for PHP >= 5.4
*/
$options = 0;
- if (defined('JSON_UNESCAPED_UNICODE')) $options |= JSON_UNESCAPED_UNICODE;
- if (defined('JSON_PRETTY_PRINT')) $options |= JSON_PRETTY_PRINT;
+ if (defined('JSON_UNESCAPED_UNICODE')) {
+ $options |= JSON_UNESCAPED_UNICODE;
+ }
+ if (defined('JSON_PRETTY_PRINT')) {
+ $options |= JSON_PRETTY_PRINT;
+ }
- return json_encode($this->_translations, $options);
+ return json_encode($this->translations, $options);
}
/**
@@ -235,7 +241,7 @@ class Writer
*/
public function save()
{
- $this->_applyFilters();
+ $this->applyFilters();
if (!$this->hasTranslations() || !$this->isValid()) {
throw new Exception('unable to save empty or invalid translations');
@@ -256,7 +262,7 @@ class Writer
*/
public function saveTemporary()
{
- $this->_applyFilters();
+ $this->applyFilters();
if (!$this->hasTranslations() || !$this->isValid()) {
throw new Exception('unable to save empty or invalid translations');
@@ -276,7 +282,7 @@ class Writer
*/
public function addValidator(ValidateAbstract $validator)
{
- $this->_validators[] = $validator;
+ $this->validators[] = $validator;
}
/**
@@ -286,13 +292,13 @@ class Writer
*/
public function isValid()
{
- $this->_applyFilters();
+ $this->applyFilters();
- $this->_validationMessage = null;
+ $this->validationMessage = null;
- foreach ($this->_validators AS $validator) {
- if (!$validator->isValid($this->_translations)) {
- $this->_validationMessage = $validator->getMessage();
+ foreach ($this->validators AS $validator) {
+ if (!$validator->isValid($this->translations)) {
+ $this->validationMessage = $validator->getMessage();
return false;
}
}
@@ -307,7 +313,7 @@ class Writer
*/
public function getValidationMessage()
{
- return $this->_validationMessage;
+ return $this->validationMessage;
}
/**
@@ -317,7 +323,7 @@ class Writer
*/
public function wasFiltered()
{
- return !empty($this->_filterMessages);
+ return !empty($this->filterMessages);
}
/**
@@ -327,7 +333,7 @@ class Writer
*/
public function getFilterMessages()
{
- return $this->_filterMessages;
+ return $this->filterMessages;
}
/**
@@ -335,7 +341,7 @@ class Writer
*/
public function addFilter(FilterAbstract $filter)
{
- $this->_filters[] = $filter;
+ $this->filters[] = $filter;
}
/**
@@ -343,39 +349,39 @@ class Writer
*
* @return bool error state
*/
- protected function _applyFilters()
+ protected function applyFilters()
{
// skip if already cleaned
- if ($this->_currentState == self::__FILTERED__) {
+ if ($this->currentState == self::FILTERED) {
return $this->wasFiltered();
}
- $this->_filterMessages = array();
+ $this->filterMessages = array();
// skip if not translations available
if (!$this->hasTranslations()) {
- $this->_currentState = self::__FILTERED__;
+ $this->currentState = self::FILTERED;
return false;
}
- $cleanedTranslations = $this->_translations;
+ $cleanedTranslations = $this->translations;
- foreach ($this->_filters AS $filter) {
+ foreach ($this->filters AS $filter) {
$cleanedTranslations = $filter->filter($cleanedTranslations);
$filteredData = $filter->getFilteredData();
if (!empty($filteredData)) {
- $this->_filterMessages[] = get_class($filter) . " changed: " .var_export($filteredData, 1);
+ $this->filterMessages[] = get_class($filter) . " changed: " .var_export($filteredData, 1);
}
}
- $this->_currentState = self::__FILTERED__;
+ $this->currentState = self::FILTERED;
- if ($cleanedTranslations != $this->_translations) {
- $this->_filterMessages[] = 'translations have been cleaned';
+ if ($cleanedTranslations != $this->translations) {
+ $this->filterMessages[] = 'translations have been cleaned';
}
- $this->_translations = $cleanedTranslations;
+ $this->translations = $cleanedTranslations;
return $this->wasFiltered();
}
}