Permalink
Browse files

Merge pull request #205 from hailwood/patch-1

Allow Subscribe/Unsubscribe to be called without ajax
  • Loading branch information...
2 parents 094b15f + db7cdca commit 40b3d1a3cdc6cc090b07c66bb4bafabc5cc11fef @dhensby dhensby committed May 23, 2017
Showing with 8 additions and 5 deletions.
  1. +8 −5 code/pagetypes/Forum.php
View
@@ -626,6 +626,8 @@ public function subscribe(SS_HTTPRequest $request)
if (!SecurityToken::inst()->checkRequest($request)) {
return $this->httpError(400);
}
+
+ $subscribed = false;
if (Member::currentUser() && !ForumThread_Subscription::already_subscribed($this->urlParams['ID'])) {
$obj = new ForumThread_Subscription();
@@ -634,10 +636,10 @@ public function subscribe(SS_HTTPRequest $request)
$obj->LastSent = date("Y-m-d H:i:s");
$obj->write();
- die('1');
+ $subscribed = true;
}
- return false;
+ return ($request->isAjax()) ? $subscribed : $this->redirectBack();
}
/**
@@ -650,6 +652,7 @@ public function subscribe(SS_HTTPRequest $request)
public function unsubscribe(SS_HTTPRequest $request)
{
$member = Member::currentUser();
+ $unsubscribed = false;
if (!$member) {
Security::permissionFailure($this, _t('LOGINTOUNSUBSCRIBE', 'To unsubscribe from that thread, please log in first.'));
@@ -660,11 +663,11 @@ public function unsubscribe(SS_HTTPRequest $request)
DELETE FROM \"ForumThread_Subscription\"
WHERE \"ThreadID\" = '". Convert::raw2sql($this->urlParams['ID']) ."'
AND \"MemberID\" = '$member->ID'");
-
- die('1');
+
+ $unsubscribed = true;
}
- return false;
+ return ($request->isAjax()) ? $unsubscribed : $this->redirectBack();
}
/**

0 comments on commit 40b3d1a

Please sign in to comment.