Se connecter avec
S'enregistrer | Connectez-vous

[Réglé] Requête SQL et condition "if"

Dernière réponse : dans Programmation

Bonjour,

Il s'agit de ma première présence ici...

Je travaille sur Post Control, un MOD pour phpBB offrant aux administrateurs et modérateurs la possibilité de modérer les messages avant qu'ils n'apparaissent en ligne.

Les messages non-validés n'apparaissent pas dans les résultats d'une recherche; cependant, le nombre total de messages trouvés inclus présentement les messages non-validés. Ce que je désire faire est donc de vérifier la validation du message avant d'ajouter celui-ci au nombre de résultats trouvés; s'il n'est pas validé, il faudrait sauter l'instruction word_count++ du fichier search.php (voir ligne 195 ci-dessous).

Sachant que les messages non-validés ont, à l'intérieur de la table phpbb_posts la variable validate positionnée à 1, est-ce que quelqu'un saurait m'indiquer la requête SQL à effectuer afin d'accomplir ceci?


Merci de votra aide et support! ;) 


P.S.: Voici un extrait du fichier search.php, lequel doit être modifier afin de tenir compte du nombre de messages non-validés lors de l'affichage du nombre de résultats trouvés au cours d'une recherche:
  1. //
  2. // Cycle through options ...
  3. //
  4. if ( $search_id == 'newposts' || $search_id == 'egosearch' || $search_id == 'unanswered' || $search_keywords != '' || $search_author != '' )
  5. {
  6. if ( $search_id == 'newposts' || $search_id == 'egosearch' || ( $search_author != '' && $search_keywords == '' ) )
  7. {
  8. if ( $search_id == 'newposts' )
  9. {
  10. if ( $userdata['session_logged_in'] )
  11. {
  12. $sql = "SELECT post_id
  13. FROM " . POSTS_TABLE . "
  14. WHERE post_time >= " . $userdata['user_lastvisit'];
  15. }
  16. else
  17. {
  18. redirect(append_sid("login.$phpEx?redirect=search.$phpEx&search_id=newposts", true));
  19. }
  20.  
  21. $show_results = 'topics';
  22. $sort_by = 0;
  23. $sort_dir = 'DESC';
  24. }
  25. else if ( $search_id == 'egosearch' )
  26. {
  27. if ( $userdata['session_logged_in'] )
  28. {
  29. $sql = "SELECT post_id
  30. FROM " . POSTS_TABLE . "
  31. WHERE poster_id = " . $userdata['user_id'];
  32. }
  33. else
  34. {
  35. redirect(append_sid("login.$phpEx?redirect=search.$phpEx&search_id=egosearch", true));
  36. }
  37.  
  38. $show_results = 'topics';
  39. $sort_by = 0;
  40. $sort_dir = 'DESC';
  41. }
  42. else
  43. {
  44. if (preg_match('#^[\*%]+$#', trim($search_author)) || preg_match('#^[^\*]{1,2}$#', str_replace(array('*', '%'), '', trim($search_author))))
  45. {
  46. $search_author = '';
  47. }
  48. $search_author = str_replace('*', '%', trim($search_author));
  49.  
  50. $sql = "SELECT user_id
  51. FROM " . USERS_TABLE . "
  52. WHERE username LIKE '" . str_replace("\'", "''", $search_author) . "'";
  53. if ( !($result = $db->sql_query($sql)) )
  54. {
  55. message_die(GENERAL_ERROR, "Couldn't obtain list of matching users (searching for: $search_author)", "", __LINE__, __FILE__, $sql);
  56. }
  57.  
  58. $matching_userids = '';
  59. if ( $row = $db->sql_fetchrow($result) )
  60. {
  61. do
  62. {
  63. $matching_userids .= ( ( $matching_userids != '' ) ? ', ' : '' ) . $row['user_id'];
  64. }
  65. while( $row = $db->sql_fetchrow($result) );
  66. }
  67. else
  68. {
  69. message_die(GENERAL_MESSAGE, $lang['No_search_match']);
  70. }
  71.  
  72. $sql = "SELECT post_id
  73. FROM " . POSTS_TABLE . "
  74. WHERE poster_id IN ($matching_userids)";
  75.  
  76. if ($search_time)
  77. {
  78. $sql .= " AND post_time >= " . $search_time;
  79. }
  80. }
  81.  
  82. if ( !($result = $db->sql_query($sql)) )
  83. {
  84. message_die(GENERAL_ERROR, 'Could not obtain matched posts list', '', __LINE__, __FILE__, $sql);
  85. }
  86.  
  87. $search_ids = array();
  88. while( $row = $db->sql_fetchrow($result) )
  89. {
  90. $search_ids[] = $row['post_id'];
  91. }
  92. $db->sql_freeresult($result);
  93.  
  94. $total_match_count = count($search_ids);
  95.  
  96. }
  97. else if ( $search_keywords != '' )
  98. {
  99. $stopword_array = @file($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/search_stopwords.txt');
  100. $synonym_array = @file($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/search_synonyms.txt');
  101.  
  102. $split_search = array();
  103. $split_search = ( !strstr($multibyte_charset, $lang['ENCODING']) ) ? split_words(clean_words('search', stripslashes($search_keywords), $stopword_array, $synonym_array), 'search') : split(' ', $search_keywords);
  104.  
  105. $search_msg_only = ( !$search_fields ) ? "AND m.title_match = 0" : ( ( strstr($multibyte_charset, $lang['ENCODING']) ) ? '' : '' );
  106.  
  107. $word_count = 0;
  108. $current_match_type = 'or';
  109.  
  110. $word_match = array();
  111. $result_list = array();
  112.  
  113. for($i = 0; $i < count($split_search); $i++)
  114. {
  115. if (preg_match('#^[\*%]+$#', trim($split_search[$i])) || preg_match('#^[^\*]{1,2}$#', str_replace(array('*', '%'), '', trim($split_search[$i]))))
  116. {
  117. $split_search[$i] = '';
  118. continue;
  119. }
  120. switch ( $split_search[$i] )
  121. {
  122. case 'and':
  123. $current_match_type = 'and';
  124. break;
  125.  
  126. case 'or':
  127. $current_match_type = 'or';
  128. break;
  129.  
  130. case 'not':
  131. $current_match_type = 'not';
  132. break;
  133.  
  134. default:
  135. if ( !empty($search_terms) )
  136. {
  137. $current_match_type = 'and';
  138. }
  139.  
  140. if ( !strstr($multibyte_charset, $lang['ENCODING']) )
  141. {
  142. $match_word = str_replace('*', '%', $split_search[$i]);
  143. $sql = "SELECT m.post_id
  144. FROM " . SEARCH_WORD_TABLE . " w, " . SEARCH_MATCH_TABLE . " m
  145. WHERE w.word_text LIKE '$match_word'
  146. AND m.word_id = w.word_id
  147. AND w.word_common <> 1
  148. $search_msg_only";
  149. }
  150. else
  151. {
  152. $match_word = addslashes('%' . str_replace('*', '', $split_search[$i]) . '%');
  153. $search_msg_only = ( $search_fields ) ? "OR post_subject LIKE '$match_word'" : '';
  154. $sql = "SELECT post_id
  155. FROM " . POSTS_TEXT_TABLE . "
  156. WHERE post_text LIKE '$match_word'
  157. $search_msg_only";
  158. }
  159. if ( !($result = $db->sql_query($sql)) )
  160. {
  161. message_die(GENERAL_ERROR, 'Could not obtain matched posts list', '', __LINE__, __FILE__, $sql);
  162. }
  163.  
  164. $row = array();
  165. while( $temp_row = $db->sql_fetchrow($result) )
  166. {
  167. $row[$temp_row['post_id']] = 1;
  168.  
  169. if ( !$word_count )
  170. {
  171. $result_list[$temp_row['post_id']] = 1;
  172. }
  173. else if ( $current_match_type == 'or' )
  174. {
  175. $result_list[$temp_row['post_id']] = 1;
  176. }
  177. else if ( $current_match_type == 'not' )
  178. {
  179. $result_list[$temp_row['post_id']] = 0;
  180. }
  181. }
  182.  
  183. if ( $current_match_type == 'and' && $word_count )
  184. {
  185. @reset($result_list);
  186. while( list($post_id, $match_count) = @each($result_list) )
  187. {
  188. if ( !$row[$post_id] )
  189. {
  190. $result_list[$post_id] = 0;
  191. }
  192. }
  193. }
  194.  
  195. $word_count++;
  196.  
  197. $db->sql_freeresult($result);
  198. }
  199. }
  200.  
  201. @reset($result_list);
  202.  
  203. $search_ids = array();
  204. while( list($post_id, $matches) = each($result_list) )
  205. {
  206. if ( $matches )
  207. {
  208. $search_ids[] = $post_id;
  209. }
  210. }
  211.  
  212. unset($result_list);
  213. $total_match_count = count($search_ids);
  214. }

Autres pages sur : regle requete sql condition

Lassé par la pub ? Créez un compte

Merci pour cette info!

Cependant, tu as sans doute remarqué que je ne m'y connaissais pas en php, d'où la raison de cette demande. Je ne désire que corriger un bug à l'intérieur du MOD Post Control, lequel a été abandonné par son auteur...

De ce fait, pourrais-tu spécifier à quelles requêtes exactement je dois ajouter cette ligne?

Car à l'intérieur de search.php, il y a des $SQL à n'en plus finir! ;-)


Merci beaucoup!

L'accès à l'ensemble du fichier search.php serait sans doute utile dans ce cas; le voici donc!

  1. <?php
  2. //-- mod : calendar --------------------------------------------------------------------------------
  3. /***************************************************************************
  4. * search.php
  5. * -------------------
  6. * begin : Saturday, Feb 13, 2001
  7. * copyright : (C) 2001 The phpBB Group
  8. * email : support@phpbb.com
  9. *
  10. * $Id: search.php,v 1.72.2.14 2004/07/17 13:48:32 acydburn Exp $
  11. *
  12. *
  13. ***************************************************************************/
  14.  
  15. /***************************************************************************
  16. *
  17. * This program is free software; you can redistribute it and/or modify
  18. * it under the terms of the GNU General Public License as published by
  19. * the Free Software Foundation; either version 2 of the License, or
  20. * (at your option) any later version.
  21. *
  22. ***************************************************************************/
  23.  
  24. define('IN_PHPBB', true);
  25. $phpbb_root_path = './';
  26. include($phpbb_root_path . 'extension.inc');
  27. include($phpbb_root_path . 'common.'.$phpEx);
  28. include($phpbb_root_path . 'includes/bbcode.'.$phpEx);
  29. include($phpbb_root_path . 'includes/functions_search.'.$phpEx);
  30.  
  31. //-- mod : calendar --------------------------------------------------------------------------------
  32. //-- add
  33. include_once($phpbb_root_path . 'includes/functions_calendar.'.$phpEx);
  34. //-- fin mod : calendar ----------------------------------------------------------------------------
  35.  
  36. //
  37. // Start session management
  38. //
  39. $userdata = session_pagestart($user_ip, PAGE_SEARCH);
  40. init_userprefs($userdata);
  41. //
  42. // End session management
  43. //
  44.  
  45. //
  46. // Define initial vars
  47. //
  48. if ( isset($HTTP_POST_VARS['mode']) || isset($HTTP_GET_VARS['mode']) )
  49. {
  50. $mode = ( isset($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode'];
  51. }
  52. else
  53. {
  54. $mode = '';
  55. }
  56.  
  57. if ( isset($HTTP_POST_VARS['search_keywords']) || isset($HTTP_GET_VARS['search_keywords']) )
  58. {
  59. $search_keywords = ( isset($HTTP_POST_VARS['search_keywords']) ) ? $HTTP_POST_VARS['search_keywords'] : $HTTP_GET_VARS['search_keywords'];
  60. }
  61. else
  62. {
  63. $search_keywords = '';
  64. }
  65.  
  66. if ( isset($HTTP_POST_VARS['search_author']) || isset($HTTP_GET_VARS['search_author']))
  67. {
  68. $search_author = ( isset($HTTP_POST_VARS['search_author']) ) ? $HTTP_POST_VARS['search_author'] : $HTTP_GET_VARS['search_author'];
  69. $search_author = phpbb_clean_username($search_author);
  70. }
  71. else
  72. {
  73. $search_author = '';
  74. }
  75.  
  76. $search_id = ( isset($HTTP_GET_VARS['search_id']) ) ? $HTTP_GET_VARS['search_id'] : '';
  77.  
  78. $show_results = ( isset($HTTP_POST_VARS['show_results']) ) ? $HTTP_POST_VARS['show_results'] : 'posts';
  79. $show_results = ($show_results == 'topics') ? 'topics' : 'posts';
  80.  
  81. if ( isset($HTTP_POST_VARS['search_terms']) )
  82. {
  83. $search_terms = ( $HTTP_POST_VARS['search_terms'] == 'all' ) ? 1 : 0;
  84. }
  85. else
  86. {
  87. $search_terms = 0;
  88. }
  89.  
  90. if ( isset($HTTP_POST_VARS['search_fields']) )
  91. {
  92. $search_fields = ( $HTTP_POST_VARS['search_fields'] == 'all' ) ? 1 : 0;
  93. }
  94. else
  95. {
  96. $search_fields = 0;
  97. }
  98.  
  99. $return_chars = ( isset($HTTP_POST_VARS['return_chars']) ) ? intval($HTTP_POST_VARS['return_chars']) : 200;
  100.  
  101. $search_cat = ( isset($HTTP_POST_VARS['search_cat']) ) ? intval($HTTP_POST_VARS['search_cat']) : -1;
  102. $search_forum = ( isset($HTTP_POST_VARS['search_forum']) ) ? intval($HTTP_POST_VARS['search_forum']) : -1;
  103.  
  104. $sort_by = ( isset($HTTP_POST_VARS['sort_by']) ) ? intval($HTTP_POST_VARS['sort_by']) : 0;
  105.  
  106. if ( isset($HTTP_POST_VARS['sort_dir']) )
  107. {
  108. $sort_dir = ( $HTTP_POST_VARS['sort_dir'] == 'DESC' ) ? 'DESC' : 'ASC';
  109. }
  110. else
  111. {
  112. $sort_dir = 'DESC';
  113. }
  114.  
  115. if ( !empty($HTTP_POST_VARS['search_time']) || !empty($HTTP_GET_VARS['search_time']))
  116. {
  117. $search_time = time() - ( ( ( !empty($HTTP_POST_VARS['search_time']) ) ? intval($HTTP_POST_VARS['search_time']) : intval($HTTP_GET_VARS['search_time']) ) * 86400 );
  118. $topic_days = (!empty($HTTP_POST_VARS['search_time'])) ? intval($HTTP_POST_VARS['search_time']) : intval($HTTP_GET_VARS['search_time']);
  119. }
  120. else
  121. {
  122. $search_time = 0;
  123. $topic_days = 0;
  124. }
  125.  
  126. $start = ( isset($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0;
  127.  
  128. $sort_by_types = array($lang['Sort_Time'], $lang['Sort_Post_Subject'], $lang['Sort_Topic_Title'], $lang['Sort_Author'], $lang['Sort_Forum']);
  129.  
  130. //
  131. // encoding match for workaround
  132. //
  133. $multibyte_charset = 'utf-8, big5, shift_jis, euc-kr, gb2312';
  134.  
  135. //
  136. // Begin core code
  137. //
  138. if ( $mode == 'searchuser' )
  139. {
  140. //
  141. // This handles the simple windowed user search functions called from various other scripts
  142. //
  143. if ( isset($HTTP_POST_VARS['search_username']) )
  144. {
  145. username_search($HTTP_POST_VARS['search_username']);
  146. }
  147. else
  148. {
  149. username_search('');
  150. }
  151.  
  152. exit;
  153. }
  154. else if ( $search_keywords != '' || $search_author != '' || $search_id )
  155. {
  156. $store_vars = array('search_results', 'total_match_count', 'split_search', 'sort_by', 'sort_dir', 'show_results', 'return_chars');
  157. $search_results = '';
  158.  
  159. //
  160. // Search ID Limiter, decrease this value if you experience further timeout problems with searching forums
  161. $limiter = 5000;
  162.  
  163. //
  164. // Cycle through options ...
  165. //
  166. if ( $search_id == 'newposts' || $search_id == 'egosearch' || $search_id == 'unanswered' || $search_keywords != '' || $search_author != '' )
  167. {
  168. if ( $search_id == 'newposts' || $search_id == 'egosearch' || ( $search_author != '' && $search_keywords == '' ) )
  169. {
  170. if ( $search_id == 'newposts' )
  171. {
  172. if ( $userdata['session_logged_in'] )
  173. {
  174. $sql = "SELECT post_id
  175. FROM " . POSTS_TABLE . "
  176. WHERE post_time >= " . $userdata['user_lastvisit'];
  177. }
  178. else
  179. {
  180. redirect(append_sid("login.$phpEx?redirect=search.$phpEx&search_id=newposts", true));
  181. }
  182.  
  183. $show_results = 'topics';
  184. $sort_by = 0;
  185. $sort_dir = 'DESC';
  186. }
  187. else if ( $search_id == 'egosearch' )
  188. {
  189. if ( $userdata['session_logged_in'] )
  190. {
  191. $sql = "SELECT post_id
  192. FROM " . POSTS_TABLE . "
  193. WHERE poster_id = " . $userdata['user_id'];
  194. }
  195. else
  196. {
  197. redirect(append_sid("login.$phpEx?redirect=search.$phpEx&search_id=egosearch", true));
  198. }
  199.  
  200. $show_results = 'topics';
  201. $sort_by = 0;
  202. $sort_dir = 'DESC';
  203. }
  204. else
  205. {
  206. if (preg_match('#^[\*%]+$#', trim($search_author)) || preg_match('#^[^\*]{1,2}$#', str_replace(array('*', '%'), '', trim($search_author))))
  207. {
  208. $search_author = '';
  209. }
  210. $search_author = str_replace('*', '%', trim($search_author));
  211.  
  212. $sql = "SELECT user_id
  213. FROM " . USERS_TABLE . "
  214. WHERE username LIKE '" . str_replace("\'", "''", $search_author) . "'";
  215. if ( !($result = $db->sql_query($sql)) )
  216. {
  217. message_die(GENERAL_ERROR, "Couldn't obtain list of matching users (searching for: $search_author)", "", __LINE__, __FILE__, $sql);
  218. }
  219.  
  220. $matching_userids = '';
  221. if ( $row = $db->sql_fetchrow($result) )
  222. {
  223. do
  224. {
  225. $matching_userids .= ( ( $matching_userids != '' ) ? ', ' : '' ) . $row['user_id'];
  226. }
  227. while( $row = $db->sql_fetchrow($result) );
  228. }
  229. else
  230. {
  231. message_die(GENERAL_MESSAGE, $lang['No_search_match']);
  232. }
  233.  
  234. $sql = "SELECT post_id
  235. FROM " . POSTS_TABLE . "
  236. WHERE poster_id IN ($matching_userids)";
  237.  
  238. if ($search_time)
  239. {
  240. $sql .= " AND post_time >= " . $search_time;
  241. }
  242. }
  243.  
  244. if ( !($result = $db->sql_query($sql)) )
  245. {
  246. message_die(GENERAL_ERROR, 'Could not obtain matched posts list', '', __LINE__, __FILE__, $sql);
  247. }
  248.  
  249. $search_ids = array();
  250. while( $row = $db->sql_fetchrow($result) )
  251. {
  252. $search_ids[] = $row['post_id'];
  253. }
  254. $db->sql_freeresult($result);
  255.  
  256. $total_match_count = count($search_ids);
  257.  
  258. }
  259. else if ( $search_keywords != '' )
  260. {
  261. $stopword_array = @file($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/search_stopwords.txt');
  262. $synonym_array = @file($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/search_synonyms.txt');
  263.  
  264. $split_search = array();
  265. $split_search = ( !strstr($multibyte_charset, $lang['ENCODING']) ) ? split_words(clean_words('search', stripslashes($search_keywords), $stopword_array, $synonym_array), 'search') : split(' ', $search_keywords);
  266.  
  267. $search_msg_only = ( !$search_fields ) ? "AND m.title_match = 0" : ( ( strstr($multibyte_charset, $lang['ENCODING']) ) ? '' : '' );
  268.  
  269. $word_count = 0;
  270. $current_match_type = 'or';
  271.  
  272. $word_match = array();
  273. $result_list = array();
  274.  
  275. for($i = 0; $i < count($split_search); $i++)
  276. {
  277. if (preg_match('#^[\*%]+$#', trim($split_search[$i])) || preg_match('#^[^\*]{1,2}$#', str_replace(array('*', '%'), '', trim($split_search[$i]))))
  278. {
  279. $split_search[$i] = '';
  280. continue;
  281. }
  282. switch ( $split_search[$i] )
  283. {
  284. case 'and':
  285. $current_match_type = 'and';
  286. break;
  287.  
  288. case 'or':
  289. $current_match_type = 'or';
  290. break;
  291.  
  292. case 'not':
  293. $current_match_type = 'not';
  294. break;
  295.  
  296. default:
  297. if ( !empty($search_terms) )
  298. {
  299. $current_match_type = 'and';
  300. }
  301.  
  302. if ( !strstr($multibyte_charset, $lang['ENCODING']) )
  303. {
  304. $match_word = str_replace('*', '%', $split_search[$i]);
  305. $sql = "SELECT m.post_id
  306. FROM " . SEARCH_WORD_TABLE . " w, " . SEARCH_MATCH_TABLE . " m
  307. WHERE w.word_text LIKE '$match_word'
  308. AND m.word_id = w.word_id
  309. AND w.word_common <> 1
  310. $search_msg_only";
  311. }
  312. else
  313. {
  314. $match_word = addslashes('%' . str_replace('*', '', $split_search[$i]) . '%');
  315. $search_msg_only = ( $search_fields ) ? "OR post_subject LIKE '$match_word'" : '';
  316. $sql = "SELECT post_id
  317. FROM " . POSTS_TEXT_TABLE . "
  318. WHERE post_text LIKE '$match_word'
  319. $search_msg_only";
  320. }
  321. if ( !($result = $db->sql_query($sql)) )
  322. {
  323. message_die(GENERAL_ERROR, 'Could not obtain matched posts list', '', __LINE__, __FILE__, $sql);
  324. }
  325.  
  326. $row = array();
  327. while( $temp_row = $db->sql_fetchrow($result) )
  328. {
  329. $row[$temp_row['post_id']] = 1;
  330.  
  331. if ( !$word_count )
  332. {
  333. $result_list[$temp_row['post_id']] = 1;
  334. }
  335. else if ( $current_match_type == 'or' )
  336. {
  337. $result_list[$temp_row['post_id']] = 1;
  338. }
  339. else if ( $current_match_type == 'not' )
  340. {
  341. $result_list[$temp_row['post_id']] = 0;
  342. }
  343. }
  344.  
  345. if ( $current_match_type == 'and' && $word_count )
  346. {
  347. @reset($result_list);
  348. while( list($post_id, $match_count) = @each($result_list) )
  349. {
  350. if ( !$row[$post_id] )
  351. {
  352. $result_list[$post_id] = 0;
  353. }
  354. }
  355. }
  356.  
  357. $word_count++;
  358.  
  359. $db->sql_freeresult($result);
  360. }
  361. }
  362.  
  363. @reset($result_list);
  364.  
  365. $search_ids = array();
  366. while( list($post_id, $matches) = each($result_list) )
  367. {
  368. if ( $matches )
  369. {
  370. $search_ids[] = $post_id;
  371. }
  372. }
  373.  
  374. unset($result_list);
  375. $total_match_count = count($search_ids);
  376. }
  377.  
  378. //
  379. // If user is logged in then we'll check to see which (if any) private
  380. // forums they are allowed to view and include them in the search.
  381. //
  382. // If not logged in we explicitly prevent searching of private forums
  383. //
  384. $auth_sql = '';
  385. if ( $search_forum != -1 )
  386. {
  387. $is_auth = auth(AUTH_READ, $search_forum, $userdata);
  388.  
  389. if ( !$is_auth['auth_read'] )
  390. {
  391. message_die(GENERAL_MESSAGE, $lang['No_searchable_forums']);
  392. }
  393.  
  394. $auth_sql = "f.forum_id = $search_forum";
  395. }
  396. else
  397. {
  398. $is_auth_ary = auth(AUTH_READ, AUTH_LIST_ALL, $userdata);
  399.  
  400. if ( $search_cat != -1 )
  401. {
  402. $auth_sql = "f.cat_id = $search_cat";
  403. }
  404.  
  405. $ignore_forum_sql = '';
  406. while( list($key, $value) = each($is_auth_ary) )
  407. {
  408. if ( !$value['auth_read'] )
  409. {
  410. $ignore_forum_sql .= ( ( $ignore_forum_sql != '' ) ? ', ' : '' ) . $key;
  411. }
  412. }
  413.  
  414. if ( $ignore_forum_sql != '' )
  415. {
  416. $auth_sql .= ( $auth_sql != '' ) ? " AND f.forum_id NOT IN ($ignore_forum_sql) " : "f.forum_id NOT IN ($ignore_forum_sql) ";
  417. }
  418. }
  419.  
  420. //
  421. // Author name search
  422. //
  423. if ( $search_author != '' )
  424. {
  425. if (preg_match('#^[\*%]+$#', trim($search_author)) || preg_match('#^[^\*]{1,2}$#', str_replace(array('*', '%'), '', trim($search_author))))
  426. {
  427. $search_author = '';
  428. }
  429. $search_author = str_replace('*', '%', trim(str_replace("\'", "''", $search_author)));
  430. }
  431.  
  432. if ( $total_match_count )
  433. {
  434. if ( $show_results == 'topics' )
  435. {
  436. //
  437. // This one is a beast, try to seperate it a bit (workaround for connection timeouts)
  438. //
  439. $search_id_chunks = array();
  440. $count = 0;
  441. $chunk = 0;
  442.  
  443. if (count($search_ids) > $limiter)
  444. {
  445. for ($i = 0; $i < count($search_ids); $i++)
  446. {
  447. if ($count == $limiter)
  448. {
  449. $chunk++;
  450. $count = 0;
  451. }
  452.  
  453. $search_id_chunks[$chunk][$count] = $search_ids[$i];
  454. $count++;
  455. }
  456. }
  457. else
  458. {
  459. $search_id_chunks[0] = $search_ids;
  460. }
  461.  
  462. $search_ids = array();
  463.  
  464. for ($i = 0; $i < count($search_id_chunks); $i++)
  465. {
  466. $where_sql = '';
  467.  
  468. if ( $search_time )
  469. {
  470. $where_sql .= ( $search_author == '' && $auth_sql == '' ) ? " AND post_time >= $search_time " : " AND p.post_time >= $search_time ";
  471. }
  472.  
  473. if ( $search_author == '' && $auth_sql == '' )
  474. {
  475. $sql = "SELECT topic_id
  476. FROM " . POSTS_TABLE . "
  477. WHERE post_id IN (" . implode(", ", $search_id_chunks[$i]) . ")
  478. $where_sql
  479. GROUP BY topic_id";
  480. }
  481. else
  482. {
  483. $from_sql = POSTS_TABLE . " p";
  484.  
  485. if ( $search_author != '' )
  486. {
  487. $from_sql .= ", " . USERS_TABLE . " u";
  488. $where_sql .= " AND u.user_id = p.poster_id AND u.username LIKE '$search_author' ";
  489. }
  490.  
  491. if ( $auth_sql != '' )
  492. {
  493. $from_sql .= ", " . FORUMS_TABLE . " f";
  494. $where_sql .= " AND f.forum_id = p.forum_id AND $auth_sql";
  495. }
  496.  
  497. $sql = "SELECT p.topic_id
  498. FROM $from_sql
  499. WHERE p.post_id IN (" . implode(", ", $search_id_chunks[$i]) . ")
  500. $where_sql
  501. GROUP BY p.topic_id";
  502. }
  503.  
  504. if ( !($result = $db->sql_query($sql)) )
  505. {
  506. message_die(GENERAL_ERROR, 'Could not obtain topic ids', '', __LINE__, __FILE__, $sql);
  507. }
  508.  
  509. while ($row = $db->sql_fetchrow($result))
  510. {
  511. $search_ids[] = $row['topic_id'];
  512. }
  513. $db->sql_freeresult($result);
  514. }
  515.  
  516. $total_match_count = sizeof($search_ids);
  517.  
  518. }
  519. else if ( $search_author != '' || $search_time || $auth_sql != '' )
  520. {
  521. $search_id_chunks = array();
  522. $count = 0;
  523. $chunk = 0;
  524.  
  525. if (count($search_ids) > $limiter)
  526. {
  527. for ($i = 0; $i < count($search_ids); $i++)
  528. {
  529. if ($count == $limiter)
  530. {
  531. $chunk++;
  532. $count = 0;
  533. }
  534.  
  535. $search_id_chunks[$chunk][$count] = $search_ids[$i];
  536. $count++;
  537. }
  538. }
  539. else
  540. {
  541. $search_id_chunks[0] = $search_ids;
  542. }
  543.  
  544. $search_ids = array();
  545.  
  546. for ($i = 0; $i < count($search_id_chunks); $i++)
  547. {
  548. $where_sql = ( $search_author == '' && $auth_sql == '' ) ? 'post_id IN (' . implode(', ', $search_id_chunks[$i]) . ')' : 'p.post_id IN (' . implode(', ', $search_id_chunks[$i]) . ')';
  549. $select_sql = ( $search_author == '' && $auth_sql == '' ) ? 'post_id' : 'p.post_id';
  550. $from_sql = ( $search_author == '' && $auth_sql == '' ) ? POSTS_TABLE : POSTS_TABLE . ' p';
  551.  
  552. if ( $search_time )
  553. {
  554. $where_sql .= ( $search_author == '' && $auth_sql == '' ) ? " AND post_time >= $search_time " : " AND p.post_time >= $search_time";
  555. }
  556.  
  557. if ( $auth_sql != '' )
  558. {
  559. $from_sql .= ", " . FORUMS_TABLE . " f";
  560. $where_sql .= " AND f.forum_id = p.forum_id AND $auth_sql";
  561. }
  562.  
  563. if ( $search_author != '' )
  564. {
  565. $from_sql .= ", " . USERS_TABLE . " u";
  566. $where_sql .= " AND u.user_id = p.poster_id AND u.username LIKE '$search_author'";
  567. }
  568.  
  569. $sql = "SELECT " . $select_sql . "
  570. FROM $from_sql
  571. WHERE $where_sql";
  572. if ( !($result = $db->sql_query($sql)) )
  573. {
  574. message_die(GENERAL_ERROR, 'Could not obtain post ids', '', __LINE__, __FILE__, $sql);
  575. }
  576.  
  577. while( $row = $db->sql_fetchrow($result) )
  578. {
  579. $search_ids[] = $row['post_id'];
  580. }
  581. $db->sql_freeresult($result);
  582. }
  583.  
  584. $total_match_count = count($search_ids);
  585. }
  586. }
  587. else if ( $search_id == 'unanswered' )
  588. {
  589. if ( $auth_sql != '' )
  590. {
  591. $sql = "SELECT t.topic_id, f.forum_id
  592. FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f
  593. WHERE t.topic_replies = 0
  594. AND t.forum_id = f.forum_id
  595. AND t.topic_moved_id = 0
  596. AND $auth_sql";
  597. }
  598. else
  599. {
  600. $sql = "SELECT topic_id
  601. FROM " . TOPICS_TABLE . "
  602. WHERE topic_replies = 0
  603. AND topic_moved_id = 0";
  604. }
  605.  
  606. if ( !($result = $db->sql_query($sql)) )
  607. {
  608. message_die(GENERAL_ERROR, 'Could not obtain post ids', '', __LINE__, __FILE__, $sql);
  609. }
  610.  
  611. $search_ids = array();
  612. while( $row = $db->sql_fetchrow($result) )
  613. {
  614. $search_ids[] = $row['topic_id'];
  615. }
  616. $db->sql_freeresult($result);
  617.  
  618. $total_match_count = count($search_ids);
  619.  
  620. //
  621. // Basic requirements
  622. //
  623. $show_results = 'topics';
  624. $sort_by = 0;
  625. $sort_dir = 'DESC';
  626. }
  627. else
  628. {
  629. message_die(GENERAL_MESSAGE, $lang['No_search_match']);
  630. }
  631.  
  632. //
  633. // Finish building query (for all combinations)
  634. // and run it ...
  635. //
  636. $sql = "SELECT session_id
  637. FROM " . SESSIONS_TABLE;
  638. if ( $result = $db->sql_query($sql) )
  639. {
  640. $delete_search_ids = array();
  641. while( $row = $db->sql_fetchrow($result) )
  642. {
  643. $delete_search_ids[] = "'" . $row['session_id'] . "'";
  644. }
  645.  
  646. if ( count($delete_search_ids) )
  647. {
  648. $sql = "DELETE FROM " . SEARCH_TABLE . "
  649. WHERE session_id NOT IN (" . implode(", ", $delete_search_ids) . ")";
  650. if ( !$result = $db->sql_query($sql) )
  651. {
  652. message_die(GENERAL_ERROR, 'Could not delete old search id sessions', '', __LINE__, __FILE__, $sql);
  653. }
  654. }
  655. }
  656.  
  657. //
  658. // Store new result data
  659. //
  660. $search_results = implode(', ', $search_ids);
  661. $per_page = ( $show_results == 'posts' ) ? $board_config['posts_per_page'] : $board_config['topics_per_page'];
  662.  
  663. //
  664. // Combine both results and search data (apart from original query)
  665. // so we can serialize it and place it in the DB
  666. //
  667. $store_search_data = array();
  668.  
  669. //
  670. // Limit the character length (and with this the results displayed at all following pages) to prevent
  671. // truncated result arrays. Normally, search results above 12000 are affected.
  672. // - to include or not to include
  673. /*
  674. $max_result_length = 60000;
  675. if (strlen($search_results) > $max_result_length)
  676. {
  677. $search_results = substr($search_results, 0, $max_result_length);
  678. $search_results = substr($search_results, 0, strrpos($search_results, ','));
  679. $total_match_count = count(explode(', ', $search_results));
  680. }
  681. */
  682.  
  683. for($i = 0; $i < count($store_vars); $i++)
  684. {
  685. $store_search_data[$store_vars[$i]] = $$store_vars[$i];
  686. }
  687.  
  688. $result_array = serialize($store_search_data);
  689. unset($store_search_data);
  690.  
  691. mt_srand ((double) microtime() * 1000000);
  692. $search_id = mt_rand();
  693.  
  694. $sql = "UPDATE " . SEARCH_TABLE . "
  695. SET search_id = $search_id, search_array = '" . str_replace("\'", "''", $result_array) . "'
  696. WHERE session_id = '" . $userdata['session_id'] . "'";
  697. if ( !($result = $db->sql_query($sql)) || !$db->sql_affectedrows() )
  698. {
  699. $sql = "INSERT INTO " . SEARCH_TABLE . " (search_id, session_id, search_array)
  700. VALUES($search_id, '" . $userdata['session_id'] . "', '" . str_replace("\'", "''", $result_array) . "')";
  701. if ( !($result = $db->sql_query($sql)) )
  702. {
  703. message_die(GENERAL_ERROR, 'Could not insert search results', '', __LINE__, __FILE__, $sql);
  704. }
  705. }
  706. }
  707. else
  708. {
  709. $search_id = intval($search_id);
  710. if ( $search_id )
  711. {
  712. $sql = "SELECT search_array
  713. FROM " . SEARCH_TABLE . "
  714. WHERE search_id = $search_id
  715. AND session_id = '". $userdata['session_id'] . "'";
  716. if ( !($result = $db->sql_query($sql)) )
  717. {
  718. message_die(GENERAL_ERROR, 'Could not obtain search results', '', __LINE__, __FILE__, $sql);
  719. }
  720.  
  721. if ( $row = $db->sql_fetchrow($result) )
  722. {
  723. $search_data = unserialize($row['search_array']);
  724. for($i = 0; $i < count($store_vars); $i++)
  725. {
  726. $$store_vars[$i] = $search_data[$store_vars[$i]];
  727. }
  728. }
  729. }
  730. }
  731.  
  732. //
  733. // Look up data ...
  734. //
  735. if ( $search_results != '' )
  736. {
  737. if ( $show_results == 'posts' )
  738. {
  739. $sql = "SELECT pt.post_text, pt.bbcode_uid, pt.post_subject, p.*, f.forum_id, f.forum_name, t.*, u.username, u.user_id, u.user_sig, u.user_sig_bbcode_uid
  740. FROM " . FORUMS_TABLE . " f, " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TEXT_TABLE . " pt
  741. WHERE p.post_id IN ($search_results)
  742. AND pt.post_id = p.post_id
  743. AND f.forum_id = p.forum_id
  744. AND p.topic_id = t.topic_id
  745. AND p.validate = 0
  746. AND p.poster_id = u.user_id";
  747. }
  748. else
  749. {
  750. $sql = "SELECT t.*, pt.post_text, f.forum_id, f.forum_name, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_username, p2.post_username AS post_username2, p2.post_time
  751. FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2, " . POSTS_TEXT_TABLE . " pt," . USERS_TABLE . " u2
  752. WHERE t.topic_id IN ($search_results)
  753. AND t.topic_poster = u.user_id
  754. AND f.forum_id = t.forum_id
  755. AND p.post_id = t.topic_first_post_id
  756. AND p.validate = 0
  757. AND p2.post_id = t.topic_last_post_id
  758. AND pt.post_id = p.post_id
  759. AND u2.user_id = p2.poster_id";
  760. }
  761.  
  762. $per_page = ( $show_results == 'posts' ) ? $board_config['posts_per_page'] : $board_config['topics_per_page'];
  763.  
  764. $sql .= " ORDER BY ";
  765. switch ( $sort_by )
  766. {
  767. case 1:
  768. $sql .= ( $show_results == 'posts' ) ? 'pt.post_subject' : 't.topic_title';
  769. break;
  770. case 2:
  771. $sql .= 't.topic_title';
  772. break;
  773. case 3:
  774. $sql .= 'u.username';
  775. break;
  776. case 4:
  777. $sql .= 'f.forum_id';
  778. break;
  779. default:
  780. $sql .= ( $show_results == 'posts' ) ? 'p.post_time' : 'p2.post_time';
  781. break;
  782. }
  783. $sql .= " $sort_dir LIMIT $start, " . $per_page;
  784.  
  785. if ( !$result = $db->sql_query($sql) )
  786. {
  787. message_die(GENERAL_ERROR, 'Could not obtain search results', '', __LINE__, __FILE__, $sql);
  788. }
  789.  
  790. $searchset = array();
  791. while( $row = $db->sql_fetchrow($result) )
  792. {
  793. $searchset[] = $row;
  794. }
  795.  
  796. $db->sql_freeresult($result);
  797.  
  798. //
  799. // Define censored word matches
  800. //
  801. $orig_word = array();
  802. $replacement_word = array();
  803. obtain_word_list($orig_word, $replacement_word);
  804.  
  805. //
  806. // Output header
  807. //
  808. $page_title = $lang['Search'];
  809. include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  810.  
  811. if ( $show_results == 'posts' )
  812. {
  813. $template->set_filenames(array(
  814. 'body' => 'search_results_posts.tpl')
  815. );
  816. }
  817. else
  818. {
  819. $template->set_filenames(array(
  820. 'body' => 'search_results_topics.tpl')
  821. );
  822. }
  823. make_jumpbox('viewforum.'.$phpEx);
  824.  
  825. $l_search_matches = ( $total_match_count == 1 ) ? sprintf($lang['Found_search_match'], $total_match_count) : sprintf($lang['Found_search_matches'], $total_match_count);
  826.  
  827. $template->assign_vars(array(
  828. 'L_SEARCH_MATCHES' => $l_search_matches,
  829. 'L_TOPIC' => $lang['Topic'])
  830. );
  831.  
  832. $highlight_active = '';
  833. $highlight_match = array();
  834. for($j = 0; $j < count($split_search); $j++ )
  835. {
  836. $split_word = $split_search[$j];
  837.  
  838. if ( $split_word != 'and' && $split_word != 'or' && $split_word != 'not' )
  839. {
  840. $highlight_match[] = '#\b(' . str_replace("*", "([\w]+)?", $split_word) . ')\b#is';
  841. $highlight_active .= " " . $split_word;
  842.  
  843. for ($k = 0; $k < count($synonym_array); $k++)
  844. {
  845. list($replace_synonym, $match_synonym) = split(' ', trim(strtolower($synonym_array[$k])));
  846.  
  847. if ( $replace_synonym == $split_word )
  848. {
  849. $highlight_match[] = '#\b(' . str_replace("*", "([\w]+)?", $replace_synonym) . ')\b#is';
  850. $highlight_active .= ' ' . $match_synonym;
  851. }
  852. }
  853. }
  854. }
  855.  
  856. $highlight_active = urlencode(trim($highlight_active));
  857.  
  858. $tracking_topics = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) : array();
  859. $tracking_forums = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) : array();
  860.  
  861. for($i = 0; $i < count($searchset); $i++)
  862. {
  863. $forum_url = append_sid("viewforum.$phpEx?" . POST_FORUM_URL . '=' . $searchset[$i]['forum_id']);
  864. $topic_url = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . '=' . $searchset[$i]['topic_id'] . "&highlight=$highlight_active");
  865. $post_url = append_sid("viewtopic.$phpEx?" . POST_POST_URL . '=' . $searchset[$i]['post_id'] . "&highlight=$highlight_active") . '#' . $searchset[$i]['post_id'];
  866.  
  867. $post_date = create_date($board_config['default_dateformat'], $searchset[$i]['post_time'], $board_config['board_timezone']);
  868.  
  869. $message = $searchset[$i]['post_text'];
  870. $topic_title = $searchset[$i]['topic_title'];
  871.  
  872. $forum_id = $searchset[$i]['forum_id'];
  873. $topic_id = $searchset[$i]['topic_id'];
  874.  
  875. if ( $show_results == 'posts' )
  876. {
  877. if ( isset($return_chars) )
  878. {
  879. $bbcode_uid = $searchset[$i]['bbcode_uid'];
  880.  
  881. //
  882. // If the board has HTML off but the post has HTML
  883. // on then we process it, else leave it alone
  884. //
  885. if ( $return_chars != -1 )
  886. {
  887. $message = strip_tags($message);
  888. $message = preg_replace("/\[.*?:$bbcode_uid:?.*?\]/si", '', $message);
  889. $message = preg_replace('/\[url\]|\[\/url\]/si', '', $message);
  890. $message = ( strlen($message) > $return_chars ) ? substr($message, 0, $return_chars) . ' ...' : $message;
  891. }
  892. else
  893. {
  894. if ( !$board_config['allow_html'] )
  895. {
  896. if ( $postrow[$i]['enable_html'] )
  897. {
  898. $message = preg_replace('#(<)([\/]?.*?)(>)#is', '<\\2>', $message);
  899. }
  900. }
  901.  
  902. if ( $bbcode_uid != '' )
  903. {
  904. $message = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($message, $bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $message);
  905. }
  906.  
  907. $message = make_clickable($message);
  908.  
  909. if ( $highlight_active )
  910. {
  911. if ( preg_match('/<.*>/', $message) )
  912. {
  913. $message = preg_replace($highlight_match, '<!-- #sh -->\1<!-- #eh -->', $message);
  914.  
  915. $end_html = 0;
  916. $start_html = 1;
  917. $temp_message = '';
  918. $message = ' ' . $message . ' ';
  919.  
  920. while( $start_html = strpos($message, '<', $start_html) )
  921. {
  922. $grab_length = $start_html - $end_html - 1;
  923. $temp_message .= substr($message, $end_html + 1, $grab_length);
  924.  
  925. if ( $end_html = strpos($message, '>', $start_html) )
  926. {
  927. $length = $end_html - $start_html + 1;
  928. $hold_string = substr($message, $start_html, $length);
  929.  
  930. if ( strrpos(' ' . $hold_string, '<') != 1 )
  931. {
  932. $end_html = $start_html + 1;
  933. $end_counter = 1;
  934.  
  935. while ( $end_counter && $end_html < strlen($message) )
  936. {
  937. if ( substr($message, $end_html, 1) == '>' )
  938. {
  939. $end_counter--;
  940. }
  941. else if ( substr($message, $end_html, 1) == '<' )
  942. {
  943. $end_counter++;
  944. }
  945.  
  946. $end_html++;
  947. }
  948.  
  949. $length = $end_html - $start_html + 1;
  950. $hold_string = substr($message, $start_html, $length);
  951. $hold_string = str_replace('<!-- #sh -->', '', $hold_string);
  952. $hold_string = str_replace('<!-- #eh -->', '', $hold_string);
  953. }
  954. else if ( $hold_string == '<!-- #sh -->' )
  955. {
  956. $hold_string = str_replace('<!-- #sh -->', '<span style="color:#' . $theme['fontcolor3'] . '"><b>', $hold_string);
  957. }
  958. else if ( $hold_string == '<!-- #eh -->' )
  959. {
  960. $hold_string = str_replace('<!-- #eh -->', '</b></span>', $hold_string);
  961. }
  962.  
  963. $temp_message .= $hold_string;
  964.  
  965. $start_html += $length;
  966. }
  967. else
  968. {
  969. $start_html = strlen($message);
  970. }
  971. }
  972.  
  973. $grab_length = strlen($message) - $end_html - 1;
  974. $temp_message .= substr($message, $end_html + 1, $grab_length);
  975.  
  976. $message = trim($temp_message);
  977. }
  978. else
  979. {
  980. $message = preg_replace($highlight_match, '<span style="color:#' . $theme['fontcolor3'] . '"><b>\1</b></span>', $message);
  981. }
  982. }
  983. }
  984.  
  985. if ( count($orig_word) )
  986. {
  987. $topic_title = preg_replace($orig_word, $replacement_word, $topic_title);
  988. $post_subject = ( $searchset[$i]['post_subject'] != "" ) ? preg_replace($orig_word, $replacement_word, $searchset[$i]['post_subject']) : $lang['Re'] . ': ' . $topic_title;
  989.  
  990. $message = preg_replace($orig_word, $replacement_word, $message);
  991. }
  992. else
  993. {
  994. $post_subject = ( $searchset[$i]['post_subject'] != '' ) ? $searchset[$i]['post_subject'] : $lang['Re'] . ': ' . $topic_title;
  995. }
  996.  
  997. if ($board_config['allow_smilies'] && $searchset[$i]['enable_smilies'])
  998. {
  999. $message = smilies_pass($message);
  1000. }
  1001.  
  1002. $message = str_replace("\n", '<br />', $message);
  1003.  
  1004. }
  1005.  
  1006. $poster = ( $searchset[$i]['user_id'] != ANONYMOUS ) ? '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=" . $searchset[$i]['user_id']) . '">' : '';
  1007. $poster .= ( $searchset[$i]['user_id'] != ANONYMOUS ) ? $searchset[$i]['username'] : ( ( $searchset[$i]['post_username'] != "" ) ? $searchset[$i]['post_username'] : $lang['Guest'] );
  1008. $poster .= ( $searchset[$i]['user_id'] != ANONYMOUS ) ? '</a>' : '';
  1009.  
  1010. if ( $userdata['session_logged_in'] && $searchset[$i]['post_time'] > $userdata['user_lastvisit'] )
  1011. {
  1012. if ( !empty($tracking_topics[$topic_id]) && !empty($tracking_forums[$forum_id]) )
  1013. {
  1014. $topic_last_read = ( $tracking_topics[$topic_id] > $tracking_forums[$forum_id] ) ? $tracking_topics[$topic_id] : $tracking_forums[$forum_id];
  1015. }
  1016. else if ( !empty($tracking_topics[$topic_id]) || !empty($tracking_forums[$forum_id]) )
  1017. {
  1018. $topic_last_read = ( !empty($tracking_topics[$topic_id]) ) ? $tracking_topics[$topic_id] : $tracking_forums[$forum_id];
  1019. }
  1020.  
  1021. if ( $searchset[$i]['post_time'] > $topic_last_read )
  1022. {
  1023. $mini_post_img = $images['icon_minipost_new'];
  1024. $mini_post_alt = $lang['New_post'];
  1025. }
  1026. else
  1027. {
  1028. $mini_post_img = $images['icon_minipost'];
  1029. $mini_post_alt = $lang['Post'];
  1030. }
  1031. }
  1032. else
  1033. {
  1034. $mini_post_img = $images['icon_minipost'];
  1035. $mini_post_alt = $lang['Post'];
  1036. }
  1037.  
  1038. //-- mod : calendar --------------------------------------------------------------------------------
  1039. //-- add
  1040. if (!empty($searchset[$i]['topic_calendar_time']) && ($searchset[$i]['post_id'] == $searchset[$i]['topic_first_post_id']))
  1041. {
  1042. $post_subject .= '</a></b>' . get_calendar_title($searchset[$i]['topic_calendar_time'], $searchset[$i]['topic_calendar_duration']);
  1043. }
  1044. //-- fin mod : calendar ----------------------------------------------------------------------------
  1045.  
  1046. $template->assign_block_vars("searchresults", array(
  1047. 'TOPIC_TITLE' => $topic_title,
  1048. 'FORUM_NAME' => $searchset[$i]['forum_name'],
  1049. 'POST_SUBJECT' => $post_subject,
  1050. 'POST_DATE' => $post_date,
  1051. 'POSTER_NAME' => $poster,
  1052. 'TOPIC_REPLIES' => $searchset[$i]['topic_replies'],
  1053. 'TOPIC_VIEWS' => $searchset[$i]['topic_views'],
  1054. 'MESSAGE' => $message,
  1055. 'MINI_POST_IMG' => $mini_post_img,
  1056.  
  1057. 'L_MINI_POST_ALT' => $mini_post_alt,
  1058.  
  1059. 'U_POST' => $post_url,
  1060. 'U_TOPIC' => $topic_url,
  1061. 'U_FORUM' => $forum_url)
  1062. );
  1063. }
  1064. else
  1065. {
  1066. $message = '';
  1067.  
  1068. if ( count($orig_word) )
  1069. {
  1070. $topic_title = preg_replace($orig_word, $replacement_word, $searchset[$i]['topic_title']);
  1071. }
  1072.  
  1073. $topic_type = $searchset[$i]['topic_type'];
  1074.  
  1075. if ($topic_type == POST_ANNOUNCE)
  1076. {
  1077. $topic_type = $lang['Topic_Announcement'] . ' ';
  1078. }
  1079. else if ($topic_type == POST_STICKY)
  1080. {
  1081. $topic_type = $lang['Topic_Sticky'] . ' ';
  1082. }
  1083. else
  1084. {
  1085. $topic_type = '';
  1086. }
  1087.  
  1088. if ( $searchset[$i]['topic_vote'] )
  1089. {
  1090. $topic_type .= $lang['Topic_Poll'] . ' ';
  1091. }
  1092.  
  1093. $views = $searchset[$i]['topic_views'];
  1094. $replies = $searchset[$i]['topic_replies'];
  1095.  
  1096. if ( ( $replies + 1 ) > $board_config['posts_per_page'] )
  1097. {
  1098. $total_pages = ceil( ( $replies + 1 ) / $board_config['posts_per_page'] );
  1099. $goto_page = ' [ <img src="' . $images['icon_gotopost'] . '" alt="' . $lang['Goto_page'] . '" title="' . $lang['Goto_page'] . '" />' . $lang['Goto_page'] . ': ';
  1100.  
  1101. $times = 1;
  1102. for($j = 0; $j < $replies + 1; $j += $board_config['posts_per_page'])
  1103. {
  1104. $goto_page .= '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=" . $topic_id . "&start=$j") . '">' . $times . '</a>';
  1105. if ( $times == 1 && $total_pages > 4 )
  1106. {
  1107. $goto_page .= ' ... ';
  1108. $times = $total_pages - 3;
  1109. $j += ( $total_pages - 4 ) * $board_config['posts_per_page'];
  1110. }
  1111. else if ( $times < $total_pages )
  1112. {
  1113. $goto_page .= ', ';
  1114. }
  1115. $times++;
  1116. }
  1117. $goto_page .= ' ] ';
  1118. }
  1119. else
  1120. {
  1121. $goto_page = '';
  1122. }
  1123.  
  1124. if ( $searchset[$i]['topic_status'] == TOPIC_MOVED )
  1125. {
  1126. $topic_type = $lang['Topic_Moved'] . ' ';
  1127. $topic_id = $searchset[$i]['topic_moved_id'];
  1128.  
  1129. $folder_image = '<img src="' . $images['folder'] . '" alt="' . $lang['No_new_posts'] . '" />';
  1130. $newest_post_img = '';
  1131. }
  1132. else
  1133. {
  1134. if ( $searchset[$i]['topic_status'] == TOPIC_LOCKED )
  1135. {
  1136. $folder = $images['folder_locked'];
  1137. $folder_new = $images['folder_locked_new'];
  1138. }
  1139. else if ( $searchset[$i]['topic_type'] == POST_ANNOUNCE )
  1140. {
  1141. $folder = $images['folder_announce'];
  1142. $folder_new = $images['folder_announce_new'];
  1143. }
  1144. else if ( $searchset[$i]['topic_type'] == POST_STICKY )
  1145. {
  1146. $folder = $images['folder_sticky'];
  1147. $folder_new = $images['folder_sticky_new'];
  1148. }
  1149. else
  1150. {
  1151. if ( $replies >= $board_config['hot_threshold'] )
  1152. {
  1153. $folder = $images['folder_hot'];
  1154. $folder_new = $images['folder_hot_new'];
  1155. }
  1156. else
  1157. {
  1158. $folder = $images['folder'];
  1159. $folder_new = $images['folder_new'];
  1160. }
  1161. }
  1162.  
  1163. if ( $userdata['session_logged_in'] )
  1164. {
  1165. if ( $searchset[$i]['post_time'] > $userdata['user_lastvisit'] )
  1166. {
  1167. if ( !empty($tracking_topics) || !empty($tracking_forums) || isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all']) )
  1168. {
  1169.  
  1170. $unread_topics = true;
  1171.  
  1172. if ( !empty($tracking_topics[$topic_id]) )
  1173. {
  1174. if ( $tracking_topics[$topic_id] > $searchset[$i]['post_time'] )
  1175. {
  1176. $unread_topics = false;
  1177. }
  1178. }
  1179.  
  1180. if ( !empty($tracking_forums[$forum_id]) )
  1181. {
  1182. if ( $tracking_forums[$forum_id] > $searchset[$i]['post_time'] )
  1183. {
  1184. $unread_topics = false;
  1185. }
  1186. }
  1187.  
  1188. if ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all']) )
  1189. {
  1190. if ( $HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all'] > $searchset[$i]['post_time'] )
  1191. {
  1192. $unread_topics = false;
  1193. }
  1194. }
  1195.  
  1196. if ( $unread_topics )
  1197. {
  1198. $folder_image = $folder_new;
  1199. $folder_alt = $lang['New_posts'];
  1200.  
  1201. $newest_post_img = '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&view=newest") . '"><img src="' . $images['icon_newest_reply'] . '" alt="' . $lang['View_newest_post'] . '" title="' . $lang['View_newest_post'] . '" border="0" /></a> ';
  1202. }
  1203. else
  1204. {
  1205. $folder_alt = ( $searchset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts'];
  1206.  
  1207. $folder_image = $folder;
  1208. $folder_alt = $folder_alt;
  1209. $newest_post_img = '';
  1210. }
  1211.  
  1212. }
  1213. else if ( $searchset[$i]['post_time'] > $userdata['user_lastvisit'] )
  1214. {
  1215. $folder_image = $folder_new;
  1216. $folder_alt = $lang['New_posts'];
  1217.  
  1218. $newest_post_img = '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&view=newest") . '"><img src="' . $images['icon_newest_reply'] . '" alt="' . $lang['View_newest_post'] . '" title="' . $lang['View_newest_post'] . '" border="0" /></a> ';
  1219. }
  1220. else
  1221. {
  1222. $folder_image = $folder;
  1223. $folder_alt = ( $searchset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts'];
  1224. $newest_post_img = '';
  1225. }
  1226. }
  1227. else
  1228. {
  1229. $folder_image = $folder;
  1230. $folder_alt = ( $searchset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts'];
  1231. $newest_post_img = '';
  1232. }
  1233. }
  1234. else
  1235. {
  1236. $folder_image = $folder;
  1237. $folder_alt = ( $searchset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts'];
  1238. $newest_post_img = '';
  1239. }
  1240. }
  1241.  
  1242.  
  1243. $topic_author = ( $searchset[$i]['user_id'] != ANONYMOUS ) ? '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . '=' . $searchset[$i]['user_id']) . '">' : '';
  1244. $topic_author .= ( $searchset[$i]['user_id'] != ANONYMOUS ) ? $searchset[$i]['username'] : ( ( $searchset[$i]['post_username'] != '' ) ? $searchset[$i]['post_username'] : $lang['Guest'] );
  1245.  
  1246. // replace html tags and trim length to 255
  1247. $summary = $searchset[$i]['post_text'];
  1248. $summary = smilies_pass($summary, false);
  1249. if (strlen($summary) > 252) $summary=substr($summary,0,252) . "...";
  1250. $summary = preg_replace("/[\n\r]{1,2}/", ' ', $summary);
  1251. $summary = preg_replace("/\[.+\]/iU",'',$summary);
  1252. $summary = htmlspecialchars(strip_tags($summary));
  1253.  
  1254. $topic_author .= ( $searchset[$i]['user_id'] != ANONYMOUS ) ? '</a>' : '';
  1255.  
  1256. $first_post_time = create_date($board_config['default_dateformat'], $searchset[$i]['topic_time'], $board_config['board_timezone']);
  1257.  
  1258. $last_post_time = create_date($board_config['default_dateformat'], $searchset[$i]['post_time'], $board_config['board_timezone']);
  1259.  
  1260. $last_post_author = ( $searchset[$i]['id2'] == ANONYMOUS ) ? ( ($searchset[$i]['post_username2'] != '' ) ? $searchset[$i]['post_username2'] . ' ' : $lang['Guest'] . ' ' ) : '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . '=' . $searchset[$i]['id2']) . '">' . $searchset[$i]['user2'] . '</a>';
  1261.  
  1262. $last_post_url = '<a href="' . append_sid("viewtopic.$phpEx?" . POST_POST_URL . '=' . $searchset[$i]['topic_last_post_id']) . '#' . $searchset[$i]['topic_last_post_id'] . '"><img src="' . $images['icon_latest_reply'] . '" alt="' . $lang['View_latest_post'] . '" title="' . $lang['View_latest_post'] . '" border="0" /></a>';
  1263.  
  1264. $template->assign_block_vars('searchresults', array(
  1265. 'FORUM_NAME' => $searchset[$i]['forum_name'],
  1266. 'FORUM_ID' => $forum_id,
  1267. 'TOPIC_ID' => $topic_id,
  1268. 'FOLDER' => $folder_image,
  1269. 'NEWEST_POST_IMG' => $newest_post_img,
  1270. 'TOPIC_FOLDER_IMG' => $folder_image,
  1271. 'GOTO_PAGE' => $goto_page,
  1272. 'REPLIES' => $replies,
  1273. 'TOPIC_TITLE' => $topic_title,
  1274. 'TOPIC_SUMMARY' => $summary,
  1275. 'TOPIC_TYPE' => $topic_type,
  1276. 'VIEWS' => $views,
  1277. 'TOPIC_AUTHOR' => $topic_author,
  1278. 'FIRST_POST_TIME' => $first_post_time,
  1279. 'LAST_POST_TIME' => $last_post_time,
  1280. 'LAST_POST_AUTHOR' => $last_post_author,
  1281. 'LAST_POST_IMG' => $last_post_url,
  1282.  
  1283. 'L_TOPIC_FOLDER_ALT' => $folder_alt,
  1284.  
  1285. 'U_VIEW_FORUM' => $forum_url,
  1286. 'U_VIEW_TOPIC' => $topic_url)
  1287. );
  1288. }
  1289. }
  1290.  
  1291. $base_url = "search.$phpEx?search_id=$search_id";
  1292.  
  1293. $template->assign_vars(array(
  1294. 'PAGINATION' => generate_pagination($base_url, $total_match_count, $per_page, $start),
  1295. 'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $per_page ) + 1 ), ceil( $total_match_count / $per_page )),
  1296.  
  1297. 'L_AUTHOR' => $lang['Author'],
  1298. 'L_MESSAGE' => $lang['Message'],
  1299. 'L_FORUM' => $lang['Forum'],
  1300. 'L_TOPICS' => $lang['Topics'],
  1301. 'L_REPLIES' => $lang['Replies'],
  1302. 'L_VIEWS' => $lang['Views'],
  1303. 'L_POSTS' => $lang['Posts'],
  1304. 'L_LASTPOST' => $lang['Last_Post'],
  1305. 'L_POSTED' => $lang['Posted'],
  1306. 'L_SUBJECT' => $lang['Subject'],
  1307.  
  1308. 'L_GOTO_PAGE' => $lang['Goto_page'])
  1309. );
  1310.  
  1311. $template->pparse('body');
  1312.  
  1313. include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
  1314. }
  1315. else
  1316. {
  1317. message_die(GENERAL_MESSAGE, $lang['No_search_match']);
  1318. }
  1319. }
  1320.  
  1321. //
  1322. // Search forum
  1323. //
  1324. $sql = "SELECT c.cat_title, c.cat_id, f.forum_name, f.forum_id
  1325. FROM " . CATEGORIES_TABLE . " c, " . FORUMS_TABLE . " f
  1326. WHERE f.cat_id = c.cat_id
  1327. ORDER BY c.cat_order, f.forum_order";
  1328. $result = $db->sql_query($sql);
  1329. if ( !$result )
  1330. {
  1331. message_die(GENERAL_ERROR, 'Could not obtain forum_name/forum_id', '', __LINE__, __FILE__, $sql);
  1332. }
  1333.  
  1334. $is_auth_ary = auth(AUTH_READ, AUTH_LIST_ALL, $userdata);
  1335.  
  1336. $s_forums = '';
  1337. while( $row = $db->sql_fetchrow($result) )
  1338. {
  1339. if ( $is_auth_ary[$row['forum_id']]['auth_read'] )
  1340. {
  1341. $s_forums .= '<option value="' . $row['forum_id'] . '">' . $row['forum_name'] . '</option>';
  1342. if ( empty($list_cat[$row['cat_id']]) )
  1343. {
  1344. $list_cat[$row['cat_id']] = $row['cat_title'];
  1345. }
  1346. }
  1347. }
  1348.  
  1349. if ( $s_forums != '' )
  1350. {
  1351. $s_forums = '<option value="-1">' . $lang['All_available'] . '</option>' . $s_forums;
  1352.  
  1353. //
  1354. // Category to search
  1355. //
  1356. $s_categories = '<option value="-1">' . $lang['All_available'] . '</option>';
  1357. while( list($cat_id, $cat_title) = @each($list_cat))
  1358. {
  1359. $s_categories .= '<option value="' . $cat_id . '">' . $cat_title . '</option>';
  1360. }
  1361. }
  1362. else
  1363. {
  1364. message_die(GENERAL_MESSAGE, $lang['No_searchable_forums']);
  1365. }
  1366.  
  1367. //
  1368. // Number of chars returned
  1369. //
  1370. $s_characters = '<option value="-1">' . $lang['All_available'] . '</option>';
  1371. $s_characters .= '<option value="0">0</option>';
  1372. $s_characters .= '<option value="25">25</option>';
  1373. $s_characters .= '<option value="50">50</option>';
  1374.  
  1375. for($i = 100; $i < 1100 ; $i += 100)
  1376. {
  1377. $selected = ( $i == 200 ) ? ' selected="selected"' : '';
  1378. $s_characters .= '<option value="' . $i . '"' . $selected . '>' . $i . '</option>';
  1379. }
  1380.  
  1381. //
  1382. // Sorting
  1383. //
  1384. $s_sort_by = "";
  1385. for($i = 0; $i < count($sort_by_types); $i++)
  1386. {
  1387. $s_sort_by .= '<option value="' . $i . '">' . $sort_by_types[$i] . '</option>';
  1388. }
  1389.  
  1390. //
  1391. // Search time
  1392. //
  1393. $previous_days = array(0, 1, 7, 14, 30, 90, 180, 364);
  1394. $previous_days_text = array($lang['All_Posts'], $lang['1_Day'], $lang['7_Days'], $lang['2_Weeks'], $lang['1_Month'], $lang['3_Months'], $lang['6_Months'], $lang['1_Year']);
  1395.  
  1396. $s_time = '';
  1397. for($i = 0; $i < count($previous_days); $i++)
  1398. {
  1399. $selected = ( $topic_days == $previous_days[$i] ) ? ' selected="selected"' : '';
  1400. $s_time .= '<option value="' . $previous_days[$i] . '"' . $selected . '>' . $previous_days_text[$i] . '</option>';
  1401. }
  1402.  
  1403. //
  1404. // Output the basic page
  1405. //
  1406. $page_title = $lang['Search'];
  1407. include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  1408.  
  1409. $template->set_filenames(array(
  1410. 'body' => 'search_body.tpl')
  1411. );
  1412. make_jumpbox('viewforum.'.$phpEx);
  1413.  
  1414. $template->assign_vars(array(
  1415. 'L_SEARCH_QUERY' => $lang['Search_query'],
  1416. 'L_SEARCH_OPTIONS' => $lang['Search_options'],
  1417. 'L_SEARCH_KEYWORDS' => $lang['Search_keywords'],
  1418. 'L_SEARCH_KEYWORDS_EXPLAIN' => $lang['Search_keywords_explain'],
  1419. 'L_SEARCH_AUTHOR' => $lang['Search_author'],
  1420. 'L_SEARCH_AUTHOR_EXPLAIN' => $lang['Search_author_explain'],
  1421. 'L_SEARCH_ANY_TERMS' => $lang['Search_for_any'],
  1422. 'L_SEARCH_ALL_TERMS' => $lang['Search_for_all'],
  1423. 'L_SEARCH_MESSAGE_ONLY' => $lang['Search_msg_only'],
  1424. 'L_SEARCH_MESSAGE_TITLE' => $lang['Search_title_msg'],
  1425. 'L_CATEGORY' => $lang['Category'],
  1426. 'L_RETURN_FIRST' => $lang['Return_first'],
  1427. 'L_CHARACTERS' => $lang['characters_posts'],
  1428. 'L_SORT_BY' => $lang['Sort_by'],
  1429. 'L_SORT_ASCENDING' => $lang['Sort_Ascending'],
  1430. 'L_SORT_DESCENDING' => $lang['Sort_Descending'],
  1431. 'L_SEARCH_PREVIOUS' => $lang['Search_previous'],
  1432. 'L_DISPLAY_RESULTS' => $lang['Display_results'],
  1433. 'L_FORUM' => $lang['Forum'],
  1434. 'L_TOPICS' => $lang['Topics'],
  1435. 'L_POSTS' => $lang['Posts'],
  1436.  
  1437. 'S_SEARCH_ACTION' => append_sid("search.$phpEx?mode=results"),
  1438. 'S_CHARACTER_OPTIONS' => $s_characters,
  1439. 'S_FORUM_OPTIONS' => $s_forums,
  1440. 'S_CATEGORY_OPTIONS' => $s_categories,
  1441. 'S_TIME_OPTIONS' => $s_time,
  1442. 'S_SORT_OPTIONS' => $s_sort_by,
  1443. 'S_HIDDEN_FIELDS' => '')
  1444. );
  1445.  
  1446. $template->pparse('body');
  1447.  
  1448. include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
  1449.  
  1450. ?>

et tu crois que je vais me coltiner les 1450 lignes parce que tu veux pas faire l'effort d'apprendre ??

tu veux corriger un bug dans un programme, tres bien ! mais tu fais moi l'effort d'apprendre le language en question pour pas faire de conneries ...

alors ici, pas la peine de connaitre le php (enfin, juste le minimum et encore, avec un code bien commenté ca devrait pas etre un problème) puisque c'est un problème de sql

Citation :
et tu crois que je vais me coltiner les 1450 lignes parce que tu veux pas faire l'effort d'apprendre ??


Pas du tout!
D'ailleurs, j'ai essayé ceci, mais en vain...

remplacer
  1. $sql = "SELECT post_id
  2. FROM " . POSTS_TABLE . "
  3. WHERE post_time >= " . $userdata['user_lastvisit'];

par
  1. $sql = "SELECT post_id
  2. FROM " . POSTS_TABLE . "
  3. WHERE post_time >= " . $userdata['user_lastvisit'] . "
  4. AND validate=1";


et de même pour
  1. $sql = "SELECT post_id
  2. FROM " . POSTS_TABLE . "
  3. WHERE poster_id = " . $userdata['user_id'];

et
  1. $sql = "SELECT post_id
  2. FROM " . POSTS_TABLE . "
  3. WHERE poster_id IN ($matching_userids)";


et celle-ci
  1. $sql = "SELECT post_id
  2. FROM " . POSTS_TEXT_TABLE . "
  3. WHERE post_text LIKE '$match_word'
  4. $search_msg_only";

remplacée par
  1. $sql = "SELECT pt.post_id
  2. FROM " . POSTS_TEXT_TABLE . " pt
  3. JOIN " . POSTS_TABLE . " p ON p.post_id = pt.post_id
  4. WHERE p.validate = 1
  5. AND pt.post_text LIKE '$match_word'
  6. $search_msg_only";



Je mets à la disposition de tous le fichier search.php uniquement pour faciliter la compréhension du problème et l'identification rapide et précise des lignes de code qui pourraient être problématiques. Je suis désolé si j'ai pu t'offenser.

Si vous avez d'autres idées de solutions possibles, je suis preneur!


Merci!

Citation :
et ca donne quoi ces remplacements ?


Absolument rien!
Les posts non-validés sont toujours inclus dans le nombre de résultats de recherche...

Bizarre, non? Le code semble pourtant logique de cette façon...

Je continue de chercher; si vous avez des idées, n'hésitez pas!

Bonjour,

Il y a du nouveau à ce sujet!

Les trois premières modifications fonctionnent parfaitement; il suffisait simplement de remplacer le 1 par 0!

Cependant, la dernière modification (celle qui concerne la recherche par mots-clés) ne fonctionne pas... Des suggestions?


Merci beaucoup!


P.S.: La recherche des messages sans réponses inclus présentement les messages non-validés; comment puis-je corriger cela? J'imagine qu'il s'agit de cette section de code:

  1. else if ( $search_id == 'unanswered' )
  2. {
  3. if ( $auth_sql != '' )
  4. {
  5. $sql = "SELECT t.topic_id, f.forum_id
  6. FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f
  7. WHERE t.topic_replies = 0
  8. AND t.forum_id = f.forum_id
  9. AND t.topic_moved_id = 0
  10. AND $auth_sql";
  11. }
  12. else
  13. {
  14. $sql = "SELECT topic_id
  15. FROM " . TOPICS_TABLE . "
  16. WHERE topic_replies = 0
  17. AND topic_moved_id = 0";
  18. }


Merci encore!

Citation :

Bonjour je n'y connais rien en mécanique mais j'ai réparé ma voiture tout seul, mais c'est bizarre, parfois le volant il a du mal à tourner.

Ah ben oui, j'aurai du l'emmener au garage avant, parce que là je viens d'avoir un accident et j'ai tué ma femme et mes 3 enfants
Expert Programmation

Gatsu35> Considère-t-il PPC comme un garage ? Comme ça, après avoir bidouiller sa bagnole lui-même et avant d'y embarquer femme et enfants, veut-il l'avis de spécialistes.

alexletos a dit :
Citation :

Bonjour je n'y connais rien en mécanique mais j'ai réparé ma voiture tout seul, mais c'est bizarre, parfois le volant il a du mal à tourner.

Ah ben oui, j'aurai du l'emmener au garage avant, parce que là je viens d'avoir un accident et j'ai tué ma femme et mes 3 enfants


Voilà justement pourquoi je demande l'avis des gens ici... Tu n'es pas obligé de répondre si tu n'en a pas envie; les forums sont justement un point de rencontre pour les gens qui désirent s'entraider. Alors si quelqu'un connait la solution et désire la partager, tant mieux.

T'inquiète, je ne modifie rien à l'aveuglette et lorsque je suis dans le doute, je questionne!


Sans rancune! ;) 

OK; la recherche des messages sans réponse ne pose plus problème!

Citation :
P.S.: La recherche des messages sans réponses inclus présentement les messages non-validés; comment puis-je corriger cela? J'imagine qu'il s'agit de cette section de code:

  1. else if ( $search_id == 'unanswered' )
  2. {
  3. if ( $auth_sql != '' )
  4. {
  5. $sql = "SELECT t.topic_id, f.forum_id
  6. FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f
  7. WHERE t.topic_replies = 0
  8. AND t.forum_id = f.forum_id
  9. AND t.topic_moved_id = 0
  10. AND $auth_sql";
  11. }
  12. else
  13. {
  14. $sql = "SELECT topic_id
  15. FROM " . TOPICS_TABLE . "
  16. WHERE topic_replies = 0
  17. AND topic_moved_id = 0";
  18. }


Cette section de code a été remplacée par:

  1. if ( $auth_sql != '' )
  2. {
  3. $sql = "SELECT t.topic_id, f.forum_id
  4. FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f, " . POSTS_TABLE . " p
  5. WHERE t.topic_replies = 0
  6. AND t.forum_id = f.forum_id
  7. AND t.topic_moved_id = 0
  8. AND t.topic_id = p.topic_id
  9. AND p.validate = 0
  10. AND $auth_sql";
  11. }
  12. else
  13. {
  14. $sql = "SELECT t.topic_id
  15. FROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p
  16. WHERE t.topic_id = p.topic_id
  17. AND t.topic_replies = 0
  18. AND p.validate = 0
  19. AND t.topic_moved_id = 0";
  20. }


Ne reste donc que cette section à modifier, soit celle qui touche la recherche par mots-clés:

  1. $sql = "SELECT post_id
  2. FROM " . POSTS_TEXT_TABLE . "
  3. WHERE post_text LIKE '$match_word'
  4. $search_msg_only";



Si vous avez des idées...
Merci encore!

Citation :
Relis ton manuel sur le SQL à la page LIKE. Concentre-toi sur l'utilisation du caractère %. Je crois que tu y trouveras ton bonheur.


Merci pour cette suggestion; je vais concentrer mes lectures sur cet aspect précis! :) 

Et bien j'ai finalement trouvé! :pt1cable: 

  1. #
  2. #-----[ FIND ]----------------------------
  3. #
  4. $sql = "SELECT m.post_id
  5. FROM " . SEARCH_WORD_TABLE . " w, " . SEARCH_MATCH_TABLE . " m
  6. WHERE w.word_text LIKE '$match_word'
  7. AND m.word_id = w.word_id
  8. AND w.word_common <> 1
  9. $search_msg_only";
  10.  
  11. #
  12. #-----[ REPLACE WITH ]---------------------
  13. #
  14. $sql = "SELECT m.post_id
  15. FROM " . SEARCH_WORD_TABLE . " w, " . SEARCH_MATCH_TABLE . " m, " . POSTS_TABLE . " p
  16. WHERE p.post_id = m.post_id
  17. AND p.validate = 0
  18. AND w.word_text LIKE '$match_word'
  19. AND m.word_id = w.word_id
  20. AND w.word_common <> 1
  21. $search_msg_only";


Il s'agissait donc de modifier la partie de code qui touche directement la sélection des mots-clés recherchés, plutôt que celle qui identifie les messages contenant les mots recherchés!

Merci à tous ceux qui ont bien voulu partager leurs connaissances et leur savoir-faire!

Citation :
Ravi que tu ais trouvé.

Mais à quoi te sert d'utiliser LIKE au lieu de = ?
( La réponse est peut-être dans ce contenu de $match_word )


Et bien cette section de code apparaissait tel quel dans le fichier original; je ne l'ai donc pas modifiée.

Pour info, $match_word est défini à la ligne 304 du fichier search.php (je savais bien que l'inclusion de ce fichier finirait par servir éventuellement!) ;) 


Au plaisir!
Lassé par la pub ? Créez un compte