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; }
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; }
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; }
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'); } }
/** * 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; }
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; }
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(); } }
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); } }