'1', 'key' => self::registration_token(), ), home_url( '/' ) ); } private static function registration_status( $user_id ) { return sanitize_key( (string) get_user_meta( (int) $user_id, self::REGISTRATION_STATUS, true ) ); } public static function block_unapproved_login( $user, $username = '', $password = '' ) { if ( !$user instanceof WP_User ) { return $user; } $status = self::registration_status( $user->ID ); if ( 'pending' === $status ) { return new WP_Error('mydrivecloud_registration_pending', __( 'Your account is awaiting administrator approval.', 'mydrivecloud' )); } if ( 'rejected' === $status ) { return new WP_Error('mydrivecloud_registration_rejected', __( 'Your portal access request was not approved.', 'mydrivecloud' )); } if ( 'suspended' === $status ) { return new WP_Error('mydrivecloud_account_suspended', __( 'Your portal access has been suspended by an administrator.', 'mydrivecloud' )); } return $user; } private static function require_admin() { if ( !MyDriveCloud_Roles::user_can( 'manage_access' ) ) { wp_die( esc_html__( 'You do not have permission to manage access.', 'mydrivecloud' ), '', array( 'response' => 403, ) ); } } private static function redirect( $tab = 'clients', $message = '' ) { $url = add_query_arg( array( 'page' => self::PAGE, 'tab' => sanitize_key( $tab ), ), admin_url( 'admin.php' ) ); if ( $message ) { $url = add_query_arg( 'mydrivecloud_notice', rawurlencode( $message ), $url ); } wp_safe_redirect( $url ); exit; } public static function handle_action() { self::require_admin(); check_admin_referer( 'mydrivecloud_access_action' ); global $wpdb; $action = ( isset( $_POST['access_action'] ) ? sanitize_key( wp_unslash( $_POST['access_action'] ) ) : '' ); $now = current_time( 'mysql', true ); if ( 'toggle_client' === $action ) { $user_id = ( isset( $_POST['user_id'] ) ? absint( $_POST['user_id'] ) : 0 ); $user = get_userdata( $user_id ); if ( !$user ) { self::redirect( 'clients', __( 'The user was not found.', 'mydrivecloud' ) ); } if ( user_can( $user, 'mydrivecloud_manage_all' ) ) { self::redirect( 'clients', __( 'MyDriveCloud administrator access cannot be disabled here.', 'mydrivecloud' ) ); } $enabled = !empty( $_POST['enabled'] ); // A per-user false value overrides roles such as Subscriber that normally include portal access. $user->add_cap( 'mydrivecloud_access', $enabled ); MyDriveCloud_DB::audit( ( $enabled ? 'client_access_enabled' : 'client_access_disabled' ), null, array( 'client_id' => $user_id, ) ); self::redirect( 'clients', __( 'Client access was updated.', 'mydrivecloud' ) ); } if ( 'set_client_role' === $action ) { $user_id = ( isset( $_POST['user_id'] ) ? absint( $_POST['user_id'] ) : 0 ); $role = ( isset( $_POST['mydrivecloud_role'] ) ? sanitize_key( wp_unslash( $_POST['mydrivecloud_role'] ) ) : 'client' ); $user = get_userdata( $user_id ); if ( !$user || !MyDriveCloud_Roles::get( $role ) ) { self::redirect( 'clients', __( 'The selected role is invalid.', 'mydrivecloud' ) ); } $selected_role = MyDriveCloud_Roles::get( $role ); if ( $user_id === get_current_user_id() && empty( $selected_role['permissions']['manage_access'] ) ) { self::redirect( 'clients', __( 'You cannot remove your own MyDriveCloud administration permission.', 'mydrivecloud' ) ); } MyDriveCloud_Roles::assign( $user_id, $role ); MyDriveCloud_DB::audit( 'client_role_changed', null, array( 'client_id' => $user_id, 'role' => $role, ) ); self::redirect( 'clients', __( 'The user role was updated.', 'mydrivecloud' ) ); } if ( 'save_client_quota' === $action ) { $user_id = ( isset( $_POST['user_id'] ) ? absint( $_POST['user_id'] ) : 0 ); $user = get_userdata( $user_id ); if ( !$user ) { self::redirect( 'clients', __( 'The client account was not found.', 'mydrivecloud' ) ); } $unlimited = !empty( $_POST['quota_unlimited'] ); $quota_input = ( isset( $_POST['quota_gb'] ) ? sanitize_text_field( wp_unslash( $_POST['quota_gb'] ) ) : '' ); $quota = MyDriveCloud_Settings::validate_quota_gb( $quota_input ); if ( is_wp_error( $quota ) ) { self::redirect( 'clients', $quota->get_error_message() ); } update_user_meta( $user_id, MyDriveCloud_Settings::USER_QUOTA_META, $quota ); update_user_meta( $user_id, MyDriveCloud_Settings::USER_UNLIMITED_META, ( $unlimited ? '1' : '0' ) ); MyDriveCloud_DB::audit( 'client_storage_quota_updated', null, array( 'client_id' => $user_id, 'quota_gb' => $quota, 'unlimited' => $unlimited, ) ); self::redirect( 'clients', __( 'The client storage limit was updated.', 'mydrivecloud' ) ); } if ( 'send_registration_link' === $action ) { $email = ( isset( $_POST['invite_email'] ) ? sanitize_email( wp_unslash( $_POST['invite_email'] ) ) : '' ); if ( !is_email( $email ) ) { self::redirect( 'clients', __( 'Enter a valid e-mail address.', 'mydrivecloud' ) ); } $brand = MyDriveCloud_Settings::brand_name(); /* translators: %s: portal brand name. */ $subject = sprintf( __( 'Your registration invitation to %s', 'mydrivecloud' ), $brand ); /* translators: 1: portal brand name, 2: private registration URL. */ $message = sprintf( __( 'You have been invited to create a client account in %1$s. Open the registration link: %2$s After registration, the account must be approved by an administrator.', 'mydrivecloud' ), $brand, self::registration_url() ); if ( !wp_mail( $email, $subject, $message ) ) { self::redirect( 'clients', __( 'The message could not be sent. Check the site e-mail configuration.', 'mydrivecloud' ) ); } MyDriveCloud_DB::audit( 'registration_invitation_sent', null, array( 'email' => $email, ) ); self::redirect( 'clients', __( 'The registration invitation was sent.', 'mydrivecloud' ) ); } if ( 'regenerate_registration_link' === $action ) { update_option( self::REGISTRATION_TOKEN, wp_generate_password( 40, false, false ), false ); MyDriveCloud_DB::audit( 'registration_link_regenerated' ); self::redirect( 'clients', __( 'A new link was generated. The previous link is no longer valid.', 'mydrivecloud' ) ); } if ( in_array( $action, array('approve_registration', 'reject_registration'), true ) ) { $user_id = ( isset( $_POST['user_id'] ) ? absint( $_POST['user_id'] ) : 0 ); $user = get_userdata( $user_id ); if ( !$user || !in_array( self::registration_status( $user_id ), array('pending', 'rejected'), true ) ) { self::redirect( 'clients', __( 'The registration request was not found.', 'mydrivecloud' ) ); } if ( 'approve_registration' === $action ) { MyDriveCloud_Roles::assign( $user_id, 'client' ); delete_user_meta( $user_id, self::REGISTRATION_STATUS ); $user->add_cap( 'mydrivecloud_access', true ); /* translators: %s: portal brand name. */ $approved_subject = sprintf( __( 'Your %s account was approved', 'mydrivecloud' ), MyDriveCloud_Settings::brand_name() ); /* translators: %s: portal sign-in URL. */ $approved_message = sprintf( __( 'Your account was approved. You can sign in here: %s', 'mydrivecloud' ), MyDriveCloud_Settings::return_url() ); wp_mail( $user->user_email, $approved_subject, $approved_message ); MyDriveCloud_DB::audit( 'registration_approved', null, array( 'client_id' => $user_id, ) ); self::redirect( 'clients', __( 'The client was approved and can now access the portal.', 'mydrivecloud' ) ); } update_user_meta( $user_id, self::REGISTRATION_STATUS, 'rejected' ); $user->add_cap( 'mydrivecloud_access', false ); WP_Session_Tokens::get_instance( $user_id )->destroy_all(); /* translators: %s: portal brand name. */ $rejected_subject = sprintf( __( '%s access request', 'mydrivecloud' ), MyDriveCloud_Settings::brand_name() ); wp_mail( $user->user_email, $rejected_subject, __( 'Your portal access request was not approved. Contact the site administrator for details.', 'mydrivecloud' ) ); MyDriveCloud_DB::audit( 'registration_rejected', null, array( 'client_id' => $user_id, ) ); self::redirect( 'clients', __( 'The client request was rejected.', 'mydrivecloud' ) ); } if ( 'delete_rejected_registration' === $action ) { $user_id = ( isset( $_POST['user_id'] ) ? absint( $_POST['user_id'] ) : 0 ); $user = get_userdata( $user_id ); if ( !$user || 'rejected' !== self::registration_status( $user_id ) ) { self::redirect( 'clients', __( 'The rejected account was not found.', 'mydrivecloud' ) ); } if ( $user_id === get_current_user_id() || user_can( $user, 'mydrivecloud_manage_all' ) ) { self::redirect( 'clients', __( 'This account cannot be deleted here.', 'mydrivecloud' ) ); } $wpdb->delete( MyDriveCloud_DB::table( 'group_members' ), array( 'user_id' => $user_id, ), array('%d') ); $wpdb->delete( MyDriveCloud_DB::table( 'access' ), array( 'subject_type' => 'user', 'subject_id' => $user_id, ), array('%s', '%d') ); MyDriveCloud_DB::audit( 'rejected_registration_deleted', null, array( 'client_id' => $user_id, 'email' => $user->user_email, ) ); require_once ABSPATH . 'wp-admin/includes/user.php'; if ( !wp_delete_user( $user_id ) ) { self::redirect( 'clients', __( 'The rejected account could not be deleted.', 'mydrivecloud' ) ); } self::redirect( 'clients', __( 'The rejected account was permanently deleted.', 'mydrivecloud' ) ); } if ( in_array( $action, array('suspend_client', 'reactivate_client'), true ) ) { $user_id = ( isset( $_POST['user_id'] ) ? absint( $_POST['user_id'] ) : 0 ); $user = get_userdata( $user_id ); if ( !$user ) { self::redirect( 'clients', __( 'The client account was not found.', 'mydrivecloud' ) ); } if ( $user_id === get_current_user_id() || user_can( $user, 'mydrivecloud_manage_all' ) ) { self::redirect( 'clients', __( 'Administrator accounts cannot be suspended here.', 'mydrivecloud' ) ); } if ( in_array( self::registration_status( $user_id ), array('pending', 'rejected'), true ) ) { self::redirect( 'clients', __( 'Approve or reject this registration request first.', 'mydrivecloud' ) ); } if ( 'suspend_client' === $action ) { update_user_meta( $user_id, self::REGISTRATION_STATUS, 'suspended' ); $user->add_cap( 'mydrivecloud_access', false ); WP_Session_Tokens::get_instance( $user_id )->destroy_all(); MyDriveCloud_DB::audit( 'client_suspended', null, array( 'client_id' => $user_id, ) ); self::redirect( 'clients', __( 'The client was suspended and all active sessions were revoked.', 'mydrivecloud' ) ); } delete_user_meta( $user_id, self::REGISTRATION_STATUS ); $user->add_cap( 'mydrivecloud_access', true ); MyDriveCloud_DB::audit( 'client_reactivated', null, array( 'client_id' => $user_id, ) ); self::redirect( 'clients', __( 'The client was reactivated.', 'mydrivecloud' ) ); } if ( 'delete_client' === $action ) { $user_id = ( isset( $_POST['user_id'] ) ? absint( $_POST['user_id'] ) : 0 ); $user = get_userdata( $user_id ); if ( !$user ) { self::redirect( 'clients', __( 'The client account was not found.', 'mydrivecloud' ) ); } if ( $user_id === get_current_user_id() || user_can( $user, 'mydrivecloud_manage_all' ) ) { self::redirect( 'clients', __( 'Administrator accounts cannot be deleted here.', 'mydrivecloud' ) ); } $new_owner = get_current_user_id(); $wpdb->update( MyDriveCloud_DB::table( 'items' ), array( 'owner_id' => $new_owner, ), array( 'owner_id' => $user_id, ), array('%d'), array('%d') ); $wpdb->update( MyDriveCloud_DB::table( 'shares' ), array( 'created_by' => $new_owner, ), array( 'created_by' => $user_id, ), array('%d'), array('%d') ); $wpdb->update( MyDriveCloud_DB::table( 'groups' ), array( 'created_by' => $new_owner, ), array( 'created_by' => $user_id, ), array('%d'), array('%d') ); $wpdb->update( MyDriveCloud_DB::table( 'access' ), array( 'created_by' => $new_owner, ), array( 'created_by' => $user_id, ), array('%d'), array('%d') ); $wpdb->delete( MyDriveCloud_DB::table( 'group_members' ), array( 'user_id' => $user_id, ), array('%d') ); $wpdb->delete( MyDriveCloud_DB::table( 'access' ), array( 'subject_type' => 'user', 'subject_id' => $user_id, ), array('%s', '%d') ); $wpdb->delete( MyDriveCloud_DB::table( 'shares' ), array( 'user_id' => $user_id, ), array('%d') ); MyDriveCloud_DB::audit( 'client_deleted', null, array( 'client_id' => $user_id, 'email' => $user->user_email, 'files_transferred_to' => $new_owner, ) ); require_once ABSPATH . 'wp-admin/includes/user.php'; if ( !wp_delete_user( $user_id ) ) { self::redirect( 'clients', __( 'The client account could not be deleted.', 'mydrivecloud' ) ); } self::redirect( 'clients', __( 'The client account was permanently deleted. Its regular files were transferred to your account.', 'mydrivecloud' ) ); } if ( 'create_role' === $action ) { $name = ( isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '' ); $description = ( isset( $_POST['description'] ) ? sanitize_textarea_field( wp_unslash( $_POST['description'] ) ) : '' ); $permissions = ( isset( $_POST['permissions'] ) ? (array) wp_unslash( $_POST['permissions'] ) : array() ); $result = MyDriveCloud_Roles::create( $name, $description, $permissions ); if ( is_wp_error( $result ) ) { self::redirect( 'roles', $result->get_error_message() ); } MyDriveCloud_DB::audit( 'role_created', null, array( 'role' => $result, ) ); self::redirect( 'roles', __( 'The custom role was created.', 'mydrivecloud' ) ); } if ( 'delete_role' === $action ) { $role = ( isset( $_POST['mydrivecloud_role'] ) ? sanitize_key( wp_unslash( $_POST['mydrivecloud_role'] ) ) : '' ); if ( MyDriveCloud_Roles::current_role_slug() === $role ) { self::redirect( 'roles', __( 'You cannot delete the role assigned to your own account.', 'mydrivecloud' ) ); } if ( !MyDriveCloud_Roles::delete( $role ) ) { self::redirect( 'roles', __( 'The role cannot be deleted.', 'mydrivecloud' ) ); } MyDriveCloud_DB::audit( 'role_deleted', null, array( 'role' => $role, ) ); self::redirect( 'roles', __( 'The role was deleted. Its users were assigned the Client role.', 'mydrivecloud' ) ); } if ( 'create_group' === $action ) { $name = ( isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '' ); $description = ( isset( $_POST['description'] ) ? sanitize_textarea_field( wp_unslash( $_POST['description'] ) ) : '' ); if ( !$name ) { self::redirect( 'groups', __( 'Enter a name for the group.', 'mydrivecloud' ) ); } $created = $wpdb->insert( MyDriveCloud_DB::table( 'groups' ), array( 'name' => $name, 'description' => $description, 'created_by' => get_current_user_id(), 'created_at' => $now, ), array( '%s', '%s', '%d', '%s' ) ); self::redirect( 'groups', ( false === $created ? __( 'The group already exists or could not be created.', 'mydrivecloud' ) : __( 'The group was created.', 'mydrivecloud' ) ) ); } if ( 'save_members' === $action ) { $group_id = ( isset( $_POST['group_id'] ) ? absint( $_POST['group_id'] ) : 0 ); $group = $wpdb->get_var( $wpdb->prepare( 'SELECT id FROM %i WHERE id=%d', MyDriveCloud_DB::table( 'groups' ), $group_id ) ); if ( !$group ) { self::redirect( 'groups', __( 'The group was not found.', 'mydrivecloud' ) ); } $members = ( isset( $_POST['members'] ) ? array_unique( array_map( 'absint', (array) wp_unslash( $_POST['members'] ) ) ) : array() ); $wpdb->delete( MyDriveCloud_DB::table( 'group_members' ), array( 'group_id' => $group_id, ), array('%d') ); foreach ( $members as $user_id ) { if ( $user_id && get_userdata( $user_id ) ) { $wpdb->insert( MyDriveCloud_DB::table( 'group_members' ), array( 'group_id' => $group_id, 'user_id' => $user_id, 'created_at' => $now, ), array('%d', '%d', '%s') ); } } MyDriveCloud_DB::audit( 'group_members_updated', null, array( 'group_id' => $group_id, 'members' => $members, ) ); self::redirect( 'groups', __( 'Group members were updated.', 'mydrivecloud' ) ); } if ( 'delete_group' === $action ) { $group_id = ( isset( $_POST['group_id'] ) ? absint( $_POST['group_id'] ) : 0 ); $wpdb->delete( MyDriveCloud_DB::table( 'access' ), array( 'subject_type' => 'group', 'subject_id' => $group_id, ), array('%s', '%d') ); $wpdb->delete( MyDriveCloud_DB::table( 'group_members' ), array( 'group_id' => $group_id, ), array('%d') ); $wpdb->delete( MyDriveCloud_DB::table( 'groups' ), array( 'id' => $group_id, ), array('%d') ); MyDriveCloud_DB::audit( 'group_deleted', null, array( 'group_id' => $group_id, ) ); self::redirect( 'groups', __( 'The group and its permissions were removed.', 'mydrivecloud' ) ); } if ( 'grant' === $action ) { $item_id = ( isset( $_POST['item_id'] ) ? absint( $_POST['item_id'] ) : 0 ); $subject_type = ( isset( $_POST['subject_type'] ) && 'group' === sanitize_key( wp_unslash( $_POST['subject_type'] ) ) ? 'group' : 'user' ); $subject_id = ( isset( $_POST['subject_id'] ) ? absint( $_POST['subject_id'] ) : 0 ); $item = MyDriveCloud_Permissions::get_item( $item_id ); if ( !$item || !$subject_id ) { self::redirect( 'permissions', __( 'Choose a valid file or folder and recipient.', 'mydrivecloud' ) ); } $valid_subject = ( 'user' === $subject_type ? get_userdata( $subject_id ) : $wpdb->get_var( $wpdb->prepare( 'SELECT id FROM %i WHERE id=%d', MyDriveCloud_DB::table( 'groups' ), $subject_id ) ) ); if ( !$valid_subject ) { self::redirect( 'permissions', __( 'The recipient is invalid.', 'mydrivecloud' ) ); } $expires = ( isset( $_POST['expires_at'] ) ? sanitize_text_field( wp_unslash( $_POST['expires_at'] ) ) : '' ); if ( $expires ) { $expires_timestamp = strtotime( $expires ); if ( false === $expires_timestamp || $expires_timestamp <= time() ) { self::redirect( 'permissions', __( 'The expiration date must be in the future.', 'mydrivecloud' ) ); } $expires = gmdate( 'Y-m-d H:i:s', $expires_timestamp ); } else { $expires = null; } $data = array( 'item_id' => $item_id, 'subject_type' => $subject_type, 'subject_id' => $subject_id, 'can_preview' => ( !empty( $_POST['can_preview'] ) ? 1 : 0 ), 'can_download' => ( !empty( $_POST['can_download'] ) ? 1 : 0 ), 'expires_at' => $expires, 'created_by' => get_current_user_id(), 'created_at' => $now, ); $wpdb->replace( MyDriveCloud_DB::table( 'access' ), $data, array( '%d', '%s', '%d', '%d', '%d', '%s', '%d', '%s' ) ); MyDriveCloud_DB::audit( 'access_granted', $item_id, array( 'subject_type' => $subject_type, 'subject_id' => $subject_id, 'preview' => $data['can_preview'], 'download' => $data['can_download'], 'expires_at' => $expires, ) ); self::redirect( 'permissions', __( 'The permission was saved.', 'mydrivecloud' ) ); } if ( 'revoke' === $action ) { $grant_id = ( isset( $_POST['grant_id'] ) ? absint( $_POST['grant_id'] ) : 0 ); $grant = $wpdb->get_row( $wpdb->prepare( 'SELECT * FROM %i WHERE id=%d', MyDriveCloud_DB::table( 'access' ), $grant_id ) ); if ( $grant ) { $wpdb->delete( MyDriveCloud_DB::table( 'access' ), array( 'id' => $grant_id, ), array('%d') ); MyDriveCloud_DB::audit( 'access_revoked', $grant->item_id, array( 'grant_id' => $grant_id, ) ); } self::redirect( 'permissions', __( 'The permission was removed.', 'mydrivecloud' ) ); } self::redirect( 'clients', __( 'The action is invalid.', 'mydrivecloud' ) ); } private static function action_fields( $action ) { wp_nonce_field( 'mydrivecloud_access_action' ); echo ''; } private static function users() { $users = get_users( array( 'orderby' => 'display_name', 'order' => 'ASC', 'number' => 500, ) ); usort( $users, static function ( $a, $b ) { $a_admin = 'administrator' === MyDriveCloud_Roles::current_role_slug( $a->ID ) || user_can( $a, 'mydrivecloud_manage_all' ); $b_admin = 'administrator' === MyDriveCloud_Roles::current_role_slug( $b->ID ) || user_can( $b, 'mydrivecloud_manage_all' ); if ( $a_admin !== $b_admin ) { return ( $a_admin ? -1 : 1 ); } $a_pending = 'pending' === self::registration_status( $a->ID ); $b_pending = 'pending' === self::registration_status( $b->ID ); return ( $a_pending === $b_pending ? strcasecmp( $a->display_name, $b->display_name ) : (( $a_pending ? -1 : 1 )) ); } ); return $users; } public static function registration_page() { if ( !isset( $_GET['mydrivecloud_register'] ) ) { return; } $provided = ( isset( $_REQUEST['key'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['key'] ) ) : '' ); if ( !$provided || !hash_equals( self::registration_token(), $provided ) ) { status_header( 404 ); nocache_headers(); exit; } if ( is_user_logged_in() ) { wp_safe_redirect( home_url( '/' ) ); exit; } $error = ''; $success = false; if ( 'POST' === strtoupper( ( isset( $_SERVER['REQUEST_METHOD'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_METHOD'] ) ) : '' ) ) ) { $nonce = ( isset( $_POST['_mydrivecloud_register_nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['_mydrivecloud_register_nonce'] ) ) : '' ); $username = ( isset( $_POST['user_login'] ) ? sanitize_user( wp_unslash( $_POST['user_login'] ), true ) : '' ); $email = ( isset( $_POST['user_email'] ) ? sanitize_email( wp_unslash( $_POST['user_email'] ) ) : '' ); $first_name = ( isset( $_POST['first_name'] ) ? sanitize_text_field( wp_unslash( $_POST['first_name'] ) ) : '' ); $last_name = ( isset( $_POST['last_name'] ) ? sanitize_text_field( wp_unslash( $_POST['last_name'] ) ) : '' ); $password = ( isset( $_POST['user_password'] ) ? (string) wp_unslash( $_POST['user_password'] ) : '' ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Passwords must remain byte-for-byte unchanged. $confirm = ( isset( $_POST['password_confirm'] ) ? (string) wp_unslash( $_POST['password_confirm'] ) : '' ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Compared directly with the password. $honeypot = ( isset( $_POST['company_website'] ) ? trim( (string) wp_unslash( $_POST['company_website'] ) ) : '' ); if ( !wp_verify_nonce( $nonce, 'mydrivecloud_register' ) || $honeypot ) { $error = __( 'The form session expired. Reload the page and try again.', 'mydrivecloud' ); } elseif ( strlen( $username ) < 3 || !validate_username( $username ) ) { $error = __( 'Choose a valid username with at least 3 characters.', 'mydrivecloud' ); } elseif ( !is_email( $email ) ) { $error = __( 'Enter a valid e-mail address.', 'mydrivecloud' ); } elseif ( username_exists( $username ) || email_exists( $email ) ) { $error = __( 'This username or e-mail address is already in use.', 'mydrivecloud' ); } elseif ( strlen( $password ) < 10 ) { $error = __( 'The password must contain at least 10 characters.', 'mydrivecloud' ); } elseif ( !hash_equals( $password, $confirm ) ) { $error = __( 'The passwords do not match.', 'mydrivecloud' ); } else { $user_id = wp_insert_user( array( 'user_login' => $username, 'user_email' => $email, 'user_pass' => $password, 'first_name' => $first_name, 'last_name' => $last_name, 'display_name' => ( trim( $first_name . ' ' . $last_name ) ?: $username ), 'role' => 'subscriber', ) ); if ( is_wp_error( $user_id ) ) { $error = wp_strip_all_tags( $user_id->get_error_message() ); } else { MyDriveCloud_Roles::assign( $user_id, 'client' ); update_user_meta( $user_id, self::REGISTRATION_STATUS, 'pending' ); $new_user = get_userdata( $user_id ); if ( $new_user ) { $new_user->add_cap( 'mydrivecloud_access', false ); } $admin_url = add_query_arg( array( 'page' => self::PAGE, 'tab' => 'clients', ), admin_url( 'admin.php' ) ); /* translators: %s: portal brand name. */ $admin_subject = sprintf( __( 'New client awaiting approval — %s', 'mydrivecloud' ), MyDriveCloud_Settings::brand_name() ); $admin_message = sprintf( /* translators: 1: client display name, 2: client email, 3: admin management URL. */ __( '%1$s (%2$s) registered and is awaiting approval. Manage the request: %3$s', 'mydrivecloud' ), ( $new_user ? $new_user->display_name : $username ), $email, $admin_url ); wp_mail( get_option( 'admin_email' ), $admin_subject, $admin_message ); MyDriveCloud_DB::audit( 'registration_submitted', null, array( 'client_id' => $user_id, ) ); $success = true; } } } $brand = MyDriveCloud_Settings::brand_name(); $logo = MyDriveCloud_Settings::brand_icon_url(); wp_enqueue_style( 'mydrivecloud-registration', MYDRIVECLOUD_URL . 'assets/css/mydrivecloud-admin.css', array(), MYDRIVECLOUD_VERSION ); status_header( ( $success ? 201 : 200 ) ); nocache_headers(); ?> > <?php /* translators: %s: portal brand name. */ echo esc_html( sprintf( __( 'Register — %s', 'mydrivecloud' ), $brand ) ); ?>
✓

get_results( $wpdb->prepare( 'SELECT g.*,COUNT(m.user_id) AS member_count FROM %i g LEFT JOIN %i m ON m.group_id=g.id GROUP BY g.id ORDER BY g.name ASC', MyDriveCloud_DB::table( 'groups' ), MyDriveCloud_DB::table( 'group_members' ) ) ); } private static function item_path( $item ) { $parts = array($item->name); $seen = array( (int) $item->id => true, ); while ( $item->parent_id && !isset( $seen[(int) $item->parent_id] ) ) { $seen[(int) $item->parent_id] = true; $item = MyDriveCloud_Permissions::get_item( $item->parent_id ); if ( !$item ) { break; } array_unshift( $parts, $item->name ); } return implode( ' / ', $parts ); } private static function view_as_items( $type, $id ) { global $wpdb; $rows = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM %i WHERE trashed_at IS NULL ORDER BY type DESC,name ASC LIMIT 1000', MyDriveCloud_DB::table( 'items' ) ) ); return array_values( array_filter( $rows, static function ( $item ) use($type, $id) { return ( 'group' === $type ? MyDriveCloud_Permissions::group_can_view( $item, $id ) : MyDriveCloud_Permissions::can_view( $item, $id ) ); } ) ); } public static function page() { self::require_admin(); global $wpdb; $tab = ( isset( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : 'clients' ); if ( !in_array( $tab, array( 'clients', 'roles', 'groups', 'permissions' ), true ) ) { $tab = 'clients'; } $users = self::users(); $groups = self::groups(); $roles = MyDriveCloud_Roles::all_roles(); $view_type = ( isset( $_GET['view_type'] ) && 'group' === sanitize_key( wp_unslash( $_GET['view_type'] ) ) ? 'group' : 'user' ); $view_id = ( isset( $_GET['view_id'] ) ? absint( $_GET['view_id'] ) : 0 ); $notice = ( isset( $_GET['mydrivecloud_notice'] ) ? sanitize_text_field( rawurldecode( wp_unslash( $_GET['mydrivecloud_notice'] ) ) ) : '' ); ?>

ID ); $role_data = MyDriveCloud_Roles::get( $role_slug ); $has_access = MyDriveCloud_Roles::user_can( 'access_portal', $user->ID ); $vault = false; $registration_status = self::registration_status( $user->ID ); $quota_settings = MyDriveCloud_Settings::user_quota_settings( $user->ID ); ?>
ID, 48 ); ?>
display_name ); ?>user_email ); ?>

