forums plugin missing line of code, I think

By wizzle - July 17, 2017

I just downloaded and configured the simple forums plugin within the past week.  It went live today.  I noticed that I was not getting emails when new topics were created in the categories that I am subscribed to (but I was getting emails for individual threads I was subscribed to).

Digging into the files, I found the following code on /forum/forum-posts-reply.php 

//Send thread followers emails letting them know the thread has been updated.
      sforum_sendFollowersPostNotifications($post, $topic, $forum);

Which is the code that was sending me emails properly when someone replied to a thread.

I looked for something similar in /forum/forum-topics-create.php that would generate an email when a NEW topic was created but I couldn't find it anywhere.  After looking at the function, it seemed to me that the same function is used to send both emails (new topics and replies). So I just copied the code into the forum-topics-create.php file and tested it.  It seemed to work fine!  

I just re-downloaded the simple forum plugin and checked it from a fresh download ... the code is missing from forum-topics-create.php

So my question is this...

Was I right to insert that code so that email will get sent when someone subscribes to a forum ... or is there a different code that does that and I am just not seeing it.  My fix seemed to work but I'm nervous it wasn't the right thing to do.  Is the sforum_sendFollowersPostNotifications functions intended to send both types of subscriber emails or is there a different function I should be using?

thanks.

Greg Williams

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 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