Overview
Comment:Fix error display for module
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA3-256: 4383a59e9c9d20e75a98d32cf2f184e992a793952cf7cee51c91680d85610e4c
User & Date: bohwaz on 2023-03-29 20:37:02
Other Links: branch diff | manifest | tags
Context
2023-03-29
20:59
Allow editing of modules code check-in: 086c6bbd7e user: bohwaz tags: dev
20:37
Fix error display for module check-in: 4383a59e9c user: bohwaz tags: dev
17:20
Only show first image of a field in users list check-in: 9cbed54da9 user: bohwaz tags: dev
Changes

Modified src/include/lib/Garradin/UserTemplate/UserTemplate.php from [a242297143] to [c3e468eca6].

371
372
373
374
375
376
377
378


379
380
381
382
383
384
385
386
387
388
389
390




391


392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407

408
409
	}

	public function error(\Exception $e, string $message)
	{
		$header = ini_get('error_prepend_string');
		$header = preg_replace('!<if\((sent|logged|report|email|log)\)>(.*?)</if>!is', '', $header);
		echo $header;



		$path = $this->file->name ?? $this->path;
		$location = false !== strpos($path, '/web/') ? 'Dans un squelette du site web' : 'Dans le code d\'un formulaire';

		printf('<section><header><h1>%s</h1><h2>%s</h2></header>',
			$location, nl2br(htmlspecialchars($message)));

		if ($this->code || !preg_match('/Line (\d+)\s*:/i', $message, $match)) {
			return;
		}

		$line = $match[1] - 1;





		$file = file($path);


		$start = max(0, $line - 5);
		$max = min(count($file), $line + 6);

		echo '<pre><code>';

		for ($i = $start; $i < $max; $i++) {
			$code = sprintf('<b>%d</b>%s', $i + 1, htmlspecialchars($file[$i]));

			if ($i == $line) {
				$code = sprintf('<u>%s</u>', $code);
			}

			echo $code;
		}

		echo '</code></pre>';

	}
}








>
>

|










>
>
>
>
|
>
>
















>


371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
	}

	public function error(\Exception $e, string $message)
	{
		$header = ini_get('error_prepend_string');
		$header = preg_replace('!<if\((sent|logged|report|email|log)\)>(.*?)</if>!is', '', $header);
		echo $header;

		$name = strtok($this->_tpl_path, '/');

		$path = $this->file->name ?? $this->path;
		$location = sprintf('Dans le code du module "%s"', $name);

		printf('<section><header><h1>%s</h1><h2>%s</h2></header>',
			$location, nl2br(htmlspecialchars($message)));

		if ($this->code || !preg_match('/Line (\d+)\s*:/i', $message, $match)) {
			return;
		}

		$line = $match[1] - 1;

		if ($this->file) {
			$file = explode("\n", $this->file->fetch());
		}
		else {
			$file = file($path);
		}

		$start = max(0, $line - 5);
		$max = min(count($file), $line + 6);

		echo '<pre><code>';

		for ($i = $start; $i < $max; $i++) {
			$code = sprintf('<b>%d</b>%s', $i + 1, htmlspecialchars($file[$i]));

			if ($i == $line) {
				$code = sprintf('<u>%s</u>', $code);
			}

			echo $code;
		}

		echo '</code></pre>';
		exit;
	}
}