ID === get_current_user_id() ) { ?>
ID !== get_current_user_id() && 'administrator' !== $role_slug ) { ?>

get_col( $wpdb->prepare( 'SELECT user_id FROM %i WHERE group_id=%d', MyDriveCloud_DB::table( 'group_members' ), $group->id ) ) ); /* translators: %d: number of users assigned to the group. */ $member_count_label = sprintf( _n( '%d member', '%d members', $group->member_count, 'mydrivecloud' ), $group->member_count ); ?>
name ); ?>

description ); ?>

get_row( $wpdb->prepare( 'SELECT * FROM %i WHERE id=%d', MyDriveCloud_DB::table( 'groups' ), $id ) ); $name = ( $subject ? $subject->name : __( 'Unknown group', 'mydrivecloud' ) ); $vault = false; } else { $subject = get_userdata( $id ); $name = ( $subject ? $subject->display_name : __( 'Unknown user', 'mydrivecloud' ) ); $vault = false; } $items = ( $subject ? self::view_as_items( $type, $id ) : array() ); ?>

owner_id ); ?>
type ? __( 'Folder', 'mydrivecloud' ) : __( 'File', 'mydrivecloud' ) ) ); ?>display_name : '—' ) ); ?>
'ids', ) ); ?>

$label ) { ?>

$role ) { $count = 0; foreach ( $user_ids as $user_id ) { if ( MyDriveCloud_Roles::current_role_slug( $user_id ) === $slug ) { $count++; } } ?>

    $label ) { if ( !empty( $role['permissions'][$key] ) ) { ?>
  • ✓
get_results( $wpdb->prepare( 'SELECT i.*,u.display_name AS owner_name FROM %i i LEFT JOIN %i u ON u.ID=i.owner_id WHERE i.trashed_at IS NULL ORDER BY i.type DESC,i.name ASC LIMIT 1000', MyDriveCloud_DB::table( 'items' ), $wpdb->users ) ); $grants = $wpdb->get_results( $wpdb->prepare( 'SELECT a.*,i.name AS item_name,u.display_name AS user_name,g.name AS group_name FROM %i a LEFT JOIN %i i ON i.id=a.item_id LEFT JOIN %i u ON a.subject_type="user" AND u.ID=a.subject_id LEFT JOIN %i g ON a.subject_type="group" AND g.id=a.subject_id ORDER BY a.created_at DESC', MyDriveCloud_DB::table( 'access' ), MyDriveCloud_DB::table( 'items' ), $wpdb->users, MyDriveCloud_DB::table( 'groups' ) ) ); ?>

item_name ?: '—' ) ); ?>subject_type ? '👥 ' . $grant->group_name : '👤 ' . $grant->user_name ) ); ?>can_preview ? 'Preview ' : '' ); echo ( $grant->can_download ? 'Download' : '' ); echo ( $grant->expires_at ? '
' . esc_html( $grant->expires_at ) . '' : '' ); ?>