$new_pid = $db->insert_id(); // Update the thread with last_post_id $db->query('UPDATE ' . $db->prefix . 'topics SET last_post_id=' . $new_pid . ', first_post_id=' . $new_pid . ' WHERE id=' . $new_tid) or error('Unable to update topic', __FILE__, __LINE__, $db->error()); update_search_index('post', $new_pid, $message, $subject); update_forum($fid); // Should we send out notifications? if ($luna_config['o_forum_subscriptions'] == '1') { // Get any subscribed users that should be notified (banned users are excluded) $result = $db->query('SELECT u.id, u.email, u.notify_with_post, u.language FROM ' . $db->prefix . 'users AS u INNER JOIN ' . $db->prefix . 'forum_subscriptions AS s ON u.id=s.user_id LEFT JOIN ' . $db->prefix . 'forum_perms AS fp ON (fp.forum_id=' . $cur_posting['fid'] . ' AND fp.group_id=u.group_id) LEFT JOIN ' . $db->prefix . 'bans AS b ON u.username=b.username WHERE b.username IS NULL AND (fp.read_forum IS NULL OR fp.read_forum=1) AND s.forum_id=' . $cur_posting['fid'] . ' AND u.id!=' . $luna_user['id']) or error('Unable to fetch subscription info', __FILE__, __LINE__, $db->error()); if ($db->num_rows($result)) { require_once FORUM_ROOT . 'include/email.php'; $notification_emails = array(); if ($luna_config['o_censoring'] == '1') { $cleaned_message = bbcode2email($censored_message, -1); } else { $cleaned_message = bbcode2email($message, -1); } // Loop through subscribed users and send emails while ($cur_subscriber = $db->fetch_assoc($result)) { // Is the subscription email for $cur_subscriber['language'] cached or not? if (!isset($notification_emails[$cur_subscriber['language']])) { // Load the "new thread" template $mail_tpl = trim(__('Subject: New thread in forum: "<forum_name>" <commenter> has commented a new thread "<thread_subject>" in the forum "<forum_name>", to which you are subscribed. The thread is located at <thread_url> You can unsubscribe by going to <unsubscribe_url> --
public function send_notifications_new_topic($post, $cur_posting, $new_tid) { // Get any subscribed users that should be notified (banned users are excluded) $where_send_notifications_reply = array(array('fp.read_forum' => 'IS NULL'), array('fp.read_forum' => '1')); $select_send_notifications_reply = array('u.id', 'u.email', 'u.notify_with_post', 'u.language'); $result = DB::for_table('users')->table_alias('u')->select_many($select_send_notifications_reply)->inner_join('forum_subscriptions', array('u.id', '=', 's.user_id'), 's')->left_outer_join('forum_perms', array('fp.forum_id', '=', $cur_posting['id']), 'fp', true)->left_outer_join('forum_perms', array('fp.group_id', '=', 'u.group_id'))->left_outer_join('bans', array('u.username', '=', 'b.username'), 'b')->where_null('b.username')->where_any_is($where_send_notifications_reply)->where('s.forum_id', $cur_posting['id'])->where_not_equal('u.id', $this->user->id)->find_many(); if ($result) { require_once FEATHER_ROOT . 'include/email.php'; $notification_emails = array(); if ($this->config['o_censoring'] == '1') { $cleaned_message = bbcode2email($censored_message, -1); } else { $cleaned_message = bbcode2email($post['message'], -1); } // Loop through subscribed users and send emails foreach ($result as $cur_subscriber) { // Is the subscription email for $cur_subscriber['language'] cached or not? if (!isset($notification_emails[$cur_subscriber['language']])) { if (file_exists(FEATHER_ROOT . 'lang/' . $cur_subscriber['language'] . '/mail_templates/new_topic.tpl')) { // Load the "new topic" template $mail_tpl = trim(file_get_contents(FEATHER_ROOT . 'lang/' . $cur_subscriber['language'] . '/mail_templates/new_topic.tpl')); // Load the "new topic full" template (with post included) $mail_tpl_full = trim(file_get_contents(FEATHER_ROOT . 'lang/' . $cur_subscriber['language'] . '/mail_templates/new_topic_full.tpl')); // The first row contains the subject (it also starts with "Subject:") $first_crlf = strpos($mail_tpl, "\n"); $mail_subject = trim(substr($mail_tpl, 8, $first_crlf - 8)); $mail_message = trim(substr($mail_tpl, $first_crlf)); $first_crlf = strpos($mail_tpl_full, "\n"); $mail_subject_full = trim(substr($mail_tpl_full, 8, $first_crlf - 8)); $mail_message_full = trim(substr($mail_tpl_full, $first_crlf)); $mail_subject = str_replace('<forum_name>', $cur_posting['forum_name'], $mail_subject); $mail_message = str_replace('<topic_subject>', $this->config['o_censoring'] == '1' ? $censored_subject : $post['subject'], $mail_message); $mail_message = str_replace('<forum_name>', $cur_posting['forum_name'], $mail_message); $mail_message = str_replace('<poster>', $post['username'], $mail_message); $mail_message = str_replace('<topic_url>', get_link('topic/' . $new_tid . '/'), $mail_message); $mail_message = str_replace('<unsubscribe_url>', get_base_url() . '/misc.php?action=unsubscribe&fid=' . $cur_posting['id'], $mail_message); $mail_message = str_replace('<board_mailer>', $this->config['o_board_title'], $mail_message); $mail_subject_full = str_replace('<forum_name>', $cur_posting['forum_name'], $mail_subject_full); $mail_message_full = str_replace('<topic_subject>', $this->config['o_censoring'] == '1' ? $censored_subject : $post['subject'], $mail_message_full); $mail_message_full = str_replace('<forum_name>', $cur_posting['forum_name'], $mail_message_full); $mail_message_full = str_replace('<poster>', $post['username'], $mail_message_full); $mail_message_full = str_replace('<message>', $cleaned_message, $mail_message_full); $mail_message_full = str_replace('<topic_url>', get_link('topic/' . $new_tid . '/'), $mail_message_full); $mail_message_full = str_replace('<unsubscribe_url>', get_base_url() . '/misc.php?action=unsubscribe&fid=' . $cur_posting['id'], $mail_message_full); $mail_message_full = str_replace('<board_mailer>', $this->config['o_board_title'], $mail_message_full); $notification_emails[$cur_subscriber['language']][0] = $mail_subject; $notification_emails[$cur_subscriber['language']][1] = $mail_message; $notification_emails[$cur_subscriber['language']][2] = $mail_subject_full; $notification_emails[$cur_subscriber['language']][3] = $mail_message_full; } } // We have to double check here because the templates could be missing if (isset($notification_emails[$cur_subscriber['language']])) { if ($cur_subscriber['notify_with_post'] == '0') { pun_mail($cur_subscriber['email'], $notification_emails[$cur_subscriber['language']][0], $notification_emails[$cur_subscriber['language']][1]); } else { pun_mail($cur_subscriber['email'], $notification_emails[$cur_subscriber['language']][2], $notification_emails[$cur_subscriber['language']][3]); } } } unset($cleaned_message); } }