PageRenderTime 43ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/perform_site_search.php

https://bitbucket.org/mpercy/deeemm-cms
PHP | 110 lines | 73 code | 22 blank | 15 comment | 21 complexity | 8713a12640467b9df9003a98dfaf5f55 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause
  1. <?php
  2. defined( '_INDM' ) or die( 'POSSIBLE HACK ATTEMPT!' );
  3. /*===========================================================================
  4. Perform site search
  5. ===========================================================================*/
  6. $page = 'search';
  7. $search_matches = 0;
  8. $search_result = 0;
  9. $search_results_page = 0;
  10. $search_result_start = 1;
  11. $search_results_page = mysql_escape_string(stripslashes($_REQUEST['search_results_page']));
  12. //get all search results
  13. for($count=0;$count<$num_tables+1;$count++){
  14. $sql_query = mysql_query("SELECT * FROM `" . $db_table_prefix . 'cat_' . $all_tables[$count] . "` WHERE `title_lan_" . $language . "` LIKE '%" . $search_text . "%' OR `description_lan_" . $language . "` LIKE '%" . $search_text . "%' ORDER BY `date` DESC");
  15. while($sql_result = @mysql_fetch_array($sql_query)){
  16. $sql_query2 = mysql_query("SELECT * FROM `" . $db_table_prefix . "core_structure` WHERE `table` = 'cat_$all_tables[$count]'");
  17. while($sql_result2 = mysql_fetch_array($sql_query2)) {
  18. $type = $sql_result2[type];
  19. }
  20. $search_matches = $search_matches + 1;
  21. $search_result = read_file($default_url . $templates_dir . "search_results.tpl");
  22. if ($type=='list' || $type=='list + newsbox' ){
  23. $search_item_href = 'index.php?page='.$all_tables[$count].'&amp;id=' . $sql_result[id];
  24. } elseif ($type=='media'){
  25. $search_item_href = 'index.php?page='.$all_tables[$count].'&amp;id=' . $sql_result[id];
  26. } else {
  27. $search_item_href = 'index.php?page='.$all_tables[$count].'&amp;id='. $sql_result[id];
  28. }
  29. //format text for search result
  30. // $formatted_search_result = balanceTags(truncate($sql_result[description_lan_.$language], $search_result_length));
  31. // $formatted_search_result = preg_replace('/\n|\r|\n\r/',' ',$formatted_search_result);
  32. $formatted_search_result = strip_tags(balanceTags(truncate($sql_result[description_lan_.$language], $search_result_length)));
  33. $search_result = str_replace('[var]search_item_href[/var]', $search_item_href, $search_result);
  34. $search_result = str_replace('[var]search_date[/var]', strftime("%a %d %b %y", strtotime($sql_result[date])), $search_result);
  35. $search_result = str_replace('[var]search_title[/var]', $search_matches .'. '. $sql_result[parent] . ' > ' . $sql_result[title_lan_.$language], $search_result);
  36. $search_result = str_replace('[var]search_body[/var]', $formatted_search_result, $search_result);
  37. // $search_result = str_replace($search_text, '<span class="highlight">'.$search_text.'</span>', $search_result);
  38. $search_results_array[] .= $search_result;
  39. }
  40. }
  41. if ($search_results_page > 1){
  42. $search_result_start = ($search_results_page - 1) * $num_search_results_per_page + 1;
  43. }
  44. //no matches
  45. if ($search_matches == 0){
  46. $search_result_start = 0;
  47. $search_result_end = 0;
  48. $search_warning = $lan[search_warning_text];
  49. //first results page ???
  50. } elseif ($search_results_page == 1 || $search_results_page == 0) {
  51. $search_result_end = $search_result_start + $num_search_results_per_page - 1;
  52. if ($search_result_end > $search_matches) $search_result_end = $search_matches;
  53. for($count=$search_result_start-1;$count<$num_search_results_per_page;$count++){
  54. $search_results .= $search_results_array[$count];
  55. }
  56. $search_warning = '';
  57. //multiple pages
  58. } else {
  59. $search_result_end = ($search_results_page * $num_search_results_per_page);
  60. if ($search_result_end > $search_matches) $search_result_end = $search_matches;
  61. for($count=$search_result_start-1;$count<$search_result_end;$count++){
  62. $search_results .= $search_results_array[$count];
  63. }
  64. }
  65. //too many matches
  66. if ($search_matches > $max_search_results){
  67. $search_warning = $lan[search_warning_text];
  68. }
  69. //check number of results to format page display and choose language elements
  70. if ($search_matches == 1){
  71. $search_matches .= ' ' . $lan[match];
  72. $search_result_end = 1;
  73. } else {
  74. $search_matches .= ' ' . $lan[matches];
  75. }
  76. //format search text for use in url
  77. $search_text = str_replace(' ', '+', $search_text);
  78. //generate navigation links
  79. if ($search_matches > 0){
  80. $search_results_nav = '<span class="float_right">Page ';
  81. for($count=1;$count<$search_matches+1;$count+=$num_search_results_per_page){
  82. $num_pages = $num_pages + 1;
  83. $search_results_nav .= '<a href="' . $default_url . 'index.php?search=' . $search_text . '&amp;search_results_page=' . $num_pages . '"> ' . $num_pages . ' </a>';
  84. }
  85. $search_results_nav .= '</span>';
  86. $search_results_nav .= '<br>';
  87. }
  88. ?>