Skip to content

Commit

Permalink
Convert follow topic to post request
Browse files Browse the repository at this point in the history
  • Loading branch information
samerton committed Aug 28, 2021
1 parent fed9214 commit 6dd1d50
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
10 changes: 8 additions & 2 deletions custom/templates/DefaultRevamp/forum/view_topic.tpl
Expand Up @@ -56,9 +56,15 @@

<div class="res right floated">
{if isset($UNFOLLOW)}
<a class="ui small primary button" href="{$UNFOLLOW_URL}">{$UNFOLLOW}</a>
<form action="{$UNFOLLOW_URL}" method="post" style="display: inline">
<input type="hidden" value="{$TOKEN}" name="token" />
<button class="ui small primary button">{$UNFOLLOW}</button>
</form>
{elseif isset($FOLLOW)}
<a class="ui small primary button" href="{$FOLLOW_URL}">{$FOLLOW}</a>
<form action="{$FOLLOW_URL}" method="post" style="display: inline">
<input type="hidden" value="{$TOKEN}" name="token" />
<button class="ui small primary button">{$FOLLOW}</button>
</form>
{/if}
{if isset($CAN_MODERATE)}
<form action="{$LOCK_URL}" method="post" id="lockTopic" style="display: none">
Expand Down
44 changes: 23 additions & 21 deletions modules/Forum/pages/forum/view_topic.php
Expand Up @@ -120,27 +120,29 @@
// Follow/unfollow
if (isset($_GET['action'])) {
if ($user->isLoggedIn()) {
switch ($_GET['action']) {
case 'follow':
$already_following = DB::getInstance()->query('SELECT id FROM nl2_topics_following WHERE topic_id = ? AND user_id = ?', array($tid, $user->data()->id));
if (!$already_following->count()) {
$queries->create('topics_following', array(
'topic_id' => $tid,
'user_id' => $user->data()->id,
'existing_alerts' => 0
));
Session::flash('success_post', $forum_language->get('forum', 'now_following_topic'));
}
break;
case 'unfollow':
$delete = DB::getInstance()->createQuery('DELETE FROM nl2_topics_following WHERE topic_id = ? AND user_id = ?', array($tid, $user->data()->id));
Session::flash('success_post', $forum_language->get('forum', 'no_longer_following_topic'));
if (isset($_GET['return']) && $_GET['return'] == 'list') {
Redirect::to(URL::build('/user/following_topics'));
die();
}
break;
}
if (Token::check($_POST['token'])) {
switch ($_GET['action']) {
case 'follow':
$already_following = DB::getInstance()->query('SELECT id FROM nl2_topics_following WHERE topic_id = ? AND user_id = ?', array($tid, $user->data()->id));
if (!$already_following->count()) {
$queries->create('topics_following', array(
'topic_id' => $tid,
'user_id' => $user->data()->id,
'existing_alerts' => 0
));
Session::flash('success_post', $forum_language->get('forum', 'now_following_topic'));
}
break;
case 'unfollow':
$delete = DB::getInstance()->createQuery('DELETE FROM nl2_topics_following WHERE topic_id = ? AND user_id = ?', array($tid, $user->data()->id));
Session::flash('success_post', $forum_language->get('forum', 'no_longer_following_topic'));
if (isset($_GET['return']) && $_GET['return'] == 'list') {
Redirect::to(URL::build('/user/following_topics'));
die();
}
break;
}
} else Session::flash('failure_post', $language->get('general', 'invalid_token'));
}

Redirect::to(URL::build('/forum/topic/' . $tid . '-' . $forum->titleToURL($topic->topic_title)));
Expand Down

0 comments on commit 6dd1d50

Please sign in to comment.