hooks to allow changing RSS content

This commit is contained in:
Evan Prodromou 2010-08-13 11:44:26 -07:00
parent 91c914fa3b
commit ed8d8eb5ee
2 changed files with 61 additions and 48 deletions

View File

@ -1056,3 +1056,11 @@ EndNoticeSaveWeb: after saving a notice through the Web interface
- $action: action being executed (instance of NewNoticeAction) - $action: action being executed (instance of NewNoticeAction)
- $notice: notice that was saved - $notice: notice that was saved
StartRssEntryArray: at the start of copying a notice to an array
- $notice: the notice being copied
- &$entry: the entry (empty at beginning)
EndRssEntryArray: at the end of copying a notice to an array
- $notice: the notice being copied
- &$entry: the entry, with all the fields filled up

View File

@ -462,66 +462,71 @@ class ApiAction extends Action
function twitterRssEntryArray($notice) function twitterRssEntryArray($notice)
{ {
$profile = $notice->getProfile();
$entry = array(); $entry = array();
// We trim() to avoid extraneous whitespace in the output if (Event::handle('StartRssEntryArray', array($notice, &$entry))) {
$entry['content'] = common_xml_safe_str(trim($notice->rendered)); $profile = $notice->getProfile();
$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(); // We trim() to avoid extraneous whitespace in the output
$entry['id'] = "tag:$taguribase:$entry[link]";
$entry['updated'] = $entry['published']; $entry['content'] = common_xml_safe_str(trim($notice->rendered));
$entry['author'] = $profile->getBestName(); $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);
// Enclosures $taguribase = TagURI::base();
$attachments = $notice->attachments(); $entry['id'] = "tag:$taguribase:$entry[link]";
$enclosures = array();
foreach ($attachments as $attachment) { $entry['updated'] = $entry['published'];
$enclosure_o=$attachment->getEnclosure(); $entry['author'] = $profile->getBestName();
if ($enclosure_o) {
$enclosure = array(); // Enclosures
$enclosure['url'] = $enclosure_o->url; $attachments = $notice->attachments();
$enclosure['mimetype'] = $enclosure_o->mimetype; $enclosures = array();
$enclosure['size'] = $enclosure_o->size;
$enclosures[] = $enclosure; 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)) { if (!empty($enclosures)) {
$entry['enclosures'] = $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 // Tags/Categories
$entry['description'] = $entry['content']; $tag = new Notice_tag();
$entry['pubDate'] = common_date_rfc2822($notice->created); $tag->notice_id = $notice->id;
$entry['guid'] = $entry['link']; if ($tag->find()) {
$entry['tags']=array();
while ($tag->fetch()) {
$entry['tags'][]=$tag->tag;
}
}
$tag->free();
if (isset($notice->lat) && isset($notice->lon)) { // RSS Item specific
// This is the format that GeoJSON expects stuff to be in. $entry['description'] = $entry['content'];
// showGeoRSS() below uses it for XML output, so we reuse it $entry['pubDate'] = common_date_rfc2822($notice->created);
$entry['geo'] = array('type' => 'Point', $entry['guid'] = $entry['link'];
'coordinates' => array((float) $notice->lat,
(float) $notice->lon)); if (isset($notice->lat) && isset($notice->lon)) {
} else { // This is the format that GeoJSON expects stuff to be in.
$entry['geo'] = null; // showGeoRSS() below uses it for XML output, so we reuse it
$entry['geo'] = array('type' => 'Point',
'coordinates' => array((float) $notice->lat,
(float) $notice->lon));
} else {
$entry['geo'] = null;
}
Event::handle('EndRssEntryArray', array($notice, &$entry));
} }
return $entry; return $entry;