Overview
Comment:Add HTML extension to Skriv to allow for HTML tags
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 2048ba5d16ed80d3ff08a7504c280b030298781914481def65bb0d4aaba17673
User & Date: bohwaz on 2022-03-14 17:17:39
Other Links: manifest | tags
Context
2022-03-15
23:36
Fix [c92f28b12f8b869b3b251374d22e733c85e9286e]: graphs cannot be printed as they require login check-in: 620bb5b1a9 user: bohwaz tags: trunk, stable
2022-03-14
17:17
Add HTML extension to Skriv to allow for HTML tags check-in: 2048ba5d16 user: bohwaz tags: trunk
2022-03-12
02:07
Fix PHP 8.1 error when plugin config is empty check-in: a9ac1da00e user: bohwaz tags: trunk, stable
Changes

Modified src/include/lib/Garradin/Web/Render/Skriv.php from [02e93f8ff3] to [d47507aaf3].

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16

17
18
19
20
21
22
23
24
25

26
27
28
29
30
31
32
<?php

namespace Garradin\Web\Render;

use Garradin\Entities\Files\File;

use Garradin\Plugin;
use Garradin\UserTemplate\CommonModifiers;

use KD2\SkrivLite;


use const Garradin\{ADMIN_URL, WWW_URL};

class Skriv extends AbstractRender
{
	protected $skriv;


	public function __construct(?File $file = null, ?string $user_prefix = null)
	{
		parent::__construct($file, $user_prefix);

		$this->skriv = new SkrivLite;
		$this->skriv->registerExtension('file', [$this, 'SkrivFile']);
		$this->skriv->registerExtension('fichier', [$this, 'SkrivFile']);
		$this->skriv->registerExtension('image', [$this, 'SkrivImage']);


		// Enregistrer d'autres extensions éventuellement
		Plugin::fireSignal('skriv.init', ['skriv' => $this->skriv]);
	}

	public function render(?string $content = null): string
	{










>






>









>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php

namespace Garradin\Web\Render;

use Garradin\Entities\Files\File;

use Garradin\Plugin;
use Garradin\UserTemplate\CommonModifiers;

use KD2\SkrivLite;
use KD2\Garbage2xhtml;

use const Garradin\{ADMIN_URL, WWW_URL};

class Skriv extends AbstractRender
{
	protected $skriv;
	protected $g2x;

	public function __construct(?File $file = null, ?string $user_prefix = null)
	{
		parent::__construct($file, $user_prefix);

		$this->skriv = new SkrivLite;
		$this->skriv->registerExtension('file', [$this, 'SkrivFile']);
		$this->skriv->registerExtension('fichier', [$this, 'SkrivFile']);
		$this->skriv->registerExtension('image', [$this, 'SkrivImage']);
		$this->skriv->registerExtension('html', [$this, 'SkrivHTML']);

		// Enregistrer d'autres extensions éventuellement
		Plugin::fireSignal('skriv.init', ['skriv' => $this->skriv]);
	}

	public function render(?string $content = null): string
	{
121
122
123
124
125
126
127


















128
129
130
			if ($caption) {
				$caption = sprintf('<figcaption>%s</figcaption>', htmlspecialchars($caption));
			}

			$out = sprintf('<figure class="image img-%s">%s%s</figure>', $align, $out, $caption);
		}



















		return $out;
	}
}







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
			if ($caption) {
				$caption = sprintf('<figcaption>%s</figcaption>', htmlspecialchars($caption));
			}

			$out = sprintf('<figure class="image img-%s">%s%s</figure>', $align, $out, $caption);
		}

		return $out;
	}

	/**
	 * Callback utilisé pour l'extension <<html>>: permet d'insérer du code HTML protégé contre le XSS
	 * (enfin, au max de ce qui est possible…)
	 */
	public function SkrivHTML(array $args, ?string $content, SkrivLite $skriv): string
	{
		if (null == $this->g2x) {
			$this->g2x = new Garbage2xhtml;
			$this->g2x->secure = true;
			$this->g2x->enclose_text = false;
			$this->g2x->auto_br = false;
		}

		$out = $this->g2x->process($content);

		return $out;
	}
}

Modified src/include/lib/dependencies.list from [e9b8ffa0d9] to [b7af745ab8].

1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
KD2/data/
KD2/DB/AbstractEntity.php
KD2/DB/DB.php
KD2/DB/EntityManager.php
KD2/DB/SQLite3.php
KD2/Brindille.php
KD2/ErrorManager.php
KD2/FileInfo.php
KD2/Form.php
KD2/FossilInstaller.php
KD2/HTTP.php

KD2/Graphics/Image.php
KD2/Graphics/QRCode.php
KD2/Graphics/SVG/Pie.php
KD2/Graphics/SVG/Plot.php
KD2/Graphics/SVG/Bar.php
KD2/Office/Calc/Writer.php
KD2/Security.php











>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
KD2/data/
KD2/DB/AbstractEntity.php
KD2/DB/DB.php
KD2/DB/EntityManager.php
KD2/DB/SQLite3.php
KD2/Brindille.php
KD2/ErrorManager.php
KD2/FileInfo.php
KD2/Form.php
KD2/FossilInstaller.php
KD2/HTTP.php
KD2/Garbage2xhtml.php
KD2/Graphics/Image.php
KD2/Graphics/QRCode.php
KD2/Graphics/SVG/Pie.php
KD2/Graphics/SVG/Plot.php
KD2/Graphics/SVG/Bar.php
KD2/Office/Calc/Writer.php
KD2/Security.php