]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/User.php
Merge branch '0.9.x' of gitorious.org:statusnet/mainline into 0.9.x
[quix0rs-gnu-social.git] / classes / User.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2008, 2009, StatusNet, Inc.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 if (!defined('STATUSNET') && !defined('LACONICA')) {
21     exit(1);
22 }
23
24 /**
25  * Table Definition for user
26  */
27
28 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
29 require_once 'Validate.php';
30
31 class User extends Memcached_DataObject
32 {
33     ###START_AUTOCODE
34     /* the code below is auto generated do not remove the above tag */
35
36     public $__table = 'user';                            // table name
37     public $id;                              // int(4)  primary_key not_null
38     public $nickname;                        // varchar(64)  unique_key
39     public $password;                        // varchar(255)
40     public $email;                           // varchar(255)  unique_key
41     public $incomingemail;                   // varchar(255)  unique_key
42     public $emailnotifysub;                  // tinyint(1)   default_1
43     public $emailnotifyfav;                  // tinyint(1)   default_1
44     public $emailnotifynudge;                // tinyint(1)   default_1
45     public $emailnotifymsg;                  // tinyint(1)   default_1
46     public $emailnotifyattn;                 // tinyint(1)   default_1
47     public $emailmicroid;                    // tinyint(1)   default_1
48     public $language;                        // varchar(50)
49     public $timezone;                        // varchar(50)
50     public $emailpost;                       // tinyint(1)   default_1
51     public $jabber;                          // varchar(255)  unique_key
52     public $jabbernotify;                    // tinyint(1)
53     public $jabberreplies;                   // tinyint(1)
54     public $jabbermicroid;                   // tinyint(1)   default_1
55     public $updatefrompresence;              // tinyint(1)
56     public $sms;                             // varchar(64)  unique_key
57     public $carrier;                         // int(4)
58     public $smsnotify;                       // tinyint(1)
59     public $smsreplies;                      // tinyint(1)
60     public $smsemail;                        // varchar(255)
61     public $uri;                             // varchar(255)  unique_key
62     public $autosubscribe;                   // tinyint(1)
63     public $urlshorteningservice;            // varchar(50)   default_ur1.ca
64     public $inboxed;                         // tinyint(1)
65     public $design_id;                       // int(4)
66     public $viewdesigns;                     // tinyint(1)   default_1
67     public $created;                         // datetime()   not_null
68     public $modified;                        // timestamp()   not_null default_CURRENT_TIMESTAMP
69
70     /* Static get */
71     function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('User',$k,$v); }
72
73     /* the code above is auto generated do not remove the tag below */
74     ###END_AUTOCODE
75
76     function getProfile()
77     {
78         $profile = Profile::staticGet('id', $this->id);
79         if (empty($profile)) {
80             throw new UserNoProfileException($this);
81         }
82         return $profile;
83     }
84
85     function isSubscribed($other)
86     {
87         return Subscription::exists($this->getProfile(), $other);
88     }
89
90     // 'update' won't write key columns, so we have to do it ourselves.
91
92     function updateKeys(&$orig)
93     {
94         $this->_connect();
95         $parts = array();
96         foreach (array('nickname', 'email', 'jabber', 'incomingemail', 'sms', 'carrier', 'smsemail', 'language', 'timezone') as $k) {
97             if (strcmp($this->$k, $orig->$k) != 0) {
98                 $parts[] = $k . ' = ' . $this->_quote($this->$k);
99             }
100         }
101         if (count($parts) == 0) {
102             // No changes
103             return true;
104         }
105         $toupdate = implode(', ', $parts);
106
107         $table = common_database_tablename($this->tableName());
108         $qry = 'UPDATE ' . $table . ' SET ' . $toupdate .
109           ' WHERE id = ' . $this->id;
110         $orig->decache();
111         $result = $this->query($qry);
112         if ($result) {
113             $this->encache();
114         }
115         return $result;
116     }
117
118     static function allowed_nickname($nickname)
119     {
120         // XXX: should already be validated for size, content, etc.
121         $blacklist = common_config('nickname', 'blacklist');
122
123         //all directory and file names should be blacklisted
124         $d = dir(INSTALLDIR);
125         while (false !== ($entry = $d->read())) {
126             $blacklist[]=$entry;
127         }
128         $d->close();
129
130         //all top level names in the router should be blacklisted
131         $router = Router::get();
132         foreach(array_keys($router->m->getPaths()) as $path){
133             if(preg_match('/^\/(.*?)[\/\?]/',$path,$matches)){
134                 $blacklist[]=$matches[1];
135             }
136         }
137         return !in_array($nickname, $blacklist);
138     }
139
140     /**
141      * Get the most recent notice posted by this user, if any.
142      *
143      * @return mixed Notice or null
144      */
145     function getCurrentNotice()
146     {
147         $profile = $this->getProfile();
148         return $profile->getCurrentNotice();
149     }
150
151     function getCarrier()
152     {
153         return Sms_carrier::staticGet('id', $this->carrier);
154     }
155
156     /**
157      * @deprecated use Subscription::start($sub, $other);
158      */
159     function subscribeTo($other)
160     {
161         return Subscription::start($this->getProfile(), $other);
162     }
163
164     function hasBlocked($other)
165     {
166         $profile = $this->getProfile();
167         return $profile->hasBlocked($other);
168     }
169
170     /**
171      * Register a new user account and profile and set up default subscriptions.
172      * If a new-user welcome message is configured, this will be sent.
173      *
174      * @param array $fields associative array of optional properties
175      *              string 'bio'
176      *              string 'email'
177      *              bool 'email_confirmed' pass true to mark email as pre-confirmed
178      *              string 'fullname'
179      *              string 'homepage'
180      *              string 'location' informal string description of geolocation
181      *              float 'lat' decimal latitude for geolocation
182      *              float 'lon' decimal longitude for geolocation
183      *              int 'location_id' geoname identifier
184      *              int 'location_ns' geoname namespace to interpret location_id
185      *              string 'nickname' REQUIRED
186      *              string 'password' (may be missing for eg OpenID registrations)
187      *              string 'code' invite code
188      *              ?string 'uri' permalink to notice; defaults to local notice URL
189      * @return mixed User object or false on failure
190      */
191     static function register($fields) {
192
193         // MAGICALLY put fields into current scope
194
195         extract($fields);
196
197         $profile = new Profile();
198
199         if(!empty($email))
200         {
201             $email = common_canonical_email($email);
202         }
203
204         $nickname = common_canonical_nickname($nickname);
205         $profile->nickname = $nickname;
206         if(! User::allowed_nickname($nickname)){
207             common_log(LOG_WARNING, sprintf("Attempted to register a nickname that is not allowed: %s", $profile->nickname),
208                        __FILE__);
209             return false;
210         }
211         $profile->profileurl = common_profile_url($nickname);
212
213         if (!empty($fullname)) {
214             $profile->fullname = $fullname;
215         }
216         if (!empty($homepage)) {
217             $profile->homepage = $homepage;
218         }
219         if (!empty($bio)) {
220             $profile->bio = $bio;
221         }
222         if (!empty($location)) {
223             $profile->location = $location;
224
225             $loc = Location::fromName($location);
226
227             if (!empty($loc)) {
228                 $profile->lat         = $loc->lat;
229                 $profile->lon         = $loc->lon;
230                 $profile->location_id = $loc->location_id;
231                 $profile->location_ns = $loc->location_ns;
232             }
233         }
234
235         $profile->created = common_sql_now();
236
237         $user = new User();
238
239         $user->nickname = $nickname;
240
241         // Users who respond to invite email have proven their ownership of that address
242
243         if (!empty($code)) {
244             $invite = Invitation::staticGet($code);
245             if ($invite && $invite->address && $invite->address_type == 'email' && $invite->address == $email) {
246                 $user->email = $invite->address;
247             }
248         }
249
250         if(isset($email_confirmed) && $email_confirmed) {
251             $user->email = $email;
252         }
253
254         // This flag is ignored but still set to 1
255
256         $user->inboxed = 1;
257
258         // Set default-on options here, otherwise they'll be disabled
259         // initially for sites using caching, since the initial encache
260         // doesn't know about the defaults in the database.
261         $user->emailnotifysub = 1;
262         $user->emailnotifyfav = 1;
263         $user->emailnotifynudge = 1;
264         $user->emailnotifymsg = 1;
265         $user->emailnotifyattn = 1;
266         $user->emailmicroid = 1;
267         $user->emailpost = 1;
268         $user->jabbermicroid = 1;
269         $user->viewdesigns = 1;
270
271         $user->created = common_sql_now();
272
273         if (Event::handle('StartUserRegister', array(&$user, &$profile))) {
274
275             $profile->query('BEGIN');
276
277             $id = $profile->insert();
278
279             if (empty($id)) {
280                 common_log_db_error($profile, 'INSERT', __FILE__);
281                 return false;
282             }
283
284             $user->id = $id;
285
286             if (!empty($uri)) {
287                 $user->uri = $uri;
288             } else {
289                 $user->uri = common_user_uri($user);
290             }
291
292             if (!empty($password)) { // may not have a password for OpenID users
293                 $user->password = common_munge_password($password, $id);
294             }
295
296             $result = $user->insert();
297
298             if (!$result) {
299                 common_log_db_error($user, 'INSERT', __FILE__);
300                 return false;
301             }
302
303             // Everyone gets an inbox
304
305             $inbox = new Inbox();
306
307             $inbox->user_id = $user->id;
308             $inbox->notice_ids = '';
309
310             $result = $inbox->insert();
311
312             if (!$result) {
313                 common_log_db_error($inbox, 'INSERT', __FILE__);
314                 return false;
315             }
316
317             // Everyone is subscribed to themself
318
319             $subscription = new Subscription();
320             $subscription->subscriber = $user->id;
321             $subscription->subscribed = $user->id;
322             $subscription->created = $user->created;
323
324             $result = $subscription->insert();
325
326             if (!$result) {
327                 common_log_db_error($subscription, 'INSERT', __FILE__);
328                 return false;
329             }
330
331             if (!empty($email) && !$user->email) {
332
333                 $confirm = new Confirm_address();
334                 $confirm->code = common_confirmation_code(128);
335                 $confirm->user_id = $user->id;
336                 $confirm->address = $email;
337                 $confirm->address_type = 'email';
338
339                 $result = $confirm->insert();
340
341                 if (!$result) {
342                     common_log_db_error($confirm, 'INSERT', __FILE__);
343                     return false;
344                 }
345             }
346
347             if (!empty($code) && $user->email) {
348                 $user->emailChanged();
349             }
350
351             // Default system subscription
352
353             $defnick = common_config('newuser', 'default');
354
355             if (!empty($defnick)) {
356                 $defuser = User::staticGet('nickname', $defnick);
357                 if (empty($defuser)) {
358                     common_log(LOG_WARNING, sprintf("Default user %s does not exist.", $defnick),
359                                __FILE__);
360                 } else {
361                     Subscription::start($user, $defuser);
362                 }
363             }
364
365             $profile->query('COMMIT');
366
367             if (!empty($email) && !$user->email) {
368                 mail_confirm_address($user, $confirm->code, $profile->nickname, $email);
369             }
370
371             // Welcome message
372
373             $welcome = common_config('newuser', 'welcome');
374
375             if (!empty($welcome)) {
376                 $welcomeuser = User::staticGet('nickname', $welcome);
377                 if (empty($welcomeuser)) {
378                     common_log(LOG_WARNING, sprintf("Welcome user %s does not exist.", $defnick),
379                                __FILE__);
380                 } else {
381                     $notice = Notice::saveNew($welcomeuser->id,
382                                               // TRANS: Notice given on user registration.
383                                               // TRANS: %1$s is the sitename, $2$s is the registering user's nickname.
384                                               sprintf(_('Welcome to %1$s, @%2$s!'),
385                                                       common_config('site', 'name'),
386                                                       $user->nickname),
387                                               'system');
388                 }
389             }
390
391             Event::handle('EndUserRegister', array(&$profile, &$user));
392         }
393
394         return $user;
395     }
396
397     // Things we do when the email changes
398     function emailChanged()
399     {
400
401         $invites = new Invitation();
402         $invites->address = $this->email;
403         $invites->address_type = 'email';
404
405         if ($invites->find()) {
406             while ($invites->fetch()) {
407                 $other = User::staticGet($invites->user_id);
408                 subs_subscribe_to($other, $this);
409             }
410         }
411     }
412
413     function hasFave($notice)
414     {
415         $profile = $this->getProfile();
416         return $profile->hasFave($notice);
417     }
418
419     function mutuallySubscribed($other)
420     {
421         return $this->isSubscribed($other) &&
422           $other->isSubscribed($this);
423     }
424
425     function mutuallySubscribedUsers()
426     {
427         // 3-way join; probably should get cached
428         $UT = common_config('db','type')=='pgsql'?'"user"':'user';
429         $qry = "SELECT $UT.* " .
430           "FROM subscription sub1 JOIN $UT ON sub1.subscribed = $UT.id " .
431           "JOIN subscription sub2 ON $UT.id = sub2.subscriber " .
432           'WHERE sub1.subscriber = %d and sub2.subscribed = %d ' .
433           "ORDER BY $UT.nickname";
434         $user = new User();
435         $user->query(sprintf($qry, $this->id, $this->id));
436
437         return $user;
438     }
439
440     function getReplies($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
441     {
442         $ids = Reply::stream($this->id, $offset, $limit, $since_id, $before_id);
443         return Notice::getStreamByIds($ids);
444     }
445
446     function getTaggedNotices($tag, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0) {
447         $profile = $this->getProfile();
448         return $profile->getTaggedNotices($tag, $offset, $limit, $since_id, $before_id);
449     }
450
451     function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
452     {
453         $profile = $this->getProfile();
454         return $profile->getNotices($offset, $limit, $since_id, $before_id);
455     }
456
457     function favoriteNotices($own=false, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0)
458     {
459         $ids = Fave::stream($this->id, $offset, $limit, $own, $since_id, $max_id);
460         return Notice::getStreamByIds($ids);
461     }
462
463     function noticesWithFriends($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
464     {
465         return Inbox::streamNotices($this->id, $offset, $limit, $since_id, $before_id, false);
466     }
467
468     function noticeInbox($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
469     {
470         return Inbox::streamNotices($this->id, $offset, $limit, $since_id, $before_id, true);
471     }
472
473     function friendsTimeline($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
474     {
475         return Inbox::streamNotices($this->id, $offset, $limit, $since_id, $before_id, false);
476     }
477
478     function ownFriendsTimeline($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
479     {
480         return Inbox::streamNotices($this->id, $offset, $limit, $since_id, $before_id, true);
481     }
482
483     function blowFavesCache()
484     {
485         $profile = $this->getProfile();
486         $profile->blowFavesCache();
487     }
488
489     function getSelfTags()
490     {
491         return Profile_tag::getTags($this->id, $this->id);
492     }
493
494     function setSelfTags($newtags)
495     {
496         return Profile_tag::setTags($this->id, $this->id, $newtags);
497     }
498
499     function block($other)
500     {
501         // Add a new block record
502
503         // no blocking (and thus unsubbing from) yourself
504
505         if ($this->id == $other->id) {
506             common_log(LOG_WARNING,
507                 sprintf(
508                     "Profile ID %d (%s) tried to block themself.",
509                     $this->id,
510                     $this->nickname
511                 )
512             );
513             return false;
514         }
515
516         $block = new Profile_block();
517
518         // Begin a transaction
519
520         $block->query('BEGIN');
521
522         $block->blocker = $this->id;
523         $block->blocked = $other->id;
524
525         $result = $block->insert();
526
527         if (!$result) {
528             common_log_db_error($block, 'INSERT', __FILE__);
529             return false;
530         }
531
532         $self = $this->getProfile();
533         if (Subscription::exists($other, $self)) {
534             Subscription::cancel($other, $self);
535         }
536         if (Subscription::exists($self, $other)) {
537             Subscription::cancel($self, $other);
538         }
539
540         $block->query('COMMIT');
541
542         return true;
543     }
544
545     function unblock($other)
546     {
547         // Get the block record
548
549         $block = Profile_block::get($this->id, $other->id);
550
551         if (!$block) {
552             return false;
553         }
554
555         $result = $block->delete();
556
557         if (!$result) {
558             common_log_db_error($block, 'DELETE', __FILE__);
559             return false;
560         }
561
562         return true;
563     }
564
565     function isMember($group)
566     {
567         $profile = $this->getProfile();
568         return $profile->isMember($group);
569     }
570
571     function isAdmin($group)
572     {
573         $profile = $this->getProfile();
574         return $profile->isAdmin($group);
575     }
576
577     function getGroups($offset=0, $limit=null)
578     {
579         $profile = $this->getProfile();
580         return $profile->getGroups($offset, $limit);
581     }
582
583     function getSubscriptions($offset=0, $limit=null)
584     {
585         $profile = $this->getProfile();
586         return $profile->getSubscriptions($offset, $limit);
587     }
588
589     function getSubscribers($offset=0, $limit=null)
590     {
591         $profile = $this->getProfile();
592         return $profile->getSubscribers($offset, $limit);
593     }
594
595     function getTaggedSubscribers($tag, $offset=0, $limit=null)
596     {
597         $qry =
598           'SELECT profile.* ' .
599           'FROM profile JOIN subscription ' .
600           'ON profile.id = subscription.subscriber ' .
601           'JOIN profile_tag ON (profile_tag.tagged = subscription.subscriber ' .
602           'AND profile_tag.tagger = subscription.subscribed) ' .
603           'WHERE subscription.subscribed = %d ' .
604           "AND profile_tag.tag = '%s' " .
605           'AND subscription.subscribed != subscription.subscriber ' .
606           'ORDER BY subscription.created DESC ';
607
608         if ($offset) {
609             $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
610         }
611
612         $profile = new Profile();
613
614         $cnt = $profile->query(sprintf($qry, $this->id, $tag));
615
616         return $profile;
617     }
618
619     function getTaggedSubscriptions($tag, $offset=0, $limit=null)
620     {
621         $qry =
622           'SELECT profile.* ' .
623           'FROM profile JOIN subscription ' .
624           'ON profile.id = subscription.subscribed ' .
625           'JOIN profile_tag on (profile_tag.tagged = subscription.subscribed ' .
626           'AND profile_tag.tagger = subscription.subscriber) ' .
627           'WHERE subscription.subscriber = %d ' .
628           "AND profile_tag.tag = '%s' " .
629           'AND subscription.subscribed != subscription.subscriber ' .
630           'ORDER BY subscription.created DESC ';
631
632         $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
633
634         $profile = new Profile();
635
636         $profile->query(sprintf($qry, $this->id, $tag));
637
638         return $profile;
639     }
640
641     function getDesign()
642     {
643         return Design::staticGet('id', $this->design_id);
644     }
645
646     function hasRight($right)
647     {
648         $profile = $this->getProfile();
649         return $profile->hasRight($right);
650     }
651
652     function delete()
653     {
654         try {
655             $profile = $this->getProfile();
656             $profile->delete();
657         } catch (UserNoProfileException $unp) {
658             common_log(LOG_INFO, "User {$this->nickname} has no profile; continuing deletion.");
659         }
660
661         $related = array('Fave',
662                          'Confirm_address',
663                          'Remember_me',
664                          'Foreign_link',
665                          'Invitation',
666                          );
667
668         Event::handle('UserDeleteRelated', array($this, &$related));
669
670         foreach ($related as $cls) {
671             $inst = new $cls();
672             $inst->user_id = $this->id;
673             $inst->delete();
674         }
675
676         $this->_deleteTags();
677         $this->_deleteBlocks();
678
679         parent::delete();
680     }
681
682     function _deleteTags()
683     {
684         $tag = new Profile_tag();
685         $tag->tagger = $this->id;
686         $tag->delete();
687     }
688
689     function _deleteBlocks()
690     {
691         $block = new Profile_block();
692         $block->blocker = $this->id;
693         $block->delete();
694         // XXX delete group block? Reset blocker?
695     }
696
697     function hasRole($name)
698     {
699         $profile = $this->getProfile();
700         return $profile->hasRole($name);
701     }
702
703     function grantRole($name)
704     {
705         $profile = $this->getProfile();
706         return $profile->grantRole($name);
707     }
708
709     function revokeRole($name)
710     {
711         $profile = $this->getProfile();
712         return $profile->revokeRole($name);
713     }
714
715     function isSandboxed()
716     {
717         $profile = $this->getProfile();
718         return $profile->isSandboxed();
719     }
720
721     function isSilenced()
722     {
723         $profile = $this->getProfile();
724         return $profile->isSilenced();
725     }
726
727     function repeatedByMe($offset=0, $limit=20, $since_id=null, $max_id=null)
728     {
729         $ids = Notice::stream(array($this, '_repeatedByMeDirect'),
730                               array(),
731                               'user:repeated_by_me:'.$this->id,
732                               $offset, $limit, $since_id, $max_id, null);
733
734         return Notice::getStreamByIds($ids);
735     }
736
737     function _repeatedByMeDirect($offset, $limit, $since_id, $max_id)
738     {
739         $notice = new Notice();
740
741         $notice->selectAdd(); // clears it
742         $notice->selectAdd('id');
743
744         $notice->profile_id = $this->id;
745         $notice->whereAdd('repeat_of IS NOT NULL');
746
747         $notice->orderBy('id DESC');
748
749         if (!is_null($offset)) {
750             $notice->limit($offset, $limit);
751         }
752
753         if ($since_id != 0) {
754             $notice->whereAdd('id > ' . $since_id);
755         }
756
757         if ($max_id != 0) {
758             $notice->whereAdd('id <= ' . $max_id);
759         }
760
761         $ids = array();
762
763         if ($notice->find()) {
764             while ($notice->fetch()) {
765                 $ids[] = $notice->id;
766             }
767         }
768
769         $notice->free();
770         $notice = NULL;
771
772         return $ids;
773     }
774
775     function repeatsOfMe($offset=0, $limit=20, $since_id=null, $max_id=null)
776     {
777         $ids = Notice::stream(array($this, '_repeatsOfMeDirect'),
778                               array(),
779                               'user:repeats_of_me:'.$this->id,
780                               $offset, $limit, $since_id, $max_id);
781
782         return Notice::getStreamByIds($ids);
783     }
784
785     function _repeatsOfMeDirect($offset, $limit, $since_id, $max_id)
786     {
787         $qry =
788           'SELECT DISTINCT original.id AS id ' .
789           'FROM notice original JOIN notice rept ON original.id = rept.repeat_of ' .
790           'WHERE original.profile_id = ' . $this->id . ' ';
791
792         if ($since_id != 0) {
793             $qry .= 'AND original.id > ' . $since_id . ' ';
794         }
795
796         if ($max_id != 0) {
797             $qry .= 'AND original.id <= ' . $max_id . ' ';
798         }
799
800         // NOTE: we sort by fave time, not by notice time!
801
802         $qry .= 'ORDER BY original.id DESC ';
803
804         if (!is_null($offset)) {
805             $qry .= "LIMIT $limit OFFSET $offset";
806         }
807
808         $ids = array();
809
810         $notice = new Notice();
811
812         $notice->query($qry);
813
814         while ($notice->fetch()) {
815             $ids[] = $notice->id;
816         }
817
818         $notice->free();
819         $notice = NULL;
820
821         return $ids;
822     }
823
824     function repeatedToMe($offset=0, $limit=20, $since_id=null, $max_id=null)
825     {
826         throw new Exception("Not implemented since inbox change.");
827     }
828
829     function shareLocation()
830     {
831         $cfg = common_config('location', 'share');
832
833         if ($cfg == 'always') {
834             return true;
835         } else if ($cfg == 'never') {
836             return false;
837         } else { // user
838             $share = true;
839
840             $prefs = User_location_prefs::staticGet('user_id', $this->id);
841
842             if (empty($prefs)) {
843                 $share = common_config('location', 'sharedefault');
844             } else {
845                 $share = $prefs->share_location;
846                 $prefs->free();
847             }
848
849             return $share;
850         }
851     }
852
853     static function siteOwner()
854     {
855         $owner = self::cacheGet('user:site_owner');
856
857         if ($owner === false) { // cache miss
858
859             $pr = new Profile_role();
860
861             $pr->role = Profile_role::OWNER;
862
863             $pr->orderBy('created');
864
865             $pr->limit(1);
866
867             if ($pr->find(true)) {
868                 $owner = User::staticGet('id', $pr->profile_id);
869             } else {
870                 $owner = null;
871             }
872
873             self::cacheSet('user:site_owner', $owner);
874         }
875
876         return $owner;
877     }
878 }