function getNoticeIds($offset, $limit, $since_id, $max_id)
 {
     $notice = new Notice();
     $notice->selectAdd();
     // clears it
     $notice->selectAdd('id');
     $notice->orderBy('created DESC, id DESC');
     if (!is_null($offset)) {
         $notice->limit($offset, $limit);
     }
     $notice->whereAdd('is_local =' . Notice::REMOTE);
     // -1 == blacklisted, -2 == gateway (i.e. Twitter)
     $notice->whereAdd('is_local !=' . Notice::LOCAL_NONPUBLIC);
     $notice->whereAdd('is_local !=' . Notice::GATEWAY);
     Notice::addWhereSinceId($notice, $since_id);
     Notice::addWhereMaxId($notice, $max_id);
     if (!empty($this->selectVerbs)) {
         $notice->whereAddIn('verb', $this->selectVerbs, $notice->columnType('verb'));
     }
     $ids = array();
     if ($notice->find()) {
         while ($notice->fetch()) {
             $ids[] = $notice->id;
         }
     }
     $notice->free();
     $notice = NULL;
     return $ids;
 }
 function getNoticeIds($offset, $limit, $since_id = null, $max_id = null)
 {
     $notice = new Notice();
     // SELECT
     $notice->selectAdd();
     $notice->selectAdd('id');
     // WHERE
     $notice->conversation = $this->id;
     if (!empty($since_id)) {
         $notice->whereAdd(sprintf('notice.id > %d', $since_id));
     }
     if (!empty($max_id)) {
         $notice->whereAdd(sprintf('notice.id <= %d', $max_id));
     }
     if (!is_null($offset)) {
         $notice->limit($offset, $limit);
     }
     if (!empty($this->selectVerbs)) {
         $notice->whereAddIn('verb', $this->selectVerbs, $notice->columnType('verb'));
     }
     // ORDER BY
     // currently imitates the previously used "_reverseChron" sorting
     $notice->orderBy('notice.created DESC');
     $notice->find();
     return $notice->fetchAll('id');
 }
Esempio n. 3
0
 function getNoticeIds($offset, $limit, $since_id, $max_id)
 {
     $notice = new Notice();
     $notice->selectAdd();
     // clears it
     $notice->selectAdd('id');
     $notice->orderBy('created DESC, id DESC');
     if (!is_null($offset)) {
         $notice->limit($offset, $limit);
     }
     if (common_config('public', 'localonly')) {
         $notice->whereAdd('is_local = ' . Notice::LOCAL_PUBLIC);
     } else {
         // -1 == blacklisted, -2 == gateway (i.e. Twitter)
         $notice->whereAdd('is_local !=' . Notice::LOCAL_NONPUBLIC);
         $notice->whereAdd('is_local !=' . Notice::GATEWAY);
     }
     Notice::addWhereSinceId($notice, $since_id);
     Notice::addWhereMaxId($notice, $max_id);
     $ids = array();
     if ($notice->find()) {
         while ($notice->fetch()) {
             $ids[] = $notice->id;
         }
     }
     $notice->free();
     $notice = NULL;
     return $ids;
 }
 function getNoticeIds($offset, $limit, $since_id, $max_id)
 {
     $notice = new Notice();
     $notice->selectAdd();
     // clears it
     $notice->selectAdd('id');
     $notice->orderBy('created DESC, id DESC');
     if (!is_null($offset)) {
         $notice->limit($offset, $limit);
     }
     // This feed always gives only local activities.
     $notice->whereAdd('is_local = ' . Notice::LOCAL_PUBLIC);
     Notice::addWhereSinceId($notice, $since_id);
     Notice::addWhereMaxId($notice, $max_id);
     if (!empty($this->selectVerbs)) {
         $notice->whereAddIn('verb', $this->selectVerbs, $notice->columnType('verb'));
     }
     $ids = array();
     if ($notice->find()) {
         while ($notice->fetch()) {
             $ids[] = $notice->id;
         }
     }
     $notice->free();
     $notice = NULL;
     return $ids;
 }
 function getNoticeIds($offset, $limit, $since_id, $max_id)
 {
     $notice = new Notice();
     $notice->selectAdd();
     // clears it
     $notice->selectAdd('id');
     $notice->orderBy('created DESC, id DESC');
     if (!is_null($offset)) {
         $notice->limit($offset, $limit);
     }
     if (common_config('public', 'localonly')) {
         $notice->whereAdd('is_local = ' . Notice::LOCAL_PUBLIC);
     } else {
         // -1 == blacklisted, -2 == gateway (i.e. Twitter)
         $notice->whereAdd('is_local !=' . Notice::LOCAL_NONPUBLIC);
         $notice->whereAdd('is_local !=' . Notice::GATEWAY);
     }
     Notice::addWhereSinceId($notice, $since_id);
     Notice::addWhereMaxId($notice, $max_id);
     $strSql = sprintf('(content_type=%d or content_type=%d)', NOTICE::CONTENT_TYPE_POST, NOTICE::CONTENT_TYPE_REPEAT);
     $strSql = sprintf('(content_type in (%d,%d,%d,%d))', NOTICE::CONTENT_TYPE_REPEAT, NOTICE::CONTENT_TYPE_REPEAT | NOTICE::CONTENT_TYPE_MENTIONS, NOTICE::CONTENT_TYPE_POST, NOTICE::CONTENT_TYPE_POST | NOTICE::CONTENT_TYPE_MENTIONS);
     $notice->whereAdd($strSql);
     $ids = array();
     if ($notice->find()) {
         while ($notice->fetch()) {
             $ids[] = $notice->id;
         }
     }
     $notice->free();
     $notice = NULL;
     return $ids;
 }
