Changeset 702 for trunk/forum/search.php


Ignore:
Timestamp:
Mar 31, 2010, 6:32:40 PM (14 years ago)
Author:
george
Message:
  • Upraveno: Aktualizace fóra.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/forum/search.php

    r400 r702  
    33*
    44* @package phpBB3
    5 * @version $Id: search.php 9040 2008-11-01 19:00:50Z naderman $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    4848$search_forum   = request_var('fid', array(0));
    4949
     50// We put login boxes for the case if search_id is egosearch or unreadposts
     51// because a guest should be able to log in even if guests search is not permitted
     52
     53// Egosearch is an author search
     54if ($search_id == 'egosearch')
     55{
     56        $author_id = $user->data['user_id'];
     57
     58        if ($user->data['user_id'] == ANONYMOUS)
     59        {
     60                login_box('', $user->lang['LOGIN_EXPLAIN_EGOSEARCH']);
     61        }
     62}
     63
     64// Search for unread posts needs user to be logged in if topics tracking for guests is disabled
     65if ($search_id == 'unreadposts' && !$config['load_anon_lastread'] && !$user->data['is_registered'])
     66{
     67        login_box('', $user->lang['LOGIN_EXPLAIN_UNREADSEARCH']);
     68}
     69
    5070// Is user able to search? Has search been disabled?
    5171if (!$auth->acl_get('u_search') || !$auth->acl_getf_global('f_search') || !$config['load_search'])
     
    85105        $id_ary = array();
    86106
    87         // egosearch is an author search
    88         if ($search_id == 'egosearch')
    89         {
    90                 $author_id = $user->data['user_id'];
    91 
    92                 if ($user->data['user_id'] == ANONYMOUS)
    93                 {
    94                         login_box('', $user->lang['LOGIN_EXPLAIN_EGOSEARCH']);
    95                 }
    96         }
    97 
    98107        // If we are looking for authors get their ids
    99108        $author_id_ary = array();
     109        $sql_author_match = '';
    100110        if ($author_id)
    101111        {
     
    114124                        FROM ' . USERS_TABLE . "
    115125                        WHERE $sql_where
    116                                 AND user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')';
     126                                AND user_type <> " . USER_IGNORE;
    117127                $result = $db->sql_query_limit($sql, 100);
    118128
     
    122132                }
    123133                $db->sql_freeresult($result);
     134
     135                $sql_where = (strpos($author, '*') !== false) ? ' post_username ' . $db->sql_like_expression(str_replace('*', $db->any_char, utf8_clean_string($author))) : " post_username = '" . $db->sql_escape(utf8_clean_string($author)) . "'";
     136
     137                $sql = 'SELECT 1 as guest_post
     138                        FROM ' . POSTS_TABLE . "
     139                        WHERE $sql_where
     140                                AND poster_id = " . ANONYMOUS;
     141                $result = $db->sql_query_limit($sql, 1);
     142                $found_guest_post = $db->sql_fetchfield('guest_post');
     143                $db->sql_freeresult($result);
     144
     145                if ($found_guest_post)
     146                {
     147                        $author_id_ary[] = ANONYMOUS;
     148                        $sql_author_match = (strpos($author, '*') !== false) ? ' ' . $db->sql_like_expression(str_replace('*', $db->any_char, utf8_clean_string($author))) : " = '" . $db->sql_escape(utf8_clean_string($author)) . "'";
     149                }
    124150
    125151                if (!sizeof($author_id_ary))
     
    156182        $not_in_fid = (sizeof($ex_fid_ary)) ? 'WHERE ' . $db->sql_in_set('f.forum_id', $ex_fid_ary, true) . " OR (f.forum_password <> '' AND fa.user_id <> " . (int) $user->data['user_id'] . ')' : "";
    157183
    158         $sql = 'SELECT f.forum_id, f.forum_name, f.parent_id, f.forum_type, f.right_id, f.forum_password, fa.user_id
     184        $sql = 'SELECT f.forum_id, f.forum_name, f.parent_id, f.forum_type, f.right_id, f.forum_password, f.forum_flags, fa.user_id
    159185                FROM ' . FORUMS_TABLE . ' f
    160186                LEFT JOIN ' . FORUMS_ACCESS_TABLE . " fa ON (fa.forum_id = f.forum_id
     
    169195        {
    170196                if ($row['forum_password'] && $row['user_id'] != $user->data['user_id'])
     197                {
     198                        $ex_fid_ary[] = (int) $row['forum_id'];
     199                        continue;
     200                }
     201
     202                // Exclude forums from active topics
     203                if (!($row['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS) && ($search_id == 'active_topics'))
    171204                {
    172205                        $ex_fid_ary[] = (int) $row['forum_id'];
     
    308341                                        $last_post_time = '';
    309342                                }
    310 
    311343
    312344                                if ($sort_key == 'a')
     
    342374                        break;
    343375
     376                        case 'unreadposts':
     377                                $l_search_title = $user->lang['SEARCH_UNREAD'];
     378                                // force sorting
     379                                $show_results = 'topics';
     380                                $sort_key = 't';
     381                                $sort_by_sql['t'] = 't.topic_last_post_time';
     382                                $sql_sort = 'ORDER BY ' . $sort_by_sql[$sort_key] . (($sort_dir == 'a') ? ' ASC' : ' DESC');
     383
     384                                $sql_where = 'AND t.topic_moved_id = 0
     385                                        ' . str_replace(array('p.', 'post_'), array('t.', 'topic_'), $m_approve_fid_sql) . '
     386                                        ' . ((sizeof($ex_fid_ary)) ? 'AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '');
     387
     388                                gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
     389                                $s_sort_key = $s_sort_dir = $u_sort_param = $s_limit_days = '';
     390
     391                                $unread_list = array();
     392                                $unread_list = get_unread_topics($user->data['user_id'], $sql_where, $sql_sort);
     393
     394                                if (!empty($unread_list))
     395                                {
     396                                        $sql = 'SELECT t.topic_id
     397                                                FROM ' . TOPICS_TABLE . ' t
     398                                                WHERE ' . $db->sql_in_set('t.topic_id', array_keys($unread_list)) . "
     399                                                $sql_sort";
     400                                        $field = 'topic_id';
     401                                }
     402                        break;
     403
    344404                        case 'newposts':
    345405                                $l_search_title = $user->lang['SEARCH_NEW'];
     
    373433                                                        ' . ((sizeof($ex_fid_ary)) ? 'AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '') . "
    374434                                                $sql_sort";
     435/*
     436                [Fix] queued replies missing from "view new posts" (Bug #42705 - Patch by Paul)
     437                - Creates temporary table, query is far from optimized
     438
     439                                        $sql = 'SELECT t.topic_id
     440                                                FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p
     441                                                WHERE p.post_time > ' . $user->data['user_lastvisit'] . '
     442                                                        AND t.topic_id = p.topic_id
     443                                                        AND t.topic_moved_id = 0
     444                                                        ' . $m_approve_fid_sql . '
     445                                                        ' . ((sizeof($ex_fid_ary)) ? 'AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '') . "
     446                                                GROUP BY t.topic_id
     447                                                $sql_sort";
     448*/
    375449                                        $field = 'topic_id';
    376450                                }
     
    396470                        while ($row = $db->sql_fetchrow($result))
    397471                        {
    398                                 $id_ary[] = $row[$field];
     472                                $id_ary[] = (int) $row[$field];
    399473                        }
    400474                        $db->sql_freeresult($result);
     
    416490        if (!empty($search->search_query))
    417491        {
    418                 $total_match_count = $search->keyword_search($show_results, $search_fields, $search_terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_id_ary, $id_ary, $start, $per_page);
     492                $total_match_count = $search->keyword_search($show_results, $search_fields, $search_terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_id_ary, $sql_author_match, $id_ary, $start, $per_page);
    419493        }
    420494        else if (sizeof($author_id_ary))
    421495        {
    422496                $firstpost_only = ($search_fields === 'firstpost' || $search_fields == 'titleonly') ? true : false;
    423                 $total_match_count = $search->author_search($show_results, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_id_ary, $id_ary, $start, $per_page);
     497                $total_match_count = $search->author_search($show_results, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_id_ary, $sql_author_match, $id_ary, $start, $per_page);
    424498        }
    425499
     
    471545
    472546        $u_hilit = urlencode(htmlspecialchars_decode(str_replace('|', ' ', $hilit)));
    473         $u_show_results = ($show_results != 'posts') ? '&amp;sr=' . $show_results : '';
     547        $u_show_results = '&amp;sr=' . $show_results;
    474548        $u_search_forum = implode('&amp;fid%5B%5D=', $search_forum);
    475549
    476550        $u_search = append_sid("{$phpbb_root_path}search.$phpEx", $u_sort_param . $u_show_results);
    477551        $u_search .= ($search_id) ? '&amp;search_id=' . $search_id : '';
    478         $u_search .= ($u_hilit) ? '&amp;keywords=' . urlencode(htmlspecialchars_decode($search->search_query)) : '';
     552        $u_search .= ($u_hilit) ? '&amp;keywords=' . urlencode(htmlspecialchars_decode($keywords)) : '';
    479553        $u_search .= ($search_terms != 'all') ? '&amp;terms=' . $search_terms : '';
    480554        $u_search .= ($topic_id) ? '&amp;t=' . $topic_id : '';
     
    582656                        while ($row = $db->sql_fetchrow($result))
    583657                        {
     658                                $row['forum_id'] = (int) $row['forum_id'];
     659                                $row['topic_id'] = (int) $row['topic_id'];
     660
    584661                                if ($row['topic_status'] == ITEM_MOVED)
    585662                                {
     
    768845                        }
    769846
    770                         $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$u_forum_id&amp;t=$result_topic_id" . (($u_hilit) ? "&amp;hilit=$u_hilit" : ''));
     847                        $view_topic_url_params = "f=$u_forum_id&amp;t=$result_topic_id" . (($u_hilit) ? "&amp;hilit=$u_hilit" : '');
     848                        $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params);
    771849
    772850                        $replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];
     
    826904                                        'S_POSTS_UNAPPROVED'    => $posts_unapproved,
    827905
    828                                         'U_LAST_POST'                   => $view_topic_url . '&amp;p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id'],
     906                                        'U_LAST_POST'                   => append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&amp;p=' . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'],
    829907                                        'U_LAST_POST_AUTHOR'    => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
    830908                                        'U_TOPIC_AUTHOR'                => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
    831                                         'U_NEWEST_POST'                 => $view_topic_url . '&amp;view=unread#unread',
     909                                        'U_NEWEST_POST'                 => append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&amp;view=unread') . '#unread',
    832910                                        'U_MCP_REPORT'                  => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&amp;mode=reports&amp;t=' . $result_topic_id, true, $user->session_id),
    833911                                        'U_MCP_QUEUE'                   => $u_mcp_queue,
     
    9301008        page_footer();
    9311009}
    932 
    9331010
    9341011// Search forum
Note: See TracChangeset for help on using the changeset viewer.