Esempio n. 1
0
 function showNoticePlus($item)
 {
     $replies = new Notice();
     $replies->reply_to = $item->notice->id;
     // We take responsibility for doing the li
     $this->out->elementStart('li', array('class' => 'h-entry notice', 'id' => 'notice-' . $item->notice->id));
     $item->show();
     if ($replies->find()) {
         $this->out->elementStart('ol', array('class' => 'notices'));
         $replieslist = array();
         while ($replies->fetch()) {
             $replieslist[] = $this->newListItem(clone $replies);
         }
         //Sorting based on url argument
         if ($_GET['sort'] == 'faves') {
             usort($replieslist, array($this, '_cmpFav'));
         } else {
             usort($replieslist, array($this, '_cmpDate'));
         }
         foreach ($replieslist as $reply) {
             $this->showNoticePlus($reply);
         }
         $this->out->elementEnd('ol');
     }
     $this->out->elementEnd('li');
 }
 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 getNoticeIds($offset, $limit, $since_id, $max_id)
 {
     $notice = new Notice();
     $qry = null;
     $qry = 'SELECT notice.* FROM notice ';
     $qry .= 'INNER JOIN happening ON happening.uri = notice.uri ';
     $qry .= 'AND notice.is_local != ' . Notice::GATEWAY . ' ';
     if ($since_id != 0) {
         $qry .= 'AND notice.id > ' . $since_id . ' ';
     }
     if ($max_id != 0) {
         $qry .= 'AND notice.id <= ' . $max_id . ' ';
     }
     // NOTE: we sort by event time, not by notice time!
     $qry .= 'ORDER BY happening.created DESC ';
     if (!is_null($offset)) {
         $qry .= "LIMIT {$limit} OFFSET {$offset}";
     }
     $notice->query($qry);
     $ids = array();
     while ($notice->fetch()) {
         $ids[] = $notice->id;
     }
     $notice->free();
     unset($notice);
     return $ids;
 }
Esempio n. 5
0
 function getUpdates($seconds)
 {
     $notice = new Notice();
     # XXX: cache this. Depends on how big this protocol becomes;
     # Re-doing this query every 15 seconds isn't the end of the world.
     $notice->query('SELECT profile_id, max(id) AS max_id ' . 'FROM notice ' . (common_config('db', 'type') == 'pgsql' ? 'WHERE extract(epoch from created) > (extract(epoch from now()) - ' . $seconds . ') ' : 'WHERE created > (now() - ' . $seconds . ') ') . 'GROUP BY profile_id');
     $updates = array();
     while ($notice->fetch()) {
         $updates[] = array($notice->profile_id, $notice->max_id);
     }
     return $updates;
 }
 function handle($args)
 {
     parent::handle($args);
     $notice = new Notice();
     $notice->source = 'activity';
     $notice->find();
     while ($notice->fetch()) {
         $data = Notice::staticGet('id', $notice->id);
         $orign = clone $data;
         $data->content_type = NOTICE::CONTENT_TYPE_ACTIVITY;
         if (!$data->update($orign)) {
             echo 'profile update error' . $data->id;
             echo '<br>';
         }
     }
 }
 function getNoticeIds($offset, $limit, $since_id, $max_id)
 {
     $notice = new Notice();
     $search_engine = $notice->getSearchEngine('notice');
     $search_engine->set_sort_mode('chron');
     $search_engine->limit($offset, $limit);
     $ids = array();
     // wtf?
     $search_engine->query($this->q);
     if ($notice->find()) {
         while ($notice->fetch()) {
             $ids[] = $notice->id;
         }
     }
     return $ids;
 }
