Ejemplo n.º 1
0
/**
 * Formats forum messages.
 *
 * @param array $data
 *     An array containing an array of messages to be formatted.
 *
 * @param array $author_specs
 *     By default, the formatting function will create  author info
 *     data out of the fields "user_id", "author" and "email".
 *     This will create $data["URL"]["PROFILE"] if needed (either pointing
 *     to a user profile for registered users or the email address of
 *     anonymous users that left an email address in the forum) and will
 *     do formatting on the $data["author"] field.
 *
 *     By providing extra $author_specs, this formatting can be done on
 *     more author fields. This argument should be an array, containing
 *     arrays with five fields: the field that contains a user_id,
 *     the field for the name of the author and the field for the email
 *     address (can be NULL if none available), the name of the field
 *     to store the author name in and the name of the URL field to store
 *     the profile/email link in. For the default author field like
 *     describe above, this array would be:
 *
 *     array("user_id", "author", "email", "author", "PROFILE");
 *
 * @return data - The formatted messages.
 */
function phorum_format_messages($data, $author_specs = NULL)
{
    $PHORUM = $GLOBALS["PHORUM"];
    // Prepare author specs.
    if ($author_specs === NULL) {
        $author_specs = array();
    }
    $author_specs[] = array("user_id", "author", "email", "author", "PROFILE");
    // Prepare the bad-words replacement code.
    $bad_word_check = false;
    $banlists = NULL;
    if (!empty($PHORUM['cache_banlists']) && !empty($PHORUM['banlist_version'])) {
        $cache_key = $PHORUM['forum_id'];
        $banlists = phorum_cache_get('banlist', $cache_key, $PHORUM['banlist_version']);
    }
    // not found or no caching enabled
    if ($banlists === NULL) {
        $banlists = phorum_db_get_banlists();
        if (!empty($PHORUM['cache_banlists']) && !empty($PHORUM['banlist_version'])) {
            phorum_cache_put('banlist', $cache_key, $banlists, 7200, $PHORUM['banlist_version']);
        }
    }
    if (isset($banlists[PHORUM_BAD_WORDS]) && is_array($banlists[PHORUM_BAD_WORDS])) {
        $replace_vals = array();
        $replace_words = array();
        foreach ($banlists[PHORUM_BAD_WORDS] as $item) {
            $replace_words[] = "/\\b" . preg_quote($item['string'], '/') . "(ing|ed|s|er|es)*\\b/i";
            $replace_vals[] = PHORUM_BADWORD_REPLACE;
            $bad_word_check = true;
        }
    }
    // A special <br> tag to keep track of breaks that are added by phorum.
    $phorum_br = '<phorum break>';
    // prepare url-templates used later on
    $profile_url_template = phorum_get_url(PHORUM_PROFILE_URL, '%spec_data%');
    // Apply Phorum's formatting rules to all messages.
    foreach ($data as $key => $message) {
        // Normally, the message_id must be set, since we should be handling
        // message data. It might not be set however, because sometimes
        // the message formatting is called using some fake message data
        // for formatting something else than a message.
        if (!isset($message['message_id'])) {
            $data[$key]['message_id'] = $message['message_id'] = $key;
        }
        // Work on the message body ========================
        if (isset($message["body"])) {
            $body = $message["body"];
            // Convert legacy <> urls into bare urls.
            $body = preg_replace("/<((http|https|ftp):\\/\\/[a-z0-9;\\/\\?:@=\\&\$\\-_\\.\\+!*'\\(\\),~%]+?)>/i", "\$1", $body);
            // Escape special HTML characters.
            $escaped_body = htmlspecialchars($body, ENT_COMPAT, $PHORUM["DATA"]["HCHARSET"]);
            if ($escaped_body == "") {
                if (function_exists("iconv")) {
                    // we are gonna guess and see if we get lucky
                    $escaped_body = iconv("ISO-8859-1", $PHORUM["DATA"]["HCHARSET"], $body);
                } else {
                    // we let htmlspecialchars use its defaults
                    $escaped_body = htmlspecialchars($body);
                }
            }
            $body = $escaped_body;
            // Replace newlines with $phorum_br temporarily.
            // This way the mods know what Phorum did vs the user.
            $body = str_replace("\n", "{$phorum_br}\n", $body);
            // Run bad word replacement code.
            if ($bad_word_check) {
                $body = preg_replace($replace_words, $replace_vals, $body);
            }
            $data[$key]["body"] = $body;
        }
        // Work on the other fields ========================
        // Run bad word replacement code on subject and author.
        if ($bad_word_check) {
            if (isset($message["subject"])) {
                $data[$key]["subject"] = preg_replace($replace_words, $replace_vals, $data[$key]["subject"]);
            }
            if (isset($message["author"])) {
                $data[$key]["author"] = preg_replace($replace_words, $replace_vals, $data[$key]["author"]);
            }
        }
        // Escape special HTML characters in fields.
        if (isset($message["email"])) {
            $data[$key]["email"] = htmlspecialchars($data[$key]["email"], ENT_COMPAT, $PHORUM["DATA"]["HCHARSET"]);
        }
        if (isset($message["subject"])) {
            $data[$key]["subject"] = htmlspecialchars($data[$key]["subject"], ENT_COMPAT, $PHORUM["DATA"]["HCHARSET"]);
        }
        // Do author formatting for all provided author fields.
        foreach ($author_specs as $spec) {
            // Use "Anonymous user" as the author name if there's no author
            // name available for some reason.
            if (!isset($message[$spec[1]]) || $message[$spec[1]] == '') {
                $data[$key][$spec[3]] = $PHORUM["DATA"]["LANG"]["AnonymousUser"];
            } elseif (!empty($message[$spec[0]])) {
                $url = str_replace('%spec_data%', $message[$spec[0]], $profile_url_template);
                $data[$key]["URL"][$spec[4]] = $url;
                $data[$key][$spec[3]] = empty($PHORUM["custom_display_name"]) ? htmlspecialchars($message[$spec[1]], ENT_COMPAT, $PHORUM["DATA"]["HCHARSET"]) : $message[$spec[1]];
            } elseif ($spec[2] !== NULL && !empty($message[$spec[2]]) && (empty($PHORUM['hide_email_addr']) || !empty($PHORUM["user"]["admin"]) || phorum_api_user_check_access(PHORUM_USER_ALLOW_MODERATE_MESSAGES) && PHORUM_MOD_EMAIL_VIEW || phorum_api_user_check_access(PHORUM_USER_ALLOW_MODERATE_USERS) && PHORUM_MOD_EMAIL_VIEW)) {
                $data[$key][$spec[3]] = htmlspecialchars($message[$spec[1]], ENT_COMPAT, $PHORUM["DATA"]["HCHARSET"]);
                $email_url = phorum_html_encode("mailto:" . $message[$spec[2]]);
                $data[$key]["URL"]["PROFILE"] = $email_url;
            } else {
                $data[$key][$spec[3]] = htmlspecialchars($message[$spec[1]], ENT_COMPAT, $PHORUM["DATA"]["HCHARSET"]);
            }
        }
    }
    // A hook for module writers to apply custom message formatting.
    if (isset($PHORUM["hooks"]["format"])) {
        $data = phorum_hook("format", $data);
    }
    // A hook for module writers for doing post formatting fixups.
    if (isset($PHORUM["hooks"]["format_fixup"])) {
        $data = phorum_hook("format_fixup", $data);
    }
    // Clean up after the mods are done.
    foreach ($data as $key => $message) {
        // Clean up line breaks inside pre and xmp tags. These tags
        // take care of showing newlines as breaks themselves.
        if (isset($message["body"])) {
            foreach (array("pre", "goep", "xmp") as $tagname) {
                if (preg_match_all("/(<{$tagname}.*?>).+?(<\\/{$tagname}>)/si", $message["body"], $matches)) {
                    foreach ($matches[0] as $match) {
                        $stripped = str_replace($phorum_br, "", $match);
                        $message["body"] = str_replace($match, $stripped, $message["body"]);
                    }
                }
            }
            // Remove line break after div, quote and code tags. These
            // tags have their own line break. Without this, there would
            // be to many white lines.
            $message["body"] = preg_replace("/\\s*(<\\/?(?:div|xmp|blockquote|pre)[^>]*>)\\s*\\Q{$phorum_br}\\E/", "\$1", $message["body"]);
            // Normalize the Phorum line breaks that are left.
            $data[$key]["body"] = str_replace($phorum_br, "<br />", $message["body"]);
        }
    }
    return $data;
}
Ejemplo n.º 2
0
            // add the edited-message to a post if its edited
            if(isset($row['meta']['edit_count']) && $row['meta']['edit_count'] > 0) {
                $editmessage = str_replace ("%count%", $row['meta']['edit_count'], $PHORUM["DATA"]["LANG"]["EditedMessage"]);
                $editmessage = str_replace ("%lastedit%", phorum_date($PHORUM["short_date"],$row['meta']['edit_date']),  $editmessage);
                $editmessage = str_replace ("%lastuser%", $row['meta']['edit_username'],  $editmessage);
                $row["body"].="\n\n\n\n$editmessage";
            }
        }


        if(!empty($row["user_id"])) {
            $row["profile_url"] = phorum_get_url(PHORUM_PROFILE_URL, $row["user_id"]);
            // we don't normally put HTML in this code, but this makes it easier on template builders
            $row["linked_author"] = "<a href=\"".$row["profile_url"]."\">$row[author]</a>";
        } elseif(!empty($row["email"])) {
            $row["email_url"] = phorum_html_encode("mailto:$row[email]");
            // we don't normally put HTML in this code, but this makes it easier on template builders
            $row["linked_author"] = "<a href=\"".$row["email_url"]."\">".htmlspecialchars($row["author"])."</a>";
        } else {
            $row["linked_author"] = htmlspecialchars($row["author"]);
        }

        // mask host if not a moderator
        if(empty($PHORUM["user"]["admin"]) && (empty($PHORUM["DATA"]["MODERATOR"]) || !PHORUM_MOD_IP_VIEW)){
            if($PHORUM["display_ip_address"]){
                if($row["moderator_post"]){
                    $row["ip"]=$PHORUM["DATA"]["LANG"]["Moderator"];
                } elseif(is_numeric(str_replace(".", "", $row["ip"]))){
                    $row["ip"]=substr($row["ip"],0,strrpos($row["ip"],'.')).'.---';
                } else {
                    $row["ip"]="---".strstr($row["ip"], ".");
Ejemplo n.º 3
0
        if (!isset($user[$field['name']])) {
            $user[$field['name']] = "";
        }
    }
}
// No need to show the real name in case it's the same
// as the display name.
if ($user["real_name"] == $user["display_name"]) {
    unset($user["real_name"]);
}
$PHORUM["DATA"]["PROFILE"] = $user;
$PHORUM["DATA"]["PROFILE"]["forum_id"] = $PHORUM["forum_id"];
$PHORUM["DATA"]["PROFILE"]["raw_date_added"] = $PHORUM["DATA"]["PROFILE"]["date_added"];
$PHORUM["DATA"]["PROFILE"]["date_added"] = phorum_date($PHORUM['short_date_time'], $PHORUM["DATA"]["PROFILE"]["date_added"]);
if (empty($PHORUM['hide_email_addr']) && !$user['hide_email'] || !empty($PHORUM["user"]["admin"]) || phorum_api_user_check_access(PHORUM_USER_ALLOW_MODERATE_MESSAGES) && PHORUM_MOD_EMAIL_VIEW || phorum_api_user_check_access(PHORUM_USER_ALLOW_MODERATE_USERS) && PHORUM_MOD_EMAIL_VIEW) {
    $PHORUM["DATA"]["PROFILE"]["email"] = phorum_html_encode($user["email"]);
} else {
    $PHORUM["DATA"]["PROFILE"]["email"] = $PHORUM["DATA"]["LANG"]["Hidden"];
}
if ($PHORUM["track_user_activity"] && (!empty($PHORUM["user"]["admin"]) || phorum_api_user_check_access(PHORUM_USER_ALLOW_MODERATE_MESSAGES) || phorum_api_user_check_access(PHORUM_USER_ALLOW_MODERATE_USERS) || !$user["hide_activity"])) {
    $PHORUM["DATA"]["PROFILE"]["raw_date_last_active"] = $PHORUM["DATA"]["PROFILE"]["date_last_active"];
    $PHORUM["DATA"]["PROFILE"]["date_last_active"] = phorum_date($PHORUM['short_date_time'], $PHORUM["DATA"]["PROFILE"]["date_last_active"]);
} else {
    unset($PHORUM["DATA"]["PROFILE"]["date_last_active"]);
}
$PHORUM["DATA"]["PROFILE"]["posts"] = number_format($PHORUM["DATA"]["PROFILE"]["posts"], 0, "", $PHORUM["thous_sep"]);
$PHORUM["DATA"]["PROFILE"]["URL"]["PM"] = phorum_get_url(PHORUM_PM_URL, "page=send", "to_id=" . urlencode($user["user_id"]));
$PHORUM["DATA"]["PROFILE"]["URL"]["ADD_BUDDY"] = phorum_get_url(PHORUM_PM_URL, "page=buddies", "action=addbuddy", "addbuddy_id=" . urlencode($user["user_id"]));
$PHORUM["DATA"]["PROFILE"]["is_buddy"] = phorum_db_pm_is_buddy($user["user_id"]);
// unset($PHORUM["DATA"]["PROFILE"]["signature"]);
$PHORUM["DATA"]["PROFILE"]["URL"]["SEARCH"] = phorum_get_url(PHORUM_SEARCH_URL, "author=" . urlencode($PHORUM["DATA"]["PROFILE"]["user_id"]), "match_type=USER_ID", "match_dates=0", "match_threads=0");
Ejemplo n.º 4
0
foreach($subscr_array as $dummy => $data) {
    if ($data['forum_id'] == 0) {
        $data['forum'] = $PHORUM['DATA']['LANG']['Announcement'];
    } else {
        $data['forum'] = $forums_arr[$data['forum_id']]['name'];
    } 

    $data['datestamp'] = phorum_date($PHORUM["short_date"], $data["modifystamp"]);
    $data['readurl'] = phorum_get_url(PHORUM_FOREIGN_READ_URL, $data["forum_id"], $data["thread"]);

    if(!empty($data["user_id"])) {
        $data["profile_url"] = phorum_get_url(PHORUM_PROFILE_URL, $data["user_id"]);
        // we don't normally put HTML in this code, but this makes it easier on template builders
        $data["linked_author"] = "<a href=\"".$data["profile_url"]."\">".htmlspecialchars($data["author"])."</a>";
    } elseif(!empty($data["email"])) {
        $data["email_url"] = phorum_html_encode("mailto:$data[email]");
        // we don't normally put HTML in this code, but this makes it easier on template builders
        $data["linked_author"] = "<a href=\"".$data["email_url"]."\">".htmlspecialchars($data["author"])."</a>";
    } else {
        $data["linked_author"] = htmlspecialchars($data["author"]);
    }

    $data["subject"]=htmlspecialchars($data["subject"]);

    $subscr_array_final[] = $data;
}

$PHORUM['DATA']['subscriptions'] = $subscr_array_final;
$template = "cc_subscriptions";

?>