Visman 7 лет назад
Родитель
Сommit
50a09149a5

+ 5 - 5
app/Controllers/Routing.php

@@ -66,13 +66,13 @@ class Routing
             }
             // поиск
             if ($user->g_search == '1') {
-                $r->add('GET',  '/search[/simple/{keywords}[/{page:[1-9]\d*}]]',  'Search:view',   'Search');
-                $r->add('POST', '/search',                                        'Search:view');
+                $r->add('GET',  '/search[/simple/{keywords}[/{page:[1-9]\d*}]]', 'Search:view',   'Search');
+                $r->add('POST', '/search',                                       'Search:view');
 
-                $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/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:latest|unanswered}[/{page:[1-9]\d*}]', 'Search:action', 'SearchAction');
+                $r->add('GET', '/search/{action:(?!search)\w+}[/{page:[1-9]\d*}]', 'Search:action', 'SearchAction');
             }
             // юзеры
             if ($user->g_view_users == '1') {

+ 4 - 3
app/Models/Page.php

@@ -74,11 +74,12 @@ class Page extends Model
 
         if ($this->user->g_read_board == '1' && $this->user->g_search == '1') {
             $sub = [];
+            $sub['latest']     = [$r->link('SearchAction', ['action' => 'latest_active_topics']), 'Latest active topics', 'Find latest active topics'];
             if (! $this->user->isGuest) {
-                $sub['with-your-posts'] = [$r->link('SearchAction', ['action' => '???']), 'Topics with your posts', 'Find topics with your posts'];
+                $sub['with-your-posts'] = [$r->link('SearchAction', ['action' => 'topics_with_your_posts']), 'Topics with your posts', 'Find topics with your posts'];
             }
-            $sub['latest']     = [$r->link('SearchAction', ['action' => 'latest']), 'Latest active topics', 'Find latest active topics'];
-            $sub['unanswered'] = [$r->link('SearchAction', ['action' => 'unanswered']), 'Unanswered topics', 'Find unanswered topics'];
+            $sub['unanswered'] = [$r->link('SearchAction', ['action' => 'unanswered_topics']), 'Unanswered topics', 'Find unanswered topics'];
+
             $nav['search']     = [$r->link('Search'), 'Search', null, $sub];
         }
 

+ 16 - 9
app/Models/Pages/Search.php

@@ -392,31 +392,38 @@ class Search extends Page
         $model->page  = isset($args['page']) ? (int) $args['page'] : 1;
         $action       = $args['action'];
         $asTopicsList = true;
+        $list         = false;
+        $uid          = isset($args['uid']) ? (int) $args['uid'] : null;
         switch ($action) {
             case 'search':
                 if (1 === $model->showAs) {
                     $list = $model->actionT($action);
                 } else {
                     $list = $model->actionP($action);
-                    $asTopicsList = false;
+                    $asTopicsList  = false;
                 }
                 if ('*' === $args['author']) {
-                    $model->name  = \ForkBB\__('Search query: %s', $args['keywords']);
+                    $model->name   = \ForkBB\__('Search query: %s', $args['keywords']);
                 } else {
-                    $model->name  = \ForkBB\__('Search query: %1$s and Author: %2$s', $args['keywords'], $args['author']);
+                    $model->name   = \ForkBB\__('Search query: %1$s and Author: %2$s', $args['keywords'], $args['author']);
                 }
                 $model->linkMarker = $advanced ? 'SearchAdvanced' : 'Search';
                 $model->linkArgs   = $args;
                 break;
-            case 'latest':
-            case 'unanswered':
-                $list = $model->actionT($action);
-                $model->name       = \ForkBB\__('Quick search show_' . $action);
+            case 'topics_with_your_posts':
+                if ($this->user->isGuest) {
+                    break;
+                }
+                $uid               = $this->user->id;
+            case 'latest_active_topics':
+            case 'unanswered_topics':
+                $list              = $model->actionT($action, $uid);
+                $model->name       = \ForkBB\__('Quick search ' . $action);
                 $model->linkMarker = 'SearchAction';
                 $model->linkArgs   = ['action' => $action];
                 break;
-            default:
-                throw new InvalidArgumentException('Unknown action: ' . $action);
+#            default:
+#                throw new InvalidArgumentException('Unknown action: ' . $action);
         }
 
         if (false === $list) {

+ 13 - 3
app/Models/Search/ActionT.php

@@ -14,12 +14,13 @@ class ActionT extends Method
      * Поисковые действия по темам
      *
      * @param string $action
+     * @param int $uid
      *
      * @throws InvalidArgumentException
      *
      * @return false|array
      */
-    public function actionT($action)
+    public function actionT($action, $uid = null)
     {
         $root = $this->c->forums->get(0);
         if (! $root instanceof Forum || empty($root->descendants)) {
@@ -31,18 +32,26 @@ class ActionT extends Method
             case 'search':
                 $list = $this->model->queryIds;
                 break;
-            case 'latest':
+            case 'latest_active_topics':
                 $sql = 'SELECT t.id
                         FROM ::topics AS t
                         WHERE t.forum_id IN (?ai:forums) AND t.moved_to IS NULL
                         ORDER BY t.last_post DESC';
                 break;
-            case 'unanswered':
+            case 'unanswered_topics':
                 $sql = 'SELECT t.id
                         FROM ::topics AS t
                         WHERE t.forum_id IN (?ai:forums) AND t.moved_to IS NULL AND t.num_replies=0
                         ORDER BY t.last_post DESC';
                 break;
+            case 'topics_with_your_posts':
+                $sql = 'SELECT t.id
+                        FROM ::topics AS t
+                        INNER JOIN ::posts AS p 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
+                        GROUP BY t.id
+                        ORDER BY t.last_post DESC';
+                break;
             default:
                 throw new InvalidArgumentException('Unknown action: ' . $action);
         }
@@ -50,6 +59,7 @@ class ActionT extends Method
         if (null !== $sql) {
             $vars = [
                 ':forums' => \array_keys($root->descendants),
+                ':uid'    => $uid,
             ];
             $list = $this->c->DB->query($sql, $vars)->fetchAll(PDO::FETCH_COLUMN);
         }

+ 3 - 3
app/lang/English/search.po

@@ -102,13 +102,13 @@ msgstr "Search results"
 msgid "Quick search show_new"
 msgstr "New"
 
-msgid "Quick search show_latest"
+msgid "Quick search latest_active_topics"
 msgstr "Latest active"
 
-msgid "Quick search show_unanswered"
+msgid "Quick search unanswered_topics"
 msgstr "Unanswered"
 
-msgid "Quick search show_replies"
+msgid "Quick search topics_with_your_posts"
 msgstr "Posted"
 
 msgid "Quick search show_user_topics"

+ 3 - 3
app/lang/Russian/search.po

@@ -102,13 +102,13 @@ msgstr "Результаты поиска"
 msgid "Quick search show_new"
 msgstr "Темы с новыми сообщениями"
 
-msgid "Quick search show_latest"
+msgid "Quick search latest_active_topics"
 msgstr "Последние активные темы"
 
-msgid "Quick search show_unanswered"
+msgid "Quick search unanswered_topics"
 msgstr "Темы без ответа"
 
-msgid "Quick search show_replies"
+msgid "Quick search topics_with_your_posts"
 msgstr "Темы с вашим участием"
 
 msgid "Quick search show_user_topics"