Last active
December 26, 2016 23:59
-
-
Save AmauryCarrade/58ec37a2d92ce9f4423f57f71fc09416 to your computer and use it in GitHub Desktop.
Per-thread search for FluxBB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/search.php b/search.php | |
index 28c4661..0822fd2 100755 | |
--- a/search.php | |
+++ b/search.php | |
@@ -29,6 +29,7 @@ if (isset($_GET['action']) || isset($_GET['search_id'])) | |
{ | |
$action = (isset($_GET['action'])) ? $_GET['action'] : null; | |
$forum = (isset($_GET['forum'])) ? intval($_GET['forum']) : -1; | |
+ $topic = (isset($_GET['topic'])) ? intval($_GET['topic']) : -1; | |
$sort_dir = (isset($_GET['sort_dir']) && $_GET['sort_dir'] == 'DESC') ? 'DESC' : 'ASC'; | |
// If a search_id was supplied | |
@@ -102,6 +103,9 @@ if (isset($_GET['action']) || isset($_GET['search_id'])) | |
// Search a specific forum? | |
$forum_sql = ($forum != -1 || ($forum == -1 && $pun_config['o_search_all_forums'] == '0' && !$pun_user['is_admmod'])) ? ' AND t.forum_id = '.$forum : ''; | |
+ // Search a specific topic? | |
+ $topic_sql = $topic != -1 ? ' AND t.id = ' . $topic : ''; | |
+ | |
if (!empty($author) || !empty($keywords)) | |
{ | |
// Flood protection | |
@@ -174,10 +178,10 @@ if (isset($_GET['action']) || isset($_GET['search_id'])) | |
$where_cond = str_replace('*', '%', $cur_word); | |
$where_cond = ($search_in ? (($search_in > 0) ? 'p.message LIKE \'%'.$db->escape($where_cond).'%\'' : 't.subject LIKE \'%'.$db->escape($where_cond).'%\'') : 'p.message LIKE \'%'.$db->escape($where_cond).'%\' | |
- $result = $db->query('SELECT p.id AS post_id, p.topic_id, '.$sort_by_sql.' AS sort_by FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'topics AS t ON t.id=p.topic_id LEFT JOIN '.$db->prefix.'forum_pe | |
+ $result = $db->query('SELECT p.id AS post_id, p.topic_id, '.$sort_by_sql.' AS sort_by FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'topics AS t ON t.id=p.topic_id LEFT JOIN '.$db->prefix.'forum_pe | |
} | |
else | |
- $result = $db->query('SELECT m.post_id, p.topic_id, '.$sort_by_sql.' AS sort_by FROM '.$db->prefix.'search_words AS w INNER JOIN '.$db->prefix.'search_matches AS m ON m.word_id = w.id INNER JOIN '.$db->prefi | |
+ $result = $db->query('SELECT m.post_id, p.topic_id, '.$sort_by_sql.' AS sort_by FROM '.$db->prefix.'search_words AS w INNER JOIN '.$db->prefix.'search_matches AS m ON m.word_id = w.id INNER JOIN '.$db->prefi | |
$row = array(); | |
while ($temp = $db->fetch_assoc($result)) | |
@@ -256,7 +260,7 @@ if (isset($_GET['action']) || isset($_GET['search_id'])) | |
while ($row = $db->fetch_row($result)) | |
$user_ids[] = $row[0]; | |
- $result = $db->query('SELECT p.id AS post_id, p.topic_id FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'topics AS t ON t.id=p.topic_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=t.forum_id AND fp.group_id= | |
+ $result = $db->query('SELECT p.id AS post_id, p.topic_id FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'topics AS t ON t.id=p.topic_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=t.forum_id AND fp.group_id= | |
while ($temp = $db->fetch_assoc($result)) | |
$author_results[$temp['post_id']] = $temp['topic_id']; | |
@@ -651,6 +655,24 @@ if (isset($_GET['action']) || isset($_GET['search_id'])) | |
$page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_search['Search']); | |
$focus_element = array('search', 'keywords'); | |
+ | |
+$search_in_topic = isset($_GET['topic']) ? intval($_GET['topic']) : -1; | |
+$topic_subject = ''; | |
+ | |
+if ($search_in_topic != -1) | |
+{ | |
+ // First check if the user is allowed to view this post | |
+ if (!$pun_user['is_guest']) | |
+ $result = $db->query('SELECT t.subject FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS | |
+ else | |
+ $result = $db->query('SELECT t.subject FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS | |
+ | |
+ if (!$db->num_rows($result)) | |
+ message($lang_common['Bad request'], false, 404); | |
+ | |
+ $topic_subject = $db->result($result); | |
+} | |
+ | |
define('PUN_ACTIVE_PAGE', 'search'); | |
require PUN_ROOT.'header.php'; | |
@@ -659,6 +681,12 @@ require PUN_ROOT.'header.php'; | |
<h2><span><?php echo $lang_search['Search'] ?></span></h2> | |
<div class="box"> | |
<form id="search" method="get" action="search.php"> | |
+ <?php if ($search_in_topic != -1): ?> | |
+ <input type="hidden" name="topic" value="<?php echo $search_in_topic; ?>" /> | |
+ <div style="background: rgb(246, 249, 252); border: rgb(223, 230, 238) 1px solid; padding: 12px 18px; margin: 18px 18px 9px;"> | |
+ Vous recherchez dans le sujet <strong><a href="viewtopic.php?id=<?php echo $search_in_topic; ?>"><?php echo $topic_subject; ?></a></strong>. | |
+ </div> | |
+ <?php endif; ?> | |
<div class="inform"> | |
<fieldset> | |
<legend><?php echo $lang_search['Search criteria legend'] ?></legend> | |
@@ -670,6 +698,7 @@ require PUN_ROOT.'header.php'; | |
</div> | |
</fieldset> | |
</div> | |
+ <?php if ($search_in_topic == -1): ?> | |
<div class="inform"> | |
<fieldset> | |
<legend><?php echo $lang_search['Search in legend'] ?></legend> | |
@@ -713,6 +742,7 @@ while ($cur_forum = $db->fetch_assoc($result)) | |
</div> | |
</fieldset> | |
</div> | |
+ <?php endif; ?> | |
<div class="inform"> | |
<fieldset> | |
<legend><?php echo $lang_search['Search results legend'] ?></legend> | |
@@ -732,8 +762,8 @@ while ($cur_forum = $db->fetch_assoc($result)) | |
</select> | |
<br /></label> | |
<label class="conl"><?php echo $lang_search['Show as']."\n" ?> | |
- <br /><select name="show_as"> | |
- <option value="topics"><?php echo $lang_search['Show as topics'] ?></option> | |
+ <br /><select name="show_as"<?php if ($search_in_topic != -1): ?> disabled="disabled"<?php endif; ?>> | |
+ <?php if ($search_in_topic == -1): ?><option value="topics"><?php echo $lang_search['Show as topics'] ?></option><?php endif; ?> | |
<option value="posts"><?php echo $lang_search['Show as posts'] ?></option> | |
</select> | |
<br /></label> | |
@@ -748,3 +778,4 @@ while ($cur_forum = $db->fetch_assoc($result)) | |
<?php | |
require PUN_ROOT.'footer.php'; | |
+ | |
diff --git a/viewtopic.php b/viewtopic.php | |
index 0d0fcfc..ce61fa9 100755 | |
--- a/viewtopic.php | |
+++ b/viewtopic.php | |
@@ -160,9 +160,9 @@ if (!$pun_user['is_guest'] && $pun_config['o_subscriptions'] == '1') | |
{ | |
if ($cur_topic['is_subscribed']) | |
// I apologize for the variable naming here. It's a mix of subscription and action I guess :-) | |
- $subscraction = "\t\t".'<p class="subscribelink clearb"><span>'.$lang_topic['Is subscribed'].' - </span><a href="misc.php?unsubscribe='.$id.'">'.$lang_topic['Unsubscribe'].'</a></p>'."\n"; | |
+ $subscraction = "\t\t".'<span>'.$lang_topic['Is subscribed'].' - </span><a href="misc.php?unsubscribe='.$id.'">'.$lang_topic['Unsubscribe'].'</a>'."\n"; | |
else | |
- $subscraction = "\t\t".'<p class="subscribelink clearb"><a href="misc.php?subscribe='.$id.'">'.$lang_topic['Subscribe'].'</a></p>'."\n"; | |
+ $subscraction = "\t\t".'<a href="misc.php?subscribe='.$id.'">'.$lang_topic['Subscribe'].'</a>'."\n"; | |
} | |
else | |
$subscraction = ''; | |
@@ -487,7 +487,7 @@ while ($cur_post = $db->fetch_assoc($result)) | |
} | |
?> | |
-<div class="postlinksb"> | |
+<div class="postlinksb"<?php if (!empty($subscraction)): ?> style="margin-bottom: 18px;"<?php endif; ?>> | |
<div class="inbox crumbsplus"> | |
<div class="pagepost"> | |
<p class="pagelink conl"><?php echo $paging_links ?></p> | |
@@ -498,7 +498,11 @@ while ($cur_post = $db->fetch_assoc($result)) | |
<li><span>» </span><a href="viewforum.php?id=<?php echo $cur_topic['forum_id'] ?>"><?php echo pun_htmlspecialchars($cur_topic['forum_name']) ?></a></li> | |
<li><span>» </span><strong><?php echo pun_htmlspecialchars($cur_topic['subject']) ?></strong></li> | |
</ul> | |
-<?php echo $subscraction ?> | |
+ <p class="subscribelink clearb"> | |
+ <?php echo $subscraction ?> | |
+ <?php if (!empty($subscraction)): ?><br /><?php endif; ?> | |
+ <a href="search.php?topic=<?php echo $id; ?>">Rechercher dans ce sujet</a> | |
+ </p> | |
<div class="clearer"></div> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment