function getNotices()
 {
     // @fixme there should be a common func for this
     if (common_config('db', 'type') == 'pgsql') {
         if (!empty($this->out->tag)) {
             $tag = pg_escape_string($this->out->tag);
         }
     } else {
         if (!empty($this->out->tag)) {
             $tag = mysql_escape_string($this->out->tag);
         }
     }
     $weightexpr = common_sql_weight('fave.modified', common_config('popular', 'dropoff'));
     $cutoff = sprintf("fave.modified > '%s'", common_sql_date(time() - common_config('popular', 'cutoff')));
     $qry = "SELECT notice.*, {$weightexpr} as weight ";
     if (isset($tag)) {
         $qry .= 'FROM notice_tag, notice JOIN fave ON notice.id = fave.notice_id ' . "WHERE {$cutoff} and notice.id = notice_tag.notice_id and '{$tag}' = notice_tag.tag";
     } else {
         $qry .= 'FROM notice JOIN fave ON notice.id = fave.notice_id ' . "WHERE {$cutoff}";
     }
     $qry .= ' GROUP BY notice.id,notice.profile_id,notice.content,notice.uri,' . 'notice.rendered,notice.url,notice.created,notice.modified,' . 'notice.reply_to,notice.is_local,notice.source,notice.conversation, ' . 'notice.lat,notice.lon,location_id,location_ns,notice.repeat_of' . ' ORDER BY weight DESC';
     $offset = 0;
     $limit = NOTICES_PER_SECTION + 1;
     $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
     $notice = Memcached_DataObject::cachedQuery('Notice', $qry, 1200);
     return $notice;
 }
