3 * @copyright Copyright (C) 2010-2022, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module\Item;
25 use Friendica\BaseModule;
26 use Friendica\Content\Feature;
27 use Friendica\Core\ACL;
28 use Friendica\Core\Hook;
29 use Friendica\Core\Renderer;
30 use Friendica\Core\Theme;
31 use Friendica\Database\DBA;
33 use Friendica\Model\Contact;
34 use Friendica\Model\Item;
35 use Friendica\Model\User;
36 use Friendica\Module\Security\Login;
37 use Friendica\Network\HTTPException\NotImplementedException;
38 use Friendica\Util\Crypto;
39 use Friendica\Util\Temporal;
41 class Compose extends BaseModule
43 protected function post(array $request = [])
45 if (!empty($_REQUEST['body'])) {
46 $_REQUEST['return'] = 'network';
47 require_once 'mod/item.php';
50 notice(DI::l10n()->t('Please enter a post body.'));
54 protected function content(array $request = []): string
57 return Login::form('compose', false);
62 if ($a->getCurrentTheme() !== 'frio') {
63 throw new NotImplementedException(DI::l10n()->t('This feature is only available with the frio theme.'));
66 /// @TODO Retrieve parameter from router
67 $posttype = $this->parameters['type'] ?? Item::PT_ARTICLE;
68 if (!in_array($posttype, [Item::PT_ARTICLE, Item::PT_PERSONAL_NOTE])) {
71 $posttype = Item::PT_PERSONAL_NOTE;
74 $posttype = Item::PT_ARTICLE;
79 $user = User::getById(local_user(), ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'default-location']);
81 $aclFormatter = DI::aclFormatter();
83 $contact_allow_list = $aclFormatter->expand($user['allow_cid']);
84 $group_allow_list = $aclFormatter->expand($user['allow_gid']);
85 $contact_deny_list = $aclFormatter->expand($user['deny_cid']);
86 $group_deny_list = $aclFormatter->expand($user['deny_gid']);
89 case Item::PT_PERSONAL_NOTE:
90 $compose_title = DI::l10n()->t('Compose new personal note');
92 $doesFederate = false;
93 $contact_allow_list = [$a->getContactId()];
94 $group_allow_list = [];
95 $contact_deny_list = [];
96 $group_deny_list = [];
99 $compose_title = DI::l10n()->t('Compose new post');
101 $doesFederate = true;
103 $contact_allow = $_REQUEST['contact_allow'] ?? '';
104 $group_allow = $_REQUEST['group_allow'] ?? '';
105 $contact_deny = $_REQUEST['contact_deny'] ?? '';
106 $group_deny = $_REQUEST['group_deny'] ?? '';
113 $contact_allow_list = $contact_allow ? explode(',', $contact_allow) : [];
114 $group_allow_list = $group_allow ? explode(',', $group_allow) : [];
115 $contact_deny_list = $contact_deny ? explode(',', $contact_deny) : [];
116 $group_deny_list = $group_deny ? explode(',', $group_deny) : [];
122 $title = $_REQUEST['title'] ?? '';
123 $category = $_REQUEST['category'] ?? '';
124 $body = $_REQUEST['body'] ?? '';
125 $location = $_REQUEST['location'] ?? $user['default-location'];
126 $wall = $_REQUEST['wall'] ?? $type == 'post';
129 Hook::callAll('jot_tool', $jotplugins);
132 DI::page()->registerFooterScript(Theme::getPathForFile('js/ajaxupload.js'));
133 DI::page()->registerFooterScript(Theme::getPathForFile('js/linkPreview.js'));
134 DI::page()->registerFooterScript(Theme::getPathForFile('js/compose.js'));
136 $contact = Contact::getById($a->getContactId());
138 if (DI::config()->get(local_user(), 'system', 'set_creation_date')) {
139 $created_at = Temporal::getDateTimeField(
140 new \DateTime(DBA::NULL_DATETIME),
141 new \DateTime('now'),
143 $this->l10n->t('Created at'),
150 $tpl = Renderer::getMarkupTemplate('item/compose.tpl');
151 return Renderer::replaceMacros($tpl, [
152 '$compose_title'=> $compose_title,
153 '$visibility_title'=> DI::l10n()->t('Visibility'),
155 '$posttype' => $posttype,
159 '$mylink' => DI::baseUrl()->remove($contact['url']),
160 '$mytitle' => DI::l10n()->t('This is you'),
161 '$myphoto' => DI::baseUrl()->remove($contact['thumb']),
162 '$submit' => DI::l10n()->t('Submit'),
163 '$edbold' => DI::l10n()->t('Bold'),
164 '$editalic' => DI::l10n()->t('Italic'),
165 '$eduline' => DI::l10n()->t('Underline'),
166 '$edquote' => DI::l10n()->t('Quote'),
167 '$edcode' => DI::l10n()->t('Code'),
168 '$edimg' => DI::l10n()->t('Image'),
169 '$edurl' => DI::l10n()->t('Link'),
170 '$edattach' => DI::l10n()->t('Link or Media'),
171 '$prompttext' => DI::l10n()->t('Please enter a image/video/audio/webpage URL:'),
172 '$preview' => DI::l10n()->t('Preview'),
173 '$location_set' => DI::l10n()->t('Set your location'),
174 '$location_clear' => DI::l10n()->t('Clear the location'),
175 '$location_unavailable' => DI::l10n()->t('Location services are unavailable on your device'),
176 '$location_disabled' => DI::l10n()->t('Location services are disabled. Please check the website\'s permissions on your device'),
177 '$wait' => DI::l10n()->t('Please wait'),
178 '$placeholdertitle' => DI::l10n()->t('Set title'),
179 '$placeholdercategory' => (Feature::isEnabled(local_user(),'categories') ? DI::l10n()->t('Categories (comma-separated list)') : ''),
180 '$scheduled_at' => Temporal::getDateTimeField(
182 new DateTime('now + 6 months'),
184 DI::l10n()->t('Scheduled at'),
187 '$created_at' => $created_at,
189 '$category' => $category,
191 '$location' => $location,
193 '$contact_allow'=> implode(',', $contact_allow_list),
194 '$group_allow' => implode(',', $group_allow_list),
195 '$contact_deny' => implode(',', $contact_deny_list),
196 '$group_deny' => implode(',', $group_deny_list),
198 '$jotplugins' => $jotplugins,
199 '$rand_num' => Crypto::randomDigits(12),
200 '$acl_selector' => ACL::getFullSelectorHTML(DI::page(), $a->getLoggedInUserId(), $doesFederate, [
201 'allow_cid' => $contact_allow_list,
202 'allow_gid' => $group_allow_list,
203 'deny_cid' => $contact_deny_list,
204 'deny_gid' => $group_deny_list,