From b85df0b177ad0576148e98b700f81d347aa06845 Mon Sep 17 00:00:00 2001 From: Roman Parpalak Date: Mon, 25 Sep 2023 20:35:47 +0300 Subject: [PATCH] Updated s2_latex extension. --- _extensions/s2_latex/functions.php | 10 +++++----- .../hooks/fn_get_template_pre_includes_merge.php | 6 ++++-- .../s2_latex/hooks/pr_render_pre_get_content_4.php | 8 ++++---- .../s2_latex/hooks/pr_render_pre_item_render_4.php | 6 +++--- _extensions/s2_latex/lang/English.php | 6 +++--- _extensions/s2_latex/manifest.xml | 6 +++--- 6 files changed, 22 insertions(+), 20 deletions(-) diff --git a/_extensions/s2_latex/functions.php b/_extensions/s2_latex/functions.php index e47db339..d8859df7 100644 --- a/_extensions/s2_latex/functions.php +++ b/_extensions/s2_latex/functions.php @@ -12,16 +12,16 @@ die; } -function s2_encodeURIComponent($str) +function s2_encodeURIComponent(string $str): string { $revert = array('%21' => '!', '%2A' => '*', '%27' => "'", '%28' => '(', '%29' => ')'); return strtr(rawurlencode($str), $revert); } -function s2_latex_make($text) +function s2_latex_make($text): string { - return preg_replace_callback('#\\$\\$([^<>\\$]*)\\$\\$#Ss', function ($matches) { - $formula = str_replace(array(' ', '<', '>', '&'), array(' ', '<', '>', '&'), $matches[1]); - return '' . s2_htmlencode($formula) . ''; + return preg_replace_callback('#\\$\\$([^<$]*)\\$\\$#S', static function ($matches) { + $formula = str_replace([' ', '<', '>', '&'], [' ', '<', '>', '&'], $matches[1]); + return '' . s2_htmlencode($formula) . ''; }, $text); } diff --git a/_extensions/s2_latex/hooks/fn_get_template_pre_includes_merge.php b/_extensions/s2_latex/hooks/fn_get_template_pre_includes_merge.php index 46c8c038..04c9ca28 100644 --- a/_extensions/s2_latex/hooks/fn_get_template_pre_includes_merge.php +++ b/_extensions/s2_latex/hooks/fn_get_template_pre_includes_merge.php @@ -6,11 +6,13 @@ * @license http://www.gnu.org/licenses/gpl.html GPL version 2 or higher * @package s2_latex * - * @var \S2\Cms\Asset\AssetPack $assetPack + * @var AssetPack $assetPack */ +use S2\Cms\Asset\AssetPack; + if (!defined('S2_ROOT')) { die; } -$assetPack->addHeadJs('//i.upmath.me/latex.js'); +$assetPack->addJs('//i.upmath.me/latex.js', [AssetPack::OPTION_PRELOAD, AssetPack::OPTION_DEFER]); diff --git a/_extensions/s2_latex/hooks/pr_render_pre_get_content_4.php b/_extensions/s2_latex/hooks/pr_render_pre_get_content_4.php index 255277fc..5ffae5df 100644 --- a/_extensions/s2_latex/hooks/pr_render_pre_get_content_4.php +++ b/_extensions/s2_latex/hooks/pr_render_pre_get_content_4.php @@ -7,11 +7,11 @@ * @package s2_latex */ - if (!defined('S2_ROOT')) { - die; +if (!defined('S2_ROOT')) { + die; } -require S2_ROOT.'/_extensions/s2_latex'.'/functions.php'; +require S2_ROOT . '/_extensions/s2_latex/functions.php'; -$content['rss_title'] = s2_latex_make($content['rss_title']); +$content['rss_title'] = s2_latex_make($content['rss_title']); $content['rss_description'] = s2_latex_make($content['rss_description']); diff --git a/_extensions/s2_latex/hooks/pr_render_pre_item_render_4.php b/_extensions/s2_latex/hooks/pr_render_pre_item_render_4.php index 8e55a0d0..90cded99 100644 --- a/_extensions/s2_latex/hooks/pr_render_pre_item_render_4.php +++ b/_extensions/s2_latex/hooks/pr_render_pre_item_render_4.php @@ -7,9 +7,9 @@ * @package s2_latex */ - if (!defined('S2_ROOT')) { - die; +if (!defined('S2_ROOT')) { + die; } $item['title'] = s2_latex_make($item['title']); -$item['text'] = s2_latex_make($item['text']); +$item['text'] = s2_latex_make($item['text']); diff --git a/_extensions/s2_latex/lang/English.php b/_extensions/s2_latex/lang/English.php index 1421b20b..01d61500 100644 --- a/_extensions/s2_latex/lang/English.php +++ b/_extensions/s2_latex/lang/English.php @@ -1,7 +1,7 @@ 'Latex formulae: $$f(x) = x^2-\sqrt{x}$$ converts into $$f(x) = x^2-\sqrt{x}$$.
', + 'Comment syntax' => 'Latex formulas: $$f(x) = x^2-\sqrt{x}$$ converts into $$f(x) = x^2-\sqrt{x}$$.
', -); +]; diff --git a/_extensions/s2_latex/manifest.xml b/_extensions/s2_latex/manifest.xml index ac51f0b5..adc444af 100644 --- a/_extensions/s2_latex/manifest.xml +++ b/_extensions/s2_latex/manifest.xml @@ -4,9 +4,9 @@ /** * LaTeX * - * Integrates site with tex.s2cms.ru service + * Integrates site with i.upmath.me service * - * @copyright (C) 2011-2014 Roman Parpalak + * @copyright (C) 2011-2023 Roman Parpalak * @license http://www.gnu.org/licenses/gpl.html GPL version 2 or higher * @package s2_latex */ @@ -16,7 +16,7 @@ s2_latex LaTeX 2.0dev - Allows to write LaTeX formulae. + Allows to write LaTeX formulas. Roman Parpalak 2.0dev