]> git.mxchange.org Git - friendica.git/blob - src/Module/Item/Compose.php
Remove deprecated App::removeBaseURL - process methods to DI::baseUrl()->remove()
[friendica.git] / src / Module / Item / Compose.php
1 <?php
2
3 namespace Friendica\Module\Item;
4
5 use Friendica\BaseModule;
6 use Friendica\Content\Feature;
7 use Friendica\Core\ACL;
8 use Friendica\Core\Config;
9 use Friendica\Core\Hook;
10 use Friendica\Core\L10n;
11 use Friendica\Core\Renderer;
12 use Friendica\Core\System;
13 use Friendica\Core\Theme;
14 use Friendica\Database\DBA;
15 use Friendica\DI;
16 use Friendica\Model\Contact;
17 use Friendica\Model\FileTag;
18 use Friendica\Model\Group;
19 use Friendica\Model\Item;
20 use Friendica\Model\User;
21 use Friendica\Module\Security\Login;
22 use Friendica\Network\HTTPException\NotImplementedException;
23 use Friendica\Util\ACLFormatter;
24 use Friendica\Util\Crypto;
25
26 class Compose extends BaseModule
27 {
28         public static function post(array $parameters = [])
29         {
30                 if (!empty($_REQUEST['body'])) {
31                         $_REQUEST['return'] = 'network';
32                         require_once 'mod/item.php';
33                         item_post(DI::app());
34                 } else {
35                         notice(L10n::t('Please enter a post body.'));
36                 }
37         }
38
39         public static function content(array $parameters = [])
40         {
41                 if (!local_user()) {
42                         return Login::form('compose', false);
43                 }
44
45                 $a = DI::app();
46
47                 if ($a->getCurrentTheme() !== 'frio') {
48                         throw new NotImplementedException(L10n::t('This feature is only available with the frio theme.'));
49                 }
50
51                 /// @TODO Retrieve parameter from router
52                 $posttype = $parameters['type'] ?? Item::PT_ARTICLE;
53                 if (!in_array($posttype, [Item::PT_ARTICLE, Item::PT_PERSONAL_NOTE])) {
54                         switch ($posttype) {
55                                 case 'note':
56                                         $posttype = Item::PT_PERSONAL_NOTE;
57                                         break;
58                                 default:
59                                         $posttype = Item::PT_ARTICLE;
60                                         break;
61                         }
62                 }
63
64                 $user = User::getById(local_user(), ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'hidewall', 'default-location']);
65
66                 $aclFormatter = DI::aclFormatter();
67
68                 $contact_allow_list = $aclFormatter->expand($user['allow_cid']);
69                 $group_allow_list   = $aclFormatter->expand($user['allow_gid']);
70                 $contact_deny_list  = $aclFormatter->expand($user['deny_cid']);
71                 $group_deny_list    = $aclFormatter->expand($user['deny_gid']);
72
73                 switch ($posttype) {
74                         case Item::PT_PERSONAL_NOTE:
75                                 $compose_title = L10n::t('Compose new personal note');
76                                 $type = 'note';
77                                 $doesFederate = false;
78                                 $contact_allow_list = [$a->contact['id']];
79                                 $group_allow_list = [];
80                                 $contact_deny_list = [];
81                                 $group_deny_list = [];
82                                 break;
83                         default:
84                                 $compose_title = L10n::t('Compose new post');
85                                 $type = 'post';
86                                 $doesFederate = true;
87
88                                 $contact_allow = $_REQUEST['contact_allow'] ?? '';
89                                 $group_allow = $_REQUEST['group_allow'] ?? '';
90                                 $contact_deny = $_REQUEST['contact_deny'] ?? '';
91                                 $group_deny = $_REQUEST['group_deny'] ?? '';
92
93                                 if ($contact_allow
94                                         . $group_allow
95                                         . $contact_deny
96                                     . $group_deny)
97                                 {
98                                         $contact_allow_list = $contact_allow ? explode(',', $contact_allow) : [];
99                                         $group_allow_list   = $group_allow   ? explode(',', $group_allow)   : [];
100                                         $contact_deny_list  = $contact_deny  ? explode(',', $contact_deny)  : [];
101                                         $group_deny_list    = $group_deny    ? explode(',', $group_deny)    : [];
102                                 }
103
104                                 break;
105                 }
106
107                 $title         = $_REQUEST['title']         ?? '';
108                 $category      = $_REQUEST['category']      ?? '';
109                 $body          = $_REQUEST['body']          ?? '';
110                 $location      = $_REQUEST['location']      ?? $user['default-location'];
111                 $wall          = $_REQUEST['wall']          ?? $type == 'post';
112
113                 $jotplugins = '';
114                 Hook::callAll('jot_tool', $jotplugins);
115
116                 // Output
117                 $a->page->registerFooterScript(Theme::getPathForFile('js/ajaxupload.js'));
118                 $a->page->registerFooterScript(Theme::getPathForFile('js/linkPreview.js'));
119                 $a->page->registerFooterScript(Theme::getPathForFile('js/compose.js'));
120
121                 $tpl = Renderer::getMarkupTemplate('item/compose.tpl');
122                 return Renderer::replaceMacros($tpl, [
123                         '$compose_title'=> $compose_title,
124                         '$visibility_title'=> L10n::t('Visibility'),
125                         '$id'           => 0,
126                         '$posttype'     => $posttype,
127                         '$type'         => $type,
128                         '$wall'         => $wall,
129                         '$default'      => '',
130                         '$mylink'       => DI::baseUrl()->remove($a->contact['url']),
131                         '$mytitle'      => L10n::t('This is you'),
132                         '$myphoto'      => DI::baseUrl()->remove($a->contact['thumb']),
133                         '$submit'       => L10n::t('Submit'),
134                         '$edbold'       => L10n::t('Bold'),
135                         '$editalic'     => L10n::t('Italic'),
136                         '$eduline'      => L10n::t('Underline'),
137                         '$edquote'      => L10n::t('Quote'),
138                         '$edcode'       => L10n::t('Code'),
139                         '$edimg'        => L10n::t('Image'),
140                         '$edurl'        => L10n::t('Link'),
141                         '$edattach'     => L10n::t('Link or Media'),
142                         '$prompttext'   => L10n::t('Please enter a image/video/audio/webpage URL:'),
143                         '$preview'      => L10n::t('Preview'),
144                         '$location_set' => L10n::t('Set your location'),
145                         '$location_clear' => L10n::t('Clear the location'),
146                         '$location_unavailable' => L10n::t('Location services are unavailable on your device'),
147                         '$location_disabled' => L10n::t('Location services are disabled. Please check the website\'s permissions on your device'),
148                         '$wait'         => L10n::t('Please wait'),
149                         '$placeholdertitle' => L10n::t('Set title'),
150                         '$placeholdercategory' => (Feature::isEnabled(local_user(),'categories') ? L10n::t('Categories (comma-separated list)') : ''),
151
152                         '$title'        => $title,
153                         '$category'     => $category,
154                         '$body'         => $body,
155                         '$location'     => $location,
156
157                         '$contact_allow'=> implode(',', $contact_allow_list),
158                         '$group_allow'  => implode(',', $group_allow_list),
159                         '$contact_deny' => implode(',', $contact_deny_list),
160                         '$group_deny'   => implode(',', $group_deny_list),
161
162                         '$jotplugins'   => $jotplugins,
163                         '$sourceapp'    => L10n::t($a->sourcename),
164                         '$rand_num'     => Crypto::randomDigits(12),
165                         '$acl_selector'  => ACL::getFullSelectorHTML($a->page, $a->user, $doesFederate, [
166                                 'allow_cid' => $contact_allow_list,
167                                 'allow_gid' => $group_allow_list,
168                                 'deny_cid'  => $contact_deny_list,
169                                 'deny_gid'  => $group_deny_list,
170                         ]),
171                 ]);
172         }
173 }