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