示例#1
0
}
// somehow we got to a folder
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'];
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']);
    }
    if ($PHORUM['user']['newinfo'] == null) {
        $PHORUM['user']['newinfo'] = phorum_db_newflag_get_flags();
        if ($PHORUM['cache_newflags']) {
            phorum_cache_put('newflags', $newflagkey, $PHORUM['user']['newinfo'], 86400, $PHORUM['cache_version']);
        }
    }
}
$PHORUM["DATA"]["MODERATOR"] = phorum_api_user_check_access(PHORUM_USER_ALLOW_MODERATE_MESSAGES);
// Find out how many forums this user can moderate.
// If the user can moderate more than one forum, then
// present the move message moderation link.
if ($PHORUM["DATA"]["MODERATOR"]) {
    $modforums = phorum_api_user_check_access(PHORUM_USER_ALLOW_MODERATE_MESSAGES, PHORUM_ACCESS_LIST);
    $build_move_url = count($modforums) >= 2;
}
// setup some stuff based on the url passed
if (empty($PHORUM["args"][1])) {
示例#2
0
文件: mysql.php 项目: sheldon/dejavu
/**
 * Move a thread to another forum.
 *
 * @param integer $thread_id
 *     The id of the thread that has to be moved.
 *
 * @param integer
 *     The id of the destination forum.
 */
function phorum_db_move_thread($thread_id, $toforum)
{
    $PHORUM = $GLOBALS['PHORUM'];
    settype($thread_id, 'int');
    settype($toforum, 'int');
    if ($toforum > 0 && $thread_id > 0) {
        // Retrieve the messages from the thread, so we know for which
        // messages we have to update the newflags and search data below.
        $thread_messages = phorum_db_get_messages($thread_id);
        unset($thread_messages['users']);
        // All we have to do to move the thread to a different forum,
        // is update the forum_id for the messages in that thread.
        // Simple, isn't it?
        phorum_db_interact(DB_RETURN_RES, "UPDATE {$PHORUM['message_table']}\n             SET    forum_id = {$toforum}\n             WHERE  thread   = {$thread_id}", NULL, DB_MASTERQUERY);
        // Update the stats for the source forum.
        phorum_db_update_forum_stats(TRUE);
        // Update the stats for the destination forum.
        $old_id = $GLOBALS['PHORUM']['forum_id'];
        $GLOBALS['PHORUM']['forum_id'] = $toforum;
        phorum_db_update_forum_stats(TRUE);
        $GLOBALS['PHORUM']['forum_id'] = $old_id;
        // Move the newflags and search data to the destination forum.
        /**
         * @todo In the move thread code, there are some flaws. The
         *       newflags for the user that is moving the message
         *       are used as the source for deciding what flags
         *       to delete or move for all other users. This results
         *       in strange newflag problems.
         *
         *       This main issue here is that the newflags should be
         *       handled separately for each user; no updates should be
         *       based on the newflags for the active user. The current
         *       algorithm will only make sure that the newflags will look
         *       correct for that specific user. The problem is that we
         *       do not yet have an idea on how to handle this with
         *       enough performance.
         */
        // First, gather information for doing the updates.
        $new_newflags = phorum_db_newflag_get_flags($toforum);
        $message_ids = array();
        $delete_ids = array();
        $search_ids = array();
        foreach ($thread_messages as $mid => $data) {
            // Gather information for updating the newflags.
            // Moving the newflag is only useful if it is higher than the
            // min_id of the target forum.
            if (!empty($new_newflags['min_id'][$toforum]) && $mid > $new_newflags['min_id'][$toforum]) {
                $message_ids[] = $mid;
            } else {
                // Other newflags can be deleted.
                $delete_ids[] = $mid;
            }
            // gather the information for updating the search table
            $search_ids[] = $mid;
        }
        // Move newflags.
        if (count($message_ids)) {
            phorum_db_newflag_update_forum($message_ids);
        }
        // Update subscriptions.
        if (count($message_ids)) {
            $ids_str = implode(', ', $message_ids);
            phorum_db_interact(DB_RETURN_RES, "UPDATE {$PHORUM['subscribers_table']}\n                 SET    forum_id = {$toforum}\n                 WHERE  thread IN ({$ids_str})", NULL, DB_MASTERQUERY);
        }
        // Delete newflags.
        if (count($delete_ids)) {
            $ids_str = implode(', ', $delete_ids);
            phorum_db_interact(DB_RETURN_RES, "DELETE FROM {$PHORUM['user_newflags_table']}\n                 WHERE  message_id IN({$ids_str})", NULL, DB_MASTERQUERY);
        }
        // Update search data.
        if (count($search_ids)) {
            $ids_str = implode(', ', $search_ids);
            phorum_db_interact(DB_RETURN_RES, "UPDATE {$PHORUM['search_table']}\n                 SET    forum_id = {$toforum}\n                 WHERE  message_id in ({$ids_str})", NULL, DB_MASTERQUERY);
        }
    }
}
示例#3
0
function phorum_setup_announcements()
{
    global $PHORUM;
    // This variable will be used to store the formatted announcements.
    $PHORUM['DATA']['MOD_ANNOUNCEMENTS'] = '';
    // Check if we are on a page on which the announcements have to be shown.
    if (phorum_page == 'index') {
        // Hide the announcements, unless enabled for "index".
        $hide = empty($PHORUM["mod_announcements"]["pages"]["index"]);
        // Show announcements for the root page if "home" is enabled.
        if ($PHORUM['vroot'] == $PHORUM['forum_id'] && !empty($PHORUM["mod_announcements"]["pages"]["home"])) {
            $hide = FALSE;
        }
        if ($hide) {
            return;
        }
    } else {
        if (empty($PHORUM["mod_announcements"]["pages"][phorum_page])) {
            return;
        }
    }
    // Check if we need to show announcements.
    $ann_forum_id = NULL;
    // Inside a vroot, where we have a vroot configuration for the forum
    // to use for announcements and the current forum is not that
    // announcement forum.
    if ($PHORUM['vroot'] > 0 && !empty($PHORUM["mod_announcements"]["vroot"][$PHORUM['vroot']]) && $PHORUM["forum_id"] != $PHORUM["mod_announcements"]["vroot"][$PHORUM['vroot']]) {
        $ann_forum_id = $PHORUM["mod_announcements"]["vroot"][$PHORUM['vroot']];
        // Inside the top level folder, where we have a forum that is configured
        // to be used for announcements and the current forum is not that
        // announcement forum.
    } elseif ($PHORUM['vroot'] == 0 && !empty($PHORUM["mod_announcements"]["forum_id"]) && $PHORUM["forum_id"] != $PHORUM["mod_announcements"]["forum_id"]) {
        $ann_forum_id = $PHORUM["mod_announcements"]["forum_id"];
    }
    // If no announcement forum_id is found, no announcements
    // have to be shown.
    if ($ann_forum_id === NULL) {
        return;
    }
    // Retrieve the last number of posts from the announcement forum.
    $messages = phorum_db_get_recent_messages($PHORUM["mod_announcements"]["number_to_show"], 0, $ann_forum_id, 0, true);
    unset($messages["users"]);
    // No announcements to show? Then we are done.
    if (count($messages) == 0) {
        return;
    }
    // Read the newflags information for authenticated users.
    $newinfo = NULL;
    if ($PHORUM["DATA"]["LOGGEDIN"]) {
        $newflagkey = $ann_forum_id . "-" . $PHORUM['user']['user_id'];
        if ($PHORUM['cache_newflags']) {
            $newinfo = phorum_cache_get('newflags', $newflagkey, $PHORUM['cache_version']);
        }
        if ($newinfo == NULL) {
            $newinfo = phorum_db_newflag_get_flags($ann_forum_id);
            if ($PHORUM['cache_newflags']) {
                phorum_cache_put('newflags', $newflagkey, $newinfo, 86400, $PHORUM['cache_version']);
            }
        }
    }
    require_once "./include/format_functions.php";
    // Process the announcements.
    foreach ($messages as $message) {
        // Skip this message if it's older than the number of days that was
        // configured in the settings screen.
        if (!empty($PHORUM["mod_announcements"]["days_to_show"]) && $message["datestamp"] < time() - $PHORUM["mod_announcements"]["days_to_show"] * 86400) {
            continue;
        }
        // Check if there are new messages in the thread.
        if (isset($newinfo)) {
            $new = 0;
            foreach ($message["meta"]["message_ids"] as $id) {
                if (!isset($newinfo[$id]) && $id > $newinfo['min_id']) {
                    $new = 1;
                    break;
                }
            }
            // There are new messages. Setup the template data for showing
            // a new flag.
            if ($new) {
                $message["new"] = $new ? $PHORUM["DATA"]["LANG"]["newflag"] : NULL;
                $message["URL"]["NEWPOST"] = phorum_get_url(PHORUM_FOREIGN_READ_URL, $message["forum_id"], $message["thread"], "gotonewpost");
            } elseif ($PHORUM["mod_announcements"]["only_show_unread"]) {
                continue;
            }
        }
        // Setup template data for the message.
        unset($message['body']);
        $message["lastpost"] = phorum_date($PHORUM["short_date_time"], $message["modifystamp"]);
        $message["raw_datestamp"] = $message["datestamp"];
        $message["datestamp"] = phorum_date($PHORUM["short_date_time"], $message["datestamp"]);
        $message["URL"]["READ"] = phorum_get_url(PHORUM_FOREIGN_READ_URL, $message["forum_id"], $message["message_id"]);
        $PHORUM["DATA"]["ANNOUNCEMENTS"][] = $message;
    }
    // If all announcements were skipped, then we are done.
    if (!isset($PHORUM["DATA"]["ANNOUNCEMENTS"])) {
        return;
    }
    // format / clean etc. the messages found
    $PHORUM["DATA"]["ANNOUNCEMENTS"] = phorum_format_messages($PHORUM["DATA"]["ANNOUNCEMENTS"]);
    // Build the announcements code.
    ob_start();
    include phorum_get_template("announcements::announcements");
    $PHORUM['DATA']['MOD_ANNOUNCEMENTS'] = ob_get_contents();
    ob_end_clean();
}
示例#4
0
 $data['forum'] = $forums[$data['forum_id']]['name'];
 $data['raw_datestamp'] = $data["modifystamp"];
 $data['datestamp'] = phorum_date($PHORUM["short_date_time"], $data["modifystamp"]);
 $data['raw_lastpost'] = $data['modifystamp'];
 $data['lastpost'] = phorum_date($PHORUM["short_date_time"], $data["modifystamp"]);
 $data["URL"]["READ"] = phorum_get_url(PHORUM_FOREIGN_READ_URL, $data["forum_id"], $data["thread"]);
 $data["URL"]["NEWPOST"] = phorum_get_url(PHORUM_FOREIGN_READ_URL, $data["forum_id"], $data["thread"], "gotonewpost");
 // Check if there are new messages for the current thread.
 if (!isset($PHORUM['user']['newinfo'][$data["forum_id"]])) {
     $PHORUM['user']['newinfo'][$data["forum_id"]] = null;
     if ($PHORUM['cache_newflags']) {
         $newflagkey = $data["forum_id"] . "-" . $PHORUM['user']['user_id'];
         $PHORUM['user']['newinfo'][$data["forum_id"]] = phorum_cache_get('newflags', $newflagkey, $forums[$data["forum_id"]]['cache_version']);
     }
     if ($PHORUM['user']['newinfo'][$data["forum_id"]] == null) {
         $PHORUM['user']['newinfo'][$data["forum_id"]] = phorum_db_newflag_get_flags($data["forum_id"]);
         if ($PHORUM['cache_newflags']) {
             phorum_cache_put('newflags', $newflagkey, $PHORUM['user']['newinfo'][$data["forum_id"]], 86400, $forums[$data["forum_id"]]['cache_version']);
         }
     }
 }
 $new = array();
 foreach ($data["meta"]["message_ids"] as $mid) {
     if (!isset($PHORUM['user']['newinfo'][$data["forum_id"]][$mid]) && $mid > $PHORUM['user']['newinfo'][$data["forum_id"]]['min_id']) {
         $new[] = $mid;
     }
 }
 if (count($new)) {
     $data["new"] = $PHORUM["DATA"]["LANG"]["newflag"];
 }
 $subscr_array_final[] = $data;
示例#5
0
/**
 * Retrieve newflags data for a forum for the active Phorum user.
 *
 * This is mainly an internal helper function, which normally is
 * called from other Phorum core code. There should be no need for
 * you to call it from other code.
 *
 * @param mixed $forum
 *     Either a forum_id or a forum data array, containing at least the fields
 *     forum_id and cache_version.
 *
 * @return mixed
 *     The newflags data array for the forum or NULL if no newflags
 *     are available for that forum.
 */
function phorum_api_newflags_by_forum($forum)
{
    global $PHORUM;
    // No newflags for anonymous users.
    if (!$PHORUM['user']['user_id']) {
        return NULL;
    }
    // If a forum_id was provided as the argument, then load the forum info.
    if (!is_array($forum)) {
        $forums = phorum_db_get_forums($forum);
        if (empty($forums)) {
            trigger_error('phorum_api_newflags_by_forum(): unknown forum_id ' . $forum);
        }
        $forum = $forums[$forum];
    }
    // Check the input data.
    if (!is_array($forum) || !isset($forum['forum_id']) || !isset($forum['cache_version'])) {
        trigger_error('phorum_api_newflags_by_forum(): illegal argument; no forum info ' . 'or either one of "forum_id" or "cache_version" is ' . 'missing in the data.');
        return NULL;
    }
    $forum_id = (int) $forum['forum_id'];
    $cache_version = $forum['cache_version'];
    // Initialize call time newflags info cache.
    if (!isset($PHORUM['user']['newflags'])) {
        $PHORUM['user']['newflags'] = array();
    }
    // First, try to retrieve a cached version of the newflags.
    if (!isset($PHORUM['user']['newflags'][$forum_id])) {
        $PHORUM['user']['newflags'][$forum_id] = NULL;
        if ($PHORUM['cache_newflags']) {
            $cachekey = $forum_id . '-' . $PHORUM['user']['user_id'];
            $PHORUM['user']['newflags'][$forum_id] = phorum_cache_get('newflags', $cachekey, $cache_version);
        }
    }
    // No cached data found? Then retrieve the newflags from the database.
    if ($PHORUM['user']['newflags'][$forum_id] === NULL) {
        $PHORUM['user']['newflags'][$forum_id] = phorum_db_newflag_get_flags($forum_id);
        if ($PHORUM['cache_newflags']) {
            phorum_cache_put('newflags', $cachekey, $PHORUM['user']['newflags'][$forum_id], 86400, $cache_version);
        }
    }
    return $PHORUM['user']['newflags'][$forum_id];
}
示例#6
0
/**
* This function returns the count of unread messages the current user and forum
* optionally for a given forum (for the index)
*/
function phorum_db_newflag_get_unread_count($forum_id=0)
{
    $PHORUM = $GLOBALS["PHORUM"];

    settype($forum_id, "int");

    if(empty($forum_id)) $forum_id=$PHORUM["forum_id"];

    // get the read message array
    $read_msgs = phorum_db_newflag_get_flags($forum_id);

    if($read_msgs["min_id"]==0) return array(0,0);

    $sql="SELECT count(*) as count FROM ".$PHORUM['message_table']." WHERE message_id NOT in (".implode(",", $read_msgs).") and message_id > {$read_msgs['min_id']} and forum_id in ({$forum_id},0) and status=".PHORUM_STATUS_APPROVED." and not ".PHORUM_SQL_MOVEDMESSAGES;

    $conn = phorum_db_postgresql_connect();
    $res = pg_query($conn, $sql);

    if ($err = pg_last_error()) phorum_db_pg_last_error("$err: $sql");

    $counts[] = pg_fetch_result($res, 0, "count");

    $sql="SELECT count(*) as count FROM ".$PHORUM['message_table']." WHERE message_id NOT in (".implode(",", $read_msgs).") and message_id > {$read_msgs['min_id']} and forum_id in ({$forum_id},0) and parent_id=0 and status=".PHORUM_STATUS_APPROVED." and not ".PHORUM_SQL_MOVEDMESSAGES;

    $conn = phorum_db_postgresql_connect();
    $res = pg_query($conn, $sql);

    if ($err = pg_last_error()) phorum_db_pg_last_error("$err: $sql");

    $counts[] = pg_fetch_result($res, 0, "count");

    return $counts;
}