summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSavetheinternet <savetheinternet@n0v4.com>2011-03-30 00:56:38 +1100
committerSavetheinternet <savetheinternet@n0v4.com>2011-03-30 00:56:38 +1100
commitb2ae5fdcba9c61383f990034eebdbd5270a81e29 (patch)
tree645a04e466c6ef4e41189195d8db922d3a6527d5
parent80955172e98938f96a9b6c08ec9886d74500552f (diff)
Basic search function for mods
-rw-r--r--inc/config.php4
-rw-r--r--mod.php73
2 files changed, 75 insertions, 2 deletions
diff --git a/inc/config.php b/inc/config.php
index f7cf1e55..710edced 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -250,6 +250,8 @@
$config['mod']['recent_reports'] = 5;
// How many actions to show per page in the moderation log
$config['mod']['modlog_page'] = 350;
+ // Maximum number of results to display for a search, per board
+ $config['mod']['search_results'] = 75;
// Probably best not to change these:
if(!defined('JANITOR')) {
@@ -333,6 +335,8 @@
$config['mod']['create_pm'] = JANITOR;
// Rebuild everything
$config['mod']['rebuild'] = ADMIN;
+ // Search through posts
+ $config['mod']['search'] = JANITOR;
// Wait indefinitely when rebuilding everything
$config['mod']['rebuild_timelimit'] = 0;
diff --git a/mod.php b/mod.php
index c47d7b78..09017386 100644
--- a/mod.php
+++ b/mod.php
@@ -79,6 +79,7 @@
$fieldset = Array(
'Boards' => '',
'Administration' => '',
+ 'Search' => '',
'Logout' => ''
);
@@ -104,6 +105,16 @@
$fieldset['Administration'] .= '<li><a href="?/config">Show configuration</a></li>';
}
+ if($mod['type'] >= $config['mod']['search']) {
+ $fieldset['Search'] .= '<li><form style="display:inline" action="?/search" method="post">' .
+ '<label style="display:inline" for="search">Phrase:</label> ' .
+ '<input id="search" name="search" type="text" size="35" />' .
+ '<input type="submit" value="Search" />' .
+ '</form>' .
+ '<p class="unimportant">(Search is case-insensitive but not based on keywords.)</p>' .
+ '</li>';
+ }
+
$fieldset['Logout'] .= '<li><a href="?/logout">Logout</a></li>';
// TODO: Statistics, etc, in the dashboard.
@@ -283,11 +294,69 @@
echo Element('page.html', Array(
'config'=>$config,
'title'=>'New PM for ' . htmlentities($to['username']),
- 'body'=>$body
- ,'mod'=>true
+ 'body'=>$body,
+ 'mod'=>true
)
);
}
+ } elseif(preg_match('/^\/search$/', $query)) {
+ if($mod['type'] < $config['mod']['search']) error($config['error']['noaccess']);
+
+ $body = '<div class="ban"><h2>Search</h2><form style="display:inline" action="?/search" method="post">' .
+ '<p><label style="display:inline" for="search">Phrase:</label> ' .
+ '<input id="search" name="search" type="text" size="35" ' .
+ (isset($_POST['search']) ? 'value="' . htmlentities($_POST['search']) . '" ' : '') .
+ '/>' .
+ '<input type="submit" value="Search" />' .
+ '</p></form>' .
+ '<p><span class="unimportant">(Search is case-insensitive but not based on keywords.)</span></p>' .
+ '</div>';
+
+ if(isset($_POST['search']) && !empty($_POST['search'])) {
+ $phrase = $_POST['search'];
+ $_body = '';
+
+ $boards = listBoards();
+ foreach($boards as &$_b) {
+ openBoard($_b['uri']);
+
+ $query = prepare(sprintf("SELECT * FROM `posts_%s` WHERE `body` LIKE :query ORDER BY `time` DESC LIMIT :limit", $board['uri']));
+ $query->bindValue(':query', "%{$phrase}%");
+ $query->bindValue(':limit', $config['mod']['search_results'], PDO::PARAM_INT);
+ $query->execute() or error(db_error($query));
+
+ $temp = '';
+ while($post = $query->fetch()) {
+ if(!$post['thread']) {
+ $po = new Thread($post['id'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $post['sticky'], $post['locked'], '?/', $mod, false);
+ } else {
+ $po = new Post($post['id'], $post['thread'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], '?/', $mod);
+ }
+ $temp .= $po->build(true) . '<hr/>';
+ }
+
+ if(!empty($temp))
+ $_body .= '<fieldset><legend>' . $query->rowCount() . ' result' . ($query->rowCount() != 1 ? 's' : '') . ' on <a href="?/' .
+ sprintf($config['board_path'], $board['uri']) . $config['file_index'] .
+ '">' .
+ sprintf($config['board_abbreviation'], $board['uri']) . ' - ' . $board['title'] .
+ '</a></legend>' . $temp . '</fieldset>';
+ }
+
+ $body .= '<hr/>';
+ if(!empty($_body))
+ $body .= $_body;
+ else
+ $body .= '<p style="text-align:center" class="unimportant">(No results.)</p>';
+ }
+
+ echo Element('page.html', Array(
+ 'config'=>$config,
+ 'title'=>'Search',
+ 'body'=>$body,
+ 'mod'=>true
+ )
+ );
} elseif(preg_match('/^\/users$/', $query)) {
if($mod['type'] < $config['mod']['manageusers']) error($config['error']['noaccess']);