3 namespace Friendica\Module\Item;
5 use Friendica\BaseModule;
6 use Friendica\Content\Feature;
7 use Friendica\Core\Config;
8 use Friendica\Core\Hook;
9 use Friendica\Core\L10n;
10 use Friendica\Core\Renderer;
11 use Friendica\Database\DBA;
12 use Friendica\Model\Contact;
13 use Friendica\Model\FileTag;
14 use Friendica\Model\Group;
15 use Friendica\Model\Item;
16 use Friendica\Model\User;
17 use Friendica\Module\Login;
18 use Friendica\Network\HTTPException\NotImplementedException;
19 use Friendica\Util\ACLFormatter;
20 use Friendica\Util\Crypto;
22 class Compose extends BaseModule
24 public static function post()
26 if (!empty($_REQUEST['body'])) {
27 $_REQUEST['return'] = 'network';
28 require_once 'mod/item.php';
29 item_post(self::getApp());
31 notice(L10n::t('Please enter a post body.'));
35 public static function content()
38 return Login::form('compose', false);
43 if ($a->getCurrentTheme() !== 'frio') {
44 throw new NotImplementedException(L10n::t('This feature is only available with the frio theme.'));
47 /// @TODO Retrieve parameter from router
48 $posttype = $a->argv[1] ?? Item::PT_ARTICLE;
49 if (!in_array($posttype, [Item::PT_ARTICLE, Item::PT_PERSONAL_NOTE])) {
52 $posttype = Item::PT_PERSONAL_NOTE;
55 $posttype = Item::PT_ARTICLE;
60 $user = User::getById(local_user(), ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'hidewall', 'default-location']);
62 /** @var ACLFormatter $aclFormatter */
63 $aclFormatter = self::getClass(ACLFormatter::class);
66 case Item::PT_PERSONAL_NOTE:
67 $compose_title = L10n::t('Compose new personal note');
69 $doesFederate = false;
70 $contact_allow = $a->contact['id'];
74 $compose_title = L10n::t('Compose new post');
77 $contact_allow = implode(',', $aclFormatter->expand($user['allow_cid'] ?? ''));
78 $group_allow = implode(',', $aclFormatter->expand($user['allow_gid'] ?? '')) ?: Group::FOLLOWERS;
82 $title = $_REQUEST['title'] ?? '';
83 $category = $_REQUEST['category'] ?? '';
84 $body = $_REQUEST['body'] ?? '';
85 $location = $_REQUEST['location'] ?? $user['default-location'];
86 $wall = $_REQUEST['wall'] ?? $type == 'post';
87 $contact_allow = $_REQUEST['contact_allow'] ?? $contact_allow;
88 $group_allow = $_REQUEST['group_allow'] ?? $group_allow;
89 $contact_deny = $_REQUEST['contact_deny'] ?? implode(',', $aclFormatter->expand($user['deny_cid'] ?? ''));
90 $group_deny = $_REQUEST['group_deny'] ?? implode(',', $aclFormatter->expand($user['deny_gid'] ?? ''));
91 $visibility = ($contact_allow . $user['allow_gid'] . $user['deny_cid'] . $user['deny_gid']) ? 'custom' : 'public';
93 $acl_contacts = Contact::selectToArray(['id', 'name', 'addr', 'micro'], ['uid' => local_user(), 'pending' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]]);
94 array_walk($acl_contacts, function (&$value) {
95 $value['type'] = 'contact';
100 'id' => Group::FOLLOWERS,
101 'name' => L10n::t('Followers'),
103 'micro' => 'images/twopeople.png',
107 'id' => Group::MUTUALS,
108 'name' => L10n::t('Mutuals'),
110 'micro' => 'images/twopeople.png',
114 foreach (Group::getByUserId(local_user()) as $group) {
116 'id' => $group['id'],
117 'name' => $group['name'],
119 'micro' => 'images/twopeople.png',
124 $acl = array_merge($acl_groups, $acl_contacts);
126 $jotnets_fields = [];
127 $mail_enabled = false;
128 $pubmail_enabled = false;
129 if (function_exists('imap_open') && !Config::get('system', 'imap_disabled')) {
130 $mailacct = DBA::selectFirst('mailacct', ['pubmail'], ['`uid` = ? AND `server` != ""', local_user()]);
131 if (DBA::isResult($mailacct)) {
132 $mail_enabled = true;
133 $pubmail_enabled = !empty($mailacct['pubmail']);
137 if (empty($user['hidewall'])) {
139 $jotnets_fields[] = [
140 'type' => 'checkbox',
143 L10n::t('Post to Email'),
149 Hook::callAll('jot_networks', $jotnets_fields);
153 Hook::callAll('jot_tool', $jotplugins);
157 $a->registerFooterScript('view/js/ajaxupload.js');
158 $a->registerFooterScript('view/js/linkPreview.js');
159 $a->registerFooterScript('view/asset/typeahead.js/dist/typeahead.bundle.js');
160 $a->registerFooterScript('view/theme/frio/frameworks/friendica-tagsinput/friendica-tagsinput.js');
161 $a->registerStylesheet('view/theme/frio/frameworks/friendica-tagsinput/friendica-tagsinput.css');
162 $a->registerStylesheet('view/theme/frio/frameworks/friendica-tagsinput/friendica-tagsinput-typeahead.css');
164 $tpl = Renderer::getMarkupTemplate('item/compose-footer.tpl');
165 $a->page['footer'] .= Renderer::replaceMacros($tpl, [
166 '$acl_contacts' => $acl_contacts,
167 '$acl_groups' => $acl_groups,
171 $tpl = Renderer::getMarkupTemplate('item/compose.tpl');
172 return Renderer::replaceMacros($tpl, [
173 '$compose_title'=> $compose_title,
175 '$posttype' => $posttype,
179 '$mylink' => $a->removeBaseURL($a->contact['url']),
180 '$mytitle' => L10n::t('This is you'),
181 '$myphoto' => $a->removeBaseURL($a->contact['thumb']),
182 '$submit' => L10n::t('Submit'),
183 '$edbold' => L10n::t('Bold'),
184 '$editalic' => L10n::t('Italic'),
185 '$eduline' => L10n::t('Underline'),
186 '$edquote' => L10n::t('Quote'),
187 '$edcode' => L10n::t('Code'),
188 '$edimg' => L10n::t('Image'),
189 '$edurl' => L10n::t('Link'),
190 '$edattach' => L10n::t('Link or Media'),
191 '$prompttext' => L10n::t('Please enter a image/video/audio/webpage URL:'),
192 '$preview' => L10n::t('Preview'),
193 '$location_set' => L10n::t('Set your location'),
194 '$location_clear' => L10n::t('Clear the location'),
195 '$location_unavailable' => L10n::t('Location services are unavailable on your device'),
196 '$location_disabled' => L10n::t('Location services are disabled. Please check the website\'s permissions on your device'),
197 '$wait' => L10n::t('Please wait'),
198 '$placeholdertitle' => L10n::t('Set title'),
199 '$placeholdercategory' => (Feature::isEnabled(local_user(),'categories') ? L10n::t('Categories (comma-separated list)') : ''),
200 '$public_title' => L10n::t('Public'),
201 '$public_desc' => L10n::t('This post will be sent to all your followers and can be seen in the community pages and by anyone with its link.'),
202 '$custom_title' => L10n::t('Limited/Private'),
203 '$custom_desc' => L10n::t('This post will be sent only to the people in the first box, to the exception of the people mentioned in the second box. It won\'t appear anywhere public.'),
204 '$emailcc' => L10n::t('CC: email addresses'),
206 '$category' => $category,
208 '$location' => $location,
209 '$visibility' => $visibility,
210 '$contact_allow'=> $contact_allow,
211 '$group_allow' => $group_allow,
212 '$contact_deny' => $contact_deny,
213 '$group_deny' => $group_deny,
214 '$jotplugins' => $jotplugins,
215 '$doesFederate' => $doesFederate,
216 '$jotnets_fields'=> $jotnets_fields,
217 '$sourceapp' => L10n::t($a->sourcename),
218 '$rand_num' => Crypto::randomDigits(12)