Пример #1
0
function phorum_moderator_data_save($moderator_data)
{
    $PHORUM = $GLOBALS["PHORUM"];
    // Clear value in case no data is left in $moderator_data.
    $value = count($moderator_data) ? serialize($moderator_data) : '';
    phorum_api_user_save_raw(array("user_id" => $PHORUM['user']['user_id'], "moderator_data" => $value));
}
Пример #2
0
/**
 * Destroy a Phorum user session.
 *
 * This will destroy a Phorum user session and set the active
 * Phorum user to the anonymous user.
 *
 * @param string $type
 *     The type of session to destroy. This must be one of
 *     {@link PHORUM_FORUM_SESSION} or {@link PHORUM_ADMIN_SESSION}.
 *     See the documentation for {@link phorum_api_user_session_create()}
 *     for more information on Phorum user sessions.
 */
function phorum_api_user_session_destroy($type)
{
    $PHORUM = $GLOBALS['PHORUM'];
    /**
     * [hook]
     *     user_session_destroy
     *
     * [description]
     *     Allow modules to override Phorum's session destroy management or
     *     to even fully omit destroying a session (for example useful
     *     if the hook <hook>user_session_restore</hook> is used
     *     to inherit an external session from some 3rd party application).
     *
     * [category]
     *     User authentication and session handling
     *
     * [when]
     *     Just before Phorum runs its own session destroy code
     *     in the user API function
     *     <literal>phorum_api_user_session_destroy()</literal>.
     *
     * [input]
     *     The session type for which a session must be destroyed.
     *     This can be either <literal>PHORUM_FORUM_SESSION</literal>
     *     or <literal>PHORUM_ADMIN_SESSION</literal>.
     *
     * [output]
     *     Same as input if Phorum has to run its standard session
     *     destroy code or NULL if that code should be fully skipped.
     *
     * [example]
     *     See the <hook>user_session_create</hook> hook for an example
     *     of how to let Phorum setup the PHP session that is destroyed
     *     in this example hook.
     *     <hookcode>
     *     function phorum_mod_foo_user_session_destroy($type)
     *     {
     *         // Let Phorum handle destroying of admin sessions on its own.
     *         if ($type == PHORUM_ADMIN_SESSION) return $type;
     *
     *         // Override the session handling for front end forum sessions.
     *         // We could for example have stored the session in a standard
     *         // PHP session. First, we start a PHP session if that was
     *         // not done yet.
     *         if (!session_id()) session_start();
     *
     *         // After starting the PHP session, we can clear the session
     *         // data for the Phorum user. In the user_session_create hook
     *         // example code, we stored the user_id for the active user
     *         // in the session. Here we clear that data. We could also
     *         // have destroyed the full PHP session, but in that case we
     *         // would risk destroying session data that was setup by
     *         // other PHP scripts.
     *         unset($_SESSION['phorum_user_id']);
     *
     *         // Tell Phorum not to run its own session destroy code.
     *         return NULL;
     *     }
     *     </hookcode>
     */
    $do_phorum_destroy_session = TRUE;
    if (isset($PHORUM['hooks']['user_session_destroy'])) {
        if (phorum_hook('user_session_destroy', $type) === NULL) {
            $do_phorum_destroy_session = FALSE;
        }
    }
    if ($do_phorum_destroy_session) {
        // Destroy session cookie(s). We do not care here if use_cookies is
        // enabled or not. We just want to clean out all that we have here.
        if ($type == PHORUM_FORUM_SESSION) {
            setcookie(PHORUM_SESSION_SHORT_TERM, '', time() - 86400, $PHORUM['session_path'], $PHORUM['session_domain']);
            setcookie(PHORUM_SESSION_LONG_TERM, '', time() - 86400, $PHORUM['session_path'], $PHORUM['session_domain']);
        } elseif ($type == PHORUM_ADMIN_SESSION) {
            setcookie(PHORUM_SESSION_ADMIN, '', time() - 86400, $PHORUM['session_path'], $PHORUM['session_domain']);
        } else {
            trigger_error('phorum_api_user_session_destroy(): Illegal session type: ' . htmlspecialchars($type), E_USER_ERROR);
            return NULL;
        }
        // If cookies are not in use, then the long term session is reset
        // to a new value. That way we fully invalidate URI authentication
        // data, so that old URL's won't work anymore. We can only do this
        // if we have an active Phorum user.
        if ($PHORUM['use_cookies'] == PHORUM_NO_COOKIES && $type == PHORUM_FORUM_SESSION && !empty($PHORUM['user']) && !empty($PHORUM['user']['user_id'])) {
            $user = $PHORUM['user'];
            $sessid_lt = md5($user['username'] . microtime() . $user['password']);
            phorum_api_user_save_raw(array('user_id' => $user['user_id'], 'sessid_lt' => $sessid_lt));
        }
    }
    // Force Phorum to see the anonymous user from here on.
    phorum_api_user_set_active_user(PHORUM_FORUM_SESSION, NULL);
}
Пример #3
0
    echo "This script cannot be run from a browser.";
    return;
}
define("PHORUM_ADMIN", 1);
define('phorum_page', 'rebuild_postcount');
chdir(dirname(__FILE__) . "/..");
require_once './common.php';
// Make sure that the output is not buffered.
phorum_ob_clean();
if (!ini_get('safe_mode')) {
    set_time_limit(0);
    ini_set("memory_limit", "64M");
}
print "\nCounting the posts for all users ...\n";
$postcounts = phorum_db_interact(DB_RETURN_ROWS, "SELECT user_id, count(*) \n     FROM   {$PHORUM["message_table"]}\n     WHERE  user_id != 0\n     GROUP  BY user_id");
print "Updating the post counts ...\n";
$count_total = count($postcounts);
$size = strlen($count_total);
$count = 0;
foreach ($postcounts as $row) {
    phorum_api_user_save_raw(array("user_id" => $row[0], "posts" => $row[1]));
    $count++;
    $perc = floor($count / $count_total * 100);
    $barlen = floor(20 * ($perc / 100));
    $bar = "[";
    $bar .= str_repeat("=", $barlen);
    $bar .= str_repeat(" ", 20 - $barlen);
    $bar .= "]";
    printf("updating %{$size}d / %{$size}d  %s (%d%%)\r", $count, $count_total, $bar, $perc);
}
print "\n\n";
Пример #4
0
 function testUserApiSave()
 {
     $user_id = phorum_api_user_search('username', 'testuser' . $this->sharedFixture, '=');
     $gotten_user = phorum_api_user_get($user_id, true);
     // now for saving the user
     $gotten_user['real_name'] = 'foo';
     $ret = phorum_api_user_save($gotten_user);
     $this->assertGreaterThan(0, $ret, 'Saved changed user.');
     $mod_user2 = array('user_id' => $gotten_user['user_id'], 'real_name' => 'test');
     // and saving it raw too
     $ret = phorum_api_user_save_raw($mod_user2);
     $this->assertTrue($ret, 'Saved changed user (raw).');
 }
