]> git.mxchange.org Git - friendica.git/blob - mod/oexchange.php
79a5b06fdb9c60e0e3fa9ee122f4f9180cb3bee8
[friendica.git] / mod / oexchange.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 use Friendica\App;
23 use Friendica\Content\Text\BBCode;
24 use Friendica\Core\System;
25 use Friendica\DI;
26 use Friendica\Module\Response;
27 use Friendica\Module\Security\Login;
28 use Friendica\Util\XML;
29
30 function oexchange_init(App $a)
31 {
32         if ((DI::args()->getArgc() <= 1) || (DI::args()->getArgv()[1] != 'xrd')) {
33                 return;
34         }
35
36         $baseURL = DI::baseUrl()->get();
37
38         $xml = null;
39
40         XML::fromArray([
41                 'XRD' => [
42                         '@attributes' => [
43                                 'xmlns'    => 'http://docs.oasis-open.org/ns/xri/xrd-1.0',
44                         ],
45                         'Subject' => $baseURL,
46                         '1:Property' => [
47                                 '@attributes' => [
48                                         'type'  => 'http://www.oexchange.org/spec/0.8/prop/vendor',
49                                 ],
50                                 'Friendica'
51                         ],
52                         '2:Property' => [
53                                 '@attributes' => [
54                                         'type'  => 'http://www.oexchange.org/spec/0.8/prop/title',
55                                 ],
56                                 'Friendica Social Network'
57                         ],
58                         '3:Property' => [
59                                 '@attributes' => [
60                                         'type'  => 'http://www.oexchange.org/spec/0.8/prop/name',
61                                 ],
62                                 'Friendica'
63                         ],
64                         '4:Property' => [
65                                 '@attributes' => [
66                                         'type'  => 'http://www.oexchange.org/spec/0.8/prop/prompt',
67                                 ],
68                                 'Send to Friendica'
69                         ],
70                         '1:link' => [
71                                 '@attributes' => [
72                                         'rel'  => 'icon',
73                                         'type' => 'image/png',
74                                         'href' => $baseURL . '/images/friendica-16.png'
75                                 ]
76                         ],
77                         '2:link' => [
78                                 '@attributes' => [
79                                         'rel'  => 'icon32',
80                                         'type' => 'image/png',
81                                         'href' => $baseURL . '/images/friendica-32.png'
82                                 ]
83                         ],
84                         '3:link' => [
85                                 '@attributes' => [
86                                         'rel'  => 'http://www.oexchange.org/spec/0.8/rel/offer',
87                                         'type' => 'text/html',
88                                         'href' => $baseURL . '/oexchange'
89                                 ]
90                         ],
91                 ],
92         ], $xml);
93
94         System::httpExit($xml->saveXML(), Response::TYPE_XML, 'application/xrd+xml');
95 }
96
97 function oexchange_content(App $a)
98 {
99         if (!local_user()) {
100                 $o = Login::form();
101                 return $o;
102         }
103
104         if ((DI::args()->getArgc() > 1) && DI::args()->getArgv()[1] === 'done') {
105                 return;
106         }
107
108         $url         = !empty($_REQUEST['url'])         ? trim($_REQUEST['url'])         : '';
109         $title       = !empty($_REQUEST['title'])       ? trim($_REQUEST['title'])       : '';
110         $description = !empty($_REQUEST['description']) ? trim($_REQUEST['description']) : '';
111         $tags        = !empty($_REQUEST['tags'])        ? trim($_REQUEST['tags'])        : '';
112
113         $s = BBCode::embedURL($url, true, $title, $description, $tags);
114
115         if (!strlen($s)) {
116                 return;
117         }
118
119         $post = [];
120
121         $post['profile_uid'] = local_user();
122         $post['return'] = '/oexchange/done';
123         $post['body'] = HTML::toBBCode($s);
124
125         $_REQUEST = $post;
126         require_once 'mod/item.php';
127         item_post($a);
128 }