1
0
Fork 0

Merge pull request #12585 from MrPetovan/task/4090-mod-oexchange

Remove obsolete OExchange module and reference
This commit is contained in:
Michael Vogel 2023-01-02 13:15:32 +01:00 committed by GitHub
commit 6318406951
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 20 additions and 165 deletions

View file

@ -1,128 +0,0 @@
<?php
/**
* @copyright Copyright (C) 2010-2023, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
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();
$xml = null;
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'
]
],
],
], $xml);
System::httpExit($xml->saveXML(), 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);
}

View file

@ -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();

View file

@ -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);
}
/**

View file

@ -43,8 +43,6 @@ class OpenSearch extends BaseModule
$baseUrl = DI::baseUrl()->get();
/** @var DOMDocument $xml */
$xml = null;
XML::fromArray([
'OpenSearchDescription' => [
'@attributes' => [

View file

@ -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);
}
}

View file

@ -48,7 +48,6 @@ class HostMeta extends BaseModule
$domain = DI::baseUrl()->get();
$xml = null;
XML::fromArray([
'XRD' => [
'@attributes' => [
@ -81,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',

View file

@ -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');
}
}

View file

@ -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]);
}
/**

View file

@ -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, [

View file

@ -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);
}