From 1d9ca9814d34f45142ed8ad11107bb6577827d55 Mon Sep 17 00:00:00 2001 From: Visman Date: Thu, 12 Apr 2018 21:29:04 +0700 Subject: [PATCH] 2018-04-12 --- app/Controllers/Routing.php | 2 +- app/Models/Pages/Profile.php | 6 +++--- app/Models/Pages/Search.php | 30 +++++++++++++++++++++++++++--- app/Models/Search/ActionP.php | 12 +++++++++++- app/Models/Search/ActionT.php | 7 +++++++ app/lang/English/search.po | 4 ++-- app/lang/Russian/search.po | 4 ++-- 7 files changed, 53 insertions(+), 12 deletions(-) diff --git a/app/Controllers/Routing.php b/app/Controllers/Routing.php index 8684f2a8..6ab8c847 100644 --- a/app/Controllers/Routing.php +++ b/app/Controllers/Routing.php @@ -72,7 +72,7 @@ class Routing $r->add('GET', '/search/advanced[/{keywords}/{author}/{forums}/{serch_in:\d}/{sort_by:\d}/{sort_dir:\d}/{show_as:\d}[/{page:[1-9]\d*}]]', 'Search:viewAdvanced', 'SearchAdvanced'); $r->add('POST', '/search/advanced', 'Search:viewAdvanced'); - $r->add('GET', '/search/{action:(?!search)\w+}[/{page:[1-9]\d*}]', 'Search:action', 'SearchAction'); + $r->add('GET', '/search[/user/{uid:[2-9]|[1-9]\d+}]/{action:(?!search)\w+}[/{page:[1-9]\d*}]', 'Search:action', 'SearchAction'); } // юзеры if ($user->viewUsers) { diff --git a/app/Models/Pages/Profile.php b/app/Models/Pages/Profile.php index f40d6935..33685f6d 100644 --- a/app/Models/Pages/Profile.php +++ b/app/Models/Pages/Profile.php @@ -406,7 +406,7 @@ class Profile extends Page # $auth = $this->c->Auth; # $auth->fIswev = ['s' => [\ForkBB\__('Pass updated')]]; # return $auth->login(['_username' => $this->curUser->username], 'GET'); - return $this->c->Redirect->page('Login')->message('Pass updated'); // ???? + return $this->c->Redirect->page('Login')->message('Pass updated'); // ???? нужна передача данных между скриптами не привязанная к пользователю } else { return $this->c->Redirect->page('EditUserProfile', ['id' => $this->curUser->id])->message('Pass updated redirect'); } @@ -955,7 +955,7 @@ class Profile extends Page 'type' => 'link', 'caption' => \ForkBB\__('Posts info'), 'value' => $this->user->showPostCount ? \ForkBB\num($this->curUser->num_posts) : \ForkBB\__('Show posts'), - 'href' => '', + 'href' => $this->c->Router->link('SearchAction', ['action' => 'posts', 'uid' => $this->curUser->id]), 'title' => \ForkBB\__('Show posts'), ]; $fields['topics'] = [ @@ -964,7 +964,7 @@ class Profile extends Page 'type' => 'link', 'caption' => \ForkBB\__('Topics info'), 'value' => $this->user->showPostCount ? \ForkBB\num($this->curUser->num_topics) : \ForkBB\__('Show topics'), - 'href' => '', + 'href' => $this->c->Router->link('SearchAction', ['action' => 'topics', 'uid' => $this->curUser->id]), 'title' => \ForkBB\__('Show topics'), ]; } elseif ($this->user->showPostCount) { diff --git a/app/Models/Pages/Search.php b/app/Models/Pages/Search.php index a1b737ba..2f26b145 100644 --- a/app/Models/Pages/Search.php +++ b/app/Models/Pages/Search.php @@ -5,6 +5,7 @@ namespace ForkBB\Models\Pages; use ForkBB\Models\Page; use ForkBB\Core\Validator; use ForkBB\Models\Forum\Model as Forum; +use ForkBB\Models\User\Model as User; use InvalidArgumentException; class Search extends Page @@ -402,9 +403,9 @@ class Search extends Page switch ($action) { case 'search': if (1 === $model->showAs) { - $list = $model->actionT($action); + $list = $model->actionT($action); } else { - $list = $model->actionP($action); + $list = $model->actionP($action); $asTopicsList = false; } if ('*' === $args['author']) { @@ -419,14 +420,37 @@ class Search extends Page if ($this->user->isGuest) { break; } - $uid = $this->user->id; case 'latest_active_topics': case 'unanswered_topics': + if (isset($uid)) { + break; + } + $uid = $this->user->id; $list = $model->actionT($action, $uid); $model->name = \ForkBB\__('Quick search ' . $action); $model->linkMarker = 'SearchAction'; $model->linkArgs = ['action' => $action]; $this->fSubIndex = $subIndex[$action]; + break; + case 'posts': + $asTopicsList = false; + case 'topics': + if (! isset($uid)) { + break; + } + $user = $this->c->users->load($uid); + if (! $user instanceof User) { + break; + } + if ($asTopicsList) { + $list = $model->actionT($action, $user->id); + } else { + $list = $model->actionP($action, $user->id); + } + $model->name = \ForkBB\__('Quick search user ' . $action, $user->username); + $model->linkMarker = 'SearchAction'; + $model->linkArgs = ['action' => $action, 'uid' => $user->id]; + break; # default: # throw new InvalidArgumentException('Unknown action: ' . $action); diff --git a/app/Models/Search/ActionP.php b/app/Models/Search/ActionP.php index d3191654..4274947e 100644 --- a/app/Models/Search/ActionP.php +++ b/app/Models/Search/ActionP.php @@ -14,12 +14,13 @@ class ActionP extends Method * Поисковые действия по сообщениям * * @param string $action + * @param int $uid * * @throws InvalidArgumentException * * @return false|array */ - public function actionP($action) + public function actionP($action, $uid = null) { $root = $this->c->forums->get(0); if (! $root instanceof Forum || empty($root->descendants)) { @@ -31,6 +32,14 @@ class ActionP extends Method case 'search': $list = $this->model->queryIds; break; + case 'posts': + $sql = 'SELECT p.id + FROM ::posts AS p + INNER JOIN ::topics AS t ON t.id=p.topic_id + WHERE t.forum_id IN (?ai:forums) AND t.moved_to IS NULL AND p.poster_id=?i:uid + ORDER BY p.posted DESC'; + break; + # case 'last': # $sql = 'SELECT t.id # FROM ::topics AS t @@ -50,6 +59,7 @@ class ActionP extends Method if (null !== $sql) { $vars = [ ':forums' => array_keys($root->descendants), + ':uid' => $uid, ]; $list = $this->c->DB->query($sql, $vars)->fetchAll(PDO::FETCH_COLUMN); } diff --git a/app/Models/Search/ActionT.php b/app/Models/Search/ActionT.php index ab8d5c95..0ad7b6d6 100644 --- a/app/Models/Search/ActionT.php +++ b/app/Models/Search/ActionT.php @@ -52,6 +52,13 @@ class ActionT extends Method GROUP BY t.id ORDER BY t.last_post DESC'; break; + case 'topics': + $sql = 'SELECT t.id + FROM ::topics AS t + INNER JOIN ::posts AS p ON t.first_post_id=p.id + WHERE t.forum_id IN (?ai:forums) AND t.moved_to IS NULL AND p.poster_id=?i:uid + ORDER BY t.last_post DESC'; + break; default: throw new InvalidArgumentException('Unknown action: ' . $action); } diff --git a/app/lang/English/search.po b/app/lang/English/search.po index 7c318dad..0e6ead57 100644 --- a/app/lang/English/search.po +++ b/app/lang/English/search.po @@ -111,10 +111,10 @@ msgstr "Unanswered" msgid "Quick search topics_with_your_posts" msgstr "Posted" -msgid "Quick search show_user_topics" +msgid "Quick search user topics" msgstr "Topics by %s" -msgid "Quick search show_user_posts" +msgid "Quick search user posts" msgstr "Posts by %s" msgid "Quick search show_subscriptions" diff --git a/app/lang/Russian/search.po b/app/lang/Russian/search.po index 2a8674e8..09209a7f 100644 --- a/app/lang/Russian/search.po +++ b/app/lang/Russian/search.po @@ -111,10 +111,10 @@ msgstr "Темы без ответа" msgid "Quick search topics_with_your_posts" msgstr "Темы с вашим участием" -msgid "Quick search show_user_topics" +msgid "Quick search user topics" msgstr "Темы от %s" -msgid "Quick search show_user_posts" +msgid "Quick search user posts" msgstr "Сообщения от %s" msgid "Quick search show_subscriptions"