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