Overview
Comment:Web page: add checkInternalLinks method, fix existing pages renamed to lowercase when saving
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | stable
Files: files | file ages | folders
SHA3-256: 7d9327ff42344d0c268cec8230b4deb22933709a33588e1cd312b8a4735b13b2
User & Date: bohwaz on 2022-07-12 21:16:52
Other Links: manifest | tags
References
2022-07-19
00:28 Fixed ticket [acec72a567]: URI : manque caracteres en upper case plus 5 other changes artifact: 98e0dc1c6b user: bohwaz
Context
2022-07-12
21:17
Improve files search rendering check-in: e63b3a552f user: bohwaz tags: trunk, stable
21:16
Web page: add checkInternalLinks method, fix existing pages renamed to lowercase when saving check-in: 7d9327ff42 user: bohwaz tags: trunk, stable
21:15
Make sure to escape links check-in: 1c7f30a616 user: bohwaz tags: trunk, stable
Changes

Modified src/include/lib/Garradin/Entities/Web/Page.php from [b52cb5ff16] to [103caaaf73].

181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
			}

			$file = $this->file();

			// Or update file
			if ($file->fetch() !== $export) {
				$file->set('modified', $this->modified);
				$file->store(null, $export);
			}
		}

		$this->syncSearch();
	}

	public function syncSearch(): void







|







181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
			}

			$file = $this->file();

			// Or update file
			if ($file->fetch() !== $export) {
				$file->set('modified', $this->modified);
				$file->store(null, $export, false);
			}
		}

		$this->syncSearch();
	}

	public function syncSearch(): void
273
274
275
276
277
278
279



280


281
282
283
284
285
286
287
		$parent = $this->parent;

		if (isset($source['title']) && is_null($this->path)) {
			$source['uri'] = $source['title'];
		}

		if (isset($source['uri'])) {



			$source['uri'] = strtolower(Utils::transformTitleToURI($source['uri']));


			$source['path'] = trim($parent . '/' . $source['uri'], '/');
		}

		$uri = $source['uri'] ?? $this->uri;

		if (array_key_exists('parent', $source)) {
			if (is_array($source['parent'])) {







>
>
>
|
>
>







273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
		$parent = $this->parent;

		if (isset($source['title']) && is_null($this->path)) {
			$source['uri'] = $source['title'];
		}

		if (isset($source['uri'])) {
			$source['uri'] = Utils::transformTitleToURI($source['uri']);

			if (!$this->exists()) {
				$source['uri'] = strtolower($source['uri']);
			}

			$source['path'] = trim($parent . '/' . $source['uri'], '/');
		}

		$uri = $source['uri'] ?? $this->uri;

		if (array_key_exists('parent', $source)) {
			if (is_array($source['parent'])) {
402
403
404
405
406
407
408

































409
410
411
412
413
414
415
			}

			$out[] = $a;
		}

		return $out;
	}


































	public function export(): string
	{
		$meta = [
			'Title' => str_replace("\n", '', trim($this->title)),
			'Status' => $this->status,
			'Published' => $this->published->format('Y-m-d H:i:s'),







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







407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
			}

			$out[] = $a;
		}

		return $out;
	}

	/**
	 * Return list of internal links in page that link to non-existing pages
	 */
	public function checkInternalLinks(): array
	{
		if ($this->format == Render::FORMAT_ENCRYPTED) {
			return [];
		}

		$html = $this->render();
		preg_match_all('/<a[^>]+href=["\']([^"\']+)["\']/', $html, $match, PREG_PATTERN_ORDER);
		$errors = [];

		foreach ($match[1] as $link) {
			if (strpos($link, WWW_URL) === 0) {
				$link = substr($link, strlen(WWW_URL));
			}

			$link = trim($link, '/');

			// Link is not internal
			if (preg_match('!https?:|\w+:|/!', $link)) {
				continue;
			}

			if (!Web::getByURI($link)) {
				$errors[] = $link;
			}
		}

		return array_unique($errors);
	}

	public function export(): string
	{
		$meta = [
			'Title' => str_replace("\n", '', trim($this->title)),
			'Status' => $this->status,
			'Published' => $this->published->format('Y-m-d H:i:s'),