]> git.mxchange.org Git - friendica.git/blob - mod/oexchange.php
Merge pull request #11059 from MrPetovan/bug/notices
[friendica.git] / mod / oexchange.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, 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\Renderer;
24 use Friendica\DI;
25 use Friendica\Module\Security\Login;
26
27 function oexchange_init(App $a) {
28
29         if ((DI::args()->getArgc() > 1) && (DI::args()->getArgv()[1] === 'xrd')) {
30                 $tpl = Renderer::getMarkupTemplate('oexchange_xrd.tpl');
31
32                 $o = Renderer::replaceMacros($tpl, ['$base' => DI::baseUrl()]);
33                 echo $o;
34                 exit();
35         }
36 }
37
38 function oexchange_content(App $a) {
39
40         if (!local_user()) {
41                 $o = Login::form();
42                 return $o;
43         }
44
45         if ((DI::args()->getArgc() > 1) && DI::args()->getArgv()[1] === 'done') {
46                 return;
47         }
48
49         $url         = !empty($_REQUEST['url'])         ? trim($_REQUEST['url'])         : '';
50         $title       = !empty($_REQUEST['title'])       ? trim($_REQUEST['title'])       : '';
51         $description = !empty($_REQUEST['description']) ? trim($_REQUEST['description']) : '';
52         $tags        = !empty($_REQUEST['tags'])        ? trim($_REQUEST['tags'])        : '';
53
54         $s = \Friendica\Content\Text\BBCode::embedURL($url, true, $title, $description, $tags);
55
56         if (!strlen($s)) {
57                 return;
58         }
59
60         $post = [];
61
62         $post['profile_uid'] = local_user();
63         $post['return'] = '/oexchange/done';
64         $post['body'] = Friendica\Content\Text\HTML::toBBCode($s);
65
66         $_REQUEST = $post;
67         require_once('mod/item.php');
68         item_post($a);
69 }