Beispiel #1
0
/**
 * function to handle the nice urls for Custom Profile Fields
 * 
 * @param $page
 * @return unknown_type
 */
function profile_manager_page_handler($page)
{
    switch ($page[0]) {
        case "forms":
            $form = $page[1];
            if (!empty($form) && elgg_is_admin_logged_in()) {
                set_input("guid", $page[2]);
                include dirname(__FILE__) . "/pages/forms/" . $form . ".php";
                return true;
            }
            break;
        case "validate_username":
            if (elgg_is_logged_in()) {
                $new_username = get_input("username");
                $valid = false;
                if (!empty($new_username)) {
                    $valid = profile_manager_validate_username($new_username);
                }
                $result = array("valid" => $valid);
                echo json_encode($result);
                return true;
            }
            break;
        case "user_summary_control":
            include dirname(__FILE__) . "/pages/user_summary_control/preview.php";
            return true;
    }
}
Beispiel #2
0
/**
 * If possible change the username of a user
 *
 * @param string  $hook_name    name of the hook
 * @param string  $entity_type  type of the hook
 * @param unknown $return_value return value
 * @param unknown $parameters   hook parameters
 *
 * @return void
 */
function profile_manager_username_change_hook($hook_name, $entity_type, $return_value, $parameters)
{
    $user_guid = (int) get_input('guid');
    $new_username = get_input('username');
    $enable_username_change = elgg_get_plugin_setting("enable_username_change", "profile_manager");
    if ($enable_username_change == "yes" || $enable_username_change == "admin" && elgg_is_admin_logged_in()) {
        if (!empty($user_guid) && !empty($new_username)) {
            if (profile_manager_validate_username($new_username)) {
                if ($user = get_user($user_guid)) {
                    if ($user->canEdit()) {
                        if ($user->username !== $new_username) {
                            $user->username = $new_username;
                            if ($user->save()) {
                                elgg_register_plugin_hook_handler("forward", "system", "profile_manager_username_change_forward_hook");
                                system_message(elgg_echo('profile_manager:action:username:change:succes'));
                            }
                        }
                    }
                }
            }
        }
    }
}