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