Gazelle/sections/wiki/search.php

142 lines
3.9 KiB
PHP
Raw Normal View History

2013-05-28 08:01:02 +00:00
<?php
2013-04-20 08:01:01 +00:00
if (empty($_GET['nojump'])) {
2013-12-24 08:00:55 +00:00
$ArticleID = Wiki::alias_to_id($_GET['search']);
if ($ArticleID) {
//Found the article!
2011-03-28 14:21:28 +00:00
header('Location: wiki.php?action=article&id='.$ArticleID);
2013-12-24 08:00:55 +00:00
die();
2011-03-28 14:21:28 +00:00
}
}
define('ARTICLES_PER_PAGE', 25);
2013-05-28 08:01:02 +00:00
list($Page, $Limit) = Format::page_limit(ARTICLES_PER_PAGE);
2011-03-28 14:21:28 +00:00
$OrderVals = array('Title', 'Created', 'Edited');
$WayVals = array('Ascending', 'Descending');
2013-11-17 08:00:47 +00:00
$TypeTable = array('Title'=>'Title', 'Body'=>'Body');
$OrderTable = array('Title'=>'Title', 'Created'=>'ID', 'Edited'=>'Date');
2011-03-28 14:21:28 +00:00
$WayTable = array('Ascending'=>'ASC', 'Descending'=>'DESC');
// What are we looking for? Let's make sure it isn't dangerous.
$Search = db_string(trim($_GET['search']));
2013-11-17 08:00:47 +00:00
if (!in_array($Type, array('Title', 'Body'))) {
$Type = 'Title';
2013-04-20 08:01:01 +00:00
}
2011-03-28 14:21:28 +00:00
// Break search string down into individual words
$Words = explode(' ', $Search);
$Type = $TypeTable[$_GET['type']];
2013-04-20 08:01:01 +00:00
if (!$Type) {
2013-11-17 08:00:47 +00:00
$Type = 'Title';
2013-04-20 08:01:01 +00:00
}
2011-03-28 14:21:28 +00:00
$Order = $OrderTable[$_GET['order']];
2013-04-20 08:01:01 +00:00
if (!$Order) {
$Order = 'ID';
}
2011-03-28 14:21:28 +00:00
$Way = $WayTable[$_GET['way']];
2013-04-20 08:01:01 +00:00
if (!$Way) {
$Way = 'DESC';
}
2011-03-28 14:21:28 +00:00
2013-04-20 08:01:01 +00:00
$SQL = "
2013-05-29 08:00:51 +00:00
SELECT
SQL_CALC_FOUND_ROWS
2013-11-17 08:00:47 +00:00
ID,
Title,
Date,
Author
FROM wiki_articles
WHERE MinClassRead <= '".$LoggedUser['EffectiveClass']."'";
2013-04-20 08:01:01 +00:00
if ($Search != '') {
2011-03-28 14:21:28 +00:00
$SQL .= " AND $Type LIKE '%";
$SQL .= implode("%' AND $Type LIKE '%", $Words);
$SQL .= "%' ";
}
2013-08-23 08:00:54 +00:00
$SQL .= "
2013-06-06 08:01:03 +00:00
ORDER BY $Order $Way
LIMIT $Limit ";
2011-03-28 14:21:28 +00:00
$RS = $DB->query($SQL);
2013-06-06 08:01:03 +00:00
$DB->query("
SELECT FOUND_ROWS()");
2011-03-28 14:21:28 +00:00
list($NumResults) = $DB->next_record();
2012-10-11 08:00:15 +00:00
View::show_header('Search articles');
2012-06-18 08:00:14 +00:00
$DB->set_query_id($RS);
2011-03-28 14:21:28 +00:00
?>
<div class="thin">
2012-08-19 08:00:19 +00:00
<div class="header">
<h2>Search articles</h2>
<div class="linkbox">
2013-12-24 08:00:55 +00:00
<a href="wiki.php?action=create&amp;alias=<?=display_str(Wiki::normalize_alias($_GET['search']))?>" class="brackets">Create an article</a>
2012-08-19 08:00:19 +00:00
</div>
2011-03-28 14:21:28 +00:00
</div>
<div>
<form action="" method="get">
<div>
<input type="hidden" name="action" value="search" />
<input type="hidden" name="nojump" value="1" />
</div>
2012-09-01 08:00:24 +00:00
<table cellpadding="6" cellspacing="1" border="0" class="layout border" width="100%">
2011-03-28 14:21:28 +00:00
<tr>
2013-08-23 08:00:54 +00:00
<td class="label"><label for="search"><strong>Search for:</strong></label></td>
2011-03-28 14:21:28 +00:00
<td colspan="3">
2014-03-23 08:00:50 +00:00
<input type="search" name="search" id="search" size="70" value="<?=display_str($_GET['search'])?>" />
2011-03-28 14:21:28 +00:00
</td>
</tr>
<tr>
<td class="label"><strong>Search in:</strong></td>
<td>
2013-11-17 08:00:47 +00:00
<label><input type="radio" name="type" value="Title" <? if ($Type == 'Title') { echo 'checked="checked" '; } ?>/> Title</label>
<label><input type="radio" name="type" value="Body" <? if ($Type == 'Body') { echo 'checked="checked" '; } ?>/> Body</label>
2011-03-28 14:21:28 +00:00
</td>
<td class="label"><strong>Order by:</strong></td>
<td>
<select name="order">
2013-04-20 08:01:01 +00:00
<? foreach ($OrderVals as $Cur) { ?>
<option value="<?=$Cur?>"<? if ($_GET['order'] == $Cur || (!$_GET['order'] && $Cur == 'Time')) { echo ' selected="selected"'; } ?>><?=$Cur?></option>
<? } ?>
2011-03-28 14:21:28 +00:00
</select>
<select name="way">
2013-04-20 08:01:01 +00:00
<? foreach ($WayVals as $Cur) { ?>
<option value="<?=$Cur?>"<? if ($_GET['way'] == $Cur || (!$_GET['way'] && $Cur == 'Descending')) { echo ' selected="selected"'; } ?>><?=$Cur?></option>
<? } ?>
2011-03-28 14:21:28 +00:00
</select>
</td>
</tr>
<tr>
<td colspan="4" class="center">
<input type="submit" value="Search" />
</td>
</tr>
2013-02-22 08:00:24 +00:00
</table>
2011-03-28 14:21:28 +00:00
</form>
</div>
<br />
2013-08-23 08:00:54 +00:00
<?
$Pages = Format::get_pages($Page, $NumResults, ARTICLES_PER_PAGE);
2013-05-21 08:01:09 +00:00
if ($Pages) { ?>
<div class="linkbox pager"><?=($Pages)?></div>
<? } ?>
2011-03-28 14:21:28 +00:00
<table width="100%">
<tr class="colhead">
<td>Article</td>
2012-09-09 08:00:26 +00:00
<td>Last updated on</td>
2011-03-28 14:21:28 +00:00
<td>Last edited by</td>
</tr>
2013-08-23 08:00:54 +00:00
<? while (list($ID, $Title, $Date, $UserID) = $DB->next_record()) { ?>
2011-03-28 14:21:28 +00:00
<tr>
2012-09-09 08:00:26 +00:00
<td><a href="wiki.php?action=article&amp;id=<?=$ID?>"><?=$Title?></a></td>
2011-03-28 14:21:28 +00:00
<td><?=$Date?></td>
2012-10-11 08:00:15 +00:00
<td><?=Users::format_username($UserID, false, false, false)?></td>
2011-03-28 14:21:28 +00:00
</tr>
2013-08-23 08:00:54 +00:00
<? } ?>
2011-03-28 14:21:28 +00:00
</table>
<div class="linkbox"><?=$Pages?></div>
</div>
2012-10-11 08:00:15 +00:00
<? View::show_footer(); ?>