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');
 }
 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. 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);
     }
     $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;
 }
Esempio n. 5
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->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;
 }
 static function getStreamByIds($ids)
 {
     $cache = Cache::instance();
     if (!empty($cache)) {
         $notices = array();
         foreach ($ids as $id) {
             $n = Notice::staticGet('id', $id);
             if (!empty($n)) {
                 $notices[] = $n;
             }
         }
         return new ArrayWrapper($notices);
     } else {
         $notice = new Notice();
         if (empty($ids)) {
             //if no IDs requested, just return the notice object
             return $notice;
         }
         $notice->whereAdd('id in (' . implode(', ', $ids) . ')');
         $notice->find();
         $temp = array();
         while ($notice->fetch()) {
             $temp[$notice->id] = clone $notice;
         }
         $wrapped = array();
         foreach ($ids as $id) {
             if (array_key_exists($id, $temp)) {
                 $wrapped[] = $temp[$id];
             }
         }
         return new ArrayWrapper($wrapped);
     }
 }
 /**
  * For initializing members of the class.
  *
  * @param array $argarray misc. arguments
  *
  * @return boolean true
  */
 function prepare($argarray)
 {
     parent::prepare($argarray);
     $convId = $this->trimmed('id');
     if (empty($convId)) {
         // TRANS: Client exception thrown when no conversation ID is given.
         throw new ClientException(_('No conversation ID.'));
     }
     $this->conversation = Conversation::staticGet('id', $convId);
     if (empty($this->conversation)) {
         // TRANS: Client exception thrown when referring to a non-existing conversation ID (%d).
         $this->clientError(_('No conversation ID found'), 404);
         return false;
     }
     $profile = Profile::current();
     $stream = new ConversationNoticeStream($convId, $profile);
     $notice = $stream->getNotices(($this->page - 1) * $this->count, $this->count, $this->since_id, $this->max_id);
     $this->notices = $notice->fetchAll();
     $originalConversation = new Notice();
     $originalConversation->whereAdd('conversation=' . $convId);
     $originalConversation->limit(1);
     $originalConversation->orderBy('created');
     $originalConversation->find();
     if ($originalConversation->fetch()) {
         $this->originalNotice = $originalConversation;
     }
     return true;
 }
 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;
 }
 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 onEndUpgrade()
 {
     // Version 0.9.x of the plugin didn't stamp notices
     // with verb and object-type (for obvious reasons). Update
     // those notices here.
     $notice = new Notice();
     $notice->whereAdd('exists (select uri from bookmark where bookmark.uri = notice.uri)');
     $notice->whereAdd('((object_type is null) or (object_type = "' . ActivityObject::NOTE . '"))');
     $notice->find();
     while ($notice->fetch()) {
         $original = clone $notice;
         $notice->verb = ActivityVerb::POST;
         $notice->object_type = ActivityObject::BOOKMARK;
         $notice->update($original);
     }
 }
Esempio n. 12
0
 static function checkDupes($profile_id, $content)
 {
     $profile = Profile::getKV($profile_id);
     if (!$profile instanceof Profile) {
         return false;
     }
     $notice = $profile->getNotices(0, CachingNoticeStream::CACHE_WINDOW);
     if (!empty($notice)) {
         $last = 0;
         while ($notice->fetch()) {
             if (time() - strtotime($notice->created) >= common_config('site', 'dupelimit')) {
                 return true;
             } else {
                 if ($notice->content == $content) {
                     return false;
                 }
             }
         }
     }
     // If we get here, oldest item in cache window is not
     // old enough for dupe limit; do direct check against DB
     $notice = new Notice();
     $notice->profile_id = $profile_id;
     $notice->content = $content;
     $threshold = common_sql_date(time() - common_config('site', 'dupelimit'));
     $notice->whereAdd(sprintf("created > '%s'", $notice->escape($threshold)));
     $cnt = $notice->count();
     return $cnt == 0;
 }
 /**
  *
  * @param int $start unix timestamp for earliest
  * @param int $end unix timestamp for latest
  * @return array of Notice objects
  */
 function getNoticesBetween($start = 0, $end = 0)
 {
     $notices = array();
     $notice = new Notice();
     $notice->profile_id = $this->user->id;
     // Only stuff after $this->after
     if (!empty($this->after)) {
         if ($start) {
             $start = max($start, $this->after);
         }
         if ($end) {
             $end = max($end, $this->after);
         }
     }
     if ($start) {
         $tsstart = common_sql_date($start);
         $notice->whereAdd("created >= '{$tsstart}'");
     }
     if ($end) {
         $tsend = common_sql_date($end);
         $notice->whereAdd("created < '{$tsend}'");
     }
     $notice->orderBy('created DESC');
     if ($notice->find()) {
         while ($notice->fetch()) {
             $notices[] = clone $notice;
         }
     }
     return $notices;
 }
