[2] | 1 | <?php |
---|
[354] | 2 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 3 | // | Piwigo - a PHP based photo gallery | |
---|
[2297] | 4 | // +-----------------------------------------------------------------------+ |
---|
[26461] | 5 | // | Copyright(C) 2008-2014 Piwigo Team http://piwigo.org | |
---|
[2297] | 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 | |
---|
[28587] | 33 | trigger_notify('loc_begin_search'); |
---|
[18063] | 34 | |
---|
[455] | 35 | //------------------------------------------------------------------ form check |
---|
| 36 | $search = array(); |
---|
| 37 | if (isset($_POST['submit'])) |
---|
[2] | 38 | { |
---|
[4753] | 39 | foreach ($_POST as $post_key => $post_value) |
---|
| 40 | { |
---|
| 41 | if (!is_array($post_value)) |
---|
| 42 | { |
---|
[6518] | 43 | $_POST[$post_key] = pwg_db_real_escape_string($post_value); |
---|
[4753] | 44 | } |
---|
| 45 | } |
---|
| 46 | |
---|
[634] | 47 | if (isset($_POST['search_allwords']) |
---|
| 48 | and !preg_match('/^\s*$/', $_POST['search_allwords'])) |
---|
[1059] | 49 | { |
---|
[26825] | 50 | check_input_parameter('mode', $_POST, false, '/^(OR|AND)$/'); |
---|
| 51 | |
---|
[634] | 52 | $drop_char_match = array( |
---|
| 53 | '-','^','$',';','#','&','(',')','<','>','`','\'','"','|',',','@','_', |
---|
| 54 | '?','%','~','.','[',']','{','}',':','\\','/','=','\'','!','*'); |
---|
| 55 | $drop_char_replace = array( |
---|
| 56 | ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','','',' ',' ',' ',' ','',' ', |
---|
| 57 | ' ',' ',' ',' ',' ',' ',' ',' ','' ,' ',' ',' ',' ',' '); |
---|
[1059] | 58 | |
---|
[634] | 59 | // Split words |
---|
[1008] | 60 | $search['fields']['allwords'] = array( |
---|
| 61 | 'words' => array_unique( |
---|
| 62 | preg_split( |
---|
| 63 | '/\s+/', |
---|
| 64 | str_replace( |
---|
| 65 | $drop_char_match, |
---|
| 66 | $drop_char_replace, |
---|
| 67 | $_POST['search_allwords'] |
---|
| 68 | ) |
---|
| 69 | ) |
---|
| 70 | ), |
---|
| 71 | 'mode' => $_POST['mode'], |
---|
| 72 | ); |
---|
[455] | 73 | } |
---|
[1059] | 74 | |
---|
[1119] | 75 | if (isset($_POST['tags'])) |
---|
| 76 | { |
---|
[5195] | 77 | check_input_parameter('tags', $_POST, true, PATTERN_ID); |
---|
[26825] | 78 | check_input_parameter('tag_mode', $_POST, false, '/^(OR|AND)$/'); |
---|
[4753] | 79 | |
---|
[1119] | 80 | $search['fields']['tags'] = array( |
---|
| 81 | 'words' => $_POST['tags'], |
---|
| 82 | 'mode' => $_POST['tag_mode'], |
---|
| 83 | ); |
---|
| 84 | } |
---|
[1125] | 85 | |
---|
[28707] | 86 | if (isset($_POST['authors']) and is_array($_POST['authors']) and count($_POST['authors']) > 0) |
---|
[455] | 87 | { |
---|
[28707] | 88 | $authors = array(); |
---|
| 89 | |
---|
| 90 | foreach ($_POST['authors'] as $author) |
---|
| 91 | { |
---|
| 92 | $authors[] = strip_tags($author); |
---|
| 93 | } |
---|
| 94 | |
---|
[1008] | 95 | $search['fields']['author'] = array( |
---|
[28707] | 96 | 'words' => $authors, |
---|
[1015] | 97 | 'mode' => 'OR', |
---|
[1008] | 98 | ); |
---|
[17] | 99 | } |
---|
[1059] | 100 | |
---|
[621] | 101 | if (isset($_POST['cat'])) |
---|
[2] | 102 | { |
---|
[5195] | 103 | check_input_parameter('cat', $_POST, true, PATTERN_ID); |
---|
[4753] | 104 | |
---|
[1008] | 105 | $search['fields']['cat'] = array( |
---|
| 106 | 'words' => $_POST['cat'], |
---|
| 107 | 'sub_inc' => ($_POST['subcats-included'] == 1) ? true : false, |
---|
| 108 | ); |
---|
[2] | 109 | } |
---|
[634] | 110 | |
---|
| 111 | // dates |
---|
| 112 | $type_date = $_POST['date_type']; |
---|
[1059] | 113 | |
---|
[621] | 114 | if (!empty($_POST['start_year'])) |
---|
[634] | 115 | { |
---|
[1008] | 116 | $search['fields'][$type_date.'-after'] = array( |
---|
[6518] | 117 | 'date' => sprintf( |
---|
[25005] | 118 | '%d-%02d-%02d', |
---|
| 119 | $_POST['start_year'], |
---|
| 120 | $_POST['start_month'] != 0 ? $_POST['start_month'] : '01', |
---|
| 121 | $_POST['start_day'] != 0 ? $_POST['start_day'] : '01' |
---|
[1008] | 122 | ), |
---|
| 123 | 'inc' => true, |
---|
| 124 | ); |
---|
[634] | 125 | } |
---|
[621] | 126 | |
---|
[634] | 127 | if (!empty($_POST['end_year'])) |
---|
[621] | 128 | { |
---|
[1008] | 129 | $search['fields'][$type_date.'-before'] = array( |
---|
[6518] | 130 | 'date' => sprintf( |
---|
[25005] | 131 | '%d-%02d-%02d', |
---|
| 132 | $_POST['end_year'], |
---|
| 133 | $_POST['end_month'] != 0 ? $_POST['end_month'] : '12', |
---|
| 134 | $_POST['end_day'] != 0 ? $_POST['end_day'] : '31' |
---|
[6518] | 135 | ), |
---|
[1008] | 136 | 'inc' => true, |
---|
| 137 | ); |
---|
[621] | 138 | } |
---|
[1059] | 139 | |
---|
[621] | 140 | if (!empty($search)) |
---|
| 141 | { |
---|
[1008] | 142 | // default search mode : each clause must be respected |
---|
| 143 | $search['mode'] = 'AND'; |
---|
| 144 | |
---|
| 145 | // register search rules in database, then they will be available on |
---|
| 146 | // thumbnails page and picture page. |
---|
| 147 | $query =' |
---|
| 148 | INSERT INTO '.SEARCH_TABLE.' |
---|
[1816] | 149 | (rules, last_seen) |
---|
[1008] | 150 | VALUES |
---|
[1816] | 151 | (\''.serialize($search).'\', NOW()) |
---|
[1008] | 152 | ;'; |
---|
| 153 | pwg_query($query); |
---|
| 154 | |
---|
[4892] | 155 | $search_id = pwg_db_insert_id(SEARCH_TABLE); |
---|
[455] | 156 | } |
---|
[621] | 157 | else |
---|
[455] | 158 | { |
---|
[25018] | 159 | $page['errors'][] = l10n('Empty query. No criteria has been entered.'); |
---|
[455] | 160 | } |
---|
[2] | 161 | } |
---|
[455] | 162 | //----------------------------------------------------------------- redirection |
---|
[12764] | 163 | if (isset($_POST['submit']) and count($page['errors']) == 0) |
---|
[455] | 164 | { |
---|
[1082] | 165 | redirect( |
---|
| 166 | make_index_url( |
---|
| 167 | array( |
---|
| 168 | 'section' => 'search', |
---|
| 169 | 'search' => $search_id, |
---|
| 170 | ) |
---|
| 171 | ) |
---|
| 172 | ); |
---|
[455] | 173 | } |
---|
[2] | 174 | //----------------------------------------------------- template initialization |
---|
[621] | 175 | |
---|
[345] | 176 | // |
---|
| 177 | // Start output of page |
---|
| 178 | // |
---|
[5021] | 179 | $title= l10n('Search'); |
---|
[850] | 180 | $page['body_id'] = 'theSearchPage'; |
---|
[345] | 181 | |
---|
[2223] | 182 | $template->set_filename('search' ,'search.tpl' ); |
---|
[1125] | 183 | |
---|
[2223] | 184 | $month_list = $lang['month']; |
---|
| 185 | $month_list[0]='------------'; |
---|
| 186 | ksort($month_list); |
---|
| 187 | |
---|
| 188 | $template->assign( |
---|
[1314] | 189 | array( |
---|
[2223] | 190 | 'F_SEARCH_ACTION' => 'search.php', |
---|
[1314] | 191 | 'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=search', |
---|
[2324] | 192 | |
---|
[2223] | 193 | 'month_list' => $month_list, |
---|
| 194 | 'START_DAY_SELECTED' => @$_POST['start_day'], |
---|
| 195 | 'START_MONTH_SELECTED' => @$_POST['start_month'], |
---|
| 196 | 'END_DAY_SELECTED' => @$_POST['end_day'], |
---|
| 197 | 'END_MONTH_SELECTED' => @$_POST['end_month'], |
---|
[1314] | 198 | ) |
---|
| 199 | ); |
---|
| 200 | |
---|
[1677] | 201 | $available_tags = get_available_tags(); |
---|
[1125] | 202 | |
---|
[1314] | 203 | if (count($available_tags) > 0) |
---|
| 204 | { |
---|
[2409] | 205 | usort( $available_tags, 'tag_alpha_compare'); |
---|
[1119] | 206 | |
---|
[28708] | 207 | $template->assign('TAGS', $available_tags); |
---|
[1314] | 208 | } |
---|
[355] | 209 | |
---|
[28707] | 210 | // authors |
---|
| 211 | $query = ' |
---|
| 212 | SELECT |
---|
| 213 | author, |
---|
| 214 | COUNT(*) AS counter |
---|
| 215 | FROM '.IMAGES_TABLE.' AS i |
---|
| 216 | JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.image_id = i.id |
---|
| 217 | '.get_sql_condition_FandF( |
---|
| 218 | array( |
---|
| 219 | 'forbidden_categories' => 'category_id', |
---|
| 220 | 'visible_categories' => 'category_id', |
---|
| 221 | 'visible_images' => 'ic.image_id' |
---|
| 222 | ), |
---|
| 223 | ' WHERE ' |
---|
| 224 | ).' |
---|
| 225 | AND author IS NOT NULL |
---|
| 226 | GROUP BY author |
---|
| 227 | ORDER BY author |
---|
| 228 | ;'; |
---|
| 229 | $authors = query2array($query); |
---|
| 230 | |
---|
| 231 | $template->assign('AUTHORS', $authors); |
---|
| 232 | |
---|
[455] | 233 | //------------------------------------------------------------- categories form |
---|
[614] | 234 | $query = ' |
---|
[2324] | 235 | SELECT id,name,global_rank,uppercats |
---|
[1677] | 236 | FROM '.CATEGORIES_TABLE.' |
---|
| 237 | '.get_sql_condition_FandF |
---|
| 238 | ( |
---|
| 239 | array |
---|
| 240 | ( |
---|
| 241 | 'forbidden_categories' => 'id', |
---|
| 242 | 'visible_categories' => 'id' |
---|
| 243 | ), |
---|
| 244 | 'WHERE' |
---|
| 245 | ).' |
---|
[614] | 246 | ;'; |
---|
[2223] | 247 | display_select_cat_wrapper($query, array(), 'category_options', false); |
---|
[621] | 248 | |
---|
[10812] | 249 | |
---|
| 250 | // include menubar |
---|
| 251 | $themeconf = $template->get_template_vars('themeconf'); |
---|
[10824] | 252 | if (!isset($themeconf['hide_menu_on']) OR !in_array('theSearchPage', $themeconf['hide_menu_on'])) |
---|
[10812] | 253 | { |
---|
| 254 | include( PHPWG_ROOT_PATH.'include/menubar.inc.php'); |
---|
| 255 | } |
---|
| 256 | |
---|
| 257 | //------------------------------------------------------------ html code display |
---|
[1627] | 258 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
[28587] | 259 | trigger_notify('loc_end_search'); |
---|
[20609] | 260 | flush_page_messages(); |
---|
[2223] | 261 | $template->pparse('search'); |
---|
[369] | 262 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
[362] | 263 | ?> |
---|