Overview
Comment:Allow skeletons to generate PDF
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 7b190b62335676adf592a9890f5ba67f62f02a9bf597053b44e58f07193a1429
User & Date: bohwaz on 2022-07-05 00:20:37
Other Links: manifest | tags
Context
2022-07-05
00:33
If content type is application/pdf then output a PDF file! check-in: 565e1f9100 user: bohwaz tags: trunk, stable, 1.1.27
00:20
Allow skeletons to generate PDF check-in: 7b190b6233 user: bohwaz tags: trunk
00:20
Implement logged user logic to Brindille check-in: 5fef060471 user: bohwaz tags: trunk
Changes

Modified src/include/lib/Garradin/Web/Skeleton.php from [47f3389dab] to [d48e7ab5de].

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use KD2\Brindille_Exception;
use KD2\DB\EntityManager as EM;

use const Garradin\ROOT;

class Skeleton
{
	const TEMPLATE_TYPES = '!^(?:text/(?:html|plain)|\w+/(?:\w+\+)?xml)$!';

	protected $name;
	protected $file;

	public function __construct(string $tpl)
	{
		if (!preg_match('!^[\w\d_-]+(?:\.[\w\d_-]+)*$!i', $tpl)) {







|







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use KD2\Brindille_Exception;
use KD2\DB\EntityManager as EM;

use const Garradin\ROOT;

class Skeleton
{
	const TEMPLATE_TYPES = '!^(?:text/(?:html|plain)|\w+/(?:\w+\+)?xml|application/pdf)$!';

	protected $name;
	protected $file;

	public function __construct(string $tpl)
	{
		if (!preg_match('!^[\w\d_-]+(?:\.[\w\d_-]+)*$!i', $tpl)) {
57
58
59
60
61
62
63
64
65
66
67





68

69
70
71
72
73
74
75
		if (preg_match(self::TEMPLATE_TYPES, $this->type())) {
			$ut = new UserTemplate($this->file);

			if (!$this->file) {
				$ut->setSource($this->defaultPath());
			}

			header(sprintf('Content-Type: %s;charset=utf-8', $this->type()));

			try {
				$ut->assignArray($params);





				$ut->display();

			}
			catch (Brindille_Exception $e) {
				if (!headers_sent()) {
					header('Content-Type: text/html; charset=utf-8', true);
				}

				printf('<div style="border: 5px solid orange; padding: 10px; background: yellow;"><h2>Erreur dans le squelette</h2><p>%s</p></div>', nl2br(htmlspecialchars($e->getMessage())));







|



>
>
>
>
>
|
>







57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
		if (preg_match(self::TEMPLATE_TYPES, $this->type())) {
			$ut = new UserTemplate($this->file);

			if (!$this->file) {
				$ut->setSource($this->defaultPath());
			}

			$type = $this->type();

			try {
				$ut->assignArray($params);
				if ($type == 'application/pdf') {
					$ut->displayPDF();
				}
				else {
					header(sprintf('Content-Type: %s;charset=utf-8', $type));
					$ut->display();
				}
			}
			catch (Brindille_Exception $e) {
				if (!headers_sent()) {
					header('Content-Type: text/html; charset=utf-8', true);
				}

				printf('<div style="border: 5px solid orange; padding: 10px; background: yellow;"><h2>Erreur dans le squelette</h2><p>%s</p></div>', nl2br(htmlspecialchars($e->getMessage())));
173
174
175
176
177
178
179



180
181
182
183
184
185
186
		}
		elseif ($ext == 'html') {
			return 'text/html';
		}
		elseif ($ext == 'js') {
			return 'text/javascript';
		}




		if ($this->file) {
			return $this->file->mime;
  		}

		$finfo = \finfo_open(\FILEINFO_MIME_TYPE);
		return finfo_file($finfo, $this->defaultPath());







>
>
>







179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
		}
		elseif ($ext == 'html') {
			return 'text/html';
		}
		elseif ($ext == 'js') {
			return 'text/javascript';
		}
		elseif ($ext == 'pdf') {
			return 'application/pdf';
		}

		if ($this->file) {
			return $this->file->mime;
  		}

		$finfo = \finfo_open(\FILEINFO_MIME_TYPE);
		return finfo_file($finfo, $this->defaultPath());