Esempio n. 8
0
 function getNotices($limit = 0)
 {
     $q = $this->trimmed('q');
     $notices = array();
     $notice = new Notice();
     $search_engine = $notice->getSearchEngine('identica_notices');
     $search_engine->set_sort_mode('chron');
     if (!$limit) {
         $limit = 20;
     }
     $search_engine->limit(0, $limit, true);
     $search_engine->query($q);
     $notice->find();
     while ($notice->fetch()) {
         $notices[] = clone $notice;
     }
     return $notices;
 }
 protected function getNotices()
 {
     $q = $this->trimmed('q');
     $notices = array();
     $notice = new Notice();
     $search_engine = $notice->getSearchEngine('notice');
     $search_engine->set_sort_mode('chron');
     $search_engine->limit(0, $this->limit, true);
     if (false === $search_engine->query($q)) {
         $cnt = 0;
     } else {
         $cnt = $notice->find();
     }
     if ($cnt > 0) {
         while ($notice->fetch()) {
             $notices[] = clone $notice;
         }
     }
     return $notices;
 }
Esempio n. 10
0
 /**
  * Check to see if this Twitter status has already been imported
  *
  * @param Profile $profile   Twitter user's local profile
  * @param string  $statusUri URI of the status on Twitter
  *
  * @return mixed value a matching Notice or null
  */
 function checkDupe($profile, $statusUri)
 {
     $notice = new Notice();
     $notice->uri = $statusUri;
     $notice->profile_id = $profile->id;
     $notice->limit(1);
     if ($notice->find()) {
         $notice->fetch();
         return $notice;
     }
     return null;
 }
Esempio n. 11
0
 public static function beforeSchemaUpdate()
 {
     $table = strtolower(get_called_class());
     $schema = Schema::get();
     $schemadef = $schema->getTableDef($table);
     // 2015-09-04 We move Notice location data to Notice_location
     // First we see if we have to do this at all
     if (!isset($schemadef['fields']['lat']) && !isset($schemadef['fields']['lon']) && !isset($schemadef['fields']['location_id']) && !isset($schemadef['fields']['location_ns'])) {
         // We have already removed the location fields, so no need to migrate.
         return;
     }
     // Then we make sure the Notice_location table is created!
     $schema->ensureTable('notice_location', Notice_location::schemaDef());
     // Then we continue on our road to migration!
     echo "\nFound old {$table} table, moving location data to 'notice_location' table... (this will probably take a LONG time, but can be aborted and continued)";
     $notice = new Notice();
     $notice->query(sprintf('SELECT id, lat, lon, location_id, location_ns FROM %1$s ' . 'WHERE lat IS NOT NULL ' . 'OR lon IS NOT NULL ' . 'OR location_id IS NOT NULL ' . 'OR location_ns IS NOT NULL', $schema->quoteIdentifier($table)));
     print "\nFound {$notice->N} notices with location data, inserting";
     while ($notice->fetch()) {
         $notloc = Notice_location::getKV('notice_id', $notice->id);
         if ($notloc instanceof Notice_location) {
             print "-";
             continue;
         }
         $notloc = new Notice_location();
         $notloc->notice_id = $notice->id;
         $notloc->lat = $notice->lat;
         $notloc->lon = $notice->lon;
         $notloc->location_id = $notice->location_id;
         $notloc->location_ns = $notice->location_ns;
         $notloc->insert();
         print ".";
     }
     print "\n";
 }
 /**
  *
  * @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;
 }
 /**
  * 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. 14
0
 function getNotices()
 {
     $notices = array();
     $notice = new Notice();
     $notice->profile_id = $this->user->id;
     if ($notice->find()) {
         while ($notice->fetch()) {
             $notices[] = clone $notice;
         }
     }
     return $notices;
 }
 function getNoticeIds($offset, $limit, $since_id, $max_id)
 {
     // XXX It would be nice to do this without a join
     // (necessary to do it efficiently on accounts with long history)
     $notice = new Notice();
     $query = "select id from notice join notice_tag on id=notice_id where tag='" . $notice->escape($this->tag) . "' and profile_id=" . intval($this->profile->id);
     $since = Notice::whereSinceId($since_id, 'id', 'notice.created');
     if ($since) {
         $query .= " and ({$since})";
     }
     $max = Notice::whereMaxId($max_id, 'id', 'notice.created');
     if ($max) {
         $query .= " and ({$max})";
     }
     $query .= ' order by notice.created DESC, id DESC';
     if (!is_null($offset)) {
         $query .= " LIMIT " . intval($limit) . " OFFSET " . intval($offset);
     }
     $notice->query($query);
     $ids = array();
     while ($notice->fetch()) {
         $ids[] = $notice->id;
     }
     return $ids;
 }
Esempio n. 16
0
 /**
  * Get the notices to output as results. This also sets some class
  * attrs so we can use them to calculate pagination, and output
  * since_id and max_id.
  *
  * @return array an array of Notice objects sorted in reverse chron
  */
 function getNotices()
 {
     // TODO: Support search operators like from: and to:, boolean, etc.
     $notices = array();
     $notice = new Notice();
     // lcase it for comparison
     $q = strtolower($this->query);
     $search_engine = $notice->getSearchEngine('notice');
     $search_engine->set_sort_mode('chron');
     $search_engine->limit(($this->page - 1) * $this->rpp, $this->rpp + 1, true);
     if (false === $search_engine->query($q)) {
         $this->cnt = 0;
     } else {
         $this->cnt = $notice->find();
     }
     $cnt = 0;
     $this->max_id = 0;
     if ($this->cnt > 0) {
         while ($notice->fetch()) {
             ++$cnt;
             if (!$this->max_id) {
                 $this->max_id = $notice->id;
             }
             if ($this->since_id && $notice->id <= $this->since_id) {
                 break;
             }
             if ($cnt > $this->rpp) {
                 break;
             }
             $notices[] = clone $notice;
         }
     }
     return $notices;
 }
