User.php

Summary
User.php
UserUser table definition
UserSuperclass containing the representation of a user in the database as well as the related interfaces.
schemaDefReturns an array describing the underlying schema for the user data in the database.
__sleepMagic function called at serialize() time.
getProfileReturns the profile associated with this user.
sameAs
getUriReturns the URI of this user.
getNicknameReturns the nickname of this user from their profile.
getByNicknameReturns a user account by a given nickname.
isSubscribedReturns true/false whether this user is subscribed to the profile $other.
hasPendingSubscriptionReturns true/false whether this user has a pending subscription to the profile $other.
getCurrentNoticeGet the most recent notice posted by this user, if any.
getCarrierReturns the SMS carrier gateway used by a user, if one is being used.
hasBlockedReturns true/false whether the user has profile $other blocked.
registerRegister a new user account and profile and set up default subscriptions.
emailChangedThings we do when the email changes
mutuallySubscribedReturns true/false whether this user is subscribed to profile $other and that profile is in turn subscribed to them.
mutuallySubscribedUsersReturns an array of users that mutually subscribe to this user.
getRepliesReturns an array of replies to this user.
getTaggedNoticesReturns an array of notices tagged by this user.
getRepliesReturns an array of notices from this user.
blockAdd a new block record for this user, indicating they blocked target profile $other.
unblockRemove the block record this has for target profile $other.
repeatsOfMeReturns an array of notices of this user which have been repeated by others, that we are aware of.
repeatedToMeReturns an array of notices repeated to this user.
siteOwnerReturns the User object of the account labelled as the site owner.
singleUserPull the primary site account to use in single-user mode.
singleUserNicknameThis is kind of a hack for using external setup code that’s trying to build single-user sites.
shortenLinksFind and shorten links in the given text using this user’s URL shortening settings.
getConnectedAppsGet a list of OAuth client applications that have access to this user’s account.
recoverPasswordSends a password recovery email for this user if they have an email on record.
streamModeOnlyReturns whether to only display notice streams in the classic UI.
streamNicknamesReturns whether to use nicknames as opposed to the full names in classic UI streams.
registrationActivityCreates and returns an ActivityObject representing a new user registration.
isPrivateStreamReturns whether the user has their profile to private.
hasPasswordReturns whether the user has a password set (false for remote users for example.)
setPasswordSet the password associated with this user to the given $password.
delPrefDelete the given extended user preference of $namespace, $topic from the profile of this user.
getPrefRetrieves the given extended user preference of $namespace, $topic from the profile of this user.
getConfigPrefgetPref, but we will fallback to the site configuration setting of the same $namespace and $topic if the user hasn’t specified a preference.
setPrefSet the extended preference $namespace, $topic to contain the $data specified in this user’s profile.

User

User table definition

postActiv

the micro-blogging software

Copyright

Copyright © 2016-2017, Maiyannah Bishop

Derived from code copyright various sources

  • GNU Social © 2013-2016, Free Software Foundation, Inc
  • StatusNet © 2008-2012, StatusNet, Inc

License

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program.  If not, see http://www.gnu.org/licenses/.

https://www.gnu.org/licenses/agpl.html

About

User table definition

PHP version

Tested with PHP 7

File Authors

Web

User

Superclass containing the representation of a user in the database as well as the related interfaces.

It should be noted this is the USER object, not the PROFILE object for that user, although it does contain many interfaces to the profile object to the associated profile for ease of use.

Properties

  • __table = ‘user’ - table name
  • id - int(4) primary_key not_null
  • nickname - varchar(64) unique_key
  • password - varchar(191) not 255 because utf8mb4 takes more space
  • email - varchar(191) unique_key not 255 because utf8mb4 takes more space
  • incomingemail - varchar(191) unique_key not 255 because utf8mb4 takes more space
  • emailnotifysub - tinyint(1) default_1
  • emailnotifyfav - tinyint(1) default_1
  • emailnotifynudge - tinyint(1) default_1
  • emailnotifymsg - tinyint(1) default_1
  • emailnotifyattn - tinyint(1) default_1
  • language - varchar(50)
  • timezone - varchar(50)
  • emailpost - tinyint(1) default_1
  • sms - varchar(64) unique_key
  • carrier - int(4)
  • smsnotify - tinyint(1)
  • smsreplies - tinyint(1)
  • smsemail - varchar(191) not 255 because utf8mb4 takes more space
  • uri - varchar(191) unique_key not 255 because utf8mb4 takes more space
  • autosubscribe - tinyint(1)
  • subscribe_policy - tinyint(1)
  • urlshorteningservice - varchar(50) default_ur1.ca
  • private_stream - tinyint(1) default_0
  • created - datetime() not_null
  • modified - timestamp() not_null default_CURRENT_TIMESTAMP
