diff --git a/e107_plugins/forum/forum_class.php b/e107_plugins/forum/forum_class.php
index a50589441..960e1374d 100644
--- a/e107_plugins/forum/forum_class.php
+++ b/e107_plugins/forum/forum_class.php
@@ -396,8 +396,8 @@ class e107forum
if($this->track('del', USERID, $threadID))
{
$ret['html'] = IMAGE_untrack;
- $ret['msg'] = "You are no longer tracking this thread."; //TODO LAN
- $ret['status'] = 'ok';
+ $ret['msg'] = LAN_FORUM_8004; // "Email notifications for this topic are now turned off. ";
+ $ret['status'] = 'info';
}
else
{
@@ -410,7 +410,7 @@ class e107forum
{
if($this->track('add', USERID, $threadID))
{
- $ret['msg'] = "You are now tracking this thread. "; //TODO LAN
+ $ret['msg'] = LAN_FORUM_8003; // "Email notifications for this topic are now turned on. ";
$ret['html'] = IMAGE_track;
$ret['status'] = 'ok';
}
@@ -748,10 +748,11 @@ class e107forum
return -1;
}
+
+
$addUserPostCount = true;
$result = false;
- $e107 = e107::getInstance();
$sql = e107::getDb();
$info = array();
$tp = e107::getParser();
@@ -762,9 +763,17 @@ class e107forum
$info['data'] = $postInfo;
$postId = $sql->insert('forum_post', $info);
- // Append last inserted ID to data array for passing it to event callbacks.
- $info['data']['post_id'] = $postId;
+
+ $info['data']['post_id'] = $postId; // Append last inserted ID to data array for passing it to event callbacks.
+
+
+
e107::getEvent()->trigger('user_forum_post_created', $info);
+
+ ob_start(); // precaution so json doesn't break.
+ $this->trackEmail($info['data']);
+ ob_end_clean();
+
$forumInfo = array();
if($postId && $updateThread)
@@ -838,6 +847,10 @@ class e107forum
';
$result = $sql->gen($qry);
}
+
+
+
+
return $postId;
}
@@ -1602,6 +1615,15 @@ class e107forum
}
+
+ /**
+ * Topic/Thread tracking add/remove
+ * @param $which
+ * @param $uid
+ * @param $threadId
+ * @param bool|false $force
+ * @return bool|int
+ */
function track($which, $uid, $threadId, $force=false)
{
$sql = e107::getDb();
@@ -1634,6 +1656,109 @@ class e107forum
}
+ /**
+ * Send an email to users who are tracking the topic/thread.
+ * @param $post
+ * @return bool
+ */
+ function trackEmail($post)
+ {
+ $sql = e107::getDb();
+ $tp = e107::getParser();
+
+ $trackingPref = $this->prefs->get('track');
+
+ if(empty($trackingPref))
+ {
+ return false;
+ }
+
+ $data = $sql->retrieve('SELECT t.*, u.user_id, u.user_name, u.user_email, u.user_lastvisit FROM `#forum_track` AS t LEFT JOIN `#user` AS u ON t.track_userid = u.user_id WHERE t.track_thread='.intval($post['post_thread']), true);
+
+ if(empty($data))
+ {
+ return false;
+ }
+
+ $threadData = $this->threadGet($post['post_thread']);
+
+ $recipients = array();
+
+ $thread_name = $tp->toText($threadData['thread_name']);
+ // $thread_name = str_replace('"', '"', $thread_name); // This not picked up by toText();
+ $datestamp = $tp->toDate($post['post_datestamp']);
+ $email_post = $tp->toHTML($post['post_entry'], true);
+
+ // $mail_link = "".SITEURL.$PLUGINS_DIRECTORY."forum/forum_viewtopic.php?".$thread_parent.".last";
+
+ $query = array('last'=>1);
+ $mail_link = e107::url('forum','topic', $threadData, array('mode'=>'full','query'=>$query));
+ $subject = $this->prefs->get('eprefix')." ".$thread_name;
+
+ foreach($data as $row)
+ {
+
+ $recipients[] = array(
+ 'mail_recipient_id' => $row['user_id'],
+ 'mail_recipient_name' => $row['user_name'], // Should this use realname?
+ 'mail_recipient_email' => $row['user_email'],
+ 'mail_target_info' => array(
+ 'USERID' => $row['user_id'],
+ 'DISPLAYNAME' => $row['user_name'],
+ 'SUBJECT' => $subject,
+ 'USERNAME' => $row['user_name'],
+ 'USERLASTVISIT' => $row['user_lastvisit'],
+ // 'UNSUBSCRIBE' => (!in_array($notifyTarget, $exclude)) ? $unsubUrl : '',
+ // 'UNSUBSCRIBE_MESSAGE' => (!in_array($notifyTarget, $exclude)) ? $unsubMessage : '',
+ // 'USERCLASS' => $notifyTarget,
+ 'DATE_SHORT' => $tp->toDate(time(),'short'),
+ 'DATE_LONG' => $tp->toDate(time(),'long'),
+
+
+ )
+ );
+ }
+
+
+ require_once(e_HANDLER.'mail_manager_class.php');
+
+ $mailer = new e107MailManager;
+
+ $vars = array('x'=>USERNAME, 'y'=>$thread_name, 'z'=>$datestamp);
+
+ $message = "[html]".$tp->lanVars(LAN_FORUM_8001, $vars,true)."
".$tp->toEmail($email_post, false)."