From 5bab0418142fb2b9d37389f68733faa76c381ffe Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Mon, 29 Jul 2013 12:27:10 -0400 Subject: [PATCH 1/4] Make font-awesome enabled by default --- inc/config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/config.php b/inc/config.php index d7580a8b..7dda86ab 100644 --- a/inc/config.php +++ b/inc/config.php @@ -568,7 +568,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 From c0e0a5db7d566aed16d5d9d9036a1f46f658e9eb Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Mon, 29 Jul 2013 13:14:21 -0400 Subject: [PATCH 2/4] Error in news template --- templates/mod/news.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 @@ {% trans 'no subject' %} {% endif %} - — {% trans 'by' %} {{ post.name }} {% trans 'at' %} {{ notice.time|date(config.post_date) }} + — {% trans 'by' %} {{ post.name }} {% trans 'at' %} {{ post.time|date(config.post_date) }}

From 58306bdc63b7dcaf964ab3541fe4b5a8e0c813b0 Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Mon, 29 Jul 2013 16:18:06 -0400 Subject: [PATCH 3/4] Search posts --- inc/config.php | 2 + inc/mod/pages.php | 41 +++++++++++++++-- templates/mod/search_results.html | 97 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 132 insertions(+), 8 deletions(-) diff --git a/inc/config.php b/inc/config.php index 7dda86ab..582c3145 100644 --- a/inc/config.php +++ b/inc/config.php @@ -1035,6 +1035,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 01794d2e..8289d0b0 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/search_results.html b/templates/mod/search_results.html index b441a28f..035773fb 100644 --- a/templates/mod/search_results.html +++ b/templates/mod/search_results.html @@ -39,7 +39,7 @@ {% endfor %} -{% endif %} +{% endif %} {% if search_type == 'bans' %} @@ -125,7 +125,7 @@ {% endfor %}
-{% endif %} +{% endif %} {% if search_type == 'log' %} @@ -166,7 +166,98 @@ {% endfor %}
-{% endif %} +{% endif %} + +{% if search_type == 'posts' %} + + + + + + + + + + + + + {% for post in results %} + + + + + + + + + + + + {% endfor %} +
TimeBoardIDThreadIPNameSubjectFileBody (snippet)
+ {{ post.time | ago }} ago + + {{ config.board_abbreviation|sprintf(post.board) }} + + {% if post.thread %} + {% set thread = post.thread %} + {% else %} + {% set thread = post.id %} + {% endif %} + + {{ post.id }} + + + + {% if post.thread %} + {{ post.thread }} + {% else %} + (OP) + {% endif %} + + + {% if mod|hasPermission(config.mod.show_ip, post.board) %} + + {{ post.ip }} + + {% else %} + hidden + {% endif %} + + + {% if post.email|length > 0 %} + {# start email #} + + {% endif %} + {% if capcode %} + {{ capcode.cap }} + {% endif %} + + + {% if post.subject %} + {{ post.subject }} + {% else %} + – + {% endif %} + + {% if post.file %} + {{ post.file }} ({{ post.filesize | filesize }}) + {% else %} + – + {% endif %} + + {{ post.snippet }} +
+{% endif %} {% if result_count > results|count %}

From c8e93f04d2522224dd84b7d93e526b918a105451 Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Mon, 29 Jul 2013 16:24:11 -0400 Subject: [PATCH 4/4] Update search results template --- templates/mod/search_results.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/mod/search_results.html b/templates/mod/search_results.html index 035773fb..aeaf57b0 100644 --- a/templates/mod/search_results.html +++ b/templates/mod/search_results.html @@ -189,7 +189,7 @@ {{ config.board_abbreviation|sprintf(post.board) }} - + {% if post.thread %} {% set thread = post.thread %} {% else %} @@ -217,7 +217,7 @@ hidden {% endif %} - + {% if post.email|length > 0 %} {# start email #} @@ -237,14 +237,14 @@ {% endif %} - + {% if post.subject %} {{ post.subject }} {% else %} – {% endif %} - + {% if post.file %} {{ post.file }} ({{ post.filesize | filesize }}) {% else %}