diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2022-01-11 12:35:47 +0100 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2022-01-11 12:35:47 +0100 |
commit | 19985dbb8c0aa66dc4bf7905abc1148de909097d (patch) | |
tree | 2cd5a5d20d7e80fc2a51adf60d838d8a2c40999e /admin/survey/classes/htmlpurifier-4.3.0/library/HTMLPurifier/Injector/PurifierLinkify.php | |
download | 1ka-19985dbb8c0aa66dc4bf7905abc1148de909097d.tar 1ka-19985dbb8c0aa66dc4bf7905abc1148de909097d.tar.gz 1ka-19985dbb8c0aa66dc4bf7905abc1148de909097d.tar.bz2 1ka-19985dbb8c0aa66dc4bf7905abc1148de909097d.tar.lz 1ka-19985dbb8c0aa66dc4bf7905abc1148de909097d.tar.xz 1ka-19985dbb8c0aa66dc4bf7905abc1148de909097d.tar.zst 1ka-19985dbb8c0aa66dc4bf7905abc1148de909097d.zip |
Diffstat (limited to 'admin/survey/classes/htmlpurifier-4.3.0/library/HTMLPurifier/Injector/PurifierLinkify.php')
-rw-r--r-- | admin/survey/classes/htmlpurifier-4.3.0/library/HTMLPurifier/Injector/PurifierLinkify.php | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/admin/survey/classes/htmlpurifier-4.3.0/library/HTMLPurifier/Injector/PurifierLinkify.php b/admin/survey/classes/htmlpurifier-4.3.0/library/HTMLPurifier/Injector/PurifierLinkify.php new file mode 100644 index 0000000..89c02c2 --- /dev/null +++ b/admin/survey/classes/htmlpurifier-4.3.0/library/HTMLPurifier/Injector/PurifierLinkify.php @@ -0,0 +1,45 @@ +<?php
+
+/**
+ * Injector that converts configuration directive syntax %Namespace.Directive
+ * to links
+ */
+class HTMLPurifier_Injector_PurifierLinkify extends HTMLPurifier_Injector
+{
+
+ public $name = 'PurifierLinkify';
+ public $docURL;
+ public $needed = array('a' => array('href'));
+
+ public function prepare($config, $context) {
+ $this->docURL = $config->get('AutoFormat.PurifierLinkify.DocURL');
+ return parent::prepare($config, $context);
+ }
+
+ public function handleText(&$token) {
+ if (!$this->allowsElement('a')) return;
+ if (strpos($token->data, '%') === false) return;
+
+ $bits = preg_split('#%([a-z0-9]+\.[a-z0-9]+)#Si', $token->data, -1, PREG_SPLIT_DELIM_CAPTURE);
+ $token = array();
+
+ // $i = index
+ // $c = count
+ // $l = is link
+ for ($i = 0, $c = count($bits), $l = false; $i < $c; $i++, $l = !$l) {
+ if (!$l) {
+ if ($bits[$i] === '') continue;
+ $token[] = new HTMLPurifier_Token_Text($bits[$i]);
+ } else {
+ $token[] = new HTMLPurifier_Token_Start('a',
+ array('href' => str_replace('%s', $bits[$i], $this->docURL)));
+ $token[] = new HTMLPurifier_Token_Text('%' . $bits[$i]);
+ $token[] = new HTMLPurifier_Token_End('a');
+ }
+ }
+
+ }
+
+}
+
+// vim: et sw=4 sts=4
|