XML class standards

updated the xml class for PSR-2
This commit is contained in:
Adam Magness 2017-11-20 12:56:31 -05:00
parent aac2258bc3
commit ddacbf2c13
9 changed files with 210 additions and 203 deletions

View File

@ -902,7 +902,7 @@ function api_create_xml($data, $root_element)
$data3 = array($root_element => $data2); $data3 = array($root_element => $data2);
$ret = XML::from_array($data3, $xml, false, $namespaces); $ret = XML::fromArray($data3, $xml, false, $namespaces);
return $ret; return $ret;
} }

View File

@ -414,7 +414,7 @@ function xml_status($st, $message = '')
$xmldata = array("result" => $result); $xmldata = array("result" => $result);
echo XML::from_array($xmldata, $xml); echo XML::fromArray($xmldata, $xml);
killme(); killme();
} }

View File

@ -112,7 +112,7 @@ function slapper($owner, $url, $slap)
$namespaces = array("me" => "http://salmon-protocol.org/ns/magic-env"); $namespaces = array("me" => "http://salmon-protocol.org/ns/magic-env");
$salmon = XML::from_array($xmldata, $xml, false, $namespaces); $salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
// slap them // slap them
post_url($url, $salmon, array( post_url($url, $salmon, array(
@ -138,7 +138,7 @@ function slapper($owner, $url, $slap)
$namespaces = array("me" => "http://salmon-protocol.org/ns/magic-env"); $namespaces = array("me" => "http://salmon-protocol.org/ns/magic-env");
$salmon = XML::from_array($xmldata, $xml, false, $namespaces); $salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
// slap them // slap them
post_url($url, $salmon, array( post_url($url, $salmon, array(
@ -161,7 +161,7 @@ function slapper($owner, $url, $slap)
$namespaces = array("me" => "http://salmon-protocol.org/ns/magic-env"); $namespaces = array("me" => "http://salmon-protocol.org/ns/magic-env");
$salmon = XML::from_array($xmldata, $xml, false, $namespaces); $salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
// slap them // slap them
post_url($url, $salmon, array( post_url($url, $salmon, array(

View File

@ -115,7 +115,7 @@ function ping_init(App $a)
} }
} else { } else {
header("Content-type: text/xml"); header("Content-type: text/xml");
echo XML::from_array($data, $xml); echo XML::fromArray($data, $xml);
} }
killme(); killme();
} }
@ -412,7 +412,7 @@ function ping_init(App $a)
$data = ping_format_xml_data($data, $sysnotify_count, $notifications, $sysmsgs, $sysmsgs_info, $groups_unseen, $forums_unseen); $data = ping_format_xml_data($data, $sysnotify_count, $notifications, $sysmsgs, $sysmsgs_info, $groups_unseen, $forums_unseen);
header("Content-type: text/xml"); header("Content-type: text/xml");
echo XML::from_array(array("result" => $data), $xml); echo XML::fromArray(array("result" => $data), $xml);
} }
killme(); killme();

View File

@ -127,7 +127,7 @@ class Probe
return array(); return array();
} }
$links = XML::element_to_array($xrd); $links = XML::elementToArray($xrd);
if (!isset($links["xrd"]["link"])) { if (!isset($links["xrd"]["link"])) {
logger("No xrd data found for ".$host, LOGGER_DEBUG); logger("No xrd data found for ".$host, LOGGER_DEBUG);
return array(); return array();
@ -712,7 +712,7 @@ class Probe
return false; return false;
} }
$xrd_arr = XML::element_to_array($xrd); $xrd_arr = XML::elementToArray($xrd);
if (!isset($xrd_arr["xrd"]["link"])) { if (!isset($xrd_arr["xrd"]["link"])) {
logger("No XML webfinger links for ".$url, LOGGER_DEBUG); logger("No XML webfinger links for ".$url, LOGGER_DEBUG);
return false; return false;

View File

@ -403,17 +403,17 @@ class DFRN
$mail = $doc->createElement("dfrn:mail"); $mail = $doc->createElement("dfrn:mail");
$sender = $doc->createElement("dfrn:sender"); $sender = $doc->createElement("dfrn:sender");
XML::add_element($doc, $sender, "dfrn:name", $owner['name']); XML::addElement($doc, $sender, "dfrn:name", $owner['name']);
XML::add_element($doc, $sender, "dfrn:uri", $owner['url']); XML::addElement($doc, $sender, "dfrn:uri", $owner['url']);
XML::add_element($doc, $sender, "dfrn:avatar", $owner['thumb']); XML::addElement($doc, $sender, "dfrn:avatar", $owner['thumb']);
$mail->appendChild($sender); $mail->appendChild($sender);
XML::add_element($doc, $mail, "dfrn:id", $item['uri']); XML::addElement($doc, $mail, "dfrn:id", $item['uri']);
XML::add_element($doc, $mail, "dfrn:in-reply-to", $item['parent-uri']); XML::addElement($doc, $mail, "dfrn:in-reply-to", $item['parent-uri']);
XML::add_element($doc, $mail, "dfrn:sentdate", datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , ATOM_TIME)); XML::addElement($doc, $mail, "dfrn:sentdate", datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , ATOM_TIME));
XML::add_element($doc, $mail, "dfrn:subject", $item['title']); XML::addElement($doc, $mail, "dfrn:subject", $item['title']);
XML::add_element($doc, $mail, "dfrn:content", $item['body']); XML::addElement($doc, $mail, "dfrn:content", $item['body']);
$root->appendChild($mail); $root->appendChild($mail);
@ -438,11 +438,11 @@ class DFRN
$suggest = $doc->createElement("dfrn:suggest"); $suggest = $doc->createElement("dfrn:suggest");
XML::add_element($doc, $suggest, "dfrn:url", $item['url']); XML::addElement($doc, $suggest, "dfrn:url", $item['url']);
XML::add_element($doc, $suggest, "dfrn:name", $item['name']); XML::addElement($doc, $suggest, "dfrn:name", $item['name']);
XML::add_element($doc, $suggest, "dfrn:photo", $item['photo']); XML::addElement($doc, $suggest, "dfrn:photo", $item['photo']);
XML::add_element($doc, $suggest, "dfrn:request", $item['request']); XML::addElement($doc, $suggest, "dfrn:request", $item['request']);
XML::add_element($doc, $suggest, "dfrn:note", $item['note']); XML::addElement($doc, $suggest, "dfrn:note", $item['note']);
$root->appendChild($suggest); $root->appendChild($suggest);
@ -490,18 +490,18 @@ class DFRN
$relocate = $doc->createElement("dfrn:relocate"); $relocate = $doc->createElement("dfrn:relocate");
XML::add_element($doc, $relocate, "dfrn:url", $owner['url']); XML::addElement($doc, $relocate, "dfrn:url", $owner['url']);
XML::add_element($doc, $relocate, "dfrn:name", $owner['name']); XML::addElement($doc, $relocate, "dfrn:name", $owner['name']);
XML::add_element($doc, $relocate, "dfrn:addr", $owner['addr']); XML::addElement($doc, $relocate, "dfrn:addr", $owner['addr']);
XML::add_element($doc, $relocate, "dfrn:avatar", $owner['avatar']); XML::addElement($doc, $relocate, "dfrn:avatar", $owner['avatar']);
XML::add_element($doc, $relocate, "dfrn:photo", $photos[4]); XML::addElement($doc, $relocate, "dfrn:photo", $photos[4]);
XML::add_element($doc, $relocate, "dfrn:thumb", $photos[5]); XML::addElement($doc, $relocate, "dfrn:thumb", $photos[5]);
XML::add_element($doc, $relocate, "dfrn:micro", $photos[6]); XML::addElement($doc, $relocate, "dfrn:micro", $photos[6]);
XML::add_element($doc, $relocate, "dfrn:request", $owner['request']); XML::addElement($doc, $relocate, "dfrn:request", $owner['request']);
XML::add_element($doc, $relocate, "dfrn:confirm", $owner['confirm']); XML::addElement($doc, $relocate, "dfrn:confirm", $owner['confirm']);
XML::add_element($doc, $relocate, "dfrn:notify", $owner['notify']); XML::addElement($doc, $relocate, "dfrn:notify", $owner['notify']);
XML::add_element($doc, $relocate, "dfrn:poll", $owner['poll']); XML::addElement($doc, $relocate, "dfrn:poll", $owner['poll']);
XML::add_element($doc, $relocate, "dfrn:sitepubkey", Config::get('system','site_pubkey')); XML::addElement($doc, $relocate, "dfrn:sitepubkey", Config::get('system','site_pubkey'));
$root->appendChild($relocate); $root->appendChild($relocate);
@ -540,17 +540,17 @@ class DFRN
$root->setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS); $root->setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS);
$root->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET); $root->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
XML::add_element($doc, $root, "id", System::baseUrl()."/profile/".$owner["nick"]); XML::addElement($doc, $root, "id", System::baseUrl()."/profile/".$owner["nick"]);
XML::add_element($doc, $root, "title", $owner["name"]); XML::addElement($doc, $root, "title", $owner["name"]);
$attributes = array("uri" => "https://friendi.ca", "version" => FRIENDICA_VERSION."-".DB_UPDATE_VERSION); $attributes = array("uri" => "https://friendi.ca", "version" => FRIENDICA_VERSION."-".DB_UPDATE_VERSION);
XML::add_element($doc, $root, "generator", FRIENDICA_PLATFORM, $attributes); XML::addElement($doc, $root, "generator", FRIENDICA_PLATFORM, $attributes);
$attributes = array("rel" => "license", "href" => "http://creativecommons.org/licenses/by/3.0/"); $attributes = array("rel" => "license", "href" => "http://creativecommons.org/licenses/by/3.0/");
XML::add_element($doc, $root, "link", "", $attributes); XML::addElement($doc, $root, "link", "", $attributes);
$attributes = array("rel" => "alternate", "type" => "text/html", "href" => $alternatelink); $attributes = array("rel" => "alternate", "type" => "text/html", "href" => $alternatelink);
XML::add_element($doc, $root, "link", "", $attributes); XML::addElement($doc, $root, "link", "", $attributes);
if ($public) { if ($public) {
@ -558,26 +558,26 @@ class DFRN
OStatus::hublinks($doc, $root, $owner["nick"]); OStatus::hublinks($doc, $root, $owner["nick"]);
$attributes = array("rel" => "salmon", "href" => System::baseUrl()."/salmon/".$owner["nick"]); $attributes = array("rel" => "salmon", "href" => System::baseUrl()."/salmon/".$owner["nick"]);
XML::add_element($doc, $root, "link", "", $attributes); XML::addElement($doc, $root, "link", "", $attributes);
$attributes = array("rel" => "http://salmon-protocol.org/ns/salmon-replies", "href" => System::baseUrl()."/salmon/".$owner["nick"]); $attributes = array("rel" => "http://salmon-protocol.org/ns/salmon-replies", "href" => System::baseUrl()."/salmon/".$owner["nick"]);
XML::add_element($doc, $root, "link", "", $attributes); XML::addElement($doc, $root, "link", "", $attributes);
$attributes = array("rel" => "http://salmon-protocol.org/ns/salmon-mention", "href" => System::baseUrl()."/salmon/".$owner["nick"]); $attributes = array("rel" => "http://salmon-protocol.org/ns/salmon-mention", "href" => System::baseUrl()."/salmon/".$owner["nick"]);
XML::add_element($doc, $root, "link", "", $attributes); XML::addElement($doc, $root, "link", "", $attributes);
} }
// For backward compatibility we keep this element // For backward compatibility we keep this element
if ($owner['page-flags'] == PAGE_COMMUNITY) { if ($owner['page-flags'] == PAGE_COMMUNITY) {
XML::add_element($doc, $root, "dfrn:community", 1); XML::addElement($doc, $root, "dfrn:community", 1);
} }
// The former element is replaced by this one // The former element is replaced by this one
XML::add_element($doc, $root, "dfrn:account_type", $owner["account-type"]); XML::addElement($doc, $root, "dfrn:account_type", $owner["account-type"]);
/// @todo We need a way to transmit the different page flags like "PAGE_PRVGROUP" /// @todo We need a way to transmit the different page flags like "PAGE_PRVGROUP"
XML::add_element($doc, $root, "updated", datetime_convert("UTC", "UTC", "now", ATOM_TIME)); XML::addElement($doc, $root, "updated", datetime_convert("UTC", "UTC", "now", ATOM_TIME));
$author = self::add_author($doc, $owner, $authorelement, $public); $author = self::add_author($doc, $owner, $authorelement, $public);
$root->appendChild($author); $root->appendChild($author);
@ -621,9 +621,9 @@ class DFRN
$attributes = array("dfrn:updated" => $namdate); $attributes = array("dfrn:updated" => $namdate);
} }
XML::add_element($doc, $author, "name", $owner["name"], $attributes); XML::addElement($doc, $author, "name", $owner["name"], $attributes);
XML::add_element($doc, $author, "uri", System::baseUrl().'/profile/'.$owner["nickname"], $attributes); XML::addElement($doc, $author, "uri", System::baseUrl().'/profile/'.$owner["nickname"], $attributes);
XML::add_element($doc, $author, "dfrn:handle", $owner["addr"], $attributes); XML::addElement($doc, $author, "dfrn:handle", $owner["addr"], $attributes);
$attributes = array("rel" => "photo", "type" => "image/jpeg", $attributes = array("rel" => "photo", "type" => "image/jpeg",
"media:width" => 175, "media:height" => 175, "href" => $owner['photo']); "media:width" => 175, "media:height" => 175, "href" => $owner['photo']);
@ -632,13 +632,13 @@ class DFRN
$attributes["dfrn:updated"] = $picdate; $attributes["dfrn:updated"] = $picdate;
} }
XML::add_element($doc, $author, "link", "", $attributes); XML::addElement($doc, $author, "link", "", $attributes);
$attributes["rel"] = "avatar"; $attributes["rel"] = "avatar";
XML::add_element($doc, $author, "link", "", $attributes); XML::addElement($doc, $author, "link", "", $attributes);
if ($hidewall) { if ($hidewall) {
XML::add_element($doc, $author, "dfrn:hide", "true"); XML::addElement($doc, $author, "dfrn:hide", "true");
} }
// The following fields will only be generated if the data isn't meant for a public feed // The following fields will only be generated if the data isn't meant for a public feed
@ -649,7 +649,7 @@ class DFRN
$birthday = feed_birthday($owner['uid'], $owner['timezone']); $birthday = feed_birthday($owner['uid'], $owner['timezone']);
if ($birthday) { if ($birthday) {
XML::add_element($doc, $author, "dfrn:birthday", $birthday); XML::addElement($doc, $author, "dfrn:birthday", $birthday);
} }
// Only show contact details when we are allowed to // Only show contact details when we are allowed to
@ -665,26 +665,26 @@ class DFRN
if (DBM::is_result($r)) { if (DBM::is_result($r)) {
$profile = $r[0]; $profile = $r[0];
XML::add_element($doc, $author, "poco:displayName", $profile["name"]); XML::addElement($doc, $author, "poco:displayName", $profile["name"]);
XML::add_element($doc, $author, "poco:updated", $namdate); XML::addElement($doc, $author, "poco:updated", $namdate);
if (trim($profile["dob"]) > '0001-01-01') { if (trim($profile["dob"]) > '0001-01-01') {
XML::add_element($doc, $author, "poco:birthday", "0000-".date("m-d", strtotime($profile["dob"]))); XML::addElement($doc, $author, "poco:birthday", "0000-".date("m-d", strtotime($profile["dob"])));
} }
XML::add_element($doc, $author, "poco:note", $profile["about"]); XML::addElement($doc, $author, "poco:note", $profile["about"]);
XML::add_element($doc, $author, "poco:preferredUsername", $profile["nickname"]); XML::addElement($doc, $author, "poco:preferredUsername", $profile["nickname"]);
$savetz = date_default_timezone_get(); $savetz = date_default_timezone_get();
date_default_timezone_set($profile["timezone"]); date_default_timezone_set($profile["timezone"]);
XML::add_element($doc, $author, "poco:utcOffset", date("P")); XML::addElement($doc, $author, "poco:utcOffset", date("P"));
date_default_timezone_set($savetz); date_default_timezone_set($savetz);
if (trim($profile["homepage"]) != "") { if (trim($profile["homepage"]) != "") {
$urls = $doc->createElement("poco:urls"); $urls = $doc->createElement("poco:urls");
XML::add_element($doc, $urls, "poco:type", "homepage"); XML::addElement($doc, $urls, "poco:type", "homepage");
XML::add_element($doc, $urls, "poco:value", $profile["homepage"]); XML::addElement($doc, $urls, "poco:value", $profile["homepage"]);
XML::add_element($doc, $urls, "poco:primary", "true"); XML::addElement($doc, $urls, "poco:primary", "true");
$author->appendChild($urls); $author->appendChild($urls);
} }
@ -692,33 +692,33 @@ class DFRN
$keywords = explode(",", $profile["pub_keywords"]); $keywords = explode(",", $profile["pub_keywords"]);
foreach ($keywords as $keyword) { foreach ($keywords as $keyword) {
XML::add_element($doc, $author, "poco:tags", trim($keyword)); XML::addElement($doc, $author, "poco:tags", trim($keyword));
} }
} }
if (trim($profile["xmpp"]) != "") { if (trim($profile["xmpp"]) != "") {
$ims = $doc->createElement("poco:ims"); $ims = $doc->createElement("poco:ims");
XML::add_element($doc, $ims, "poco:type", "xmpp"); XML::addElement($doc, $ims, "poco:type", "xmpp");
XML::add_element($doc, $ims, "poco:value", $profile["xmpp"]); XML::addElement($doc, $ims, "poco:value", $profile["xmpp"]);
XML::add_element($doc, $ims, "poco:primary", "true"); XML::addElement($doc, $ims, "poco:primary", "true");
$author->appendChild($ims); $author->appendChild($ims);
} }
if (trim($profile["locality"].$profile["region"].$profile["country-name"]) != "") { if (trim($profile["locality"].$profile["region"].$profile["country-name"]) != "") {
$element = $doc->createElement("poco:address"); $element = $doc->createElement("poco:address");
XML::add_element($doc, $element, "poco:formatted", Profile::formatLocation($profile)); XML::addElement($doc, $element, "poco:formatted", Profile::formatLocation($profile));
if (trim($profile["locality"]) != "") { if (trim($profile["locality"]) != "") {
XML::add_element($doc, $element, "poco:locality", $profile["locality"]); XML::addElement($doc, $element, "poco:locality", $profile["locality"]);
} }
if (trim($profile["region"]) != "") { if (trim($profile["region"]) != "") {
XML::add_element($doc, $element, "poco:region", $profile["region"]); XML::addElement($doc, $element, "poco:region", $profile["region"]);
} }
if (trim($profile["country-name"]) != "") { if (trim($profile["country-name"]) != "") {
XML::add_element($doc, $element, "poco:country", $profile["country-name"]); XML::addElement($doc, $element, "poco:country", $profile["country-name"]);
} }
$author->appendChild($element); $author->appendChild($element);
@ -744,9 +744,9 @@ class DFRN
$contact = Contact::getDetailsByURL($contact_url, $item["uid"]); $contact = Contact::getDetailsByURL($contact_url, $item["uid"]);
$author = $doc->createElement($element); $author = $doc->createElement($element);
XML::add_element($doc, $author, "name", $contact["name"]); XML::addElement($doc, $author, "name", $contact["name"]);
XML::add_element($doc, $author, "uri", $contact["url"]); XML::addElement($doc, $author, "uri", $contact["url"]);
XML::add_element($doc, $author, "dfrn:handle", $contact["addr"]); XML::addElement($doc, $author, "dfrn:handle", $contact["addr"]);
/// @Todo /// @Todo
/// - Check real image type and image size /// - Check real image type and image size
@ -757,7 +757,7 @@ class DFRN
"media:width" => 80, "media:width" => 80,
"media:height" => 80, "media:height" => 80,
"href" => $contact["photo"]); "href" => $contact["photo"]);
XML::add_element($doc, $author, "link", "", $attributes); XML::addElement($doc, $author, "link", "", $attributes);
$attributes = array( $attributes = array(
"rel" => "avatar", "rel" => "avatar",
@ -765,7 +765,7 @@ class DFRN
"media:width" => 80, "media:width" => 80,
"media:height" => 80, "media:height" => 80,
"href" => $contact["photo"]); "href" => $contact["photo"]);
XML::add_element($doc, $author, "link", "", $attributes); XML::addElement($doc, $author, "link", "", $attributes);
return $author; return $author;
} }
@ -790,13 +790,13 @@ class DFRN
return false; return false;
} }
if ($r->type) { if ($r->type) {
XML::add_element($doc, $entry, "activity:object-type", $r->type); XML::addElement($doc, $entry, "activity:object-type", $r->type);
} }
if ($r->id) { if ($r->id) {
XML::add_element($doc, $entry, "id", $r->id); XML::addElement($doc, $entry, "id", $r->id);
} }
if ($r->title) { if ($r->title) {
XML::add_element($doc, $entry, "title", $r->title); XML::addElement($doc, $entry, "title", $r->title);
} }
if ($r->link) { if ($r->link) {
@ -815,16 +815,16 @@ class DFRN
foreach ($link->attributes() as $parameter => $value) { foreach ($link->attributes() as $parameter => $value) {
$attributes[$parameter] = $value; $attributes[$parameter] = $value;
} }
XML::add_element($doc, $entry, "link", "", $attributes); XML::addElement($doc, $entry, "link", "", $attributes);
} }
} }
} else { } else {
$attributes = array("rel" => "alternate", "type" => "text/html", "href" => $r->link); $attributes = array("rel" => "alternate", "type" => "text/html", "href" => $r->link);
XML::add_element($doc, $entry, "link", "", $attributes); XML::addElement($doc, $entry, "link", "", $attributes);
} }
} }
if ($r->content) { if ($r->content) {
XML::add_element($doc, $entry, "content", bbcode($r->content), array("type" => "html")); XML::addElement($doc, $entry, "content", bbcode($r->content), array("type" => "html"));
} }
return $entry; return $entry;
@ -863,7 +863,7 @@ class DFRN
$attributes["title"] = trim($matches[4]); $attributes["title"] = trim($matches[4]);
} }
XML::add_element($doc, $root, "link", "", $attributes); XML::addElement($doc, $root, "link", "", $attributes);
} }
} }
} }
@ -893,7 +893,7 @@ class DFRN
if ($item['deleted']) { if ($item['deleted']) {
$attributes = array("ref" => $item['uri'], "when" => datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00', ATOM_TIME)); $attributes = array("ref" => $item['uri'], "when" => datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00', ATOM_TIME));
return XML::create_element($doc, "at:deleted-entry", "", $attributes); return XML::createElement($doc, "at:deleted-entry", "", $attributes);
} }
if (!$single) { if (!$single) {
@ -944,7 +944,7 @@ class DFRN
$attributes = array("ref" => $parent_item, "type" => "text/html", $attributes = array("ref" => $parent_item, "type" => "text/html",
"href" => $parent[0]['plink'], "href" => $parent[0]['plink'],
"dfrn:diaspora_guid" => $parent[0]['guid']); "dfrn:diaspora_guid" => $parent[0]['guid']);
XML::add_element($doc, $entry, "thr:in-reply-to", "", $attributes); XML::addElement($doc, $entry, "thr:in-reply-to", "", $attributes);
} }
// Add conversation data. This is used for OStatus // Add conversation data. This is used for OStatus
@ -967,23 +967,23 @@ class DFRN
"href" => $conversation_href, "href" => $conversation_href,
"ref" => $conversation_uri); "ref" => $conversation_uri);
XML::add_element($doc, $entry, "ostatus:conversation", $conversation_uri, $attributes); XML::addElement($doc, $entry, "ostatus:conversation", $conversation_uri, $attributes);
XML::add_element($doc, $entry, "id", $item["uri"]); XML::addElement($doc, $entry, "id", $item["uri"]);
XML::add_element($doc, $entry, "title", $item["title"]); XML::addElement($doc, $entry, "title", $item["title"]);
XML::add_element($doc, $entry, "published", datetime_convert("UTC", "UTC", $item["created"] . "+00:00", ATOM_TIME)); XML::addElement($doc, $entry, "published", datetime_convert("UTC", "UTC", $item["created"] . "+00:00", ATOM_TIME));
XML::add_element($doc, $entry, "updated", datetime_convert("UTC", "UTC", $item["edited"] . "+00:00", ATOM_TIME)); XML::addElement($doc, $entry, "updated", datetime_convert("UTC", "UTC", $item["edited"] . "+00:00", ATOM_TIME));
// "dfrn:env" is used to read the content // "dfrn:env" is used to read the content
XML::add_element($doc, $entry, "dfrn:env", base64url_encode($body, true)); XML::addElement($doc, $entry, "dfrn:env", base64url_encode($body, true));
// The "content" field is not read by the receiver. We could remove it when the type is "text" // The "content" field is not read by the receiver. We could remove it when the type is "text"
// We keep it at the moment, maybe there is some old version that doesn't read "dfrn:env" // We keep it at the moment, maybe there is some old version that doesn't read "dfrn:env"
XML::add_element($doc, $entry, "content", (($type == 'html') ? $htmlbody : $body), array("type" => $type)); XML::addElement($doc, $entry, "content", (($type == 'html') ? $htmlbody : $body), array("type" => $type));
// We save this value in "plink". Maybe we should read it from there as well? // We save this value in "plink". Maybe we should read it from there as well?
XML::add_element( XML::addElement(
$doc, $doc,
$entry, $entry,
"link", "link",
@ -995,50 +995,50 @@ class DFRN
// "comment-allow" is some old fashioned stuff for old Friendica versions. // "comment-allow" is some old fashioned stuff for old Friendica versions.
// It is included in the rewritten code for completeness // It is included in the rewritten code for completeness
if ($comment) { if ($comment) {
XML::add_element($doc, $entry, "dfrn:comment-allow", intval($item['last-child'])); XML::addElement($doc, $entry, "dfrn:comment-allow", intval($item['last-child']));
} }
if ($item['location']) { if ($item['location']) {
XML::add_element($doc, $entry, "dfrn:location", $item['location']); XML::addElement($doc, $entry, "dfrn:location", $item['location']);
} }
if ($item['coord']) { if ($item['coord']) {
XML::add_element($doc, $entry, "georss:point", $item['coord']); XML::addElement($doc, $entry, "georss:point", $item['coord']);
} }
if (($item['private']) || strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])) { if (($item['private']) || strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])) {
XML::add_element($doc, $entry, "dfrn:private", (($item['private']) ? $item['private'] : 1)); XML::addElement($doc, $entry, "dfrn:private", (($item['private']) ? $item['private'] : 1));
} }
if ($item['extid']) { if ($item['extid']) {
XML::add_element($doc, $entry, "dfrn:extid", $item['extid']); XML::addElement($doc, $entry, "dfrn:extid", $item['extid']);
} }
if ($item['bookmark']) { if ($item['bookmark']) {
XML::add_element($doc, $entry, "dfrn:bookmark", "true"); XML::addElement($doc, $entry, "dfrn:bookmark", "true");
} }
if ($item['app']) { if ($item['app']) {
XML::add_element($doc, $entry, "statusnet:notice_info", "", array("local_id" => $item['id'], "source" => $item['app'])); XML::addElement($doc, $entry, "statusnet:notice_info", "", array("local_id" => $item['id'], "source" => $item['app']));
} }
XML::add_element($doc, $entry, "dfrn:diaspora_guid", $item["guid"]); XML::addElement($doc, $entry, "dfrn:diaspora_guid", $item["guid"]);
// The signed text contains the content in Markdown, the sender handle and the signatur for the content // The signed text contains the content in Markdown, the sender handle and the signatur for the content
// It is needed for relayed comments to Diaspora. // It is needed for relayed comments to Diaspora.
if ($item['signed_text']) { if ($item['signed_text']) {
$sign = base64_encode(json_encode(array('signed_text' => $item['signed_text'],'signature' => $item['signature'],'signer' => $item['signer']))); $sign = base64_encode(json_encode(array('signed_text' => $item['signed_text'],'signature' => $item['signature'],'signer' => $item['signer'])));
XML::add_element($doc, $entry, "dfrn:diaspora_signature", $sign); XML::addElement($doc, $entry, "dfrn:diaspora_signature", $sign);
} }
XML::add_element($doc, $entry, "activity:verb", construct_verb($item)); XML::addElement($doc, $entry, "activity:verb", construct_verb($item));
if ($item['object-type'] != "") { if ($item['object-type'] != "") {
XML::add_element($doc, $entry, "activity:object-type", $item['object-type']); XML::addElement($doc, $entry, "activity:object-type", $item['object-type']);
} elseif ($item['id'] == $item['parent']) { } elseif ($item['id'] == $item['parent']) {
XML::add_element($doc, $entry, "activity:object-type", ACTIVITY_OBJ_NOTE); XML::addElement($doc, $entry, "activity:object-type", ACTIVITY_OBJ_NOTE);
} else { } else {
XML::add_element($doc, $entry, "activity:object-type", ACTIVITY_OBJ_COMMENT); XML::addElement($doc, $entry, "activity:object-type", ACTIVITY_OBJ_COMMENT);
} }
$actobj = self::create_activity($doc, "activity:object", $item['object']); $actobj = self::create_activity($doc, "activity:object", $item['object']);
@ -1056,7 +1056,7 @@ class DFRN
if (count($tags)) { if (count($tags)) {
foreach ($tags as $t) { foreach ($tags as $t) {
if (($type != 'html') || ($t[0] != "@")) { if (($type != 'html') || ($t[0] != "@")) {
XML::add_element($doc, $entry, "category", "", array("scheme" => "X-DFRN:".$t[0].":".$t[1], "term" => $t[2])); XML::addElement($doc, $entry, "category", "", array("scheme" => "X-DFRN:".$t[0].":".$t[1], "term" => $t[2]));
} }
} }
} }
@ -1077,7 +1077,7 @@ class DFRN
); );
if (DBM::is_result($r) && ($r[0]["forum"] || $r[0]["prv"])) { if (DBM::is_result($r) && ($r[0]["forum"] || $r[0]["prv"])) {
XML::add_element( XML::addElement(
$doc, $doc,
$entry, $entry,
"link", "link",
@ -1087,7 +1087,7 @@ class DFRN
"href" => $mention) "href" => $mention)
); );
} else { } else {
XML::add_element( XML::addElement(
$doc, $doc,
$entry, $entry,
"link", "link",
@ -1704,7 +1704,7 @@ class DFRN
$obj_element = $obj_doc->createElementNS(NAMESPACE_ATOM1, $element); $obj_element = $obj_doc->createElementNS(NAMESPACE_ATOM1, $element);
$activity_type = $xpath->query("activity:object-type/text()", $activity)->item(0)->nodeValue; $activity_type = $xpath->query("activity:object-type/text()", $activity)->item(0)->nodeValue;
XML::add_element($obj_doc, $obj_element, "type", $activity_type); XML::addElement($obj_doc, $obj_element, "type", $activity_type);
$id = $xpath->query("atom:id", $activity)->item(0); $id = $xpath->query("atom:id", $activity)->item(0);
if (is_object($id)) { if (is_object($id)) {

View File

@ -1913,7 +1913,7 @@ class Diaspora
"title" => "", "title" => "",
"content" => $parent_body)); "content" => $parent_body));
return XML::from_array($xmldata, $xml, true); return XML::fromArray($xmldata, $xml, true);
} }
/** /**
@ -2345,7 +2345,7 @@ class Diaspora
"id" => $contact["url"]."/".$contact["name"], "id" => $contact["url"]."/".$contact["name"],
"link" => $link)); "link" => $link));
return XML::from_array($xmldata, $xml, true); return XML::fromArray($xmldata, $xml, true);
} }
/** /**
@ -3040,7 +3040,7 @@ class Diaspora
$namespaces = array("me" => "http://salmon-protocol.org/ns/magic-env"); $namespaces = array("me" => "http://salmon-protocol.org/ns/magic-env");
return XML::from_array($xmldata, $xml, false, $namespaces); return XML::fromArray($xmldata, $xml, false, $namespaces);
} }
/** /**
@ -3173,7 +3173,7 @@ class Diaspora
{ {
$data = array($type => $message); $data = array($type => $message);
return XML::from_array($data, $xml); return XML::fromArray($data, $xml);
} }
/** /**

View File

@ -1250,39 +1250,39 @@ class OStatus
$root->setAttribute("xmlns:mastodon", NAMESPACE_MASTODON); $root->setAttribute("xmlns:mastodon", NAMESPACE_MASTODON);
$attributes = array("uri" => "https://friendi.ca", "version" => FRIENDICA_VERSION."-".DB_UPDATE_VERSION); $attributes = array("uri" => "https://friendi.ca", "version" => FRIENDICA_VERSION."-".DB_UPDATE_VERSION);
XML::add_element($doc, $root, "generator", FRIENDICA_PLATFORM, $attributes); XML::addElement($doc, $root, "generator", FRIENDICA_PLATFORM, $attributes);
XML::add_element($doc, $root, "id", System::baseUrl()."/profile/".$owner["nick"]); XML::addElement($doc, $root, "id", System::baseUrl()."/profile/".$owner["nick"]);
XML::add_element($doc, $root, "title", sprintf("%s timeline", $owner["name"])); XML::addElement($doc, $root, "title", sprintf("%s timeline", $owner["name"]));
XML::add_element($doc, $root, "subtitle", sprintf("Updates from %s on %s", $owner["name"], $a->config["sitename"])); XML::addElement($doc, $root, "subtitle", sprintf("Updates from %s on %s", $owner["name"], $a->config["sitename"]));
XML::add_element($doc, $root, "logo", $owner["photo"]); XML::addElement($doc, $root, "logo", $owner["photo"]);
XML::add_element($doc, $root, "updated", datetime_convert("UTC", "UTC", "now", ATOM_TIME)); XML::addElement($doc, $root, "updated", datetime_convert("UTC", "UTC", "now", ATOM_TIME));
$author = self::addAuthor($doc, $owner); $author = self::addAuthor($doc, $owner);
$root->appendChild($author); $root->appendChild($author);
$attributes = array("href" => $owner["url"], "rel" => "alternate", "type" => "text/html"); $attributes = array("href" => $owner["url"], "rel" => "alternate", "type" => "text/html");
XML::add_element($doc, $root, "link", "", $attributes); XML::addElement($doc, $root, "link", "", $attributes);
/// @TODO We have to find out what this is /// @TODO We have to find out what this is
/// $attributes = array("href" => System::baseUrl()."/sup", /// $attributes = array("href" => System::baseUrl()."/sup",
/// "rel" => "http://api.friendfeed.com/2008/03#sup", /// "rel" => "http://api.friendfeed.com/2008/03#sup",
/// "type" => "application/json"); /// "type" => "application/json");
/// XML::add_element($doc, $root, "link", "", $attributes); /// XML::addElement($doc, $root, "link", "", $attributes);
self::hublinks($doc, $root, $owner["nick"]); self::hublinks($doc, $root, $owner["nick"]);
$attributes = array("href" => System::baseUrl()."/salmon/".$owner["nick"], "rel" => "salmon"); $attributes = array("href" => System::baseUrl()."/salmon/".$owner["nick"], "rel" => "salmon");
XML::add_element($doc, $root, "link", "", $attributes); XML::addElement($doc, $root, "link", "", $attributes);
$attributes = array("href" => System::baseUrl()."/salmon/".$owner["nick"], "rel" => "http://salmon-protocol.org/ns/salmon-replies"); $attributes = array("href" => System::baseUrl()."/salmon/".$owner["nick"], "rel" => "http://salmon-protocol.org/ns/salmon-replies");
XML::add_element($doc, $root, "link", "", $attributes); XML::addElement($doc, $root, "link", "", $attributes);
$attributes = array("href" => System::baseUrl()."/salmon/".$owner["nick"], "rel" => "http://salmon-protocol.org/ns/salmon-mention"); $attributes = array("href" => System::baseUrl()."/salmon/".$owner["nick"], "rel" => "http://salmon-protocol.org/ns/salmon-mention");
XML::add_element($doc, $root, "link", "", $attributes); XML::addElement($doc, $root, "link", "", $attributes);
$attributes = array("href" => System::baseUrl()."/api/statuses/user_timeline/".$owner["nick"].".atom", $attributes = array("href" => System::baseUrl()."/api/statuses/user_timeline/".$owner["nick"].".atom",
"rel" => "self", "type" => "application/atom+xml"); "rel" => "self", "type" => "application/atom+xml");
XML::add_element($doc, $root, "link", "", $attributes); XML::addElement($doc, $root, "link", "", $attributes);
return $root; return $root;
} }
@ -1297,7 +1297,7 @@ class OStatus
public static function hublinks($doc, $root, $nick) public static function hublinks($doc, $root, $nick)
{ {
$h = System::baseUrl() . '/pubsubhubbub/'.$nick; $h = System::baseUrl() . '/pubsubhubbub/'.$nick;
XML::add_element($doc, $root, "link", "", array("href" => $h, "rel" => "hub")); XML::addElement($doc, $root, "link", "", array("href" => $h, "rel" => "hub"));
} }
/** /**
@ -1319,7 +1319,7 @@ class OStatus
"href" => $siteinfo["image"], "href" => $siteinfo["image"],
"type" => $imgdata["mime"], "type" => $imgdata["mime"],
"length" => intval($imgdata["size"])); "length" => intval($imgdata["size"]));
XML::add_element($doc, $root, "link", "", $attributes); XML::addElement($doc, $root, "link", "", $attributes);
break; break;
case 'video': case 'video':
$attributes = array("rel" => "enclosure", $attributes = array("rel" => "enclosure",
@ -1327,7 +1327,7 @@ class OStatus
"type" => "text/html; charset=UTF-8", "type" => "text/html; charset=UTF-8",
"length" => "", "length" => "",
"title" => $siteinfo["title"]); "title" => $siteinfo["title"]);
XML::add_element($doc, $root, "link", "", $attributes); XML::addElement($doc, $root, "link", "", $attributes);
break; break;
default: default:
break; break;
@ -1340,7 +1340,7 @@ class OStatus
"type" => $imgdata["mime"], "type" => $imgdata["mime"],
"length" => intval($imgdata["size"])); "length" => intval($imgdata["size"]));
XML::add_element($doc, $root, "link", "", $attributes); XML::addElement($doc, $root, "link", "", $attributes);
} }
$arr = explode('[/attach],', $item['attach']); $arr = explode('[/attach],', $item['attach']);
@ -1359,7 +1359,7 @@ class OStatus
if (trim($matches[4]) != "") { if (trim($matches[4]) != "") {
$attributes["title"] = trim($matches[4]); $attributes["title"] = trim($matches[4]);
} }
XML::add_element($doc, $root, "link", "", $attributes); XML::addElement($doc, $root, "link", "", $attributes);
} }
} }
} }
@ -1380,15 +1380,15 @@ class OStatus
$profile = $r[0]; $profile = $r[0];
} }
$author = $doc->createElement("author"); $author = $doc->createElement("author");
XML::add_element($doc, $author, "id", $owner["url"]); XML::addElement($doc, $author, "id", $owner["url"]);
XML::add_element($doc, $author, "activity:object-type", ACTIVITY_OBJ_PERSON); XML::addElement($doc, $author, "activity:object-type", ACTIVITY_OBJ_PERSON);
XML::add_element($doc, $author, "uri", $owner["url"]); XML::addElement($doc, $author, "uri", $owner["url"]);
XML::add_element($doc, $author, "name", $owner["nick"]); XML::addElement($doc, $author, "name", $owner["nick"]);
XML::add_element($doc, $author, "email", $owner["addr"]); XML::addElement($doc, $author, "email", $owner["addr"]);
XML::add_element($doc, $author, "summary", bbcode($owner["about"], false, false, 7)); XML::addElement($doc, $author, "summary", bbcode($owner["about"], false, false, 7));
$attributes = array("rel" => "alternate", "type" => "text/html", "href" => $owner["url"]); $attributes = array("rel" => "alternate", "type" => "text/html", "href" => $owner["url"]);
XML::add_element($doc, $author, "link", "", $attributes); XML::addElement($doc, $author, "link", "", $attributes);
$attributes = array( $attributes = array(
"rel" => "avatar", "rel" => "avatar",
@ -1396,7 +1396,7 @@ class OStatus
"media:width" => 175, "media:width" => 175,
"media:height" => 175, "media:height" => 175,
"href" => $owner["photo"]); "href" => $owner["photo"]);
XML::add_element($doc, $author, "link", "", $attributes); XML::addElement($doc, $author, "link", "", $attributes);
if (isset($owner["thumb"])) { if (isset($owner["thumb"])) {
$attributes = array( $attributes = array(
@ -1405,34 +1405,34 @@ class OStatus
"media:width" => 80, "media:width" => 80,
"media:height" => 80, "media:height" => 80,
"href" => $owner["thumb"]); "href" => $owner["thumb"]);
XML::add_element($doc, $author, "link", "", $attributes); XML::addElement($doc, $author, "link", "", $attributes);
} }
XML::add_element($doc, $author, "poco:preferredUsername", $owner["nick"]); XML::addElement($doc, $author, "poco:preferredUsername", $owner["nick"]);
XML::add_element($doc, $author, "poco:displayName", $owner["name"]); XML::addElement($doc, $author, "poco:displayName", $owner["name"]);
XML::add_element($doc, $author, "poco:note", bbcode($owner["about"], false, false, 7)); XML::addElement($doc, $author, "poco:note", bbcode($owner["about"], false, false, 7));
if (trim($owner["location"]) != "") { if (trim($owner["location"]) != "") {
$element = $doc->createElement("poco:address"); $element = $doc->createElement("poco:address");
XML::add_element($doc, $element, "poco:formatted", $owner["location"]); XML::addElement($doc, $element, "poco:formatted", $owner["location"]);
$author->appendChild($element); $author->appendChild($element);
} }
if (trim($profile["homepage"]) != "") { if (trim($profile["homepage"]) != "") {
$urls = $doc->createElement("poco:urls"); $urls = $doc->createElement("poco:urls");
XML::add_element($doc, $urls, "poco:type", "homepage"); XML::addElement($doc, $urls, "poco:type", "homepage");
XML::add_element($doc, $urls, "poco:value", $profile["homepage"]); XML::addElement($doc, $urls, "poco:value", $profile["homepage"]);
XML::add_element($doc, $urls, "poco:primary", "true"); XML::addElement($doc, $urls, "poco:primary", "true");
$author->appendChild($urls); $author->appendChild($urls);
} }
if (count($profile)) { if (count($profile)) {
XML::add_element($doc, $author, "followers", "", array("url" => System::baseUrl()."/viewcontacts/".$owner["nick"])); XML::addElement($doc, $author, "followers", "", array("url" => System::baseUrl()."/viewcontacts/".$owner["nick"]));
XML::add_element($doc, $author, "statusnet:profile_info", "", array("local_id" => $owner["uid"])); XML::addElement($doc, $author, "statusnet:profile_info", "", array("local_id" => $owner["uid"]));
} }
if ($profile["publish"]) { if ($profile["publish"]) {
XML::add_element($doc, $author, "mastodon:scope", "public"); XML::addElement($doc, $author, "mastodon:scope", "public");
} }
return $author; return $author;
} }
@ -1514,12 +1514,12 @@ class OStatus
private static function sourceEntry($doc, $contact) private static function sourceEntry($doc, $contact)
{ {
$source = $doc->createElement("source"); $source = $doc->createElement("source");
XML::add_element($doc, $source, "id", $contact["poll"]); XML::addElement($doc, $source, "id", $contact["poll"]);
XML::add_element($doc, $source, "title", $contact["name"]); XML::addElement($doc, $source, "title", $contact["name"]);
XML::add_element($doc, $source, "link", "", array("rel" => "alternate", "type" => "text/html", "href" => $contact["alias"])); XML::addElement($doc, $source, "link", "", array("rel" => "alternate", "type" => "text/html", "href" => $contact["alias"]));
XML::add_element($doc, $source, "link", "", array("rel" => "self", "type" => "application/atom+xml", "href" => $contact["poll"])); XML::addElement($doc, $source, "link", "", array("rel" => "self", "type" => "application/atom+xml", "href" => $contact["poll"]));
XML::add_element($doc, $source, "icon", $contact["photo"]); XML::addElement($doc, $source, "icon", $contact["photo"]);
XML::add_element($doc, $source, "updated", datetime_convert("UTC", "UTC", $contact["success_update"]."+00:00", ATOM_TIME)); XML::addElement($doc, $source, "updated", datetime_convert("UTC", "UTC", $contact["success_update"]."+00:00", ATOM_TIME));
return $source; return $source;
} }
@ -1618,7 +1618,7 @@ class OStatus
$as_object = $doc->createElement("activity:object"); $as_object = $doc->createElement("activity:object");
XML::add_element($doc, $as_object, "activity:object-type", NAMESPACE_ACTIVITY_SCHEMA."activity"); XML::addElement($doc, $as_object, "activity:object-type", NAMESPACE_ACTIVITY_SCHEMA."activity");
self::entryContent($doc, $as_object, $repeated_item, $owner, "", "", false); self::entryContent($doc, $as_object, $repeated_item, $owner, "", "", false);
@ -1627,7 +1627,7 @@ class OStatus
$as_object2 = $doc->createElement("activity:object"); $as_object2 = $doc->createElement("activity:object");
XML::add_element($doc, $as_object2, "activity:object-type", self::constructObjecttype($repeated_item)); XML::addElement($doc, $as_object2, "activity:object-type", self::constructObjecttype($repeated_item));
$title = sprintf("New comment by %s", $contact["nick"]); $title = sprintf("New comment by %s", $contact["nick"]);
@ -1678,7 +1678,7 @@ class OStatus
); );
$parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']); $parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']);
XML::add_element($doc, $as_object, "activity:object-type", self::constructObjecttype($parent[0])); XML::addElement($doc, $as_object, "activity:object-type", self::constructObjecttype($parent[0]));
self::entryContent($doc, $as_object, $parent[0], $owner, "New entry"); self::entryContent($doc, $as_object, $parent[0], $owner, "New entry");
@ -1701,18 +1701,18 @@ class OStatus
private static function addPersonObject($doc, $owner, $contact) private static function addPersonObject($doc, $owner, $contact)
{ {
$object = $doc->createElement("activity:object"); $object = $doc->createElement("activity:object");
XML::add_element($doc, $object, "activity:object-type", ACTIVITY_OBJ_PERSON); XML::addElement($doc, $object, "activity:object-type", ACTIVITY_OBJ_PERSON);
if ($contact['network'] == NETWORK_PHANTOM) { if ($contact['network'] == NETWORK_PHANTOM) {
XML::add_element($doc, $object, "id", $contact['url']); XML::addElement($doc, $object, "id", $contact['url']);
return $object; return $object;
} }
XML::add_element($doc, $object, "id", $contact["alias"]); XML::addElement($doc, $object, "id", $contact["alias"]);
XML::add_element($doc, $object, "title", $contact["nick"]); XML::addElement($doc, $object, "title", $contact["nick"]);
$attributes = array("rel" => "alternate", "type" => "text/html", "href" => $contact["url"]); $attributes = array("rel" => "alternate", "type" => "text/html", "href" => $contact["url"]);
XML::add_element($doc, $object, "link", "", $attributes); XML::addElement($doc, $object, "link", "", $attributes);
$attributes = array( $attributes = array(
"rel" => "avatar", "rel" => "avatar",
@ -1720,14 +1720,14 @@ class OStatus
"media:width" => 175, "media:width" => 175,
"media:height" => 175, "media:height" => 175,
"href" => $contact["photo"]); "href" => $contact["photo"]);
XML::add_element($doc, $object, "link", "", $attributes); XML::addElement($doc, $object, "link", "", $attributes);
XML::add_element($doc, $object, "poco:preferredUsername", $contact["nick"]); XML::addElement($doc, $object, "poco:preferredUsername", $contact["nick"]);
XML::add_element($doc, $object, "poco:displayName", $contact["name"]); XML::addElement($doc, $object, "poco:displayName", $contact["name"]);
if (trim($contact["location"]) != "") { if (trim($contact["location"]) != "") {
$element = $doc->createElement("poco:address"); $element = $doc->createElement("poco:address");
XML::add_element($doc, $element, "poco:formatted", $contact["location"]); XML::addElement($doc, $element, "poco:formatted", $contact["location"]);
$object->appendChild($element); $object->appendChild($element);
} }
@ -1817,7 +1817,7 @@ class OStatus
$title = self::entryHeader($doc, $entry, $owner, $toplevel); $title = self::entryHeader($doc, $entry, $owner, $toplevel);
XML::add_element($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);
@ -1879,8 +1879,8 @@ class OStatus
$verb = self::constructVerb($item); $verb = self::constructVerb($item);
} }
XML::add_element($doc, $entry, "id", $item["uri"]); XML::addElement($doc, $entry, "id", $item["uri"]);
XML::add_element($doc, $entry, "title", $title); XML::addElement($doc, $entry, "title", $title);
$body = self::formatPicturePost($item['body']); $body = self::formatPicturePost($item['body']);
@ -1890,20 +1890,25 @@ class OStatus
$body = bbcode($body, false, false, 7); $body = bbcode($body, false, false, 7);
XML::add_element($doc, $entry, "content", $body, array("type" => "html")); XML::addElement($doc, $entry, "content", $body, array("type" => "html"));
XML::add_element($doc, $entry, "link", "", array("rel" => "alternate", "type" => "text/html", XML::addElement(
$doc,
$entry,
"link",
"",
array("rel" => "alternate", "type" => "text/html",
"href" => System::baseUrl()."/display/".$item["guid"]) "href" => System::baseUrl()."/display/".$item["guid"])
); );
if ($complete && ($item["id"] > 0)) { if ($complete && ($item["id"] > 0)) {
XML::add_element($doc, $entry, "status_net", "", array("notice_id" => $item["id"])); XML::addElement($doc, $entry, "status_net", "", array("notice_id" => $item["id"]));
} }
XML::add_element($doc, $entry, "activity:verb", $verb); XML::addElement($doc, $entry, "activity:verb", $verb);
XML::add_element($doc, $entry, "published", datetime_convert("UTC", "UTC", $item["created"]."+00:00", ATOM_TIME)); XML::addElement($doc, $entry, "published", datetime_convert("UTC", "UTC", $item["created"]."+00:00", ATOM_TIME));
XML::add_element($doc, $entry, "updated", datetime_convert("UTC", "UTC", $item["edited"]."+00:00", ATOM_TIME)); XML::addElement($doc, $entry, "updated", datetime_convert("UTC", "UTC", $item["edited"]."+00:00", ATOM_TIME));
} }
/** /**
@ -1941,12 +1946,12 @@ class OStatus
$attributes = array( $attributes = array(
"ref" => $parent_item, "ref" => $parent_item,
"href" => $parent_plink); "href" => $parent_plink);
XML::add_element($doc, $entry, "thr:in-reply-to", "", $attributes); XML::addElement($doc, $entry, "thr:in-reply-to", "", $attributes);
$attributes = array( $attributes = array(
"rel" => "related", "rel" => "related",
"href" => $parent_plink); "href" => $parent_plink);
XML::add_element($doc, $entry, "link", "", $attributes); XML::addElement($doc, $entry, "link", "", $attributes);
} }
if (intval($item["parent"]) > 0) { if (intval($item["parent"]) > 0) {
@ -1965,14 +1970,14 @@ class OStatus
} }
} }
XML::add_element($doc, $entry, "link", "", array("rel" => "ostatus:conversation", "href" => $conversation_href)); XML::addElement($doc, $entry, "link", "", array("rel" => "ostatus:conversation", "href" => $conversation_href));
$attributes = array( $attributes = array(
"href" => $conversation_href, "href" => $conversation_href,
"local_id" => $item["parent"], "local_id" => $item["parent"],
"ref" => $conversation_uri); "ref" => $conversation_uri);
XML::add_element($doc, $entry, "ostatus:conversation", $conversation_uri, $attributes); XML::addElement($doc, $entry, "ostatus:conversation", $conversation_uri, $attributes);
} }
$tags = item_getfeedtags($item); $tags = item_getfeedtags($item);
@ -2000,14 +2005,14 @@ class OStatus
dbesc(normalise_link($mention)) dbesc(normalise_link($mention))
); );
if ($r[0]["forum"] || $r[0]["prv"]) { if ($r[0]["forum"] || $r[0]["prv"]) {
XML::add_element($doc, $entry, "link", "", XML::addElement($doc, $entry, "link", "",
array( array(
"rel" => "mentioned", "rel" => "mentioned",
"ostatus:object-type" => ACTIVITY_OBJ_GROUP, "ostatus:object-type" => ACTIVITY_OBJ_GROUP,
"href" => $mention) "href" => $mention)
); );
} else { } else {
XML::add_element($doc, $entry, "link", "", XML::addElement($doc, $entry, "link", "",
array( array(
"rel" => "mentioned", "rel" => "mentioned",
"ostatus:object-type" => ACTIVITY_OBJ_PERSON, "ostatus:object-type" => ACTIVITY_OBJ_PERSON,
@ -2017,18 +2022,18 @@ class OStatus
} }
if (!$item["private"]) { if (!$item["private"]) {
XML::add_element($doc, $entry, "link", "", array("rel" => "ostatus:attention", XML::addElement($doc, $entry, "link", "", array("rel" => "ostatus:attention",
"href" => "http://activityschema.org/collection/public")); "href" => "http://activityschema.org/collection/public"));
XML::add_element($doc, $entry, "link", "", array("rel" => "mentioned", XML::addElement($doc, $entry, "link", "", array("rel" => "mentioned",
"ostatus:object-type" => "http://activitystrea.ms/schema/1.0/collection", "ostatus:object-type" => "http://activitystrea.ms/schema/1.0/collection",
"href" => "http://activityschema.org/collection/public")); "href" => "http://activityschema.org/collection/public"));
XML::add_element($doc, $entry, "mastodon:scope", "public"); XML::addElement($doc, $entry, "mastodon:scope", "public");
} }
if (count($tags)) { if (count($tags)) {
foreach ($tags as $t) { foreach ($tags as $t) {
if ($t[0] != "@") { if ($t[0] != "@") {
XML::add_element($doc, $entry, "category", "", array("term" => $t[2])); XML::addElement($doc, $entry, "category", "", array("term" => $t[2]));
} }
} }
} }
@ -2048,10 +2053,10 @@ class OStatus
} }
if ($item["coord"] != "") { if ($item["coord"] != "") {
XML::add_element($doc, $entry, "georss:point", $item["coord"]); XML::addElement($doc, $entry, "georss:point", $item["coord"]);
} }
XML::add_element($doc, $entry, "statusnet:notice_info", "", $attributes); XML::addElement($doc, $entry, "statusnet:notice_info", "", $attributes);
} }
} }

View File

@ -1,5 +1,4 @@
<?php <?php
/** /**
* @file src/Util/XML.php * @file src/Util/XML.php
*/ */
@ -24,7 +23,7 @@ class XML
* *
* @return string The created XML * @return string The created XML
*/ */
public static function from_array($array, &$xml, $remove_header = false, $namespaces = array(), $root = true) public static function fromArray($array, &$xml, $remove_header = false, $namespaces = array(), $root = true)
{ {
if ($root) { if ($root) {
foreach ($array as $key => $value) { foreach ($array as $key => $value) {
@ -34,7 +33,7 @@ class XML
if (is_array($value)) { if (is_array($value)) {
$root = new SimpleXMLElement("<".$key."/>"); $root = new SimpleXMLElement("<".$key."/>");
self::from_array($value, $root, $remove_header, $namespaces, false); self::fromArray($value, $root, $remove_header, $namespaces, false);
} else { } else {
$root = new SimpleXMLElement("<".$key.">".xmlify($value)."</".$key.">"); $root = new SimpleXMLElement("<".$key.">".xmlify($value)."</".$key.">");
} }
@ -106,7 +105,7 @@ class XML
$element = $xml->addChild($key, xmlify($value), $namespace); $element = $xml->addChild($key, xmlify($value), $namespace);
} elseif (is_array($value)) { } elseif (is_array($value)) {
$element = $xml->addChild($key, null, $namespace); $element = $xml->addChild($key, null, $namespace);
self::from_array($value, $element, $remove_header, $namespaces, false); self::fromArray($value, $element, $remove_header, $namespaces, false);
} }
} }
} }
@ -117,6 +116,7 @@ class XML
* @param object $source The XML source * @param object $source The XML source
* @param object $target The XML target * @param object $target The XML target
* @param string $elementname Name of the XML element of the target * @param string $elementname Name of the XML element of the target
* @return void
*/ */
public static function copy(&$source, &$target, $elementname) public static function copy(&$source, &$target, $elementname)
{ {
@ -140,7 +140,7 @@ class XML
* *
* @return object XML element object * @return object XML element object
*/ */
public static function create_element($doc, $element, $value = "", $attributes = array()) public static function createElement($doc, $element, $value = "", $attributes = array())
{ {
$element = $doc->createElement($element, xmlify($value)); $element = $doc->createElement($element, xmlify($value));
@ -160,10 +160,11 @@ class XML
* @param string $element XML element name * @param string $element XML element name
* @param string $value XML value * @param string $value XML value
* @param array $attributes array containing the attributes * @param array $attributes array containing the attributes
* @return void
*/ */
public static function add_element($doc, $parent, $element, $value = "", $attributes = array()) public static function addElement($doc, $parent, $element, $value = "", $attributes = array())
{ {
$element = self::create_element($doc, $element, $value, $attributes); $element = self::createElement($doc, $element, $value, $attributes);
$parent->appendChild($element); $parent->appendChild($element);
} }
@ -177,7 +178,7 @@ class XML
* *
* @return array | sring The array from the xml element or the string * @return array | sring The array from the xml element or the string
*/ */
public static function element_to_array($xml_element, &$recursion_depth=0) public static function elementToArray($xml_element, &$recursion_depth = 0)
{ {
// If we're getting too deep, bail out // If we're getting too deep, bail out
if ($recursion_depth > 512) { if ($recursion_depth > 512) {
@ -200,7 +201,7 @@ class XML
foreach ($xml_element as $key => $value) { foreach ($xml_element as $key => $value) {
$recursion_depth++; $recursion_depth++;
$result_array[strtolower($key)] = self::element_to_array($value, $recursion_depth); $result_array[strtolower($key)] = self::elementToArray($value, $recursion_depth);
$recursion_depth--; $recursion_depth--;
} }
@ -220,13 +221,13 @@ class XML
/** /**
* @brief Convert the given XML text to an array in the XML structure. * @brief Convert the given XML text to an array in the XML structure.
* *
* Xml::to_array() will convert the given XML text to an array in the XML structure. * Xml::toArray() will convert the given XML text to an array in the XML structure.
* Link: http://www.bin-co.com/php/scripts/xml2array/ * Link: http://www.bin-co.com/php/scripts/xml2array/
* Portions significantly re-written by mike@macgirvin.com for Friendica * Portions significantly re-written by mike@macgirvin.com for Friendica
* (namespaces, lowercase tags, get_attribute default changed, more...) * (namespaces, lowercase tags, get_attribute default changed, more...)
* *
* Examples: $array = Xml::to_array(file_get_contents('feed.xml')); * Examples: $array = Xml::toArray(file_get_contents('feed.xml'));
* $array = Xml::to_array(file_get_contents('feed.xml', true, 1, 'attribute')); * $array = Xml::toArray(file_get_contents('feed.xml', true, 1, 'attribute'));
* *
* @param object $contents The XML text * @param object $contents The XML text
* @param boolean $namespaces True or false include namespace information * @param boolean $namespaces True or false include namespace information
@ -238,14 +239,14 @@ class XML
* *
* @return array The parsed XML in an array form. Use print_r() to see the resulting array structure. * @return array The parsed XML in an array form. Use print_r() to see the resulting array structure.
*/ */
public static function to_array($contents, $namespaces = true, $get_attributes = 1, $priority = 'attribute') public static function toArray($contents, $namespaces = true, $get_attributes = 1, $priority = 'attribute')
{ {
if (!$contents) { if (!$contents) {
return array(); return array();
} }
if (!function_exists('xml_parser_create')) { if (!function_exists('xml_parser_create')) {
logger('Xml::to_array: parser function missing'); logger('Xml::toArray: parser function missing');
return array(); return array();
} }
@ -260,7 +261,7 @@ class XML
} }
if (! $parser) { if (! $parser) {
logger('Xml::to_array: xml_parser_create: no resource'); logger('Xml::toArray: xml_parser_create: no resource');
return array(); return array();
} }
@ -272,7 +273,7 @@ class XML
@xml_parser_free($parser); @xml_parser_free($parser);
if (! $xml_values) { if (! $xml_values) {
logger('Xml::to_array: libxml: parse error: ' . $contents, LOGGER_DATA); logger('Xml::toArray: libxml: parse error: ' . $contents, LOGGER_DATA);
foreach (libxml_get_errors() as $err) { foreach (libxml_get_errors() as $err) {
logger('libxml: parse: ' . $err->code . " at " . $err->line . ":" . $err->column . " : " . $err->message, LOGGER_DATA); logger('libxml: parse: ' . $err->code . " at " . $err->line . ":" . $err->column . " : " . $err->message, LOGGER_DATA);
} }
@ -402,6 +403,7 @@ class XML
* *
* @param object $doc XML document * @param object $doc XML document
* @param string $node Node name * @param string $node Node name
* @return void
*/ */
public static function deleteNode(&$doc, $node) public static function deleteNode(&$doc, $node)
{ {