<?php include '../../appg/settings.php'; include '../../conf/settings.php'; include '../../appg/init_vanilla.php'; $PostBackAction = ForceIncomingString('PostBackAction', ''); $Type = ForceIncomingString('Type', ''); $ElementID = ForceIncomingInt('ElementID', 0); $Value = ForceIncomingInt('Value', 0); if ($PostBackAction == 'ChangeNotifi') { if ($Type != 'OWN') { if ($Type != 'KEEPEMAILING') { ChangeNotifi($Context, $Type, $ElementID, $Value); } if ($Type == 'ALL') { notifiSwitch($Context, $Value, $Context->Session->UserID, 'SubscribedEntireForum'); } elseif ($Type == 'KEEPEMAILING') { notifiSwitch($Context, $Value, $Context->Session->UserID, 'KeepEmailing'); } elseif ($Type == 'COMMENT') { notifiSwitch($Context, $Value, $Context->Session->UserID, 'SubscribeComment'); } } else { notifiSwitch($Context, $Value, $Context->Session->UserID, 'SubscribeOwn'); } echo 'Complete'; } $Context->Unload();
function SaveDiscussion($Discussion) { if (!$this->Context->Session->User->Permission('PERMISSION_START_DISCUSSION')) { $this->Context->WarningCollector->Add($this->Context->GetDefinition('ErrPermissionStartDiscussions')); } else { // If not editing, and the posted discussion count is less than the // user's current discussion count, silently skip the posting and // redirect as if everything is normal. if ($Discussion->DiscussionID == 0 && $Discussion->UserDiscussionCount < $this->Context->Session->User->CountDiscussions) { // Silently fail to post the data // Need to get the user's last posted discussionID and direct them to it $s = $this->Context->ObjectFactory->NewContextObject($this->Context, 'SqlBuilder'); $s->SetMainTable('Discussion', 'd'); $s->AddSelect('DiscussionID', 'd'); $s->AddWhere('c', 'AuthUserID', '', $this->Context->Session->UserID, '='); $s->AddOrderBy('DateCreated', 'd', 'desc'); $s->AddLimit(0, 1); $LastDiscussionData = $this->Context->Database->Select($s, $this->Name, 'SaveDiscussion', 'An error occurred while retrieving your last discussion.'); while ($Row = $this->Context->Database->GetRow($LastDiscussionData)) { $Discussion->DiscussionID = ForceInt($Row['DiscussionID'], 0); } // Make sure we got it if ($Discussion->DiscussionID == 0) { $this->Context->ErrorManager->AddError($this->Context, $this->Name, 'SaveDiscussion', 'Your last discussion could not be found.'); } } else { $NewDiscussion = 0; $OldDiscussion = false; if ($Discussion->DiscussionID == 0) { $NewDiscussion = 1; } else { $OldDiscussion = $this->GetDiscussionById($Discussion->DiscussionID); } // Validate the Discussion topic $Name = FormatStringForDatabaseInput($Discussion->Name); Validate($this->Context->GetDefinition('DiscussionTopicLower'), 1, $Name, 100, '', $this->Context); //Validate the category ID and role $s = $this->Context->ObjectFactory->NewContextObject($this->Context, 'SqlBuilder'); $s->SetMainTable('Category', 'c'); $s->AddSelect('CategoryID', 'c'); $s->AddJoin('CategoryRoleBlock', 'crb', 'CategoryID', 'c', 'CategoryID', 'left join', ' and crb.' . $this->Context->DatabaseColumns['CategoryRoleBlock']['RoleID'] . ' = ' . $this->Context->Session->User->RoleID); $s->AddWhere('crb', 'Blocked', '', '0', '=', 'and', '', 1, 1); $s->AddWhere('crb', 'Blocked', '', '0', '=', 'or', '', 0, 0); $s->AddWhere('crb', 'Blocked', '', 'null', 'is', 'or', '', 0, 0); $s->AddWhere('c', 'CategoryID', '', $Discussion->CategoryID, '=', 'and'); $s->EndWhereGroup(); $CategoryAllowed = $this->Context->Database->Select($s, $this->Name, 'SaveDiscussion', 'An error occurred while validating category permissions.'); if ($this->Context->Database->RowCount($CategoryAllowed) < 1) { $Discussion->CategoryID = 0; } // Validate first comment $Discussion->Comment->DiscussionID = $Discussion->DiscussionID; if ($OldDiscussion) { $Discussion->Comment->CommentID = $OldDiscussion->FirstCommentID; } else { $Discussion->Comment->CommentID = 0; } $CommentManager = $this->Context->ObjectFactory->NewContextObject($this->Context, 'CommentManager'); $CommentManager->ValidateComment($Discussion->Comment, 0); // Validate the whisperusername $CommentManager->ValidateWhisperUsername($Discussion); // If updating, validate that this is admin or the author if (!$NewDiscussion) { if ($OldDiscussion->AuthUserID != $this->Context->Session->UserID && !$this->Context->Session->User->Permission('PERMISSION_EDIT_DISCUSSIONS')) { $this->Context->WarningCollector->Add($this->Context->GetDefinition('ErrPermissionEditComments')); } } // If validation was successful, then reset the properties to db safe values for saving if ($this->Context->WarningCollector->Count() == 0) { $Discussion->Name = $Name; } if ($this->Context->WarningCollector->Iif()) { $s->Clear(); // Update the user info & check for spam if ($NewDiscussion) { $UserManager = $this->Context->ObjectFactory->NewContextObject($this->Context, 'UserManager'); $UserManager->UpdateUserDiscussionCount($this->Context->Session->UserID); } $this->MakeSticky = false; if ($Discussion->CategoryID <= 0 && ForceIncomingInt('CommentID', 0) == 0) { // create new category and set it $this->Category = $this->Context->ObjectFactory->NewObject($this->Context, 'Category'); $this->Category->Name = $_POST['RoomName']; $this->Category->AllowedRoles = array(1, 2, 3, 4); $this->CategoryManager = $this->Context->ObjectFactory->NewContextObject($this->Context, 'CategoryManager'); $this->CategoryManager->SaveCategory($this->Category); $Discussion->CategoryID = $this->Category->CategoryID; $this->MakeSticky = true; ChangeNotifi($this->Context, 'CATEGORY', $this->Category->CategoryID, 1); } // Proceed with the save if there are no warnings if ($this->Context->WarningCollector->Count() == 0) { $this->DelegateParameters['SqlBuilder'] =& $s; $this->CallDelegate('PreSaveDiscussion'); $s->SetMainTable('Discussion', 'd'); $s->AddFieldNameValue('Name', $Discussion->Name); $s->AddFieldNameValue('CategoryID', $Discussion->CategoryID); if ($NewDiscussion) { $s->AddFieldNameValue('AuthUserID', $this->Context->Session->UserID); $s->AddFieldNameValue('DateCreated', MysqlDateTime()); $s->AddFieldNameValue('DateLastActive', MysqlDateTime()); $s->AddFieldNameValue('CountComments', 0); $s->AddFieldNameValue('WhisperUserID', $Discussion->WhisperUserID); $Discussion->DiscussionID = $this->Context->Database->Insert($s, $this->Name, 'NewDiscussion', 'An error occurred while creating a new discussion.'); $Discussion->Comment->DiscussionID = $Discussion->DiscussionID; } else { $s->AddWhere('d', 'DiscussionID', '', $Discussion->DiscussionID, '='); $this->Context->Database->Update($s, $this->Name, 'NewDiscussion', 'An error occurred while updating the discussion.'); } if ($this->MakeSticky) { $this->SwitchDiscussionProperty($Discussion->DiscussionID, 'Sticky', true); $this->SwitchDiscussionProperty($Discussion->DiscussionID, 'Closed', true); $um = $this->Context->ObjectFactory->NewContextObject($this->Context, 'UserManager'); $um->RemoveCategoryBlock($Discussion->CategoryID); } } // Now save the associated Comment if ($Discussion->Comment->DiscussionID > 0) { $CommentManager->SaveComment($Discussion->Comment, 1); // Now update the topic table so that we know what the first comment in the discussion was if ($Discussion->Comment->CommentID > 0 && $NewDiscussion) { $s->Clear(); $s->SetMainTable('Discussion', 'd'); $s->AddFieldNameValue('FirstCommentID', $Discussion->Comment->CommentID); $s->AddWhere('d', 'DiscussionID', '', $Discussion->Comment->DiscussionID, '='); $this->Context->Database->Update($s, $this->Name, 'NewDiscussion', 'An error occurred while updating discussion properties.'); } } } } } return $this->Context->WarningCollector->Iif($Discussion, false); }
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 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] . "'"); } } } } } }