]> git.mxchange.org Git - friendica.git/blob - mod/oexchange.php
get markup template
[friendica.git] / mod / oexchange.php
1 <?php
2 /**
3  * @file mod/oexchange.php
4  */
5 use Friendica\App;
6 use Friendica\Core\L10n;
7 use Friendica\Core\Renderer;
8 use Friendica\Core\System;
9 use Friendica\Module\Login;
10 use Friendica\Util\Network;
11
12 function oexchange_init(App $a) {
13
14         if (($a->argc > 1) && ($a->argv[1] === 'xrd')) {
15                 $tpl = Renderer::getMarkupTemplate('oexchange_xrd.tpl');
16
17                 $o = Renderer::replaceMacros($tpl, ['$base' => System::baseUrl()]);
18                 echo $o;
19                 killme();
20         }
21 }
22
23 function oexchange_content(App $a) {
24
25         if (!local_user()) {
26                 $o = Login::form();
27                 return $o;
28         }
29
30         if (($a->argc > 1) && $a->argv[1] === 'done') {
31                 info(L10n::t('Post successful.') . EOL);
32                 return;
33         }
34
35         $url = ((x($_REQUEST,'url') && strlen($_REQUEST['url']))
36                 ? urlencode(notags(trim($_REQUEST['url']))) : '');
37         $title = ((x($_REQUEST,'title') && strlen($_REQUEST['title']))
38                 ? '&title=' . urlencode(notags(trim($_REQUEST['title']))) : '');
39         $description = ((x($_REQUEST,'description') && strlen($_REQUEST['description']))
40                 ? '&description=' . urlencode(notags(trim($_REQUEST['description']))) : '');
41         $tags = ((x($_REQUEST,'tags') && strlen($_REQUEST['tags']))
42                 ? '&tags=' . urlencode(notags(trim($_REQUEST['tags']))) : '');
43
44         $s = Network::fetchUrl(System::baseUrl() . '/parse_url?f=&url=' . $url . $title . $description . $tags);
45
46         if (!strlen($s)) {
47                 return;
48         }
49
50         $post = [];
51
52         $post['profile_uid'] = local_user();
53         $post['return'] = '/oexchange/done';
54         $post['body'] = Friendica\Content\Text\HTML::toBBCode($s);
55
56         $_REQUEST = $post;
57         require_once('mod/item.php');
58         item_post($a);
59 }