Пример #5
0
    return;
}
$real_name_field = NULL;
foreach ($PHORUM['PROFILE_FIELDS'] as $id => $field) {
    if ($id === 'num_fields') {
        continue;
    }
    if ($field['name'] == 'real_name') {
        $field['id'] = $id;
        $real_name_field = $field;
        break;
    }
}
if (empty($real_name_field) || !empty($real_name_field['deleted'])) {
    return;
}
// If we do, then copy all available real_names to the new real_name
// field in the user table.
$sth = $PHORUM['DB']->interact(DB_RETURN_RES, "SELECT * FROM {$PHORUM['DB']->prefix}_user_custom_fields\n     WHERE  type = {$real_name_field['id']}");
while ($row = $PHORUM['DB']->fetch_row($sth, DB_RETURN_ASSOC)) {
    $user = phorum_api_user_get($row['user_id']);
    if ($user) {
        phorum_api_user_save_raw(array('user_id' => $row['user_id'], 'real_name' => $row['data']));
    }
}
// Now we delete the existing real_name custom field.
// We only mark it as deleted. We keep the original data around for
// reference (just in case this upgrade failed in a terrible way)
$field =& $PHORUM['PROFILE_FIELDS'][$real_name_field['id']];
$field['deleted'] = 1;
$PHORUM['DB']->update_settings(array('PROFILE_FIELDS' => $PHORUM['PROFILE_FIELDS']));
Пример #6
0
<?php

require_once './include/api/custom_profile_fields.php';
// Find out if we have an active real_name custom user profile field.
$field = phorum_api_custom_profile_field_byname('real_name');
if (empty($field) || !empty($field['deleted'])) {
    return;
}
// If we do, then copy all available real_names to the new real_name
// field in the user table.
$ids = phorum_api_user_search_custom_profile_field($field['id'], '', '*', TRUE);
if (!empty($ids)) {
    foreach ($ids as $id) {
        $user = phorum_api_user_get($id);
        phorum_api_user_save_raw(array("user_id" => $id, "real_name" => $user["real_name"]));
    }
}
// Now we can delete the existing real_name field.
phorum_api_custom_profile_field_delete($real_name_field_id, TRUE);