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\Session;
35 use Friendica\Core\Theme;
36 use Friendica\Database\DBA;
38 use Friendica\Model\Contact;
39 use Friendica\Model\Item;
40 use Friendica\Model\User;
41 use Friendica\Module\Response;
42 use Friendica\Module\Security\Login;
43 use Friendica\Navigation\SystemMessages;
44 use Friendica\Network\HTTPException\NotImplementedException;
45 use Friendica\Util\ACLFormatter;
46 use Friendica\Util\Crypto;
47 use Friendica\Util\Profiler;
48 use Friendica\Util\Temporal;
49 use Psr\Log\LoggerInterface;
51 class Compose extends BaseModule
53 /** @var SystemMessages */
54 private $systemMessages;
56 /** @var ACLFormatter */
57 private $ACLFormatter;
62 /** @var IManagePersonalConfigValues */
65 /** @var IManageConfigValues */
68 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 = [])
70 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
72 $this->systemMessages = $systemMessages;
73 $this->ACLFormatter = $ACLFormatter;
75 $this->pConfig = $pConfig;
76 $this->config = $config;
79 protected function post(array $request = [])
81 if (!empty($_REQUEST['body'])) {
82 $_REQUEST['return'] = 'network';
83 require_once 'mod/item.php';
86 $this->systemMessages->addNotice($this->l10n->t('Please enter a post body.'));
90 protected function content(array $request = []): string
92 if (!Session::getLocalUser()) {
93 return Login::form('compose');
98 if ($a->getCurrentTheme() !== 'frio') {
99 throw new NotImplementedException($this->l10n->t('This feature is only available with the frio theme.'));
102 $posttype = $this->parameters['type'] ?? Item::PT_ARTICLE;
103 if (!in_array($posttype, [Item::PT_ARTICLE, Item::PT_PERSONAL_NOTE])) {
106 $posttype = Item::PT_PERSONAL_NOTE;
109 $posttype = Item::PT_ARTICLE;
114 $user = User::getById(Session::getLocalUser(), ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'default-location']);
116 $contact_allow_list = $this->ACLFormatter->expand($user['allow_cid']);
117 $group_allow_list = $this->ACLFormatter->expand($user['allow_gid']);
118 $contact_deny_list = $this->ACLFormatter->expand($user['deny_cid']);
119 $group_deny_list = $this->ACLFormatter->expand($user['deny_gid']);
122 case Item::PT_PERSONAL_NOTE:
123 $compose_title = $this->l10n->t('Compose new personal note');
125 $doesFederate = false;
126 $contact_allow_list = [$a->getContactId()];
127 $group_allow_list = [];
128 $contact_deny_list = [];
129 $group_deny_list = [];
132 $compose_title = $this->l10n->t('Compose new post');
134 $doesFederate = true;
136 $contact_allow = $_REQUEST['contact_allow'] ?? '';
137 $group_allow = $_REQUEST['group_allow'] ?? '';
138 $contact_deny = $_REQUEST['contact_deny'] ?? '';
139 $group_deny = $_REQUEST['group_deny'] ?? '';
146 $contact_allow_list = $contact_allow ? explode(',', $contact_allow) : [];
147 $group_allow_list = $group_allow ? explode(',', $group_allow) : [];
148 $contact_deny_list = $contact_deny ? explode(',', $contact_deny) : [];
149 $group_deny_list = $group_deny ? explode(',', $group_deny) : [];
155 $title = $_REQUEST['title'] ?? '';
156 $category = $_REQUEST['category'] ?? '';
157 $body = $_REQUEST['body'] ?? '';
158 $location = $_REQUEST['location'] ?? $user['default-location'];
159 $wall = $_REQUEST['wall'] ?? $type == 'post';
162 Hook::callAll('jot_tool', $jotplugins);
165 $this->page->registerFooterScript(Theme::getPathForFile('js/ajaxupload.js'));
166 $this->page->registerFooterScript(Theme::getPathForFile('js/linkPreview.js'));
167 $this->page->registerFooterScript(Theme::getPathForFile('js/compose.js'));
169 $contact = Contact::getById($a->getContactId());
171 if ($this->pConfig->get(Session::getLocalUser(), 'system', 'set_creation_date')) {
172 $created_at = Temporal::getDateTimeField(
173 new \DateTime(DBA::NULL_DATETIME),
174 new \DateTime('now'),
176 $this->l10n->t('Created at'),
183 $tpl = Renderer::getMarkupTemplate('item/compose.tpl');
184 return Renderer::replaceMacros($tpl, [
186 'compose_title' => $compose_title,
188 'visibility_title' => $this->l10n->t('Visibility'),
189 'mytitle' => $this->l10n->t('This is you'),
190 'submit' => $this->l10n->t('Submit'),
191 'edbold' => $this->l10n->t('Bold'),
192 'editalic' => $this->l10n->t('Italic'),
193 'eduline' => $this->l10n->t('Underline'),
194 'edquote' => $this->l10n->t('Quote'),
195 'edcode' => $this->l10n->t('Code'),
196 'edimg' => $this->l10n->t('Image'),
197 'edurl' => $this->l10n->t('Link'),
198 'edattach' => $this->l10n->t('Link or Media'),
199 'prompttext' => $this->l10n->t('Please enter a image/video/audio/webpage URL:'),
200 'preview' => $this->l10n->t('Preview'),
201 'location_set' => $this->l10n->t('Set your location'),
202 'location_clear' => $this->l10n->t('Clear the location'),
203 'location_unavailable' => $this->l10n->t('Location services are unavailable on your device'),
204 'location_disabled' => $this->l10n->t('Location services are disabled. Please check the website\'s permissions on your device'),
205 'wait' => $this->l10n->t('Please wait'),
206 'placeholdertitle' => $this->l10n->t('Set title'),
207 'placeholdercategory' => Feature::isEnabled(Session::getLocalUser(),'categories') ? $this->l10n->t('Categories (comma-separated list)') : '',
208 'always_open_compose' => $this->pConfig->get(Session::getLocalUser(), 'frio', 'always_open_compose',
209 $this->config->get('frio', 'always_open_compose', false)) ? '' :
210 $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>.'),
214 '$posttype' => $posttype,
217 '$mylink' => $this->baseUrl->remove($contact['url']),
218 '$myphoto' => $this->baseUrl->remove($contact['thumb']),
219 '$scheduled_at' => Temporal::getDateTimeField(
221 new DateTime('now + 6 months'),
223 $this->l10n->t('Scheduled at'),
226 '$created_at' => $created_at,
228 '$category' => $category,
230 '$location' => $location,
232 '$contact_allow'=> implode(',', $contact_allow_list),
233 '$group_allow' => implode(',', $group_allow_list),
234 '$contact_deny' => implode(',', $contact_deny_list),
235 '$group_deny' => implode(',', $group_deny_list),
237 '$jotplugins' => $jotplugins,
238 '$rand_num' => Crypto::randomDigits(12),
239 '$acl_selector' => ACL::getFullSelectorHTML($this->page, $a->getLoggedInUserId(), $doesFederate, [
240 'allow_cid' => $contact_allow_list,
241 'allow_gid' => $group_allow_list,
242 'deny_cid' => $contact_deny_list,
243 'deny_gid' => $group_deny_list,