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