Esempio n. 6
0
 function getNotices($y, $m, $d, $i)
 {
     $n = Notice::cacheGet("sitemap:notice:{$y}:{$m}:{$d}:{$i}");
     if ($n === false) {
         $notice = new Notice();
         $begindt = sprintf('%04d-%02d-%02d 00:00:00', $y, $m, $d);
         // XXX: estimates 1d == 24h, which screws up days
         // with leap seconds (1d == 24h + 1s). Thankfully they're
         // few and far between.
         $theend = strtotime($begindt) + 24 * 60 * 60;
         $enddt = common_sql_date($theend);
         $notice->selectAdd();
         $notice->selectAdd('id, created');
         $notice->whereAdd("created >= '{$begindt}'");
         $notice->whereAdd("created <  '{$enddt}'");
         $notice->whereAdd('is_local = ' . Notice::LOCAL_PUBLIC);
         $notice->orderBy('created');
         $offset = ($i - 1) * SitemapPlugin::NOTICES_PER_MAP;
         $limit = SitemapPlugin::NOTICES_PER_MAP;
         $notice->limit($offset, $limit);
         $notice->find();
         $n = array();
         while ($notice->fetch()) {
             $n[] = array($notice->id, $notice->created);
         }
         $c = Cache::instance();
         if (!empty($c)) {
             $c->set(Cache::key("sitemap:notice:{$y}:{$m}:{$d}:{$i}"), $n, Cache::COMPRESSED, time() > $theend ? time() + 90 * 24 * 60 * 60 : time() + 5 * 60);
         }
     }
     return $n;
 }
 function getNoticeIds($offset, $limit, $since_id, $max_id)
 {
     $notice = new Notice();
     $notice->profile_id = $this->profile->id;
     $notice->selectAdd();
     $notice->selectAdd('id');
     Notice::addWhereSinceId($notice, $since_id);
     Notice::addWhereMaxId($notice, $max_id);
     $notice->orderBy('created DESC, id DESC');
     if (!is_null($offset)) {
         $notice->limit($offset, $limit);
     }
     $notice->find();
     $ids = array();
     while ($notice->fetch()) {
         $ids[] = $notice->id;
     }
     return $ids;
 }
 function getNotices()
 {
     $notice = new Notice();
     $notice->joinAdd(array('id', 'file_to_post:post_id'));
     $notice->whereAdd(sprintf('file_to_post.file_id = %d', $this->out->attachment->id));
     $notice->orderBy('created desc');
     $notice->selectAdd('post_id as id');
     $notice->find();
     return $notice;
 }
