diff --git a/Config/lib/structure.php b/Config/lib/structure.php index 8f7f1c3d0..b9df38670 100644 --- a/Config/lib/structure.php +++ b/Config/lib/structure.php @@ -42,7 +42,7 @@ function df_config_e($path, $throw = true, $expectedClass = null) { * проверил в отладчике. * @used-by \Df\Config\Backend::fc() * @used-by \Df\Config\Source::f() - * @used-by \Df\Payment\Comment\Description::getCommentText() + * @used-by \Df\Payment\Comment\Description::groupPath() * @param string|null $path [optional] * @return Field */ @@ -132,7 +132,7 @@ function df_config_field($path = null) { /** * 2016-08-02 - * @used-by \Df\Payment\Comment\Description::getCommentText() + * @used-by \Df\Payment\Comment\Description::locations() * @param string $path * @param bool $throw [optional] * @return Group|null diff --git a/Core/Format/Html/Tag.php b/Core/Format/Html/Tag.php index 3dec1a9f5..f3d2d36ae 100644 --- a/Core/Format/Html/Tag.php +++ b/Core/Format/Html/Tag.php @@ -40,9 +40,16 @@ private function openTagWithAttributesAsText() {return df_cc_s( * Не использую @see df_e(), чтобы сохранить двойные кавычки (data-mage-init) * и в то же время сконвертировать одинарные * (потому что значения атрибутов мы ниже обрамляем именно одинарными). + * + * 2017-09-11 + * Today I have notices that `'` does not work for me + * on the Magento 2 backend configuration pages: + * @see \Df\Payment\Comment\Description::a() + * So I switched to the `'` solution. + * «How do I escape a single quote?» https://stackoverflow.com/a/2428595 */ $value = htmlspecialchars( - str_replace("'", ''', !is_array($value) ? $value : df_cc_s($value)) + str_replace("'", ''', !is_array($value) ? $value : df_cc_s($value)) ,ENT_NOQUOTES ,'UTF-8' ,false diff --git a/Core/lib/array.php b/Core/lib/array.php index 48a6acc06..a949f391f 100644 --- a/Core/lib/array.php +++ b/Core/lib/array.php @@ -312,7 +312,7 @@ function df_first(array $a) {return !$a ? null : reset($a);} * Похожая системная функция @see array_pop() возвращает отсечённый последний элемент. * Противоположная системная функция @see df_tail() отсекает первый элемент массива. * @used-by \Df\Config\Source::sibling() - * @used-by \Df\Payment\Comment\Description::getCommentText() + * @used-by \Df\Payment\Comment\Description::groupPath() * @param mixed[] $a * @return mixed[]|string[] */ diff --git a/Core/lib/html.php b/Core/lib/html.php index e6e738e99..98551763e 100644 --- a/Core/lib/html.php +++ b/Core/lib/html.php @@ -146,7 +146,8 @@ function df_tag_ab($text, ...$url) {return df_tag( );} /** - * 2016-10-24 + * 2016-10-24 + * @used-by \Df\Payment\Comment\Description::a() * @param string $content * @param bool $condition * @param string $tag diff --git a/Core/lib/text.php b/Core/lib/text.php index 8fb70a3d9..4fb3ea15f 100644 --- a/Core/lib/text.php +++ b/Core/lib/text.php @@ -124,7 +124,7 @@ function df_cc_n(...$args) {return df_ccc("\n", dfa_flatten($args));} * @used-by \Df\API\Facade::p() * @used-by \Df\Config\Source::sibling() * @used-by \Df\Intl\Js::_toHtml() - * @used-by \Df\Payment\Comment\Description::getCommentText() + * @used-by \Df\Payment\Comment\Description::groupPath() * @param string[] ...$args * @return string */ @@ -332,7 +332,7 @@ function df_explode_n($s) {return explode("\n", df_normalize($s));} /** * 2016-09-03 Другой возможный алгоритм: df_explode_multiple(['/', DS], $path) - * @used-by \Df\Payment\Comment\Description::getCommentText() + * @used-by \Df\Payment\Comment\Description::groupPath() * @param string $path * @return string[] */ diff --git a/Payment/Comment/Description.php b/Payment/Comment/Description.php index ec9499907..fbd936f8a 100644 --- a/Payment/Comment/Description.php +++ b/Payment/Comment/Description.php @@ -32,25 +32,59 @@ class Description implements IComment { * @return string */ function getCommentText($v) { - /** @var string $groupPath */ - $groupPath = df_cc_path(df_head(df_explode_path(df_config_field()->getPath()))); - $m = df_config_group($groupPath)->getData()['dfExtension']; /** @var string $m */ - $rules = df_cfg("$groupPath/description_rules"); /** @var array(string => mixed)|null $rules */ + $rules = df_cfg("{$this->groupPath()}/description_rules"); /** @var array(string => mixed)|null $rules */ $maxLength = dfa($rules, 'maxLength'); /** @var array(string => mixed)|null $maxLength */ - $mTitle = dfpm_title($m); /** @var string $mTitle */ $title = $maxLength['title']; /** @var string $title */ $url = $maxLength['url']; /** @var string $url */ $v = dfa($maxLength, 'value'); /** @var int|null $v */ - /** @var string $to */ - $to = "to you in the $mTitle merchant interface alongside the payment"; - if (dfa($rules, 'shownToTheCustomers')) { - $to = "to the customers on the $mTitle payment page, and $to"; - } return - "
It will be displayed $to.
+ "It will be displayed {$this->locations(dfa($rules, 'locations', []))}.
You can use some variables in the description.
" . ($v ? "The full description length (after the variables substitution) should be not greater than $v characters (the description will be automatically chopped to $v characters if it is longer).
" : "The length is not limited.
" ); } + + /** + * 2017-09-11 + * @used-by locations() + * @param string $text + * @param array(string => string|bool) $o + * @return string + */ + private function a($text, array $o) {return df_tag_if($text, dfa($o, 'url'), 'a', [ + 'target' => '_blank', 'title' => dfa($o, 'title'), 'href' => dfa($o, 'url') + ]);} + + /** + * 2017-09-11 + * @return string + */ + private function groupPath() {return dfc($this, function() {return df_cc_path(df_head(df_explode_path( + df_config_field()->getPath() + )));});} + + /** + * 2017-09-11 + * @param array(string => mixed) $locations + * @return string + */ + private function locations(array $locations) { + $customer = dfa($locations, 'customer', []); /** @var array(string => mixed)|null $customer */ + $merchant = dfa($locations, 'merchant', []); /** @var array(string => mixed)|null $merchant */ + $payment = dfa($locations, 'payment', []); /** @var array(string => mixed)|null $payment */ + /** @var string $mTitle */ + $mTitle = dfpm_title(df_config_group($this->groupPath())->getData()['dfExtension']); + /** @var string $m */ + $m = !df_bool(dfa($merchant, 'shown')) ? '' : + "to you {$this->a("in the $mTitle merchant interface", $merchant)} alongside the payment" + ; + /** @var string $c */ + $c = !df_bool(dfa($customer, 'shown')) ? '' : $this->a("in the $mTitle customer account", $customer); + /** @var string $p */ + $p = !df_bool(dfa($payment, 'shown')) ? '' :$this->a("on the $mTitle payment page", $payment); + /** @var string $c */ + $cc = !($c || $p) ? '' : 'to the customers' . ($c && $p ? ": $c and $p" : ' ' . ($c ?: $p)); + return df_ccc(' and ', $m, $cc); + } } \ No newline at end of file diff --git a/Payment/lib/method.php b/Payment/lib/method.php index 96340c3b5..b037aff9a 100644 --- a/Payment/lib/method.php +++ b/Payment/lib/method.php @@ -119,9 +119,10 @@ function dfpm_code_short($c) {return df_trim_text_left(dfpm_code($c), 'dfe_');} * 2016-12-22 * @used-by dfp_report() * @used-by dfp_sentry_tags() + * @used-by \Df\Payment\Comment\Description::locations() + * @used-by \Df\Payment\Settings::titleB() * @used-by \Df\Payment\W\Action::notImplemented() * @used-by \Df\Payment\W\Exception::mTitle() - * @used-by \Df\Payment\Settings::titleB() * @used-by \Df\Payment\W\Handler::log() * @param string|object $c * @return string diff --git a/composer.json b/composer.json index ee1c157bb..80c5774d4 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "mage2pro/core" - ,"version": "2.11.35" + ,"version": "2.11.36" ,"description": "Mage2.PRO core package." ,"type": "magento2-module" ,"homepage": "https://mage2.pro"