From af219ac9ec547595fbc2b5b19ac402041f35dcf5 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sat, 6 Feb 2016 21:44:10 +0100 Subject: [PATCH] Just some more code cleanup and documentation. --- include/dfrn.php | 83 +++++++++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 37 deletions(-) diff --git a/include/dfrn.php b/include/dfrn.php index 043f02cc2..84660a0d1 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -26,9 +26,9 @@ require_once("library/HTMLPurifier.auto.php"); */ class dfrn { - const DFRN_TOP_LEVEL = 0; - const DFRN_REPLY = 1; - const DFRN_REPLY_RC = 2; + const DFRN_TOP_LEVEL = 0; // Top level posting + const DFRN_REPLY = 1; // Regular reply that is stored locally + const DFRN_REPLY_RC = 2; // Reply that will be relayed /** * @brief Generates the atom entries for delivery.php @@ -1840,6 +1840,47 @@ class dfrn { return true; } + /** + * @brief Processes the link elements + * + * @param object $links link elements + * @param array $item the item record + */ + private function parse_links($links, &$item) { + $rel = ""; + $href = ""; + $type = ""; + $length = "0"; + $title = ""; + foreach ($links AS $link) { + foreach($link->attributes AS $attributes) { + if ($attributes->name == "href") + $href = $attributes->textContent; + if ($attributes->name == "rel") + $rel = $attributes->textContent; + if ($attributes->name == "type") + $type = $attributes->textContent; + if ($attributes->name == "length") + $length = $attributes->textContent; + if ($attributes->name == "title") + $title = $attributes->textContent; + } + if (($rel != "") AND ($href != "")) + switch($rel) { + case "alternate": + $item["plink"] = $href; + break; + case "enclosure": + $enclosure = $href; + if(strlen($item["attach"])) + $item["attach"] .= ","; + + $item["attach"] .= '[attach]href="'.$href.'" length="'.$length.'" type="'.$type.'" title="'.$title.'"[/attach]'; + break; + } + } + } + /** * @brief Processes the entry elements which contain the items and comments * @@ -1970,40 +2011,8 @@ class dfrn { $enclosure = ""; $links = $xpath->query("atom:link", $entry); - if ($links) { - $rel = ""; - $href = ""; - $type = ""; - $length = "0"; - $title = ""; - foreach ($links AS $link) { - foreach($link->attributes AS $attributes) { - if ($attributes->name == "href") - $href = $attributes->textContent; - if ($attributes->name == "rel") - $rel = $attributes->textContent; - if ($attributes->name == "type") - $type = $attributes->textContent; - if ($attributes->name == "length") - $length = $attributes->textContent; - if ($attributes->name == "title") - $title = $attributes->textContent; - } - if (($rel != "") AND ($href != "")) - switch($rel) { - case "alternate": - $item["plink"] = $href; - break; - case "enclosure": - $enclosure = $href; - if(strlen($item["attach"])) - $item["attach"] .= ","; - - $item["attach"] .= '[attach]href="'.$href.'" length="'.$length.'" type="'.$type.'" title="'.$title.'"[/attach]'; - break; - } - } - } + if ($links) + self::parse_links($links, $item); // Is it a reply or a top level posting? $item["parent-uri"] = $item["uri"];