Esempio n. 9
0
 function getNotices()
 {
     $notice = new Notice();
     $f2p = new File_to_post();
     $f2p->file_id = $this->out->attachment->id;
     $notice->joinAdd($f2p);
     $notice->orderBy('created desc');
     $notice->selectAdd('post_id as id');
     $notice->find();
     return $notice;
 }
 function getNoticeIds($offset, $limit, $since_id, $max_id)
 {
     $notice = new Notice();
     $notice->selectAdd();
     $notice->selectAdd('id');
     $notice->orderBy('id DESC');
     if (!is_null($offset)) {
         $notice->limit($offset, $limit);
     }
     $notice->whereAdd('is_local !=' . Notice::LOCAL_NONPUBLIC);
     $notice->whereAdd('is_local !=' . Notice::GATEWAY);
     $notice->whereAdd('repeat_of IS NULL');
     Notice::addWhereSinceId($notice, $since_id);
     Notice::addWhereMaxId($notice, $max_id);
     $ids = array();
     if ($notice->find()) {
         while ($notice->fetch()) {
             $ids[] = $notice->id;
         }
     }
     $notice->free();
     $notice = NULL;
     return $ids;
 }
Esempio n. 11
0
function initInbox()
{
    printfnq("Ensuring all users have an inbox...");
    $user = new User();
    $user->whereAdd('not exists (select user_id from inbox where user_id = user.id)');
    $user->orderBy('id');
    if ($user->find()) {
        while ($user->fetch()) {
            try {
                $notice = new Notice();
                $notice->selectAdd();
                $notice->selectAdd('id');
                $notice->joinAdd(array('profile_id', 'subscription:subscribed'));
                $notice->whereAdd('subscription.subscriber = ' . $user->id);
                $notice->whereAdd('notice.created >= subscription.created');
                $ids = array();
                if ($notice->find()) {
                    while ($notice->fetch()) {
                        $ids[] = $notice->id;
                    }
                }
                $notice = null;
                $inbox = new Inbox();
                $inbox->user_id = $user->id;
                $inbox->pack($ids);
                $inbox->insert();
            } catch (Exception $e) {
                printv("Error initializing inbox: " . $e->getMessage());
            }
        }
    }
    printfnq("DONE.\n");
}
Esempio n. 12
0
 function _repeatStreamDirect($limit)
 {
     $notice = new Notice();
     $notice->selectAdd();
     // clears it
     $notice->selectAdd('id');
     $notice->repeat_of = $this->id;
     $notice->orderBy('created, id');
     // NB: asc!
     if (!is_null($limit)) {
         $notice->limit(0, $limit);
     }
     return $notice->fetchAll('id');
 }
 function getNoticeIds($offset, $limit, $since_id, $max_id)
 {
     $notice = new Notice();
     $notice->profile_id = $this->profile->id;
     $notice->selectAdd();
     $notice->selectAdd('id');
     Notice::addWhereSinceId($notice, $since_id);
     Notice::addWhereMaxId($notice, $max_id);
     $strSql = sprintf('(content_type in (%d,%d,%d,%d))', NOTICE::CONTENT_TYPE_REPEAT, NOTICE::CONTENT_TYPE_REPEAT | NOTICE::CONTENT_TYPE_MENTIONS, NOTICE::CONTENT_TYPE_POST, NOTICE::CONTENT_TYPE_POST | NOTICE::CONTENT_TYPE_MENTIONS);
     $notice->whereAdd($strSql);
     $notice->orderBy('created DESC, id DESC');
     if (!is_null($offset)) {
         $notice->limit($offset, $limit);
     }
     $notice->find();
     $ids = array();
     while ($notice->fetch()) {
         $ids[] = $notice->id;
     }
     return $ids;
 }
