/** * Send a new forum message notification by mail to subscribed users. * * @param array $message * An array containing the data for a forum message. */ function phorum_api_mail_message_notify($message) { // Not "global $PHORUM", because we do not want the loading of language // files to override our already loaded language file. $PHORUM = $GLOBALS['PHORUM']; // Check if email notifications are allowed for the current forum. if (empty($PHORUM['allow_email_notify'])) { return; } $recipients = phorum_api_user_list_subscribers($PHORUM['forum_id'], $message['thread'], PHORUM_SUBSCRIPTION_MESSAGE); // No subscribers? Then we are done. if (empty($recipients)) { return; } $mail_data = array('forumname' => strip_tags($PHORUM['DATA']['NAME']), 'forum_id' => $message['forum_id'], "thread_id" => $message['thread'], 'message_id' => $message['message_id'], 'author' => phorum_api_user_get_display_name($message['user_id'], $message['author'], PHORUM_FLAG_PLAINTEXT), 'subject' => $message['subject'], 'fully_body' => $message['body'], 'plain_body' => wordwrap(phorum_api_format_strip($message['body']), 72), 'read_url' => phorum_api_url_no_uri_auth(PHORUM_READ_URL, $message['thread'], $message['message_id']), 'remove_url' => phorum_api_url_no_uri_auth(PHORUM_FOLLOW_URL, $message['thread'], 'stop=1'), 'noemail_url' => phorum_api_url_no_uri_auth(PHORUM_FOLLOW_URL, $message['thread'], 'noemail=1'), 'followed_threads_url' => phorum_api_url_no_uri_auth(PHORUM_CONTROLCENTER_URL, 'panel=' . PHORUM_CC_SUBSCRIPTION_THREADS), 'msgid' => $message['msgid'], 'mailmessagetpl' => 'NewReplyMessage', 'mailsubjecttpl' => 'NewReplySubject'); foreach ($recipients as $language => $addresses) { $language = basename($language); if (file_exists(PHORUM_PATH . "/include/lang/{$language}.php")) { $mail_data['language'] = $language; include PHORUM_PATH . "/include/lang/{$language}.php"; } else { $mail_data['language'] = $PHORUM['language']; include PHORUM_PATH . "/include/lang/{$PHORUM['language']}.php"; } $mail_data['mailmessage'] = $PHORUM['DATA']['LANG']['NewReplyMessage']; $mail_data['mailsubject'] = $PHORUM['DATA']['LANG']['NewReplySubject']; phorum_api_mail($addresses, $mail_data); } }
/** * Send a new forum message for moderation to the moderator(s). * * @param array $message * An array containing the data for a forum message. */ function phorum_api_mail_message_moderate($message) { // Not "global $PHORUM", because we do not want the loading of language // files to override our already loaded language file. $PHORUM = $GLOBALS['PHORUM']; // Retrieve the list of moderators for the current forum. $moderators = phorum_api_user_list_moderators($PHORUM['forum_id'], $PHORUM['email_ignore_admin'], TRUE); // The list moderators function returns user_id => mail address. // We want the full user info, so we can lookup the preferred // language for the moderators. $moderators = phorum_api_user_get(array_keys($moderators)); // Sort all moderators by their preferred language. $recipients = array(); foreach ($moderators as $moderator) { if (!isset($recipients[$moderator['user_language']])) { $recipients[$moderator['user_language']] = array($moderator['email']); } else { $recipients[$moderator['user_language']][] = $moderator['email']; } } // No moderators (oomph)? Then we are done. if (empty($recipients)) { return; } if ($message['status'] > 0) { $mailsubjecttpl = 'NewUnModeratedSubject'; $mailmessagetpl = 'NewUnModeratedMessage'; } else { $mailsubjecttpl = 'NewModeratedSubject'; $mailmessagetpl = 'NewModeratedMessage'; } $mail_data = array('forumname' => strip_tags($PHORUM['DATA']['NAME']), 'forum_id' => $message['forum_id'], 'message_id' => $message['message_id'], 'author' => phorum_api_user_get_display_name($message['user_id'], $message['author'], PHORUM_FLAG_PLAINTEXT), 'subject' => $message['subject'], 'fully_body' => $message['body'], 'plain_body' => wordwrap(phorum_api_format_strip($message['body']), 72), 'approve_url' => phorum_api_url_no_uri_auth(PHORUM_CONTROLCENTER_URL, 'panel=messages'), 'read_url' => phorum_api_url_no_uri_auth(PHORUM_READ_URL, $message['thread'], $message['message_id']), 'mailmessagetpl' => $mailmessagetpl, 'mailsubjecttpl' => $mailsubjecttpl); foreach ($recipients as $language => $addresses) { $language = basename($language); if (file_exists(PHORUM_PATH . "/include/lang/{$language}.php")) { $mail_data['language'] = $language; include PHORUM_PATH . "/include/lang/{$language}.php"; } else { $mail_data['language'] = $PHORUM['language']; include PHORUM_PATH . "/include/lang/{$PHORUM['language']}.php"; } $mail_data['mailmessage'] = $PHORUM['DATA']['LANG'][$mailmessagetpl]; $mail_data['mailsubject'] = $PHORUM['DATA']['LANG'][$mailsubjecttpl]; phorum_api_mail($addresses, $mail_data); } }
/** * Send a PM notification by mail. * * @param array $message * An array containing the private message data. * * @param array $recipients * An array of users that have received the PM. */ function phorum_api_mail_pm_notify($message, $recipients) { // Not "global $PHORUM", because we do not want the loading of language // files to override our already loaded language file. $PHORUM = $GLOBALS['PHORUM']; // Sort all recipients that want a notification by their preferred language. $recipients_by_lang = array(); foreach ($recipients as $recipient) { if ($recipient['pm_email_notify']) { if (!isset($recipients_by_lang[$recipient['user_language']])) { $recipients_by_lang[$recipient['user_language']] = array($recipient); } else { $recipients_by_lang[$recipient['user_language']][] = $recipient; } } } // No users found that want a notification? Then we are done. if (empty($recipients_by_lang)) { return; } // Build the data array for phorum_api_mail(). $mail_data = array('pm_message_id' => $message['pm_message_id'], 'author' => phorum_api_user_get_display_name($message['user_id'], $message['from_username'], PHORUM_FLAG_PLAINTEXT), 'subject' => $message['subject'], 'full_body' => $message['message'], 'plain_body' => wordwrap(phorum_api_format_strip($message['message']), 72), 'read_url' => phorum_api_url_no_uri_auth(PHORUM_PM_URL, 'page=read', 'pm_id=' . $message['pm_message_id']), 'mailmessagetpl' => 'PMNotifyMessage', 'mailsubjecttpl' => 'PMNotifySubject'); foreach ($recipients_by_lang as $language => $users) { $language = basename($language); if (file_exists(PHORUM_PATH . "/include/lang/{$language}.php")) { $mail_data['language'] = $language; include PHORUM_PATH . "/include/lang/{$language}.php"; } else { $mail_data['language'] = $PHORUM['language']; include PHORUM_PATH . "/include/lang/{$PHORUM['language']}.php"; } $mail_data['mailmessage'] = $PHORUM['DATA']['LANG']['PMNotifyMessage']; $mail_data['mailsubject'] = $PHORUM['DATA']['LANG']['PMNotifySubject']; $addresses = array(); foreach ($users as $user) { $addresses[] = $user['email']; } phorum_api_mail($addresses, $mail_data); } }
function phorum_pm_quoteformat($orig_author, $orig_author_id, $message, $inreplyto = NULL) { global $PHORUM; // Build the reply subject. if (substr($message["subject"], 0, 3) != "Re:") { $message["subject"] = "Re: " . $message["subject"]; } // Lookup the plain text name that we have to use for the author that we reply to. $author = phorum_api_user_get_display_name($orig_author_id, '', PHORUM_FLAG_PLAINTEXT); // TODO we'll have to handle anonymous users in the PM box. Those are // TODO users which sent a PM to somebody, but signed out afterwards. // TODO Currently, there's no graceful handling for that I think // TODO (maybe it's handled already, but that would only be by accident). if (isset($PHORUM["hooks"]["quote"])) { $quote = phorum_api_hook("quote", array($author, $message["message"], $orig_author_id)); } if (empty($quote) || is_array($quote)) { // Build a quoted version of the message body. $quote = phorum_api_format_strip($message["message"]); $quote = str_replace("\n", "\n> ", $quote); $quote = wordwrap(trim($quote), 50, "\n> ", true); $quote = "{$author} {$PHORUM['DATA']['LANG']['Wrote']}:\n" . str_repeat("-", 55) . "\n> {$quote}\n\n\n"; } $quote = ($inreplyto != NULL ? "{$PHORUM['DATA']['LANG']['InReplyTo']} {$inreplyto}\n\n" : '') . $quote; $message["message"] = $quote; return $message; }
$dbmessage["subject"] = "Re: " . $dbmessage["subject"]; } $message["subject"] = $dbmessage["subject"]; // Add a quoted version of the body for quoted reply messages. if ($mode == "quote") { // Lookup the name that we have to use for the author, if the // author is a registered user. The author field could be used // directly, but it can contain HTML formatting code, in case // some module uses the custom display name functionality. $author = phorum_api_user_get_display_name($dbmessage["user_id"], $dbmessage['author'], PHORUM_FLAG_PLAINTEXT); $quoted = 0; if (isset($PHORUM["hooks"]["quote"])) { $quoted = phorum_api_hook("quote", array($author, $dbmessage["body"], $dbmessage["user_id"])); } if (empty($quoted) || is_array($quoted)) { $quoted = phorum_api_format_strip($dbmessage["body"]); $quoted = str_replace("\n", "\n> ", $quoted); $quoted = wordwrap(trim($quoted), 50, "\n> ", true); $quoted = "{$author} " . "{$PHORUM["DATA"]["LANG"]["Wrote"]}:\n" . str_repeat("-", 55) . "\n> {$quoted}\n\n\n"; } $message["body"] = $quoted; } } // Set message data for editing posts. if ($mode == "edit" || $mode == "moderation") { // Transfer all database fields to the form fields. $message = phorum_posting_merge_db2form($message, $dbmessage, ALLFIELDS); } // For new messages, set some default values for logged in users. if (($mode == "post" || $mode == "reply" || $mode == "quote") && $PHORUM["DATA"]["LOGGEDIN"]) { if (isset($PHORUM["user"]["show_signature"]) && $PHORUM["user"]["show_signature"]) {
/** * @deprecated Replaced by {@link phorum_api_format_strip()}. */ function phorum_strip_body($body) { return phorum_api_format_strip($body); }
$arr['rows'] = $search_request_data['results']; $arr['count'] = $search_request_data['totals']; $raw_body = $search_request_data['raw_body']; } if (count($arr["rows"])) { $match_number = $start + 1; $forums = phorum_api_forums_by_vroot($PHORUM["vroot"], PHORUM_FLAG_INCLUDE_INACTIVE); if (!$raw_body) { $arr["rows"] = phorum_api_format_messages($arr["rows"]); } foreach ($arr["rows"] as $key => $row) { $arr["rows"][$key]["number"] = $match_number; $arr["rows"][$key]["URL"]["READ"] = phorum_api_url(PHORUM_FOREIGN_READ_URL, $row["forum_id"], $row["thread"], $row["message_id"]); // strip HTML & BB Code if (!$raw_body) { $body = phorum_api_format_strip($arr["rows"][$key]["body"]); $arr["rows"][$key]["short_body"] = mb_substr($body, 0, 400, $PHORUM["DATA"]["HCHARSET"]); } $arr["rows"][$key]["raw_datestamp"] = $row["datestamp"]; $arr["rows"][$key]["datestamp"] = phorum_api_format_relative_date($row["datestamp"]); $forum_ids[$row["forum_id"]] = $row["forum_id"]; $match_number++; } foreach ($arr["rows"] as $key => $row) { $arr["rows"][$key]["URL"]["LIST"] = phorum_api_url(PHORUM_LIST_URL, $row["forum_id"]); $arr["rows"][$key]["forum_name"] = $forums[$row["forum_id"]]["name"]; } $PHORUM["DATA"]["RANGE_START"] = $start + 1; $PHORUM["DATA"]["RANGE_END"] = $start + count($arr["rows"]); $PHORUM["DATA"]["TOTAL"] = $arr["count"]; $PHORUM["DATA"]["SEARCH"]["showresults"] = true;
/** * This function implements the HTML output adapter for the Feed API. * * @param array $messages * An array of messages to include in the feed. * * @param array $forums * An array of related forums. * * @param string $url * The URL that points to the feed's target. * * @param string $title * The title to use for the feed. * * @param string $description * The description to use for the feed. * * @param bool $replies * Whether or not this is a feed that includes reply messages. * If not, then it will only contain thread starter messages. * * @return array * An array containing two elements: * - The generated feed data (HTML code). * - The Content-Type header to use for the feed. */ function phorum_api_feed_html($messages, $forums, $url, $title, $description, $replies) { global $PHORUM; $hcharset = $PHORUM['DATA']['HCHARSET']; $url = htmlspecialchars($url, ENT_COMPAT, $hcharset); $title = htmlspecialchars($title, ENT_COMPAT, $hcharset); $description = htmlspecialchars($description, ENT_COMPAT, $hcharset); $builddate = htmlspecialchars(date('r'), ENT_COMPAT, $hcharset); $buffer = "<div id=\"phorum_feed\">\n"; $buffer .= " <div id=\"phorum_feed_title\">\n"; $buffer .= " <a href=\"{$url}\" title=\"{$description}\">{$title}</a>\n"; $buffer .= " </div>\n"; $buffer .= " <div id=\"phorum_feed_date\">{$builddate}</div>\n"; $buffer .= " <ul>\n"; unset($messages['users']); foreach ($messages as $message) { $title = htmlspecialchars(strip_tags($message["subject"]), ENT_COMPAT, $hcharset); if (!$replies) { $lang = $PHORUM['DATA']['LANG']; switch ($message['thread_count']) { case 1: $title .= " (no {$lang['replies']})"; break; case 2: $title .= " (1 {$lang['reply']})"; break; default: $replies = $message['thread_count'] - 1; $title .= " ({$replies} {$lang['replies']})"; } } $url = htmlspecialchars(phorum_api_url(PHORUM_FOREIGN_READ_URL, $message["forum_id"], $message["thread"], $message["message_id"])); $body = substr(htmlspecialchars(phorum_api_format_strip($message['body']), ENT_COMPAT, $hcharset), 0, 200); $buffer .= " <li><a href=\"{$url}\" title=\"{$body}\">{$title}</a></li>\n"; } $buffer .= " </ul>\n"; $buffer .= "</div>\n"; return array($buffer, 'text/html'); }