From 1f0fae68094a5d2865f6722c45d2c5fd4c6d20fb Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Sat, 9 Dec 2017 20:13:57 +0500 Subject: [PATCH 1/7] * Minor changes: Code style and comments. --- ddTypograph.php | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/ddTypograph.php b/ddTypograph.php index 8e234db..1d97cd1 100644 --- a/ddTypograph.php +++ b/ddTypograph.php @@ -1,24 +1,23 @@ = 0.12 {@link http://code.divandesign.biz/modx/ddtools }. * @uses EMT lib 3.5 (contains in archive). * * @param $text {string} — Text to correct. @required - * @param $optAlign {0 | 1} — Optical alignment (hanging punctuation). Default: 0. - * @param $text_paragraphs {0 | 1} — Section signs and line breaks insertion. Default: 0. - * @param $text_autoLinks {0 | 1} — Marking links (including email ones). Default: 0. - * @param $etc_unicodeConvert {0 | 1} — Convert html entities into Unicode (“—” instead of “—” etc.). Default: 1. - * @param $noTags {0 | 1} — Whether HTML element insertion is allowed or not. There are cases when using tags causes the text to be invalid, for example, using the snippet inside of an HTML attribute. Default: 0. + * @param $optAlign {0|1} — Optical alignment (hanging punctuation). Default: 0. + * @param $text_paragraphs {0|1} — Section signs and line breaks insertion. Default: 0. + * @param $text_autoLinks {0|1} — Marking links (including email ones). Default: 0. + * @param $etc_unicodeConvert {0|1} — Convert html entities into Unicode (“—” instead of “—” etc.). Default: 1. + * @param $noTags {0|1} — Whether HTML element insertion is allowed or not. There are cases when using tags causes the text to be invalid, for example, using the snippet inside of an HTML attribute. Default: 0. * * @link http://code.divandesign.biz/modx/ddtypograph/2.3 * - * @copyright 2015, DivanDesign - * http://www.DivanDesign.biz + * @copyright 2010–2015 DivanDesign {@link http://www.DivanDesign.biz } */ //Если есть что типографировать @@ -26,7 +25,11 @@ global $ddTypograph; //Заменим кавычки, вставленные через спец. символы на обычные (а то не обрабатываются в библиотеке) - $text = str_replace('"', '"', $text); + $text = str_replace( + '"', + '"', + $text + ); if (!isset($ddTypograph)){ //Подключаем EMT типограф @@ -39,15 +42,21 @@ require_once $modx->config['base_path'].'assets/snippets/ddTools/modx.ddtools.class.php'; //Для обратной совместимости - extract(ddTools::verifyRenamedParams($params, array( - 'optAlign' => 'OptAlign', - 'text_paragraphs' => 'Text_paragraphs', - 'text_autoLinks' => 'Text_autoLinks', - 'etc_unicodeConvert' => 'Etc_unicodeConvert' - ))); + extract(ddTools::verifyRenamedParams( + $params, + array( + 'optAlign' => 'OptAlign', + 'text_paragraphs' => 'Text_paragraphs', + 'text_autoLinks' => 'Text_autoLinks', + 'etc_unicodeConvert' => 'Etc_unicodeConvert' + ) + )); //Если нельзя добавлять теги к тексту - if (isset($noTags) && $noTags == 1){ + if ( + isset($noTags) && + $noTags == 1 + ){ // $noTags = 'off'; $optAlign = 'off'; From 93fa9ece424e436e6426677b9f6961a569792dcf Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Sat, 9 Dec 2017 20:18:37 +0500 Subject: [PATCH 2/7] =?UTF-8?q?*=20Refactoring:=20The=20=E2=80=9C$modx->ge?= =?UTF-8?q?tConfig=E2=80=9D=20method=20is=20used=20instead=20of=20direct?= =?UTF-8?q?=20accessing=20to=20the=20=E2=80=9C$modx->config=E2=80=9D=20arr?= =?UTF-8?q?ay.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ddTypograph.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ddTypograph.php b/ddTypograph.php index 1d97cd1..174a428 100644 --- a/ddTypograph.php +++ b/ddTypograph.php @@ -33,13 +33,13 @@ if (!isset($ddTypograph)){ //Подключаем EMT типограф - require_once $modx->config['base_path'].'assets/snippets/ddTypograph/EMT.php'; + require_once $modx->getConfig('base_path').'assets/snippets/ddTypograph/EMT.php'; $ddTypograph = new EMTypograph(); } //Подключаем modx.ddTools - require_once $modx->config['base_path'].'assets/snippets/ddTools/modx.ddtools.class.php'; + require_once $modx->getConfig('base_path').'assets/snippets/ddTools/modx.ddtools.class.php'; //Для обратной совместимости extract(ddTools::verifyRenamedParams( From f1093d7bb4a63808b6af4c01a9aecb9e51cad293 Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Sat, 9 Dec 2017 20:19:50 +0500 Subject: [PATCH 3/7] * Attention! Library now requires MODXEvo.libraries.ddTools >= 0.21. --- ddTypograph.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ddTypograph.php b/ddTypograph.php index 174a428..9ae2d4b 100644 --- a/ddTypograph.php +++ b/ddTypograph.php @@ -5,7 +5,7 @@ * * @desc Snippet for text typography. The snippet doesn’t use third-party services, also it sends no requests. In other words, everything is performed on your server. * - * @uses MODXEvo.libraries.ddTools >= 0.12 {@link http://code.divandesign.biz/modx/ddtools }. + * @uses MODXEvo.libraries.ddTools >= 0.21 {@link http://code.divandesign.biz/modx/ddtools }. * @uses EMT lib 3.5 (contains in archive). * * @param $text {string} — Text to correct. @required @@ -38,8 +38,8 @@ $ddTypograph = new EMTypograph(); } - //Подключаем modx.ddTools - require_once $modx->getConfig('base_path').'assets/snippets/ddTools/modx.ddtools.class.php'; + //Include MODXEvo.libraries.ddTools + require_once $modx->getConfig('base_path').'assets/libs/ddTools/modx.ddtools.class.php'; //Для обратной совместимости extract(ddTools::verifyRenamedParams( From c2d56ccf3af653225a6616f344267788fa6c2e55 Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Sat, 9 Dec 2017 20:22:01 +0500 Subject: [PATCH 4/7] * The short array syntax is used. It is more convenient and simple for visual identification. * Attention! PHP >= 5.4 is required. --- ddTypograph.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ddTypograph.php b/ddTypograph.php index 9ae2d4b..24de418 100644 --- a/ddTypograph.php +++ b/ddTypograph.php @@ -5,6 +5,7 @@ * * @desc Snippet for text typography. The snippet doesn’t use third-party services, also it sends no requests. In other words, everything is performed on your server. * + * @uses PHP >= 5.4. * @uses MODXEvo.libraries.ddTools >= 0.21 {@link http://code.divandesign.biz/modx/ddtools }. * @uses EMT lib 3.5 (contains in archive). * @@ -44,12 +45,12 @@ //Для обратной совместимости extract(ddTools::verifyRenamedParams( $params, - array( + [ 'optAlign' => 'OptAlign', 'text_paragraphs' => 'Text_paragraphs', 'text_autoLinks' => 'Text_autoLinks', 'etc_unicodeConvert' => 'Etc_unicodeConvert' - ) + ] )); //Если нельзя добавлять теги к тексту @@ -76,7 +77,7 @@ $etc_unicodeConvert = isset($etc_unicodeConvert) && $etc_unicodeConvert == 0 ? 'off' : 'on'; - $ddTypograph->setup(array( + $ddTypograph->setup([ //Расстановка «кавычек-елочек» первого уровня 'Quote.quotes' => 'on', //Внутренние кавычки-лапки @@ -245,7 +246,7 @@ 'Etc.nobr_to_nbsp' => $etc_nobr_to_nbsp, //Разбиение числа на триады («10000» → «10 000») 'Etc.split_number_to_triads' => 'on' - )); + ]); $ddTypograph->set_text($text); From 7345ab564b3ccfd5b31eb42872af4a4e83eeef6a Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Sat, 9 Dec 2017 20:49:53 +0500 Subject: [PATCH 5/7] =?UTF-8?q?+=20Added=20an=20ability=20to=20exlude=20HT?= =?UTF-8?q?ML=20tags=20from=20snippet=20processing=20(see=20the=20?= =?UTF-8?q?=E2=80=9CexcludeTags=E2=80=9D=20parameter).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ddTypograph.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/ddTypograph.php b/ddTypograph.php index 24de418..d94422d 100644 --- a/ddTypograph.php +++ b/ddTypograph.php @@ -15,6 +15,7 @@ * @param $text_autoLinks {0|1} — Marking links (including email ones). Default: 0. * @param $etc_unicodeConvert {0|1} — Convert html entities into Unicode (“—” instead of “—” etc.). Default: 1. * @param $noTags {0|1} — Whether HTML element insertion is allowed or not. There are cases when using tags causes the text to be invalid, for example, using the snippet inside of an HTML attribute. Default: 0. + * @param $excludeTags {string_commaSeparated} — HTML tags which content will be ignored by snippet. Default: 'notg'. * * @link http://code.divandesign.biz/modx/ddtypograph/2.3 * @@ -53,6 +54,34 @@ ] )); + //Safe tags + $excludeTags = isset($excludeTags) ? strtolower($excludeTags) : 'notg'; + $excludeTags = explode(',', $excludeTags); + + foreach ($excludeTags as $excludeTags_item){ + $excludeTags_item = trim($excludeTags_item); + + //We don't need anything with default EMT tag + if ($excludeTags_item != 'notg'){ + //Wrap + $text = str_ireplace( + [ + //Tag start + '<'.$excludeTags_item, + //Tag end + '' + ], + [ + //Tag start + '<'.$excludeTags_item, + //Tag end + '' + ], + $text + ); + } + } + //Если нельзя добавлять теги к тексту if ( isset($noTags) && From 94cbc23e6ee154b7270d96cb629f0da5226b7276 Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Sat, 9 Dec 2017 20:53:21 +0500 Subject: [PATCH 6/7] =?UTF-8?q?*=20Content=20of=20the=20=E2=80=9C?= =?UTF-8?q?=E2=80=9D=20tag=20is=20excluded=20by=20default=20from=20the=20s?= =?UTF-8?q?nippet=20processing=20(the=20=E2=80=9CexcludeTags=E2=80=9D=20pa?= =?UTF-8?q?rameter=20by=20default=20is=20equal=20to=20'notg,code').?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ddTypograph.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ddTypograph.php b/ddTypograph.php index d94422d..b3bb4c5 100644 --- a/ddTypograph.php +++ b/ddTypograph.php @@ -15,7 +15,7 @@ * @param $text_autoLinks {0|1} — Marking links (including email ones). Default: 0. * @param $etc_unicodeConvert {0|1} — Convert html entities into Unicode (“—” instead of “—” etc.). Default: 1. * @param $noTags {0|1} — Whether HTML element insertion is allowed or not. There are cases when using tags causes the text to be invalid, for example, using the snippet inside of an HTML attribute. Default: 0. - * @param $excludeTags {string_commaSeparated} — HTML tags which content will be ignored by snippet. Default: 'notg'. + * @param $excludeTags {string_commaSeparated} — HTML tags which content will be ignored by snippet. Default: 'notg,code'. * * @link http://code.divandesign.biz/modx/ddtypograph/2.3 * @@ -55,7 +55,7 @@ )); //Safe tags - $excludeTags = isset($excludeTags) ? strtolower($excludeTags) : 'notg'; + $excludeTags = isset($excludeTags) ? strtolower($excludeTags) : 'notg,code'; $excludeTags = explode(',', $excludeTags); foreach ($excludeTags as $excludeTags_item){ From 4cc4161a37bc35ef018b63715c717ad20cf3d6c8 Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Sat, 9 Dec 2017 20:57:44 +0500 Subject: [PATCH 7/7] Prerelease 2.4 --- README.md | 2 +- ddTypograph.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2891eed..5ac507e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# ddTypograph +# MODXEvo.snippets.ddTypograph Snippet for text typography. The snippet doesn’t use third-party services, also it sends no requests. In other words, everything is performed on your server. ___ diff --git a/ddTypograph.php b/ddTypograph.php index b3bb4c5..65f495a 100644 --- a/ddTypograph.php +++ b/ddTypograph.php @@ -1,7 +1,7 @@