Summary
schemaDefReturns an array describing the underlying schema for the user data in the database.
__sleepMagic function called at serialize() time.
getProfileReturns the profile associated with this user.
sameAs
getUriReturns the URI of this user.
getNicknameReturns the nickname of this user from their profile.
getByNicknameReturns a user account by a given nickname.
isSubscribedReturns true/false whether this user is subscribed to the profile $other.
hasPendingSubscriptionReturns true/false whether this user has a pending subscription to the profile $other.
getCurrentNoticeGet the most recent notice posted by this user, if any.
getCarrierReturns the SMS carrier gateway used by a user, if one is being used.
hasBlockedReturns true/false whether the user has profile $other blocked.
registerRegister a new user account and profile and set up default subscriptions.
emailChangedThings we do when the email changes
mutuallySubscribedReturns true/false whether this user is subscribed to profile $other and that profile is in turn subscribed to them.
mutuallySubscribedUsersReturns an array of users that mutually subscribe to this user.
getRepliesReturns an array of replies to this user.
getTaggedNoticesReturns an array of notices tagged by this user.
getRepliesReturns an array of notices from this user.
blockAdd a new block record for this user, indicating they blocked target profile $other.
unblockRemove the block record this has for target profile $other.
repeatsOfMeReturns an array of notices of this user which have been repeated by others, that we are aware of.
repeatedToMeReturns an array of notices repeated to this user.
siteOwnerReturns the User object of the account labelled as the site owner.
singleUserPull the primary site account to use in single-user mode.
singleUserNicknameThis is kind of a hack for using external setup code that’s trying to build single-user sites.
shortenLinksFind and shorten links in the given text using this user’s URL shortening settings.
getConnectedAppsGet a list of OAuth client applications that have access to this user’s account.
recoverPasswordSends a password recovery email for this user if they have an email on record.
streamModeOnlyReturns whether to only display notice streams in the classic UI.
streamNicknamesReturns whether to use nicknames as opposed to the full names in classic UI streams.
registrationActivityCreates and returns an ActivityObject representing a new user registration.
isPrivateStreamReturns whether the user has their profile to private.
hasPasswordReturns whether the user has a password set (false for remote users for example.)
setPasswordSet the password associated with this user to the given $password.
delPrefDelete the given extended user preference of $namespace, $topic from the profile of this user.
getPrefRetrieves the given extended user preference of $namespace, $topic from the profile of this user.
getConfigPrefgetPref, but we will fallback to the site configuration setting of the same $namespace and $topic if the user hasn’t specified a preference.
setPrefSet the extended preference $namespace, $topic to contain the $data specified in this user’s profile.

schemaDef

public static function schemaDef()

Returns an array describing the underlying schema for the user data in the database.

__sleep

function __sleep()

Magic function called at serialize() time.

We use this to drop a couple process-specific references from DB_DataObject which can cause trouble in future processes.

Returns

  • array of variable names to include in serialization.

getProfile

public function getProfile()

Returns the profile associated with this user.

Error States

  • throws UserNoProfileException if user has no profile

sameAs

public function sameAs(Profile $other)
Duplicationcheck - returns if the profile for this user is identical to a given $other profile.

getUri

public function getUri()

Returns the URI of this user.

getNickname

public function getNickname()

Returns the nickname of this user from their profile.

getByNickname

static function getByNickname($nickname)

Returns a user account by a given nickname.

Error States

  • throws NoSuchUserException if the user is not found.

isSubscribed

function isSubscribed(Profile $other)

Returns true/false whether this user is subscribed to the profile $other.

hasPendingSubscription

function hasPendingSubscription(Profile $other)

Returns true/false whether this user has a pending subscription to the profile $other.

getCurrentNotice

function getCurrentNotice()

Get the most recent notice posted by this user, if any.

@return mixed Notice or null

getCarrier

function getCarrier()

Returns the SMS carrier gateway used by a user, if one is being used.

hasBlocked

function hasBlocked(Profile $other)

Returns true/false whether the user has profile $other blocked.

register

static function register(array $fields,  
 $accept_email_fail = false)

