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'] .= '
  • Show configuration
  • '; } + if($mod['type'] >= $config['mod']['search']) { + $fieldset['Search'] .= '
  • ' . + ' ' . + '' . + '' . + '
    ' . + '

    (Search is case-insensitive but not based on keywords.)

    ' . + '
  • '; + } + $fieldset['Logout'] .= '
  • Logout
  • '; // 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 = '

    Search

    ' . + '

    ' . + '' . + '' . + '

    ' . + '

    (Search is case-insensitive but not based on keywords.)

    ' . + '
    '; + + 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) . '
    '; + } + + if(!empty($temp)) + $_body .= '
    ' . $query->rowCount() . ' result' . ($query->rowCount() != 1 ? 's' : '') . ' on ' . + sprintf($config['board_abbreviation'], $board['uri']) . ' - ' . $board['title'] . + '' . $temp . '
    '; + } + + $body .= '
    '; + if(!empty($_body)) + $body .= $_body; + else + $body .= '

    (No results.)

    '; + } + + 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']);