示例#1
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);
}
示例#2
0
 if ($PHORUM['threaded_read'] && isset($PHORUM["reverse_threading"]) && $PHORUM["reverse_threading"]) {
     $message_index = array_reverse($message_index);
 }
 $start = $PHORUM["read_length"] * ($page - 1);
 if (!$PHORUM['threaded_read']) {
     // get the message-ids from this page (only in flat mode)
     $message_ids_page = array_slice($message_index, $start, $PHORUM["read_length"]);
 } else {
     // we need all message in threaded read ...
     $message_ids_page = $message_index;
 }
 // we need the threadstarter too but its not available in the additional pages
 if ($page > 1) {
     array_unshift($message_ids_page, $thread);
 }
 $cache_messages = phorum_cache_get('message', $message_ids_page);
 // check the returned messages if they were found in the cache
 $db_messages = array();
 $msg_not_in_cache = 0;
 foreach ($message_ids_page as $mid) {
     if (!isset($cache_messages[$mid])) {
         $db_messages[] = $mid;
         $msg_not_in_cache++;
     } else {
         $data[$mid] = $cache_messages[$mid];
         $data['users'][] = $data[$mid]['user_id'];
     }
 }
 if ($msg_not_in_cache) {
     $db_messages = phorum_db_get_message($db_messages, 'message_id');
     // store the found messages in the cache
示例#3
0
文件: user.php 项目: mgs2/kw-forum
/**
 * Retrieve data for Phorum users.
 *
 * @param mixed $user_id
 *     Either a single user_id or an array of user_ids.
 *
 * @param boolean $detailed
 *     If this parameter is TRUE (default is FALSE), then the user's
 *     groups and permissions are included in the user data.
 *
 * @param boolean $use_write_server
 *     This parameter is for internal use only. It is used to flag that
 *     the database layer has to run the query against the master database
 *     server (known as the "write server"; only applicable if the database
 *     system is setup as a replicated master/slave environment). When you
 *     are using this API call in your own code, then you most probably do
 *     not need to use this parameter.
 *
 * @return mixed
 *     If the $user_id parameter is a single user_id, then either an array
 *     containing user data is returned or NULL if the user was not found.
 *     If the $user_id parameter is an array of user_ids, then an array
 *     of user data arrays is returned, indexed by the user_id.
 *     Users for user_ids that are not found are not included in the
 *     returned array.
 */
function phorum_api_user_get($user_id, $detailed = FALSE, $use_write_server = FALSE, $raw_data = FALSE)
{
    $PHORUM = $GLOBALS['PHORUM'];
    if (!is_array($user_id)) {
        $user_ids = array($user_id);
    } else {
        $user_ids = $user_id;
    }
    // Prepare the return data array. For each requested user_id,
    // a slot is prepared in this array. Also, turn the user id array
    // into an array which has the user_id as both the key and value.
    $users = array();
    $new_user_ids = array();
    foreach ($user_ids as $id) {
        $users[$id] = NULL;
        $new_user_ids[$id] = $id;
    }
    $user_ids = $new_user_ids;
    // First, try to retrieve user data from the user cache,
    // if user caching is enabled.
    if ($raw_data === FALSE && !empty($PHORUM['cache_users'])) {
        $cached_users = phorum_cache_get('user', $user_ids);
        if (is_array($cached_users)) {
            foreach ($cached_users as $id => $user) {
                $users[$id] = $user;
                unset($user_ids[$id]);
            }
            // We need to retrieve the data for some dynamic fields
            // from the database.
            $dynamic_data = phorum_db_user_get_fields(array_keys($cached_users), array('date_last_active', 'last_active_forum', 'posts'));
            // Store the results in the users array.
            foreach ($dynamic_data as $id => $data) {
                $users[$id] = array_merge($users[$id], $data);
            }
        }
    }
    // Retrieve user data for the users for which no data was
    // retrieved from the cache.
    if (count($user_ids)) {
        $db_users = phorum_db_user_get($user_ids, $detailed, $use_write_server, $raw_data);
        foreach ($db_users as $id => $user) {
            // Merge the group and forum permissions into a final
            // permission value per forum. Forum permissions that are
            // assigned to a user directly override any group based
            // permission.
            if (!$user['admin']) {
                if (!empty($user['group_permissions'])) {
                    foreach ($user['group_permissions'] as $fid => $perm) {
                        if (!isset($user['permissions'][$fid])) {
                            $user['permissions'][$fid] = $perm;
                        } else {
                            $user['permissions'][$fid] |= $perm;
                        }
                    }
                }
                if (!empty($user['forum_permissions'])) {
                    foreach ($user['forum_permissions'] as $fid => $perm) {
                        $user['permissions'][$fid] = $perm;
                    }
                }
            }
            // If detailed information was requested, we store the data in
            // the cache. For non-detailed information, we do not cache the
            // data, because there is not much to gain there by caching.
            if ($detailed && !empty($PHORUM['cache_users']) && $raw_data === FALSE) {
                phorum_cache_put('user', $id, $user);
            }
            // Store the results in the users array.
            $users[$id] = $user;
        }
    }
    // Remove the users for which we did not find data from the array.
    foreach ($users as $id => $user) {
        if ($user === NULL) {
            unset($users[$id]);
        }
    }
    /**
     * [hook]
     *     user_get
     *
     * [description]
     *     This hook can be used to handle the data that was retrieved
     *     from the database for a user. Modules can add and modify the
     *     user data.<sbr/>
     *     <sbr/>
     *     In combination with the <hook>user_save</hook> hook, this hook
     *     could also be used to store and retrieve some of the Phorum
     *     user fields in some external system
     *
     * [category]
     *     User data handling
     *
     * [when]
     *     Just after user data has been retrieved from the database.
     *
     * [input]
     *     This hook receives two arguments.<sbr/>
     *     The first argument contains an array of users.
     *     Each item in this array is an array containing data for
     *     a single user, which can be updated.<sbr/>
     *     The second argument contains a boolean that indicates whether
     *     detailed information (i.e. including group info) is retrieved.
     *
     * [output]
     *     The array that was used as the first argument for the hook call,
     *     possibly with some updated users in it.
     *
     * [example]
     *     <hookcode>
     *     function phorum_mod_foo_user_get($user, $detailed)
     *     {
     *         // Let's asume that our usernames are based on the
     *         // system users on a UNIX system. We could merge some
     *         // info from the password file with the Phorum info here.
     *
     *         // First try to lookup the password file entry.
     *         // Return if this lookup fails.
     *         $pw = posix_getpwnam($user['username']);
     *         if (empty($pw)) return $user;
     *
     *         // On a lot of systems, the "gecos" field contains
     *         // the real name for the user.
     *         $user['real_name'] = $pw["gecos"] != ''
     *                            ? $pw["gecos"]
     *                            : $user["real_name"];
     *
     *         // If a custom profile field "shell" was created, then
     *         // we could also put the user's shell in the data.
     *         $user['shell'] = $pw['shell'];
     *
     *         return $user;
     *     }
     *     </hookcode>
     */
    if (isset($PHORUM['hooks']['user_get'])) {
        $users = phorum_hook('user_get', $users, $detailed);
    }
    // Return the results.
    if (is_array($user_id)) {
        return $users;
    } else {
        return isset($users[$user_id]) ? $users[$user_id] : NULL;
    }
}
示例#4
0
文件: feed.php 项目: mgs2/kw-forum
if (!empty($PHORUM["folder_flag"]) && $PHORUM["forum_id"] != $PHORUM["vroot"]) {
    exit;
}
// Get the forums that this user can read.
// Check all forums below the current (v)root.
if ($PHORUM["forum_id"] == $PHORUM["vroot"]) {
    $forums = phorum_db_get_forums(null, null, $PHORUM["forum_id"]);
} else {
    // its cheap to copy this even though there is more than needed in it
    $forums[$PHORUM["forum_id"]] = $PHORUM;
}
// grab the data from cache if we can
// only do this with caching enabled
$cache_key = $_SERVER["REQUEST_URI"] . "," . $PHORUM["user"]["user_id"];
if (isset($PHORUM['cache_rss']) && !empty($PHORUM['cache_rss'])) {
    $cache = phorum_cache_get("feed", $cache_key);
}
if (!empty($cache)) {
    // extract the two members from cache
    list($data, $content_type) = $cache;
} else {
    // if it wasn't in cache, we need to make it
    // init array
    $messages = array();
    // check if this is a thread subscription
    $thread = isset($PHORUM["args"][1]) ? (int) $PHORUM["args"][1] : 0;
    if ($thread) {
        $PHORUM["args"]["replies"] = 1;
    }
    // check if we are getting replies
    $replies = empty($PHORUM["args"]["replies"]) ? false : true;
示例#5
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();
}
示例#6
0
                    trigger_error("javascript_register hook: module registration " . "error: \"cache_key\" field missing for source " . "\"{$r['source']}\" in module \"{$r['module']}\".");
                    exit(1);
                }
                break;
        }
    } else {
        trigger_error("javascript_register hook: module registration error: " . "illegal format for source definition \"{$r['source']}\" " . "in module \"{$r['module']}\".");
        exit(1);
    }
    $cache_key .= '|' . $r['module'] . ':' . $r['cache_key'];
}
$cache_key = md5($cache_key);
$content = NULL;
$cache_time = 0;
if (!empty($PHORUM['cache_javascript'])) {
    $cache_data = phorum_cache_get('js', $cache_key);
    if ($cache_data !== null) {
        list($cache_time, $content) = $cache_data;
    }
}
// Create the cache file if it does not exist or if caching is disabled.
if (isset($PHORUM['args']['refresh']) || $content === null) {
    $content = '';
    foreach ($module_registrations as $id => $r) {
        $content .= "/* Added by module \"{$r['module']}\", " . "{$r['type']} \"{$r['source']}\" */\n";
        switch ($r['type']) {
            case "file":
                ob_start();
                // Make sure that relative paths start with "./",
                // just in case "." is not in the PHP include path.
                $path = $r['source'][0] == '/' ? $r['source'] : './' . $r['source'];
示例#7
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);
    }
示例#8
0
$subscr_array_final = array();
unset($subscr_array["forum_ids"]);
foreach ($subscr_array as $id => $data) {
    $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)) {
示例#9
0
/**
 * Strips HTML <tags> and BBcode [tags] from the body.
 *
 * @param body - The block of body text to strip
 * @return stripped - The stripped body
 */
function phorum_strip_body($body, $strip_tags = true)
{
    if ($strip_tags) {
        // Strip HTML <tags>
        $stripped = preg_replace("|</*[a-z][^>]*>|i", "", $body);
        // Strip BB Code [tags]
        $stripped = preg_replace("|\\[/*[a-z][^\\]]*\\]|i", "", $stripped);
    } else {
        $stripped = $body;
    }
    // do badwords check
    // 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;
        }
    }
    if ($bad_word_check) {
        $stripped = preg_replace($replace_words, $replace_vals, $stripped);
    }
    return $stripped;
}
示例#10
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];
}
示例#11
0
/**
 * calls the db-function for listing all the moderators for a forum
 * This returns an array of moderators, key as their userid, value as their email address.
 */
