forums plugin missing line of code, I think

By Dave - July 22, 2017

Great find, Wizzle.

That line was missing and it sounds like you added it back in the right place.  

I've released an update with that fix and PHP 7 support.

Thanks for letting us know, much appreciated!

Dave Edis - Senior Developer
interactivetools.com

By wizzle - July 25, 2017

Thanks Dave.

I asked in another thread about a similar issue but it has not received any replies...

Basically I can't figure out how the "subscribe to category" feature works for simple forum.  Is it

If an account is subscribed to an entire category, do they...

A. get emails for all new threads within the category AND for all replies to threads in the category

OR

B. get emails ONLY when a new thread is created (but not the replies to an existing thread).

I assumed it was going to be option B, but based on my user feedback I think it is currently functioning as option A.  

How could I modify the line on  /forum/forum-posts-reply.php (the code that was missing) so that replies to a topic only send emails to people specifically subscribed to that topic, but not to people that are just generally subscribed to the entire category.

I am hoping to achieve option B above.

Greg Williams

By Dave - July 28, 2017

Hi Wizzle, 

It works as you describe in option A:

>A. get emails for all new threads within the category AND for all replies to threads in the category

How could I modify the line on  /forum/forum-posts-reply.php (the code that was missing) so that replies to a topic only send emails to people specifically subscribed to that topic, but not to people that are just generally subscribed to the entire category.

Hmm, there's no easy way to do that.  What you'd probably need to do was modify sforum_sendFollowersPostNotifications() to check how many posts were in a topic ( $topic['posts'] ) and then update sforum_db_getFollowerEmails() to only return forum subscriber emails if the topic only had 1 post.  

It would take a bit of custom programming and experimentation.

Dave Edis - Senior Developer
interactivetools.com

By wizzle - August 1, 2017

Thanks Dave.

I'm digging deep for a little help here. I really have no idea what I'm doing, but I think I've found a route to make this change pretty easy.  But in order to test it, I'll have to set up a new site, install CMSB, membership plugin, forum plugin etc to have a testing playground (my site that I need it for is now active.) So before I go through all that, let me know if this approach sound decent (pretty please!)

Currently, the page creating a new topic (forum-topics-create.php) and the page generating a reply to a topic (forum-posts-reply.php) both use the same function to send the email notifications. It's called sforum_sendFollowersPostNotifications($post, $topic, $forum);  

That function exists on the page simpleForum.php, but within that function is a call to another function  foreach (sforum_db_getFollowerEmails($topic['num'], $forum['num']) as $followerEmail) . This function seems to be where the list of people following a specific topic are joined together with those follow the entire category to make a single array of email addresses for the notification.  The function code looks like

function sforum_db_getFollowerEmails($topicNum, $forumNum) {
  global $TABLE_PREFIX;
  $followersQuery   = mysql_escapef("SELECT tu.email
                                      FROM `{$TABLE_PREFIX}_frm_topic_follow` tf
                                      JOIN `{$TABLE_PREFIX}".accountsTable()."` tu
                                        ON tf.userNum = tu.num
                                      WHERE tf.topicNum = ?
                                      UNION
                                      SELECT fu.email
                                      FROM `{$TABLE_PREFIX}_frm_forum_follow` ff
                                      JOIN `{$TABLE_PREFIX}".accountsTable()."` fu
                                        ON ff.userNum = fu.num
                                      WHERE ff.forumNum = ? 
                                       ", $topicNum, $forumNum  );
  $followers = mysql_fetch($followersQuery);
  return array_pluck($followers, 'email');
}

My Plan is basically this...

1. Leave the sforum_db_getFollowerEmails function alone, but make another very similar function that does not combine the general category followers but instead it only includes the followers of the specific topic.  I would call it sforum_db_getReplyFollowerEmails.

2. Leave the sforum_sendFollowersPostNotifications function alone, but make another very similar function called sforum_sendReplyFollowersPostNotifications .  The only difference is that this function would call the new sforum_db_getReplyFollowerEmails from step 1.

3. On forum-posts-reply.php replace sforum_sendFollowersPostNotifications($post, $topic, $forum);
with sforum_sendReplyFollowersPostNotifications($post, $topic, $forum);

If that plan seems reasonable, I would just need help modifying the QUERY in the code block above. 

Greg Williams

By Dave - August 8, 2017

Hi wizzle, 

Sounds good.  You're getting into some pretty advanced code here.  If at any point you want us to do some consulting to get this working for you just email me direct at dave@interactivetools.com.  Beyond that, you can split the query in sforum_db_getFollowerEmails()  into two queries, and debug it by calling sforum_db_getFollowerEmails() directly from a test script.  Or create a copy of the function sforum_db_getFollowerEmails2().

Let me know how it goes!

Dave Edis - Senior Developer
interactivetools.com

By wizzle - August 17, 2017

Thanks Dave. I'm a novice so this will take some digging on my part.

I did just notice that the auto-generated emails say 

If you don't want to receive updates on this forum topic, please unsubscribe.

So what if I unsubscribe from the forum topic, but I'm still subscribed to the overall forum Category?  Does this link prevent me from getting email notices for replies to that specific topic even if I am subscribed to the entire Forum Category, or does the category subscription override the individual topics?

Greg Williams

By Dave - September 6, 2017

Hi Wizzle, 

Just wanted to follow up and see if you made any progress with this?  I believe the category subscription overrides.  If you want some minor enhancements to the plugin let me know what they are and I can take a look.

Dave Edis - Senior Developer
interactivetools.com