/** * Sends an e-mail to users who have subscribed to certain forumcategory * @param $topicId int The UID of the new topic that was created * @param $forumId int The UID of the forum about which the users are to be alerted. * @param \tx_mmforum_base $forumObj * @return void * @author Cyrill Helg */ static function notifyForumSubscribers($topicId, $forumId, \tx_mmforum_base $forumObj) { $res = $this->databaseHandle->exec_SELECTquery('topic_title', 'tx_mmforum_topics', 'uid = ' . intval($topicId) . $forumObj->getStoragePIDQuery()); list($topicName) = $this->databaseHandle->sql_fetch_row($res); $res = $this->databaseHandle->exec_SELECTquery('forum_name, parentID', 'tx_mmforum_forums', 'uid = ' . intval($forumId) . $forumObj->getStoragePIDQuery()); list($forumName, $categoryId) = $this->databaseHandle->sql_fetch_row($res); // prepare the template (the variables that don't change all the time need only to be set once) $linkParams[$forumObj->prefixId] = array('action' => 'open_topic', 'id' => $topicId); $link = $forumObj->pi_getPageLink($GLOBALS['TSFE']->id, '', $linkParams); $link = $forumObj->tools->escapeBrackets($link); if (strlen($forumObj->conf['notifyingMail.']['topicLinkPrefix_override']) > 0) { $link = $forumObj->conf['notifyingMail.']['topicLinkPrefix_override'] . $link; } $template = $forumObj->pi_getLL('ntfMailForum.text'); $marker = array('###LINK###' => $link, '###USERNAME###' => $toUsername, '###FORUMNAME###' => $forumName, '###TEAM###' => $forumObj->conf['teamName']); $subjectMarker = array('###TOPICNAME###' => $topicName, '###FORUMNAME###' => $forumName, '###BOARDNAME###' => $forumObj->conf['boardName']); // loop through each user who subscribed $res = $this->databaseHandle->exec_SELECTquery('DISTINCT tx_mmforum_forummail.user_id, fe_users.email, fe_users.' . $forumObj->getUserNameField(), 'tx_mmforum_forummail, fe_users', 'tx_mmforum_forummail.user_id = fe_users.uid AND (tx_mmforum_forummail.forum_id = ' . intval($forumId) . ($categoryId > 0 ? ' OR tx_mmforum_forummail.forum_id = ' . $categoryId : '') . ') AND fe_users.deleted = 0 AND fe_users.disable = 0 AND fe_users.email != "" AND tx_mmforum_forummail.user_id != ' . intval($GLOBALS['TSFE']->fe_user->user['uid']) . $forumObj->getStoragePIDQuery('tx_mmforum_forummail')); while (list($toUserId, $toEmail, $toUsername) = $this->databaseHandle->sql_fetch_row($res)) { $marker['###USERNAME###'] = $forumObj->escape($toUsername); $mailtext = $forumObj->cObj->substituteMarkerArrayCached($template, $marker); // Compose mail and send $subject = $forumObj->cObj->substituteMarkerArray($forumObj->pi_getLL('ntfMailForum.subject'), $subjectMarker); $mail = GeneralUtility::makeInstance('t3lib_mail_Message'); $mail->setFrom(array($forumObj->conf['notifyingMail.']['sender_address'] => $forumObj->conf['notifyingMail.']['sender'])); $mail->setTo(array($toEmail => $toUsername)); $mail->setSubject($subject); $mail->setBody($mailtext, 'text/plain'); $mail->send(); } }