1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | search.php | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | application : PhpWebGallery <http://phpwebgallery.net> | |
---|
6 | // | branch : BSF (Best So Far) | |
---|
7 | // +-----------------------------------------------------------------------+ |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2004-03-31 20:43:09 +0000 (Wed, 31 Mar 2004) $ |
---|
10 | // | last modifier : $Author: z0rglub $ |
---|
11 | // | revision : $Revision: 405 $ |
---|
12 | // +-----------------------------------------------------------------------+ |
---|
13 | // | This program is free software; you can redistribute it and/or modify | |
---|
14 | // | it under the terms of the GNU General Public License as published by | |
---|
15 | // | the Free Software Foundation | |
---|
16 | // | | |
---|
17 | // | This program is distributed in the hope that it will be useful, but | |
---|
18 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
19 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
20 | // | General Public License for more details. | |
---|
21 | // | | |
---|
22 | // | You should have received a copy of the GNU General Public License | |
---|
23 | // | along with this program; if not, write to the Free Software | |
---|
24 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
25 | // | USA. | |
---|
26 | // +-----------------------------------------------------------------------+ |
---|
27 | |
---|
28 | //----------------------------------------------------------- include |
---|
29 | define('PHPWG_ROOT_PATH','./'); |
---|
30 | include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); |
---|
31 | //-------------------------------------------------- access authorization check |
---|
32 | check_login_authorization(); |
---|
33 | //----------------------------------------------------------------- redirection |
---|
34 | $error = array(); |
---|
35 | if ( isset( $_POST['search'] ) ) |
---|
36 | { |
---|
37 | $redirect = true; |
---|
38 | $search = array(); |
---|
39 | $words = preg_split( '/\s+/', $_POST['search'] ); |
---|
40 | foreach ( $words as $i => $word ) { |
---|
41 | if ( strlen( $word ) > 2 and !preg_match( '/[,;:\']/', $word ) ) |
---|
42 | { |
---|
43 | array_push( $search, $word ); |
---|
44 | } |
---|
45 | else |
---|
46 | { |
---|
47 | $redirect = false; |
---|
48 | array_push( $error, $lang['invalid_search'] ); |
---|
49 | break; |
---|
50 | } |
---|
51 | } |
---|
52 | $search = array_unique( $search ); |
---|
53 | $search = implode( ',', $search ); |
---|
54 | if ( $redirect ) |
---|
55 | { |
---|
56 | $url = 'category.php?cat=search&search='.$search.'&mode='.$_POST['mode']; |
---|
57 | $url = add_session_id( $url, true ); |
---|
58 | redirect( $url ); |
---|
59 | } |
---|
60 | } |
---|
61 | //----------------------------------------------------- template initialization |
---|
62 | // |
---|
63 | // Start output of page |
---|
64 | // |
---|
65 | $title= $lang['search_title']; |
---|
66 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
67 | |
---|
68 | $template->set_filenames( array('search'=>'search.tpl') ); |
---|
69 | $template->assign_vars(array( |
---|
70 | 'L_TITLE' => $lang['search_title'], |
---|
71 | 'L_COMMENTS' => $lang['search_comments'], |
---|
72 | 'L_RETURN' => $lang['search_return_main_page'], |
---|
73 | 'L_SUBMIT' => $lang['submit'], |
---|
74 | 'L_SEARCH'=>$lang['search_field_search'].' *', |
---|
75 | 'L_SEARCH_OR'=>$lang['search_mode_or'], |
---|
76 | 'L_SEARCH_AND'=>$lang['search_mode_and'], |
---|
77 | |
---|
78 | 'F_ACTION' => add_session_id( 'search.php' ), |
---|
79 | 'F_TEXT_VALUE' => isset($_POST['search'])?$_POST['search']:'', |
---|
80 | |
---|
81 | 'U_HOME' => add_session_id( 'category.php' ) |
---|
82 | ) |
---|
83 | ); |
---|
84 | |
---|
85 | //-------------------------------------------------------------- errors display |
---|
86 | if ( sizeof( $error ) != 0 ) |
---|
87 | { |
---|
88 | $template->assign_block_vars('errors',array()); |
---|
89 | for ( $i = 0; $i < sizeof( $error ); $i++ ) |
---|
90 | { |
---|
91 | $template->assign_block_vars('errors.error',array('ERROR'=>$error[$i])); |
---|
92 | } |
---|
93 | } |
---|
94 | //------------------------------------------------------------ log informations |
---|
95 | pwg_log( 'search', $title ); |
---|
96 | mysql_close(); |
---|
97 | $template->pparse('search'); |
---|
98 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
99 | ?> |
---|