Пример #1
0
function phorum_check_cache($is_install = FALSE)
{
    global $PHORUM;
    $dir = $PHORUM['CACHECONFIG']['directory'];
    // Some general solution descriptions.
    $solution_1 = "Change the Cache Directory setting in\n                   include/config/cache.php.";
    $solution_2 = "Change the Cache Directory setting in\n                   include/config/cache.php or give your webserver more\n                   permissions 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_api_cache_put('sanity_checks', 'dummy', 'dummy');
    $entry = phorum_api_cache_get('sanity_checks', 'dummy');
    phorum_api_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);
}
Пример #2
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_api_cache_remove('message', $PHORUM["forum_id"] . "-" . $message["message_id"]);
    phorum_api_forums_increment_cache_version($PHORUM['forum_id']);
}
// 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_api_cache_remove('message', $PHORUM["forum_id"] . "-" . $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_api_thread_update_metadata($message['thread']);
// Update thread subscription.
Пример #3
0
Файл: pm.php Проект: netovs/Core
         // 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_api_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
Пример #4
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 vroot, 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},
 *     {@link PHORUM_MARKREAD_VROOTS}
 */
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;
        }
    }
    $orig_forum_id = $PHORUM['forum_id'];
    // An array to keep track of the forums for which we need to invalidate
    // the cache later on.
    $processed_forum_ids = array();
    // Handle marking vroots read.
    if ($mode == PHORUM_MARKREAD_VROOTS) {
        foreach ($markread_ids as $vroot) {
            $forums = phorum_api_forums_by_vroot($vroot, PHORUM_FLAG_FORUMS);
            foreach ($forums as $forum) {
                $forum_id = $forum['forum_id'];
                $PHORUM['forum_id'] = $forum_id;
                $PHORUM['DB']->newflag_allread($forum_id);
                $processed_forum_ids[$forum_id] = $forum_id;
            }
        }
    } elseif ($mode == PHORUM_MARKREAD_FORUMS) {
        foreach ($markread_ids as $forum_id) {
            $PHORUM['forum_id'] = $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])) {
                $PHORUM['forum_id'] = $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_id' => $forum_id);
                }
            }
            $processed_forum_ids[$forum_id] = $forum_id;
            $PHORUM['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_id' => $message['forum_id']);
            $processed_forum_ids[$message['forum_id']] = $message['forum_id'];
            $PHORUM['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_api_cache_remove('newflags', $cachekey);
            phorum_api_cache_remove('newflags_index', $cachekey);
        }
    }
    $PHORUM['forum_id'] = $orig_forum_id;
}
Пример #5
0
if (!defined('PHORUM') || phorum_page !== 'moderation') {
    return;
}
settype($_POST['forum_id'], "int");
settype($_POST['message'], "int");
settype($_POST['thread'], "int");
$PHORUM['DATA']['OKMSG'] = $PHORUM["DATA"]['LANG']['MsgSplitOk'];
$PHORUM['DATA']["URL"]["REDIRECT"] = $PHORUM["DATA"]["URL"]["LIST"];
$new_subject = isset($_POST['new_subject']) ? $_POST['new_subject'] : NULL;
$update_subjects = isset($_POST['update_subjects']);
$PHORUM['DB']->split_thread($_POST['message'], $_POST['forum_id'], $new_subject, $update_subjects);
if ($PHORUM['cache_messages']) {
    $message = $PHORUM['DB']->get_message($_POST['thread']);
    foreach ($message['meta']['message_ids'] as $message_id) {
        phorum_api_cache_remove('message', $message_id);
    }
}
// update message count / stats
phorum_api_thread_update_metadata($_POST['thread']);
phorum_api_thread_update_metadata($_POST['message']);
$PHORUM['DB']->update_forum_stats(TRUE);
/*
 * [hook]
 *     after_split
 *
 * [description]
 *     This hook can be used for performing actions on
 *     splitting threads
 *
 * [category]
Пример #6
0
/**
 * @deprecated Replaced by {@link phorum_api_cache_remove()}.
 */
function phorum_cache_remove($type, $key)
{
    return phorum_api_cache_remove($type, $key);
}
Пример #7
0
    case PHORUM_MAKE_STICKY:
        // make a thread sticky
        include PHORUM_PATH . '/include/moderation/make_sticky.php';
        break;
    case PHORUM_MAKE_UNSTICKY:
        // make a thread unsticky
        include PHORUM_PATH . '/include/moderation/make_unsticky.php';
        break;
    default:
        phorum_api_redirect(phorum_moderation_back_url());
}
// Remove the affected messages from the cache if caching is enabled.
if ($PHORUM['cache_messages']) {
    $invalidate_forums = array();
    foreach ($invalidate_message_cache as $message) {
        phorum_api_cache_remove('message', $message['forum_id'] . "-" . $message["message_id"]);
        $invalidate_forums[$message['forum_id']] = $message['forum_id'];
    }
    if (is_array($invalidate_forums) && count($invalidate_forums)) {
        // increment the cache version for all involved forums once
        foreach ($invalidate_forums as $forum_id) {
            phorum_api_forums_increment_cache_version($forum_id);
        }
    }
}
if (!isset($PHORUM['DATA']['BACKMSG'])) {
    $PHORUM['DATA']["BACKMSG"] = $PHORUM['DATA']["LANG"]["BacktoForum"];
}
phorum_api_output($template);
// ----------------------------------------------------------------------
// Functions
Пример #8
0
/**
 * Set the sort type to use for a thread.
 *
 * Note: Historically, there were more sort types available in the Phorum core,
 * which is the reason why sticky threads aren't simply implemented using a
 * single is_sticky field or so.
 *
 * @param integer $thread_id
 *     The id of the thread to set the sort type for.
 *
 * @param integer $sort
 *     PHORUM_SORT_DEFAULT (default) to make the thread a default thread.
 *     PHORUM_SORT_STICKY to make the thread a sticky thread.
 */
function phorum_api_thread_set_sort($thread_id, $sort = PHORUM_SORT_DEFAULT)
{
    global $PHORUM;
    // Check the $sort parameter.
    if ($sort !== PHORUM_SORT_DEFAULT && $sort !== PHORUM_SORT_STICKY) {
        trigger_error('phorum_api_thread_set_sort(): Illegal sort type provided', E_USER_ERROR);
    }
    // Retrieve the messages for the provided thread id.
    $messages = $PHORUM['DB']->get_messages($thread_id, 0, TRUE, TRUE, FALSE);
    unset($messages['users']);
    // Update all messages with the new sort value.
    $forum_id = NULL;
    foreach ($messages as $id => $message) {
        if ($message['sort'] !== $sort) {
            $forum_id = $message['forum_id'];
            $PHORUM['DB']->update_message($id, array('sort' => $sort));
            if (!empty($PHORUM['cache_messages'])) {
                $cache_key = $PHORUM["forum_id"] . "-" . $message["message_id"];
                phorum_api_cache_remove('message', $cache_key);
            }
        }
    }
    // Update the forum statistics to update the sticky_count.
    if ($forum_id !== NULL) {
        $tmp = $PHORUM['forum_id'];
        $PHORUM['forum_id'] = $forum_id;
        $PHORUM['DB']->update_forum_stats(true);
        $PHORUM['forum_id'] = $tmp;
    }
}
Пример #9
0
/**
 * 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)
{
    global $PHORUM;
    if (!empty($PHORUM['cache_users'])) {
        phorum_api_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_api_hook('user_save_groups', array($user_id, $dbgroups));
    }
    return $PHORUM['DB']->user_save_groups($user_id, $dbgroups);
}
Пример #10
0
$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_api_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");
}