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;
26 use Friendica\BaseModule;
27 use Friendica\Content\Feature;
28 use Friendica\Core\ACL;
29 use Friendica\Core\Config\Capability\IManageConfigValues;
30 use Friendica\Core\Hook;
31 use Friendica\Core\L10n;
32 use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
33 use Friendica\Core\Renderer;
34 use Friendica\Core\Theme;
35 use Friendica\Database\DBA;
37 use Friendica\Model\Contact;
38 use Friendica\Model\Item;
39 use Friendica\Model\User;
40 use Friendica\Module\Response;
41 use Friendica\Module\Security\Login;
42 use Friendica\Navigation\SystemMessages;
43 use Friendica\Network\HTTPException\NotImplementedException;
44 use Friendica\Util\ACLFormatter;
45 use Friendica\Util\Crypto;
46 use Friendica\Util\Profiler;
47 use Friendica\Util\Temporal;
48 use Psr\Log\LoggerInterface;
50 class Compose extends BaseModule
52 /** @var SystemMessages */
53 private $systemMessages;
55 /** @var ACLFormatter */
56 private $ACLFormatter;
61 /** @var IManagePersonalConfigValues */
64 /** @var IManageConfigValues */
67 public function __construct(IManageConfigValues $config, IManagePersonalConfigValues $pConfig, App\Page $page, ACLFormatter $ACLFormatter, SystemMessages $systemMessages, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
69 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
71 $this->systemMessages = $systemMessages;
72 $this->ACLFormatter = $ACLFormatter;
74 $this->pConfig = $pConfig;
75 $this->config = $config;
78 protected function post(array $request = [])
80 if (!empty($_REQUEST['body'])) {
81 $_REQUEST['return'] = 'network';
82 require_once 'mod/item.php';
85 $this->systemMessages->addNotice($this->l10n->t('Please enter a post body.'));
89 protected function content(array $request = []): string
91 if (!DI::userSession()->getLocalUserId()) {
92 return Login::form('compose');
97 if ($a->getCurrentTheme() !== 'frio') {
98 throw new NotImplementedException($this->l10n->t('This feature is only available with the frio theme.'));
101 $posttype = $this->parameters['type'] ?? Item::PT_ARTICLE;
102 if (!in_array($posttype, [Item::PT_ARTICLE, Item::PT_PERSONAL_NOTE])) {
105 $posttype = Item::PT_PERSONAL_NOTE;
108 $posttype = Item::PT_ARTICLE;
113 $user = User::getById(DI::userSession()->getLocalUserId(), ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'default-location']);
115 $contact_allow_list = $this->ACLFormatter->expand($user['allow_cid']);
116 $group_allow_list = $this->ACLFormatter->expand($user['allow_gid']);
117 $contact_deny_list = $this->ACLFormatter->expand($user['deny_cid']);
118 $group_deny_list = $this->ACLFormatter->expand($user['deny_gid']);
121 case Item::PT_PERSONAL_NOTE:
122 $compose_title = $this->l10n->t('Compose new personal note');
124 $doesFederate = false;
125 $contact_allow_list = [$a->getContactId()];
126 $group_allow_list = [];
127 $contact_deny_list = [];
128 $group_deny_list = [];
131 $compose_title = $this->l10n->t('Compose new post');
133 $doesFederate = true;
135 $contact_allow = $_REQUEST['contact_allow'] ?? '';
136 $group_allow = $_REQUEST['group_allow'] ?? '';
137 $contact_deny = $_REQUEST['contact_deny'] ?? '';
138 $group_deny = $_REQUEST['group_deny'] ?? '';
145 $contact_allow_list = $contact_allow ? explode(',', $contact_allow) : [];
146 $group_allow_list = $group_allow ? explode(',', $group_allow) : [];
147 $contact_deny_list = $contact_deny ? explode(',', $contact_deny) : [];
148 $group_deny_list = $group_deny ? explode(',', $group_deny) : [];
154 $title = $_REQUEST['title'] ?? '';
155 $category = $_REQUEST['category'] ?? '';
156 $body = $_REQUEST['body'] ?? '';
157 $location = $_REQUEST['location'] ?? $user['default-location'];
158 $wall = $_REQUEST['wall'] ?? $type == 'post';
161 Hook::callAll('jot_tool', $jotplugins);
164 $this->page->registerFooterScript(Theme::getPathForFile('js/ajaxupload.js'));
165 $this->page->registerFooterScript(Theme::getPathForFile('js/linkPreview.js'));
166 $this->page->registerFooterScript(Theme::getPathForFile('js/compose.js'));
168 $contact = Contact::getById($a->getContactId());
170 if ($this->pConfig->get(DI::userSession()->getLocalUserId(), 'system', 'set_creation_date')) {
171 $created_at = Temporal::getDateTimeField(
172 new \DateTime(DBA::NULL_DATETIME),
173 new \DateTime('now'),
175 $this->l10n->t('Created at'),
182 $tpl = Renderer::getMarkupTemplate('item/compose.tpl');
183 return Renderer::replaceMacros($tpl, [
185 'compose_title' => $compose_title,
187 'visibility_title' => $this->l10n->t('Visibility'),
188 'mytitle' => $this->l10n->t('This is you'),
189 'submit' => $this->l10n->t('Submit'),
190 'edbold' => $this->l10n->t('Bold'),
191 'editalic' => $this->l10n->t('Italic'),
192 'eduline' => $this->l10n->t('Underline'),
193 'edquote' => $this->l10n->t('Quote'),
194 'edcode' => $this->l10n->t('Code'),
195 'edimg' => $this->l10n->t('Image'),
196 'edurl' => $this->l10n->t('Link'),
197 'edattach' => $this->l10n->t('Link or Media'),
198 'prompttext' => $this->l10n->t('Please enter a image/video/audio/webpage URL:'),
199 'preview' => $this->l10n->t('Preview'),
200 'location_set' => $this->l10n->t('Set your location'),
201 'location_clear' => $this->l10n->t('Clear the location'),
202 'location_unavailable' => $this->l10n->t('Location services are unavailable on your device'),
203 'location_disabled' => $this->l10n->t('Location services are disabled. Please check the website\'s permissions on your device'),
204 'wait' => $this->l10n->t('Please wait'),
205 'placeholdertitle' => $this->l10n->t('Set title'),
206 'placeholdercategory' => Feature::isEnabled(DI::userSession()->getLocalUserId(),'categories') ? $this->l10n->t('Categories (comma-separated list)') : '',
207 'always_open_compose' => $this->pConfig->get(DI::userSession()->getLocalUserId(), 'frio', 'always_open_compose',
208 $this->config->get('frio', 'always_open_compose', false)) ? '' :
209 $this->l10n->t('You can make this page always open when you use the New Post button in the <a href="/settings/display">Theme Customization settings</a>.'),
213 '$posttype' => $posttype,
216 '$mylink' => $this->baseUrl->remove($contact['url']),
217 '$myphoto' => $this->baseUrl->remove($contact['thumb']),
218 '$scheduled_at' => Temporal::getDateTimeField(
220 new DateTime('now + 6 months'),
222 $this->l10n->t('Scheduled at'),
225 '$created_at' => $created_at,
227 '$category' => $category,
229 '$location' => $location,
231 '$contact_allow'=> implode(',', $contact_allow_list),
232 '$group_allow' => implode(',', $group_allow_list),
233 '$contact_deny' => implode(',', $contact_deny_list),
234 '$group_deny' => implode(',', $group_deny_list),
236 '$jotplugins' => $jotplugins,
237 '$rand_num' => Crypto::randomDigits(12),
238 '$acl_selector' => ACL::getFullSelectorHTML($this->page, $a->getLoggedInUserId(), $doesFederate, [
239 'allow_cid' => $contact_allow_list,
240 'allow_gid' => $group_allow_list,
241 'deny_cid' => $contact_deny_list,
242 'deny_gid' => $group_deny_list,