]> git.mxchange.org Git - friendica.git/blob - mod/oexchange.php
Merge pull request #12025 from annando/no-boot-src-module
[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\Content\Text\HTML;
25 use Friendica\Core\Session;
26 use Friendica\Core\System;
27 use Friendica\DI;
28 use Friendica\Module\Response;
29 use Friendica\Module\Security\Login;
30 use Friendica\Util\XML;
31
32 function oexchange_init(App $a)
33 {
34         if ((DI::args()->getArgc() <= 1) || (DI::args()->getArgv()[1] != 'xrd')) {
35                 return;
36         }
37
38         $baseURL = DI::baseUrl()->get();
39
40         $xml = null;
41
42         XML::fromArray([
43                 'XRD' => [
44                         '@attributes' => [
45                                 'xmlns'    => 'http://docs.oasis-open.org/ns/xri/xrd-1.0',
46                         ],
47                         'Subject' => $baseURL,
48                         '1:Property' => [
49                                 '@attributes' => [
50                                         'type'  => 'http://www.oexchange.org/spec/0.8/prop/vendor',
51                                 ],
52                                 'Friendica'
53                         ],
54                         '2:Property' => [
55                                 '@attributes' => [
56                                         'type'  => 'http://www.oexchange.org/spec/0.8/prop/title',
57                                 ],
58                                 'Friendica Social Network'
59                         ],
60                         '3:Property' => [
61                                 '@attributes' => [
62                                         'type'  => 'http://www.oexchange.org/spec/0.8/prop/name',
63                                 ],
64                                 'Friendica'
65                         ],
66                         '4:Property' => [
67                                 '@attributes' => [
68                                         'type'  => 'http://www.oexchange.org/spec/0.8/prop/prompt',
69                                 ],
70                                 'Send to Friendica'
71                         ],
72                         '1:link' => [
73                                 '@attributes' => [
74                                         'rel'  => 'icon',
75                                         'type' => 'image/png',
76                                         'href' => $baseURL . '/images/friendica-16.png'
77                                 ]
78                         ],
79                         '2:link' => [
80                                 '@attributes' => [
81                                         'rel'  => 'icon32',
82                                         'type' => 'image/png',
83                                         'href' => $baseURL . '/images/friendica-32.png'
84                                 ]
85                         ],
86                         '3:link' => [
87                                 '@attributes' => [
88                                         'rel'  => 'http://www.oexchange.org/spec/0.8/rel/offer',
89                                         'type' => 'text/html',
90                                         'href' => $baseURL . '/oexchange'
91                                 ]
92                         ],
93                 ],
94         ], $xml);
95
96         System::httpExit($xml->saveXML(), Response::TYPE_XML, 'application/xrd+xml');
97 }
98
99 function oexchange_content(App $a)
100 {
101         if (!Session::getLocalUser()) {
102                 $o = Login::form();
103                 return $o;
104         }
105
106         if ((DI::args()->getArgc() > 1) && DI::args()->getArgv()[1] === 'done') {
107                 return;
108         }
109
110         $url         = !empty($_REQUEST['url'])         ? trim($_REQUEST['url'])         : '';
111         $title       = !empty($_REQUEST['title'])       ? trim($_REQUEST['title'])       : '';
112         $description = !empty($_REQUEST['description']) ? trim($_REQUEST['description']) : '';
113         $tags        = !empty($_REQUEST['tags'])        ? trim($_REQUEST['tags'])        : '';
114
115         $s = BBCode::embedURL($url, true, $title, $description, $tags);
116
117         if (!strlen($s)) {
118                 return;
119         }
120
121         $post = [];
122
123         $post['profile_uid'] = Session::getLocalUser();
124         $post['return'] = '/oexchange/done';
125         $post['body'] = HTML::toBBCode($s);
126
127         $_REQUEST = $post;
128         require_once 'mod/item.php';
129         item_post($a);
130 }