3 * @copyright Copyright (C) 2010-2021, 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;
32 use Friendica\Model\Contact;
33 use Friendica\Model\Item;
34 use Friendica\Model\User;
35 use Friendica\Module\Security\Login;
36 use Friendica\Network\HTTPException\NotImplementedException;
37 use Friendica\Util\Crypto;
38 use Friendica\Util\DateTimeFormat;
39 use Friendica\Util\Temporal;
41 class Compose extends BaseModule
43 protected function post(array $request = [], array $post = [])
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 $tpl = Renderer::getMarkupTemplate('item/compose.tpl');
139 return Renderer::replaceMacros($tpl, [
140 '$compose_title'=> $compose_title,
141 '$visibility_title'=> DI::l10n()->t('Visibility'),
143 '$posttype' => $posttype,
147 '$mylink' => DI::baseUrl()->remove($contact['url']),
148 '$mytitle' => DI::l10n()->t('This is you'),
149 '$myphoto' => DI::baseUrl()->remove($contact['thumb']),
150 '$submit' => DI::l10n()->t('Submit'),
151 '$edbold' => DI::l10n()->t('Bold'),
152 '$editalic' => DI::l10n()->t('Italic'),
153 '$eduline' => DI::l10n()->t('Underline'),
154 '$edquote' => DI::l10n()->t('Quote'),
155 '$edcode' => DI::l10n()->t('Code'),
156 '$edimg' => DI::l10n()->t('Image'),
157 '$edurl' => DI::l10n()->t('Link'),
158 '$edattach' => DI::l10n()->t('Link or Media'),
159 '$prompttext' => DI::l10n()->t('Please enter a image/video/audio/webpage URL:'),
160 '$preview' => DI::l10n()->t('Preview'),
161 '$location_set' => DI::l10n()->t('Set your location'),
162 '$location_clear' => DI::l10n()->t('Clear the location'),
163 '$location_unavailable' => DI::l10n()->t('Location services are unavailable on your device'),
164 '$location_disabled' => DI::l10n()->t('Location services are disabled. Please check the website\'s permissions on your device'),
165 '$wait' => DI::l10n()->t('Please wait'),
166 '$placeholdertitle' => DI::l10n()->t('Set title'),
167 '$placeholdercategory' => (Feature::isEnabled(local_user(),'categories') ? DI::l10n()->t('Categories (comma-separated list)') : ''),
168 '$scheduled_at' => Temporal::getDateTimeField(
170 new DateTime('now + 6 months'),
172 DI::l10n()->t('Scheduled at'),
177 '$category' => $category,
179 '$location' => $location,
181 '$contact_allow'=> implode(',', $contact_allow_list),
182 '$group_allow' => implode(',', $group_allow_list),
183 '$contact_deny' => implode(',', $contact_deny_list),
184 '$group_deny' => implode(',', $group_deny_list),
186 '$jotplugins' => $jotplugins,
187 '$rand_num' => Crypto::randomDigits(12),
188 '$acl_selector' => ACL::getFullSelectorHTML(DI::page(), $a->getLoggedInUserId(), $doesFederate, [
189 'allow_cid' => $contact_allow_list,
190 'allow_gid' => $group_allow_list,
191 'deny_cid' => $contact_deny_list,
192 'deny_gid' => $group_deny_list,