3 namespace Friendica\Module\Item;
5 use Friendica\BaseModule;
6 use Friendica\Content\Feature;
7 use Friendica\Core\ACL;
8 use Friendica\Core\Config;
9 use Friendica\Core\Hook;
10 use Friendica\Core\L10n;
11 use Friendica\Core\Renderer;
12 use Friendica\Core\System;
13 use Friendica\Core\Theme;
14 use Friendica\Database\DBA;
15 use Friendica\Model\Contact;
16 use Friendica\Model\FileTag;
17 use Friendica\Model\Group;
18 use Friendica\Model\Item;
19 use Friendica\Model\User;
20 use Friendica\Module\Login;
21 use Friendica\Network\HTTPException\NotImplementedException;
22 use Friendica\Util\ACLFormatter;
23 use Friendica\Util\Crypto;
25 class Compose extends BaseModule
27 public static function post(array $parameters = [])
29 if (!empty($_REQUEST['body'])) {
30 $_REQUEST['return'] = 'network';
31 require_once 'mod/item.php';
32 item_post(self::getApp());
34 notice(L10n::t('Please enter a post body.'));
38 public static function content(array $parameters = [])
41 return Login::form('compose', false);
46 if ($a->getCurrentTheme() !== 'frio') {
47 throw new NotImplementedException(L10n::t('This feature is only available with the frio theme.'));
50 /// @TODO Retrieve parameter from router
51 $posttype = $parameters['type'] ?? Item::PT_ARTICLE;
52 if (!in_array($posttype, [Item::PT_ARTICLE, Item::PT_PERSONAL_NOTE])) {
55 $posttype = Item::PT_PERSONAL_NOTE;
58 $posttype = Item::PT_ARTICLE;
63 $user = User::getById(local_user(), ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'hidewall', 'default-location']);
65 /** @var ACLFormatter $aclFormatter */
66 $aclFormatter = self::getClass(ACLFormatter::class);
68 $contact_allow_list = $aclFormatter->expand($user['allow_cid']);
69 $group_allow_list = $aclFormatter->expand($user['allow_gid']);
70 $contact_deny_list = $aclFormatter->expand($user['deny_cid']);
71 $group_deny_list = $aclFormatter->expand($user['deny_gid']);
74 case Item::PT_PERSONAL_NOTE:
75 $compose_title = L10n::t('Compose new personal note');
77 $doesFederate = false;
78 $contact_allow_list = [$a->contact['id']];
79 $group_allow_list = [];
80 $contact_deny_list = [];
81 $group_deny_list = [];
84 $compose_title = L10n::t('Compose new post');
88 $contact_allow = $_REQUEST['contact_allow'] ?? '';
89 $group_allow = $_REQUEST['group_allow'] ?? '';
90 $contact_deny = $_REQUEST['contact_deny'] ?? '';
91 $group_deny = $_REQUEST['group_deny'] ?? '';
98 $contact_allow_list = $contact_allow ? explode(',', $contact_allow) : [];
99 $group_allow_list = $group_allow ? explode(',', $group_allow) : [];
100 $contact_deny_list = $contact_deny ? explode(',', $contact_deny) : [];
101 $group_deny_list = $group_deny ? explode(',', $group_deny) : [];
107 $title = $_REQUEST['title'] ?? '';
108 $category = $_REQUEST['category'] ?? '';
109 $body = $_REQUEST['body'] ?? '';
110 $location = $_REQUEST['location'] ?? $user['default-location'];
111 $wall = $_REQUEST['wall'] ?? $type == 'post';
114 Hook::callAll('jot_tool', $jotplugins);
117 $a->page->registerFooterScript(Theme::getPathForFile('js/ajaxupload.js'));
118 $a->page->registerFooterScript(Theme::getPathForFile('js/linkPreview.js'));
119 $a->page->registerFooterScript(Theme::getPathForFile('js/compose.js'));
121 $tpl = Renderer::getMarkupTemplate('item/compose.tpl');
122 return Renderer::replaceMacros($tpl, [
123 '$compose_title'=> $compose_title,
124 '$visibility_title'=> L10n::t('Visibility'),
126 '$posttype' => $posttype,
130 '$mylink' => $a->removeBaseURL($a->contact['url']),
131 '$mytitle' => L10n::t('This is you'),
132 '$myphoto' => $a->removeBaseURL($a->contact['thumb']),
133 '$submit' => L10n::t('Submit'),
134 '$edbold' => L10n::t('Bold'),
135 '$editalic' => L10n::t('Italic'),
136 '$eduline' => L10n::t('Underline'),
137 '$edquote' => L10n::t('Quote'),
138 '$edcode' => L10n::t('Code'),
139 '$edimg' => L10n::t('Image'),
140 '$edurl' => L10n::t('Link'),
141 '$edattach' => L10n::t('Link or Media'),
142 '$prompttext' => L10n::t('Please enter a image/video/audio/webpage URL:'),
143 '$preview' => L10n::t('Preview'),
144 '$location_set' => L10n::t('Set your location'),
145 '$location_clear' => L10n::t('Clear the location'),
146 '$location_unavailable' => L10n::t('Location services are unavailable on your device'),
147 '$location_disabled' => L10n::t('Location services are disabled. Please check the website\'s permissions on your device'),
148 '$wait' => L10n::t('Please wait'),
149 '$placeholdertitle' => L10n::t('Set title'),
150 '$placeholdercategory' => (Feature::isEnabled(local_user(),'categories') ? L10n::t('Categories (comma-separated list)') : ''),
153 '$category' => $category,
155 '$location' => $location,
157 '$contact_allow'=> implode(',', $contact_allow_list),
158 '$group_allow' => implode(',', $group_allow_list),
159 '$contact_deny' => implode(',', $contact_deny_list),
160 '$group_deny' => implode(',', $group_deny_list),
162 '$jotplugins' => $jotplugins,
163 '$sourceapp' => L10n::t($a->sourcename),
164 '$rand_num' => Crypto::randomDigits(12),
165 '$acl_selector' => ACL::getFullSelectorHTML($a->page, $a->user, $doesFederate, [
166 'allow_cid' => $contact_allow_list,
167 'allow_gid' => $group_allow_list,
168 'deny_cid' => $contact_deny_list,
169 'deny_gid' => $group_deny_list,