Exemplo n.º 1
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);
 }
Exemplo n.º 2
0
 function getTags($lst, $usr)
 {
     $profile_tag = new Notice_tag();
     $profile_tag->query('SELECT DISTINCT(tag) ' . 'FROM profile_tag, subscription ' . 'WHERE tagger = ' . $this->target->id . ' ' . 'AND ' . $usr . ' = ' . $this->target->id . ' ' . 'AND ' . $lst . ' = tagged ' . 'AND tagger != tagged');
     $tags = array();
     while ($profile_tag->fetch()) {
         $tags[] = $profile_tag->tag;
     }
     $profile_tag->free();
     return $tags;
 }
Exemplo n.º 3
0
function ping_notice_tags($notice)
{
    $tag = new Notice_tag();
    $tag->notice_id = $notice->id;
    $tags = array();
    if ($tag->find()) {
        while ($tag->fetch()) {
            $tags[] = $tag->tag;
        }
        $tag->free();
        unset($tag);
        return implode('|', $tags);
    }
    return NULL;
}
Exemplo n.º 4
0
 function _streamDirect($tag, $offset, $limit, $since_id, $max_id)
 {
     $nt = new Notice_tag();
     $nt->tag = $tag;
     $nt->selectAdd();
     $nt->selectAdd('notice_id');
     if ($since_id != 0) {
         $nt->whereAdd('notice_id > ' . $since_id);
     }
     if ($max_id != 0) {
         $nt->whereAdd('notice_id < ' . $max_id);
     }
     $nt->orderBy('notice_id DESC');
     if (!is_null($offset)) {
         $nt->limit($offset, $limit);
     }
     $ids = array();
     if ($nt->find()) {
         while ($nt->fetch()) {
             $ids[] = $nt->notice_id;
         }
     }
     return $ids;
 }
 function showItem($notice)
 {
     $profile = Profile::staticGet($notice->profile_id);
     $nurl = common_local_url('shownotice', array('notice' => $notice->id));
     $creator_uri = common_profile_uri($profile);
     $this->elementStart('item', array('rdf:about' => $notice->uri, 'rdf:type' => 'http://rdfs.org/sioc/types#MicroblogPost'));
     $title = $profile->nickname . ': ' . common_xml_safe_str(trim($notice->content));
     $this->element('title', null, $title);
     $this->element('link', null, $nurl);
     $this->element('description', null, $profile->nickname . "'s status on " . common_exact_date($notice->created));
     if ($notice->rendered) {
         $this->element('content:encoded', null, common_xml_safe_str($notice->rendered));
     }
     $this->element('dc:date', null, common_date_w3dtf($notice->created));
     $this->element('dc:creator', null, $profile->fullname ? $profile->fullname : $profile->nickname);
     $this->element('foaf:maker', array('rdf:resource' => $creator_uri));
     $this->element('sioc:has_creator', array('rdf:resource' => $creator_uri . '#acct'));
     $location = $notice->getLocation();
     if ($location && isset($location->lat) && isset($location->lon)) {
         $location_uri = $location->getRdfURL();
         $attrs = array('geo:lat' => $location->lat, 'geo:long' => $location->lon);
         if (strlen($location_uri)) {
             $attrs['rdf:resource'] = $location_uri;
         }
         $this->element('statusnet:origin', $attrs);
     }
     $this->element('statusnet:postIcon', array('rdf:resource' => $profile->avatarUrl()));
     $this->element('cc:licence', array('rdf:resource' => common_config('license', 'url')));
     if ($notice->reply_to) {
         $replyurl = common_local_url('shownotice', array('notice' => $notice->reply_to));
         $this->element('sioc:reply_of', array('rdf:resource' => $replyurl));
     }
     if (!empty($notice->conversation)) {
         $conversationurl = common_local_url('conversation', array('id' => $notice->conversation));
         $this->element('sioc:has_discussion', array('rdf:resource' => $conversationurl));
     }
     $attachments = $notice->attachments();
     if ($attachments) {
         foreach ($attachments as $attachment) {
             $enclosure = $attachment->getEnclosure();
             if ($enclosure) {
                 $attribs = array('rdf:resource' => $enclosure->url);
                 if ($enclosure->title) {
                     $attribs['dc:title'] = $enclosure->title;
                 }
                 if ($enclosure->modified) {
                     $attribs['dc:date'] = common_date_w3dtf($enclosure->modified);
                 }
                 if ($enclosure->size) {
                     $attribs['enc:length'] = $enclosure->size;
                 }
                 if ($enclosure->mimetype) {
                     $attribs['enc:type'] = $enclosure->mimetype;
                 }
                 $this->element('enc:enclosure', $attribs);
             }
             $this->element('sioc:links_to', array('rdf:resource' => $attachment->url));
         }
     }
     $tag = new Notice_tag();
     $tag->notice_id = $notice->id;
     if ($tag->find()) {
         $entry['tags'] = array();
         while ($tag->fetch()) {
             $tagpage = common_local_url('tag', array('tag' => $tag->tag));
             if (in_array($tag, $this->tags_already_output)) {
                 $this->element('ctag:tagged', array('rdf:resource' => $tagpage . '#concept'));
                 continue;
             }
             $tagrss = common_local_url('tagrss', array('tag' => $tag->tag));
             $this->elementStart('ctag:tagged');
             $this->elementStart('ctag:Tag', array('rdf:about' => $tagpage . '#concept', 'ctag:label' => $tag->tag));
             $this->element('foaf:page', array('rdf:resource' => $tagpage));
             $this->element('rdfs:seeAlso', array('rdf:resource' => $tagrss));
             $this->elementEnd('ctag:Tag');
             $this->elementEnd('ctag:tagged');
             $this->tags_already_output[] = $tag->tag;
         }
     }
     $this->elementEnd('item');
     $this->creators[$creator_uri] = $profile;
 }
