FORUM Tom's Hardware » Programmation » PHP & MySQL & ASP » [Réglé] Requête SQL et condition "if"
 

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

Il y a 273 utilisateurs connus et inconnus. Pour voir la liste des connectés connus, cliquez ici
Ajouter une réponse



 Mot :   Pseudo :  
 
Bas de page
Auteur
 Sujet : [Réglé] Requête SQL et condition "if"
 
Plus d'informations

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:

Code :
  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.                 $show_results = 'topics';
  21.                 $sort_by = 0;
  22.                 $sort_dir = 'DESC';
  23.             }
  24.             else if ( $search_id == 'egosearch' )
  25.             {
  26.                 if ( $userdata['session_logged_in'] )
  27.                 {
  28.                     $sql = "SELECT post_id
  29.                         FROM " . POSTS_TABLE . "
  30.                         WHERE poster_id = " . $userdata['user_id'];
  31.                 }
  32.                 else
  33.                 {
  34.                     redirect(append_sid("login.$phpEx?redirect=search.$phpEx&search_id=egosearch", true));
  35.                 }
  36.                 $show_results = 'topics';
  37.                 $sort_by = 0;
  38.                 $sort_dir = 'DESC';
  39.             }
  40.             else
  41.             {
  42.                 if (preg_match('#^[\*%]+$#', trim($search_author)) || preg_match('#^[^\*]{1,2}$#', str_replace(array('*', '%'), '', trim($search_author))))
  43.                 {
  44.                     $search_author = '';
  45.                 }
  46.                 $search_author = str_replace('*', '%', trim($search_author));
  47.                 $sql = "SELECT user_id
  48.                     FROM " . USERS_TABLE . "
  49.                     WHERE username LIKE '" . str_replace("\'", "''", $search_author) . "'";
  50.                 if ( !($result = $db->sql_query($sql)) )
  51.                 {
  52.                     message_die(GENERAL_ERROR, "Couldn't obtain list of matching users (searching for: $search_author)", "", __LINE__, __FILE__, $sql);
  53.                 }
  54.                 $matching_userids = '';
  55.                 if ( $row = $db->sql_fetchrow($result) )
  56.                 {
  57.                     do
  58.                     {
  59.                         $matching_userids .= ( ( $matching_userids != '' ) ? ', ' : '' ) . $row['user_id'];
  60.                     }
  61.                     while( $row = $db->sql_fetchrow($result) );
  62.                 }
  63.                 else
  64.                 {
  65.                     message_die(GENERAL_MESSAGE, $lang['No_search_match']);
  66.                 }
  67.                 $sql = "SELECT post_id
  68.                     FROM " . POSTS_TABLE . "
  69.                     WHERE poster_id IN ($matching_userids)";
  70.                 if ($search_time)
  71.                 {
  72.                     $sql .= " AND post_time >= " . $search_time;
  73.                 }
  74.             }
  75.             if ( !($result = $db->sql_query($sql)) )
  76.             {
  77.                 message_die(GENERAL_ERROR, 'Could not obtain matched posts list', '', __LINE__, __FILE__, $sql);
  78.             }
  79.             $search_ids = array();
  80.             while( $row = $db->sql_fetchrow($result) )
  81.             {
  82.                 $search_ids[] = $row['post_id'];
  83.             }
  84.             $db->sql_freeresult($result);
  85.             $total_match_count = count($search_ids);
  86.         }
  87.         else if ( $search_keywords != '' )
  88.         {
  89.             $stopword_array = @file($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/search_stopwords.txt');
  90.             $synonym_array = @file($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/search_synonyms.txt');
  91.             $split_search = array();
  92.             $split_search = ( !strstr($multibyte_charset, $lang['ENCODING']) ) ?  split_words(clean_words('search', stripslashes($search_keywords), $stopword_array, $synonym_array), 'search') : split(' ', $search_keywords);
  93.             $search_msg_only = ( !$search_fields ) ? "AND m.title_match = 0" : ( ( strstr($multibyte_charset, $lang['ENCODING']) ) ? '' : '' );
  94.             $word_count = 0;
  95.             $current_match_type = 'or';
  96.             $word_match = array();
  97.             $result_list = array();
  98.             for($i = 0; $i < count($split_search); $i++)
  99.             {
  100.                 if (preg_match('#^[\*%]+$#', trim($split_search[$i])) || preg_match('#^[^\*]{1,2}$#', str_replace(array('*', '%'), '', trim($split_search[$i]))))
  101.                 {
  102.                     $split_search[$i] = '';
  103.                     continue;
  104.                 }
  105.                 switch ( $split_search[$i] )
  106.                 {
  107.                     case 'and':
  108.                         $current_match_type = 'and';
  109.                         break;
  110.                     case 'or':
  111.                         $current_match_type = 'or';
  112.                         break;
  113.                     case 'not':
  114.                         $current_match_type = 'not';
  115.                         break;
  116.                     default:
  117.                         if ( !empty($search_terms) )
  118.                         {
  119.                             $current_match_type = 'and';
  120.                         }
  121.                         if ( !strstr($multibyte_charset, $lang['ENCODING']) )
  122.                         {
  123.                             $match_word = str_replace('*', '%', $split_search[$i]);
  124.                             $sql = "SELECT m.post_id
  125.                                 FROM " . SEARCH_WORD_TABLE . " w, " . SEARCH_MATCH_TABLE . " m
  126.                                 WHERE w.word_text LIKE '$match_word'
  127.                                     AND m.word_id = w.word_id
  128.                                     AND w.word_common <> 1
  129.                                     $search_msg_only";
  130.                         }
  131.                         else
  132.                         {
  133.                             $match_word =  addslashes('%' . str_replace('*', '', $split_search[$i]) . '%');
  134.                             $search_msg_only = ( $search_fields ) ? "OR post_subject LIKE '$match_word'" : '';
  135.                             $sql = "SELECT post_id
  136.                                 FROM " . POSTS_TEXT_TABLE . "
  137.                                 WHERE post_text LIKE '$match_word'
  138.                                 $search_msg_only";
  139.                         }
  140.                         if ( !($result = $db->sql_query($sql)) )
  141.                         {
  142.                             message_die(GENERAL_ERROR, 'Could not obtain matched posts list', '', __LINE__, __FILE__, $sql);
  143.                         }
  144.                         $row = array();
  145.                         while( $temp_row = $db->sql_fetchrow($result) )
  146.                         {
  147.                             $row[$temp_row['post_id']] = 1;
  148.                             if ( !$word_count )
  149.                             {
  150.                                 $result_list[$temp_row['post_id']] = 1;
  151.                             }
  152.                             else if ( $current_match_type == 'or' )
  153.                             {
  154.                                 $result_list[$temp_row['post_id']] = 1;
  155.                             }
  156.                             else if ( $current_match_type == 'not' )
  157.                             {
  158.                                 $result_list[$temp_row['post_id']] = 0;
  159.                             }
  160.                         }
  161.                         if ( $current_match_type == 'and' && $word_count )
  162.                         {
  163.                             @reset($result_list);
  164.                             while( list($post_id, $match_count) = @each($result_list) )
  165.                             {
  166.                                 if ( !$row[$post_id] )
  167.                                 {
  168.                                     $result_list[$post_id] = 0;
  169.                                 }
  170.                             }
  171.                         }
  172.                         $word_count++;
  173.                         $db->sql_freeresult($result);
  174.                     }
  175.             }
  176.             @reset($result_list);
  177.             $search_ids = array();
  178.             while( list($post_id, $matches) = each($result_list) )
  179.             {
  180.                 if ( $matches )
  181.                 {
  182.                     $search_ids[] = $post_id;
  183.                 }
  184.             }
  185.             unset($result_list);
  186.             $total_match_count = count($search_ids);
  187.         }


Message édité par sbourdon le 10-03-2006 à 13:00:06

Profil : Pointeur
Plus d'informations

bha dans tes requetes, tu rajoutes un  

WHERE validate=0

:o

Plus d'informations

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!

Plus d'informations

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

Code :
  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. *   This program is free software; you can redistribute it and/or modify
  17. *   it under the terms of the GNU General Public License as published by
  18. *   the Free Software Foundation; either version 2 of the License, or
  19. *   (at your option) any later version.
  20. *
  21. ***************************************************************************/
  22. define('IN_PHPBB', true);
  23. $phpbb_root_path = './';
  24. include($phpbb_root_path . 'extension.inc');
  25. include($phpbb_root_path . 'common.'.$phpEx);
  26. include($phpbb_root_path . 'includes/bbcode.'.$phpEx);
  27. include($phpbb_root_path . 'includes/functions_search.'.$phpEx);
  28. //-- mod : calendar --------------------------------------------------------------------------------
  29. //-- add
  30. include_once($phpbb_root_path . 'includes/functions_calendar.'.$phpEx);
  31. //-- fin mod : calendar ----------------------------------------------------------------------------
  32. //
  33. // Start session management
  34. //
  35. $userdata = session_pagestart($user_ip, PAGE_SEARCH);
  36. init_userprefs($userdata);
  37. //
  38. // End session management
  39. //
  40. //
  41. // Define initial vars
  42. //
  43. if ( isset($HTTP_POST_VARS['mode']) || isset($HTTP_GET_VARS['mode']) )
  44. {
  45.     $mode = ( isset($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode'];
  46. }
  47. else
  48. {
  49.     $mode = '';
  50. }
  51. if ( isset($HTTP_POST_VARS['search_keywords']) || isset($HTTP_GET_VARS['search_keywords']) )
  52. {
  53.     $search_keywords = ( isset($HTTP_POST_VARS['search_keywords']) ) ? $HTTP_POST_VARS['search_keywords'] : $HTTP_GET_VARS['search_keywords'];
  54. }
  55. else
  56. {
  57.     $search_keywords = '';
  58. }
  59. if ( isset($HTTP_POST_VARS['search_author']) || isset($HTTP_GET_VARS['search_author']))
  60. {
  61.     $search_author = ( isset($HTTP_POST_VARS['search_author']) ) ? $HTTP_POST_VARS['search_author'] : $HTTP_GET_VARS['search_author'];
  62.     $search_author = phpbb_clean_username($search_author);
  63. }
  64. else
  65. {
  66.     $search_author = '';
  67. }
  68. $search_id = ( isset($HTTP_GET_VARS['search_id']) ) ? $HTTP_GET_VARS['search_id'] : '';
  69. $show_results = ( isset($HTTP_POST_VARS['show_results']) ) ? $HTTP_POST_VARS['show_results'] : 'posts';
  70. $show_results = ($show_results == 'topics') ? 'topics' : 'posts';
  71. if ( isset($HTTP_POST_VARS['search_terms']) )
  72. {
  73.     $search_terms = ( $HTTP_POST_VARS['search_terms'] == 'all' ) ? 1 : 0;
  74. }
  75. else
  76. {
  77.     $search_terms = 0;
  78. }
  79. if ( isset($HTTP_POST_VARS['search_fields']) )
  80. {
  81.     $search_fields = ( $HTTP_POST_VARS['search_fields'] == 'all' ) ? 1 : 0;
  82. }
  83. else
  84. {
  85.     $search_fields = 0;
  86. }
  87. $return_chars = ( isset($HTTP_POST_VARS['return_chars']) ) ? intval($HTTP_POST_VARS['return_chars']) : 200;
  88. $search_cat = ( isset($HTTP_POST_VARS['search_cat']) ) ? intval($HTTP_POST_VARS['search_cat']) : -1;
  89. $search_forum = ( isset($HTTP_POST_VARS['search_forum']) ) ? intval($HTTP_POST_VARS['search_forum']) : -1;
  90. $sort_by = ( isset($HTTP_POST_VARS['sort_by']) ) ? intval($HTTP_POST_VARS['sort_by']) : 0;
  91. if ( isset($HTTP_POST_VARS['sort_dir']) )
  92. {
  93.     $sort_dir = ( $HTTP_POST_VARS['sort_dir'] == 'DESC' ) ? 'DESC' : 'ASC';
  94. }
  95. else
  96. {
  97.     $sort_dir =  'DESC';
  98. }
  99. if ( !empty($HTTP_POST_VARS['search_time']) || !empty($HTTP_GET_VARS['search_time']))
  100. {
  101.     $search_time = time() - ( ( ( !empty($HTTP_POST_VARS['search_time']) ) ? intval($HTTP_POST_VARS['search_time']) : intval($HTTP_GET_VARS['search_time']) ) * 86400 );
  102.     $topic_days = (!empty($HTTP_POST_VARS['search_time'])) ? intval($HTTP_POST_VARS['search_time']) : intval($HTTP_GET_VARS['search_time']);
  103. }
  104. else
  105. {
  106.     $search_time = 0;
  107.     $topic_days = 0;
  108. }
  109. $start = ( isset($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0;
  110. $sort_by_types = array($lang['Sort_Time'], $lang['Sort_Post_Subject'], $lang['Sort_Topic_Title'], $lang['Sort_Author'], $lang['Sort_Forum']);
  111. //
  112. // encoding match for workaround
  113. //
  114. $multibyte_charset = 'utf-8, big5, shift_jis, euc-kr, gb2312';
  115. //
  116. // Begin core code
  117. //
  118. if ( $mode == 'searchuser' )
  119. {
  120.     //
  121.     // This handles the simple windowed user search functions called from various other scripts
  122.     //
  123.     if ( isset($HTTP_POST_VARS['search_username']) )
  124.     {
  125.         username_search($HTTP_POST_VARS['search_username']);
  126.     }
  127.     else
  128.     {
  129.         username_search('');
  130.     }
  131.     exit;
  132. }
  133. else if ( $search_keywords != '' || $search_author != '' || $search_id )
  134. {
  135.     $store_vars = array('search_results', 'total_match_count', 'split_search', 'sort_by', 'sort_dir', 'show_results', 'return_chars');
  136.     $search_results = '';
  137.     //
  138.     // Search ID Limiter, decrease this value if you experience further timeout problems with searching forums
  139.     $limiter = 5000;
  140.     //
  141.     // Cycle through options ...
  142.     //
  143.     if ( $search_id == 'newposts' || $search_id == 'egosearch' || $search_id == 'unanswered' || $search_keywords != '' || $search_author != '' )
  144.     {
  145.         if ( $search_id == 'newposts' || $search_id == 'egosearch' || ( $search_author != '' && $search_keywords == '' )  )
  146.         {
  147.             if ( $search_id == 'newposts' )
  148.             {
  149.                 if ( $userdata['session_logged_in'] )
  150.                 {
  151.                     $sql = "SELECT post_id
  152.                         FROM " . POSTS_TABLE . "
  153.                         WHERE post_time >= " . $userdata['user_lastvisit'];
  154.                 }
  155.                 else
  156.                 {
  157.                     redirect(append_sid("login.$phpEx?redirect=search.$phpEx&search_id=newposts", true));
  158.                 }
  159.                 $show_results = 'topics';
  160.                 $sort_by = 0;
  161.                 $sort_dir = 'DESC';
  162.             }
  163.             else if ( $search_id == 'egosearch' )
  164.             {
  165.                 if ( $userdata['session_logged_in'] )
  166.                 {
  167.                     $sql = "SELECT post_id
  168.                         FROM " . POSTS_TABLE . "
  169.                         WHERE poster_id = " . $userdata['user_id'];
  170.                 }
  171.                 else
  172.                 {
  173.                     redirect(append_sid("login.$phpEx?redirect=search.$phpEx&search_id=egosearch", true));
  174.                 }
  175.                 $show_results = 'topics';
  176.                 $sort_by = 0;
  177.                 $sort_dir = 'DESC';
  178.             }
  179.             else
  180.             {
  181.                 if (preg_match('#^[\*%]+$#', trim($search_author)) || preg_match('#^[^\*]{1,2}$#', str_replace(array('*', '%'), '', trim($search_author))))
  182.                 {
  183.                     $search_author = '';
  184.                 }
  185.                 $search_author = str_replace('*', '%', trim($search_author));
  186.                 $sql = "SELECT user_id
  187.                     FROM " . USERS_TABLE . "
  188.                     WHERE username LIKE '" . str_replace("\'", "''", $search_author) . "'";
  189.                 if ( !($result = $db->sql_query($sql)) )
  190.                 {
  191.                     message_die(GENERAL_ERROR, "Couldn't obtain list of matching users (searching for: $search_author)", "", __LINE__, __FILE__, $sql);
  192.                 }
  193.                 $matching_userids = '';
  194.                 if ( $row = $db->sql_fetchrow($result) )
  195.                 {
  196.                     do
  197.                     {
  198.                         $matching_userids .= ( ( $matching_userids != '' ) ? ', ' : '' ) . $row['user_id'];
  199.                     }
  200.                     while( $row = $db->sql_fetchrow($result) );
  201.                 }
  202.                 else
  203.                 {
  204.                     message_die(GENERAL_MESSAGE, $lang['No_search_match']);
  205.                 }
  206.                 $sql = "SELECT post_id
  207.                     FROM " . POSTS_TABLE . "
  208.                     WHERE poster_id IN ($matching_userids)";
  209.                 if ($search_time)
  210.                 {
  211.                     $sql .= " AND post_time >= " . $search_time;
  212.                 }
  213.             }
  214.             if ( !($result = $db->sql_query($sql)) )
  215.             {
  216.                 message_die(GENERAL_ERROR, 'Could not obtain matched posts list', '', __LINE__, __FILE__, $sql);
  217.             }
  218.             $search_ids = array();
  219.             while( $row = $db->sql_fetchrow($result) )
  220.             {
  221.                 $search_ids[] = $row['post_id'];
  222.             }
  223.             $db->sql_freeresult($result);
  224.             $total_match_count = count($search_ids);
  225.         }
  226.         else if ( $search_keywords != '' )
  227.         {
  228.             $stopword_array = @file($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/search_stopwords.txt');
  229.             $synonym_array = @file($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/search_synonyms.txt');
  230.             $split_search = array();
  231.             $split_search = ( !strstr($multibyte_charset, $lang['ENCODING']) ) ?  split_words(clean_words('search', stripslashes($search_keywords), $stopword_array, $synonym_array), 'search') : split(' ', $search_keywords);
  232.             $search_msg_only = ( !$search_fields ) ? "AND m.title_match = 0" : ( ( strstr($multibyte_charset, $lang['ENCODING']) ) ? '' : '' );
  233.             $word_count = 0;
  234.             $current_match_type = 'or';
  235.             $word_match = array();
  236.             $result_list = array();
  237.             for($i = 0; $i < count($split_search); $i++)
  238.             {
  239.                 if (preg_match('#^[\*%]+$#', trim($split_search[$i])) || preg_match('#^[^\*]{1,2}$#', str_replace(array('*', '%'), '', trim($split_search[$i]))))
  240.                 {
  241.                     $split_search[$i] = '';
  242.                     continue;
  243.                 }
  244.                 switch ( $split_search[$i] )
  245.                 {
  246.                     case 'and':
  247.                         $current_match_type = 'and';
  248.                         break;
  249.                     case 'or':
  250.                         $current_match_type = 'or';
  251.                         break;
  252.                     case 'not':
  253.                         $current_match_type = 'not';
  254.                         break;
  255.                     default:
  256.                         if ( !empty($search_terms) )
  257.                         {
  258.                             $current_match_type = 'and';
  259.                         }
  260.                         if ( !strstr($multibyte_charset, $lang['ENCODING']) )
  261.                         {
  262.                             $match_word = str_replace('*', '%', $split_search[$i]);
  263.                             $sql = "SELECT m.post_id
  264.                                 FROM " . SEARCH_WORD_TABLE . " w, " . SEARCH_MATCH_TABLE . " m
  265.                                 WHERE w.word_text LIKE '$match_word'
  266.                                     AND m.word_id = w.word_id
  267.                                     AND w.word_common <> 1
  268.                                     $search_msg_only";
  269.                         }
  270.                         else
  271.                         {
  272.                             $match_word =  addslashes('%' . str_replace('*', '', $split_search[$i]) . '%');
  273.                             $search_msg_only = ( $search_fields ) ? "OR post_subject LIKE '$match_word'" : '';
  274.                             $sql = "SELECT post_id
  275.                                 FROM " . POSTS_TEXT_TABLE . "
  276.                                 WHERE post_text LIKE '$match_word'
  277.                                 $search_msg_only";
  278.                         }
  279.                         if ( !($result = $db->sql_query($sql)) )
  280.                         {
  281.                             message_die(GENERAL_ERROR, 'Could not obtain matched posts list', '', __LINE__, __FILE__, $sql);
  282.                         }
  283.                         $row = array();
  284.                         while( $temp_row = $db->sql_fetchrow($result) )
  285.                         {
  286.                             $row[$temp_row['post_id']] = 1;
  287.                             if ( !$word_count )
  288.                             {
  289.                                 $result_list[$temp_row['post_id']] = 1;
  290.                             }
  291.                             else if ( $current_match_type == 'or' )
  292.                             {
  293.                                 $result_list[$temp_row['post_id']] = 1;
  294.                             }
  295.                             else if ( $current_match_type == 'not' )
  296.                             {
  297.                                 $result_list[$temp_row['post_id']] = 0;
  298.                             }
  299.                         }
  300.                         if ( $current_match_type == 'and' && $word_count )
  301.                         {
  302.                             @reset($result_list);
  303.                             while( list($post_id, $match_count) = @each($result_list) )
  304.                             {
  305.                                 if ( !$row[$post_id] )
  306.                                 {
  307.                                     $result_list[$post_id] = 0;
  308.                                 }
  309.                             }
  310.                         }
  311.                         $word_count++;
  312.                         $db->sql_freeresult($result);
  313.                     }
  314.             }
  315.             @reset($result_list);
  316.             $search_ids = array();
  317.             while( list($post_id, $matches) = each($result_list) )
  318.             {
  319.                 if ( $matches )
  320.                 {
  321.                     $search_ids[] = $post_id;
  322.                 }
  323.             }
  324.             unset($result_list);
  325.             $total_match_count = count($search_ids);
  326.         }
  327.         //
  328.         // If user is logged in then we'll check to see which (if any) private
  329.         // forums they are allowed to view and include them in the search.
  330.         //
  331.         // If not logged in we explicitly prevent searching of private forums
  332.         //
  333.         $auth_sql = '';
  334.         if ( $search_forum != -1 )
  335.         {
  336.             $is_auth = auth(AUTH_READ, $search_forum, $userdata);
  337.             if ( !$is_auth['auth_read'] )
  338.             {
  339.                 message_die(GENERAL_MESSAGE, $lang['No_searchable_forums']);
  340.             }
  341.             $auth_sql = "f.forum_id = $search_forum";
  342.         }
  343.         else
  344.         {
  345.             $is_auth_ary = auth(AUTH_READ, AUTH_LIST_ALL, $userdata);
  346.             if ( $search_cat != -1 )
  347.             {
  348.                 $auth_sql = "f.cat_id = $search_cat";
  349.             }
  350.             $ignore_forum_sql = '';
  351.             while( list($key, $value) = each($is_auth_ary) )
  352.             {
  353.                 if ( !$value['auth_read'] )
  354.                 {
  355.                     $ignore_forum_sql .= ( ( $ignore_forum_sql != '' ) ? ', ' : '' ) . $key;
  356.                 }
  357.             }
  358.             if ( $ignore_forum_sql != '' )
  359.             {
  360.                 $auth_sql .= ( $auth_sql != '' ) ? " AND f.forum_id NOT IN ($ignore_forum_sql) " : "f.forum_id NOT IN ($ignore_forum_sql) ";
  361.             }
  362.         }
  363.         //
  364.         // Author name search  
  365.         //
  366.         if ( $search_author != '' )
  367.         {
  368.             if (preg_match('#^[\*%]+$#', trim($search_author)) || preg_match('#^[^\*]{1,2}$#', str_replace(array('*', '%'), '', trim($search_author))))
  369.             {
  370.                 $search_author = '';
  371.             }
  372.             $search_author = str_replace('*', '%', trim(str_replace("\'", "''", $search_author)));
  373.         }
  374.         if ( $total_match_count )
  375.         {
  376.             if ( $show_results == 'topics' )
  377.             {
  378.                 //
  379.                 // This one is a beast, try to seperate it a bit (workaround for connection timeouts)
  380.                 //
  381.                 $search_id_chunks = array();
  382.                 $count = 0;
  383.                 $chunk = 0;
  384.                 if (count($search_ids) > $limiter)
  385.                 {
  386.                     for ($i = 0; $i < count($search_ids); $i++)
  387.                     {
  388.                         if ($count == $limiter)
  389.                         {
  390.                             $chunk++;
  391.                             $count = 0;
  392.                         }
  393.                         $search_id_chunks[$chunk][$count] = $search_ids[$i];
  394.                         $count++;
  395.                     }
  396.                 }
  397.                 else
  398.                 {
  399.                     $search_id_chunks[0] = $search_ids;
  400.                 }
  401.                 $search_ids = array();
  402.                 for ($i = 0; $i < count($search_id_chunks); $i++)
  403.                 {
  404.                     $where_sql = '';
  405.                     if ( $search_time )
  406.                     {
  407.                         $where_sql .= ( $search_author == '' && $auth_sql == ''  ) ? " AND post_time >= $search_time " : " AND p.post_time >= $search_time ";
  408.                     }
  409.                     if ( $search_author == '' && $auth_sql == '' )
  410.                     {
  411.                         $sql = "SELECT topic_id
  412.                             FROM " . POSTS_TABLE . "
  413.                             WHERE post_id IN (" . implode(", ", $search_id_chunks[$i]) . " )
  414.                             $where_sql
  415.                             GROUP BY topic_id";
  416.                     }
  417.                     else
  418.                     {
  419.                         $from_sql = POSTS_TABLE . " p";
  420.                         if ( $search_author != '' )
  421.                         {
  422.                             $from_sql .= ", " . USERS_TABLE . " u";
  423.                             $where_sql .= " AND u.user_id = p.poster_id AND u.username LIKE '$search_author' ";
  424.                         }
  425.                         if ( $auth_sql != '' )
  426.                         {
  427.                             $from_sql .= ", " . FORUMS_TABLE . " f";
  428.                             $where_sql .= " AND f.forum_id = p.forum_id AND $auth_sql";
  429.                         }
  430.                         $sql = "SELECT p.topic_id
  431.                             FROM $from_sql
  432.                             WHERE p.post_id IN (" . implode(", ", $search_id_chunks[$i]) . " )
  433.                                 $where_sql
  434.                             GROUP BY p.topic_id";
  435.                     }
  436.                     if ( !($result = $db->sql_query($sql)) )
  437.                     {
  438.                         message_die(GENERAL_ERROR, 'Could not obtain topic ids', '', __LINE__, __FILE__, $sql);
  439.                     }
  440.                     while ($row = $db->sql_fetchrow($result))
  441.                     {
  442.                         $search_ids[] = $row['topic_id'];
  443.                     }
  444.                     $db->sql_freeresult($result);
  445.                 }
  446.                 $total_match_count = sizeof($search_ids);
  447.             }
  448.             else if ( $search_author != '' || $search_time || $auth_sql != '' )
  449.             {
  450.                 $search_id_chunks = array();
  451.                 $count = 0;
  452.                 $chunk = 0;
  453.                 if (count($search_ids) > $limiter)
  454.                 {
  455.                     for ($i = 0; $i < count($search_ids); $i++)
  456.                     {
  457.                         if ($count == $limiter)
  458.                         {
  459.                             $chunk++;
  460.      &n