Esempio n. 14
0
 /**
  * Handle the request
  *
  * Check the format and show the user info
  *
  * @param array $args $_REQUEST data (unused)
  *
  * @return void
  */
 protected function handle()
 {
     parent::handle();
     // favs
     $fave = new Fave();
     $fave->selectAdd();
     $fave->selectAdd('user_id');
     $fave->selectAdd('modified');
     $fave->notice_id = $this->original->id;
     $fave->orderBy('modified');
     if (!is_null($this->cnt)) {
         $fave->limit(0, $this->cnt);
     }
     $fav_ids = $fave->fetchAll('user_id', 'modified');
     // get nickname and profile image
     $fav_ids_with_profile_data = array();
     $i = 0;
     foreach ($fav_ids as $id => $time) {
         $profile = Profile::getKV('id', $id);
         $fav_ids_with_profile_data[$i]['user_id'] = $id;
         $fav_ids_with_profile_data[$i]['nickname'] = $profile->nickname;
         $fav_ids_with_profile_data[$i]['fullname'] = $profile->fullname;
         $fav_ids_with_profile_data[$i]['profileurl'] = $profile->profileurl;
         $fav_ids_with_profile_data[$i]['time'] = strtotime($time);
         $profile = new Profile();
         $profile->id = $id;
         $avatarurl = $profile->avatarUrl(48);
         $fav_ids_with_profile_data[$i]['avatarurl'] = $avatarurl;
         $i++;
     }
     // repeats
     $notice = new Notice();
     $notice->selectAdd();
     // clears it
     $notice->selectAdd('profile_id');
     $notice->selectAdd('created');
     $notice->repeat_of = $this->original->id;
     $notice->orderBy('created, id');
     // NB: asc!
     if (!is_null($this->cnt)) {
         $notice->limit(0, $this->cnt);
     }
     $repeat_ids = $notice->fetchAll('profile_id', 'created');
     // get nickname and profile image
     $repeat_ids_with_profile_data = array();
     $i = 0;
     foreach ($repeat_ids as $id => $time) {
         $profile = Profile::getKV('id', $id);
         $repeat_ids_with_profile_data[$i]['user_id'] = $id;
         $repeat_ids_with_profile_data[$i]['nickname'] = $profile->nickname;
         $repeat_ids_with_profile_data[$i]['fullname'] = $profile->fullname;
         $repeat_ids_with_profile_data[$i]['profileurl'] = $profile->profileurl;
         $repeat_ids_with_profile_data[$i]['time'] = strtotime($time);
         $profile = new Profile();
         $profile->id = $id;
         $avatarurl = $profile->avatarUrl(48);
         $repeat_ids_with_profile_data[$i]['avatarurl'] = $avatarurl;
         $i++;
     }
     $favs_and_repeats = array('favs' => $fav_ids_with_profile_data, 'repeats' => $repeat_ids_with_profile_data);
     $this->initDocument('json');
     $this->showJsonObjects($favs_and_repeats);
     $this->endDocument('json');
 }
 static function getFirstDate()
 {
     $n = new Notice();
     $n->selectAdd();
     $n->selectAdd('date(min(created)) as first_date');
     if ($n->find(true)) {
         return $n->first_date;
     } else {
         // Is this right?
         return self::dateIntToStr(time());
     }
 }
Esempio n. 16
0
 function _repeatedByMeDirect($offset, $limit, $since_id, $max_id)
 {
     $notice = new Notice();
     $notice->selectAdd();
     // clears it
     $notice->selectAdd('id');
     $notice->profile_id = $this->id;
     $notice->whereAdd('repeat_of IS NOT NULL');
     $notice->orderBy('id DESC');
     if (!is_null($offset)) {
         $notice->limit($offset, $limit);
     }
     if ($since_id != 0) {
         $notice->whereAdd('id > ' . $since_id);
     }
     if ($max_id != 0) {
         $notice->whereAdd('id <= ' . $max_id);
     }
     $ids = array();
     if ($notice->find()) {
         while ($notice->fetch()) {
             $ids[] = $notice->id;
         }
     }
     $notice->free();
     $notice = NULL;
     return $ids;
 }
 /**
  * Query notices by users associated with this tag from the database.
  *
  * @param integer $offset   offset
  * @param integer $limit    maximum no of results
  * @param integer $since_id=null    since this id
  * @param integer $max_id=null  maximum id in result
  *
  * @return array array of notice ids.
  */
 function getNoticeIds($offset, $limit, $since_id, $max_id)
 {
     $notice = new Notice();
     $notice->selectAdd();
     $notice->selectAdd('notice.id');
     $ptag = new Profile_tag();
     $ptag->tag = $this->profile_list->tag;
     $ptag->tagger = $this->profile_list->tagger;
     $notice->joinAdd(array('profile_id', 'profile_tag:tagged'));
     $notice->whereAdd('profile_tag.tagger = ' . $this->profile_list->tagger);
     $notice->whereAdd(sprintf('profile_tag.tag = "%s"', $this->profile_list->tag));
     if ($since_id != 0) {
         $notice->whereAdd('notice.id > ' . $since_id);
     }
     if ($max_id != 0) {
         $notice->whereAdd('notice.id <= ' . $max_id);
     }
     $notice->orderBy('notice.id DESC');
     if (!is_null($offset)) {
         $notice->limit($offset, $limit);
     }
     $ids = array();
     if ($notice->find()) {
         while ($notice->fetch()) {
             $ids[] = $notice->id;
         }
     }
     return $ids;
 }
