diff options
| author | Savetheinternet <savetheinternet@n0v4.com> | 2011-03-30 00:56:38 +1100 |
|---|---|---|
| committer | Savetheinternet <savetheinternet@n0v4.com> | 2011-03-30 00:56:38 +1100 |
| commit | b2ae5fdcba9c61383f990034eebdbd5270a81e29 (patch) | |
| tree | 645a04e466c6ef4e41189195d8db922d3a6527d5 /mod.php | |
| parent | 80955172e98938f96a9b6c08ec9886d74500552f (diff) | |
Basic search function for mods
Diffstat (limited to 'mod.php')
| -rw-r--r-- | mod.php | 73 |
1 files changed, 71 insertions, 2 deletions
@@ -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']); |
