BioTorrents.de’s version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

search.php 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. #declare(strict_types=1);
  3. if (empty($_GET['nojump'])) {
  4. $ArticleID = Wiki::alias_to_id($_GET['search']);
  5. if ($ArticleID) {
  6. // Found the article!
  7. header('Location: wiki.php?action=article&id='.$ArticleID);
  8. error();
  9. }
  10. }
  11. define('ARTICLES_PER_PAGE', 25);
  12. list($Page, $Limit) = Format::page_limit(ARTICLES_PER_PAGE);
  13. $OrderVals = array('Title', 'Created', 'Edited');
  14. $WayVals = array('Ascending', 'Descending');
  15. $TypeTable = array('Title'=>'Title', 'Body'=>'Body');
  16. $OrderTable = array('Title'=>'Title', 'Created'=>'ID', 'Edited'=>'Date');
  17. $WayTable = array('Ascending'=>'ASC', 'Descending'=>'DESC');
  18. // What are we looking for? Let's make sure it isn't dangerous
  19. $Search = db_string(trim($_GET['search']));
  20. if (!in_array($Type, array('Title', 'Body'))) {
  21. $Type = 'Title';
  22. }
  23. // Break search string down into individual words
  24. $Words = explode(' ', $Search);
  25. $Type = $TypeTable[$_GET['type']];
  26. if (!$Type) {
  27. $Type = 'Title';
  28. }
  29. $Order = $OrderTable[$_GET['order']];
  30. if (!$Order) {
  31. $Order = 'ID';
  32. }
  33. $Way = $WayTable[$_GET['way']];
  34. if (!$Way) {
  35. $Way = 'DESC';
  36. }
  37. $SQL = "
  38. SELECT
  39. SQL_CALC_FOUND_ROWS
  40. ID,
  41. Title,
  42. Date,
  43. Author
  44. FROM wiki_articles
  45. WHERE MinClassRead <= '".$LoggedUser['EffectiveClass']."'";
  46. if ($Search !== '') {
  47. $SQL .= " AND $Type LIKE '%";
  48. $SQL .= implode("%' AND $Type LIKE '%", $Words);
  49. $SQL .= "%' ";
  50. }
  51. $SQL .= "
  52. ORDER BY $Order $Way
  53. LIMIT $Limit ";
  54. $RS = $DB->query($SQL);
  55. $DB->query("
  56. SELECT FOUND_ROWS()");
  57. list($NumResults) = $DB->next_record();
  58. View::show_header('Search Articles');
  59. $DB->set_query_id($RS);
  60. ?>
  61. <div>
  62. <div class="header">
  63. <h2>Search articles</h2>
  64. <div class="linkbox">
  65. <a href="wiki.php?action=create&amp;alias=<?=display_str(Wiki::normalize_alias($_GET['search']))?>"
  66. class="brackets">Create an article</a>
  67. </div>
  68. </div>
  69. <div>
  70. <form action="" method="get">
  71. <div>
  72. <input type="hidden" name="action" value="search" />
  73. <input type="hidden" name="nojump" value="1" />
  74. </div>
  75. <table cellpadding="6" cellspacing="1" border="0" class="layout border" width="100%">
  76. <tr>
  77. <td class="label">
  78. <label for="search">
  79. <strong>Search Terms</strong>
  80. </label>
  81. </td>
  82. <td colspan="3">
  83. <input type="search" name="search" id="search" size="70"
  84. value="<?=display_str($_GET['search'])?>" />
  85. </td>
  86. </tr>
  87. <tr>
  88. <td class="label">
  89. <strong>Search In</strong>
  90. </td>
  91. <td>
  92. <label><input type="radio" name="type" value="Title" <?php
  93. if ($Type === 'Title') {
  94. echo 'checked="checked" ';
  95. } ?> /> Title
  96. </label>&ensp;
  97. <label><input type="radio" name="type" value="Body" <?php
  98. if ($Type === 'Body') {
  99. echo 'checked="checked" ';
  100. } ?> /> Body
  101. </label>
  102. </td>
  103. <td class="label">
  104. <strong>Order By</strong>
  105. </td>
  106. <td>
  107. <select name="order">
  108. <?php
  109. foreach ($OrderVals as $Cur) { ?>
  110. <option value="<?=$Cur?>" <?php
  111. if ($_GET['order'] === $Cur || (!$_GET['order'] && $Cur === 'Time')) {
  112. echo ' selected="selected"';
  113. } ?> />
  114. <?=$Cur?>
  115. </option>
  116. <?php } ?>
  117. </select>
  118. <select name="way">
  119. <?php
  120. foreach ($WayVals as $Cur) { ?>
  121. <option value="<?=$Cur?>" <?php
  122. if ($_GET['way'] === $Cur || (!$_GET['way'] && $Cur === 'Descending')) {
  123. echo ' selected="selected"';
  124. } ?> />
  125. <?=$Cur?>
  126. </option>
  127. <?php } ?>
  128. </select>
  129. </td>
  130. </tr>
  131. <tr>
  132. <td colspan="4" class="center">
  133. <input type="submit" value="Search" />
  134. </td>
  135. </tr>
  136. </table>
  137. </form>
  138. </div>
  139. <br />
  140. <?php
  141. $Pages = Format::get_pages($Page, $NumResults, ARTICLES_PER_PAGE);
  142. if ($Pages) { ?>
  143. <div class="linkbox pager">
  144. <?=($Pages)?>
  145. </div>
  146. <?php } ?>
  147. <table width="100%">
  148. <tr class="colhead">
  149. <td>Article</td>
  150. <td>Last updated on</td>
  151. <td>Last edited by</td>
  152. </tr>
  153. <?php
  154. while (list($ID, $Title, $Date, $UserID) = $DB->next_record()) { ?>
  155. <tr>
  156. <td><a href="wiki.php?action=article&amp;id=<?=$ID?>"><?=$Title?></a></td>
  157. <td><?=$Date?>
  158. </td>
  159. <td><?=Users::format_username($UserID, false, false, false)?>
  160. </td>
  161. </tr>
  162. <?php } ?>
  163. </table>
  164. <div class="linkbox"><?=$Pages?>
  165. </div>
  166. </div>
  167. <?php View::show_footer();