Register a new user account and profile and set up default subscriptions.  If a new-user welcome message is configured, this will be sent.

Parameters

  • array $fields - associative array of optional properties
  • string ‘bio’
  • string ‘xmpp’
  • string ‘toxid’
  • string ‘matrix’
  • string ‘donateurl’
  • string ‘gpgpubkey’
  • string ‘email’
  • bool ‘email_confirmed’ pass true to mark email as pre-confirmed
  • string ‘fullname’
  • string ‘homepage’
  • string ‘location’ informal string description of geolocation
  • float ‘lat’ decimal latitude for geolocation
  • float ‘lon’ decimal longitude for geolocation
  • int ‘location_id’ geoname identifier
  • int ‘location_ns’ geoname namespace to interpret location_id
  • string ‘nickname’ REQUIRED
  • string ‘password’ (may be missing for eg OpenID registrations)
  • string ‘code’ invite code
  • ?string ‘uri’ permalink to notice; defaults to local notice URL
  • boolean accept_email_fail - what it says on the tin

Returns

  • User object representing newly-created user.

Error States

  • throws Exception on failure

emailChanged

function emailChanged()

Things we do when the email changes

mutuallySubscribed

function mutuallySubscribed(Profile $other)

Returns true/false whether this user is subscribed to profile $other and that profile is in turn subscribed to them.

mutuallySubscribedUsers

function mutuallySubscribedUsers()

Returns an array of users that mutually subscribe to this user.

FIXME

  • 3-way join; probably should get cached

getReplies

function getReplies($offset = 0,
$limit = NOTICES_PER_PAGE,
$since_id = 0,
$before_id = 0)

Returns an array of replies to this user.

getTaggedNotices

function getTaggedNotices($tag,  
$offset = 0,
$limit = NOTICES_PER_PAGE,
$since_id = 0,
$before_id = 0)

Returns an array of notices tagged by this user.

getReplies

Returns an array of notices from this user.

block

function block(Profile $other)

Add a new block record for this user, indicating they blocked target profile $other.  This will also remove subscriptions where they exist, locally.  (But not remotely.)

unblock

function unblock(Profile $other)

Remove the block record this has for target profile $other.

repeatsOfMe

Returns an array of notices of this user which have been repeated by others, that we are aware of.

repeatedToMe

Returns an array of notices repeated to this user.

siteOwner

public static function siteOwner()

Returns the User object of the account labelled as the site owner.  Note that this will return the FIRST account found with such a role if multiple are assigned.

singleUser

public static function singleUser()

Pull the primary site account to use in single-user mode.  If a valid user nickname is listed in ‘singleuser’:’nickname’ in the config, this will be used; otherwise the site owner account is taken by default.

Returns

  • object User

Error States

  • throws ServerException if no valid single user account is present
  • throws ServerException if called when not in single-user mode

singleUserNickname

static function singleUserNickname()

This is kind of a hack for using external setup code that’s trying to build single-user sites.

Will still return a username if the config singleuser/nickname is set even if the account doesn’t exist, which normally indicates that the site is horribly misconfigured.

At the moment, we need to let it through so that router setup can complete, otherwise we won’t be able to create the account.

This will be easier when we can more easily create the account and then switch the site to 1user mode without jumping through hoops.

Returns

  • string

Error States

  • throws ServerException if no valid single user account is present
  • throws ServerException if called when not in single-user mode

shortenLinks

public function shortenLinks($text,  
$always = false)

Find and shorten links in the given text using this user’s URL shortening settings.

By default, links will be left untouched if the text is shorter than the configured maximum notice length.  Pass true for the $always parameter to force all links to be shortened regardless.

Side effects: may save file and file_redirection records for referenced URLs.

Parameters

  • string $text
  • boolean $always

Returns

  • string

getConnectedApps

function getConnectedApps($offset =  0,
$limit =  null)

Get a list of OAuth client applications that have access to this user’s account.

recoverPassword

static function recoverPassword($nore)

Sends a password recovery email for this user if they have an email on record.  If faking email recovery is enabled, it will look like one has been sent regardless of this to the end user.  Warning: In the event of an unconfirmed email address, it may actually be legit to have multiple folks who have claimed, but not yet confirmed, the same address.  We’ll only send to the first one that comes up.

FIXME: Email body is constructed in hard code here, we should put it in a template file at the very least that is then transcluded.

streamModeOnly

function streamModeOnly()

Returns whether to only display notice streams in the classic UI.  Legacy feature - kept for those who want to use “oldschool” config options.