Esempio n. 14
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;
 }
Esempio n. 15
0
 function _conversationStreamDirect($id, $offset = 0, $limit = 20, $since_id = 0, $max_id = 0)
 {
     $notice = new Notice();
     $notice->selectAdd();
     // clears it
     $notice->selectAdd('id');
     $notice->conversation = $id;
     $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;
 }
 static function getCount($d)
 {
     $notice = new Notice();
     $notice->whereAdd('created BETWEEN "' . $d . ' 00:00:00" AND "' . self::incrementDay($d) . ' 00:00:00"');
     $notice->whereAdd('is_local = ' . Notice::LOCAL_PUBLIC);
     $n = $notice->count();
     return $n;
 }
 /**
  * Handle the request
  *
  * show a timeline of the user's repeated notices
  *
  * @param array $args $_REQUEST data (unused)
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     $offset = ($this->page - 1) * $this->cnt;
     $limit = $this->cnt;
     // TRANS: Title of list of repeated notices of the logged in user.
     // TRANS: %s is the nickname of the logged in user.
     $title = sprintf(_("Repeats of %s"), $this->auth_user->nickname);
     $sitename = common_config('site', 'name');
     $profile = $this->auth_user->getProfile();
     $subtitle = sprintf(_('%1$s notices that %2$s / %3$s has repeated.'), $sitename, $this->auth_user->nickname, $profile->getBestName());
     $taguribase = TagURI::base();
     $id = "tag:{$taguribase}:RepeatsOfMe:" . $this->auth_user->id;
     $link = common_local_url('all', array('nickname' => $this->auth_user->nickname));
     // This is a really bad query for some reason
     if (!common_config('performance', 'high')) {
         $strm = $this->auth_user->repeatsOfMe($offset, $limit, $this->since_id, $this->max_id);
     } else {
         $strm = new Notice();
         $strm->whereAdd('0 = 1');
         $strm->find();
     }
     switch ($this->format) {
         case 'xml':
             $this->showXmlTimeline($strm);
             break;
         case 'json':
             $this->showJsonTimeline($strm);
             break;
         case 'atom':
             header('Content-Type: application/atom+xml; charset=utf-8');
             $atom = new AtomNoticeFeed($this->auth_user);
             $atom->setId($id);
             $atom->setTitle($title);
             $atom->setSubtitle($subtitle);
             $atom->setUpdated('now');
             $atom->addLink($link);
             $atom->setSelfLink($this->getSelfUri());
             $atom->addEntryFromNotices($strm);
             $this->raw($atom->getString());
             break;
         case 'as':
             header('Content-Type: ' . ActivityStreamJSONDocument::CONTENT_TYPE);
             $doc = new ActivityStreamJSONDocument($this->auth_user);
             $doc->setTitle($title);
             $doc->addLink($link, 'alternate', 'text/html');
             $doc->addItemsFromNotices($strm);
             $this->raw($doc->asString());
             break;
         default:
             // TRANS: Client error displayed when coming across a non-supported API method.
             $this->clientError(_('API method not found.'), 404);
             break;
     }
 }
Esempio n. 19
0
if (!have_option('y', 'yes') && !have_option('--dry-run')) {
    print "About to PERMANENTLY remove geolocation data from user '{$profile->nickname}' ({$profile->id})'s notices. Are you sure? [y/N] ";
    $response = fgets(STDIN);
    if (strtolower(trim($response)) != 'y') {
        print "Aborting.\n";
        exit(0);
    }
}
// @fixme for a very prolific poster this could be too many.
$notice = new Notice();
$notice->profile_id = $profile->id;
if (have_option('--all')) {
    print "Finding all notices by {$profile->nickname}...";
} else {
    print "Finding notices by {$profile->nickname} with geolocation data...";
    $notice->whereAdd("lat != ''");
}
$notice->find();
if ($notice->N) {
    print " {$notice->N} found.\n";
    while ($notice->fetch()) {
        print "notice id {$notice->id} ";
        if (have_option('v') || have_option('--verbose')) {
            print "({$notice->lat},{$notice->lon}) ";
            if ($notice->location_ns) {
                print "ns {$notice->location_ns} id {$notice->location_id} ";
            }
        }
        if (have_option('--dry-run')) {
            // sucka
            echo "(skipped)";
Esempio n. 20
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;
 }
Esempio n. 21
0
 function getCurrentNotice($dt = null)
 {
     $notice = new Notice();
     $notice->profile_id = $this->id;
     if ($dt) {
         $notice->whereAdd('created < "' . $dt . '"');
     }
     $notice->orderBy('created DESC, notice.id DESC');
     $notice->limit(1);
     if ($notice->find(true)) {
         return $notice;
     }
     return null;
 }
Esempio n. 22
0
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
# Abort if called from a web server
if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
    print "This script must be run from the command line\n";
    exit;
}
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('NEWTYPE', true);
define('DWORKS', true);
// compatibility
require_once INSTALLDIR . '/lib/common.php';
common_log(LOG_INFO, 'Starting to render old notices.');
$start_at = $argc > 1 ? $argv[1] : null;
$notice = new Notice();
if ($start_at) {
    $notice->whereAdd('id >= ' . $start_at);
}
$cnt = $notice->find();
while ($notice->fetch()) {
    common_log(LOG_INFO, 'Pre-rendering notice #' . $notice->id);
    $original = clone $notice;
    $notice->rendered = common_render_content($notice->content, $notice);
    $result = $notice->update($original);
    if (!$result) {
        common_log_db_error($notice, 'UPDATE', __FILE__);
    }
}
Esempio n. 23
0
function initNoticeReshare()
{
    printfnq("Ensuring all reshares have the correct verb and object-type...");
    $notice = new Notice();
    $notice->whereAdd('repeat_of is not null');
    $notice->whereAdd('(verb != "' . ActivityVerb::SHARE . '" OR object_type != "' . ActivityObject::ACTIVITY . '")');
    if ($notice->find()) {
        while ($notice->fetch()) {
            try {
                $orig = Notice::staticGet('id', $notice->id);
                $notice->verb = ActivityVerb::SHARE;
                $notice->object_type = ActivityObject::ACTIVITY;
                $notice->update($orig);
            } catch (Exception $e) {
                printfv("Error updating verb and object_type for {$notice->id}:" . $e->getMessage());
            }
        }
    }
    printfnq("DONE.\n");
}
 /**
  * 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. 25
0
 static function checkDupes($profile_id, $content)
 {
     $profile = Profile::staticGet($profile_id);
     if (!$profile) {
         return false;
     }
     $notice = $profile->getNotices(0, NOTICE_CACHE_WINDOW);
     if ($notice) {
         $last = 0;
         while ($notice->fetch()) {
             if (time() - strtotime($notice->created) >= common_config('site', 'dupelimit')) {
                 return true;
             } else {
                 if ($notice->content == $content) {
                     return false;
                 }
             }
         }
     }
     # If we get here, oldest item in cache window is not
     # old enough for dupe limit; do direct check against DB
     $notice = new Notice();
     $notice->profile_id = $profile_id;
     $notice->content = $content;
     if (common_config('db', 'type') == 'pgsql') {
         $notice->whereAdd('extract(epoch from now() - created) < ' . common_config('site', 'dupelimit'));
     } else {
         $notice->whereAdd('now() - created < ' . common_config('site', 'dupelimit'));
     }
     $cnt = $notice->count();
     return $cnt == 0;
 }