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])) {
51 $posttype = Item::PT_PERSONAL_NOTE;
54 $posttype = Item::PT_ARTICLE;
59 $user = User::getById(local_user(), ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'hidewall', 'default-location']);
62 case Item::PT_PERSONAL_NOTE:
63 $compose_title = L10n::t('Compose new personal note');
65 $doesFederate = false;
66 $contact_allow = $a->contact['id'];
70 $compose_title = L10n::t('Compose new post');
73 $contact_allow = implode(',', expand_acl($user['allow_cid']));
74 $group_allow = implode(',', expand_acl($user['allow_gid'])) ?: Group::FOLLOWERS;
78 $title = $_REQUEST['title'] ?? '';
79 $category = $_REQUEST['category'] ?? '';
80 $body = $_REQUEST['body'] ?? '';
81 $location = $_REQUEST['location'] ?? $user['default-location'];
82 $wall = $_REQUEST['wall'] ?? $type == 'post';
83 $contact_allow = $_REQUEST['contact_allow'] ?? $contact_allow;
84 $group_allow = $_REQUEST['group_allow'] ?? $group_allow;
85 $contact_deny = $_REQUEST['contact_deny'] ?? implode(',', expand_acl($user['deny_cid']));
86 $group_deny = $_REQUEST['group_deny'] ?? implode(',', expand_acl($user['deny_gid']));
87 $visibility = ($contact_allow . $user['allow_gid'] . $user['deny_cid'] . $user['deny_gid']) ? 'custom' : 'public';
89 $acl_contacts = Contact::selectToArray(['id', 'name', 'addr', 'micro'], ['uid' => local_user(), 'pending' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]]);
90 array_walk($acl_contacts, function (&$value) {
91 $value['type'] = 'contact';
96 'id' => Group::FOLLOWERS,
97 'name' => L10n::t('Followers'),
99 'micro' => 'images/twopeople.png',
103 'id' => Group::MUTUALS,
104 'name' => L10n::t('Mutuals'),
106 'micro' => 'images/twopeople.png',
110 foreach (Group::getByUserId(local_user()) as $group) {
112 'id' => $group['id'],
113 'name' => $group['name'],
115 'micro' => 'images/twopeople.png',
120 $acl = array_merge($acl_groups, $acl_contacts);
122 $jotnets_fields = [];
123 $mail_enabled = false;
124 $pubmail_enabled = false;
125 if (function_exists('imap_open') && !Config::get('system', 'imap_disabled')) {
126 $mailacct = DBA::selectFirst('mailacct', ['pubmail'], ['`uid` = ? AND `server` != ""', local_user()]);
127 if (DBA::isResult($mailacct)) {
128 $mail_enabled = true;
129 $pubmail_enabled = !empty($mailacct['pubmail']);
133 if (empty($user['hidewall'])) {
135 $jotnets_fields[] = [
136 'type' => 'checkbox',
139 L10n::t('Post to Email'),
145 Hook::callAll('jot_networks', $jotnets_fields);
149 Hook::callAll('jot_tool', $jotplugins);
153 $a->registerFooterScript('view/js/ajaxupload.js');
154 $a->registerFooterScript('view/js/linkPreview.js');
155 $a->registerFooterScript('view/asset/typeahead.js/dist/typeahead.bundle.js');
156 $a->registerFooterScript('view/theme/frio/frameworks/friendica-tagsinput/friendica-tagsinput.js');
157 $a->registerStylesheet('view/theme/frio/frameworks/friendica-tagsinput/friendica-tagsinput.css');
158 $a->registerStylesheet('view/theme/frio/frameworks/friendica-tagsinput/friendica-tagsinput-typeahead.css');
160 $tpl = Renderer::getMarkupTemplate('item/compose-footer.tpl');
161 $a->page['footer'] .= Renderer::replaceMacros($tpl, [
162 '$acl_contacts' => $acl_contacts,
163 '$acl_groups' => $acl_groups,
167 $tpl = Renderer::getMarkupTemplate('item/compose.tpl');
168 return Renderer::replaceMacros($tpl, [
169 '$compose_title'=> $compose_title,
171 '$posttype' => $posttype,
174 '$default' => L10n::t(''),
175 '$mylink' => $a->removeBaseURL($a->contact['url']),
176 '$mytitle' => L10n::t('This is you'),
177 '$myphoto' => $a->removeBaseURL($a->contact['thumb']),
178 '$submit' => L10n::t('Submit'),
179 '$edbold' => L10n::t('Bold'),
180 '$editalic' => L10n::t('Italic'),
181 '$eduline' => L10n::t('Underline'),
182 '$edquote' => L10n::t('Quote'),
183 '$edcode' => L10n::t('Code'),
184 '$edimg' => L10n::t('Image'),
185 '$edurl' => L10n::t('Link'),
186 '$edattach' => L10n::t('Link or Media'),
187 '$prompttext' => L10n::t('Please enter a image/video/audio/webpage URL:'),
188 '$preview' => L10n::t('Preview'),
189 '$location_set' => L10n::t('Set your location'),
190 '$location_clear' => L10n::t('Clear the location'),
191 '$location_unavailable' => L10n::t('Location services are unavailable on your device'),
192 '$location_disabled' => L10n::t('Location services are disabled. Please check the website\'s permissions on your device'),
193 '$wait' => L10n::t('Please wait'),
194 '$placeholdertitle' => L10n::t('Set title'),
195 '$placeholdercategory' => (Feature::isEnabled(local_user(),'categories') ? L10n::t('Categories (comma-separated list)') : ''),
196 '$public_title' => L10n::t('Public'),
197 '$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.'),
198 '$custom_title' => L10n::t('Limited/Private'),
199 '$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.'),
200 '$emailcc' => L10n::t('CC: email addresses'),
202 '$category' => $category,
204 '$location' => $location,
205 '$visibility' => $visibility,
206 '$contact_allow'=> $contact_allow,
207 '$group_allow' => $group_allow,
208 '$contact_deny' => $contact_deny,
209 '$group_deny' => $group_deny,
210 '$jotplugins' => $jotplugins,
211 '$doesFederate' => $doesFederate,
212 '$jotnets_fields'=> $jotnets_fields,
213 '$sourceapp' => L10n::t($a->sourcename),
214 '$rand_num' => Crypto::randomDigits(12)