Esempio n. 17
0
 function _repeatsOfMeDirect($offset, $limit, $since_id, $max_id)
 {
     $qry = 'SELECT DISTINCT original.id AS id ' . 'FROM notice original JOIN notice rept ON original.id = rept.repeat_of ' . 'WHERE original.profile_id = ' . $this->id . ' ';
     $since = Notice::whereSinceId($since_id, 'original.id', 'original.created');
     if ($since) {
         $qry .= "AND ({$since}) ";
     }
     $max = Notice::whereMaxId($max_id, 'original.id', 'original.created');
     if ($max) {
         $qry .= "AND ({$max}) ";
     }
     $qry .= 'ORDER BY original.created, original.id DESC ';
     if (!is_null($offset)) {
         $qry .= "LIMIT {$limit} OFFSET {$offset}";
     }
     $ids = array();
     $notice = new Notice();
     $notice->query($qry);
     while ($notice->fetch()) {
         $ids[] = $notice->id;
     }
     $notice->free();
     $notice = NULL;
     return $ids;
 }
Esempio n. 18
0
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * 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('STATUSNET', true);
define('LACONICA', true);
// compatibility
require_once INSTALLDIR . '/lib/common.php';
common_log(LOG_INFO, 'Starting to do old notices.');
$notice = new Notice();
$cnt = $notice->find();
while ($notice->fetch()) {
    common_log(LOG_INFO, 'Getting replies for notice #' . $notice->id);
    common_save_replies($notice);
}
Esempio n. 19
0
/**
 * Look for stray notices from this profile and, if present, kill them.
 *
 * @param int $profile_id
 * @param bool $dry if true, we won't delete anything
 */
function cleanup_missing_profile($profile_id, $dry)
{
    $notice = new Notice();
    $notice->profile_id = $profile_id;
    $notice->find();
    if ($notice->N == 0) {
        return;
    }
    $s = $notice->N == 1 ? '' : 's';
    print "Deleted profile {$profile_id} has {$notice->N} stray notice{$s}:\n";
    while ($notice->fetch()) {
        print "  notice {$notice->id}";
        if ($dry) {
            print " (skipped; dry run)\n";
        } else {
            $victim = clone $notice;
            try {
                $victim->delete();
                print " (deleted)\n";
            } catch (Exception $e) {
                print " FAILED: ";
                print $e->getMessage();
                print "\n";
            }
        }
    }
}
Esempio n. 20
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. 21
0
 function clearRepeats()
 {
     $repeatNotice = new Notice();
     $repeatNotice->repeat_of = $this->id;
     //Null any notices that are repeats of this notice
     if ($repeatNotice->find()) {
         while ($repeatNotice->fetch()) {
             $orig = clone $repeatNotice;
             $repeatNotice->repeat_of = null;
             $repeatNotice->update($orig);
         }
     }
 }
