[2] | 1 | <?php |
---|
[354] | 2 | // +-----------------------------------------------------------------------+ |
---|
[2297] | 3 | // | Piwigo - a PHP based picture gallery | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
| 5 | // | Copyright(C) 2008 Piwigo Team http://piwigo.org | |
---|
| 6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
| 7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
| 8 | // +-----------------------------------------------------------------------+ |
---|
| 9 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 10 | // | it under the terms of the GNU General Public License as published by | |
---|
| 11 | // | the Free Software Foundation | |
---|
| 12 | // | | |
---|
| 13 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 16 | // | General Public License for more details. | |
---|
| 17 | // | | |
---|
| 18 | // | You should have received a copy of the GNU General Public License | |
---|
| 19 | // | along with this program; if not, write to the Free Software | |
---|
| 20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 21 | // | USA. | |
---|
| 22 | // +-----------------------------------------------------------------------+ |
---|
[2] | 23 | |
---|
[455] | 24 | //--------------------------------------------------------------------- include |
---|
[364] | 25 | define('PHPWG_ROOT_PATH','./'); |
---|
| 26 | include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); |
---|
[1072] | 27 | |
---|
| 28 | // +-----------------------------------------------------------------------+ |
---|
| 29 | // | Check Access and exit when user status is not ok | |
---|
| 30 | // +-----------------------------------------------------------------------+ |
---|
| 31 | check_status(ACCESS_GUEST); |
---|
| 32 | |
---|
[455] | 33 | //------------------------------------------------------------------ form check |
---|
| 34 | $errors = array(); |
---|
| 35 | $search = array(); |
---|
| 36 | if (isset($_POST['submit'])) |
---|
[2] | 37 | { |
---|
[634] | 38 | if (isset($_POST['search_allwords']) |
---|
| 39 | and !preg_match('/^\s*$/', $_POST['search_allwords'])) |
---|
[1059] | 40 | { |
---|
[634] | 41 | $drop_char_match = array( |
---|
| 42 | '-','^','$',';','#','&','(',')','<','>','`','\'','"','|',',','@','_', |
---|
| 43 | '?','%','~','.','[',']','{','}',':','\\','/','=','\'','!','*'); |
---|
| 44 | $drop_char_replace = array( |
---|
| 45 | ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','','',' ',' ',' ',' ','',' ', |
---|
| 46 | ' ',' ',' ',' ',' ',' ',' ',' ','' ,' ',' ',' ',' ',' '); |
---|
[1059] | 47 | |
---|
[634] | 48 | // Split words |
---|
[1008] | 49 | $search['fields']['allwords'] = array( |
---|
| 50 | 'words' => array_unique( |
---|
| 51 | preg_split( |
---|
| 52 | '/\s+/', |
---|
| 53 | str_replace( |
---|
| 54 | $drop_char_match, |
---|
| 55 | $drop_char_replace, |
---|
| 56 | $_POST['search_allwords'] |
---|
| 57 | ) |
---|
| 58 | ) |
---|
| 59 | ), |
---|
| 60 | 'mode' => $_POST['mode'], |
---|
| 61 | ); |
---|
[455] | 62 | } |
---|
[1059] | 63 | |
---|
[1119] | 64 | if (isset($_POST['tags'])) |
---|
| 65 | { |
---|
| 66 | $search['fields']['tags'] = array( |
---|
| 67 | 'words' => $_POST['tags'], |
---|
| 68 | 'mode' => $_POST['tag_mode'], |
---|
| 69 | ); |
---|
| 70 | } |
---|
[1125] | 71 | |
---|
[621] | 72 | if ($_POST['search_author']) |
---|
[455] | 73 | { |
---|
[1008] | 74 | $search['fields']['author'] = array( |
---|
[1015] | 75 | 'words' => preg_split( |
---|
| 76 | '/\s+/', |
---|
| 77 | $_POST['search_author'] |
---|
| 78 | ), |
---|
| 79 | 'mode' => 'OR', |
---|
[1008] | 80 | ); |
---|
[17] | 81 | } |
---|
[1059] | 82 | |
---|
[621] | 83 | if (isset($_POST['cat'])) |
---|
[2] | 84 | { |
---|
[1008] | 85 | $search['fields']['cat'] = array( |
---|
| 86 | 'words' => $_POST['cat'], |
---|
| 87 | 'sub_inc' => ($_POST['subcats-included'] == 1) ? true : false, |
---|
| 88 | ); |
---|
[2] | 89 | } |
---|
[634] | 90 | |
---|
| 91 | // dates |
---|
| 92 | $type_date = $_POST['date_type']; |
---|
[1059] | 93 | |
---|
[621] | 94 | if (!empty($_POST['start_year'])) |
---|
[634] | 95 | { |
---|
[1008] | 96 | $search['fields'][$type_date.'-after'] = array( |
---|
| 97 | 'date' => join( |
---|
| 98 | '-', |
---|
| 99 | array( |
---|
| 100 | $_POST['start_year'], |
---|
| 101 | $_POST['start_month'] != 0 ? $_POST['start_month'] : '01', |
---|
| 102 | $_POST['start_day'] != 0 ? $_POST['start_day'] : '01', |
---|
| 103 | ) |
---|
| 104 | ), |
---|
| 105 | 'inc' => true, |
---|
| 106 | ); |
---|
[634] | 107 | } |
---|
[621] | 108 | |
---|
[634] | 109 | if (!empty($_POST['end_year'])) |
---|
[621] | 110 | { |
---|
[1008] | 111 | $search['fields'][$type_date.'-before'] = array( |
---|
| 112 | 'date' => join( |
---|
| 113 | '-', |
---|
| 114 | array( |
---|
| 115 | $_POST['end_year'], |
---|
| 116 | $_POST['end_month'] != 0 ? $_POST['end_month'] : '12', |
---|
| 117 | $_POST['end_day'] != 0 ? $_POST['end_day'] : '31', |
---|
| 118 | ) |
---|
| 119 | ), |
---|
| 120 | 'inc' => true, |
---|
| 121 | ); |
---|
[621] | 122 | } |
---|
[1059] | 123 | |
---|
[621] | 124 | if (!empty($search)) |
---|
| 125 | { |
---|
[1008] | 126 | // default search mode : each clause must be respected |
---|
| 127 | $search['mode'] = 'AND'; |
---|
| 128 | |
---|
| 129 | // register search rules in database, then they will be available on |
---|
| 130 | // thumbnails page and picture page. |
---|
| 131 | $query =' |
---|
| 132 | INSERT INTO '.SEARCH_TABLE.' |
---|
[1816] | 133 | (rules, last_seen) |
---|
[1008] | 134 | VALUES |
---|
[1816] | 135 | (\''.serialize($search).'\', NOW()) |
---|
[1008] | 136 | ;'; |
---|
| 137 | pwg_query($query); |
---|
| 138 | |
---|
| 139 | $search_id = mysql_insert_id(); |
---|
[455] | 140 | } |
---|
[621] | 141 | else |
---|
[455] | 142 | { |
---|
[2014] | 143 | array_push($errors, l10n('search_one_clause_at_least')); |
---|
[455] | 144 | } |
---|
[2] | 145 | } |
---|
[455] | 146 | //----------------------------------------------------------------- redirection |
---|
| 147 | if (isset($_POST['submit']) and count($errors) == 0) |
---|
| 148 | { |
---|
[1082] | 149 | redirect( |
---|
| 150 | make_index_url( |
---|
| 151 | array( |
---|
| 152 | 'section' => 'search', |
---|
| 153 | 'search' => $search_id, |
---|
| 154 | ) |
---|
| 155 | ) |
---|
| 156 | ); |
---|
[455] | 157 | } |
---|
[2] | 158 | //----------------------------------------------------- template initialization |
---|
[621] | 159 | |
---|
[345] | 160 | // |
---|
| 161 | // Start output of page |
---|
| 162 | // |
---|
[2014] | 163 | $title= l10n('search_title'); |
---|
[850] | 164 | $page['body_id'] = 'theSearchPage'; |
---|
[345] | 165 | |
---|
[2223] | 166 | $template->set_filename('search' ,'search.tpl' ); |
---|
[1125] | 167 | |
---|
[2223] | 168 | $month_list = $lang['month']; |
---|
| 169 | $month_list[0]='------------'; |
---|
| 170 | ksort($month_list); |
---|
| 171 | |
---|
| 172 | $template->assign( |
---|
[1314] | 173 | array( |
---|
[2223] | 174 | 'F_SEARCH_ACTION' => 'search.php', |
---|
[1314] | 175 | 'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=search', |
---|
[2324] | 176 | |
---|
[2223] | 177 | 'month_list' => $month_list, |
---|
| 178 | 'START_DAY_SELECTED' => @$_POST['start_day'], |
---|
| 179 | 'START_MONTH_SELECTED' => @$_POST['start_month'], |
---|
| 180 | 'END_DAY_SELECTED' => @$_POST['end_day'], |
---|
| 181 | 'END_MONTH_SELECTED' => @$_POST['end_month'], |
---|
[1314] | 182 | ) |
---|
| 183 | ); |
---|
| 184 | |
---|
[1677] | 185 | $available_tags = get_available_tags(); |
---|
[1125] | 186 | |
---|
[1314] | 187 | if (count($available_tags) > 0) |
---|
| 188 | { |
---|
[2409] | 189 | usort( $available_tags, 'tag_alpha_compare'); |
---|
[1119] | 190 | |
---|
[2223] | 191 | $template->assign( |
---|
| 192 | 'TAG_SELECTION', |
---|
| 193 | get_html_tag_selection( |
---|
[1314] | 194 | $available_tags, |
---|
| 195 | 'tags', |
---|
| 196 | isset($_POST['tags']) ? $_POST['tags'] : array() |
---|
[2223] | 197 | ) |
---|
[1314] | 198 | ); |
---|
| 199 | } |
---|
[355] | 200 | |
---|
[455] | 201 | //------------------------------------------------------------- categories form |
---|
[614] | 202 | $query = ' |
---|
[2324] | 203 | SELECT id,name,global_rank,uppercats |
---|
[1677] | 204 | FROM '.CATEGORIES_TABLE.' |
---|
| 205 | '.get_sql_condition_FandF |
---|
| 206 | ( |
---|
| 207 | array |
---|
| 208 | ( |
---|
| 209 | 'forbidden_categories' => 'id', |
---|
| 210 | 'visible_categories' => 'id' |
---|
| 211 | ), |
---|
| 212 | 'WHERE' |
---|
| 213 | ).' |
---|
[614] | 214 | ;'; |
---|
[2223] | 215 | display_select_cat_wrapper($query, array(), 'category_options', false); |
---|
[621] | 216 | |
---|
[2] | 217 | //-------------------------------------------------------------- errors display |
---|
[455] | 218 | if (sizeof($errors) != 0) |
---|
[2] | 219 | { |
---|
[2223] | 220 | $template->assign('errors', $errors); |
---|
[2] | 221 | } |
---|
| 222 | //------------------------------------------------------------ log informations |
---|
[1627] | 223 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
[2223] | 224 | $template->pparse('search'); |
---|
[369] | 225 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
[362] | 226 | ?> |
---|