function phorum_user_get_moderators( $forum_id , $ignore_user_perms = false, $for_email = false)
{
    $gotmods=false;
    if(isset($GLOBALS["PHORUM"]['cache_users']) && $GLOBALS["PHORUM"]['cache_users']) {
        $mods=phorum_cache_get('user','moderators-'.$forum_id.'-'.$ignore_user_perms);
        if($mods != null) {
            $gotmods=true;
        }
    }
    if(!$gotmods) {
        $mods=phorum_db_user_get_moderators( $forum_id , $ignore_user_perms, $for_email);
    }
    return $mods;
}
示例#12
0
/**
 * Check a single banlist for a match.
 * @param value - The value to check.
 * @param type - The type of banlist to check the value against.
 * @return True if all is okay. False if a match has been found.
 */
function phorum_check_ban_lists($value, $type)
{
    $PHORUM = $GLOBALS['PHORUM'];
    // Load the ban lists.
    if (!isset($GLOBALS["PHORUM"]["banlists"])) {
        $cache_key = $PHORUM['forum_id'];
        if (isset($PHORUM['cache_banlists']) && $PHORUM['cache_banlists']) {
            $GLOBALS["PHORUM"]["banlists"] = phorum_cache_get('banlist', $cache_key, $PHORUM['banlist_version']);
            if (!is_array($GLOBALS["PHORUM"]["banlists"]) || !count($GLOBALS["PHORUM"]["banlists"])) {
                unset($GLOBALS["PHORUM"]["banlists"]);
            }
        }
        // not found or no caching enabled
        if (!isset($GLOBALS["PHORUM"]["banlists"])) {
            $GLOBALS["PHORUM"]["banlists"] = phorum_db_get_banlists();
            if (isset($GLOBALS["PHORUM"]["banlists"]) && isset($PHORUM['cache_banlists']) && $PHORUM['cache_banlists']) {
                phorum_cache_put('banlist', $cache_key, $GLOBALS["PHORUM"]["banlists"], 7200, $PHORUM['banlist_version']);
            }
        }
    }
    if (!isset($GLOBALS['PHORUM']['banlists'])) {
        return true;
    }
    $banlists = $GLOBALS['PHORUM']['banlists'];
    $value = trim($value);
    if (!empty($value)) {
        if (isset($banlists[$type]) && is_array($banlists[$type])) {
            foreach ($banlists[$type] as $item) {
                if (!empty($item['string']) && ($item["pcre"] && @preg_match("/\\b" . $item['string'] . "\\b/i", $value) || !$item["pcre"] && stristr($value, $item["string"]) && $type != PHORUM_BAD_USERID || $type == PHORUM_BAD_USERID && $value == $item["string"])) {
                    return false;
                }
            }
        }
    }
    return true;
}
示例#13
0
文件: list.php 项目: mgs2/kw-forum
    $nextpage = $page + 1;
    $PHORUM["DATA"]["URL"]["NEXTPAGE"] = str_replace(array('%forum_id%', '%page_num%'), array($PHORUM["forum_id"], $nextpage), $list_page_url_template);
}
if ($page > 1) {
    $prevpage = $page - 1;
    $PHORUM["DATA"]["URL"]["PREVPAGE"] = str_replace(array('%forum_id%', '%page_num%'), array($PHORUM["forum_id"], $prevpage), $list_page_url_template);
}
$min_id = 0;
$rows = NULL;
$bodies_in_list = isset($PHORUM['TMP']['bodies_in_list']) && $PHORUM['TMP']['bodies_in_list'];
if ($PHORUM['cache_messages'] && (!$PHORUM['DATA']['LOGGEDIN'] || $PHORUM['use_cookies']) && !$PHORUM['count_views']) {
    $cache_key = $PHORUM['forum_id'] . "-" . $PHORUM['cache_version'] . "-" . $page . "-";
    $cache_key .= $PHORUM['threaded_list'] . "-" . $PHORUM['threaded_read'] . "-" . $PHORUM["language"];
    $cache_key .= "-" . $PHORUM["count_views"] . "-" . ($bodies_in_list ? "1" : "0") . "-" . $PHORUM['float_to_top'];
    $cache_key .= "-" . $PHORUM['user']['tz_offset'];
    $rows = phorum_cache_get('message_list', $cache_key);
}
if ($rows == null) {
    //timing_mark('before db');
    // Get the threads
    $rows = array();
    // get the thread set started
    $rows = phorum_db_get_thread_list($offset, $bodies_in_list);
    //timing_mark('after db');
    // redirect if invalid page
    if (count($rows) < 1 && $offset > 0) {
        $dest_url = phorum_get_url(PHORUM_LIST_URL);
        phorum_redirect_by_url($dest_url);
        exit;
    }
    if ($PHORUM["threaded_list"]) {
示例#14
0
$language = isset($_POST['language']) ? $_POST['language'] : $PHORUM["SETTINGS"]["default_language"];
$filename = isset($_POST['filename']) ? trim($_POST['filename']) : '';
$displayname = isset($_POST['displayname']) ? trim($_POST['displayname']) : '';

// Handle downloading a new language file.
if ($action == 'download_lang') 
{
    // Ditch HTML header we have so far (from the admin framework).
    ob_end_clean();

    // Send the new languagefile to the client. 
    $basename = preg_replace('/-.*$/', '', $filename);
    $fullfile = $basename . '-' . PHORUM . '.php';  
    header ("Content-Type: application/download; filename=$fullfile");
    header ("Content-Disposition: attachment; filename=\"$fullfile\"");
    $langfile = phorum_cache_get('updated_language', $filename);
    print $langfile;
    
    exit();
}

// Handle updating a language.
if ($action == 'update_lang') {
    $langinfo = phorum_get_language_info();
    return phorum_generate_language_file($language, $langinfo[$language], false);
}

// Handle generating a new language.
if ($action == 'generate_lang') {
    $filename = preg_replace('/\.php$/i', '', basename($filename));
    if ($filename == '') {
示例#15
0
//   along with this program.                                                 //
//   July 19 Fixed by Dagon, Date format and Location default                 //
////////////////////////////////////////////////////////////////////////////////

define('phorum_page', 'rss');

include_once("./common.php");
include_once("./include/format_functions.php");

// check this forum allows RSS
if(!$PHORUM['use_rss']){
    exit();
}

$cache_key = $_SERVER["QUERY_STRING"].",".$PHORUM["user"]["user_id"]; 
$data = phorum_cache_get("rss", $cache_key);

if(empty($data)){

    if($PHORUM["forum_id"]==$PHORUM["vroot"]){
        $forums = phorum_db_get_forums(0, -1, $PHORUM["vroot"]);
        $forum_ids = array_keys($forums);
    } elseif($PHORUM["folder_flag"] && $PHORUM["vroot"]==0 && $PHORUM["forum_id"]!=0){
        // we don't support rss for normal folders
        exit();
    } else {
        $forum_ids = $PHORUM["forum_id"];
        $forums = phorum_db_get_forums($PHORUM["forum_id"]);
    }
    
    // find default forum for announcements