]> git.mxchange.org Git - friendica.git/blob - mod/oexchange.php
Merge pull request #7893 from annando/api-attachments
[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 use Friendica\Util\Strings;
12
13 function oexchange_init(App $a) {
14
15         if (($a->argc > 1) && ($a->argv[1] === 'xrd')) {
16                 $tpl = Renderer::getMarkupTemplate('oexchange_xrd.tpl');
17
18                 $o = Renderer::replaceMacros($tpl, ['$base' => System::baseUrl()]);
19                 echo $o;
20                 exit();
21         }
22 }
23
24 function oexchange_content(App $a) {
25
26         if (!local_user()) {
27                 $o = Login::form();
28                 return $o;
29         }
30
31         if (($a->argc > 1) && $a->argv[1] === 'done') {
32                 info(L10n::t('Post successful.') . EOL);
33                 return;
34         }
35
36         $url = ((!empty($_REQUEST['url']))
37                 ? urlencode(Strings::escapeTags(trim($_REQUEST['url']))) : '');
38         $title = ((!empty($_REQUEST['title']))
39                 ? '&title=' . urlencode(Strings::escapeTags(trim($_REQUEST['title']))) : '');
40         $description = ((!empty($_REQUEST['description']))
41                 ? '&description=' . urlencode(Strings::escapeTags(trim($_REQUEST['description']))) : '');
42         $tags = ((!empty($_REQUEST['tags']))
43                 ? '&tags=' . urlencode(Strings::escapeTags(trim($_REQUEST['tags']))) : '');
44
45         $s = Network::fetchUrl(System::baseUrl() . '/parse_url?f=&url=' . $url . $title . $description . $tags);
46
47         if (!strlen($s)) {
48                 return;
49         }
50
51         $post = [];
52
53         $post['profile_uid'] = local_user();
54         $post['return'] = '/oexchange/done';
55         $post['body'] = Friendica\Content\Text\HTML::toBBCode($s);
56
57         $_REQUEST = $post;
58         require_once('mod/item.php');
59         item_post($a);
60 }