diff options
| author | czaks <marcin@6irc.net> | 2013-07-29 16:26:10 -0400 |
|---|---|---|
| committer | czaks <marcin@6irc.net> | 2013-07-29 16:26:10 -0400 |
| commit | 4257191acd2cb65422b66e7fcf9df79f3790e5fb (patch) | |
| tree | f4c421cf441215849db8f93976520a9eb9473358 | |
| parent | d11e9d752e1b1107469ca363b33648bbcdac9f60 (diff) | |
| parent | c8e93f04d2522224dd84b7d93e526b918a105451 (diff) | |
Merge branch 'master' of https://github.com/savetheinternet/Tinyboard
| -rw-r--r-- | inc/config.php | 4 | ||||
| -rw-r--r-- | inc/mod/pages.php | 41 | ||||
| -rw-r--r-- | templates/mod/news.html | 2 | ||||
| -rw-r--r-- | templates/mod/search_results.html | 97 |
4 files changed, 134 insertions, 10 deletions
diff --git a/inc/config.php b/inc/config.php index f691d4f5..a1ed3ecc 100644 --- a/inc/config.php +++ b/inc/config.php @@ -583,7 +583,7 @@ // Use Font-Awesome for displaying lock and pin icons, instead of the images in static/. // http://fortawesome.github.io/Font-Awesome/icon/pushpin/ // http://fortawesome.github.io/Font-Awesome/icon/lock/ - $config['font_awesome'] = false; + $config['font_awesome'] = true; $config['font_awesome_css'] = 'stylesheets/font-awesome/css/font-awesome.min.css'; // Boardlinks @@ -1062,6 +1062,8 @@ $config['mod']['rebuild'] = ADMIN; // Search through posts, IP address notes and bans $config['mod']['search'] = JANITOR; + // Allow searching posts (can be used with board configuration file to disallow searching through a certain board) + $config['mod']['search_posts'] = JANITOR; // Read the moderator noticeboard $config['mod']['noticeboard'] = JANITOR; // Post to the moderator noticeboard diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 1e47ea21..edb14c6d 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -225,7 +225,7 @@ function mod_search($type, $search_query_escaped, $page_no = 1) { // Which `field` to search? if ($type == 'posts') - $sql_field = 'body'; + $sql_field = 'body_nomarkup'; if ($type == 'IP_notes') $sql_field = 'body'; if ($type == 'bans') @@ -246,7 +246,27 @@ function mod_search($type, $search_query_escaped, $page_no = 1) { // Compile SQL query if ($type == 'posts') { - error('Searching posts is under development. Sorry.'); + $query = ''; + + $boards = listBoards(); + if (empty($boards)) + error(_('There are no boards to search!')); + + foreach ($boards as $board) { + openBoard($board['uri']); + if (!hasPermission($config['mod']['search_posts'], $board['uri'])) + continue; + + if (!empty($query)) + $query .= ' UNION ALL '; + $query .= sprintf("SELECT *, '%s' AS `board` FROM `posts_%s` WHERE %s", $board['uri'], $board['uri'], $sql_like); + } + + // You weren't allowed to search any boards + if (empty($query)) + error($config['error']['noaccess']); + + $query .= ' ORDER BY `sticky` DESC, `id` DESC'; } if ($type == 'IP_notes') { @@ -273,10 +293,15 @@ function mod_search($type, $search_query_escaped, $page_no = 1) { // Execute SQL query (with pages) $q = query($query . ' LIMIT ' . (($page_no - 1) * $config['mod']['search_page']) . ', ' . $config['mod']['search_page']) or error(db_error()); $results = $q->fetchAll(PDO::FETCH_ASSOC); - + // Get total result count - $q = query('SELECT COUNT(*) FROM `' . $sql_table . '` WHERE ' . $sql_like) or error(db_error()); - $result_count = $q->fetchColumn(); + if ($type == 'posts') { + $q = query("SELECT COUNT(*) FROM ($query) AS `tmp_table`") or error(db_error()); + $result_count = $q->fetchColumn(); + } else { + $q = query('SELECT COUNT(*) FROM `' . $sql_table . '` WHERE ' . $sql_like) or error(db_error()); + $result_count = $q->fetchColumn(); + } if ($type == 'bans') { foreach ($results as &$ban) { @@ -285,6 +310,12 @@ function mod_search($type, $search_query_escaped, $page_no = 1) { } } + if ($type == 'posts') { + foreach ($results as &$post) { + $post['snippet'] = pm_snippet($post['body']); + } + } + // $results now contains the search results mod_page(_('Search results'), 'mod/search_results.html', array( diff --git a/templates/mod/news.html b/templates/mod/news.html index b6c35798..b0335e0a 100644 --- a/templates/mod/news.html +++ b/templates/mod/news.html @@ -52,7 +52,7 @@ <em>{% trans 'no subject' %}</em> {% endif %} <small class="unimportant"> - — {% trans 'by' %} {{ post.name }} {% trans 'at' %} {{ notice.time|date(config.post_date) }} + — {% trans 'by' %} {{ post.name }} {% trans 'at' %} {{ post.time|date(config.post_date) }} </small> </h2> <p> diff --git a/templates/mod/search_results.html b/templates/mod/search_results.html index b441a28f..aeaf57b0 100644 --- a/templates/mod/search_results.html +++ b/templates/mod/search_results.html @@ -39,7 +39,7 @@ </tr> {% endfor %} </table> -{% endif %} +{% endif %} {% if search_type == 'bans' %} <table class="modlog" style="width:100%"> @@ -125,7 +125,7 @@ </tr> {% endfor %} </table> -{% endif %} +{% endif %} {% if search_type == 'log' %} <table class="modlog"> @@ -166,7 +166,98 @@ </tr> {% endfor %} </table> -{% endif %} +{% endif %} + +{% if search_type == 'posts' %} + <table class="modlog"> + <tr> + <th>Time</th> + <th>Board</th> + <th>ID</th> + <th>Thread</th> + <th>IP</th> + <th>Name</th> + <th>Subject</th> + <th>File</th> + <th>Body (snippet)</th> + </tr> + {% for post in results %} + <tr> + <td class="minimal"> + <small>{{ post.time | ago }} ago</small> + </td> + <td class="minimal"> + <a href="?/{{ config.board_path|sprintf(post.board) }}{{ config.file_index }}">{{ config.board_abbreviation|sprintf(post.board) }}</a> + </td> + <td class="minimal"> + {% if post.thread %} + {% set thread = post.thread %} + {% else %} + {% set thread = post.id %} + {% endif %} + <a href="{{ config.root ~ post.board ~ '/' ~ config.dir.res}}{{ config.file_page|sprintf(thread) }}#{{ post.id }}"> + {{ post.id }} + </a> + </td> + <td class="minimal"> + <small> + {% if post.thread %} + {{ post.thread }} + {% else %} + (OP) + {% endif %} + </small> + </td> + <td class="minimal"> + {% if mod|hasPermission(config.mod.show_ip, post.board) %} + <a href="?/IP/{{ post.ip }}"> + {{ post.ip }} + </a> + {% else %} + <em>hidden</em> + {% endif %} + </td> + <td style="max-width:100px"> + <small> + {% if post.email|length > 0 %} + {# start email #} + <a class="email" href="mailto:{{ post.email }}"> + {% endif %} + {% set capcode = post.capcode|capcode %} + <span {% if capcode.name %}style="{{ capcode.name }}" {% endif %}class="name">{{ post.name }}</span> + {% if post.trip|length > 0 %} + <span {% if capcode.trip %}style="{{ capcode.trip }}" {% endif %}class="trip">{{ post.trip }}</span> + {% endif %} + {% if post.email|length > 0 %} + {# end email #} + </a> + {% endif %} + {% if capcode %} + {{ capcode.cap }} + {% endif %} + </small> + </td> + <td style="max-width:250px"> + {% if post.subject %} + <small>{{ post.subject }}</small> + {% else %} + – + {% endif %} + </td> + <td style="max-width:200px"> + {% if post.file %} + <small>{{ post.file }} ({{ post.filesize | filesize }})</small> + {% else %} + – + {% endif %} + </td> + <td> + <small><em>{{ post.snippet }}</em></small> + </td> + </tr> + {% endfor %} + </table> +{% endif %} {% if result_count > results|count %} <p class="unimportant" style="text-align:center;word-wrap:break-word"> |
