function email_moderators($fields) { if ($this->info['skip_moderator_email'] or !$this->info['forum'] or in_coventry($this->fetch_field('userid', 'post'), true)) { return; } $mod_emails = fetch_moderator_newpost_emails($fields, $this->info['forum']['parentlist'], $newpost_lang); if (!empty($mod_emails)) { $foruminfo = $this->info['forum']; $foruminfo['title_clean'] = unhtmlspecialchars($foruminfo['title_clean']); $threadinfo = fetch_threadinfo($this->fetch_field('threadid')); require_once DIR . '/includes/class_bbcode_alt.php'; $plaintext_parser =& new vB_BbCodeParser_PlainText($this->registry, fetch_tag_list()); $email = $this->info['user']['email'] ? $this->info['user']['email'] : $this->registry->userinfo['email']; $browsing_user = $this->registry->userinfo['username']; // ugly hack -- should be fixed in the future $this->registry->userinfo['username'] = unhtmlspecialchars($this->info['user']['username'] ? $this->info['user']['username'] : $this->registry->userinfo['username']); $post = array_merge($this->existing, $this->post); if (!$post['postid']) { $post['postid'] = $this->thread['firstpostid']; } require_once DIR . '/includes/functions_misc.php'; foreach ($mod_emails as $toemail) { if ($toemail != $email) { $plaintext_parser->set_parsing_language(isset($newpost_lang["{$toemail}"]) ? $newpost_lang["{$toemail}"] : 0); $post['message'] = $plaintext_parser->parse($this->post['pagetext'], $foruminfo['forumid']); if ($threadinfo['prefixid']) { // need prefix in correct language $threadinfo['prefix_plain'] = fetch_phrase("prefix_{$threadinfo['prefixid']}_title_plain", 'global', '', false, true, isset($newpost_lang["{$toemail}"]) ? $newpost_lang["{$toemail}"] : 0, false) . ' '; } else { $threadinfo['prefix_plain'] = ''; } eval(fetch_email_phrases('moderator', iif(isset($newpost_lang["{$toemail}"]), $newpost_lang["{$toemail}"], 0))); vbmail($toemail, $subject, $message); } } // back to normal $this->registry->userinfo['username'] = htmlspecialchars_uni($browsing_user); } }
/** * Sends Thread subscription Notifications * * @param integer The Thread ID * @param integer The User ID making the Post * @param integer The Post ID of the new post * */ function exec_send_notification($threadid, $userid, $postid) { // $threadid = threadid to send from; // $userid = userid of who made the post // $postid = only sent if post is moderated -- used to get username correctly global $vbulletin, $message, $postusername; if (!$vbulletin->options['enableemail']) { return; } // include for fetch_phrase require_once DIR . '/includes/functions_misc.php'; $threadinfo = fetch_threadinfo($threadid); $foruminfo = fetch_foruminfo($threadinfo['forumid']); // get last reply time if ($postid) { $dateline = $vbulletin->db->query_first("\n\t\t\tSELECT dateline, pagetext\n\t\t\tFROM " . TABLE_PREFIX . "post\n\t\t\tWHERE postid = {$postid}\n\t\t"); $pagetext_orig = $dateline['pagetext']; $lastposttime = $vbulletin->db->query_first("\n\t\t\tSELECT MAX(dateline) AS dateline\n\t\t\tFROM " . TABLE_PREFIX . "post AS post\n\t\t\tWHERE threadid = {$threadid}\n\t\t\t\tAND dateline < {$dateline['dateline']}\n\t\t\t\tAND visible = 1\n\t\t"); } else { $lastposttime = $vbulletin->db->query_first("\n\t\t\tSELECT MAX(postid) AS postid, MAX(dateline) AS dateline\n\t\t\tFROM " . TABLE_PREFIX . "post AS post\n\t\t\tWHERE threadid = {$threadid}\n\t\t\t\tAND visible = 1\n\t\t"); $pagetext = $vbulletin->db->query_first("\n\t\t\tSELECT pagetext\n\t\t\tFROM " . TABLE_PREFIX . "post\n\t\t\tWHERE postid = {$lastposttime['postid']}\n\t\t"); $pagetext_orig = $pagetext['pagetext']; unset($pagetext); } $threadinfo['title'] = unhtmlspecialchars($threadinfo['title']); $foruminfo['title_clean'] = unhtmlspecialchars($foruminfo['title_clean']); $temp = $vbulletin->userinfo['username']; if ($postid) { $postinfo = fetch_postinfo($postid); $vbulletin->userinfo['username'] = unhtmlspecialchars($postinfo['username']); } else { $vbulletin->userinfo['username'] = unhtmlspecialchars(!$vbulletin->userinfo['userid'] ? $postusername : $vbulletin->userinfo['username']); } require_once DIR . '/includes/class_bbcode_alt.php'; $plaintext_parser =& new vB_BbCodeParser_PlainText($vbulletin, fetch_tag_list()); $pagetext_cache = array(); // used to cache the results per languageid for speed $mod_emails = fetch_moderator_newpost_emails('newpostemail', $foruminfo['parentlist'], $language_info); ($hook = vBulletinHook::fetch_hook('newpost_notification_start')) ? eval($hook) : false; $useremails = $vbulletin->db->query_read_slave("\n\t\tSELECT user.*, subscribethread.emailupdate, subscribethread.subscribethreadid\n\t\tFROM " . TABLE_PREFIX . "subscribethread AS subscribethread\n\t\tINNER JOIN " . TABLE_PREFIX . "user AS user ON (subscribethread.userid = user.userid)\n\t\tLEFT JOIN " . TABLE_PREFIX . "usergroup AS usergroup ON (usergroup.usergroupid = user.usergroupid)\n\t\tLEFT JOIN " . TABLE_PREFIX . "usertextfield AS usertextfield ON (usertextfield.userid = user.userid)\n\t\tWHERE subscribethread.threadid = {$threadid} AND\n\t\t\tsubscribethread.emailupdate IN (1, 4) AND\n\t\t\tsubscribethread.canview = 1 AND\n\t\t\t" . ($userid ? "CONCAT(' ', IF(usertextfield.ignorelist IS NULL, '', usertextfield.ignorelist), ' ') NOT LIKE '% " . intval($userid) . " %' AND" : '') . "\n\t\t\tuser.usergroupid <> 3 AND\n\t\t\tuser.userid <> " . intval($userid) . " AND\n\t\t\tuser.lastactivity >= " . intval($lastposttime['dateline']) . " AND\n\t\t\t(usergroup.genericoptions & " . $vbulletin->bf_ugp_genericoptions['isnotbannedgroup'] . ")\n\t"); vbmail_start(); $evalemail = array(); while ($touser = $vbulletin->db->fetch_array($useremails)) { if (!($vbulletin->usergroupcache["{$touser['usergroupid']}"]['genericoptions'] & $vbulletin->bf_ugp_genericoptions['isnotbannedgroup'])) { continue; } else { if (in_array($touser['email'], $mod_emails)) { // this user already received an email about this post via // a new post email for mods -- don't send another continue; } } $touser['username'] = unhtmlspecialchars($touser['username']); $touser['languageid'] = iif($touser['languageid'] == 0, $vbulletin->options['languageid'], $touser['languageid']); $touser['auth'] = md5($touser['userid'] . $touser['subscribethreadid'] . $touser['salt'] . COOKIE_SALT); if (empty($evalemail)) { $email_texts = $vbulletin->db->query_read_slave("\n\t\t\t\tSELECT text, languageid, fieldname\n\t\t\t\tFROM " . TABLE_PREFIX . "phrase\n\t\t\t\tWHERE fieldname IN ('emailsubject', 'emailbody') AND varname = 'notify'\n\t\t\t"); while ($email_text = $vbulletin->db->fetch_array($email_texts)) { $emails["{$email_text['languageid']}"]["{$email_text['fieldname']}"] = $email_text['text']; } require_once DIR . '/includes/functions_misc.php'; foreach ($emails as $languageid => $email_text) { // lets cycle through our array of notify phrases $text_message = str_replace("\\'", "'", addslashes(iif(empty($email_text['emailbody']), $emails['-1']['emailbody'], $email_text['emailbody']))); $text_message = replace_template_variables($text_message); $text_subject = str_replace("\\'", "'", addslashes(iif(empty($email_text['emailsubject']), $emails['-1']['emailsubject'], $email_text['emailsubject']))); $text_subject = replace_template_variables($text_subject); $evalemail["{$languageid}"] = ' $message = "' . $text_message . '"; $subject = "' . $text_subject . '"; '; } } // parse the page text into plain text, taking selected language into account if (!isset($pagetext_cache["{$touser['languageid']}"])) { $plaintext_parser->set_parsing_language($touser['languageid']); $pagetext_cache["{$touser['languageid']}"] = $plaintext_parser->parse($pagetext_orig, $foruminfo['forumid']); } $pagetext = $pagetext_cache["{$touser['languageid']}"]; if ($threadinfo['prefixid']) { // need prefix in correct language $threadinfo['prefix_plain'] = fetch_phrase("prefix_{$threadinfo['prefixid']}_title_plain", 'global', '', false, true, $touser['languageid'], false) . ' '; } else { $threadinfo['prefix_plain'] = ''; } ($hook = vBulletinHook::fetch_hook('newpost_notification_message')) ? eval($hook) : false; eval(iif(empty($evalemail["{$touser['languageid']}"]), $evalemail["-1"], $evalemail["{$touser['languageid']}"])); if ($touser['emailupdate'] == 4 and !empty($touser['icq'])) { // instant notification by ICQ $touser['email'] = $touser['icq'] . '@pager.icq.com'; } vbmail($touser['email'], $subject, $message); } unset($plaintext_parser, $pagetext_cache); $vbulletin->userinfo['username'] = $temp; vbmail_end(); }