3 namespace Friendica\Module\Item;
5 use Friendica\BaseModule;
6 use Friendica\Content\Feature;
7 use Friendica\Core\ACL;
8 use Friendica\Core\Hook;
9 use Friendica\Core\Renderer;
10 use Friendica\Core\Theme;
12 use Friendica\Model\Item;
13 use Friendica\Model\User;
14 use Friendica\Module\Security\Login;
15 use Friendica\Network\HTTPException\NotImplementedException;
16 use Friendica\Util\Crypto;
18 class Compose extends BaseModule
20 public static function post(array $parameters = [])
22 if (!empty($_REQUEST['body'])) {
23 $_REQUEST['return'] = 'network';
24 require_once 'mod/item.php';
27 notice(DI::l10n()->t('Please enter a post body.'));
31 public static function content(array $parameters = [])
34 return Login::form('compose', false);
39 if ($a->getCurrentTheme() !== 'frio') {
40 throw new NotImplementedException(DI::l10n()->t('This feature is only available with the frio theme.'));
43 /// @TODO Retrieve parameter from router
44 $posttype = $parameters['type'] ?? Item::PT_ARTICLE;
45 if (!in_array($posttype, [Item::PT_ARTICLE, Item::PT_PERSONAL_NOTE])) {
48 $posttype = Item::PT_PERSONAL_NOTE;
51 $posttype = Item::PT_ARTICLE;
56 $user = User::getById(local_user(), ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'hidewall', 'default-location']);
58 $aclFormatter = DI::aclFormatter();
60 $contact_allow_list = $aclFormatter->expand($user['allow_cid']);
61 $group_allow_list = $aclFormatter->expand($user['allow_gid']);
62 $contact_deny_list = $aclFormatter->expand($user['deny_cid']);
63 $group_deny_list = $aclFormatter->expand($user['deny_gid']);
66 case Item::PT_PERSONAL_NOTE:
67 $compose_title = DI::l10n()->t('Compose new personal note');
69 $doesFederate = false;
70 $contact_allow_list = [$a->contact['id']];
71 $group_allow_list = [];
72 $contact_deny_list = [];
73 $group_deny_list = [];
76 $compose_title = DI::l10n()->t('Compose new post');
80 $contact_allow = $_REQUEST['contact_allow'] ?? '';
81 $group_allow = $_REQUEST['group_allow'] ?? '';
82 $contact_deny = $_REQUEST['contact_deny'] ?? '';
83 $group_deny = $_REQUEST['group_deny'] ?? '';
90 $contact_allow_list = $contact_allow ? explode(',', $contact_allow) : [];
91 $group_allow_list = $group_allow ? explode(',', $group_allow) : [];
92 $contact_deny_list = $contact_deny ? explode(',', $contact_deny) : [];
93 $group_deny_list = $group_deny ? explode(',', $group_deny) : [];
99 $title = $_REQUEST['title'] ?? '';
100 $category = $_REQUEST['category'] ?? '';
101 $body = $_REQUEST['body'] ?? '';
102 $location = $_REQUEST['location'] ?? $user['default-location'];
103 $wall = $_REQUEST['wall'] ?? $type == 'post';
106 Hook::callAll('jot_tool', $jotplugins);
109 DI::page()->registerFooterScript(Theme::getPathForFile('js/ajaxupload.js'));
110 DI::page()->registerFooterScript(Theme::getPathForFile('js/linkPreview.js'));
111 DI::page()->registerFooterScript(Theme::getPathForFile('js/compose.js'));
113 $tpl = Renderer::getMarkupTemplate('item/compose.tpl');
114 return Renderer::replaceMacros($tpl, [
115 '$compose_title'=> $compose_title,
116 '$visibility_title'=> DI::l10n()->t('Visibility'),
118 '$posttype' => $posttype,
122 '$mylink' => DI::baseUrl()->remove($a->contact['url']),
123 '$mytitle' => DI::l10n()->t('This is you'),
124 '$myphoto' => DI::baseUrl()->remove($a->contact['thumb']),
125 '$submit' => DI::l10n()->t('Submit'),
126 '$edbold' => DI::l10n()->t('Bold'),
127 '$editalic' => DI::l10n()->t('Italic'),
128 '$eduline' => DI::l10n()->t('Underline'),
129 '$edquote' => DI::l10n()->t('Quote'),
130 '$edcode' => DI::l10n()->t('Code'),
131 '$edimg' => DI::l10n()->t('Image'),
132 '$edurl' => DI::l10n()->t('Link'),
133 '$edattach' => DI::l10n()->t('Link or Media'),
134 '$prompttext' => DI::l10n()->t('Please enter a image/video/audio/webpage URL:'),
135 '$preview' => DI::l10n()->t('Preview'),
136 '$location_set' => DI::l10n()->t('Set your location'),
137 '$location_clear' => DI::l10n()->t('Clear the location'),
138 '$location_unavailable' => DI::l10n()->t('Location services are unavailable on your device'),
139 '$location_disabled' => DI::l10n()->t('Location services are disabled. Please check the website\'s permissions on your device'),
140 '$wait' => DI::l10n()->t('Please wait'),
141 '$placeholdertitle' => DI::l10n()->t('Set title'),
142 '$placeholdercategory' => (Feature::isEnabled(local_user(),'categories') ? DI::l10n()->t('Categories (comma-separated list)') : ''),
145 '$category' => $category,
147 '$location' => $location,
149 '$contact_allow'=> implode(',', $contact_allow_list),
150 '$group_allow' => implode(',', $group_allow_list),
151 '$contact_deny' => implode(',', $contact_deny_list),
152 '$group_deny' => implode(',', $group_deny_list),
154 '$jotplugins' => $jotplugins,
155 '$sourceapp' => DI::l10n()->t($a->sourcename),
156 '$rand_num' => Crypto::randomDigits(12),
157 '$acl_selector' => ACL::getFullSelectorHTML(DI::page(), $a->user, $doesFederate, [
158 'allow_cid' => $contact_allow_list,
159 'allow_gid' => $group_allow_list,
160 'deny_cid' => $contact_deny_list,
161 'deny_gid' => $group_deny_list,