]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/User.php
2c256301c2f2d94a1cc36f4b079e9dd71b4352fc
[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         $user->created = common_sql_now();
259
260         if (Event::handle('StartUserRegister', array(&$user, &$profile))) {
261
262             $profile->query('BEGIN');
263
264             $id = $profile->insert();
265
266             if (empty($id)) {
267                 common_log_db_error($profile, 'INSERT', __FILE__);
268                 return false;
269             }
270
271             $user->id = $id;
272             $user->uri = common_user_uri($user);
273             if (!empty($password)) { // may not have a password for OpenID users
274                 $user->password = common_munge_password($password, $id);
275             }
276
277             $result = $user->insert();
278
279             if (!$result) {
280                 common_log_db_error($user, 'INSERT', __FILE__);
281                 return false;
282             }
283
284             // Everyone gets an inbox
285
286             $inbox = new Inbox();
287
288             $inbox->user_id = $user->id;
289             $inbox->notice_ids = '';
290
291             $result = $inbox->insert();
292
293             if (!$result) {
294                 common_log_db_error($inbox, 'INSERT', __FILE__);
295                 return false;
296             }
297
298             // Everyone is subscribed to themself
299
300             $subscription = new Subscription();
301             $subscription->subscriber = $user->id;
302             $subscription->subscribed = $user->id;
303             $subscription->created = $user->created;
304
305             $result = $subscription->insert();
306
307             if (!$result) {
308                 common_log_db_error($subscription, 'INSERT', __FILE__);
309                 return false;
310             }
311
312             if (!empty($email) && !$user->email) {
313
314                 $confirm = new Confirm_address();
315                 $confirm->code = common_confirmation_code(128);
316                 $confirm->user_id = $user->id;
317                 $confirm->address = $email;
318                 $confirm->address_type = 'email';
319
320                 $result = $confirm->insert();
321
322                 if (!$result) {
323                     common_log_db_error($confirm, 'INSERT', __FILE__);
324                     return false;
325                 }
326             }
327
328             if (!empty($code) && $user->email) {
329                 $user->emailChanged();
330             }
331
332             // Default system subscription
333
334             $defnick = common_config('newuser', 'default');
335
336             if (!empty($defnick)) {
337                 $defuser = User::staticGet('nickname', $defnick);
338                 if (empty($defuser)) {
339                     common_log(LOG_WARNING, sprintf("Default user %s does not exist.", $defnick),
340                                __FILE__);
341                 } else {
342                     Subscription::start($user, $defuser);
343                 }
344             }
345
346             $profile->query('COMMIT');
347
348             if (!empty($email) && !$user->email) {
349                 mail_confirm_address($user, $confirm->code, $profile->nickname, $email);
350             }
351
352             // Welcome message
353
354             $welcome = common_config('newuser', 'welcome');
355
356             if (!empty($welcome)) {
357                 $welcomeuser = User::staticGet('nickname', $welcome);
358                 if (empty($welcomeuser)) {
359                     common_log(LOG_WARNING, sprintf("Welcome user %s does not exist.", $defnick),
360                                __FILE__);
361                 } else {
362                     $notice = Notice::saveNew($welcomeuser->id,
363                                               sprintf(_('Welcome to %1$s, @%2$s!'),
364                                                       common_config('site', 'name'),
365                                                       $user->nickname),
366                                               'system');
367
368                 }
369             }
370
371             Event::handle('EndUserRegister', array(&$profile, &$user));
372         }
373
374         return $user;
375     }
376
377     // Things we do when the email changes
378
379     function emailChanged()
380     {
381
382         $invites = new Invitation();
383         $invites->address = $this->email;
384         $invites->address_type = 'email';
385
386         if ($invites->find()) {
387             while ($invites->fetch()) {
388                 $other = User::staticGet($invites->user_id);
389                 subs_subscribe_to($other, $this);
390             }
391         }
392     }
393
394     function hasFave($notice)
395     {
396         $cache = common_memcache();
397
398         // XXX: Kind of a hack.
399
400         if ($cache) {
401             // This is the stream of favorite notices, in rev chron
402             // order. This forces it into cache.
403
404             $ids = Fave::stream($this->id, 0, NOTICE_CACHE_WINDOW);
405
406             // If it's in the list, then it's a fave
407
408             if (in_array($notice->id, $ids)) {
409                 return true;
410             }
411
412             // If we're not past the end of the cache window,
413             // then the cache has all available faves, so this one
414             // is not a fave.
415
416             if (count($ids) < NOTICE_CACHE_WINDOW) {
417                 return false;
418             }
419
420             // Otherwise, cache doesn't have all faves;
421             // fall through to the default
422         }
423
424         $fave = Fave::pkeyGet(array('user_id' => $this->id,
425                                     'notice_id' => $notice->id));
426         return ((is_null($fave)) ? false : true);
427     }
428
429     function mutuallySubscribed($other)
430     {
431         return $this->isSubscribed($other) &&
432           $other->isSubscribed($this);
433     }
434
435     function mutuallySubscribedUsers()
436     {
437         // 3-way join; probably should get cached
438         $UT = common_config('db','type')=='pgsql'?'"user"':'user';
439         $qry = "SELECT $UT.* " .
440           "FROM subscription sub1 JOIN $UT ON sub1.subscribed = $UT.id " .
441           "JOIN subscription sub2 ON $UT.id = sub2.subscriber " .
442           'WHERE sub1.subscriber = %d and sub2.subscribed = %d ' .
443           "ORDER BY $UT.nickname";
444         $user = new User();
445         $user->query(sprintf($qry, $this->id, $this->id));
446
447         return $user;
448     }
449
450     function getReplies($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
451     {
452         $ids = Reply::stream($this->id, $offset, $limit, $since_id, $before_id);
453         return Notice::getStreamByIds($ids);
454     }
455
456     function getTaggedNotices($tag, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0) {
457         $profile = $this->getProfile();
458         return $profile->getTaggedNotices($tag, $offset, $limit, $since_id, $before_id);
459     }
460
461     function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
462     {
463         $profile = $this->getProfile();
464         return $profile->getNotices($offset, $limit, $since_id, $before_id);
465     }
466
467     function favoriteNotices($offset=0, $limit=NOTICES_PER_PAGE, $own=false)
468     {
469         $ids = Fave::stream($this->id, $offset, $limit, $own);
470         return Notice::getStreamByIds($ids);
471     }
472
473     function noticesWithFriends($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 noticeInbox($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 friendsTimeline($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, false);
486     }
487
488     function ownFriendsTimeline($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
489     {
490         return Inbox::streamNotices($this->id, $offset, $limit, $since_id, $before_id, true);
491     }
492
493     function blowFavesCache()
494     {
495         $cache = common_memcache();
496         if ($cache) {
497             // Faves don't happen chronologically, so we need to blow
498             // ;last cache, too
499             $cache->delete(common_cache_key('fave:ids_by_user:'.$this->id));
500             $cache->delete(common_cache_key('fave:ids_by_user:'.$this->id.';last'));
501             $cache->delete(common_cache_key('fave:ids_by_user_own:'.$this->id));
502             $cache->delete(common_cache_key('fave:ids_by_user_own:'.$this->id.';last'));
503         }
504         $profile = $this->getProfile();
505         $profile->blowFaveCount();
506     }
507
508     function getSelfTags()
509     {
510         return Profile_tag::getTags($this->id, $this->id);
511     }
512
513     function setSelfTags($newtags)
514     {
515         return Profile_tag::setTags($this->id, $this->id, $newtags);
516     }
517
518     function block($other)
519     {
520         // Add a new block record
521
522         // no blocking (and thus unsubbing from) yourself
523
524         if ($this->id == $other->id) {
525             common_log(LOG_WARNING,
526                 sprintf(
527                     "Profile ID %d (%s) tried to block his or herself.",
528                     $this->id,
529                     $this->nickname
530                 )
531             );
532             return false;
533         }
534
535         $block = new Profile_block();
536
537         // Begin a transaction
538
539         $block->query('BEGIN');
540
541         $block->blocker = $this->id;
542         $block->blocked = $other->id;
543
544         $result = $block->insert();
545
546         if (!$result) {
547             common_log_db_error($block, 'INSERT', __FILE__);
548             return false;
549         }
550
551         Subscription::cancel($other, $this->getProfile());
552
553         $block->query('COMMIT');
554
555         return true;
556     }
557
558     function unblock($other)
559     {
560         // Get the block record
561
562         $block = Profile_block::get($this->id, $other->id);
563
564         if (!$block) {
565             return false;
566         }
567
568         $result = $block->delete();
569
570         if (!$result) {
571             common_log_db_error($block, 'DELETE', __FILE__);
572             return false;
573         }
574
575         return true;
576     }
577
578     function isMember($group)
579     {
580         $profile = $this->getProfile();
581         return $profile->isMember($group);
582     }
583
584     function isAdmin($group)
585     {
586         $profile = $this->getProfile();
587         return $profile->isAdmin($group);
588     }
589
590     function getGroups($offset=0, $limit=null)
591     {
592         $profile = $this->getProfile();
593         return $profile->getGroups($offset, $limit);
594     }
595
596     function getSubscriptions($offset=0, $limit=null)
597     {
598         $profile = $this->getProfile();
599         return $profile->getSubscriptions($offset, $limit);
600     }
601
602     function getSubscribers($offset=0, $limit=null)
603     {
604         $profile = $this->getProfile();
605         return $profile->getSubscribers($offset, $limit);
606     }
607
608     function getTaggedSubscribers($tag, $offset=0, $limit=null)
609     {
610         $qry =
611           'SELECT profile.* ' .
612           'FROM profile JOIN subscription ' .
613           'ON profile.id = subscription.subscriber ' .
614           'JOIN profile_tag ON (profile_tag.tagged = subscription.subscriber ' .
615           'AND profile_tag.tagger = subscription.subscribed) ' .
616           'WHERE subscription.subscribed = %d ' .
617           "AND profile_tag.tag = '%s' " .
618           'AND subscription.subscribed != subscription.subscriber ' .
619           'ORDER BY subscription.created DESC ';
620
621         if ($offset) {
622             $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
623         }
624
625         $profile = new Profile();
626
627         $cnt = $profile->query(sprintf($qry, $this->id, $tag));
628
629         return $profile;
630     }
631
632     function getTaggedSubscriptions($tag, $offset=0, $limit=null)
633     {
634         $qry =
635           'SELECT profile.* ' .
636           'FROM profile JOIN subscription ' .
637           'ON profile.id = subscription.subscribed ' .
638           'JOIN profile_tag on (profile_tag.tagged = subscription.subscribed ' .
639           'AND profile_tag.tagger = subscription.subscriber) ' .
640           'WHERE subscription.subscriber = %d ' .
641           "AND profile_tag.tag = '%s' " .
642           'AND subscription.subscribed != subscription.subscriber ' .
643           'ORDER BY subscription.created DESC ';
644
645         $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
646
647         $profile = new Profile();
648
649         $profile->query(sprintf($qry, $this->id, $tag));
650
651         return $profile;
652     }
653
654     function getDesign()
655     {
656         return Design::staticGet('id', $this->design_id);
657     }
658
659     function hasRight($right)
660     {
661         $profile = $this->getProfile();
662         return $profile->hasRight($right);
663     }
664
665     function delete()
666     {
667         try {
668             $profile = $this->getProfile();
669             $profile->delete();
670         } catch (UserNoProfileException $unp) {
671             common_log(LOG_INFO, "User {$this->nickname} has no profile; continuing deletion.");
672         }
673
674         $related = array('Fave',
675                          'Confirm_address',
676                          'Remember_me',
677                          'Foreign_link',
678                          'Invitation',
679                          );
680
681         Event::handle('UserDeleteRelated', array($this, &$related));
682
683         foreach ($related as $cls) {
684             $inst = new $cls();
685             $inst->user_id = $this->id;
686             $inst->delete();
687         }
688
689         $this->_deleteTags();
690         $this->_deleteBlocks();
691
692         parent::delete();
693     }
694
695     function _deleteTags()
696     {
697         $tag = new Profile_tag();
698         $tag->tagger = $this->id;
699         $tag->delete();
700     }
701
702     function _deleteBlocks()
703     {
704         $block = new Profile_block();
705         $block->blocker = $this->id;
706         $block->delete();
707         // XXX delete group block? Reset blocker?
708     }
709
710     function hasRole($name)
711     {
712         $profile = $this->getProfile();
713         return $profile->hasRole($name);
714     }
715
716     function grantRole($name)
717     {
718         $profile = $this->getProfile();
719         return $profile->grantRole($name);
720     }
721
722     function revokeRole($name)
723     {
724         $profile = $this->getProfile();
725         return $profile->revokeRole($name);
726     }
727
728     function isSandboxed()
729     {
730         $profile = $this->getProfile();
731         return $profile->isSandboxed();
732     }
733
734     function isSilenced()
735     {
736         $profile = $this->getProfile();
737         return $profile->isSilenced();
738     }
739
740     function repeatedByMe($offset=0, $limit=20, $since_id=null, $max_id=null)
741     {
742         $ids = Notice::stream(array($this, '_repeatedByMeDirect'),
743                               array(),
744                               'user:repeated_by_me:'.$this->id,
745                               $offset, $limit, $since_id, $max_id, null);
746
747         return Notice::getStreamByIds($ids);
748     }
749
750     function _repeatedByMeDirect($offset, $limit, $since_id, $max_id)
751     {
752         $notice = new Notice();
753
754         $notice->selectAdd(); // clears it
755         $notice->selectAdd('id');
756
757         $notice->profile_id = $this->id;
758         $notice->whereAdd('repeat_of IS NOT NULL');
759
760         $notice->orderBy('id DESC');
761
762         if (!is_null($offset)) {
763             $notice->limit($offset, $limit);
764         }
765
766         if ($since_id != 0) {
767             $notice->whereAdd('id > ' . $since_id);
768         }
769
770         if ($max_id != 0) {
771             $notice->whereAdd('id <= ' . $max_id);
772         }
773
774         $ids = array();
775
776         if ($notice->find()) {
777             while ($notice->fetch()) {
778                 $ids[] = $notice->id;
779             }
780         }
781
782         $notice->free();
783         $notice = NULL;
784
785         return $ids;
786     }
787
788     function repeatsOfMe($offset=0, $limit=20, $since_id=null, $max_id=null)
789     {
790         $ids = Notice::stream(array($this, '_repeatsOfMeDirect'),
791                               array(),
792                               'user:repeats_of_me:'.$this->id,
793                               $offset, $limit, $since_id, $max_id);
794
795         return Notice::getStreamByIds($ids);
796     }
797
798     function _repeatsOfMeDirect($offset, $limit, $since_id, $max_id)
799     {
800         $qry =
801           'SELECT DISTINCT original.id AS id ' .
802           'FROM notice original JOIN notice rept ON original.id = rept.repeat_of ' .
803           'WHERE original.profile_id = ' . $this->id . ' ';
804
805         if ($since_id != 0) {
806             $qry .= 'AND original.id > ' . $since_id . ' ';
807         }
808
809         if ($max_id != 0) {
810             $qry .= 'AND original.id <= ' . $max_id . ' ';
811         }
812
813         // NOTE: we sort by fave time, not by notice time!
814
815         $qry .= 'ORDER BY original.id DESC ';
816
817         if (!is_null($offset)) {
818             $qry .= "LIMIT $limit OFFSET $offset";
819         }
820
821         $ids = array();
822
823         $notice = new Notice();
824
825         $notice->query($qry);
826
827         while ($notice->fetch()) {
828             $ids[] = $notice->id;
829         }
830
831         $notice->free();
832         $notice = NULL;
833
834         return $ids;
835     }
836
837     function repeatedToMe($offset=0, $limit=20, $since_id=null, $max_id=null)
838     {
839         throw new Exception("Not implemented since inbox change.");
840     }
841
842     function shareLocation()
843     {
844         $cfg = common_config('location', 'share');
845
846         if ($cfg == 'always') {
847             return true;
848         } else if ($cfg == 'never') {
849             return false;
850         } else { // user
851             $share = true;
852
853             $prefs = User_location_prefs::staticGet('user_id', $this->id);
854
855             if (empty($prefs)) {
856                 $share = common_config('location', 'sharedefault');
857             } else {
858                 $share = $prefs->share_location;
859                 $prefs->free();
860             }
861
862             return $share;
863         }
864     }
865
866     static function siteOwner()
867     {
868         $owner = self::cacheGet('user:site_owner');
869
870         if ($owner === false) { // cache miss
871
872             $pr = new Profile_role();
873
874             $pr->role = Profile_role::OWNER;
875
876             $pr->orderBy('created');
877
878             $pr->limit(1);
879
880             if ($pr->find(true)) {
881                 $owner = User::staticGet('id', $pr->profile_id);
882             } else {
883                 $owner = null;
884             }
885
886             self::cacheSet('user:site_owner', $owner);
887         }
888
889         return $owner;
890     }
891 }