aboutsummaryrefslogtreecommitdiff
path: root/ratatoeskr/sys/models.php
diff options
context:
space:
mode:
authorLaria Carolin Chabowski <laria@laria.me>2020-09-25 21:18:18 +0200
committerLaria Carolin Chabowski <laria@laria.me>2020-09-25 21:28:55 +0200
commit378881378aab5454c84cb1fecbbcc675f64dc27f (patch)
treef8bbe239c2a87cc61bec05b987099e4401dd2693 /ratatoeskr/sys/models.php
parent78c0350b3b7fc025ba565e19bfa195b68e95bb88 (diff)
downloadratatoeskr-cms-378881378aab5454c84cb1fecbbcc675f64dc27f.tar.gz
ratatoeskr-cms-378881378aab5454c84cb1fecbbcc675f64dc27f.tar.bz2
ratatoeskr-cms-378881378aab5454c84cb1fecbbcc675f64dc27f.zip
Refactor textprocessors
They are now managed by TextprocessorRepository and are instances of Textprocessor. This replaces the global $textprocessors variable.
Diffstat (limited to 'ratatoeskr/sys/models.php')
-rw-r--r--ratatoeskr/sys/models.php31
1 files changed, 21 insertions, 10 deletions
diff --git a/ratatoeskr/sys/models.php b/ratatoeskr/sys/models.php
index 9f81fcf..caf14ad 100644
--- a/ratatoeskr/sys/models.php
+++ b/ratatoeskr/sys/models.php
@@ -9,6 +9,9 @@
* See "ratatoeskr/licenses/ratatoeskr" for more information.
*/
+use r7r\cms\sys\textprocessors\TextprocessorRepository;
+use r7r\cms\sys\Env;
+
require_once(dirname(__FILE__) . "/db.php");
require_once(dirname(__FILE__) . "/utils.php");
require_once(dirname(__FILE__) . "/../libs/kses.php");
@@ -691,6 +694,16 @@ class Translation
$this->text = $text;
$this->texttype = $texttype;
}
+
+ /**
+ * Applies a textprocessor to the text according to texttype.
+ * @param TextprocessorRepository $textprocessors
+ * @return string
+ */
+ public function applyTextprocessor(TextprocessorRepository $textprocessors): string
+ {
+ return $textprocessors->apply((string)$this->text, (string)$this->texttype);
+ }
}
/*
@@ -1192,22 +1205,20 @@ class Comment extends BySQLRowEnabled
return $rv;
}
- /*
- * Function: htmlize_comment_text
- * Creates the HTML representation of a comment text. It applys the page's comment textprocessor on it
+ /**
+ * Creates the HTML representation of a comment text. It applies the page's comment textprocessor on it
* and filters some potentially harmful tags using kses.
*
- * Parameters:
- * $text - Text to HTMLize.
- *
- * Returns:
- * HTML code.
+ * @param string $text Text to HTMLize.
+ * @return string HTML code.
*/
- public static function htmlize_comment_text($text)
+ public static function htmlize_comment_text($text, ?TextprocessorRepository $textprocessors = null)
{
global $ratatoeskr_settings;
- return kses(textprocessor_apply($text, $ratatoeskr_settings["comment_textprocessor"]), [
+ $textprocessors = $textprocessors ?? Env::getGlobal()->textprocessors();
+
+ return kses($textprocessors->mustApply($text, $ratatoeskr_settings["comment_textprocessor"]), [
"a" => ["href" => 1, "hreflang" => 1, "title" => 1, "rel" => 1, "rev" => 1],
"b" => [],
"i" => [],