From 08cf7e7b945dd624a713d5d89ce50b7561f2db4c Mon Sep 17 00:00:00 2001 From: SergeiKutanov Date: Wed, 15 Jan 2014 13:29:03 +0400 Subject: [PATCH 01/10] po filles generation. All the quotation marks must be screened by adding a backslash before them. Otherwise we cannot generate .mo file. --- .../console/controllers/MessageController.php | 24 ++++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/framework/console/controllers/MessageController.php b/framework/console/controllers/MessageController.php index 34a1564..ad970ec 100644 --- a/framework/console/controllers/MessageController.php +++ b/framework/console/controllers/MessageController.php @@ -189,6 +189,7 @@ class MessageController extends Controller $merged = []; $untranslated = []; foreach ($messages as $message) { + $message = preg_replace('/\\"/', '\"', $message); if (array_key_exists($message, $translated) && strlen($translated[$message]) > 0) { $merged[$message] = $translated[$message]; } else { @@ -202,15 +203,17 @@ class MessageController extends Controller $todo[$message] = ''; } ksort($translated); - foreach ($translated as $message => $translation) { - if (!isset($merged[$message]) && !isset($todo[$message]) && !$removeUnused) { - if (substr($translation, 0, 2) === '@@' && substr($translation, -2) === '@@') { - $todo[$message] = $translation; - } else { - $todo[$message] = '@@' . $translation . '@@'; - } - } - } + if($format === 'php'){ + foreach ($translated as $message => $translation) { + if (!isset($merged[$message]) && !isset($todo[$message]) && !$removeUnused) { + if (substr($translation, 0, 2) === '@@' && substr($translation, -2) === '@@') { + $todo[$message] = $translation; + } else { + $todo[$message] = '@@' . $translation . '@@'; + } + } + } + } $merged = array_merge($todo, $merged); if ($sort) { ksort($merged); @@ -221,6 +224,8 @@ class MessageController extends Controller if($format === 'po'){ $out_str = ''; foreach($merged as $k=>$v){ + $k = preg_replace('/(\")|(\\\")/', "\\\"", $k); + $v = preg_replace('/(\")|(\\\")/', "\\\"", $v); $out_str .= "msgid \"$k\"\n"; $out_str .= "msgstr \"$v\"\n"; $out_str .= "\n"; @@ -233,6 +238,7 @@ class MessageController extends Controller $merged = ''; sort($messages); foreach($messages as $message) { + $message = preg_replace('/(\")|(\\\")/', '\\\"', $message); $merged .= "msgid \"$message\"\n"; $merged .= "msgstr \"\"\n"; $merged .= "\n"; From ae973b0392ae8aa1dca0ecd0b99f33b8a6f369e5 Mon Sep 17 00:00:00 2001 From: marsuboss Date: Wed, 15 Jan 2014 10:33:21 +0100 Subject: [PATCH 02/10] Fix --- framework/messages/fr/yii.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/messages/fr/yii.php b/framework/messages/fr/yii.php index 03f55b7..8b69491 100644 --- a/framework/messages/fr/yii.php +++ b/framework/messages/fr/yii.php @@ -73,7 +73,7 @@ return array ( '{attribute} must be less than or equal to "{compareValue}".' => '{attribute} doit être inférieur ou égal à « {compareValue} ».', '{attribute} must be no greater than {max}.' => '{attribute} ne doit pas être supérieur à {max}.', '{attribute} must be no less than {min}.' => '{attribute} ne doit pas être inférieur à {min}.', - '{attribute} must be repeated exactly.' => '{attribute} doit être répété à l\'identique.', + '{attribute} must be repeated exactly.' => '{attribute} doit être identique.', '{attribute} must not be equal to "{compareValue}".' => '{attribute} ne doit pas être égal à « {compareValue} ».', '{attribute} should contain at least {min, number} {min, plural, one{character} other{characters}}.' => '{attribute} doit comporter au moins {min, number} {min, plural, one{caractère} other{caractères}}.', '{attribute} should contain at most {max, number} {max, plural, one{character} other{characters}}.' => '{attribute} doit comporter au plus {max, number} {max, plural, one{caractère} other{caractères}}.', From 2ce5e652d7e00dc03adf3b6da83a0e4a846d12c4 Mon Sep 17 00:00:00 2001 From: SergeiKutanov Date: Wed, 15 Jan 2014 14:44:57 +0400 Subject: [PATCH 03/10] code style fixed --- .../console/controllers/MessageController.php | 31 +++++++++++----------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/framework/console/controllers/MessageController.php b/framework/console/controllers/MessageController.php index ad970ec..412634e 100644 --- a/framework/console/controllers/MessageController.php +++ b/framework/console/controllers/MessageController.php @@ -175,7 +175,6 @@ class MessageController extends Controller $translated = file_get_contents($fileName); preg_match_all('/(?<=msgid ").*(?="\nmsgstr)/', $translated, $keys); preg_match_all('/(?<=msgstr ").*(?="\n\n)/', $translated, $values); - $translated = array_combine($keys[0], $values[0]); } else { $translated = require($fileName); @@ -189,7 +188,7 @@ class MessageController extends Controller $merged = []; $untranslated = []; foreach ($messages as $message) { - $message = preg_replace('/\\"/', '\"', $message); + $message = preg_replace('/\\"/', '\"', $message); if (array_key_exists($message, $translated) && strlen($translated[$message]) > 0) { $merged[$message] = $translated[$message]; } else { @@ -203,17 +202,17 @@ class MessageController extends Controller $todo[$message] = ''; } ksort($translated); - if($format === 'php'){ - foreach ($translated as $message => $translation) { - if (!isset($merged[$message]) && !isset($todo[$message]) && !$removeUnused) { - if (substr($translation, 0, 2) === '@@' && substr($translation, -2) === '@@') { - $todo[$message] = $translation; - } else { - $todo[$message] = '@@' . $translation . '@@'; - } - } - } - } + if($format === 'php'){ + foreach ($translated as $message => $translation) { + if (!isset($merged[$message]) && !isset($todo[$message]) && !$removeUnused) { + if (substr($translation, 0, 2) === '@@' && substr($translation, -2) === '@@') { + $todo[$message] = $translation; + } else { + $todo[$message] = '@@' . $translation . '@@'; + } + } + } + } $merged = array_merge($todo, $merged); if ($sort) { ksort($merged); @@ -224,8 +223,8 @@ class MessageController extends Controller if($format === 'po'){ $out_str = ''; foreach($merged as $k=>$v){ - $k = preg_replace('/(\")|(\\\")/', "\\\"", $k); - $v = preg_replace('/(\")|(\\\")/', "\\\"", $v); + $k = preg_replace('/(\")|(\\\")/', "\\\"", $k); + $v = preg_replace('/(\")|(\\\")/', "\\\"", $v); $out_str .= "msgid \"$k\"\n"; $out_str .= "msgstr \"$v\"\n"; $out_str .= "\n"; @@ -238,7 +237,7 @@ class MessageController extends Controller $merged = ''; sort($messages); foreach($messages as $message) { - $message = preg_replace('/(\")|(\\\")/', '\\\"', $message); + $message = preg_replace('/(\")|(\\\")/', '\\\"', $message); $merged .= "msgid \"$message\"\n"; $merged .= "msgstr \"\"\n"; $merged .= "\n"; From eefba1d536984c027ccfc46591bc346e7142cc2e Mon Sep 17 00:00:00 2001 From: surek Date: Wed, 15 Jan 2014 11:15:47 +0000 Subject: [PATCH 04/10] Update upgrade-from-v1.md Text amended as "A new method" was referring to two. CHanged the text to "New methods". --- docs/guide/upgrade-from-v1.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/guide/upgrade-from-v1.md b/docs/guide/upgrade-from-v1.md index d644190..7eb66a8 100644 --- a/docs/guide/upgrade-from-v1.md +++ b/docs/guide/upgrade-from-v1.md @@ -183,7 +183,7 @@ A model is now associated with a form name returned by its `formName()` method. mainly used when using HTML forms to collect user inputs for a model. Previously in 1.1, this is usually hardcoded as the class name of the model. -A new methods called `load()` and `Model::loadMultiple()` is introduced to simplify the data population from user inputs +New methods called `load()` and `Model::loadMultiple()` are introduced to simplify the data population from user inputs to a model. For example, ```php @@ -522,4 +522,4 @@ Yii is fully inegrated with the package manager for PHP named Composer that reso up to date updating it semi-automatically and manages autoloading for third party libraries no matter which autoloading these are using. -In order to learn more refer to [composer](composer.md) and [installation](installation.md) sections of the guide. \ No newline at end of file +In order to learn more refer to [composer](composer.md) and [installation](installation.md) sections of the guide. From 92cfdb33c7cd69f626e264d6301f47503ca423a5 Mon Sep 17 00:00:00 2001 From: SergeiKutanov Date: Wed, 15 Jan 2014 16:08:13 +0400 Subject: [PATCH 05/10] po now supports obsolete messages --- framework/console/controllers/MessageController.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/framework/console/controllers/MessageController.php b/framework/console/controllers/MessageController.php index 412634e..6de3dde 100644 --- a/framework/console/controllers/MessageController.php +++ b/framework/console/controllers/MessageController.php @@ -173,7 +173,7 @@ class MessageController extends Controller if (is_file($fileName)) { if($format === 'po'){ $translated = file_get_contents($fileName); - preg_match_all('/(?<=msgid ").*(?="\nmsgstr)/', $translated, $keys); + preg_match_all('/(?<=msgid ").*(?="\n(#*)msgstr)/', $translated, $keys); preg_match_all('/(?<=msgstr ").*(?="\n\n)/', $translated, $values); $translated = array_combine($keys[0], $values[0]); } else { @@ -188,7 +188,7 @@ class MessageController extends Controller $merged = []; $untranslated = []; foreach ($messages as $message) { - $message = preg_replace('/\\"/', '\"', $message); + $message = preg_replace('/\"/', '\"', $message); if (array_key_exists($message, $translated) && strlen($translated[$message]) > 0) { $merged[$message] = $translated[$message]; } else { @@ -202,7 +202,6 @@ class MessageController extends Controller $todo[$message] = ''; } ksort($translated); - if($format === 'php'){ foreach ($translated as $message => $translation) { if (!isset($merged[$message]) && !isset($todo[$message]) && !$removeUnused) { if (substr($translation, 0, 2) === '@@' && substr($translation, -2) === '@@') { @@ -212,7 +211,6 @@ class MessageController extends Controller } } } - } $merged = array_merge($todo, $merged); if ($sort) { ksort($merged); @@ -225,8 +223,13 @@ class MessageController extends Controller foreach($merged as $k=>$v){ $k = preg_replace('/(\")|(\\\")/', "\\\"", $k); $v = preg_replace('/(\")|(\\\")/', "\\\"", $v); - $out_str .= "msgid \"$k\"\n"; - $out_str .= "msgstr \"$v\"\n"; + if(substr($v, 0, 2) === '@@' && substr($v, -2) === '@@'){ + $out_str .= "#msgid \"$k\"\n"; + $out_str .= "#msgstr \"$v\"\n"; + }else{ + $out_str .= "msgid \"$k\"\n"; + $out_str .= "msgstr \"$v\"\n"; + } $out_str .= "\n"; } $merged = $out_str; From a937e970c6147f76124f9b74be220342e99bba86 Mon Sep 17 00:00:00 2001 From: SergeiKutanov Date: Wed, 15 Jan 2014 16:40:26 +0400 Subject: [PATCH 06/10] fixes for previous solution --- framework/console/controllers/MessageController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/framework/console/controllers/MessageController.php b/framework/console/controllers/MessageController.php index 6de3dde..ae55f24 100644 --- a/framework/console/controllers/MessageController.php +++ b/framework/console/controllers/MessageController.php @@ -188,7 +188,9 @@ class MessageController extends Controller $merged = []; $untranslated = []; foreach ($messages as $message) { - $message = preg_replace('/\"/', '\"', $message); + if($format === 'po'){ + $message = preg_replace('/\"/', '\"', $message); + } if (array_key_exists($message, $translated) && strlen($translated[$message]) > 0) { $merged[$message] = $translated[$message]; } else { From 6944ca1f94f2bd05c4e855ee5a8fe7c3510e9f92 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Wed, 15 Jan 2014 15:37:42 +0100 Subject: [PATCH 07/10] Mark event as handled when filter decides to abort action fixes #1984 --- framework/CHANGELOG.md | 1 + framework/base/ActionFilter.php | 3 +++ 2 files changed, 4 insertions(+) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 3343861..e670f66 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -65,6 +65,7 @@ Yii Framework 2 Change Log - Enh #1894: The path aliases `@webroot` and `@web` are now available right after the application is initialized (qiangxue) - Enh #1921: Grid view ActionColumn now allow to name buttons like `{controller/action}` (creocoder) - Enh #1973: `yii message/extract` is now able to generate `.po` files (SergeiKutanov, samdark) +- Enh #1984: ActionFilter will now mark event as handled when action run is aborted (cebe) - Enh: Added `favicon.ico` and `robots.txt` to default application templates (samdark) - Enh: Added `Widget::autoIdPrefix` to support prefixing automatically generated widget IDs (qiangxue) - Enh: Support for file aliases in console command 'message' (omnilight) diff --git a/framework/base/ActionFilter.php b/framework/base/ActionFilter.php index 648211c..3ea04fb 100644 --- a/framework/base/ActionFilter.php +++ b/framework/base/ActionFilter.php @@ -51,6 +51,9 @@ class ActionFilter extends Behavior { if ($this->isActive($event->action)) { $event->isValid = $this->beforeAction($event->action); + if (!$event->isValid) { + $event->handled = true; + } } return $event->isValid; } From 777e22c1af6457d1319f983299d5661d76916356 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Wed, 15 Jan 2014 11:18:34 -0500 Subject: [PATCH 08/10] Fixes #1959: `Html::activeCheckbox` wasn't respecting custom values for checked/unchecked state --- framework/CHANGELOG.md | 2 +- framework/helpers/BaseHtml.php | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index e670f66..dab763c 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -27,7 +27,7 @@ Yii Framework 2 Change Log - Bug #1827: Debugger toolbar is loaded twice if an action is calling `run()` to execute another action (qiangxue) - Bug #1870: Validation errors weren't properly translated when using clientside validation (samdark) - Bug #1937: Fixed wrong behavior or advanced app's `init --env` when called without parameter actually specified (samdark) -- Bug #1959: `Html::activeCheckbox` wasn't respecting custom values for checked/unckecked state (klevron, samdark) +- Bug #1959: `Html::activeCheckbox` wasn't respecting custom values for checked/unchecked state (klevron, samdark) - Bug #1965: `Controller::findLayoutFile()` returns incorrect file path when layout name starts with a slash (qiangxue) - Bug: Fixed `Call to a member function registerAssetFiles() on a non-object` in case of wrong `sourcePath` for an asset bundle (samdark) - Bug: Fixed incorrect event name for `yii\jui\Spinner` (samdark) diff --git a/framework/helpers/BaseHtml.php b/framework/helpers/BaseHtml.php index e817830..1dad736 100644 --- a/framework/helpers/BaseHtml.php +++ b/framework/helpers/BaseHtml.php @@ -1126,10 +1126,17 @@ class BaseHtml public static function activeRadio($model, $attribute, $options = []) { $name = isset($options['name']) ? $options['name'] : static::getInputName($model, $attribute); - $checked = static::getAttributeValue($model, $attribute); + $value = static::getAttributeValue($model, $attribute); + + if (!array_key_exists('value', $options)) { + $options['value'] = '1'; + } if (!array_key_exists('uncheck', $options)) { $options['uncheck'] = '0'; } + + $checked = $value == $options['value']; + if (!array_key_exists('id', $options)) { $options['id'] = static::getInputId($model, $attribute); } @@ -1163,11 +1170,14 @@ class BaseHtml $name = isset($options['name']) ? $options['name'] : static::getInputName($model, $attribute); $value = static::getAttributeValue($model, $attribute); + if (!array_key_exists('value', $options)) { + $options['value'] = '1'; + } if (!array_key_exists('uncheck', $options)) { $options['uncheck'] = '0'; } - $checked = ($value != $options['uncheck']); + $checked = $value == $options['value']; if (!array_key_exists('id', $options)) { $options['id'] = static::getInputId($model, $attribute); From 96f210f0d23ec0770d39eae285c845e115ec6022 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Wed, 15 Jan 2014 11:39:47 -0500 Subject: [PATCH 09/10] better fix for #1959. --- framework/helpers/BaseHtml.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/helpers/BaseHtml.php b/framework/helpers/BaseHtml.php index 1dad736..0df9fbf 100644 --- a/framework/helpers/BaseHtml.php +++ b/framework/helpers/BaseHtml.php @@ -1135,7 +1135,7 @@ class BaseHtml $options['uncheck'] = '0'; } - $checked = $value == $options['value']; + $checked = "$value" === "{$options['value']}"; if (!array_key_exists('id', $options)) { $options['id'] = static::getInputId($model, $attribute); @@ -1177,7 +1177,7 @@ class BaseHtml $options['uncheck'] = '0'; } - $checked = $value == $options['value']; + $checked = "$value" === "{$options['value']}"; if (!array_key_exists('id', $options)) { $options['id'] = static::getInputId($model, $attribute); From e0f20abd551039101a53d87b8461a41b13b850ed Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Wed, 15 Jan 2014 23:41:55 +0400 Subject: [PATCH 10/10] minor formatting fixes --- .../console/controllers/MessageController.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/framework/console/controllers/MessageController.php b/framework/console/controllers/MessageController.php index ae55f24..ead2bdb 100644 --- a/framework/console/controllers/MessageController.php +++ b/framework/console/controllers/MessageController.php @@ -204,15 +204,15 @@ class MessageController extends Controller $todo[$message] = ''; } ksort($translated); - foreach ($translated as $message => $translation) { - if (!isset($merged[$message]) && !isset($todo[$message]) && !$removeUnused) { - if (substr($translation, 0, 2) === '@@' && substr($translation, -2) === '@@') { - $todo[$message] = $translation; - } else { - $todo[$message] = '@@' . $translation . '@@'; - } + foreach ($translated as $message => $translation) { + if (!isset($merged[$message]) && !isset($todo[$message]) && !$removeUnused) { + if (substr($translation, 0, 2) === '@@' && substr($translation, -2) === '@@') { + $todo[$message] = $translation; + } else { + $todo[$message] = '@@' . $translation . '@@'; } } + } $merged = array_merge($todo, $merged); if ($sort) { ksort($merged); @@ -220,15 +220,15 @@ class MessageController extends Controller if (false === $overwrite) { $fileName .= '.merged'; } - if($format === 'po'){ + if ($format === 'po'){ $out_str = ''; - foreach($merged as $k=>$v){ + foreach ($merged as $k => $v){ $k = preg_replace('/(\")|(\\\")/', "\\\"", $k); $v = preg_replace('/(\")|(\\\")/', "\\\"", $v); - if(substr($v, 0, 2) === '@@' && substr($v, -2) === '@@'){ + if (substr($v, 0, 2) === '@@' && substr($v, -2) === '@@') { $out_str .= "#msgid \"$k\"\n"; $out_str .= "#msgstr \"$v\"\n"; - }else{ + } else { $out_str .= "msgid \"$k\"\n"; $out_str .= "msgstr \"$v\"\n"; }