X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=classes%2FUser.php;h=40cf18df67406da2e16eb22089a21e328383e1c8;hb=8b9e559167e27c490648cc55c4f617c2e9122a18;hp=92ff8776b0d669cc3ceb24deef9b7970722c37b9;hpb=2d456a15e5652a0c0e2c0f9f50221eed2d16e109;p=quix0rs-gnu-social.git diff --git a/classes/User.php b/classes/User.php index 92ff8776b0..40cf18df67 100644 --- a/classes/User.php +++ b/classes/User.php @@ -40,6 +40,7 @@ class User extends Memcached_DataObject public $emailnotifyfav; // tinyint(1) default_1 public $emailnotifynudge; // tinyint(1) default_1 public $emailnotifymsg; // tinyint(1) default_1 + public $emailnotifyattn; // tinyint(1) default_1 public $emailmicroid; // tinyint(1) default_1 public $language; // varchar(50) public $timezone; // varchar(50) @@ -62,8 +63,10 @@ class User extends Memcached_DataObject public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP /* Static get */ - function staticGet($k,$v=null) - { return Memcached_DataObject::staticGet('User',$k,$v); } + function staticGet($k,$v=NULL) + { + return Memcached_DataObject::staticGet('User',$k,$v); + } /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE @@ -118,7 +121,7 @@ class User extends Memcached_DataObject static $blacklist = array('rss', 'xrds', 'doc', 'main', 'settings', 'notice', 'user', 'search', 'avatar', 'tag', 'tags', - 'api', 'message'); + 'api', 'message', 'group', 'groups'); $merged = array_merge($blacklist, common_config('nickname', 'blacklist')); return !in_array($nickname, $merged); } @@ -180,16 +183,16 @@ class User extends Memcached_DataObject $profile->nickname = $nickname; $profile->profileurl = common_profile_url($nickname); - if ($fullname) { + if (!empty($fullname)) { $profile->fullname = $fullname; } - if ($homepage) { + if (!empty($homepage)) { $profile->homepage = $homepage; } - if ($bio) { + if (!empty($bio)) { $profile->bio = $bio; } - if ($location) { + if (!empty($location)) { $profile->location = $location; } @@ -197,7 +200,7 @@ class User extends Memcached_DataObject $id = $profile->insert(); - if (!$id) { + if (empty($id)) { common_log_db_error($profile, 'INSERT', __FILE__); return false; } @@ -207,13 +210,13 @@ class User extends Memcached_DataObject $user->id = $id; $user->nickname = $nickname; - if ($password) { # may not have a password for OpenID users + 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 ($code) { + if (!empty($code)) { $invite = Invitation::staticGet($code); if ($invite && $invite->address && $invite->address_type == 'email' && $invite->address == $email) { $user->email = $invite->address; @@ -250,7 +253,7 @@ class User extends Memcached_DataObject return false; } - if ($email && !$user->email) { + if (!empty($email) && !$user->email) { $confirm = new Confirm_address(); $confirm->code = common_confirmation_code(128); @@ -265,7 +268,7 @@ class User extends Memcached_DataObject } } - if ($code && $user->email) { + if (!empty($code) && $user->email) { $user->emailChanged(); } @@ -338,11 +341,12 @@ class User extends Memcached_DataObject { # 3-way join; probably should get cached - $qry = 'SELECT user.* ' . - 'FROM subscription sub1 JOIN user ON sub1.subscribed = user.id ' . - 'JOIN subscription sub2 ON user.id = sub2.subscriber ' . + $UT = common_config('db','type')=='pgsql'?'"user"':'user'; + $qry = "SELECT $UT.* " . + "FROM subscription sub1 JOIN $UT ON sub1.subscribed = $UT.id " . + "JOIN subscription sub2 ON $UT.id = sub2.subscriber " . 'WHERE sub1.subscriber = %d and sub2.subscribed = %d ' . - 'ORDER BY user.nickname'; + "ORDER BY $UT.nickname"; $user = new User(); $user->query(sprintf($qry, $this->id, $this->id)); @@ -403,7 +407,7 @@ class User extends Memcached_DataObject 'FROM notice JOIN notice_inbox ON notice.id = notice_inbox.notice_id ' . 'WHERE notice_inbox.user_id = %d '; # NOTE: we override ORDER - $order = 'ORDER BY notice_inbox.created DESC, notice_inbox.notice_id DESC '; + $order = null; } return Notice::getStream(sprintf($qry, $this->id), 'user:notices_with_friends:' . $this->id, @@ -492,4 +496,152 @@ class User extends Memcached_DataObject return true; } + function isMember($group) + { + $profile = $this->getProfile(); + return $profile->isMember($group); + } + + function isAdmin($group) + { + $profile = $this->getProfile(); + return $profile->isAdmin($group); + } + + function getGroups($offset=0, $limit=null) + { + $qry = + 'SELECT user_group.* ' . + 'FROM user_group JOIN group_member '. + 'ON user_group.id = group_member.group_id ' . + 'WHERE group_member.profile_id = %d ' . + 'ORDER BY group_member.created DESC '; + + if ($offset) { + if (common_config('db','type') == 'pgsql') { + $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; + } else { + $qry .= ' LIMIT ' . $offset . ', ' . $limit; + } + } + + $groups = new User_group(); + + $cnt = $groups->query(sprintf($qry, $this->id)); + + return $groups; + } + + function getSubscriptions($offset=0, $limit=null) + { + $qry = + 'SELECT profile.* ' . + 'FROM profile JOIN subscription ' . + 'ON profile.id = subscription.subscribed ' . + 'WHERE subscription.subscriber = %d ' . + 'AND subscription.subscribed != subscription.subscriber ' . + 'ORDER BY subscription.created DESC '; + + if (common_config('db','type') == 'pgsql') { + $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; + } else { + $qry .= ' LIMIT ' . $offset . ', ' . $limit; + } + + $profile = new Profile(); + + $profile->query(sprintf($qry, $this->id)); + + return $profile; + } + + function getSubscribers($offset=0, $limit=null) + { + $qry = + 'SELECT profile.* ' . + 'FROM profile JOIN subscription ' . + 'ON profile.id = subscription.subscriber ' . + 'WHERE subscription.subscribed = %d ' . + 'AND subscription.subscribed != subscription.subscriber ' . + 'ORDER BY subscription.created DESC '; + + if ($offset) { + if (common_config('db','type') == 'pgsql') { + $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; + } else { + $qry .= ' LIMIT ' . $offset . ', ' . $limit; + } + } + + $profile = new Profile(); + + $cnt = $profile->query(sprintf($qry, $this->id)); + + return $profile; + } + + function getTaggedSubscribers($tag, $offset=0, $limit=null) + { + $qry = + 'SELECT profile.* ' . + 'FROM profile JOIN subscription ' . + 'ON profile.id = subscription.subscriber ' . + 'JOIN profile_tag ON (profile_tag.tagged = subscription.subscriber ' . + 'AND profile_tag.tagger = subscription.subscribed) ' . + 'WHERE subscription.subscribed = %d ' . + 'AND profile_tag.tag = "%s" ' . + 'AND subscription.subscribed != subscription.subscriber ' . + 'ORDER BY subscription.created DESC '; + + if ($offset) { + if (common_config('db','type') == 'pgsql') { + $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; + } else { + $qry .= ' LIMIT ' . $offset . ', ' . $limit; + } + } + + $profile = new Profile(); + + $cnt = $profile->query(sprintf($qry, $this->id, $tag)); + + return $profile; + } + + function getTaggedSubscriptions($tag, $offset=0, $limit=null) + { + $qry = + 'SELECT profile.* ' . + 'FROM profile JOIN subscription ' . + 'ON profile.id = subscription.subscribed ' . + 'JOIN profile_tag on (profile_tag.tagged = subscription.subscribed ' . + 'AND profile_tag.tagger = subscription.subscriber) ' . + 'WHERE subscription.subscriber = %d ' . + 'AND profile_tag.tag = "%s" ' . + 'AND subscription.subscribed != subscription.subscriber ' . + 'ORDER BY subscription.created DESC '; + + if (common_config('db','type') == 'pgsql') { + $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; + } else { + $qry .= ' LIMIT ' . $offset . ', ' . $limit; + } + + $profile = new Profile(); + + $profile->query(sprintf($qry, $this->id, $tag)); + + return $profile; + } + + function hasOpenID() + { + $oid = new User_openid(); + + $oid->user_id = $this->id; + + $cnt = $oid->find(); + + return ($cnt > 0); + } }