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