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\L10n;
10 use Friendica\Core\Renderer;
11 use Friendica\Core\Theme;
13 use Friendica\Model\Item;
14 use Friendica\Model\User;
15 use Friendica\Module\Security\Login;
16 use Friendica\Network\HTTPException\NotImplementedException;
17 use Friendica\Util\Crypto;
19 class Compose extends BaseModule
21 public static function post(array $parameters = [])
23 if (!empty($_REQUEST['body'])) {
24 $_REQUEST['return'] = 'network';
25 require_once 'mod/item.php';
28 notice(DI::l10n()->t('Please enter a post body.'));
32 public static function content(array $parameters = [])
35 return Login::form('compose', false);
40 if ($a->getCurrentTheme() !== 'frio') {
41 throw new NotImplementedException(DI::l10n()->t('This feature is only available with the frio theme.'));
44 /// @TODO Retrieve parameter from router
45 $posttype = $parameters['type'] ?? Item::PT_ARTICLE;
46 if (!in_array($posttype, [Item::PT_ARTICLE, Item::PT_PERSONAL_NOTE])) {
49 $posttype = Item::PT_PERSONAL_NOTE;
52 $posttype = Item::PT_ARTICLE;
57 $user = User::getById(local_user(), ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'hidewall', 'default-location']);
59 $aclFormatter = DI::aclFormatter();
61 $contact_allow_list = $aclFormatter->expand($user['allow_cid']);
62 $group_allow_list = $aclFormatter->expand($user['allow_gid']);
63 $contact_deny_list = $aclFormatter->expand($user['deny_cid']);
64 $group_deny_list = $aclFormatter->expand($user['deny_gid']);
67 case Item::PT_PERSONAL_NOTE:
68 $compose_title = DI::l10n()->t('Compose new personal note');
70 $doesFederate = false;
71 $contact_allow_list = [$a->contact['id']];
72 $group_allow_list = [];
73 $contact_deny_list = [];
74 $group_deny_list = [];
77 $compose_title = DI::l10n()->t('Compose new post');
81 $contact_allow = $_REQUEST['contact_allow'] ?? '';
82 $group_allow = $_REQUEST['group_allow'] ?? '';
83 $contact_deny = $_REQUEST['contact_deny'] ?? '';
84 $group_deny = $_REQUEST['group_deny'] ?? '';
91 $contact_allow_list = $contact_allow ? explode(',', $contact_allow) : [];
92 $group_allow_list = $group_allow ? explode(',', $group_allow) : [];
93 $contact_deny_list = $contact_deny ? explode(',', $contact_deny) : [];
94 $group_deny_list = $group_deny ? explode(',', $group_deny) : [];
100 $title = $_REQUEST['title'] ?? '';
101 $category = $_REQUEST['category'] ?? '';
102 $body = $_REQUEST['body'] ?? '';
103 $location = $_REQUEST['location'] ?? $user['default-location'];
104 $wall = $_REQUEST['wall'] ?? $type == 'post';
107 Hook::callAll('jot_tool', $jotplugins);
110 DI::page()->registerFooterScript(Theme::getPathForFile('js/ajaxupload.js'));
111 DI::page()->registerFooterScript(Theme::getPathForFile('js/linkPreview.js'));
112 DI::page()->registerFooterScript(Theme::getPathForFile('js/compose.js'));
114 $tpl = Renderer::getMarkupTemplate('item/compose.tpl');
115 return Renderer::replaceMacros($tpl, [
116 '$compose_title'=> $compose_title,
117 '$visibility_title'=> DI::l10n()->t('Visibility'),
119 '$posttype' => $posttype,
123 '$mylink' => DI::baseUrl()->remove($a->contact['url']),
124 '$mytitle' => DI::l10n()->t('This is you'),
125 '$myphoto' => DI::baseUrl()->remove($a->contact['thumb']),
126 '$submit' => DI::l10n()->t('Submit'),
127 '$edbold' => DI::l10n()->t('Bold'),
128 '$editalic' => DI::l10n()->t('Italic'),
129 '$eduline' => DI::l10n()->t('Underline'),
130 '$edquote' => DI::l10n()->t('Quote'),
131 '$edcode' => DI::l10n()->t('Code'),
132 '$edimg' => DI::l10n()->t('Image'),
133 '$edurl' => DI::l10n()->t('Link'),
134 '$edattach' => DI::l10n()->t('Link or Media'),
135 '$prompttext' => DI::l10n()->t('Please enter a image/video/audio/webpage URL:'),
136 '$preview' => DI::l10n()->t('Preview'),
137 '$location_set' => DI::l10n()->t('Set your location'),
138 '$location_clear' => DI::l10n()->t('Clear the location'),
139 '$location_unavailable' => DI::l10n()->t('Location services are unavailable on your device'),
140 '$location_disabled' => DI::l10n()->t('Location services are disabled. Please check the website\'s permissions on your device'),
141 '$wait' => DI::l10n()->t('Please wait'),
142 '$placeholdertitle' => DI::l10n()->t('Set title'),
143 '$placeholdercategory' => (Feature::isEnabled(local_user(),'categories') ? DI::l10n()->t('Categories (comma-separated list)') : ''),
146 '$category' => $category,
148 '$location' => $location,
150 '$contact_allow'=> implode(',', $contact_allow_list),
151 '$group_allow' => implode(',', $group_allow_list),
152 '$contact_deny' => implode(',', $contact_deny_list),
153 '$group_deny' => implode(',', $group_deny_list),
155 '$jotplugins' => $jotplugins,
156 '$sourceapp' => DI::l10n()->t($a->sourcename),
157 '$rand_num' => Crypto::randomDigits(12),
158 '$acl_selector' => ACL::getFullSelectorHTML(DI::page(), $a->user, $doesFederate, [
159 'allow_cid' => $contact_allow_list,
160 'allow_gid' => $group_allow_list,
161 'deny_cid' => $contact_deny_list,
162 'deny_gid' => $group_deny_list,