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