3 * @copyright Copyright (C) 2020, Friendica
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;
24 use Friendica\BaseModule;
25 use Friendica\Content\Feature;
26 use Friendica\Core\ACL;
27 use Friendica\Core\Hook;
28 use Friendica\Core\Renderer;
29 use Friendica\Core\Theme;
31 use Friendica\Model\Item;
32 use Friendica\Model\User;
33 use Friendica\Module\Security\Login;
34 use Friendica\Network\HTTPException\NotImplementedException;
35 use Friendica\Util\Crypto;
37 class Compose extends BaseModule
39 public static function post(array $parameters = [])
41 if (!empty($_REQUEST['body'])) {
42 $_REQUEST['return'] = 'network';
43 require_once 'mod/item.php';
46 notice(DI::l10n()->t('Please enter a post body.'));
50 public static function content(array $parameters = [])
53 return Login::form('compose', false);
58 if ($a->getCurrentTheme() !== 'frio') {
59 throw new NotImplementedException(DI::l10n()->t('This feature is only available with the frio theme.'));
62 /// @TODO Retrieve parameter from router
63 $posttype = $parameters['type'] ?? Item::PT_ARTICLE;
64 if (!in_array($posttype, [Item::PT_ARTICLE, Item::PT_PERSONAL_NOTE])) {
67 $posttype = Item::PT_PERSONAL_NOTE;
70 $posttype = Item::PT_ARTICLE;
75 $user = User::getById(local_user(), ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'default-location']);
77 $aclFormatter = DI::aclFormatter();
79 $contact_allow_list = $aclFormatter->expand($user['allow_cid']);
80 $group_allow_list = $aclFormatter->expand($user['allow_gid']);
81 $contact_deny_list = $aclFormatter->expand($user['deny_cid']);
82 $group_deny_list = $aclFormatter->expand($user['deny_gid']);
85 case Item::PT_PERSONAL_NOTE:
86 $compose_title = DI::l10n()->t('Compose new personal note');
88 $doesFederate = false;
89 $contact_allow_list = [$a->contact['id']];
90 $group_allow_list = [];
91 $contact_deny_list = [];
92 $group_deny_list = [];
95 $compose_title = DI::l10n()->t('Compose new post');
99 $contact_allow = $_REQUEST['contact_allow'] ?? '';
100 $group_allow = $_REQUEST['group_allow'] ?? '';
101 $contact_deny = $_REQUEST['contact_deny'] ?? '';
102 $group_deny = $_REQUEST['group_deny'] ?? '';
109 $contact_allow_list = $contact_allow ? explode(',', $contact_allow) : [];
110 $group_allow_list = $group_allow ? explode(',', $group_allow) : [];
111 $contact_deny_list = $contact_deny ? explode(',', $contact_deny) : [];
112 $group_deny_list = $group_deny ? explode(',', $group_deny) : [];
118 $title = $_REQUEST['title'] ?? '';
119 $category = $_REQUEST['category'] ?? '';
120 $body = $_REQUEST['body'] ?? '';
121 $location = $_REQUEST['location'] ?? $user['default-location'];
122 $wall = $_REQUEST['wall'] ?? $type == 'post';
125 Hook::callAll('jot_tool', $jotplugins);
128 DI::page()->registerFooterScript(Theme::getPathForFile('js/ajaxupload.js'));
129 DI::page()->registerFooterScript(Theme::getPathForFile('js/linkPreview.js'));
130 DI::page()->registerFooterScript(Theme::getPathForFile('js/compose.js'));
132 $tpl = Renderer::getMarkupTemplate('item/compose.tpl');
133 return Renderer::replaceMacros($tpl, [
134 '$compose_title'=> $compose_title,
135 '$visibility_title'=> DI::l10n()->t('Visibility'),
137 '$posttype' => $posttype,
141 '$mylink' => DI::baseUrl()->remove($a->contact['url']),
142 '$mytitle' => DI::l10n()->t('This is you'),
143 '$myphoto' => DI::baseUrl()->remove($a->contact['thumb']),
144 '$submit' => DI::l10n()->t('Submit'),
145 '$edbold' => DI::l10n()->t('Bold'),
146 '$editalic' => DI::l10n()->t('Italic'),
147 '$eduline' => DI::l10n()->t('Underline'),
148 '$edquote' => DI::l10n()->t('Quote'),
149 '$edcode' => DI::l10n()->t('Code'),
150 '$edimg' => DI::l10n()->t('Image'),
151 '$edurl' => DI::l10n()->t('Link'),
152 '$edattach' => DI::l10n()->t('Link or Media'),
153 '$prompttext' => DI::l10n()->t('Please enter a image/video/audio/webpage URL:'),
154 '$preview' => DI::l10n()->t('Preview'),
155 '$location_set' => DI::l10n()->t('Set your location'),
156 '$location_clear' => DI::l10n()->t('Clear the location'),
157 '$location_unavailable' => DI::l10n()->t('Location services are unavailable on your device'),
158 '$location_disabled' => DI::l10n()->t('Location services are disabled. Please check the website\'s permissions on your device'),
159 '$wait' => DI::l10n()->t('Please wait'),
160 '$placeholdertitle' => DI::l10n()->t('Set title'),
161 '$placeholdercategory' => (Feature::isEnabled(local_user(),'categories') ? DI::l10n()->t('Categories (comma-separated list)') : ''),
164 '$category' => $category,
166 '$location' => $location,
168 '$contact_allow'=> implode(',', $contact_allow_list),
169 '$group_allow' => implode(',', $group_allow_list),
170 '$contact_deny' => implode(',', $contact_deny_list),
171 '$group_deny' => implode(',', $group_deny_list),
173 '$jotplugins' => $jotplugins,
174 '$sourceapp' => DI::l10n()->t($a->sourcename),
175 '$rand_num' => Crypto::randomDigits(12),
176 '$acl_selector' => ACL::getFullSelectorHTML(DI::page(), $a->user, $doesFederate, [
177 'allow_cid' => $contact_allow_list,
178 'allow_gid' => $group_allow_list,
179 'deny_cid' => $contact_deny_list,
180 'deny_gid' => $group_deny_list,