diff --git a/app/Core/Func.php b/app/Core/Func.php index 762fdfe5..a40b0ad6 100644 --- a/app/Core/Func.php +++ b/app/Core/Func.php @@ -302,4 +302,27 @@ class Func return $timestamp; } } + + /** + * Преобразует строку в соотвествии с правилами FRIENDLY_URL + */ + public function friendly(string $str): string + { + $conf = $this->c->FRIENDLY_URL; + $rule = $conf['translit']; + + if (true === $conf['lowercase']) { + $rule .= 'Lower();'; + } + + if ('' !== $rule) { + $str = \transliterator_transliterate($rule, $str); + } + + if (true === $conf['WtoHyphen']) { + $str = \trim(\preg_replace(['%[^\w-]+%u', '%_+%'], ['-', '_'], $str), '-_'); + } + + return isset($str[0]) ? $str : '-'; + } } diff --git a/app/Models/Forum/Forum.php b/app/Models/Forum/Forum.php index 54438aa2..43b89f3e 100644 --- a/app/Models/Forum/Forum.php +++ b/app/Models/Forum/Forum.php @@ -129,7 +129,7 @@ class Forum extends DataModel 'Forum', [ 'id' => $this->id, - 'name' => $this->forum_name, + 'name' => $this->c->Func->friendly($this->forum_name), ] ); } @@ -261,7 +261,7 @@ class Forum extends DataModel 'User', [ 'id' => $id, - 'name' => $cur, + 'name' => $this->c->Func->friendly($cur), ] ) : null, @@ -391,7 +391,7 @@ class Forum extends DataModel 'Forum', [ 'id' => $this->id, - 'name' => $this->forum_name, + 'name' => $this->c->Func->friendly($this->forum_name), ] ); } diff --git a/app/Models/Online/Info.php b/app/Models/Online/Info.php index c7c20ce7..78464e51 100644 --- a/app/Models/Online/Info.php +++ b/app/Models/Online/Info.php @@ -37,7 +37,7 @@ class Info extends Method 'User', [ 'id' => $id, - 'name' => $name, + 'name' => $this->c->Func->friendly($name), ] ) : null, diff --git a/app/Models/Pages/Admin/Update.php b/app/Models/Pages/Admin/Update.php index 10e2bb87..72845c55 100644 --- a/app/Models/Pages/Admin/Update.php +++ b/app/Models/Pages/Admin/Update.php @@ -979,4 +979,26 @@ class Update extends Admin return null; } + + /** + * rev.70 to rev.71 + */ + protected function stageNumber70(array $args): ?int + { + $coreConfig = new CoreConfig($this->configFile); + + $coreConfig->add( + 'FRIENDLY_URL', + [ + 'lowercase' => 'false', + 'translit' => '\'\'', + 'WtoHyphen' => 'false', + ], + 'TIME_FORMATS' + ); + + $coreConfig->save(); + + return null; + } } diff --git a/app/Models/Pages/Forum.php b/app/Models/Pages/Forum.php index 09c47c87..11d88582 100644 --- a/app/Models/Pages/Forum.php +++ b/app/Models/Pages/Forum.php @@ -44,14 +44,7 @@ class Forum extends Page $this->nameTpl = 'forum'; $this->onlinePos = 'forum-' . $args['id']; - $this->canonical = $this->c->Router->link( - 'Forum', - [ - 'id' => $args['id'], - 'name' => $forum->forum_name, - 'page' => $forum->page, - ] - ); + $this->canonical = $forum->link; $this->model = $forum; $this->topics = $forum->pageData(); $this->crumbs = $this->crumbs($forum); diff --git a/app/Models/Pages/Index.php b/app/Models/Pages/Index.php index cdd3f1f6..093faba5 100644 --- a/app/Models/Pages/Index.php +++ b/app/Models/Pages/Index.php @@ -31,7 +31,7 @@ class Index extends Page 'User', [ 'id' => $this->c->stats->userLast['id'], - 'name' => $this->c->stats->userLast['username'], + 'name' => $this->c->Func->friendly($this->c->stats->userLast['username']), ] ) : null, diff --git a/app/Models/Pages/Post.php b/app/Models/Pages/Post.php index 079f3d07..8fa1437b 100644 --- a/app/Models/Pages/Post.php +++ b/app/Models/Pages/Post.php @@ -85,12 +85,7 @@ class Post extends Page } $this->nameTpl = 'post'; - $this->canonical = $this->c->Router->link( - 'NewTopic', - [ - 'id' => $forum->id, - ] - ); + $this->canonical = $forum->linkCreateTopic; $this->robots = 'noindex'; $this->formTitle = 'Post new topic'; $this->crumbs = $this->crumbs($this->formTitle, $forum); @@ -157,12 +152,7 @@ class Post extends Page } $this->nameTpl = 'post'; - $this->canonical = $this->c->Router->link( - 'NewReply', - [ - 'id' => $topic->id, - ] - ); + $this->canonical = $topic->linkReply; $this->robots = 'noindex'; $this->formTitle = 'Post a reply'; $this->crumbs = $this->crumbs($this->formTitle, $topic); diff --git a/app/Models/Pages/Topic.php b/app/Models/Pages/Topic.php index d33b072b..aa8ffddb 100644 --- a/app/Models/Pages/Topic.php +++ b/app/Models/Pages/Topic.php @@ -136,14 +136,7 @@ class Topic extends Page $this->nameTpl = 'topic'; $this->onlinePos = 'topic-' . $topic->id; $this->onlineDetail = true; - $this->canonical = $this->c->Router->link( - 'Topic', - [ - 'id' => $topic->id, - 'name' => $topic->name, - 'page' => $topic->page - ] - ); + $this->canonical = $topic->link; $this->model = $topic; $this->crumbs = $this->crumbs($topic); $this->online = $this->c->Online->calc($this)->info(); diff --git a/app/Models/Topic/Topic.php b/app/Models/Topic/Topic.php index f9440e94..d2501105 100644 --- a/app/Models/Topic/Topic.php +++ b/app/Models/Topic/Topic.php @@ -101,7 +101,7 @@ class Topic extends DataModel 'Topic', [ 'id' => $this->moved_to ?: $this->id, - 'name' => $this->name, + 'name' => $this->c->Func->friendly($this->name), ] ); } @@ -329,7 +329,7 @@ class Topic extends DataModel 'Topic', [ 'id' => $this->id, - 'name' => $this->name, + 'name' => $this->c->Func->friendly($this->name), ] ); } diff --git a/app/Models/User/User.php b/app/Models/User/User.php index dfa4aad4..d9b0e550 100644 --- a/app/Models/User/User.php +++ b/app/Models/User/User.php @@ -168,7 +168,7 @@ class User extends DataModel 'User', [ 'id' => $this->id, - 'name' => $this->username, + 'name' => $this->c->Func->friendly($this->username), ] ); } diff --git a/app/config/main.dist.php b/app/config/main.dist.php index f7673aa0..37d39343 100644 --- a/app/config/main.dist.php +++ b/app/config/main.dist.php @@ -74,6 +74,11 @@ return [ ], 'DATE_FORMATS' => ['Y-m-d', 'd M Y', 'Y-m-d', 'Y-d-m', 'd-m-Y', 'm-d-Y', 'M j Y', 'jS M Y'], 'TIME_FORMATS' => ['H:i:s', 'H:i', 'H:i:s', 'H:i', 'g:i:s a', 'g:i a'], + 'FRIENDLY_URL' => [ + 'lowercase' => true, + 'translit' => 'Russian-Latin/BGN;Any-Latin;Latin-ASCII;', + 'WtoHyphen' => true, + ], 'shared' => [ '%DIR_ROOT%' => \realpath(__DIR__ . '/../..'),