X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=classes%2FUser.php;h=6ea975202d2c732427a930a54451e647263605f3;hb=fbd52111e1cc68a1a2710701ae0a146bcce5580e;hp=4838fe1c7df632454b010ac5982751083ce6e828;hpb=aef4cc0a59276938f0f0aec4d67374f578f2117a;p=quix0rs-gnu-social.git diff --git a/classes/User.php b/classes/User.php index 4838fe1c7d..6ea975202d 100644 --- a/classes/User.php +++ b/classes/User.php @@ -180,6 +180,27 @@ class User extends Memcached_DataObject return $result; } + /** + * Register a new user account and profile and set up default subscriptions. + * If a new-user welcome message is configured, this will be sent. + * + * @param array $fields associative array of optional properties + * string 'bio' + * 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 + * @return mixed User object or false on failure + */ static function register($fields) { // MAGICALLY put fields into current scope @@ -270,6 +291,20 @@ class User extends Memcached_DataObject return false; } + // Everyone gets an inbox + + $inbox = new Inbox(); + + $inbox->user_id = $user->id; + $inbox->notice_ids = ''; + + $result = $inbox->insert(); + + if (!$result) { + common_log_db_error($inbox, 'INSERT', __FILE__); + return false; + } + // Everyone is subscribed to themself $subscription = new Subscription(); @@ -329,7 +364,7 @@ class User extends Memcached_DataObject $profile->query('COMMIT'); - if ($email && !$user->email) { + if (!empty($email) && !$user->email) { mail_confirm_address($user, $confirm->code, $profile->nickname, $email); } @@ -348,7 +383,7 @@ class User extends Memcached_DataObject common_config('site', 'name'), $user->nickname), 'system'); - common_broadcast_notice($notice); + } } @@ -461,14 +496,26 @@ class User extends Memcached_DataObject function noticesWithFriends($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null) { - $ids = Notice_inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, false); - + $ids = Inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, false); return Notice::getStreamByIds($ids); } function noticeInbox($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null) { - $ids = Notice_inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, true); + $ids = Inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, true); + return Notice::getStreamByIds($ids); + } + + function friendsTimeline($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null) + { + $ids = Inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, false); + + return Notice::getStreamByIds($ids); + } + + function ownFriendsTimeline($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null) + { + $ids = Inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, true); return Notice::getStreamByIds($ids); } @@ -533,20 +580,10 @@ class User extends Memcached_DataObject // Cancel their subscription, if it exists - $result = subs_unsubscribe_to($this, $other); + $otherUser = User::staticGet('id', $other->id); - if ($result !== true) { - common_log(LOG_WARNING, - sprintf( - "Error trying to unsubscribe profile ID %d (%s) from user ID %d (%s): %s", - $other->id, - $other->nickname, - $this->id, - $this->nickname, - $result - ) - ); - return false; + if (!empty($otherUser)) { + subs_unsubscribe_to($otherUser, $this->getProfile()); } $block->query('COMMIT'); @@ -695,7 +732,6 @@ class User extends Memcached_DataObject 'Remember_me', 'Foreign_link', 'Invitation', - 'Notice_inbox', ); Event::handle('UserDeleteRelated', array($this, &$related)); @@ -755,4 +791,138 @@ class User extends Memcached_DataObject $profile = $this->getProfile(); return $profile->isSilenced(); } + + function repeatedByMe($offset=0, $limit=20, $since_id=null, $max_id=null) + { + $ids = Notice::stream(array($this, '_repeatedByMeDirect'), + array(), + 'user:repeated_by_me:'.$this->id, + $offset, $limit, $since_id, $max_id, null); + + return Notice::getStreamByIds($ids); + } + + function _repeatedByMeDirect($offset, $limit, $since_id, $max_id, $since) + { + $notice = new Notice(); + + $notice->selectAdd(); // clears it + $notice->selectAdd('id'); + + $notice->profile_id = $this->id; + $notice->whereAdd('repeat_of IS NOT NULL'); + + $notice->orderBy('id DESC'); + + if (!is_null($offset)) { + $notice->limit($offset, $limit); + } + + if ($since_id != 0) { + $notice->whereAdd('id > ' . $since_id); + } + + if ($max_id != 0) { + $notice->whereAdd('id <= ' . $max_id); + } + + if (!is_null($since)) { + $notice->whereAdd('created > \'' . date('Y-m-d H:i:s', $since) . '\''); + } + + $ids = array(); + + if ($notice->find()) { + while ($notice->fetch()) { + $ids[] = $notice->id; + } + } + + $notice->free(); + $notice = NULL; + + return $ids; + } + + function repeatsOfMe($offset=0, $limit=20, $since_id=null, $max_id=null) + { + $ids = Notice::stream(array($this, '_repeatsOfMeDirect'), + array(), + 'user:repeats_of_me:'.$this->id, + $offset, $limit, $since_id, $max_id, null); + + return Notice::getStreamByIds($ids); + } + + function _repeatsOfMeDirect($offset, $limit, $since_id, $max_id, $since) + { + $qry = + 'SELECT DISTINCT original.id AS id ' . + 'FROM notice original JOIN notice rept ON original.id = rept.repeat_of ' . + 'WHERE original.profile_id = ' . $this->id . ' '; + + if ($since_id != 0) { + $qry .= 'AND original.id > ' . $since_id . ' '; + } + + if ($max_id != 0) { + $qry .= 'AND original.id <= ' . $max_id . ' '; + } + + if (!is_null($since)) { + $qry .= 'AND original.modified > \'' . date('Y-m-d H:i:s', $since) . '\' '; + } + + // NOTE: we sort by fave time, not by notice time! + + $qry .= 'ORDER BY original.id DESC '; + + if (!is_null($offset)) { + $qry .= "LIMIT $limit OFFSET $offset"; + } + + $ids = array(); + + $notice = new Notice(); + + $notice->query($qry); + + while ($notice->fetch()) { + $ids[] = $notice->id; + } + + $notice->free(); + $notice = NULL; + + return $ids; + } + + function repeatedToMe($offset=0, $limit=20, $since_id=null, $max_id=null) + { + throw new Exception("Not implemented since inbox change."); + } + + function shareLocation() + { + $cfg = common_config('location', 'share'); + + if ($cfg == 'always') { + return true; + } else if ($cfg == 'never') { + return false; + } else { // user + $share = true; + + $prefs = User_location_prefs::staticGet('user_id', $this->id); + + if (empty($prefs)) { + $share = common_config('location', 'sharedefault'); + } else { + $share = $prefs->share_location; + $prefs->free(); + } + + return $share; + } + } }