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\Crypto;
21 class Compose extends BaseModule
23 public static function post()
25 if (!empty($_REQUEST['body'])) {
26 $_REQUEST['return'] = 'network';
27 require_once 'mod/item.php';
28 item_post(self::getApp());
30 notice(L10n::t('Please enter a post body.'));
34 public static function content()
37 return Login::form('compose', false);
42 if ($a->getCurrentTheme() !== 'frio') {
43 throw new NotImplementedException(L10n::t('This feature is only available with the frio theme.'));
46 /// @TODO Retrieve parameter from router
47 $posttype = $a->argv[1] ?? Item::PT_ARTICLE;
48 if (!in_array($posttype, [Item::PT_ARTICLE, Item::PT_PERSONAL_NOTE])) {
50 case 'note': $posttype = Item::PT_PERSONAL_NOTE; break;
51 default: $posttype = Item::PT_ARTICLE; break;
55 $user = User::getById(local_user(), ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'hidewall', 'default-location']);
58 case Item::PT_PERSONAL_NOTE:
59 $compose_title = L10n::t('Compose new personal note');
61 $doesFederate = false;
62 $contact_allow = $a->contact['id'];
66 $compose_title = L10n::t('Compose new post');
69 $contact_allow = implode(',', expand_acl($user['allow_cid']));
70 $group_allow = implode(',', expand_acl($user['allow_gid'])) ?: Group::FOLLOWERS;
74 $title = $_REQUEST['title'] ?? '';
75 $category = $_REQUEST['category'] ?? '';
76 $body = $_REQUEST['body'] ?? '';
77 $location = $_REQUEST['location'] ?? $user['default-location'];
78 $wall = $_REQUEST['wall'] ?? $type == 'post';
79 $contact_allow = $_REQUEST['contact_allow'] ?? $contact_allow;
80 $group_allow = $_REQUEST['group_allow'] ?? $group_allow;
81 $contact_deny = $_REQUEST['contact_deny'] ?? implode(',', expand_acl($user['deny_cid']));
82 $group_deny = $_REQUEST['group_deny'] ?? implode(',', expand_acl($user['deny_gid']));
83 $visibility = ($contact_allow . $user['allow_gid'] . $user['deny_cid'] . $user['deny_gid']) ? 'custom' : 'public';
85 $acl_contacts = Contact::select(['id', 'name', 'addr', 'micro'], ['uid' => local_user(), 'pending' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]]);
86 array_walk($acl_contacts, function (&$value) {
87 $value['type'] = 'contact';
92 'id' => Group::FOLLOWERS,
93 'name' => L10n::t('Followers'),
95 'micro' => 'images/twopeople.png',
99 'id' => Group::MUTUALS,
100 'name' => L10n::t('Mutuals'),
102 'micro' => 'images/twopeople.png',
106 foreach (Group::getByUserId(local_user()) as $group) {
108 'id' => $group['id'],
109 'name' => $group['name'],
111 'micro' => 'images/twopeople.png',
116 $acl = array_merge($acl_groups, $acl_contacts);
118 $jotnets_fields = [];
119 $mail_enabled = false;
120 $pubmail_enabled = false;
121 if (function_exists('imap_open') && !Config::get('system', 'imap_disabled')) {
122 $mailacct = DBA::selectFirst('mailacct', ['pubmail'], ['`uid` = ? AND `server` != ""', local_user()]);
123 if (DBA::isResult($mailacct)) {
124 $mail_enabled = true;
125 $pubmail_enabled = !empty($mailacct['pubmail']);
129 if (empty($user['hidewall'])) {
131 $jotnets_fields[] = [
132 'type' => 'checkbox',
135 L10n::t('Post to Email'),
141 Hook::callAll('jot_networks', $jotnets_fields);
145 Hook::callAll('jot_tool', $jotplugins);
149 $a->registerFooterScript('view/js/ajaxupload.js');
150 $a->registerFooterScript('view/js/linkPreview.js');
151 $a->registerFooterScript('view/asset/typeahead.js/dist/typeahead.bundle.js');
152 $a->registerFooterScript('view/theme/frio/frameworks/friendica-tagsinput/friendica-tagsinput.js');
153 $a->registerStylesheet('view/theme/frio/frameworks/friendica-tagsinput/friendica-tagsinput.css');
154 $a->registerStylesheet('view/theme/frio/frameworks/friendica-tagsinput/friendica-tagsinput-typeahead.css');
156 $tpl = Renderer::getMarkupTemplate('item/compose-footer.tpl');
157 $a->page['footer'] .= Renderer::replaceMacros($tpl, [
158 '$acl_contacts' => $acl_contacts,
159 '$acl_groups' => $acl_groups,
163 $tpl = Renderer::getMarkupTemplate('item/compose.tpl');
164 return Renderer::replaceMacros($tpl, [
165 '$compose_title'=> $compose_title,
167 '$posttype' => $posttype,
170 '$default' => L10n::t(''),
171 '$mylink' => $a->removeBaseURL($a->contact['url']),
172 '$mytitle' => L10n::t('This is you'),
173 '$myphoto' => $a->removeBaseURL($a->contact['thumb']),
174 '$submit' => L10n::t('Submit'),
175 '$edbold' => L10n::t('Bold'),
176 '$editalic' => L10n::t('Italic'),
177 '$eduline' => L10n::t('Underline'),
178 '$edquote' => L10n::t('Quote'),
179 '$edcode' => L10n::t('Code'),
180 '$edimg' => L10n::t('Image'),
181 '$edurl' => L10n::t('Link'),
182 '$edattach' => L10n::t('Link or Media'),
183 '$prompttext' => L10n::t('Please enter a image/video/audio/webpage URL:'),
184 '$preview' => L10n::t('Preview'),
185 '$location_set' => L10n::t('Set your location'),
186 '$location_clear' => L10n::t('Clear the location'),
187 '$location_unavailable' => L10n::t('Location services are unavailable on your device'),
188 '$location_disabled' => L10n::t('Location services are disabled. Please check the website\'s permissions on your device'),
189 '$wait' => L10n::t('Please wait'),
190 '$placeholdertitle' => L10n::t('Set title'),
191 '$placeholdercategory' => (Feature::isEnabled(local_user(),'categories') ? L10n::t('Categories (comma-separated list)') : ''),
192 '$public_title' => L10n::t('Public'),
193 '$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.'),
194 '$custom_title' => L10n::t('Limited/Private'),
195 '$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.'),
196 '$emailcc' => L10n::t('CC: email addresses'),
198 '$category' => $category,
200 '$location' => $location,
201 '$visibility' => $visibility,
202 '$contact_allow'=> $contact_allow,
203 '$group_allow' => $group_allow,
204 '$contact_deny' => $contact_deny,
205 '$group_deny' => $group_deny,
206 '$jotplugins' => $jotplugins,
207 '$doesFederate' => $doesFederate,
208 '$jotnets_fields'=> $jotnets_fields,
209 '$sourceapp' => L10n::t($a->sourcename),
210 '$rand_num' => Crypto::randomDigits(12)