Overview
Comment:Implement new usertemplate.appendscript signal
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA3-256: ff2b0d0b59502fa3124c511872f4477423977e6fbd7f08ec88e71c111ca9cf0c
User & Date: bohwaz on 2022-12-12 01:56:58
Other Links: branch diff | manifest | tags
Context
2022-12-12
23:22
Update requirement to support SQLite 3.38+ check-in: 26aeef643d user: bohwaz tags: dev
01:56
Implement new usertemplate.appendscript signal check-in: ff2b0d0b59 user: bohwaz tags: dev
01:56
Allow cache to be generated if __reload query string is present check-in: cce3c21992 user: bohwaz tags: dev
Changes

Modified src/include/lib/Garradin/UserTemplate/UserTemplate.php from [2f0ed59012] to [1ac328eb86].

357
358
359
360
361
362
363










364
365
366











367
368
369
370
371
372
373
		foreach (headers_list() as $header) {
			if (preg_match('/^Content-Type: ([\w-]+\/[\w-]+)$/', $header, $match)) {
				$type = $match[1];
				break;
			}
		}











		if ($type != 'text/html' || !empty($this->_variables[0]['nocache'])) {
			$cache_as_uri = null;
		}












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

		if ($type == 'application/pdf') {
			Utils::streamPDF($content);
		}
		else {







>
>
>
>
>
>
>
>
>
>
|


>
>
>
>
>
>
>
>
>
>
>







357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
		foreach (headers_list() as $header) {
			if (preg_match('/^Content-Type: ([\w-]+\/[\w-]+)$/', $header, $match)) {
				$type = $match[1];
				break;
			}
		}

		if ($this->file && strpos($this->file->path, 'skel/web/') === 0) {
			$is_web = true;
		}
		elseif ($this->path && strpos($this->path, 'skel-dist/web') !== false) {
			$is_web = true;
		}
		else {
			$is_web = false;
		}

		if (!$is_web && $type != 'text/html' || !empty($this->_variables[0]['nocache'])) {
			$cache_as_uri = null;
		}

		if ($is_web && $type == 'text/html') {
			$scripts = [];
			Plugin::fireSignal('usertemplate.appendscript', ['template' => $this, 'content' => $content], $scripts);

			if (count($scripts)) {
				$scripts = array_map(fn($a) => sprintf('<script type="text/javascript" defer src="%s"></script>', $a), $scripts);
				$scripts = implode("\n", $scripts);
				$content = str_ireplace('</body', $scripts . '</body', $content);
			}
		}

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

		if ($type == 'application/pdf') {
			Utils::streamPDF($content);
		}
		else {