Overview
Comment:Fix routing of default web skeletons
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA3-256: db902cea1b1e7df98bf3e35e931858872995c8ef55492736c345f2b6d0f3c11c
User & Date: bohwaz on 2023-04-11 17:48:11
Other Links: branch diff | manifest | tags
Context
2023-04-11
17:48
Handle ../ in include paths check-in: a3d5afa4eb user: bohwaz tags: dev
17:48
Fix routing of default web skeletons check-in: db902cea1b user: bohwaz tags: dev
2023-04-08
22:13
Merge with trunk check-in: 6f574eb882 user: bohwaz tags: dev
Changes

Modified src/include/lib/Garradin/UserTemplate/Modules.php from [9178ddc22e] to [6f1390aa46].

203
204
205
206
207
208
209

210
211
212
213
214
215
216
	}

	static public function route(string $uri): void
	{
		$page = null;
		$path = null;
		$has_local_file = null;


		// We are looking for a module
		if (substr($uri, 0, 2) == 'm/') {
			$path = substr($uri, 2);
			$name = strtok($path, '/');
			$path = strtok(false);
			$module = self::get($name);







>







203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
	}

	static public function route(string $uri): void
	{
		$page = null;
		$path = null;
		$has_local_file = null;
		$has_dist_file = null;

		// We are looking for a module
		if (substr($uri, 0, 2) == 'm/') {
			$path = substr($uri, 2);
			$name = strtok($path, '/');
			$path = strtok(false);
			$module = self::get($name);
242
243
244
245
246
247
248




249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272

			if ($uri == '') {
				$path = 'index.html';
			}
			elseif ($module->hasLocalFile($uri)) {
				$path = $uri;
				$has_local_file = true;




			}
			elseif (($page = Web::getByURI($uri)) && $page->status == Page::STATUS_ONLINE) {
				$path = $page->template();
				$page = $page->asTemplateArray();
			}
			else {
				$path = '404.html';
			}
		}
		// 404 if module is not enabled, except for icon
		elseif (!$module->enabled && !$module->system && $path != Module::ICON_FILE) {
			http_response_code(404);
			throw new UserException('This page is currently disabled.');
		}

		$has_local_file ??= $module->hasLocalFile($path);
		$has_dist_file = !$has_local_file && $module->hasDistFile($path);

		// Check if the file actually exists in the module
		if (!$has_local_file && !$has_dist_file) {
			http_response_code(404);
			throw new UserException('This page is not found, sorry.');
		}








>
>
>
>
















|







243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277

			if ($uri == '') {
				$path = 'index.html';
			}
			elseif ($module->hasLocalFile($uri)) {
				$path = $uri;
				$has_local_file = true;
			}
			elseif ($module->hasDistFile($uri)) {
				$path = $uri;
				$has_dist_file = true;
			}
			elseif (($page = Web::getByURI($uri)) && $page->status == Page::STATUS_ONLINE) {
				$path = $page->template();
				$page = $page->asTemplateArray();
			}
			else {
				$path = '404.html';
			}
		}
		// 404 if module is not enabled, except for icon
		elseif (!$module->enabled && !$module->system && $path != Module::ICON_FILE) {
			http_response_code(404);
			throw new UserException('This page is currently disabled.');
		}

		$has_local_file ??= $module->hasLocalFile($path);
		$has_dist_file ??= !$has_local_file && $module->hasDistFile($path);

		// Check if the file actually exists in the module
		if (!$has_local_file && !$has_dist_file) {
			http_response_code(404);
			throw new UserException('This page is not found, sorry.');
		}