1
1
Fork 0

Merge pull request #6138 from annando/feed-mode

Make feeds look more like feeds
This commit is contained in:
Hypolite Petovan 2018-11-15 09:16:08 -05:00 committed by GitHub
commit 779612d4a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 25 deletions

View file

@ -54,7 +54,7 @@ class Feed extends BaseModule
$nickname = $a->argv[1];
header("Content-type: application/atom+xml");
echo OStatus::feed($nickname, $last_update, 10, $type, $nocache);
echo OStatus::feed($nickname, $last_update, 10, $type, $nocache, true);
killme();
}
}

View file

@ -1542,10 +1542,11 @@ class OStatus
* @param array $item Data of the item that is to be posted
* @param array $owner Contact data of the poster
* @param bool $toplevel optional default false
* @param bool $feed_mode Behave like a regular feed for users if true
*
* @return object Entry element
*/
private static function entry(DOMDocument $doc, array $item, array $owner, $toplevel = false)
private static function entry(DOMDocument $doc, array $item, array $owner, $toplevel = false, $feed_mode = false)
{
$xml = null;
@ -1563,7 +1564,7 @@ class OStatus
} elseif (in_array($item["verb"], [ACTIVITY_FOLLOW, NAMESPACE_OSTATUS."/unfollow"])) {
return self::followEntry($doc, $item, $owner, $toplevel);
} else {
return self::noteEntry($doc, $item, $owner, $toplevel);
return self::noteEntry($doc, $item, $owner, $toplevel, $feed_mode);
}
}
@ -1857,10 +1858,11 @@ class OStatus
* @param array $item Data of the item that is to be posted
* @param array $owner Contact data of the poster
* @param bool $toplevel Is it for en entry element (false) or a feed entry (true)?
* @param bool $feed_mode Behave like a regular feed for users if true
*
* @return object Entry element
*/
private static function noteEntry(DOMDocument $doc, array $item, array $owner, $toplevel)
private static function noteEntry(DOMDocument $doc, array $item, array $owner, $toplevel, $feed_mode)
{
if (($item["id"] != $item["parent"]) && (Strings::normaliseLink($item["author-link"]) != Strings::normaliseLink($owner["url"]))) {
Logger::log("OStatus entry is from author ".$owner["url"]." - not from ".$item["author-link"].". Quitting.", Logger::DEBUG);
@ -1870,7 +1872,7 @@ class OStatus
XML::addElement($doc, $entry, "activity:object-type", ACTIVITY_OBJ_NOTE);
self::entryContent($doc, $entry, $item, $owner, $title);
self::entryContent($doc, $entry, $item, $owner, $title, '', true, $feed_mode);
self::entryFooter($doc, $entry, $item, $owner);
@ -1892,7 +1894,11 @@ class OStatus
/// @todo Check if this title stuff is really needed (I guess not)
if (!$toplevel) {
$entry = $doc->createElement("entry");
if (!empty($item['title'])) {
$title = BBCode::convert($item['title'], false, 7);
} else {
$title = sprintf("New note by %s", $owner["nick"]);
}
if ($owner['account-type'] == Contact::ACCOUNT_TYPE_COMMUNITY) {
$contact = self::contactEntry($item['author-link'], $owner);
@ -1929,9 +1935,10 @@ class OStatus
* @param string $title Title for the post
* @param string $verb The activity verb
* @param bool $complete Add the "status_net" element?
* @param bool $feed_mode Behave like a regular feed for users if true
* @return void
*/
private static function entryContent(DOMDocument $doc, $entry, array $item, array $owner, $title, $verb = "", $complete = true)
private static function entryContent(DOMDocument $doc, $entry, array $item, array $owner, $title, $verb = "", $complete = true, $feed_mode = false)
{
if ($verb == "") {
$verb = self::constructVerb($item);
@ -1942,7 +1949,7 @@ class OStatus
$body = self::formatPicturePost($item['body']);
if ($item['title'] != "") {
if (!empty($item['title']) && !$feed_mode) {
$body = "[b]".$item['title']."[/b]\n\n".$body;
}
@ -2134,10 +2141,11 @@ class OStatus
* @param integer $max_items Number of maximum items to fetch
* @param string $filter Feed items filter (activity, posts or comments)
* @param boolean $nocache Wether to bypass caching
* @param boolean $feed_mode Behave like a regular feed for users if true
*
* @return string XML feed
*/
public static function feed($owner_nick, &$last_update, $max_items = 300, $filter = 'activity', $nocache = false)
public static function feed($owner_nick, &$last_update, $max_items = 300, $filter = 'activity', $nocache = false, $feed_mode = false)
{
$stamp = microtime(true);
@ -2201,7 +2209,8 @@ class OStatus
if (Config::get('system', 'ostatus_debug')) {
$item['body'] .= '🍼';
}
$entry = self::entry($doc, $item, $owner);
$entry = self::entry($doc, $item, $owner, false, $feed_mode);
$root->appendChild($entry);
if ($last_update < $item['created']) {