Exemplo n.º 6
0
 function twitterRssEntryArray($notice)
 {
     $entry = array();
     if (Event::handle('StartRssEntryArray', array($notice, &$entry))) {
         $profile = $notice->getProfile();
         // We trim() to avoid extraneous whitespace in the output
         $entry['content'] = common_xml_safe_str(trim($notice->rendered));
         $entry['title'] = $profile->nickname . ': ' . common_xml_safe_str(trim($notice->content));
         $entry['link'] = common_local_url('shownotice', array('notice' => $notice->id));
         $entry['published'] = common_date_iso8601($notice->created);
         $taguribase = TagURI::base();
         $entry['id'] = "tag:{$taguribase}:{$entry['link']}";
         $entry['updated'] = $entry['published'];
         $entry['author'] = $profile->getBestName();
         // Enclosures
         $attachments = $notice->attachments();
         $enclosures = array();
         foreach ($attachments as $attachment) {
             $enclosure_o = $attachment->getEnclosure();
             if ($enclosure_o) {
                 $enclosure = array();
                 $enclosure['url'] = $enclosure_o->url;
                 $enclosure['mimetype'] = $enclosure_o->mimetype;
                 $enclosure['size'] = $enclosure_o->size;
                 $enclosures[] = $enclosure;
             }
         }
         if (!empty($enclosures)) {
             $entry['enclosures'] = $enclosures;
         }
         // Tags/Categories
         $tag = new Notice_tag();
         $tag->notice_id = $notice->id;
         if ($tag->find()) {
             $entry['tags'] = array();
             while ($tag->fetch()) {
                 $entry['tags'][] = $tag->tag;
             }
         }
         $tag->free();
         // RSS Item specific
         $entry['description'] = $entry['content'];
         $entry['pubDate'] = common_date_rfc2822($notice->created);
         $entry['guid'] = $entry['link'];
         if (isset($notice->lat) && isset($notice->lon)) {
             // This is the format that GeoJSON expects stuff to be in.
             // showGeoRSS() below uses it for XML output, so we reuse it
             $entry['geo'] = array('type' => 'Point', 'coordinates' => array((double) $notice->lat, (double) $notice->lon));
         } else {
             $entry['geo'] = null;
         }
         Event::handle('EndRssEntryArray', array($notice, &$entry));
     }
     return $entry;
 }
Exemplo n.º 7
0
 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');
     if (common_config('db', 'type') == 'pgsql') {
         $calc = 'sum(exp(-extract(epoch from (now()-created))/%s)) as weight';
     } else {
         $calc = 'sum(exp(-(now() - created)/%s)) as weight';
     }
     $tags->selectAdd(sprintf($calc, common_config('tag', 'dropoff')));
     $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) {
             $this->showTag($tag, $weight, $weight / $sum);
         }
         $this->elementEnd('ul');
         $this->elementEnd('dd');
         $this->elementEnd('dl');
         $this->elementEnd('div');
     }
 }
Exemplo n.º 8
0
 /**
  * Get the list of hash tags saved with this notice.
  *
  * @return array of strings
  */
 public function getTags()
 {
     $tags = array();
     $keypart = sprintf('notice:tags:%d', $this->id);
     $tagstr = self::cacheGet($keypart);
     if ($tagstr !== false) {
         $tags = explode(',', $tagstr);
     } else {
         $tag = new Notice_tag();
         $tag->notice_id = $this->id;
         if ($tag->find()) {
             while ($tag->fetch()) {
                 $tags[] = $tag->tag;
             }
         }
         self::cacheSet($keypart, implode(',', $tags));
     }
     return $tags;
 }
 function getNoticeTags($notice)
 {
     $tags = null;
     $nt = new Notice_tag();
     $nt->notice_id = $notice->id;
     if ($nt->find()) {
         $tags = array();
         while ($nt->fetch()) {
             $tags[] = $nt->tag;
         }
     }
     $nt->free();
     $nt = null;
     return $tags;
 }
Exemplo n.º 10
0
 public function getTags()
 {
     $tags = array();
     $tag = new Notice_tag();
     $tag->notice_id = $this->id;
     if ($tag->find()) {
         while ($tag->fetch()) {
             $tags[] = $tag->tag;
         }
     }
     $tag->free();
     return $tags;
 }
Exemplo n.º 11
0
 function clearTags()
 {
     $tag = new Notice_tag();
     $tag->notice_id = $this->id;
     if ($tag->find()) {
         while ($tag->fetch()) {
             self::blow('profile:notice_ids_tagged:%d:%s', $this->profile_id, common_keyize($tag->tag));
             self::blow('profile:notice_ids_tagged:%d:%s;last', $this->profile_id, common_keyize($tag->tag));
             self::blow('notice_tag:notice_ids:%s', common_keyize($tag->tag));
             self::blow('notice_tag:notice_ids:%s;last', common_keyize($tag->tag));
             $tag->delete();
         }
     }
     $tag->free();
 }
 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();
     }
 }
Exemplo n.º 13
0
 function blowTagCache($blowLast = false)
 {
     $cache = common_memcache();
     if ($cache) {
         $tag = new Notice_tag();
         $tag->notice_id = $this->id;
         if ($tag->find()) {
             while ($tag->fetch()) {
                 $cache->delete(common_cache_key('notice_tag:notice_stream:' . $tag->tag));
                 if ($blowLast) {
                     $cache->delete(common_cache_key('notice_tag:notice_stream:' . $tag->tag . ';last'));
                 }
             }
         }
         $tag->free();
         unset($tag);
     }
 }