Exemplo n.º 1
0
/**
 * A common function which is used to save the userdata from the post-data.
 * @param panel - The panel for which to save data.
 * @return array - An array containing $error and $okmsg.
 */
function phorum_controlcenter_user_save($panel)
{
    $PHORUM = $GLOBALS['PHORUM'];
    $error = "";
    $okmsg = "";
    // Setup the default userdata fields that can be changed
    // from the control panel interface.
    $userdata = array('signature' => NULL, 'hide_email' => NULL, 'hide_activity' => NULL, 'password' => NULL, 'password_temp' => NULL, 'tz_offset' => NULL, 'is_dst' => NULL, 'user_language' => NULL, 'threaded_list' => NULL, 'threaded_read' => NULL, 'email_notify' => NULL, 'show_signature' => NULL, 'pm_email_notify' => NULL, 'email' => NULL, 'email_temp' => NULL, 'user_template' => NULL, 'moderation_email' => NULL, 'real_name' => NULL);
    // Add custom profile fields as acceptable fields.
    foreach ($PHORUM["PROFILE_FIELDS"] as $id => $field) {
        if ($id === "num_fields" || !empty($field['deleted'])) {
            continue;
        }
        $userdata[$field["name"]] = NULL;
    }
    // Update userdata with $_POST information.
    foreach ($_POST as $key => $val) {
        if (array_key_exists($key, $userdata)) {
            $userdata[$key] = $val;
        }
    }
    // Remove unused profile fields.
    foreach ($userdata as $key => $val) {
        if (is_null($val)) {
            unset($userdata[$key]);
        }
    }
    // Set static userdata.
    $userdata["user_id"] = $PHORUM["user"]["user_id"];
    /**
     * [hook]
     *     cc_save_user
     *
     * [description]
     *     This hook works the same way as the <hook>before_register</hook>
     *     hook, so you can also use it for changing and checking the user data
     *     that will be saved in the database. There's one difference. If you
     *     want to check a custom field, you'll also need to check the panel
     *     which you are on, because this hook is called from multiple panels.
     *     The panel that you are on will be stored in the
     *     <literal>panel</literal> field of the user data.<sbr/>
     *     <sbr/>
     *     The example hook belows demonstrates code which could be used if you
     *     have added a custom field to the template for the option
     *     <literal>Edit My Profile</literal> in the control panel.
     *
     * [category]
     *     Control center
     *
     * [when]
     *     In <filename>control.php</filename>, right before data for a user is
     *     saved in the control panel.
     *
     * [input]
     *     An array containing the user data to save.
     *     <ul>
     *     <li>error:
     *         modules can fill this field with an error message to show.</li>
     *     </ul>
     *
     * [output]
     *     The same array as the one that was used for the hook call
     *     argument, possibly with the "error" field updated in it.
     *
     * [example]
     *     <hookcode>
     *     function phorum_mod_foo_cc_save_user ($data)
     *     {
     *         // Only check data for the panel "user".
     *         if ($data['panel'] != "user") return $data;
     *
     *         $myfield = trim($data['your_custom_field']);
     *         if (empty($myfield)) {
     *             $data['error'] = 'You need to fill in my custom field';
     *         }
     *
     *         return $data;
     *     }
     *     </hookcode>
     */
    if (isset($PHORUM["hooks"]["cc_save_user"])) {
        $userdata = phorum_hook("cc_save_user", $userdata);
    }
    // Set $error, in case the cc_save_user hook did set an error.
    if (isset($userdata['error'])) {
        $error = $userdata['error'];
        unset($userdata['error']);
        // Try to update the userdata in the database.
    } elseif (!phorum_api_user_save($userdata)) {
        // Updating the user failed.
        $error = $PHORUM["DATA"]["LANG"]["ErrUserAddUpdate"];
    } else {
        // Updating the user was successful.
        $okmsg = $PHORUM["DATA"]["LANG"]["ProfileUpdatedOk"];
        // Let the userdata be reloaded.
        phorum_api_user_set_active_user(PHORUM_FORUM_SESSION, $userdata["user_id"]);
        // If a new password was set, then reset all session id(s), so
        // other computers or browser will lose any active session that
        // they are running.
        if (isset($userdata["password"]) && $userdata["password"] != '') {
            phorum_api_user_session_create(PHORUM_FORUM_SESSION, PHORUM_SESSID_RESET_ALL);
        }
        // Copy data from the updated user back into the user template data.
        $formatted = phorum_api_user_format(array($GLOBALS['PHORUM']['user']));
        foreach ($formatted[0] as $key => $val) {
            $GLOBALS['PHORUM']['DATA']['USER'][$key] = $val;
        }
        // Copy data from the updated user back into the template data.
        // Leave PANEL and forum_id alone (these are injected into the
        // userdata in the template from this script).
        foreach ($GLOBALS["PHORUM"]["DATA"]["PROFILE"] as $key => $val) {
            if ($key == "PANEL" || $key == "forum_id") {
                continue;
            }
            if (isset($GLOBALS["PHORUM"]["user"][$key])) {
                $GLOBALS["PHORUM"]["DATA"]["PROFILE"][$key] = $GLOBALS["PHORUM"]["user"][$key];
            } else {
                $GLOBALS["PHORUM"]["DATA"]["PROFILE"][$key] = "";
            }
        }
    }
    return array($error, $okmsg);
}
Exemplo n.º 2
0
  *             $PHORUM['threaded_list'] = PHORUM_THREADED_DEFAULT;
  *         } elseif ($_COOKIE['list_style'] == 'threaded') {
  *             $PHORUM['threaded_list'] = PHORUM_THREADED_ON;
  *         } elseif ($_COOKIE['list_style'] == 'flat') {
  *             $PHORUM['threaded_list'] = PHORUM_THREADED_OFF;
  *         } elseif ($_COOKIE['list_style'] == 'hybrid') {
  *             $PHORUM['threaded_list'] = PHORUM_THREADED_HYBRID;
  *         }
  *     }
  *     </hookcode>
  */
 $page_hook = 'page_' . phorum_page;
 if (isset($PHORUM["hooks"][$page_hook])) {
     phorum_hook($page_hook, "");
 }
 $formatted = phorum_api_user_format(array($PHORUM['user']));
 $PHORUM['DATA']['USER'] = $formatted[0];
 $PHORUM['DATA']['PHORUM_PAGE'] = phorum_page;
 $PHORUM['DATA']['USERTRACK'] = $PHORUM['track_user_activity'];
 $PHORUM['DATA']['VROOT'] = $PHORUM['vroot'];
 // used in all forms as it seems
 $PHORUM['DATA']['POST_VARS'] .= "<input type=\"hidden\" name=\"forum_id\" value=\"{$PHORUM["forum_id"]}\" />\n";
 if (isset($PHORUM['use_rss']) && $PHORUM['use_rss']) {
     if ($PHORUM["default_feed"] == "rss") {
         $PHORUM["DATA"]["FEED"] = $PHORUM["DATA"]["LANG"]["RSS"];
         $PHORUM["DATA"]["FEED_CONTENT_TYPE"] = "application/rss+xml";
     } else {
         $PHORUM["DATA"]["FEED"] = $PHORUM["DATA"]["LANG"]["ATOM"];
         $PHORUM["DATA"]["FEED_CONTENT_TYPE"] = "application/atom+xml";
     }
 }