summaryrefslogtreecommitdiff
path: root/plugins/OStatus/lib
diff options
context:
space:
mode:
authorZach Copley <zach@status.net>2010-02-08 21:55:32 -0800
committerZach Copley <zach@status.net>2010-02-08 21:55:32 -0800
commit602b01a7554a2ba50ed169db45d57c54823642a0 (patch)
treec1ad0dc29faec3149610e6885e67e91671c5c98e /plugins/OStatus/lib
parentb56b154b51ede363ee8e49ec5b9b9332b8df923c (diff)
parent4e6f587f868d71f08c618d0dedf6ddf0331619c2 (diff)
Merge branch 'testing' of gitorious.org:statusnet/mainline into testing
* 'testing' of gitorious.org:statusnet/mainline: Pull GeoRSS locations over OStatus feeds Allow scripts/decache.php to blow out cache for objects that don't exist (anymore). OStatus cleanup... readme and version for beta5 Delete old Twitter user record when user changes screen name instead of updating. Simpler. Store Twitter screen_name, not name, for foreign_user.nickname when saving Twitter user. Actually store the timestamp on each nonce OAuth app name should not be null Fix issue with OAuth request parameters being parsed/stored twice when - Fix cache handling in TwitterStatusFetcher Added right margin for notice text. Helps Conversation notices look Confirm dialog for reset OAuth consumer key and secret button Always check for an OAuth request. This allows OAuth clients to set an Linkify notice source when posting from registered OAuth apps Suppress notice input box on OAuth authorization page Better token revocation Allow developers to delete OAuth applications OAuth app names should be unique. Prevents app statistic text from wrapping around avatar Sentence case for app statistics
Diffstat (limited to 'plugins/OStatus/lib')
-rw-r--r--plugins/OStatus/lib/feeddiscovery.php22
-rw-r--r--plugins/OStatus/lib/feedmunger.php84
2 files changed, 81 insertions, 25 deletions
diff --git a/plugins/OStatus/lib/feeddiscovery.php b/plugins/OStatus/lib/feeddiscovery.php
index 9bc7892fb..39985fc90 100644
--- a/plugins/OStatus/lib/feeddiscovery.php
+++ b/plugins/OStatus/lib/feeddiscovery.php
@@ -168,7 +168,13 @@ class FeedDiscovery
}
// Ok... now on to the links!
+ // Types listed in order of priority -- we'll prefer Atom if available.
// @fixme merge with the munger link checks
+ $feeds = array(
+ 'application/atom+xml' => false,
+ 'application/rss+xml' => false,
+ );
+
$nodes = $dom->getElementsByTagName('link');
for ($i = 0; $i < $nodes->length; $i++) {
$node = $nodes->item($i);
@@ -181,17 +187,21 @@ class FeedDiscovery
$type = trim($type->value);
$href = trim($href->value);
- $feedTypes = array(
- 'application/rss+xml',
- 'application/atom+xml',
- );
- if (trim($rel) == 'alternate' && in_array($type, $feedTypes)) {
- return $this->resolveURI($href, $base);
+ if (trim($rel) == 'alternate' && array_key_exists($type, $feeds) && empty($feeds[$type])) {
+ // Save the first feed found of each type...
+ $feeds[$type] = $this->resolveURI($href, $base);
}
}
}
}
+ // Return the highest-priority feed found
+ foreach ($feeds as $type => $url) {
+ if ($url) {
+ return $url;
+ }
+ }
+
return false;
}
diff --git a/plugins/OStatus/lib/feedmunger.php b/plugins/OStatus/lib/feedmunger.php
index eeb8d2df3..cbaec6775 100644
--- a/plugins/OStatus/lib/feedmunger.php
+++ b/plugins/OStatus/lib/feedmunger.php
@@ -225,44 +225,90 @@ class FeedMunger
$notice->created = common_sql_date($entry->updated); // @fixme
$notice->is_local = Notice::GATEWAY;
$notice->source = 'feed';
-
+
+ $location = $this->getLocation($entry);
+ if ($location) {
+ if ($location->location_id) {
+ $notice->location_ns = $location->location_ns;
+ $notice->location_id = $location->location_id;
+ }
+ $notice->lat = $location->lat;
+ $notice->lon = $location->lon;
+ }
+
return $notice;
}
/**
+ * @param feed item $entry
+ * @return mixed Location or false
+ */
+ function getLocation($entry)
+ {
+ $dom = $entry->model;
+ $points = $dom->getElementsByTagNameNS('http://www.georss.org/georss', 'point');
+
+ for ($i = 0; $i < $points->length; $i++) {
+ $point = trim($points->item(0)->textContent);
+ $coords = explode(' ', $point);
+ if (count($coords) == 2) {
+ list($lat, $lon) = $coords;
+ if (is_numeric($lat) && is_numeric($lon)) {
+ common_log(LOG_INFO, "Looking up location for $lat $lon from georss");
+ return Location::fromLatLon($lat, $lon);
+ }
+ }
+ common_log(LOG_ERR, "Ignoring bogus georss:point value $point");
+ }
+
+ return false;
+ }
+
+ /**
* @param XML_Feed_Type $entry
* @return string notice text, within post size limit
*/
function noticeFromEntry($entry)
{
+ $max = Notice::maxContent();
+ $ellipsis = "\xe2\x80\xa6"; // U+2026 HORIZONTAL ELLIPSIS
$title = $entry->title;
$link = $entry->link;
-
+
// @todo We can get <category> entries like this:
// $cats = $entry->getCategory('category', array(0, true));
// but it feels like an awful hack. If it's accessible cleanly,
// try adding #hashtags from the categories/tags on a post.
-
- // @todo Should we force a language here?
- $format = _m('New post: "%1$s" %2$s');
+
$title = $entry->title;
$link = $this->getAltLink($entry);
- $out = sprintf($format, $title, $link);
-
- // Trim link if needed...
- $max = Notice::maxContent();
- if (mb_strlen($out) > $max) {
- $link = common_shorten_url($link);
+ if ($link) {
+ // Blog post or such...
+ // @todo Should we force a language here?
+ $format = _m('New post: "%1$s" %2$s');
$out = sprintf($format, $title, $link);
- }
- // Trim title if needed...
- if (mb_strlen($out) > $max) {
- $ellipsis = "\xe2\x80\xa6"; // U+2026 HORIZONTAL ELLIPSIS
- $used = mb_strlen($out) - mb_strlen($title);
- $available = $max - $used - mb_strlen($ellipsis);
- $title = mb_substr($title, 0, $available) . $ellipsis;
- $out = sprintf($format, $title, $link);
+ // Trim link if needed...
+ if (mb_strlen($out) > $max) {
+ $link = common_shorten_url($link);
+ $out = sprintf($format, $title, $link);
+ }
+
+ // Trim title if needed...
+ if (mb_strlen($out) > $max) {
+ $used = mb_strlen($out) - mb_strlen($title);
+ $available = $max - $used - mb_strlen($ellipsis);
+ $title = mb_substr($title, 0, $available) . $ellipsis;
+ $out = sprintf($format, $title, $link);
+ }
+ } else {
+ // No link? Consider a bare status update.
+ if (mb_strlen($title) > $max) {
+ $available = $max - mb_strlen($ellipsis);
+ $out = mb_substr($title, 0, $available) . $ellipsis;
+ } else {
+ $out = $title;
+ }
}
return $out;