Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

FEATURE: subscribe to thread / unsubscribe without having to write / …

…edit a post in that thread. BUGFIX: Forum Views are now logged to session so you cannot refresh the page 400 times and get 400 vies
  • Loading branch information...
commit 8829d06276cb5a33e2557c6f2443050fce86811f 1 parent e19f01b
Will Rossiter authored
View
50 code/Forum.php
@@ -481,6 +481,56 @@ function StartTopicLink(){
}
/**
+ * Subscribe to thread link
+ *
+ * @return String
+ */
+ function SubscribeLink() {
+ if(Post_Subscription::already_subscribed(Director::urlParam('ID'))) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Subscribe a user to a thread given by an ID.
+ *
+ * Designed to be called via AJAX so return true / false
+ * @return Boolean | Redirection for non AJAX requests
+ */
+ function subscribe() {
+ if(Member::currentUser() && !Post_Subscription::already_subscribed(Director::urlParam('ID'))) {
+ $obj = new Post_Subscription;
+ $obj->TopicID = Director::urlParam('ID');
+ $obj->MemberID = Member::currentUserID();
+ $obj->LastSent = date("Y-m-d H:i:s"); // The user was last notified right now
+ $obj->write();
+ if(Director::is_ajax()) return true;
+ return Director::redirectBack();
+ }
+ return false;
+ }
+
+ /**
+ * Unsubscribe a user from a thread by an ID
+ *
+ * Designed to be called via AJAX so return true / false
+ * @return Boolean | Redirection for non AJAX requests
+ */
+ function unsubscribe() {
+ if(Member::currentUser() && Post_Subscription::already_subscribed(Director::urlParam('ID'))) {
+ $SQL_memberID = Member::currentUserID();
+ $topicID = (int) Director::urlParam('ID');
+ DB::query("DELETE FROM Post_Subscription WHERE `TopicID` = '$topicID' AND `MemberID` = '$SQL_memberID'");
+ if(Director::is_ajax()) return true;
+ return Director::redirectBack();
+ }
+ return false;
+ }
+
+
+
+ /**
* Get the view mode
*
* @return string Returns the view mode
View
15 code/Post.php
@@ -225,12 +225,19 @@ function NumReplies() {
/**
- * Increment the NumViews value by 1. Write just that number straight to the database
+ * Check if they have visited this thread before. If they haven't increment
+ * the NumViews value by 1 and set visited to true
+ *
+ * Write just that number straight to the database
*/
function incNumViews() {
- $this->NumViews++;
- $SQL_numViews = Convert::raw2sql($this->NumViews);
- DB::query("UPDATE Post SET NumViews = '$SQL_numViews' WHERE ID = $this->ID");
+ if(Session::get($_SESSION['SERVER_NAME']."ForumViewed-".$this->ID)) return false;
+ else {
+ Session::set($_SESSION['SERVER_NAME']."ForumViewed-".$this->ID, 'true');
+ $this->NumViews++;
+ $SQL_numViews = Convert::raw2sql($this->NumViews);
+ DB::query("UPDATE Post SET NumViews = '$SQL_numViews' WHERE ID = $this->ID");
+ }
}
View
20 css/Forum.css
@@ -280,7 +280,7 @@ table.postHeader td.gotoButton {
width: 60%;
}
table.postHeader td.replyButton {
- width: 20%;
+ width: 160px;
}
table.postHeader td.author {
padding-left: 5px;
@@ -298,10 +298,26 @@ table.postHeader td.replyButton a {
text-decoration: none;
width: 58px;
height: 20px;
- padding: 3px 11px 5px 11px;
+ float: left;
+ text-align: center;
+ line-height: 20px;
font-size: 12px;
font-weight: bold;
}
+ table.postHeader td.replyButton a.subscribe,
+ table.postHeader td.replyButton a.unsubscribe {
+ background: url(../../forum/images/subscribeButton.gif) no-repeat top left;
+ padding: 0;
+ display: block;
+ width: 96px;
+ height: 20px;
+ float: right;
+ text-align: center;
+ line-height: 20px;
+ }
+ table.postHeader td.replyButton a.hidden {
+ display: none;
+ }
table.postHeader td.replyButton a.next {
color: #d07327;
}
View
BIN  images/subscribeButton.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
22 javascript/forum.js
@@ -87,5 +87,27 @@ $(document).ready(function() {
return false;
});
+ /**
+ * Do the Subscribe / Unsubscribe button
+ */
+ $("td.replyButton a.subscribe").click(function() {
+ $.post($(this).attr("href"), function(data) {
+ if(data == 1) {
+ $("td.replyButton a.subscribe").fadeOut().hide();
+ $("td.replyButton a.unsubscribe").fadeIn();
+ }
+ });
+ return false;
+ });
+
+ $("td.replyButton a.unsubscribe").click(function() {
+ $.post($(this).attr("href"), function(data) {
+ if(data == 1) {
+ $("td.replyButton a.unsubscribe").fadeOut().hide();
+ $("td.replyButton a.subscribe").fadeIn();
+ }
+ });
+ return false;
+ });
})
})(jQuery);
View
3  templates/Layout/Forum_show.ss
@@ -19,6 +19,9 @@
<% if CheckForumPermissions(post) %>
<a href="$ReplyLink" title="<% _t('CLICKREPLY','Click here to reply to this topic') %>"><% _t('REPLY','Reply') %></a>
<% end_if %>
+
+ <a href="{$URLSegment}/unsubscribe/{$Post.TopicID}" class="unsubscribe <% if SubscribeLink %><% else %>hidden<% end_if %>" title="<% _t('CLICKUNSUBSCRIBE','Click here to Unsubscribe to this topic') %>"><% _t('UNSUBSCRIBE','Unsubscribe') %></a>
+ <a href="{$URLSegment}/subscribe/{$Post.TopicID}" class="subscribe <% if SubscribeLink %>hidden<% end_if %>" title="<% _t('CLICKSUBSCRIBE','Click here to subscribe to this topic') %>"><% _t('SUBSCRIBE','Subscribe') %></a>
</td>
</tr>
Please sign in to comment.
Something went wrong with that request. Please try again.