3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2008, 2009, StatusNet, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
23 * Table Definition for profile
25 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
27 class Profile extends Memcached_DataObject
30 /* the code below is auto generated do not remove the above tag */
32 public $__table = 'profile'; // table name
33 public $id; // int(4) primary_key not_null
34 public $nickname; // varchar(64) multiple_key not_null
35 public $fullname; // varchar(255) multiple_key
36 public $profileurl; // varchar(255)
37 public $homepage; // varchar(255) multiple_key
38 public $bio; // text() multiple_key
39 public $location; // varchar(255) multiple_key
40 public $lat; // decimal(10,7)
41 public $lon; // decimal(10,7)
42 public $location_id; // int(4)
43 public $location_ns; // int(4)
44 public $created; // datetime() not_null
45 public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
48 function staticGet($k,$v=NULL) {
49 return Memcached_DataObject::staticGet('Profile',$k,$v);
52 /* the code above is auto generated do not remove the tag below */
57 return User::staticGet('id', $this->id);
60 function getAvatar($width, $height=null)
62 if (is_null($height)) {
65 return Avatar::pkeyGet(array('profile_id' => $this->id,
67 'height' => $height));
70 function getOriginalAvatar()
72 $avatar = DB_DataObject::factory('avatar');
73 $avatar->profile_id = $this->id;
74 $avatar->original = true;
75 if ($avatar->find(true)) {
82 function setOriginal($filename)
84 $imagefile = new ImageFile($this->id, Avatar::path($filename));
86 $avatar = new Avatar();
87 $avatar->profile_id = $this->id;
88 $avatar->width = $imagefile->width;
89 $avatar->height = $imagefile->height;
90 $avatar->mediatype = image_type_to_mime_type($imagefile->type);
91 $avatar->filename = $filename;
92 $avatar->original = true;
93 $avatar->url = Avatar::url($filename);
94 $avatar->created = DB_DataObject_Cast::dateTime(); # current time
96 // XXX: start a transaction here
98 if (!$this->delete_avatars() || !$avatar->insert()) {
99 @unlink(Avatar::path($filename));
103 foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) {
104 // We don't do a scaled one if original is our scaled size
105 if (!($avatar->width == $size && $avatar->height == $size)) {
106 $scaled_filename = $imagefile->resize($size);
108 //$scaled = DB_DataObject::factory('avatar');
109 $scaled = new Avatar();
110 $scaled->profile_id = $this->id;
111 $scaled->width = $size;
112 $scaled->height = $size;
113 $scaled->original = false;
114 $scaled->mediatype = image_type_to_mime_type($imagefile->type);
115 $scaled->filename = $scaled_filename;
116 $scaled->url = Avatar::url($scaled_filename);
117 $scaled->created = DB_DataObject_Cast::dateTime(); # current time
119 if (!$scaled->insert()) {
129 * Delete attached avatars for this user from the database and filesystem.
130 * This should be used instead of a batch delete() to ensure that files
131 * get removed correctly.
133 * @param boolean $original true to delete only the original-size file
136 function delete_avatars($original=true)
138 $avatar = new Avatar();
139 $avatar->profile_id = $this->id;
141 while ($avatar->fetch()) {
142 if ($avatar->original) {
143 if ($original == false) {
153 * Gets either the full name (if filled) or the nickname.
157 function getBestName()
159 return ($this->fullname) ? $this->fullname : $this->nickname;
163 * Gets the full name (if filled) with nickname as a parenthetical, or the nickname alone
164 * if no fullname is provided.
168 function getFancyName()
170 if ($this->fullname) {
171 // TRANS: Full name of a profile or group (%1$s) followed by nickname (%2$s) in parentheses.
172 return sprintf(_m('FANCYNAME','%1$s (%2$s)'), $this->fullname, $this->nickname);
174 return $this->nickname;
179 * Get the most recent notice posted by this user, if any.
181 * @return mixed Notice or null
183 function getCurrentNotice()
185 $notice = $this->getNotices(0, 1);
187 if ($notice->fetch()) {
188 if ($notice instanceof ArrayWrapper) {
189 // hack for things trying to work with single notices
190 return $notice->_items[0];
198 function getTaggedNotices($tag, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0)
200 $stream = new TaggedProfileNoticeStream($this, $tag);
202 return $stream->getNotices($offset, $limit, $since_id, $max_id);
205 function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0)
207 $stream = new ProfileNoticeStream($this);
209 return $stream->getNotices($offset, $limit, $since_id, $max_id);
212 function isMember($group)
214 $gm = Group_member::pkeyGet(array('profile_id' => $this->id,
215 'group_id' => $group->id));
216 return (!empty($gm));
219 function isAdmin($group)
221 $gm = Group_member::pkeyGet(array('profile_id' => $this->id,
222 'group_id' => $group->id));
223 return (!empty($gm) && $gm->is_admin);
226 function isPendingMember($group)
228 $request = Group_join_queue::pkeyGet(array('profile_id' => $this->id,
229 'group_id' => $group->id));
230 return !empty($request);
233 function getGroups($offset=0, $limit=PROFILES_PER_PAGE)
237 $keypart = sprintf('profile:groups:%d', $this->id);
239 $idstring = self::cacheGet($keypart);
241 if ($idstring !== false) {
242 $ids = explode(',', $idstring);
244 $gm = new Group_member();
246 $gm->profile_id = $this->id;
249 while ($gm->fetch()) {
250 $ids[] = $gm->group_id;
254 self::cacheSet($keypart, implode(',', $ids));
259 foreach ($ids as $id) {
260 $group = User_group::staticGet('id', $id);
261 if (!empty($group)) {
266 return new ArrayWrapper($groups);
269 function isTagged($peopletag)
271 $tag = Profile_tag::pkeyGet(array('tagger' => $peopletag->tagger,
272 'tagged' => $this->id,
273 'tag' => $peopletag->tag));
277 function canTag($tagged)
279 if (empty($tagged)) {
283 if ($tagged->id == $this->id) {
287 $all = common_config('peopletag', 'allow_tagging', 'all');
288 $local = common_config('peopletag', 'allow_tagging', 'local');
289 $remote = common_config('peopletag', 'allow_tagging', 'remote');
290 $subs = common_config('peopletag', 'allow_tagging', 'subs');
296 $tagged_user = $tagged->getUser();
297 if (!empty($tagged_user)) {
302 return (Subscription::exists($this, $tagged) ||
303 Subscription::exists($tagged, $this));
304 } else if ($remote) {
310 function getOwnedTags($auth_user, $offset=0, $limit=null, $since_id=0, $max_id=0)
312 $tags = new Profile_list();
313 $tags->tagger = $this->id;
315 if (($auth_user instanceof User || $auth_user instanceof Profile) &&
316 $auth_user->id === $this->id) {
317 // no condition, get both private and public tags
319 $tags->private = false;
322 $tags->selectAdd('id as "cursor"');
325 $tags->whereAdd('id > '.$since_id);
329 $tags->whereAdd('id <= '.$max_id);
332 if($offset>=0 && !is_null($limit)) {
333 $tags->limit($offset, $limit);
336 $tags->orderBy('id DESC');
342 function getOtherTags($auth_user=null, $offset=0, $limit=null, $since_id=0, $max_id=0)
344 $lists = new Profile_list();
346 $tags = new Profile_tag();
347 $tags->tagged = $this->id;
349 $lists->joinAdd($tags);
350 #@fixme: postgres (round(date_part('epoch', my_date)))
351 $lists->selectAdd('unix_timestamp(profile_tag.modified) as "cursor"');
353 if ($auth_user instanceof User || $auth_user instanceof Profile) {
354 $lists->whereAdd('( ( profile_list.private = false ) ' .
355 'OR ( profile_list.tagger = ' . $auth_user->id . ' AND ' .
356 'profile_list.private = true ) )');
358 $lists->private = false;
362 $lists->whereAdd('cursor > '.$since_id);
366 $lists->whereAdd('cursor <= '.$max_id);
369 if($offset>=0 && !is_null($limit)) {
370 $lists->limit($offset, $limit);
373 $lists->orderBy('profile_tag.modified DESC');
379 function getPrivateTags($offset=0, $limit=null, $since_id=0, $max_id=0)
381 $tags = new Profile_list();
382 $tags->private = true;
383 $tags->tagger = $this->id;
386 $tags->whereAdd('id > '.$since_id);
390 $tags->whereAdd('id <= '.$max_id);
393 if($offset>=0 && !is_null($limit)) {
394 $tags->limit($offset, $limit);
397 $tags->orderBy('id DESC');
403 function hasLocalTags()
405 $tags = new Profile_tag();
407 $tags->joinAdd(array('tagger', 'user:id'));
408 $tags->whereAdd('tagged = '.$this->id);
409 $tags->whereAdd('tagger != '.$this->id);
414 return ($tags->N == 0) ? false : true;
417 function getTagSubscriptions($offset=0, $limit=null, $since_id=0, $max_id=0)
419 $lists = new Profile_list();
420 $subs = new Profile_tag_subscription();
422 $lists->joinAdd($subs);
423 #@fixme: postgres (round(date_part('epoch', my_date)))
424 $lists->selectAdd('unix_timestamp(profile_tag_subscription.created) as "cursor"');
426 $lists->whereAdd('profile_tag_subscription.profile_id = '.$this->id);
429 $lists->whereAdd('cursor > '.$since_id);
433 $lists->whereAdd('cursor <= '.$max_id);
436 if($offset>=0 && !is_null($limit)) {
437 $lists->limit($offset, $limit);
440 $lists->orderBy('"cursor" DESC');
447 * Request to join the given group.
448 * May throw exceptions on failure.
450 * @param User_group $group
451 * @return mixed: Group_member on success, Group_join_queue if pending approval, null on some cancels?
453 function joinGroup(User_group $group)
456 if ($group->join_policy == User_group::JOIN_POLICY_MODERATE) {
457 $join = Group_join_queue::saveNew($this, $group);
459 if (Event::handle('StartJoinGroup', array($group, $this))) {
460 $join = Group_member::join($group->id, $this->id);
461 self::blow('profile:groups:%d', $this->id);
462 Event::handle('EndJoinGroup', array($group, $this));
466 // Send any applicable notifications...
473 * Leave a group that this profile is a member of.
475 * @param User_group $group
477 function leaveGroup(User_group $group)
479 if (Event::handle('StartLeaveGroup', array($group, $this))) {
480 Group_member::leave($group->id, $this->id);
481 self::blow('profile:groups:%d', $this->id);
482 Event::handle('EndLeaveGroup', array($group, $this));
486 function avatarUrl($size=AVATAR_PROFILE_SIZE)
488 $avatar = $this->getAvatar($size);
490 return $avatar->displayUrl();
492 return Avatar::defaultImage($size);
496 function getSubscriptions($offset=0, $limit=null)
498 $subs = Subscription::bySubscriber($this->id,
504 while ($subs->fetch()) {
505 $profile = Profile::staticGet($subs->subscribed);
507 $profiles[] = $profile;
511 return new ArrayWrapper($profiles);
514 function getSubscribers($offset=0, $limit=null)
516 $subs = Subscription::bySubscribed($this->id,
522 while ($subs->fetch()) {
523 $profile = Profile::staticGet($subs->subscriber);
525 $profiles[] = $profile;
529 return new ArrayWrapper($profiles);
532 function getTaggedSubscribers($tag)
535 'SELECT profile.* ' .
536 'FROM profile JOIN (subscription, profile_tag, profile_list) ' .
537 'ON profile.id = subscription.subscriber ' .
538 'AND profile.id = profile_tag.tagged ' .
539 'AND profile_tag.tagger = profile_list.tagger AND profile_tag.tag = profile_list.tag ' .
540 'WHERE subscription.subscribed = %d ' .
541 'AND subscription.subscribed != subscription.subscriber ' .
542 'AND profile_tag.tagger = %d AND profile_tag.tag = "%s" ' .
543 'AND profile_list.private = false ' .
544 'ORDER BY subscription.created DESC';
546 $profile = new Profile();
549 $cnt = $profile->query(sprintf($qry, $this->id, $this->id, $tag));
551 while ($profile->fetch()) {
552 $tagged[] = clone($profile);
558 * Get pending subscribers, who have not yet been approved.
564 function getRequests($offset=0, $limit=null)
567 'SELECT profile.* ' .
568 'FROM profile JOIN subscription_queue '.
569 'ON profile.id = subscription_queue.subscriber ' .
570 'WHERE subscription_queue.subscribed = %d ' .
571 'ORDER BY subscription_queue.created DESC ';
573 if ($limit != null) {
574 if (common_config('db','type') == 'pgsql') {
575 $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
577 $qry .= ' LIMIT ' . $offset . ', ' . $limit;
581 $members = new Profile();
583 $members->query(sprintf($qry, $this->id));
587 function subscriptionCount()
589 $c = Cache::instance();
592 $cnt = $c->get(Cache::key('profile:subscription_count:'.$this->id));
593 if (is_integer($cnt)) {
598 $sub = new Subscription();
599 $sub->subscriber = $this->id;
601 $cnt = (int) $sub->count('distinct subscribed');
603 $cnt = ($cnt > 0) ? $cnt - 1 : $cnt;
606 $c->set(Cache::key('profile:subscription_count:'.$this->id), $cnt);
612 function subscriberCount()
614 $c = Cache::instance();
616 $cnt = $c->get(Cache::key('profile:subscriber_count:'.$this->id));
617 if (is_integer($cnt)) {
622 $sub = new Subscription();
623 $sub->subscribed = $this->id;
624 $sub->whereAdd('subscriber != subscribed');
625 $cnt = (int) $sub->count('distinct subscriber');
628 $c->set(Cache::key('profile:subscriber_count:'.$this->id), $cnt);
635 * Is this profile subscribed to another profile?
637 * @param Profile $other
640 function isSubscribed($other)
642 return Subscription::exists($this, $other);
646 * Check if a pending subscription request is outstanding for this...
648 * @param Profile $other
651 function hasPendingSubscription($other)
653 return Subscription_queue::exists($this, $other);
657 * Are these two profiles subscribed to each other?
659 * @param Profile $other
662 function mutuallySubscribed($other)
664 return $this->isSubscribed($other) &&
665 $other->isSubscribed($this);
668 function hasFave($notice)
670 $cache = Cache::instance();
672 // XXX: Kind of a hack.
674 if (!empty($cache)) {
675 // This is the stream of favorite notices, in rev chron
676 // order. This forces it into cache.
678 $ids = Fave::idStream($this->id, 0, CachingNoticeStream::CACHE_WINDOW);
680 // If it's in the list, then it's a fave
682 if (in_array($notice->id, $ids)) {
686 // If we're not past the end of the cache window,
687 // then the cache has all available faves, so this one
690 if (count($ids) < CachingNoticeStream::CACHE_WINDOW) {
694 // Otherwise, cache doesn't have all faves;
695 // fall through to the default
698 $fave = Fave::pkeyGet(array('user_id' => $this->id,
699 'notice_id' => $notice->id));
700 return ((is_null($fave)) ? false : true);
705 $c = Cache::instance();
707 $cnt = $c->get(Cache::key('profile:fave_count:'.$this->id));
708 if (is_integer($cnt)) {
714 $faves->user_id = $this->id;
715 $cnt = (int) $faves->count('distinct notice_id');
718 $c->set(Cache::key('profile:fave_count:'.$this->id), $cnt);
724 function noticeCount()
726 $c = Cache::instance();
729 $cnt = $c->get(Cache::key('profile:notice_count:'.$this->id));
730 if (is_integer($cnt)) {
735 $notices = new Notice();
736 $notices->profile_id = $this->id;
737 $cnt = (int) $notices->count('distinct id');
740 $c->set(Cache::key('profile:notice_count:'.$this->id), $cnt);
746 function blowFavesCache()
748 $cache = Cache::instance();
750 // Faves don't happen chronologically, so we need to blow
752 $cache->delete(Cache::key('fave:ids_by_user:'.$this->id));
753 $cache->delete(Cache::key('fave:ids_by_user:'.$this->id.';last'));
754 $cache->delete(Cache::key('fave:ids_by_user_own:'.$this->id));
755 $cache->delete(Cache::key('fave:ids_by_user_own:'.$this->id.';last'));
757 $this->blowFaveCount();
760 function blowSubscriberCount()
762 $c = Cache::instance();
764 $c->delete(Cache::key('profile:subscriber_count:'.$this->id));
768 function blowSubscriptionCount()
770 $c = Cache::instance();
772 $c->delete(Cache::key('profile:subscription_count:'.$this->id));
776 function blowFaveCount()
778 $c = Cache::instance();
780 $c->delete(Cache::key('profile:fave_count:'.$this->id));
784 function blowNoticeCount()
786 $c = Cache::instance();
788 $c->delete(Cache::key('profile:notice_count:'.$this->id));
792 static function maxBio()
794 $biolimit = common_config('profile', 'biolimit');
795 // null => use global limit (distinct from 0!)
796 if (is_null($biolimit)) {
797 $biolimit = common_config('site', 'textlimit');
802 static function bioTooLong($bio)
804 $biolimit = self::maxBio();
805 return ($biolimit > 0 && !empty($bio) && (mb_strlen($bio) > $biolimit));
810 $this->_deleteNotices();
811 $this->_deleteSubscriptions();
812 $this->_deleteMessages();
813 $this->_deleteTags();
814 $this->_deleteBlocks();
815 $this->delete_avatars();
817 // Warning: delete() will run on the batch objects,
818 // not on individual objects.
819 $related = array('Reply',
822 Event::handle('ProfileDeleteRelated', array($this, &$related));
824 foreach ($related as $cls) {
826 $inst->profile_id = $this->id;
833 function _deleteNotices()
835 $notice = new Notice();
836 $notice->profile_id = $this->id;
838 if ($notice->find()) {
839 while ($notice->fetch()) {
840 $other = clone($notice);
846 function _deleteSubscriptions()
848 $sub = new Subscription();
849 $sub->subscriber = $this->id;
853 while ($sub->fetch()) {
854 $other = Profile::staticGet('id', $sub->subscribed);
858 if ($other->id == $this->id) {
861 Subscription::cancel($this, $other);
864 $subd = new Subscription();
865 $subd->subscribed = $this->id;
868 while ($subd->fetch()) {
869 $other = Profile::staticGet('id', $subd->subscriber);
873 if ($other->id == $this->id) {
876 Subscription::cancel($other, $this);
879 $self = new Subscription();
881 $self->subscriber = $this->id;
882 $self->subscribed = $this->id;
887 function _deleteMessages()
889 $msg = new Message();
890 $msg->from_profile = $this->id;
893 $msg = new Message();
894 $msg->to_profile = $this->id;
898 function _deleteTags()
900 $tag = new Profile_tag();
901 $tag->tagged = $this->id;
905 function _deleteBlocks()
907 $block = new Profile_block();
908 $block->blocked = $this->id;
911 $block = new Group_block();
912 $block->blocked = $this->id;
916 // XXX: identical to Notice::getLocation.
918 function getLocation()
922 if (!empty($this->location_id) && !empty($this->location_ns)) {
923 $location = Location::fromId($this->location_id, $this->location_ns);
926 if (is_null($location)) { // no ID, or Location::fromId() failed
927 if (!empty($this->lat) && !empty($this->lon)) {
928 $location = Location::fromLatLon($this->lat, $this->lon);
932 if (is_null($location)) { // still haven't found it!
933 if (!empty($this->location)) {
934 $location = Location::fromName($this->location);
941 function hasRole($name)
944 if (Event::handle('StartHasRole', array($this, $name, &$has_role))) {
945 $role = Profile_role::pkeyGet(array('profile_id' => $this->id,
947 $has_role = !empty($role);
948 Event::handle('EndHasRole', array($this, $name, $has_role));
953 function grantRole($name)
955 if (Event::handle('StartGrantRole', array($this, $name))) {
957 $role = new Profile_role();
959 $role->profile_id = $this->id;
961 $role->created = common_sql_now();
963 $result = $role->insert();
966 throw new Exception("Can't save role '$name' for profile '{$this->id}'");
969 if ($name == 'owner') {
970 User::blow('user:site_owner');
973 Event::handle('EndGrantRole', array($this, $name));
979 function revokeRole($name)
981 if (Event::handle('StartRevokeRole', array($this, $name))) {
983 $role = Profile_role::pkeyGet(array('profile_id' => $this->id,
987 // TRANS: Exception thrown when trying to revoke an existing role for a user that does not exist.
988 // TRANS: %1$s is the role name, %2$s is the user ID (number).
989 throw new Exception(sprintf(_('Cannot revoke role "%1$s" for user #%2$d; does not exist.'),$name, $this->id));
992 $result = $role->delete();
995 common_log_db_error($role, 'DELETE', __FILE__);
996 // TRANS: Exception thrown when trying to revoke a role for a user with a failing database query.
997 // TRANS: %1$s is the role name, %2$s is the user ID (number).
998 throw new Exception(sprintf(_('Cannot revoke role "%1$s" for user #%2$d; database error.'),$name, $this->id));
1001 if ($name == 'owner') {
1002 User::blow('user:site_owner');
1005 Event::handle('EndRevokeRole', array($this, $name));
1011 function isSandboxed()
1013 return $this->hasRole(Profile_role::SANDBOXED);
1016 function isSilenced()
1018 return $this->hasRole(Profile_role::SILENCED);
1023 $this->grantRole(Profile_role::SANDBOXED);
1026 function unsandbox()
1028 $this->revokeRole(Profile_role::SANDBOXED);
1033 $this->grantRole(Profile_role::SILENCED);
1036 function unsilence()
1038 $this->revokeRole(Profile_role::SILENCED);
1042 * Does this user have the right to do X?
1044 * With our role-based authorization, this is merely a lookup for whether the user
1045 * has a particular role. The implementation currently uses a switch statement
1046 * to determine if the user has the pre-defined role to exercise the right. Future
1047 * implementations may allow per-site roles, and different mappings of roles to rights.
1049 * @param $right string Name of the right, usually a constant in class Right
1050 * @return boolean whether the user has the right in question
1052 function hasRight($right)
1056 if ($this->hasRole(Profile_role::DELETED)) {
1060 if (Event::handle('UserRightsCheck', array($this, $right, &$result))) {
1063 case Right::DELETEOTHERSNOTICE:
1064 case Right::MAKEGROUPADMIN:
1065 case Right::SANDBOXUSER:
1066 case Right::SILENCEUSER:
1067 case Right::DELETEUSER:
1068 case Right::DELETEGROUP:
1069 $result = $this->hasRole(Profile_role::MODERATOR);
1071 case Right::CONFIGURESITE:
1072 $result = $this->hasRole(Profile_role::ADMINISTRATOR);
1074 case Right::GRANTROLE:
1075 case Right::REVOKEROLE:
1076 $result = $this->hasRole(Profile_role::OWNER);
1078 case Right::NEWNOTICE:
1079 case Right::NEWMESSAGE:
1080 case Right::SUBSCRIBE:
1081 case Right::CREATEGROUP:
1082 $result = !$this->isSilenced();
1084 case Right::PUBLICNOTICE:
1085 case Right::EMAILONREPLY:
1086 case Right::EMAILONSUBSCRIBE:
1087 case Right::EMAILONFAVE:
1088 $result = !$this->isSandboxed();
1090 case Right::WEBLOGIN:
1091 $result = !$this->isSilenced();
1094 $result = !$this->isSilenced();
1096 case Right::BACKUPACCOUNT:
1097 $result = common_config('profile', 'backup');
1099 case Right::RESTOREACCOUNT:
1100 $result = common_config('profile', 'restore');
1102 case Right::DELETEACCOUNT:
1103 $result = common_config('profile', 'delete');
1105 case Right::MOVEACCOUNT:
1106 $result = common_config('profile', 'move');
1116 function hasRepeated($notice_id)
1118 // XXX: not really a pkey, but should work
1120 $notice = Memcached_DataObject::pkeyGet('Notice',
1121 array('profile_id' => $this->id,
1122 'repeat_of' => $notice_id));
1124 return !empty($notice);
1128 * Returns an XML string fragment with limited profile information
1129 * as an Atom <author> element.
1131 * Assumes that Atom has been previously set up as the base namespace.
1133 * @param Profile $cur the current authenticated user
1137 function asAtomAuthor($cur = null)
1139 $xs = new XMLStringer(true);
1141 $xs->elementStart('author');
1142 $xs->element('name', null, $this->nickname);
1143 $xs->element('uri', null, $this->getUri());
1146 $attrs['following'] = $cur->isSubscribed($this) ? 'true' : 'false';
1147 $attrs['blocking'] = $cur->hasBlocked($this) ? 'true' : 'false';
1148 $xs->element('statusnet:profile_info', $attrs, null);
1150 $xs->elementEnd('author');
1152 return $xs->getString();
1156 * Extra profile info for atom entries
1158 * Clients use some extra profile info in the atom stream.
1159 * This gives it to them.
1161 * @param User $cur Current user
1163 * @return array representation of <statusnet:profile_info> element or null
1166 function profileInfo($cur)
1168 $profileInfoAttr = array('local_id' => $this->id);
1171 // Whether the current user is a subscribed to this profile
1172 $profileInfoAttr['following'] = $cur->isSubscribed($this) ? 'true' : 'false';
1173 // Whether the current user is has blocked this profile
1174 $profileInfoAttr['blocking'] = $cur->hasBlocked($this) ? 'true' : 'false';
1177 return array('statusnet:profile_info', $profileInfoAttr, null);
1181 * Returns an XML string fragment with profile information as an
1182 * Activity Streams <activity:actor> element.
1184 * Assumes that 'activity' namespace has been previously defined.
1188 function asActivityActor()
1190 return $this->asActivityNoun('actor');
1194 * Returns an XML string fragment with profile information as an
1195 * Activity Streams noun object with the given element type.
1197 * Assumes that 'activity', 'georss', and 'poco' namespace has been
1198 * previously defined.
1200 * @param string $element one of 'actor', 'subject', 'object', 'target'
1204 function asActivityNoun($element)
1206 $noun = ActivityObject::fromProfile($this);
1207 return $noun->asString('activity:' . $element);
1211 * Returns the best URI for a profile. Plugins may override.
1213 * @return string $uri
1219 // give plugins a chance to set the URI
1220 if (Event::handle('StartGetProfileUri', array($this, &$uri))) {
1222 // check for a local user first
1223 $user = User::staticGet('id', $this->id);
1225 if (!empty($user)) {
1228 // return OMB profile if any
1229 $remote = Remote_profile::staticGet('id', $this->id);
1230 if (!empty($remote)) {
1231 $uri = $remote->uri;
1234 Event::handle('EndGetProfileUri', array($this, &$uri));
1240 function hasBlocked($other)
1242 $block = Profile_block::get($this->id, $other->id);
1244 if (empty($block)) {
1253 function getAtomFeed()
1257 if (Event::handle('StartProfileGetAtomFeed', array($this, &$feed))) {
1258 $user = User::staticGet('id', $this->id);
1259 if (!empty($user)) {
1260 $feed = common_local_url('ApiTimelineUser', array('id' => $user->id,
1261 'format' => 'atom'));
1263 Event::handle('EndProfileGetAtomFeed', array($this, $feed));
1269 static function fromURI($uri)
1273 if (Event::handle('StartGetProfileFromURI', array($uri, &$profile))) {
1274 // Get a local user or remote (OMB 0.1) profile
1275 $user = User::staticGet('uri', $uri);
1276 if (!empty($user)) {
1277 $profile = $user->getProfile();
1279 $remote_profile = Remote_profile::staticGet('uri', $uri);
1280 if (!empty($remote_profile)) {
1281 $profile = Profile::staticGet('id', $remote_profile->profile_id);
1284 Event::handle('EndGetProfileFromURI', array($uri, $profile));
1290 function canRead(Notice $notice)
1292 if ($notice->scope & Notice::SITE_SCOPE) {
1293 $user = $this->getUser();
1299 if ($notice->scope & Notice::ADDRESSEE_SCOPE) {
1300 $replies = $notice->getReplies();
1302 if (!in_array($this->id, $replies)) {
1303 $groups = $notice->getGroups();
1307 foreach ($groups as $group) {
1308 if ($this->isMember($group)) {
1320 if ($notice->scope & Notice::FOLLOWER_SCOPE) {
1321 $author = $notice->getProfile();
1322 if (!Subscription::exists($this, $author)) {