function isSubscribed($other)
{
- assert(!is_null($other));
- // XXX: cache results of this query
- $sub = Subscription::pkeyGet(array('subscriber' => $this->id,
- 'subscribed' => $other->id));
- return (is_null($sub)) ? false : true;
+ return Subscription::exists($this->getProfile(), $other);
}
// 'update' won't write key columns, so we have to do it ourselves.
function hasBlocked($other)
{
-
- $block = Profile_block::get($this->id, $other->id);
-
- if (is_null($block)) {
- $result = false;
- } else {
- $result = true;
- $block->free();
- }
-
- return $result;
+ $profile = $this->getProfile();
+ return $profile->hasBlocked($other);
}
/**
$profile = new Profile();
- $profile->query('BEGIN');
-
if(!empty($email))
{
$email = common_canonical_email($email);
$profile->nickname = $nickname;
if(! User::allowed_nickname($nickname)){
common_log(LOG_WARNING, sprintf("Attempted to register a nickname that is not allowed: %s", $profile->nickname),
- __FILE__);
+ __FILE__);
}
$profile->profileurl = common_profile_url($nickname);
$profile->created = common_sql_now();
- $id = $profile->insert();
-
- if (empty($id)) {
- common_log_db_error($profile, 'INSERT', __FILE__);
- return false;
- }
-
$user = new User();
- $user->id = $id;
$user->nickname = $nickname;
- if (!empty($password)) { // may not have a password for OpenID users
- $user->password = common_munge_password($password, $id);
- }
-
// Users who respond to invite email have proven their ownership of that address
if (!empty($code)) {
$user->inboxed = 1;
$user->created = common_sql_now();
- $user->uri = common_user_uri($user);
- $result = $user->insert();
+ if (Event::handle('StartUserRegister', array(&$user, &$profile))) {
- if (!$result) {
- common_log_db_error($user, 'INSERT', __FILE__);
- return false;
- }
+ $profile->query('BEGIN');
- // Everyone is subscribed to themself
+ $id = $profile->insert();
- $subscription = new Subscription();
- $subscription->subscriber = $user->id;
- $subscription->subscribed = $user->id;
- $subscription->created = $user->created;
+ if (empty($id)) {
+ common_log_db_error($profile, 'INSERT', __FILE__);
+ return false;
+ }
- $result = $subscription->insert();
+ $user->id = $id;
+ $user->uri = common_user_uri($user);
+ if (!empty($password)) { // may not have a password for OpenID users
+ $user->password = common_munge_password($password, $id);
+ }
- if (!$result) {
- common_log_db_error($subscription, 'INSERT', __FILE__);
- return false;
- }
+ $result = $user->insert();
- if (!empty($email) && !$user->email) {
+ if (!$result) {
+ common_log_db_error($user, 'INSERT', __FILE__);
+ return false;
+ }
- $confirm = new Confirm_address();
- $confirm->code = common_confirmation_code(128);
- $confirm->user_id = $user->id;
- $confirm->address = $email;
- $confirm->address_type = 'email';
+ // Everyone gets an inbox
+
+ $inbox = new Inbox();
+
+ $inbox->user_id = $user->id;
+ $inbox->notice_ids = '';
+
+ $result = $inbox->insert();
- $result = $confirm->insert();
if (!$result) {
- common_log_db_error($confirm, 'INSERT', __FILE__);
+ common_log_db_error($inbox, 'INSERT', __FILE__);
return false;
}
- }
- if (!empty($code) && $user->email) {
- $user->emailChanged();
- }
+ // Everyone is subscribed to themself
- // Default system subscription
+ $subscription = new Subscription();
+ $subscription->subscriber = $user->id;
+ $subscription->subscribed = $user->id;
+ $subscription->created = $user->created;
- $defnick = common_config('newuser', 'default');
+ $result = $subscription->insert();
- if (!empty($defnick)) {
- $defuser = User::staticGet('nickname', $defnick);
- if (empty($defuser)) {
- common_log(LOG_WARNING, sprintf("Default user %s does not exist.", $defnick),
- __FILE__);
- } else {
- $defsub = new Subscription();
- $defsub->subscriber = $user->id;
- $defsub->subscribed = $defuser->id;
- $defsub->created = $user->created;
+ if (!$result) {
+ common_log_db_error($subscription, 'INSERT', __FILE__);
+ return false;
+ }
+
+ if (!empty($email) && !$user->email) {
+
+ $confirm = new Confirm_address();
+ $confirm->code = common_confirmation_code(128);
+ $confirm->user_id = $user->id;
+ $confirm->address = $email;
+ $confirm->address_type = 'email';
- $result = $defsub->insert();
+ $result = $confirm->insert();
if (!$result) {
- common_log_db_error($defsub, 'INSERT', __FILE__);
+ common_log_db_error($confirm, 'INSERT', __FILE__);
return false;
}
}
- }
- $profile->query('COMMIT');
+ if (!empty($code) && $user->email) {
+ $user->emailChanged();
+ }
- if (!empty($email) && !$user->email) {
- mail_confirm_address($user, $confirm->code, $profile->nickname, $email);
- }
+ // Default system subscription
+
+ $defnick = common_config('newuser', 'default');
- // Welcome message
+ if (!empty($defnick)) {
+ $defuser = User::staticGet('nickname', $defnick);
+ if (empty($defuser)) {
+ common_log(LOG_WARNING, sprintf("Default user %s does not exist.", $defnick),
+ __FILE__);
+ } else {
+ $defsub = new Subscription();
+ $defsub->subscriber = $user->id;
+ $defsub->subscribed = $defuser->id;
+ $defsub->created = $user->created;
- $welcome = common_config('newuser', 'welcome');
+ $result = $defsub->insert();
- if (!empty($welcome)) {
- $welcomeuser = User::staticGet('nickname', $welcome);
- if (empty($welcomeuser)) {
- common_log(LOG_WARNING, sprintf("Welcome user %s does not exist.", $defnick),
- __FILE__);
- } else {
- $notice = Notice::saveNew($welcomeuser->id,
- sprintf(_('Welcome to %1$s, @%2$s!'),
- common_config('site', 'name'),
- $user->nickname),
- 'system');
- common_broadcast_notice($notice);
+ if (!$result) {
+ common_log_db_error($defsub, 'INSERT', __FILE__);
+ return false;
+ }
+ }
+ }
+
+ $profile->query('COMMIT');
+
+ if (!empty($email) && !$user->email) {
+ mail_confirm_address($user, $confirm->code, $profile->nickname, $email);
+ }
+
+ // Welcome message
+
+ $welcome = common_config('newuser', 'welcome');
+
+ if (!empty($welcome)) {
+ $welcomeuser = User::staticGet('nickname', $welcome);
+ if (empty($welcomeuser)) {
+ common_log(LOG_WARNING, sprintf("Welcome user %s does not exist.", $defnick),
+ __FILE__);
+ } else {
+ $notice = Notice::saveNew($welcomeuser->id,
+ sprintf(_('Welcome to %1$s, @%2$s!'),
+ common_config('site', 'name'),
+ $user->nickname),
+ 'system');
+
+ }
}
+
+ Event::handle('EndUserRegister', array(&$profile, &$user));
}
return $user;
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);
-
- return Notice::getStreamByIds($ids);
+ return Inbox::streamNotices($this->id, $offset, $limit, $since_id, $before_id, $since, false);
}
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);
-
- return Notice::getStreamByIds($ids);
+ return Inbox::streamNotices($this->id, $offset, $limit, $since_id, $before_id, $since, true);
}
function friendsTimeline($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
{
- $ids = Notice::stream(array($this, '_friendsTimelineDirect'),
- array(false),
- 'user:friends_timeline:'.$this->id,
- $offset, $limit, $since_id, $before_id, $since);
-
- return Notice::getStreamByIds($ids);
+ return Inbox::streamNotices($this->id, $offset, $limit, $since_id, $before_id, $since, false);
}
function ownFriendsTimeline($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
{
- $ids = Notice::stream(array($this, '_friendsTimelineDirect'),
- array(true),
- 'user:friends_timeline_own:'.$this->id,
- $offset, $limit, $since_id, $before_id, $since);
-
- return Notice::getStreamByIds($ids);
- }
-
- function _friendsTimelineDirect($own, $offset, $limit, $since_id, $max_id, $since)
- {
- $qry =
- 'SELECT notice.id AS id ' .
- 'FROM notice JOIN notice_inbox ON notice.id = notice_inbox.notice_id ' .
- 'WHERE notice_inbox.user_id = ' . $this->id . ' ' .
- 'AND notice.repeat_of IS NULL ';
-
- if (!$own) {
- // XXX: autoload notice inbox for constant
- $inbox = new Notice_inbox();
-
- $qry .= 'AND notice_inbox.source != ' . NOTICE_INBOX_SOURCE_GATEWAY . ' ';
- }
-
- if ($since_id != 0) {
- $qry .= 'AND notice.id > ' . $since_id . ' ';
- }
-
- if ($max_id != 0) {
- $qry .= 'AND notice.id <= ' . $max_id . ' ';
- }
-
- if (!is_null($since)) {
- $qry .= 'AND notice.modified > \'' . date('Y-m-d H:i:s', $since) . '\' ';
- }
-
- // NOTE: we sort by fave time, not by notice time!
-
- $qry .= 'ORDER BY notice.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;
+ return Inbox::streamNotices($this->id, $offset, $limit, $since_id, $before_id, $since, true);
}
function blowFavesCache()
// Cancel their subscription, if it exists
- subs_unsubscribe_to($other->getUser(),$this->getProfile());
+ $otherUser = User::staticGet('id', $other->id);
+
+ if (!empty($otherUser)) {
+ subs_unsubscribe_to($otherUser, $this->getProfile());
+ }
$block->query('COMMIT');
'Remember_me',
'Foreign_link',
'Invitation',
- 'Notice_inbox',
);
Event::handle('UserDeleteRelated', array($this, &$related));
function repeatedToMe($offset=0, $limit=20, $since_id=null, $max_id=null)
{
- $ids = Notice::stream(array($this, '_repeatedToMeDirect'),
- array(),
- 'user:repeated_to_me:'.$this->id,
- $offset, $limit, $since_id, $max_id, null);
-
- return Notice::getStreamByIds($ids);
+ throw new Exception("Not implemented since inbox change.");
}
- function _repeatedToMeDirect($offset, $limit, $since_id, $max_id, $since)
+ function shareLocation()
{
- $qry =
- 'SELECT notice.id AS id ' .
- 'FROM notice JOIN notice_inbox ON notice.id = notice_inbox.notice_id ' .
- 'WHERE notice_inbox.user_id = ' . $this->id . ' ' .
- 'AND notice.repeat_of IS NOT NULL ';
+ $cfg = common_config('location', 'share');
- if ($since_id != 0) {
- $qry .= 'AND notice.id > ' . $since_id . ' ';
- }
+ if ($cfg == 'always') {
+ return true;
+ } else if ($cfg == 'never') {
+ return false;
+ } else { // user
+ $share = true;
- if ($max_id != 0) {
- $qry .= 'AND notice.id <= ' . $max_id . ' ';
- }
+ $prefs = User_location_prefs::staticGet('user_id', $this->id);
- if (!is_null($since)) {
- $qry .= 'AND notice.modified > \'' . date('Y-m-d H:i:s', $since) . '\' ';
+ if (empty($prefs)) {
+ $share = common_config('location', 'sharedefault');
+ } else {
+ $share = $prefs->share_location;
+ $prefs->free();
+ }
+
+ return $share;
}
+ }
- // NOTE: we sort by fave time, not by notice time!
+ static function siteOwner()
+ {
+ $owner = self::cacheGet('user:site_owner');
- $qry .= 'ORDER BY notice.id DESC ';
+ if ($owner === false) { // cache miss
- if (!is_null($offset)) {
- $qry .= "LIMIT $limit OFFSET $offset";
- }
+ $pr = new Profile_role();
- $ids = array();
+ $pr->role = Profile_role::OWNER;
- $notice = new Notice();
+ $pr->orderBy('created');
- $notice->query($qry);
+ $pr->limit(1);
- while ($notice->fetch()) {
- $ids[] = $notice->id;
- }
+ if ($pr->find(true)) {
+ $owner = User::staticGet('id', $pr->profile_id);
+ } else {
+ $owner = null;
+ }
- $notice->free();
- $notice = NULL;
+ self::cacheSet('user:site_owner', $owner);
+ }
- return $ids;
+ return $owner;
}
}