streamNicknames

function streamNicknames()

Returns whether to use nicknames as opposed to the full names in classic UI streams.  Legacy feature - kept for those who want to use “oldschool” config options.

registrationActivity

function registrationActivity()

Creates and returns an ActivityObject representing a new user registration.

isPrivateStream

public function isPrivateStream()

Returns whether the user has their profile to private.

hasPassword

public function hasPassword()

Returns whether the user has a password set (false for remote users for example.)

setPassword

public function setPassword($password)

Set the password associated with this user to the given $password.

delPref

public function delPref($namespace,
$topic)

Delete the given extended user preference of $namespace, $topic from the profile of this user.

getPref

public function getPref($namespace,  
$topic,  
$default = null)

Retrieves the given extended user preference of $namespace, $topic from the profile of this user.

getConfigPref

public function getConfigPref($namespace,
$topic)

getPref, but we will fallback to the site configuration setting of the same $namespace and $topic if the user hasn’t specified a preference.

setPref

public function setPref($namespace,
$topic,
$data)

Set the extended preference $namespace, $topic to contain the $data specified in this user’s profile.

public static function schemaDef()
Returns an array describing the underlying schema for the user data in the database.
function __sleep()
Magic function called at serialize() time.
public function getProfile()
Returns the profile associated with this user.
public function sameAs(Profile $other)
public function getUri()
Returns the URI of this user.
public function getNickname()
Returns the nickname of this user from their profile.
static function getByNickname($nickname)
Returns a user account by a given nickname.
function isSubscribed(Profile $other)
Returns true/false whether this user is subscribed to the profile $other.
function hasPendingSubscription(Profile $other)
Returns true/false whether this user has a pending subscription to the profile $other.
function getCurrentNotice()
Get the most recent notice posted by this user, if any.
function getCarrier()
Returns the SMS carrier gateway used by a user, if one is being used.
function hasBlocked(Profile $other)
Returns true/false whether the user has profile $other blocked.
static function register(array $fields,  
 $accept_email_fail = false)
Register a new user account and profile and set up default subscriptions.
function emailChanged()
Things we do when the email changes
function mutuallySubscribed(Profile $other)
Returns true/false whether this user is subscribed to profile $other and that profile is in turn subscribed to them.
function mutuallySubscribedUsers()
Returns an array of users that mutually subscribe to this user.
function getReplies($offset = 0,
$limit = NOTICES_PER_PAGE,
$since_id = 0,
$before_id = 0)
Returns an array of replies to this user.
function getTaggedNotices($tag,  
$offset = 0,
$limit = NOTICES_PER_PAGE,
$since_id = 0,
$before_id = 0)
Returns an array of notices tagged by this user.
function block(Profile $other)
Add a new block record for this user, indicating they blocked target profile $other.
function unblock(Profile $other)
Remove the block record this has for target profile $other.
public static function siteOwner()
Returns the User object of the account labelled as the site owner.
public static function singleUser()
Pull the primary site account to use in single-user mode.
static function singleUserNickname()
This is kind of a hack for using external setup code that’s trying to build single-user sites.
public function shortenLinks($text,  
$always = false)
Find and shorten links in the given text using this user’s URL shortening settings.
function getConnectedApps($offset =  0,
$limit =  null)
Get a list of OAuth client applications that have access to this user’s account.
static function recoverPassword($nore)
Sends a password recovery email for this user if they have an email on record.
function streamModeOnly()
Returns whether to only display notice streams in the classic UI.
function streamNicknames()
Returns whether to use nicknames as opposed to the full names in classic UI streams.
function registrationActivity()
Creates and returns an ActivityObject representing a new user registration.
public function isPrivateStream()
Returns whether the user has their profile to private.
public function hasPassword()
Returns whether the user has a password set (false for remote users for example.)
public function setPassword($password)
Set the password associated with this user to the given $password.
public function delPref($namespace,
$topic)
Delete the given extended user preference of $namespace, $topic from the profile of this user.
public function getPref($namespace,  
$topic,  
$default = null)
Retrieves the given extended user preference of $namespace, $topic from the profile of this user.
public function getConfigPref($namespace,
$topic)
getPref, but we will fallback to the site configuration setting of the same $namespace and $topic if the user hasn’t specified a preference.
public function setPref($namespace,
$topic,
$data)
Set the extended preference $namespace, $topic to contain the $data specified in this user’s profile.