source: temp/test-xoops.ec-cube.net/html/modules/newbb/search.php @ 405

Revision 405, 7.9 KB checked in by root, 20 years ago (diff)
Line 
1<?php
2// $Id: search.php,v 1.3 2005/09/04 20:46:10 onokazu Exp $
3//  ------------------------------------------------------------------------ //
4//                XOOPS - PHP Content Management System                      //
5//                    Copyright (c) 2000 XOOPS.org                           //
6//                       <http://www.xoops.org/>                             //
7//  ------------------------------------------------------------------------ //
8//  This program is free software; you can redistribute it and/or modify     //
9//  it under the terms of the GNU General Public License as published by     //
10//  the Free Software Foundation; either version 2 of the License, or        //
11//  (at your option) any later version.                                      //
12//                                                                           //
13//  You may not change or alter any portion of this comment or credits       //
14//  of supporting developers from this source code or any supporting         //
15//  source code which is considered copyrighted (c) material of the          //
16//  original comment or credit authors.                                      //
17//                                                                           //
18//  This program is distributed in the hope that it will be useful,          //
19//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
20//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
21//  GNU General Public License for more details.                             //
22//                                                                           //
23//  You should have received a copy of the GNU General Public License        //
24//  along with this program; if not, write to the Free Software              //
25//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
26//  ------------------------------------------------------------------------ //
27// Author: Kazumi Ono (AKA onokazu)                                          //
28// URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //
29// Project: The XOOPS Project                                                //
30// ------------------------------------------------------------------------- //
31
32include 'header.php';
33
34if ( !isset($_POST['submit']) ) {
35    $xoopsOption['template_main']= 'newbb_search.html';
36    include XOOPS_ROOT_PATH.'/header.php';
37    $xoopsTpl->assign("lang_keywords", _MD_KEYWORDS);
38    $xoopsTpl->assign("lang_searchany", _MD_SEARCHANY);
39    $xoopsTpl->assign("lang_searchall", _MD_SEARCHALL);
40    $xoopsTpl->assign("lang_forumc", _MD_FORUMC);
41    $xoopsTpl->assign("lang_searchallforums", _MD_SEARCHALLFORUMS);
42    $xoopsTpl->assign("lang_sortby", _MD_SORTBY);
43    $xoopsTpl->assign("lang_date", _MD_DATE);
44    $xoopsTpl->assign("lang_topic", _MD_TOPIC);
45    $xoopsTpl->assign("lang_forum", _MD_FORUM);
46    $xoopsTpl->assign("lang_username", _MD_USERNAME);
47    $xoopsTpl->assign("lang_searchin", _MD_SEARCHIN);
48    $xoopsTpl->assign("lang_subject", _MD_SUBJECT);
49    $xoopsTpl->assign("lang_body", _MD_BODY);
50
51    $query = 'SELECT forum_name,forum_id FROM '.$xoopsDB->prefix('bb_forums').' WHERE forum_type != 1';
52    if ( !$result = $xoopsDB->query($query) ) {
53        exit("<big>"._MD_ERROROCCURED."</big><hr />"._MD_COULDNOTQUERY);
54    }
55    $select = '<select name="forum">';
56    while ( $row = $xoopsDB->fetchArray($result) ) {
57        $select .= '<option value="'.$row['forum_id'].'">'.$row['forum_name'].'</option>
58        ';
59    }
60    $select .= '</select>';
61    $xoopsTpl->assign("forum_selection_box", $select);
62
63} else {
64    $xoopsOption['template_main']= 'newbb_searchresults.html';
65    include XOOPS_ROOT_PATH."/header.php";
66    $forum = (isset($_POST['forum']) && $_POST['forum'] != 'all') ? intval($_POST['forum']) : 'all';
67    $xoopsTpl->assign("lang_keywords", _MD_KEYWORDS);
68    $xoopsTpl->assign("lang_searchany", _MD_SEARCHANY);
69    $xoopsTpl->assign("lang_searchall", _MD_SEARCHALL);
70    $addquery = '';
71    $subquery = '';
72    $query = 'SELECT u.uid,f.forum_id, p.topic_id, u.uname, p.post_time,t.topic_title,t.topic_views,t.topic_replies,f.forum_name FROM '.$xoopsDB->prefix('bb_posts').' p, '.$xoopsDB->prefix('bb_posts_text').' pt, '.$xoopsDB->prefix('users').' u, '.$xoopsDB->prefix('bb_forums').' f,'.$xoopsDB->prefix('bb_topics').' t';
73    $myts = MyTextSanitizer::getInstance();
74    if ( isset($_POST['term']) && trim($_POST['term']) != "" ) {
75        $terms = split(' ', $myts->oopsAddSlashes($_POST['term']));     // Get all the words into an array
76        if ( strlen($terms[0]) < 4 ) {
77
78        }
79        $addquery .= "(pt.post_text LIKE '%$terms[0]%'";
80        $subquery .= "(t.topic_title LIKE '%$terms[0]%'";
81        if ( $_POST['addterms'] == "any" ) {                    // AND/OR relates to the ANY or ALL on Search Page
82            $andor = 'OR';
83        } else {
84            $andor = 'AND';
85        }
86        $size = count($terms);
87        for ( $i = 1; $i < $size; $i++ ) {
88            if ( strlen($terms[$i]) < 4 ) {
89
90            }
91            $addquery .= " $andor pt.post_text LIKE '%$terms[$i]%'";
92            $subquery .= " $andor t.topic_title LIKE '%$terms[$i]%'";
93        }
94        $addquery .= ')';
95        $subquery .= ')';
96    }
97    if ($forum !='all' ) {
98        if ( isset($addquery) ) {
99            $addquery .= ' AND ';
100            $subquery .= ' AND ';
101        }
102        $forum = intval($_POST['forum']);
103        $addquery .= ' p.forum_id='.$forum;
104        $subquery .= ' p.forum_id='.$forum;
105    }
106    if ( isset($_POST['search_username']) && trim($_POST['search_username']) != "" ) {
107        $search_username = $myts->oopsAddSlashes(trim($_POST['search_username']));
108        if ( !$result = $xoopsDB->query("SELECT uid FROM ".$xoopsDB->prefix("users")." WHERE uname='$search_username'") ) {
109            redirect_header('search.php',1,_MD_ERROROCCURED);
110            exit();
111        }
112        $row = $xoopsDB->fetchArray($result);
113        if ( !$row ) {
114            redirect_header('search.php',1,_MD_USERNOEXIST);
115            exit();
116        }
117        if ( isset($addquery) ) {
118            $addquery .= " AND p.uid=".$row['uid']." AND u.uname='$search_username'";
119            $subquery .= " AND p.uid=".$row['uid']." AND u.uname='$search_username'";
120        } else {
121            $addquery .= " p.uid=".$row['uid']." AND u.uname='$search_username'";
122            $subquery .= " p.uid=".$row['uid']." AND u.uname='$search_username'";
123        }
124    }
125    if ( isset($addquery) ) {
126        switch ( $_POST['searchboth'] ) {
127        case 'both':
128            $query .= " WHERE ( ($subquery) OR ($addquery) ) AND ";
129            break;
130        case 'title':
131            $query .= " WHERE ( $subquery ) AND ";
132            break;
133        case 'text':
134        default:
135            $query .= " WHERE ( $addquery ) AND ";
136            break;
137        }
138    } else {
139        $query .= ' WHERE ';
140    }
141    $query .= ' p.post_id = pt.post_id AND p.topic_id = t.topic_id AND p.forum_id = f.forum_id AND p.uid = u.uid AND f.forum_type != 1';
142    $allowed = array("t.topic_title", "t.topic_views", "t.topic_replies", "f.forum_name", "u.uname");
143    $sortby = (!in_array($_POST['sortby'], $allowed)) ? "u.uid" : $_POST['sortby'];
144    $query .= ' ORDER BY '.$sortby;
145    if ( !$result = $xoopsDB->query($query,100,0) ) {
146        exit("<big>"._MD_ERROROCCURED."</big><hr />"._MD_COULDNOTQUERY);
147    }
148    if ( !$row = $xoopsDB->getRowsNum($result) ) {
149        $xoopsTpl->assign("lang_nomatch", _MD_NOMATCH);
150    } else {
151        while ( $row = $xoopsDB->fetchArray($result) ) {
152            $xoopsTpl->append('results', array('forum_name' => $myts->makeTboxData4Show($row['forum_name']), 'forum_id' => $row['forum_id'], 'topic_id' => $row['topic_id'], 'topic_title' => $myts->makeTboxData4Show($row['topic_title']), 'topic_replies' => $row['topic_replies'], 'topic_views' => $row['topic_views'], 'user_id' => $row['uid'], 'user_name' => $myts->makeTboxData4Show($row['uname']), 'post_time' => formatTimestamp($row['post_time'], "m")));
153        }
154    }
155}
156$xoopsTpl->assign("lang_forumindex", sprintf(_MD_FORUMINDEX,$xoopsConfig['sitename']));
157$xoopsTpl->assign("lang_search", _MD_SEARCH);
158$xoopsTpl->assign("lang_forum", _MD_FORUM);
159$xoopsTpl->assign("lang_topic", _MD_TOPIC);
160$xoopsTpl->assign("lang_author", _MD_AUTHOR);
161$xoopsTpl->assign('lang_replies', _MD_REPLIES);
162$xoopsTpl->assign('lang_views', _MD_VIEWS);
163$xoopsTpl->assign("lang_possttime", _MD_POSTTIME);
164$xoopsTpl->assign("lang_searchresults", _MD_SEARCHRESULTS);
165$xoopsTpl->assign("img_folder", $bbImage['folder_topic']);
166include XOOPS_ROOT_PATH.'/footer.php';
167?>
Note: See TracBrowser for help on using the repository browser.