示例#1
0
/**
 * This function sets the stats for a thread like count, timestamp, etc.
 */
function phorum_update_thread_info($thread)
{
    $PHORUM = $GLOBALS["PHORUM"];
    $messages = phorum_db_get_messages($thread, 0, 1, 1);
    //these are not needed here
    unset($messages['users']);
    // Compute the threadviewcount, based on the individual message views.
    // This can be useful for updating the view counters after enabling
    // the view_count_per_thread option.
    $threadviewcount = 0;
    foreach ($messages as $id => $message) {
        $threadviewcount += $message['viewcount'];
    }
    // remove hidden/unapproved messages from the array
    $filtered_messages = array_filter($messages, "phorum_remove_hidden");
    $thread_count = count($filtered_messages);
    if ($thread_count > 0) {
        $message_ids = array_keys($filtered_messages);
        sort($message_ids);
        $parent_message = $filtered_messages[$thread];
        // find the latest post in the thread (aka recent_message)
        $last_message_id_by_time = 0;
        $last_post_time = 0;
        foreach ($filtered_messages as $message_id => $message_data) {
            if ($message_data['datestamp'] > $last_post_time) {
                $last_post_time = $message_data['datestamp'];
                $last_message_id_by_time = $message_id;
            }
        }
        $recent_message = $filtered_messages[$last_message_id_by_time];
        // prep the message to save
        $message = array();
        $message["thread_count"] = $thread_count;
        $message["threadviewcount"] = $threadviewcount;
        $message["modifystamp"] = $recent_message["datestamp"];
        $message["recent_message_id"] = $recent_message["message_id"];
        $message["recent_user_id"] = $recent_message["user_id"];
        $message["recent_author"] = $recent_message["author"];
        $message["meta"] = $parent_message["meta"];
        // For cleaning up pre-5.2 recent post data.
        unset($message["meta"]["recent_post"]);
        $message["meta"]["message_ids"] = $message_ids;
        // used only for mods
        $message_ids_moderator = array_keys($messages);
        sort($message_ids_moderator);
        $message["meta"]["message_ids_moderator"] = $message_ids_moderator;
        if ($PHORUM['cache_messages']) {
            // we can simply store them here again, no need to invalidate the cache
            // this function is called in any place where we change something to the thread
            phorum_cache_put('message_index', $PHORUM['forum_id'] . "-{$thread}-1", $message["meta"]["message_ids"]);
            phorum_cache_put('message_index', $PHORUM['forum_id'] . "-{$thread}-0", $message["meta"]["message_ids_moderator"]);
            // but we need to invalidate the main-message as its changed for the recent author/message
            phorum_cache_remove('message', $thread);
        }
        phorum_db_update_message($thread, $message);
    }
}
示例#2
0
function phorum_check_cache($is_install = FALSE)
{
    $PHORUM = $GLOBALS["PHORUM"];
    $dir = $PHORUM["cache"];
    // Some general solution descriptions.
    $solution_1 = "Change the Cache Directory setting under\n                       General Settings.";
    $solution_2 = "Change the Cache Directory setting under General \n                       Settings or give your webserver more permissions\n                       for the current cache directory.";
    // Check if the cache directory exists.
    if (!file_exists($dir) || !is_dir($dir)) {
        return array($is_install ? PHORUM_SANITY_WARN : PHORUM_SANITY_CRIT, "The system is unable to find the cache\n             directory \"" . htmlspecialchars($dir) . "\" on\n             your system.", $solution_1);
    }
    $dummy_file = "{$dir}/sanity_check_dummy_file";
    // Check if we can create files in the cache directory.
    $fp = @fopen($dummy_file, "w");
    if (!$fp) {
        return array($is_install ? PHORUM_SANITY_WARN : PHORUM_SANITY_CRIT, "The system is unable to write files\n             to your cache directory \"" . htmlspecialchars($dir) . "\".\n             The system error was:<br/><br/>" . htmlspecialchars($php_errormsg) . ".", $solution_2);
    }
    if (!fclose($fp)) {
        return array($is_install ? PHORUM_SANITY_WARN : PHORUM_SANITY_CRIT, "The system is able to write a file to your cache\n             directory \"" . htmlspecialchars($dir) . "\",\n             however closing the file failed.", "Failure to close a file mostly indicates that the disk\n             on which the file is written is full. So check if your\n             server doesn't have any full disk and free some space\n             if this is the case.");
    }
    // Some very unusual thing might happen. On Windows2000 we have seen
    // that the webserver can write a message to the cache directory,
    // but that it cannot read it afterwards. Probably due to
    // specific NTFS file permission settings. So here we have to make
    // sure that we can open the file that we just wrote.
    $checkfp = fopen($dummy_file, "r");
    if (!$checkfp) {
        return array($is_install ? PHORUM_SANITY_WARN : PHORUM_SANITY_CRIT, "The system was able to write a file to your cache directory \n             \"" . htmlspecialchars($dir) . "\", but afterwards the created\n             file could not be read by the webserver. This is probably \n             caused by the file permissions on your cache directory.", $solution_2);
    }
    fclose($checkfp);
    unlink($dummy_file);
    $dummy_dir = "{$dir}/sanity_check_dummy_dir";
    // Check if we can create directories in the cache directory.
    if (!@mkdir($dummy_dir)) {
        return array($is_install ? PHORUM_SANITY_WARN : PHORUM_SANITY_CRIT, "The system is unable to create directories\n             in your cache directory \"" . htmlspecialchars($dir) . "\".\n             The system error was:<br/><br/>" . htmlspecialchars($php_errormsg) . ".", $solution_2);
    }
    rmdir($dummy_dir);
    // All seems OK. Do a final system check where we check
    // the caching system like the Phorum system will do.
    phorum_cache_put('sanity_checks', 'dummy', 'dummy');
    $entry = phorum_cache_get('sanity_checks', 'dummy');
    phorum_cache_remove('sanity_checks', 'dummy');
    if ($entry != 'dummy') {
        return array(PHORUM_SANITY_WARN, "There might be a problem in Phorum's caching system.\n             Storing and retrieving a dummy key failed. If you\n             experience problems with your Phorum installation,\n             it might be because of this.", "As a work around, you can disable the caching facilities\n             in the admin interface (note: this will not remove this\n             warning; it will only keep you out of troubles by making\n             sure that the caching system is not used). Please contact\n             the Phorum developers to find out what the problem is.");
    }
    return array(PHORUM_SANITY_OK, NULL, NULL);
}
示例#3
0
 // include the correct template
 $templates = array();
 if ($PHORUM["threaded_read"] == 1) {
     $templates[] = "read_threads";
 } elseif ($PHORUM["threaded_read"] == 2) {
     $templates[] = "read_hybrid";
 } else {
     $templates[] = "read";
 }
 if ($PHORUM["DATA"]["LOGGEDIN"]) {
     // setting read messages really read
     if (count($read_messages)) {
         phorum_db_newflag_add_read($read_messages);
         if ($PHORUM['cache_newflags']) {
             phorum_cache_remove('newflags', $newflagkey);
             phorum_cache_remove('newflags_index', $newflagkey);
         }
     }
 }
 // {REPLY_ON_READ} is set when message replies are done on
 // the read page. The template can use this to add the
 // #REPLY anchor to the page. This way, the browser can jump
 // to the editor when clicking a reply link.
 $PHORUM["DATA"]["REPLY_ON_READ"] = !empty($PHORUM["reply_on_read_page"]);
 if (isset($PHORUM["reply_on_read_page"]) && $PHORUM["reply_on_read_page"]) {
     // Never show the reply box if the message is closed.
     if ($thread_is_closed) {
         $PHORUM["DATA"]["OKMSG"] = $PHORUM["DATA"]["LANG"]["ThreadClosed"];
         $templates[] = "message";
     } else {
         // Prepare the arguments for the posting.php script.
示例#4
0
文件: user.php 项目: mgs2/kw-forum
/**
 * Save the groups and group permissions for a user.
 *
 * @param integer $user_id
 *     The user_id of the user for which to store the group permissions.
 *
 * @param array $groups
 *     An array of groups and their permissions. The keys in this array are
 *     group ids. The values are either group permission values or arrays
 *     containing at least the key "user_status" (which has the group
 *     permission as its value) in them. The group permission value must be
 *     one of the PHORUM_USER_GROUP_* constants.
 */
function phorum_api_user_save_groups($user_id, $groups)
{
    if (!empty($GLOBALS["PHORUM"]['cache_users'])) {
        phorum_cache_remove('user', $user_id);
    }
    $dbgroups = array();
    foreach ($groups as $id => $perm) {
        if (is_array($perm) && isset($perm['user_status'])) {
            $perm = $perm['user_status'];
        }
        if ($perm != PHORUM_USER_GROUP_SUSPENDED && $perm != PHORUM_USER_GROUP_UNAPPROVED && $perm != PHORUM_USER_GROUP_APPROVED && $perm != PHORUM_USER_GROUP_MODERATOR) {
            trigger_error('phorum_api_user_save_groups(): Illegal group permission for ' . 'group id ' . htmlspecialchars($id) . ': ' . htmlspecialchars($perm), E_USER_ERROR);
            return NULL;
        }
        $dbgroups[$id] = $perm;
    }
    /**
     * [hook]
     *     user_save_groups
     *
     * [description]
     *     This hook can be used to handle the groups data that is going to be
     *     stored in the database for a user. Modules can do some last
     *     minute change on the data or keep some external system in sync
     *     with the Phorum user data.
     *
     * [category]
     *     User data handling
     *
     * [when]
     *     Just before the groups for a user are stored in the database.
     *
     * [input]
     *     An array containing user_id and groups-data as another array.
     *
     * [output]
     *     The same array as the one that was used for the hook call
     *     argument, possibly with some updated fields in it.
     *
     * [example]
     *     <hookcode>
     *     function phorum_mod_foo_user_save_groups($data)
     *     {
     *         list($user_id,$groups) = $data;
     *         foreach($groups as $group_id => $group_permission) {
     *             // do something with the groups permissions
     *         }
     *     
     *         return array($user_id,$groups);
     *     }
     *     </hookcode>
     */
    if (isset($GLOBALS['PHORUM']['hooks']['user_save_groups'])) {
        list($user_id, $dbgroups) = phorum_hook('user_save_groups', array($user_id, $dbgroups));
    }
    return phorum_db_user_save_groups($user_id, $dbgroups);
}
示例#5
0
文件: pm.php 项目: mgs2/kw-forum
         // Setup template variables.
         $PHORUM["DATA"]["MESSAGECOUNT"] = count($list);
         $PHORUM["DATA"]["MESSAGES"] = $list;
         $PHORUM["DATA"]["PMLOCATION"] = $pm_folders[$folder_id]["name"];
         $template = "pm_list";
     }
     break;
     // Read a single private message.
 // Read a single private message.
 case "read":
     if ($message = phorum_db_pm_get($pm_id, $folder_id)) {
         // Mark the message read.
         if (!$message['read_flag']) {
             phorum_db_pm_setflag($message["pm_message_id"], PHORUM_PM_READ_FLAG, true);
             // Invalidate user cache, to update message counts.
             phorum_cache_remove('user', $user_id);
         }
         // Run the message through the default message formatting.
         list($message) = phorum_pm_format(array($message));
         // We do not want to show a recipient list if there are
         // a lot of recipients.
         $message["show_recipient_list"] = $message["recipient_count"] < 10;
         /**
          * [hook]
          *     pm_read
          *
          * [availability]
          *     Phorum 5 >= 5.2.7
          *
          * [description]
          *     This hook can be used for reformatting a single private
示例#6
0
    function phorum_check_cache(){
        $PHORUM = $GLOBALS["PHORUM"];
        $dir = $PHORUM["cache"];

        // Some general solution descriptions.
        $solution_1 = "Change the Cache Directory setting under
                       General Settings.";
        $solution_2 = "Change the Cache Directory setting under General 
                       Settings or give your webserver more permissions
                       for the current cache directory.";

        // Check if the cache directory exists.
        if (! file_exists($dir) || ! is_dir($dir)) return array(
            PHORUM_SANITY_CRIT,
            "The system is unable to find the cache
             directory \"".htmlspecialchars($dir)."\" on
             your system.", 
            $solution_1
        );

        // Check if we can create files in the cache directory.
        $fp = @fopen ("$dir/sanity_check_dummy_file", "w");
        if (! $fp) return array (
            PHORUM_SANITY_CRIT,
            "The system is unable to write files
             to your cache directory \"".htmlspecialchars($dir)."\".
             The system error was:<br/><br/>".
             htmlspecialchars($php_errormsg).".",
            $solution_2
        );
        fclose($fp);

        // Some very unusual thing might happen. On Windows2000 we have seen
        // that the webserver can write a message to the cache directory,
        // but that it cannot read it afterwards. Probably due to 
        // specific NTFS file permission settings. So here we have to make 
        // sure that we can open the file that we just wrote.
        $checkfp = fopen("$dir/sanity_check_dummy_file", "r");
        if (! $checkfp) return array(
            PHORUM_SANITY_CRIT,
            "The system was able to write a file to your cache directory 
             \"".htmlspecialchars($dir)."\", but afterwards the created
             file could not be read by the webserver. This is probably 
             caused by the file permissions on your cache directory.",
            $solution_2
        );

        unlink("$dir/sanity_check_dummy_file");

        // Check if we can create directories in the cache directory.
        if (! @mkdir("$dir/sanity_check_dummy_dir")) return array(
            PHORUM_SANITY_CRIT,
            "The system is unable to create directories
             in your cache directory \"".htmlspecialchars($dir)."\".
             The system error was:<br/><br/>".htmlspecialchars($php_errormsg).".",
            $solution_2
        );
        rmdir("$dir/sanity_check_dummy_dir");

        // All seems OK. Do a final system check where we check
        // the caching system like the Phorum system will do.
        phorum_cache_put('sanity_checks', 'dummy', 'dummy');
        $entry = phorum_cache_get('sanity_checks', 'dummy');
        phorum_cache_remove('sanity_checks', 'dummy');
        if ($entry != 'dummy') return array(
            PHORUM_SANITY_WARN,
            "There might be a problem in Phorum's caching system.
             Storing and retrieving a dummy key failed. If you
             experience problems with your Phorum installation,
             it might me because of this.",
            "As a work around, you can disable the caching facilities
             in the admin interface. Please contact the Phorum
             developers to find out what the problem is.",
        );

        return array (PHORUM_SANITY_OK, NULL);
    }
示例#7
0
// remove the message from the cache if caching is enabled
// no need to clear the thread-index as the message has only been changed
if ($PHORUM['cache_messages']) {
    phorum_cache_remove('message', $message["message_id"]);
    phorum_db_update_forum(array('forum_id' => $PHORUM['forum_id'], 'cache_version' => $PHORUM['cache_version'] + 1));
}
// Update children to the same sort setting.
if (!$message["parent_id"] && $origmessage["sort"] != $dbmessage["sort"]) {
    $messages = phorum_db_get_messages($message["thread"], 0);
    unset($messages["users"]);
    foreach ($messages as $message_id => $msg) {
        if ($msg["sort"] != $dbmessage["sort"] || $msg["forum_id"] != $dbmessage["forum_id"]) {
            $msg["sort"] = $dbmessage["sort"];
            phorum_db_update_message($message_id, $msg);
            if ($PHORUM['cache_messages']) {
                phorum_cache_remove('message', $message_id);
            }
        }
    }
}
// Update all thread messages to the same closed setting.
if (!$message["parent_id"] && $origmessage["closed"] != $dbmessage["closed"]) {
    if ($dbmessage["closed"]) {
        phorum_db_close_thread($message["thread"]);
    } else {
        phorum_db_reopen_thread($message["thread"]);
    }
}
// Update thread info.
phorum_update_thread_info($message['thread']);
// Update thread subscription.
示例#8
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);
        }
    }
}
示例#9
0
         *
         * [when]
         *     In <filename>moderation.php</filename>, right after a thread has
         *     been split by a moderator.
         *
         * [input]
         *     The id of the newly created thread
         *
         * [output]
         *     None
         *
         */
        phorum_hook('after_split', $_POST['message']);
        break;
    default:
        if (!isset($PHORUM['DATA']['OKMSG'])) {
            $PHORUM['DATA']['OKMSG'] = "";
        }
        $PHORUM['DATA']["URL"]["REDIRECT"] = $PHORUM["DATA"]["URL"]["LIST"];
}
// remove the affected messages from the cache if caching is enabled.
if ($PHORUM['cache_messages']) {
    foreach ($invalidate_message_cache as $message) {
        phorum_cache_remove('message', $message["message_id"]);
        phorum_db_update_forum(array('forum_id' => $PHORUM['forum_id'], 'cache_version' => $PHORUM['cache_version'] + 1));
    }
}
if (!isset($PHORUM['DATA']['BACKMSG'])) {
    $PHORUM['DATA']["BACKMSG"] = $PHORUM['DATA']["LANG"]["BackToList"];
}
phorum_output($template);
示例#10
0
文件: banlist.php 项目: mgs2/kw-forum
$forum_list = phorum_get_forum_info(2);
$forum_list[0] = "GLOBAL";
if (count($_POST) && $_POST["string"] != "") {
    if ($_POST["curr"] != "NEW") {
        $ret = phorum_db_mod_banlists($_POST['type'], $_POST['pcre'], $_POST['string'], $_POST['forum_id'], $_POST['comments'], $_POST['curr']);
        if (isset($PHORUM['cache_banlists']) && $PHORUM['cache_banlists']) {
            // we need to increase the version in that case to
            // invalidate them all in the cache.
            // TODO: I think I have to work out a way to make the same
            // work with vroots
            if ($_POST['forum_id'] == 0) {
                $PHORUM['banlist_version'] = $PHORUM['banlist_version'] + 1;
                phorum_db_update_settings(array('banlist_version' => $PHORUM['banlist_version']));
            } else {
                // remove the one for that forum
                phorum_cache_remove('banlist', $_POST['forum_id']);
            }
        }
    } else {
        $ret = phorum_db_mod_banlists($_POST['type'], $_POST['pcre'], $_POST['string'], $_POST['forum_id'], $_POST['comments'], 0);
    }
    if (!$ret) {
        $error = "Database error while updating settings.";
    } else {
        phorum_admin_okmsg("Ban Item Updated");
    }
}
if (isset($_POST["curr"]) && isset($_POST["delete"]) && $_POST["confirm"] == "Yes") {
    phorum_db_del_banitem((int) $_POST['curr']);
    phorum_admin_okmsg("Ban Item Deleted");
}
示例#11
0
文件: user.php 项目: sheldon/dejavu
/**
 * Save the groups and group permissions for a user.
 *
 * @param integer $user_id
 *     The user_id of the user for which to store the group permissions.
 *
 * @param array $groups
 *     An array of groups and their permissions. The keys in this array are
 *     group ids. The values are either group permission values or arrays
 *     containing at least the key "user_status" (which has the group
 *     permission as its value) in them. The group permission value must be
 *     one of the PHORUM_USER_GROUP_* constants.
 */
function phorum_api_user_save_groups($user_id, $groups)
{
    if (!empty($GLOBALS["PHORUM"]['cache_users'])) {
        phorum_cache_remove('user', $user_id);
    }
    $dbgroups = array();
    foreach ($groups as $id => $perm) {
        if (is_array($perm) && isset($perm['user_status'])) {
            $perm = $perm['user_status'];
        }
        if ($perm != PHORUM_USER_GROUP_SUSPENDED && $perm != PHORUM_USER_GROUP_UNAPPROVED && $perm != PHORUM_USER_GROUP_APPROVED && $perm != PHORUM_USER_GROUP_MODERATOR) {
            trigger_error('phorum_api_user_save_groups(): Illegal group permission for ' . 'group id ' . htmlspecialchars($id) . ': ' . htmlspecialchars($perm), E_USER_ERROR);
            return NULL;
        }
        $dbgroups[$id] = $perm;
    }
    return phorum_db_user_save_groups($user_id, $dbgroups);
}
示例#12
0
function phorum_user_delete($user_id)
{
    if(isset($GLOBALS["PHORUM"]['cache_users']) && $GLOBALS["PHORUM"]['cache_users']) {
        phorum_cache_remove('user',$user_id);
    }
    return phorum_db_user_delete($user_id);
}