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 if ($_REQUEST['contact_allow']
89 . $_REQUEST['group_allow']
90 . $_REQUEST['contact_deny']
91 . $_REQUEST['group_deny'])
93 $contact_allow_list = $_REQUEST['contact_allow'] ? explode(',', $_REQUEST['contact_allow']) : [];
94 $group_allow_list = $_REQUEST['group_allow'] ? explode(',', $_REQUEST['group_allow']) : [];
95 $contact_deny_list = $_REQUEST['contact_deny'] ? explode(',', $_REQUEST['contact_deny']) : [];
96 $group_deny_list = $_REQUEST['group_deny'] ? explode(',', $_REQUEST['group_deny']) : [];
102 $title = $_REQUEST['title'] ?? '';
103 $category = $_REQUEST['category'] ?? '';
104 $body = $_REQUEST['body'] ?? '';
105 $location = $_REQUEST['location'] ?? $user['default-location'];
106 $wall = $_REQUEST['wall'] ?? $type == 'post';
109 Hook::callAll('jot_tool', $jotplugins);
112 $a->page->registerFooterScript(Theme::getPathForFile('js/ajaxupload.js'));
113 $a->page->registerFooterScript(Theme::getPathForFile('js/linkPreview.js'));
114 $a->page->registerFooterScript(Theme::getPathForFile('js/compose.js'));
116 $tpl = Renderer::getMarkupTemplate('item/compose.tpl');
117 return Renderer::replaceMacros($tpl, [
118 '$compose_title'=> $compose_title,
119 '$visibility_title'=> L10n::t('Visibility'),
121 '$posttype' => $posttype,
125 '$mylink' => $a->removeBaseURL($a->contact['url']),
126 '$mytitle' => L10n::t('This is you'),
127 '$myphoto' => $a->removeBaseURL($a->contact['thumb']),
128 '$submit' => L10n::t('Submit'),
129 '$edbold' => L10n::t('Bold'),
130 '$editalic' => L10n::t('Italic'),
131 '$eduline' => L10n::t('Underline'),
132 '$edquote' => L10n::t('Quote'),
133 '$edcode' => L10n::t('Code'),
134 '$edimg' => L10n::t('Image'),
135 '$edurl' => L10n::t('Link'),
136 '$edattach' => L10n::t('Link or Media'),
137 '$prompttext' => L10n::t('Please enter a image/video/audio/webpage URL:'),
138 '$preview' => L10n::t('Preview'),
139 '$location_set' => L10n::t('Set your location'),
140 '$location_clear' => L10n::t('Clear the location'),
141 '$location_unavailable' => L10n::t('Location services are unavailable on your device'),
142 '$location_disabled' => L10n::t('Location services are disabled. Please check the website\'s permissions on your device'),
143 '$wait' => L10n::t('Please wait'),
144 '$placeholdertitle' => L10n::t('Set title'),
145 '$placeholdercategory' => (Feature::isEnabled(local_user(),'categories') ? L10n::t('Categories (comma-separated list)') : ''),
148 '$category' => $category,
150 '$location' => $location,
152 '$contact_allow'=> implode(',', $contact_allow_list),
153 '$group_allow' => implode(',', $group_allow_list),
154 '$contact_deny' => implode(',', $contact_deny_list),
155 '$group_deny' => implode(',', $group_deny_list),
157 '$jotplugins' => $jotplugins,
158 '$sourceapp' => L10n::t($a->sourcename),
159 '$rand_num' => Crypto::randomDigits(12),
160 '$acl_selector' => ACL::getFullSelectorHTML($a->page, $a->user, $doesFederate, [
161 'allow_cid' => $contact_allow_list,
162 'allow_gid' => $group_allow_list,
163 'deny_cid' => $contact_deny_list,
164 'deny_gid' => $group_deny_list,