Esempio n. 18
0
 function _streamDirect($offset, $limit, $since_id, $max_id)
 {
     $notice = new Notice();
     // Temporary hack until notice_profile_id_idx is updated
     // to (profile_id, id) instead of (profile_id, created, id).
     // It's been falling back to PRIMARY instead, which is really
     // very inefficient for a profile that hasn't posted in a few
     // months. Even though forcing the index will cause a filesort,
     // it's usually going to be better.
     if (common_config('db', 'type') == 'mysql') {
         $index = '';
         $query = "select id from notice force index (notice_profile_id_idx) " . "where profile_id=" . $notice->escape($this->id);
         if ($since_id != 0) {
             $query .= " and id > {$since_id}";
         }
         if ($max_id != 0) {
             $query .= " and id < {$max_id}";
         }
         $query .= ' order by id DESC';
         if (!is_null($offset)) {
             $query .= " LIMIT {$limit} OFFSET {$offset}";
         }
         $notice->query($query);
     } else {
         $index = '';
         $notice->profile_id = $this->id;
         $notice->selectAdd();
         $notice->selectAdd('id');
         if ($since_id != 0) {
             $notice->whereAdd('id > ' . $since_id);
         }
         if ($max_id != 0) {
             $notice->whereAdd('id <= ' . $max_id);
         }
         $notice->orderBy('id DESC');
         if (!is_null($offset)) {
             $notice->limit($offset, $limit);
         }
         $notice->find();
     }
     $ids = array();
     while ($notice->fetch()) {
         $ids[] = $notice->id;
     }
     return $ids;
 }
 /**
  * Handle the request
  *
  * Check the format and show the user info
  *
  * @param array $args $_REQUEST data (unused)
  *
  * @return void
  */
 protected function handle()
 {
     parent::handle();
     // since this api method is in practice only used when expanding a
     // notice, we can assume the user has seen the notice in question,
     // an no longer need a notification about it. mark reply/mention-
     // notifications tied to this notice and the current profile as read
     if ($this->auth_user) {
         QvitterPlugin::markNotificationAsSeen($this->notice_id, $this->auth_user->id, 'mention');
         QvitterPlugin::markNotificationAsSeen($this->notice_id, $this->auth_user->id, 'reply');
     }
     // favs
     $fave = new Fave();
     $fave->selectAdd();
     $fave->selectAdd('user_id');
     $fave->selectAdd('modified');
     $fave->notice_id = $this->original->id;
     $fave->orderBy('modified');
     if (!is_null($this->cnt)) {
         $fave->limit(0, $this->cnt);
     }
     $fav_ids = $fave->fetchAll('user_id', 'modified');
     // get nickname and profile image
     $fav_ids_with_profile_data = array();
     $i = 0;
     foreach ($fav_ids as $id => $time) {
         $profile = Profile::getKV('id', $id);
         $fav_ids_with_profile_data[$i]['user_id'] = $id;
         $fav_ids_with_profile_data[$i]['nickname'] = $profile->nickname;
         $fav_ids_with_profile_data[$i]['fullname'] = $profile->fullname;
         $fav_ids_with_profile_data[$i]['profileurl'] = $profile->profileurl;
         $fav_ids_with_profile_data[$i]['time'] = strtotime($time);
         $profile = new Profile();
         $profile->id = $id;
         $avatarurl = $profile->avatarUrl(48);
         $fav_ids_with_profile_data[$i]['avatarurl'] = $avatarurl;
         $i++;
     }
     // repeats
     $notice = new Notice();
     $notice->selectAdd();
     // clears it
     $notice->selectAdd('profile_id');
     $notice->selectAdd('created');
     $notice->repeat_of = $this->original->id;
     $notice->verb = ActivityVerb::SHARE;
     $notice->orderBy('created, id');
     // NB: asc!
     if (!is_null($this->cnt)) {
         $notice->limit(0, $this->cnt);
     }
     $repeat_ids = $notice->fetchAll('profile_id', 'created');
     // get nickname and profile image
     $repeat_ids_with_profile_data = array();
     $i = 0;
     foreach ($repeat_ids as $id => $time) {
         $profile = Profile::getKV('id', $id);
         $repeat_ids_with_profile_data[$i]['user_id'] = $id;
         $repeat_ids_with_profile_data[$i]['nickname'] = $profile->nickname;
         $repeat_ids_with_profile_data[$i]['fullname'] = $profile->fullname;
         $repeat_ids_with_profile_data[$i]['profileurl'] = $profile->profileurl;
         $repeat_ids_with_profile_data[$i]['time'] = strtotime($time);
         $profile = new Profile();
         $profile->id = $id;
         $avatarurl = $profile->avatarUrl(48);
         $repeat_ids_with_profile_data[$i]['avatarurl'] = $avatarurl;
         $i++;
     }
     $favs_and_repeats = array('favs' => $fav_ids_with_profile_data, 'repeats' => $repeat_ids_with_profile_data);
     $this->initDocument('json');
     $this->showJsonObjects($favs_and_repeats);
     $this->endDocument('json');
 }
 /**
  * Get IDs in a range
  *
  * @param int $offset   Offset from start
  * @param int $limit    Limit of number to get
  * @param int $since_id Since this notice
  * @param int $max_id   Before this notice
  *
  * @return Array IDs found
  */
 function getNoticeIds($offset, $limit, $since_id, $max_id)
 {
     $notice = new Notice();
     $notice->selectAdd();
     $notice->selectAdd('id');
     $notice->whereAdd(sprintf('notice.created > "%s"', $notice->escape($this->target->created)));
     // Reply:: is a table of mentions
     // Subscription:: is a table of subscriptions (every user is subscribed to themselves)
     $notice->whereAdd(sprintf('(  notice.profile_id IN (SELECT subscribed FROM subscription WHERE subscriber=%1$d) ' . 'OR notice.id IN (SELECT notice_id FROM group_inbox WHERE group_id IN (SELECT group_id FROM group_member WHERE profile_id=%1$d))' . 'OR notice.id IN (SELECT notice_id FROM attention WHERE profile_id=%1$d) ) ' . 'AND (notice.reply_to IS NULL ' . 'OR notice.profile_id=%1$d ' . 'OR notice.reply_to IN (SELECT id FROM notice as noticereplies WHERE noticereplies.profile_id IN (SELECT subscribed FROM subscription WHERE subscriber=%1$d))) ' . 'OR (notice.id IN (SELECT notice_id FROM reply WHERE profile_id=%1$d) ' . 'AND notice.profile_id IN (SELECT subscribed FROM subscription WHERE subscriber=%1$d))', $this->target->id));
     if (!empty($since_id)) {
         $notice->whereAdd(sprintf('notice.id > %d', $since_id));
     }
     if (!empty($max_id)) {
         $notice->whereAdd(sprintf('notice.id <= %d', $max_id));
     }
     if (!empty($this->selectVerbs)) {
         $notice->whereAddIn('verb', $this->selectVerbs, $notice->columnType('verb'));
     }
     $notice->limit($offset, $limit);
     // notice.id will give us even really old posts, which were
     // recently imported. For example if a remote instance had
     // problems and just managed to post here. Another solution
     // would be to have a 'notice.imported' field and order by it.
     $notice->orderBy('notice.id DESC');
     if (!$notice->find()) {
         return array();
     }
     $ids = $notice->fetchAll('id');
     return $ids;
 }
Esempio n. 21
0
 function _repeatStreamDirect($limit)
 {
     $notice = new Notice();
     $notice->selectAdd();
     // clears it
     $notice->selectAdd('id');
     $notice->repeat_of = $this->id;
     $notice->orderBy('created');
     // NB: asc!
     if (!is_null($offset)) {
         $notice->limit($offset, $limit);
     }
     $ids = array();
     if ($notice->find()) {
         while ($notice->fetch()) {
             $ids[] = $notice->id;
         }
     }
     $notice->free();
     $notice = NULL;
     return $ids;
 }