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]; $nickname = $a->argv[1];
header("Content-type: application/atom+xml"); 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(); killme();
} }
} }

View File

@ -1538,14 +1538,15 @@ class OStatus
/** /**
* @brief Adds an entry element to the XML document * @brief Adds an entry element to the XML document
* *
* @param object $doc XML document * @param object $doc XML document
* @param array $item Data of the item that is to be posted * @param array $item Data of the item that is to be posted
* @param array $owner Contact data of the poster * @param array $owner Contact data of the poster
* @param bool $toplevel optional default false * @param bool $toplevel optional default false
* @param bool $feed_mode Behave like a regular feed for users if true
* *
* @return object Entry element * @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; $xml = null;
@ -1563,7 +1564,7 @@ class OStatus
} elseif (in_array($item["verb"], [ACTIVITY_FOLLOW, NAMESPACE_OSTATUS."/unfollow"])) { } elseif (in_array($item["verb"], [ACTIVITY_FOLLOW, NAMESPACE_OSTATUS."/unfollow"])) {
return self::followEntry($doc, $item, $owner, $toplevel); return self::followEntry($doc, $item, $owner, $toplevel);
} else { } else {
return self::noteEntry($doc, $item, $owner, $toplevel); return self::noteEntry($doc, $item, $owner, $toplevel, $feed_mode);
} }
} }
@ -1853,14 +1854,15 @@ class OStatus
/** /**
* @brief Adds a regular entry element * @brief Adds a regular entry element
* *
* @param object $doc XML document * @param object $doc XML document
* @param array $item Data of the item that is to be posted * @param array $item Data of the item that is to be posted
* @param array $owner Contact data of the poster * @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 $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 * @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"]))) { 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); 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); 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); self::entryFooter($doc, $entry, $item, $owner);
@ -1892,7 +1894,11 @@ class OStatus
/// @todo Check if this title stuff is really needed (I guess not) /// @todo Check if this title stuff is really needed (I guess not)
if (!$toplevel) { if (!$toplevel) {
$entry = $doc->createElement("entry"); $entry = $doc->createElement("entry");
$title = sprintf("New note by %s", $owner["nick"]); 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) { if ($owner['account-type'] == Contact::ACCOUNT_TYPE_COMMUNITY) {
$contact = self::contactEntry($item['author-link'], $owner); $contact = self::contactEntry($item['author-link'], $owner);
@ -1922,16 +1928,17 @@ class OStatus
/** /**
* @brief Adds elements to the XML document * @brief Adds elements to the XML document
* *
* @param object $doc XML document * @param object $doc XML document
* @param object $entry Entry element where the content is added * @param object $entry Entry element where the content is added
* @param array $item Data of the item that is to be posted * @param array $item Data of the item that is to be posted
* @param array $owner Contact data of the poster * @param array $owner Contact data of the poster
* @param string $title Title for the post * @param string $title Title for the post
* @param string $verb The activity verb * @param string $verb The activity verb
* @param bool $complete Add the "status_net" element? * @param bool $complete Add the "status_net" element?
* @param bool $feed_mode Behave like a regular feed for users if true
* @return void * @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 == "") { if ($verb == "") {
$verb = self::constructVerb($item); $verb = self::constructVerb($item);
@ -1942,7 +1949,7 @@ class OStatus
$body = self::formatPicturePost($item['body']); $body = self::formatPicturePost($item['body']);
if ($item['title'] != "") { if (!empty($item['title']) && !$feed_mode) {
$body = "[b]".$item['title']."[/b]\n\n".$body; $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 integer $max_items Number of maximum items to fetch
* @param string $filter Feed items filter (activity, posts or comments) * @param string $filter Feed items filter (activity, posts or comments)
* @param boolean $nocache Wether to bypass caching * @param boolean $nocache Wether to bypass caching
* @param boolean $feed_mode Behave like a regular feed for users if true
* *
* @return string XML feed * @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); $stamp = microtime(true);
@ -2201,7 +2209,8 @@ class OStatus
if (Config::get('system', 'ostatus_debug')) { if (Config::get('system', 'ostatus_debug')) {
$item['body'] .= '🍼'; $item['body'] .= '🍼';
} }
$entry = self::entry($doc, $item, $owner);
$entry = self::entry($doc, $item, $owner, false, $feed_mode);
$root->appendChild($entry); $root->appendChild($entry);
if ($last_update < $item['created']) { if ($last_update < $item['created']) {