Beispiel #1
0
//                                                                           //
// You should have received a copy of the Phorum License                     //
// along with this program.                                                  //
///////////////////////////////////////////////////////////////////////////////
define('phorum_page', 'index');
include_once "./common.php";
include_once "./include/format_functions.php";
if (!phorum_check_read_common()) {
    return;
}
// check for markread
if (!empty($PHORUM["args"][1]) && $PHORUM["args"][1] == 'markread' && $PHORUM["DATA"]["LOGGEDIN"]) {
    // setting all posts read
    if (isset($PHORUM["forum_id"])) {
        unset($PHORUM['user']['newinfo']);
        phorum_db_newflag_allread($PHORUM["forum_id"]);
        if ($PHORUM['cache_newflags']) {
            $newflagkey = $PHORUM["forum_id"] . "-" . $PHORUM['user']['user_id'];
            phorum_cache_remove('newflags', $newflagkey);
            phorum_cache_remove('newflags_index', $newflagkey);
        }
    }
    // redirect to a fresh list of the current folder without markread in url
    if (isset($PHORUM["args"][2]) && !empty($PHORUM["args"][2])) {
        $folder_id = (int) $PHORUM["args"][2];
        $dest_url = phorum_get_url(PHORUM_INDEX_URL, $folder_id);
    } else {
        $dest_url = phorum_get_url(PHORUM_INDEX_URL);
    }
    phorum_redirect_by_url($dest_url);
    exit;
Beispiel #2
0
/**
 * Mark forums, threads or messages as read for the active Phorum user.
 *
 * @param mixed $markread_ids
 *     This parameter provides the ids of the items that have to be marked
 *     read. It can be either a single item id (depending on the $mode
 *     parameter either message_id, thread_id or forum_id) or an array
 *     of item ids.
 *
 * @param integer $mode
 *     This determines whether messages, threads or forums are marked
 *     read. Possible values for this parameter are:
 *     {@link PHORUM_MARKREAD_MESSAGES},
 *     {@link PHORUM_MARKREAD_THREADS},
 *     {@link PHORUM_MARKREAD_FORUMS}
 */
function phorum_api_newflags_markread($markread_ids, $mode = PHORUM_MARKREAD_MESSAGES)
{
    global $PHORUM;
    // No newflags for anonymous users.
    if (!$PHORUM['user']['user_id']) {
        return $messages;
    }
    // Make sure that the $markread_ids parameter is an array of integers.
    if (!is_array($markread_ids)) {
        $markread_ids = array((int) $markread_ids);
    } else {
        foreach ($markread_ids as $key => $val) {
            $markread_ids[$key] = (int) $val;
        }
    }
    // An array to keep track of the forums for which we need to invalidate
    // the cache later on.
    $processed_forum_ids = array();
    // Handle marking forums read.
    if ($mode == PHORUM_MARKREAD_FORUMS) {
        foreach ($markread_ids as $forum_id) {
            phorum_db_newflag_allread($forum_id);
            $processed_forum_ids[$forum_id] = $forum_id;
        }
    } elseif ($mode == PHORUM_MARKREAD_THREADS) {
        // Retrieve the data for the threads to mark read.
        $threads = phorum_db_get_message($markread_ids, 'message_id', TRUE);
        // Process the threads.
        $markread = array();
        foreach ($threads as $thread) {
            // In case this was no thread or broken thread data.
            if ($thread['parent_id'] != 0 || empty($thread['meta']['message_ids'])) {
                continue;
            }
            // Fetch the user's newflags for the thread's forum, so we
            // can limit the messages to mark read to the actual unread
            // messages in the thread.
            $forum_id = $thread['forum_id'];
            if (!isset($PHORUM['user']['newflags'][$forum_id])) {
                $newflags = phorum_api_newflags_by_forum($forum_id);
            } else {
                $newflags = $PHORUM['user']['newflags'][$forum_id];
            }
            // Find out what message_ids are unread in the thread.
            // If we have no newflags for the forum (yet), then consider
            // all the messages in the thread as new.
            $markread = array();
            foreach ($thread['meta']['message_ids'] as $mid) {
                if (empty($newflags) || !isset($newflags[$mid]) && $mid > $newflags['min_id']) {
                    $markread[] = array('id' => $mid, 'forum' => $forum_id);
                }
            }
            $processed_forum_ids[$forum_id] = $forum_id;
        }
        // Mark the messages in the thread(s) as read.
        phorum_db_newflag_add_read($markread);
    } elseif ($mode == PHORUM_MARKREAD_MESSAGES) {
        // Retrieve the data for the messages to mark read.
        $messages = phorum_db_get_message($markread_ids);
        // Process the messages.
        $markread = array();
        foreach ($messages as $message) {
            $markread[] = array('id' => $message['message_id'], 'forum' => $message['forum_id']);
            $processed_forum_ids[$message['forum_id']] = $message['forum_id'];
        }
        // Mark the messages read in the database.
        phorum_db_newflag_add_read($markread);
    }
    // Invalidate cached forum newflags data.
    foreach ($processed_forum_ids as $forum_id) {
        unset($PHORUM['user']['newflags'][$forum_id]);
        if ($PHORUM['cache_newflags']) {
            $cachekey = $forum_id . '-' . $PHORUM['user']['user_id'];
            phorum_cache_remove('newflags', $cachekey);
            phorum_cache_remove('newflags_index', $cachekey);
        }
    }
}
Beispiel #3
0
    $dest_url = phorum_get_url(PHORUM_INDEX_URL);
    phorum_redirect_by_url($dest_url);
    exit;
}
// somehow we got to a folder in list.php
if ($PHORUM["folder_flag"]) {
    $dest_url = phorum_get_url(PHORUM_INDEX_URL, $PHORUM["forum_id"]);
    phorum_redirect_by_url($dest_url);
    exit;
}
$newflagkey = $PHORUM["forum_id"] . "-" . $PHORUM['user']['user_id'];
// check for markread
if (!empty($PHORUM["args"][1]) && $PHORUM["args"][1] == 'markread' && $PHORUM["DATA"]["LOGGEDIN"]) {
    // setting all posts read
    unset($PHORUM['user']['newinfo']);
    phorum_db_newflag_allread();
    if ($PHORUM['cache_newflags']) {
        phorum_cache_remove('newflags', $newflagkey);
        phorum_cache_remove('newflags_index', $newflagkey);
    }
    // redirect to a fresh list without markread in url
    $dest_url = phorum_get_url(PHORUM_LIST_URL);
    phorum_redirect_by_url($dest_url);
    exit;
}
if ($PHORUM["DATA"]["LOGGEDIN"]) {
    // reading newflags in
    $PHORUM['user']['newinfo'] = null;
    if ($PHORUM['cache_newflags']) {
        $PHORUM['user']['newinfo'] = phorum_cache_get('newflags', $newflagkey, $PHORUM['cache_version']);
    }