dbXapp 2.0
RAD, CMS, Module und Runtime-IDE fuer dbXapp
Loading...
Searching...
No Matches
dbxContent_permalink.class.php
Go to the documentation of this file.
1<?php
2namespace dbx\dbxContent;
3
5
6 public static function segment($text, $fallback = 'seite') {
7 $text = trim((string)$text);
8 $text = str_replace(array('\\', '/'), '-', $text);
9 $text = strtolower($text);
10 $text = str_replace(array('ä', 'ö', 'ü', 'ß'), array('ae', 'oe', 'ue', 'ss'), $text);
11 $text = preg_replace('/\s+/', '-', $text);
12 $text = preg_replace('/[^a-z0-9._\-|]+/', '-', $text);
13 $text = preg_replace('/-+/', '-', $text);
14 $text = trim($text, '-');
15
16 return $text !== '' ? $text : $fallback;
17 }
18
19 public static function slug($text) {
20 return self::segment($text, 'seite-' . date('YmdHis'));
21 }
22
23 public static function normalize($permalink) {
24 $permalink = trim((string)$permalink);
25 $permalink = str_replace('\\', '/', $permalink);
26 $permalink = preg_replace('/\s+/', '-', $permalink);
27 $permalink = preg_replace('#/+#', '/', $permalink);
28 return trim($permalink, '/');
29 }
30
31 public static function build($db, $folder_dd, $folder_id, $title) {
32 $segments = self::folder_segments($db, $folder_dd, (int)$folder_id);
33 $segments[] = self::slug($title);
34 $permalink = implode('/', array_filter($segments, static function($segment) {
35 return trim((string)$segment) !== '';
36 }));
37
38 return substr($permalink, 0, 254);
39 }
40
41 private static function folder_segments($db, $folder_dd, $folder_id) {
42 $folder_id = (int)$folder_id;
43 if ($folder_id <= 0) {
44 return array();
45 }
46
47 $row = $db->select1($folder_dd, $folder_id);
48 if (!is_array($row)) {
49 return array();
50 }
51
52 return array(self::segment($row['name'] ?? '', 'folder-' . $folder_id));
53 }
54}
55
56?>