Esempio n. 22
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");
}
Esempio n. 23
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;
 }
Esempio n. 24
0
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * 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/>.
 */
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
require_once INSTALLDIR . '/scripts/commandline.inc';
common_log(LOG_INFO, 'Fixing up conversations.');
$nid = new Notice();
$nid->query('select id, reply_to from notice where conversation is null');
while ($nid->fetch()) {
    $cid = null;
    $notice = new Notice();
    if (empty($nid->reply_to)) {
        $cid = $nid->id;
    } else {
        $reply = Notice::staticGet('id', $notice->reply_to);
        if (empty($reply)) {
            common_log(LOG_WARNING, "Replied-to notice {$notice->reply_to} not found.");
            $notice->conversation = $notice->id;
        } else {
            if (empty($reply->conversation)) {
                common_log(LOG_WARNING, "Replied-to notice {$reply->id} has no conversation ID.");
                $notice->conversation = $notice->id;
            } else {
                $notice->conversation = $reply->conversation;
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * 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/>.
 */
define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
$helptext = <<<ENDOFHELP
USAGE: initialize_notice_to_status.php

Initializes the notice_to_status table with existing Twitter synch
data. Only necessary if you've had the Twitter bridge enabled before
version 0.9.5.

ENDOFHELP;
require_once INSTALLDIR . '/scripts/commandline.inc';
// We update any notices that may have come in from
// Twitter that we don't have a status_id for. Note that
// this won't catch notices that originated at this StatusNet site.
$n = new Notice();
$n->query('SELECT notice.id, notice.uri ' . 'FROM notice LEFT JOIN notice_to_status ' . 'ON notice.id = notice_to_status.notice_id ' . 'WHERE notice.source = "twitter"' . 'AND notice_to_status.status_id IS NULL');
while ($n->fetch()) {
    if (preg_match('#^http://twitter.com/[\\w_.]+/status/(\\d+)$#', $n->uri, $match)) {
        $status_id = $match[1];
        Notice_to_status::saveNew($n->id, $status_id);
    }
}
Esempio n. 26
0
 function _deleteNotices()
 {
     $notice = new Notice();
     $notice->profile_id = $this->id;
     if ($notice->find()) {
         while ($notice->fetch()) {
             $other = clone $notice;
             $other->delete();
         }
     }
 }
Esempio n. 27
0
 function _repeatsOfMeDirect($offset, $limit, $since_id, $max_id)
 {
     $qry = 'SELECT DISTINCT original.id AS id ' . 'FROM notice original JOIN notice rept ON original.id = rept.repeat_of ' . 'WHERE original.profile_id = ' . $this->id . ' ';
     if ($since_id != 0) {
         $qry .= 'AND original.id > ' . $since_id . ' ';
     }
     if ($max_id != 0) {
         $qry .= 'AND original.id <= ' . $max_id . ' ';
     }
     // NOTE: we sort by fave time, not by notice time!
     $qry .= 'ORDER BY original.id DESC ';
     if (!is_null($offset)) {
         $qry .= "LIMIT {$limit} OFFSET {$offset}";
     }
     $ids = array();
     $notice = new Notice();
     $notice->query($qry);
     while ($notice->fetch()) {
         $ids[] = $notice->id;
     }
     $notice->free();
     $notice = NULL;
     return $ids;
 }
Esempio n. 28
0
 function clearRepeats()
 {
     $repeatNotice = new Notice();
     $repeatNotice->repeat_of = $this->id;
     //Null any notices that are repeats of this notice
     if ($repeatNotice->find()) {
         while ($repeatNotice->fetch()) {
             $orig = clone $repeatNotice;
             $repeatNotice->repeat_of = null;
             $repeatNotice->update($orig);
         }
     }
     if (!empty($this->repeat_of)) {
         $repeatToNotice = new Notice();
         $repeatToNotice->id = $this->repeat_of;
         if ($repeatToNotice->find()) {
             $this->reduceRepostCount($repeatToNotice->id);
         }
     }
 }