function NotifiDiscussion($DiscussionForm) { // Only continue if this is a new post, not an edited one if ($_POST['CommentID'] == "0") { // Default variable values for this function set here $SubscribedOnOwn = "no"; if ($DiscussionForm->Context->Configuration['NOTIFI_FORMAT_PLAINTEXT'] == 0) { // Make Vanilla send the email/s as HTML instead of plain text $DiscussionForm->Context->Configuration['DEFAULT_EMAIL_MIME_TYPE'] = 'text/html'; } $DiscussionID = @$DiscussionForm->DelegateParameters['ResultDiscussion']->DiscussionID; if ($DiscussionID > 0) { #Detect if Whispered $result = mysql_query("SELECT WhisperUserID FROM " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "Discussion WHERE DiscussionID = '{$DiscussionID}'"); $row = mysql_fetch_row($result); if ($row[0] > 0) { $Whispered = 1; } else { $Whispered = 0; } $WhisperUserID = $row[0]; if (notifiCheck($DiscussionForm->Context, 'SubscribeOwn')) { ChangeNotifi($DiscussionForm->Context, 'DISCUSSION', $DiscussionID, 1); $SubscribedOnOwn = "yes"; } } else { $DiscussionID = @$DiscussionForm->DelegateParameters['ResultComment']->DiscussionID; #Detect if Whispered $mTitle = @$DiscussionForm->DelegateParameters['ResultComment']->Title; $CommentID = @$DiscussionForm->DelegateParameters['ResultComment']->CommentID; $result = mysql_query("SELECT WhisperUserID FROM " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "Discussion WHERE DiscussionID = '{$DiscussionID}'"); $row = mysql_fetch_row($result); if ($row[0] > 0) { $Whispered = 1; } else { $Whispered = 0; } $WhisperUserID = $row[0]; if ($Whispered == 0) { $result = mysql_query("SELECT WhisperUserID FROM " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "Comment WHERE CommentID = '{$CommentID}'"); $row = mysql_fetch_row($result); if ($row[0] > 0) { $Whispered = 1; } else { $Whispered = 0; $WhisperUserID = $row[0]; } } } if ($DiscussionID > 0) { $Notifieusers = array(); $SelfUser = $DiscussionForm->Context->Session->UserID; if ($DiscussionForm->Context->Configuration['NOTIFI_AUTO_ALL'] == 0) { #Add all users who have subscribed to all, aren't already notified except the posting user if ($DiscussionForm->Context->Configuration['NOTIFI_ALLOW_ALL'] == 1) { $result = mysql_query("SELECT A.UserID,Email,FirstName, LastName, RoleID FROM " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "Notifi AS A, " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "User AS B WHERE A.Method = 'ALL' AND A.UserID <> '{$SelfUser}' AND A.UserID = B.UserID AND (B.Notified = 0 OR B.KeepEmailing = 1)", $DiscussionForm->Context->Database->Connection); while ($row = mysql_fetch_row($result)) { if ($Whispered == 1 and $WhisperUserID == $row[0] or $Whispered == 0) { array_push($Notifieusers, array($row[0], $row[1], $row[2], $row[3], $row[4])); } } } #Add all users who have subscribed to this category , aren't already notified except the posting user if ($DiscussionForm->Context->Configuration['NOTIFI_ALLOW_CATEGORY'] == 1) { $result = mysql_query("SELECT CategoryID FROM " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "Discussion WHERE DiscussionID = '{$DiscussionID}'", $DiscussionForm->Context->Database->Connection); $row = mysql_fetch_row($result); $result2 = mysql_query("SELECT A.UserID,Email,FirstName, LastName, RoleID FROM " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "Notifi AS A, " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "User AS B WHERE A.Method = 'CATEGORY' AND A.SelectID = '{$row['0']}' AND A.UserID <> '{$SelfUser}' AND A.UserID = B.UserID AND (B.Notified = 0 OR B.KeepEmailing = 1)", $DiscussionForm->Context->Database->Connection); while ($row2 = mysql_fetch_row($result2)) { if ($Whispered == 1 and $WhisperUserID == $row2[0] or $Whispered == 0) { array_push($Notifieusers, array($row2[0], $row2[1], $row2[2], $row2[3], $row2[4])); } } } #Add all users who have subscribed to this discussion , aren't already notified except the posting user if ($DiscussionForm->Context->Configuration['NOTIFI_ALLOW_DISCUSSION'] == 1) { $result2 = mysql_query("SELECT A.UserID,Email,FirstName, LastName, RoleID FROM " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "Notifi AS A, " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "User AS B WHERE A.Method = 'DISCUSSION' AND A.SelectID = '{$DiscussionID}' AND A.UserID <> '{$SelfUser}' AND A.UserID = B.UserID AND (B.Notified = 0 OR B.KeepEmailing = 1)", $DiscussionForm->Context->Database->Connection); while ($row2 = mysql_fetch_row($result2)) { if ($Whispered == 1 and $WhisperUserID = $row2[0] or $Whispered == 0) { array_push($Notifieusers, array($row2[0], $row2[1], $row2[2], $row2[3], $row2[4])); } } } } else { #Add all users $result = mysql_query("SELECT UserID,Email,FirstName, LastName, RoleID FROM " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "User WHERE UserID <> '{$SelfUser}' AND (Notified = 0 OR KeepEmailing = 1)", $DiscussionForm->Context->Database->Connection); while ($row = mysql_fetch_row($result)) { if ($Whispered == 1 and $WhisperUserID == $row[0] or $Whispered == 0) { array_push($Notifieusers, array($row[0], $row[1], $row[2], $row[3], $row[4])); } } } // Get the username of the person who posted $mPosterName = notifiCheck($DiscussionForm->Context, 'Name'); #Remove double inserted users array_unique($Notifieusers); // Get the category ID $results = mysql_query("SELECT CategoryID, Name FROM " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "Discussion WHERE DiscussionID = '{$DiscussionID}'", $DiscussionForm->Context->Database->Connection); $row = mysql_fetch_row($results); $categoryID = $row[0]; $discussionName = $row[1]; // Get the comment contents $result = mysql_query("SELECT Body FROM " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "Comment WHERE CommentID = '{$CommentID}'"); $row = mysql_fetch_row($result); if (empty($row[0])) { $mComment = strip_tags($_POST['Body']); } else { $mComment = $row[0]; } $mailsent = array(); // Create the email object $e = $DiscussionForm->Context->ObjectFactory->NewContextObject($DiscussionForm->Context, 'Email'); $e->HtmlOn = 1; // Build an array that contains roles that are blocked from viewing this category $results = mysql_query("SELECT * FROM " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "CategoryRoleBlock WHERE CategoryID = '{$categoryID}' AND Blocked = '1'", $DiscussionForm->Context->Database->Connection); $rolesAry = array(); while ($row = mysql_fetch_row($results)) { $rolesAry[] = $row; } // If the user has chosen to be subscribed to every discussion they comment on, subscribe them if (notifiCheck($DiscussionForm->Context, 'SubscribeComment') && $SubscribedOnOwn == "no") { ChangeNotifi($DiscussionForm->Context, 'DISCUSSION', $DiscussionID, 1); } foreach ($Notifieusers as $val) { $roleID = $val[4]; $allowToMail = "yes"; // Check category permissions for ($i = 0; $i < count($rolesAry); $i++) { $record = $rolesAry[$i]; $databaseRoleID = $record[1]; if ($databaseRoleID == $roleID) { $allowToMail = "no"; } } // Check if user is permitted to view this category if ($allowToMail == "yes") { $mName = ''; if ($val[2] != '') { $mName = ' ' . $val[2]; } if ($val[1] != "" and !in_array($val[1], $mailsent)) { if ($val[2] != "" and $val[3] != "") { $NotifiName = ''; } else { $NotifiName = $val[2] . ' ' . $val[3]; } // Begin preparing the email $e->Clear(); $e->AddFrom($DiscussionForm->Context->Configuration['SUPPORT_EMAIL'], $DiscussionForm->Context->Configuration['SUPPORT_NAME']); $e->AddRecipient($val[1], $NotifiName); $e->Subject = $DiscussionForm->Context->Configuration['APPLICATION_TITLE'] . ' Notification'; // Save the ID of the user to be emailed $currentUserId = $val[0]; // Get the last viewed comment from the database $result = mysql_query("SELECT CountComments FROM " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "UserDiscussionWatch WHERE UserID={$currentUserId} AND DiscussionID=" . $DiscussionID, $DiscussionForm->Context->Database->Connection); $list = mysql_fetch_row($result); $countComments = $list[0]; // Find out which page to go to $commentsPerPage = $DiscussionForm->Context->Configuration['COMMENTS_PER_PAGE']; $pageNumber = ceil(($countComments + 1) / $commentsPerPage); // Find out which comment to tell the browser to jump to $commentNo = $countComments[strlen($countComments) - 1]; if (empty($commentNo)) { $commentNo = "1"; } // See if the admin has chosen to send emails as plaintext if ($DiscussionForm->Context->Configuration['NOTIFI_FORMAT_PLAINTEXT'] == 1) { // If this is a new comment in an existing discussion if (isset($CommentID)) { $message = ' Hello ' . $mName . ', The following comment was posted by ' . $mPosterName . ' in the discussion: ' . $discussionName . ' ' . $mComment . ' Visit the following URL to view the comment on the forum: ' . $DiscussionForm->Context->Configuration['BASE_URL'] . 'comments.php?DiscussionID=' . $DiscussionID . '&page=' . $pageNumber . '#Item_' . $commentNo . ' Kind regards, ' . $DiscussionForm->Context->Configuration['SUPPORT_NAME']; } else { $message = ' Hello ' . $mName . ', A new discussion called ' . $discussionName . ' was started by ' . $mPosterName . ', the comment is as follows: ' . $mComment . ' Visit the following URL to view the new discussion on the forum: ' . $DiscussionForm->Context->Configuration['BASE_URL'] . 'comments.php?DiscussionID=' . $DiscussionID . '&page=' . $pageNumber . '#Item_' . $commentNo . ' Kind regards, ' . $DiscussionForm->Context->Configuration['SUPPORT_NAME']; } } else { // If BBCode support is enabled, process it if ($DiscussionForm->Context->Configuration['NOTIFI_ALLOW_BBCODE'] == 1) { $mComment = htmlentities($mComment); $bbSearch = array('/\\[b\\](.*?)\\[\\/b\\]/is', '/\\[i\\](.*?)\\[\\/i\\]/is', '/\\[url\\=(.*?)\\](.*?)\\[\\/url\\]/is', '/\\[url\\](.*?)\\[\\/url\\]/is', '/\\[img\\](.*?)\\[\\/img\\]/is', '/\\[br\\]/is'); $bbReplace = array('<strong>$1</strong>', '<em>$1</em>', '<a href="$1">$2</a>', '<a href="$1">$1</a>', '<img src="$1" />', '<br />'); $mComment = preg_replace($bbSearch, $bbReplace, $mComment); } // Insert line breaks in the comment $mComment = nl2br($mComment); // If this is a new comment in an existing discussion if (isset($CommentID)) { $message = ' <html> <body style="background-color:#fff;"> Hello ' . $mName . ',<br /><br /> The following comment was posted in the discussion <strong>' . $discussionName . '</strong>. <div style="margin: 20px 0; padding: 10px; background-color: #fef9e9; border: 1px #ffedae solid;"> <p style="padding: 5px; margin: 0 0 5px 0; background-color: #fff; border: 1px #ccc solid;"> Post by: <strong>' . $mPosterName . '</strong> </p> ' . $mComment . '<br /> </div> <a href="' . $DiscussionForm->Context->Configuration['BASE_URL'] . 'comments.php?DiscussionID=' . $DiscussionID . '&page=' . $pageNumber . '#Item_' . $commentNo . '">Click here to view the comment on the forum</a><br /><br /> Kind regards,<br /> ' . $DiscussionForm->Context->Configuration['SUPPORT_NAME'] . ' </body> </html>'; } else { $message = ' <html> <body style="background-color:#fff;"> Hello ' . $mName . ',<br /><br /> A new discussion called <strong>' . $discussionName . '</strong> was started, the comment is as follows. <div style="margin: 20px 0; padding: 10px; background-color: #fef9e9; border: 1px #ffedae solid;"> <p style="padding: 5px; margin: 0 0 5px 0; background-color: #fff; border: 1px #ccc solid;"> Post by: <strong>' . $mPosterName . '</strong> </p> ' . $mComment . '<br /> </div> <a href="' . $DiscussionForm->Context->Configuration['BASE_URL'] . 'comments.php?DiscussionID=' . $DiscussionID . '&page=' . $pageNumber . '#Item_' . $commentNo . '">Click here to view the new discussion on the forum</a><br /><br /> Kind regards,<br /> ' . $DiscussionForm->Context->Configuration['SUPPORT_NAME'] . ' </body> </html>'; } } $e->Body = $message; $e->Send(); array_push($mailsent, $val[1]); mysql_query("UPDATE " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "User SET Notified = 1 WHERE UserID = '" . $val[0] . "'"); } } } } } }
function Render() { if ($this->IsPostBack) { if (notifiCheck($this->Context, 'SubscribedEntireForum')) { $SubscribedEntireForum = ' style="display:none"'; } else { $SubscribedEntireForum = ''; } if (notifiCheck($this->Context, 'SubscribeComment') && $SubscribedEntireForum != ' style="display:none"') { $SubscribedComment = ' style="display:none"'; } else { $SubscribedComment = ''; } $u = $this->Context->Session->UserID; echo ' <div id="Form" class="Account Preferences Notifications"> <fieldset> <legend>' . $this->Context->GetDefinition("EmailNotification") . '</legend> <form method="post" action=""> <p class="Description"> <strong>Changes will be made <strong style="color:#c00;">instantly</strong> when you check/uncheck the boxes.<br /> There is <strong style="color:#c00;">no submit button</strong></strong> </p> <h2>' . $this->Context->GetDefinition("NotificationOptions") . '</h2> <ul> <li> '; $Active = ' '; if (notifiCheck($this->Context, 'SubscribeOwn') == 1) { $Active = 'checked="checked" '; } echo ' <p id="NotifiOwnCont" class="notifiToggleCBox" ' . $SubscribedEntireForum . $SubscribedComment . '> <span> <label for="NotifiOwnField"> <input type="checkbox" name="NOTIFI_OWN" id="NotifiOwnField" ' . $Active . ' /> ' . $this->Context->GetDefinition("NotificationOnOwnExplanation") . ' </label> </span> </p> '; $Active = ' '; if (notifiCheck($this->Context, 'SubscribeComment') == 1) { $Active = 'checked="checked" '; } echo ' <p class="notifiToggleCBox" id="NotifiCommentCont"' . $SubscribedEntireForum . '> <span> <label for="NotifiCommentField"> <input type="checkbox" name="NOTIFY_COMMENT" id="NotifiCommentField" ' . $Active . ' /> ' . $this->Context->GetDefinition("NotificationOnCommentExplanation") . ' </label> </span> </p> '; $Active = ' '; if (notifiCheck($this->Context, 'KeepEmailing') == true) { $Active = 'checked="checked" '; } echo ' <p class="notifiToggleCBox"> <span> <label for="KeepEmailingField"> <input type="checkbox" name="NOTIFI_KEEPEMAILING" id="KeepEmailingField" ' . $Active . ' /> ' . $this->Context->GetDefinition("KeepEmailingExplanation") . ' </label> </span> </p> </li> </ul> <legend>' . $this->Context->GetDefinition("YourNotifications") . '</legend> '; if ($this->Context->Configuration['NOTIFI_ALLOW_ALL'] == 1) { echo ' <h2>Forum</h2> <ul> '; $Active = ' '; if (CheckNotifi($this->Context, 'ALL', 0, $u) == true) { $Active = 'checked="checked" '; } echo ' <li> <p class="notifiToggleCBox"> <span> <label for="NotifiAllField"> <input type="checkbox" name="NOTIFI_ALL" id="NotifiAllField" ' . $Active . ' /> ' . $this->Context->GetDefinition("NotificationForum") . ' </label> </span> </p> </li> </ul> '; } if ($this->Context->Configuration['NOTIFI_ALLOW_CATEGORY'] == 1) { $CategoryManager = $this->Context->ObjectFactory->NewContextObject($this->Context, 'CategoryManager'); $CategoryData = $CategoryManager->GetCategories(0, 1); if ($CategoryData) { echo ' <span id="categoriesContainer"' . $SubscribedEntireForum . '> <h2>Categories</h2> <p>Notify me on new comments in the following categories</p> <ul> '; $cat = $this->Context->ObjectFactory->NewObject($this->Context, 'Category'); while ($Row = $this->Context->Database->GetRow($CategoryData)) { $cat->Clear(); $cat->GetPropertiesFromDataSet($Row); $Active = ''; if (CheckNotifi($this->Context, 'CATEGORY', $cat->CategoryID, $u) == true) { $Active = 'checked="checked" '; } echo ' <li> <p class="notifiToggleCBox"> <span> <label for="NotifiCat_' . $cat->CategoryID . '"> <input type="checkbox" name="NOTIFI_CATEGORY_' . $cat->CategoryID . '" id="NotifiCat_' . $cat->CategoryID . '" ' . $Active . ');" /> ' . $cat->Name . ' </label> </span> </p> </li> '; } echo ' </ul> </span> '; } } echo '<span id="discussionsContainer"' . $SubscribedEntireForum . '>'; if ($this->Context->Configuration['NOTIFI_ALLOW_DISCUSSION'] == 1) { $res = mysql_query("SELECT B.DiscussionID,B.Name FROM " . $this->Context->Configuration['DATABASE_TABLE_PREFIX'] . "Notifi A INNER JOIN " . $this->Context->Configuration['DATABASE_TABLE_PREFIX'] . "Discussion B ON (A.SelectID = B.DiscussionID) WHERE A.UserID = '" . $u . "' AND A.Method = 'DISCUSSION' ORDER BY B.DateLastActive", $this->Context->Database->Connection); if (mysql_num_rows($res) > 0) { echo ' <h2>Discussions</h2> <p>Notify me on new comments in the following discussions. Only selected discussions are listed here. To submit to a discussion use the link provided on the discussions tab</p> <ul> '; while ($row = mysql_fetch_array($res)) { $Active = ''; if (CheckNotifi($this->Context, 'DISCUSSION', $row[0])) { $Active = 'checked="checked" '; } echo ' <li> <p class="notifiToggleCBox"> <span> <label for="NotifiDiscussion_' . $row[0] . '"> <input type="checkbox" name="NOTIFI_DISCUSSION_' . $row[0] . '" id="NotifiDiscussion_' . $row[0] . '" ' . $Active . ' /> ' . $row[1] . ' </label> </span> </p> </li> '; } echo '</ul>'; } } echo ' </span> </form> </fieldset> </div> '; } }
function NotifiDiscussion($DiscussionForm) { // Only continue if this is a new post, not an edited one if ($_POST['CommentID'] == "0") { // Default variable values for this function set here $SubscribedOnOwn = "no"; if ($DiscussionForm->Context->Configuration['NOTIFI_FORMAT_PLAINTEXT'] == 0) { // Make Vanilla send the email/s as HTML instead of plain text $DiscussionForm->Context->Configuration['DEFAULT_EMAIL_MIME_TYPE'] = 'text/html'; } $DiscussionID = @$DiscussionForm->DelegateParameters['ResultDiscussion']->DiscussionID; if ($DiscussionID > 0) { // Detect if Whispered $result = mysql_query("SELECT WhisperUserID FROM " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "Discussion WHERE DiscussionID = '{$DiscussionID}'"); $row = mysql_fetch_row($result); if ($row[0] > 0) { $Whispered = 1; } else { $Whispered = 0; } $WhisperUserID = $row[0]; if (notifiCheck($DiscussionForm->Context, 'SubscribeOwn')) { ChangeNotifi($DiscussionForm->Context, 'DISCUSSION', $DiscussionID, 1); $SubscribedOnOwn = "yes"; } } else { $DiscussionID = @$DiscussionForm->DelegateParameters['ResultComment']->DiscussionID; // Detect if Whispered $mTitle = @$DiscussionForm->DelegateParameters['ResultComment']->Title; $CommentID = @$DiscussionForm->DelegateParameters['ResultComment']->CommentID; $result = mysql_query("SELECT WhisperUserID FROM " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "Discussion WHERE DiscussionID = '{$DiscussionID}'"); $row = mysql_fetch_row($result); if ($row[0] > 0) { $Whispered = 1; } else { $Whispered = 0; } $WhisperUserID = $row[0]; if ($Whispered == 0) { $result = mysql_query("SELECT WhisperUserID FROM " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "Comment WHERE CommentID = '{$CommentID}'"); $row = mysql_fetch_row($result); if ($row[0] > 0) { $Whispered = 1; $WhisperUserID = $row[0]; } else { $Whispered = 0; } } } if ($DiscussionID > 0) { $Notifieusers = array(); $SelfUser = $DiscussionForm->Context->Session->UserID; if ($DiscussionForm->Context->Configuration['NOTIFI_AUTO_ALL'] == 0) { // Add all users who have subscribed to all, aren't already notified except the posting user if ($DiscussionForm->Context->Configuration['NOTIFI_ALLOW_ALL'] == 1) { $result = mysql_query("SELECT A.UserID,Email,FirstName, LastName, RoleID FROM " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "Notifi AS A, " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "User AS B WHERE A.Method = 'ALL' AND A.UserID <> '{$SelfUser}' AND A.UserID = B.UserID AND (B.Notified = 0 OR B.KeepEmailing = 1)", $DiscussionForm->Context->Database->Connection); while ($row = mysql_fetch_row($result)) { if ($Whispered == 1 and $WhisperUserID == $row[0] or $Whispered == 0) { array_push($Notifieusers, array($row[0], $row[1], $row[2], $row[3], $row[4])); } } } // Add all users who have subscribed to this category , aren't already notified except the posting user if ($DiscussionForm->Context->Configuration['NOTIFI_ALLOW_CATEGORY'] == 1) { $result = mysql_query("SELECT CategoryID FROM " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "Discussion WHERE DiscussionID = '{$DiscussionID}'", $DiscussionForm->Context->Database->Connection); $row = mysql_fetch_row($result); $result2 = mysql_query("SELECT A.UserID,Email,FirstName, LastName, RoleID FROM " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "Notifi AS A, " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "User AS B WHERE A.Method = 'CATEGORY' AND A.SelectID = '{$row['0']}' AND A.UserID <> '{$SelfUser}' AND A.UserID = B.UserID AND (B.Notified = 0 OR B.KeepEmailing = 1)", $DiscussionForm->Context->Database->Connection); while ($row2 = mysql_fetch_row($result2)) { if ($Whispered == 1 and $WhisperUserID == $row2[0] or $Whispered == 0) { array_push($Notifieusers, array($row2[0], $row2[1], $row2[2], $row2[3], $row2[4])); } } } // Add all users who have subscribed to this discussion , aren't already notified except the posting user if ($DiscussionForm->Context->Configuration['NOTIFI_ALLOW_DISCUSSION'] == 1) { $result2 = mysql_query("SELECT A.UserID,Email,FirstName, LastName, RoleID FROM " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "Notifi AS A, " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "User AS B WHERE A.Method = 'DISCUSSION' AND A.SelectID = '{$DiscussionID}' AND A.UserID <> '{$SelfUser}' AND A.UserID = B.UserID AND (B.Notified = 0 OR B.KeepEmailing = 1)", $DiscussionForm->Context->Database->Connection); while ($row2 = mysql_fetch_row($result2)) { if ($Whispered == 1 and $WhisperUserID == $row2[0] or $Whispered == 0) { array_push($Notifieusers, array($row2[0], $row2[1], $row2[2], $row2[3], $row2[4])); } } } } else { // Add all users $result = mysql_query("SELECT UserID,Email,FirstName, LastName, RoleID FROM " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "User WHERE UserID <> '{$SelfUser}' AND (Notified = 0 OR KeepEmailing = 1)", $DiscussionForm->Context->Database->Connection); while ($row = mysql_fetch_row($result)) { if ($Whispered == 1 and $WhisperUserID == $row[0] or $Whispered == 0) { array_push($Notifieusers, array($row[0], $row[1], $row[2], $row[3], $row[4])); } } } // Get the username of the person who posted $mPosterName = notifiCheck($DiscussionForm->Context, 'Name'); // Remove double inserted users array_unique($Notifieusers); // Get the category ID $results = mysql_query("SELECT CategoryID, Name FROM " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "Discussion WHERE DiscussionID = '{$DiscussionID}'", $DiscussionForm->Context->Database->Connection); $row = mysql_fetch_row($results); $categoryID = $row[0]; $discussionName = $row[1]; // Get the comment contents $result = mysql_query("SELECT Body FROM " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "Comment WHERE CommentID = '{$CommentID}'"); $row = mysql_fetch_row($result); if (empty($row[0])) { $mComment = strip_tags($_POST['Body']); } else { $mComment = $row[0]; } $mailsent = array(); // Create the email object $e = $DiscussionForm->Context->ObjectFactory->NewContextObject($DiscussionForm->Context, 'Email'); $e->HtmlOn = 1; // Build an array that contains roles that are blocked from viewing this category $results = mysql_query("SELECT * FROM " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "CategoryRoleBlock WHERE CategoryID = '{$categoryID}' AND Blocked = '1'", $DiscussionForm->Context->Database->Connection); $rolesAry = array(); while ($row = mysql_fetch_row($results)) { $rolesAry[] = $row; } // If the user has chosen to be subscribed to every discussion they comment on, subscribe them if (notifiCheck($DiscussionForm->Context, 'SubscribeComment') && $SubscribedOnOwn == "no") { ChangeNotifi($DiscussionForm->Context, 'DISCUSSION', $DiscussionID, 1); } foreach ($Notifieusers as $val) { $roleID = $val[4]; $allowToMail = "yes"; // Check category permissions for ($i = 0; $i < count($rolesAry); $i++) { $record = $rolesAry[$i]; $databaseRoleID = $record[1]; if ($databaseRoleID == $roleID) { $allowToMail = "no"; } } // Check if user is permitted to view this category if ($allowToMail == "yes") { $mName = ''; if ($val[2] != '') { $mName = $val[2]; } if ($val[1] != "" and !in_array($val[1], $mailsent)) { if ($val[2] != "" and $val[3] != "") { $NotifiName = ''; } else { $NotifiName = $val[2] . ' ' . $val[3]; } // Begin preparing the email $e->Clear(); $e->AddFrom($DiscussionForm->Context->Configuration['SUPPORT_EMAIL'], $DiscussionForm->Context->Configuration['SUPPORT_NAME']); $e->AddRecipient($val[1], $NotifiName); $e->Subject = $DiscussionForm->Context->Configuration['APPLICATION_TITLE'] . ' ' . $DiscussionForm->Context->GetDefinition('Notification'); // Save the ID of the user to be emailed $currentUserId = $val[0]; // Get the last viewed comment from the database $result = mysql_query("SELECT CountComments FROM " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "UserDiscussionWatch WHERE UserID=" . $currentUserId . " AND DiscussionID=" . $DiscussionID, $DiscussionForm->Context->Database->Connection); $list = mysql_fetch_row($result); $lastViewedComment = $list[0]; // Find out which page to go to $commentsPerPage = $DiscussionForm->Context->Configuration['COMMENTS_PER_PAGE']; $pageNumber = ceil($lastViewedComment / $commentsPerPage); $jumpToComment = $lastViewedComment - ($pageNumber . '0' - 10); // Include the email templates include '_includes/emailtemplates.php'; // See if the admin has chosen to send emails as plaintext if ($DiscussionForm->Context->Configuration['NOTIFI_FORMAT_PLAINTEXT'] == 1) { if (isset($CommentID)) { // If this is a new comment in an existing discussion $message = $plainTextOldDiscussion; } else { // If this is a new discussion $message = $plainTextNewDiscussion; } } else { // If BBCode support is enabled, process it if ($DiscussionForm->Context->Configuration['NOTIFI_ALLOW_BBCODE'] == 1) { $mComment = htmlentities($mComment); $bbSearch = array('/\\[b\\](.*?)\\[\\/b\\]/is', '/\\[i\\](.*?)\\[\\/i\\]/is', '/\\[url\\=(.*?)\\](.*?)\\[\\/url\\]/is', '/\\[url\\](.*?)\\[\\/url\\]/is', '/\\[img\\](.*?)\\[\\/img\\]/is', '/\\[br\\]/is', '/\\[quote\\](.*?)\\[\\/quote\\]/is', '/\\[cite\\](.*?)\\[\\/cite\\]/is'); $bbReplace = array('<strong>$1</strong>', '<em>$1</em>', '<a href="$1">$2</a>', '<a href="$1">$1</a>', '<img src="$1" />', '<br />', '<blockquote>$1</blockquote>', '<cite>$1</cite>'); $mComment = preg_replace($bbSearch, $bbReplace, $mComment); } // Insert line breaks in the comment $mComment = nl2br($mComment); if (isset($CommentID)) { // If this is a new comment in an existing discussion $message = $htmlOldDiscussion; } else { // If this is a new discussion $message = $htmlNewDiscussion; } } $e->Body = $message; $e->Send(); array_push($mailsent, $val[1]); mysql_query("UPDATE " . $DiscussionForm->Context->Configuration['DATABASE_TABLE_PREFIX'] . "User SET Notified = 1 WHERE UserID = '" . $val[0] . "'"); } } } } } }