示例#2
0
 function getTags()
 {
     $profile = Profile::current();
     $keypart = sprintf('Inbox:notice_tag:%d:%d', $this->user->id, $profile->id);
     $tag = Memcached_DataObject::cacheGet($keypart);
     if ($tag === false) {
         $stream = new InboxNoticeStream($this->user, $profile);
         $ids = $stream->getNoticeIds(0, Inbox::MAX_NOTICES, null, null);
         if (empty($ids)) {
             $tag = array();
         } else {
             $weightexpr = common_sql_weight('notice_tag.created', common_config('tag', 'dropoff'));
             // @fixme should we use the cutoff too? Doesn't help with indexing per-user.
             $qry = 'SELECT notice_tag.tag, ' . $weightexpr . ' as weight ' . 'FROM notice_tag JOIN notice ' . 'ON notice_tag.notice_id = notice.id ' . 'WHERE notice.id in (' . implode(',', $ids) . ')' . 'GROUP BY notice_tag.tag ' . 'ORDER BY weight DESC ';
             $limit = TAGS_PER_SECTION;
             $offset = 0;
             if (common_config('db', 'type') == 'pgsql') {
                 $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
             } else {
                 $qry .= ' LIMIT ' . $offset . ', ' . $limit;
             }
             $t = new Notice_tag();
             $t->query($qry);
             $tag = array();
             while ($t->fetch()) {
                 $tag[] = clone $t;
             }
         }
         Memcached_DataObject::cacheSet($keypart, $tag, 3600);
     }
     return new ArrayWrapper($tag);
 }
 function getTags()
 {
     $weightexpr = common_sql_weight('notice_tag.created', common_config('tag', 'dropoff'));
     // @fixme should we use the cutoff too? Doesn't help with indexing per-user.
     $qry = 'SELECT notice_tag.tag, ' . $weightexpr . ' as weight ' . 'FROM notice_tag JOIN notice ' . 'ON notice_tag.notice_id = notice.id ' . 'WHERE notice.profile_id = %d ' . 'GROUP BY notice_tag.tag ' . 'ORDER BY weight DESC ';
     $limit = TAGS_PER_SECTION;
     $offset = 0;
     if (common_config('db', 'type') == 'pgsql') {
         $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
     } else {
         $qry .= ' LIMIT ' . $offset . ', ' . $limit;
     }
     $tag = Memcached_DataObject::cachedQuery('Notice_tag', sprintf($qry, $this->user->id), 3600);
     return $tag;
 }
 /**
  * Content area
  *
  * Shows the list of popular notices
  *
  * @return void
  */
 function showContent()
 {
     $groupId = intval($this->group->id);
     $weightexpr = common_sql_weight('fave.modified', common_config('popular', 'dropoff'));
     $cutoff = sprintf("fave.modified > '%s'", common_sql_date(time() - common_config('popular', 'cutoff')));
     $qry = 'SELECT notice.*, ' . $weightexpr . ' as weight ' . 'FROM notice ' . "JOIN group_inbox ON notice.id = group_inbox.notice_id " . 'JOIN fave ON notice.id = fave.notice_id ' . "WHERE {$cutoff} AND group_id = {$groupId} " . 'GROUP BY id,profile_id,uri,content,rendered,url,created,notice.modified,reply_to,is_local,source,notice.conversation ' . 'ORDER BY weight DESC';
     $offset = ($this->page - 1) * NOTICES_PER_PAGE;
     $limit = NOTICES_PER_PAGE + 1;
     if (common_config('db', 'type') == 'pgsql') {
         $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
     } else {
         $qry .= ' LIMIT ' . $offset . ', ' . $limit;
     }
     $notice = Memcached_DataObject::cachedQuery('Notice', $qry, 600);
     $nl = new NoticeList($notice, $this);
     $cnt = $nl->show();
     if ($cnt == 0) {
         //$this->showEmptyList();
     }
     $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE, $this->page, 'groupfavorited', array('nickname' => $this->group->nickname));
 }
 function getTags()
 {
     $weightexpr = common_sql_weight('notice_tag.created', common_config('tag', 'dropoff'));
     // @fixme should we use the cutoff too? Doesn't help with indexing per-group.
     $names = $this->group->getAliases();
     $names = array_merge(array($this->group->nickname), $names);
     // XXX This is dumb.
     $quoted = array();
     foreach ($names as $name) {
         $quoted[] = "'{$name}'";
     }
     $namestring = implode(',', $quoted);
     $qry = 'SELECT notice_tag.tag, ' . $weightexpr . ' as weight ' . 'FROM notice_tag JOIN notice ' . 'ON notice_tag.notice_id = notice.id ' . 'JOIN group_inbox on group_inbox.notice_id = notice.id ' . 'WHERE group_inbox.group_id = %d ' . 'AND notice_tag.tag not in (%s) ' . 'GROUP BY notice_tag.tag ' . 'ORDER BY weight DESC ';
     $limit = TAGS_PER_SECTION;
     $offset = 0;
     if (common_config('db', 'type') == 'pgsql') {
         $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
     } else {
         $qry .= ' LIMIT ' . $offset . ', ' . $limit;
     }
     $tag = Memcached_DataObject::cachedQuery('Notice_tag', sprintf($qry, $this->group->id, $namestring), 3600);
     return $tag;
 }
 function getNoticeIds($offset, $limit, $since_id, $max_id)
 {
     $weightexpr = common_sql_weight('modified', common_config('popular', 'dropoff'));
     $cutoff = sprintf("modified > '%s'", common_sql_date(time() - common_config('popular', 'cutoff')));
     $fave = new Fave();
     $fave->selectAdd();
     $fave->selectAdd('notice_id');
     $fave->selectAdd("{$weightexpr} as weight");
     $fave->whereAdd($cutoff);
     $fave->orderBy('weight DESC');
     $fave->groupBy('notice_id');
     if (!is_null($offset)) {
         $fave->limit($offset, $limit);
     }
     // FIXME: $since_id, $max_id are ignored
     $ids = array();
     if ($fave->find()) {
         while ($fave->fetch()) {
             $ids[] = $fave->notice_id;
         }
     }
     return $ids;
 }
 function showContent()
 {
     # This should probably be cached rather than recalculated
     $tags = new Notice_tag();
     #Need to clear the selection and then only re-add the field
     #we are grouping by, otherwise it's not a valid 'group by'
     #even though MySQL seems to let it slide...
     $tags->selectAdd();
     $tags->selectAdd('tag');
     #Add the aggregated columns...
     $tags->selectAdd('max(notice_id) as last_notice_id');
     $calc = common_sql_weight('created', common_config('tag', 'dropoff'));
     $cutoff = sprintf("notice_tag.created > '%s'", common_sql_date(time() - common_config('tag', 'cutoff')));
     $tags->selectAdd($calc . ' as weight');
     $tags->whereAdd($cutoff);
     $tags->groupBy('tag');
     $tags->orderBy('weight DESC');
     $tags->limit(TAGS_PER_PAGE);
     $cnt = $tags->find();
     if ($cnt > 0) {
         $this->elementStart('div', array('id' => 'tagcloud', 'class' => 'section'));
         $tw = array();
         $sum = 0;
         while ($tags->fetch()) {
             $tw[$tags->tag] = $tags->weight;
             $sum += $tags->weight;
         }
         ksort($tw);
         $this->elementStart('dl');
         $this->element('dt', null, _('Tag cloud'));
         $this->elementStart('dd');
         $this->elementStart('ul', 'tags xoxo tag-cloud');
         foreach ($tw as $tag => $weight) {
             if ($sum) {
                 $weightedSum = $weight / $sum;
             } else {
                 $weightedSum = 0.5;
             }
             $this->showTag($tag, $weight, $weightedSum);
         }
         $this->elementEnd('ul');
         $this->elementEnd('dd');
         $this->elementEnd('dl');
         $this->elementEnd('div');
     } else {
         $this->showEmptyList();
     }
 }