From 8bbf9e93c61079bfa556d51b3b6e19f80ab8d795 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 31 Dec 2022 11:59:19 -0500 Subject: [PATCH 1/2] Remove dependency to the second parameter of XML::fromArray --- mod/oexchange.php | 8 +++----- src/Core/System.php | 2 +- src/Module/Api/ApiResponse.php | 2 +- src/Module/OpenSearch.php | 2 -- src/Module/ReallySimpleDiscovery.php | 3 +-- src/Module/WellKnown/HostMeta.php | 1 - src/Module/Xrd.php | 8 +++----- src/Protocol/Diaspora.php | 7 +++---- src/Protocol/Salmon.php | 10 +++------- src/Util/XML.php | 15 ++++++++------- 10 files changed, 23 insertions(+), 35 deletions(-) diff --git a/mod/oexchange.php b/mod/oexchange.php index c531eefdf..4fbf7ffeb 100644 --- a/mod/oexchange.php +++ b/mod/oexchange.php @@ -36,9 +36,7 @@ function oexchange_init(App $a) $baseURL = DI::baseUrl()->get(); - $xml = null; - - XML::fromArray([ + $xmlString = XML::fromArray([ 'XRD' => [ '@attributes' => [ 'xmlns' => 'http://docs.oasis-open.org/ns/xri/xrd-1.0', @@ -90,9 +88,9 @@ function oexchange_init(App $a) ] ], ], - ], $xml); + ]); - System::httpExit($xml->saveXML(), Response::TYPE_XML, 'application/xrd+xml'); + System::httpExit($xmlString, Response::TYPE_XML, 'application/xrd+xml'); } function oexchange_content(App $a) diff --git a/src/Core/System.php b/src/Core/System.php index 4f06bcf52..f94004a88 100644 --- a/src/Core/System.php +++ b/src/Core/System.php @@ -294,7 +294,7 @@ class System } DI::apiResponse()->setType(Response::TYPE_XML); - DI::apiResponse()->addContent(XML::fromArray(["result" => $result], $xml)); + DI::apiResponse()->addContent(XML::fromArray(['result' => $result])); DI::page()->exit(DI::apiResponse()->generate()); self::exit(); diff --git a/src/Module/Api/ApiResponse.php b/src/Module/Api/ApiResponse.php index a113dab84..2d54bc176 100644 --- a/src/Module/Api/ApiResponse.php +++ b/src/Module/Api/ApiResponse.php @@ -99,7 +99,7 @@ class ApiResponse extends Response $data3 = [$root_element => $data2]; - return XML::fromArray($data3, $xml, false, $namespaces); + return XML::fromArray($data3, $dummy, false, $namespaces); } /** diff --git a/src/Module/OpenSearch.php b/src/Module/OpenSearch.php index d5426cf38..36e8713d9 100644 --- a/src/Module/OpenSearch.php +++ b/src/Module/OpenSearch.php @@ -43,8 +43,6 @@ class OpenSearch extends BaseModule $baseUrl = DI::baseUrl()->get(); /** @var DOMDocument $xml */ - $xml = null; - XML::fromArray([ 'OpenSearchDescription' => [ '@attributes' => [ diff --git a/src/Module/ReallySimpleDiscovery.php b/src/Module/ReallySimpleDiscovery.php index 11ab3596d..d76094003 100644 --- a/src/Module/ReallySimpleDiscovery.php +++ b/src/Module/ReallySimpleDiscovery.php @@ -34,7 +34,6 @@ class ReallySimpleDiscovery extends BaseModule { protected function rawContent(array $request = []) { - $xml = null; $content = XML::fromArray([ 'rsd' => [ '@attributes' => [ @@ -67,7 +66,7 @@ class ReallySimpleDiscovery extends BaseModule ], ], ], - ], $xml); + ]); System::httpExit($content, Response::TYPE_XML); } } diff --git a/src/Module/WellKnown/HostMeta.php b/src/Module/WellKnown/HostMeta.php index fdebb05d7..fa6619920 100644 --- a/src/Module/WellKnown/HostMeta.php +++ b/src/Module/WellKnown/HostMeta.php @@ -48,7 +48,6 @@ class HostMeta extends BaseModule $domain = DI::baseUrl()->get(); - $xml = null; XML::fromArray([ 'XRD' => [ '@attributes' => [ diff --git a/src/Module/Xrd.php b/src/Module/Xrd.php index 7b008549d..ad2b25902 100644 --- a/src/Module/Xrd.php +++ b/src/Module/Xrd.php @@ -230,9 +230,7 @@ class Xrd extends BaseModule { $baseURL = $this->baseUrl->get(); - $xml = null; - - XML::fromArray([ + $xmlString = XML::fromArray([ 'XRD' => [ '@attributes' => [ 'xmlns' => 'http://docs.oasis-open.org/ns/xri/xrd-1.0', @@ -319,10 +317,10 @@ class Xrd extends BaseModule ] ], ], - ], $xml); + ]); header('Access-Control-Allow-Origin: *'); - System::httpExit($xml->saveXML(), Response::TYPE_XML, 'application/xrd+xml'); + System::httpExit($xmlString, Response::TYPE_XML, 'application/xrd+xml'); } } diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index bf6bfdd63..c0d0bc051 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -2855,7 +2855,7 @@ class Diaspora $namespaces = ['me' => ActivityNamespace::SALMON_ME]; - return XML::fromArray($xmldata, $xml, false, $namespaces); + return XML::fromArray($xmldata, $dummy, false, $namespaces); } /** @@ -2974,12 +2974,11 @@ class Diaspora * @param array $message The message data * * @return string The post XML + * @throws \Exception */ public static function buildPostXml(string $type, array $message): string { - $data = [$type => $message]; - - return XML::fromArray($data, $xml); + return XML::fromArray([$type => $message]); } /** diff --git a/src/Protocol/Salmon.php b/src/Protocol/Salmon.php index 7685c1dd9..50d1b931c 100644 --- a/src/Protocol/Salmon.php +++ b/src/Protocol/Salmon.php @@ -160,7 +160,7 @@ class Salmon $namespaces = ['me' => ActivityNamespace::SALMON_ME]; - $salmon = XML::fromArray($xmldata, $xml, false, $namespaces); + $salmon = XML::fromArray($xmldata, $dummy, false, $namespaces); // slap them $postResult = DI::httpClient()->post($url, $salmon, [ @@ -187,9 +187,7 @@ class Salmon ] ]; - $namespaces = ['me' => ActivityNamespace::SALMON_ME]; - - $salmon = XML::fromArray($xmldata, $xml, false, $namespaces); + $salmon = XML::fromArray($xmldata, $dummy, false, $namespaces); // slap them $postResult = DI::httpClient()->post($url, $salmon, [ @@ -214,9 +212,7 @@ class Salmon ] ]; - $namespaces = ['me' => ActivityNamespace::SALMON_ME]; - - $salmon = XML::fromArray($xmldata, $xml, false, $namespaces); + $salmon = XML::fromArray($xmldata, $dummy, false, $namespaces); // slap them $postResult = DI::httpClient()->post($url, $salmon, [ diff --git a/src/Util/XML.php b/src/Util/XML.php index 50ecc6d2c..0cdf1f34e 100644 --- a/src/Util/XML.php +++ b/src/Util/XML.php @@ -37,14 +37,15 @@ class XML /** * Creates an XML structure out of a given array * - * @param array $array The array of the XML structure that will be generated - * @param object $xml The created XML will be returned by reference - * @param bool $remove_header Should the XML header be removed or not? - * @param array $namespaces List of namespaces - * @param bool $root interally used parameter. Mustn't be used from outside. + * @param array $array The array of the XML structure that will be generated + * @param object|null $xml The created XML will be returned by reference + * @param bool $remove_header Should the XML header be removed or not? + * @param array $namespaces List of namespaces + * @param bool $root interally used parameter. Mustn't be used from outside. * @return string + * @throws \Exception */ - public static function fromArray(array $array, &$xml, bool $remove_header = false, array $namespaces = [], bool $root = true): string + public static function fromArray(array $array, object &$xml = null, bool $remove_header = false, array $namespaces = [], bool $root = true): string { if ($root) { foreach ($array as $key => $value) { @@ -125,7 +126,7 @@ class XML if (!is_array($value)) { $element = $xml->addChild($key, self::escape($value ?? ''), $namespace); - } elseif (is_array($value)) { + } else { $element = $xml->addChild($key, null, $namespace); self::fromArray($value, $element, $remove_header, $namespaces, false); } From 9c256ad76f191149c0917719a59b019aa301dfa3 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 31 Dec 2022 12:55:13 -0500 Subject: [PATCH 2/2] Remove obsolete OExchange module and reference - Protocol looks unsupported for a decade now --- mod/oexchange.php | 126 ------------------------------ src/Module/WellKnown/HostMeta.php | 7 -- 2 files changed, 133 deletions(-) delete mode 100644 mod/oexchange.php diff --git a/mod/oexchange.php b/mod/oexchange.php deleted file mode 100644 index 4fbf7ffeb..000000000 --- a/mod/oexchange.php +++ /dev/null @@ -1,126 +0,0 @@ -. - * - */ - -use Friendica\App; -use Friendica\Content\Text\BBCode; -use Friendica\Content\Text\HTML; -use Friendica\Core\System; -use Friendica\DI; -use Friendica\Module\Response; -use Friendica\Module\Security\Login; -use Friendica\Util\XML; - -function oexchange_init(App $a) -{ - if ((DI::args()->getArgc() <= 1) || (DI::args()->getArgv()[1] != 'xrd')) { - return; - } - - $baseURL = DI::baseUrl()->get(); - - $xmlString = XML::fromArray([ - 'XRD' => [ - '@attributes' => [ - 'xmlns' => 'http://docs.oasis-open.org/ns/xri/xrd-1.0', - ], - 'Subject' => $baseURL, - '1:Property' => [ - '@attributes' => [ - 'type' => 'http://www.oexchange.org/spec/0.8/prop/vendor', - ], - 'Friendica' - ], - '2:Property' => [ - '@attributes' => [ - 'type' => 'http://www.oexchange.org/spec/0.8/prop/title', - ], - 'Friendica Social Network' - ], - '3:Property' => [ - '@attributes' => [ - 'type' => 'http://www.oexchange.org/spec/0.8/prop/name', - ], - 'Friendica' - ], - '4:Property' => [ - '@attributes' => [ - 'type' => 'http://www.oexchange.org/spec/0.8/prop/prompt', - ], - 'Send to Friendica' - ], - '1:link' => [ - '@attributes' => [ - 'rel' => 'icon', - 'type' => 'image/png', - 'href' => $baseURL . '/images/friendica-16.png' - ] - ], - '2:link' => [ - '@attributes' => [ - 'rel' => 'icon32', - 'type' => 'image/png', - 'href' => $baseURL . '/images/friendica-32.png' - ] - ], - '3:link' => [ - '@attributes' => [ - 'rel' => 'http://www.oexchange.org/spec/0.8/rel/offer', - 'type' => 'text/html', - 'href' => $baseURL . '/oexchange' - ] - ], - ], - ]); - - System::httpExit($xmlString, Response::TYPE_XML, 'application/xrd+xml'); -} - -function oexchange_content(App $a) -{ - if (!DI::userSession()->getLocalUserId()) { - $o = Login::form(); - return $o; - } - - if ((DI::args()->getArgc() > 1) && DI::args()->getArgv()[1] === 'done') { - return; - } - - $url = !empty($_REQUEST['url']) ? trim($_REQUEST['url']) : ''; - $title = !empty($_REQUEST['title']) ? trim($_REQUEST['title']) : ''; - $description = !empty($_REQUEST['description']) ? trim($_REQUEST['description']) : ''; - $tags = !empty($_REQUEST['tags']) ? trim($_REQUEST['tags']) : ''; - - $s = BBCode::embedURL($url, true, $title, $description, $tags); - - if (!strlen($s)) { - return; - } - - $post = []; - - $post['return'] = '/oexchange/done'; - $post['body'] = HTML::toBBCode($s); - - $_REQUEST = $post; - require_once 'mod/item.php'; - item_post($a); -} diff --git a/src/Module/WellKnown/HostMeta.php b/src/Module/WellKnown/HostMeta.php index fa6619920..512ff8dd0 100644 --- a/src/Module/WellKnown/HostMeta.php +++ b/src/Module/WellKnown/HostMeta.php @@ -80,13 +80,6 @@ class HostMeta extends BaseModule 'href' => $domain . '/amcd' ] ], - '5:link' => [ - '@attributes' => [ - 'rel' => 'http://oexchange.org/spec/0.8/rel/resident-target', - 'type' => 'application/xrd+xml', - 'href' => $domain . '/oexchange/xrd' - ] - ], 'Property' => [ '@attributes' => [ 'type' => 'http://salmon-protocol.org/ns/magic-key',