]> git.mxchange.org Git - friendica.git/blob - src/Module/Item/Compose.php
Fix reshare of Diaspora posts only with pictures
[friendica.git] / src / Module / Item / Compose.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Module\Item;
23
24 use Friendica\BaseModule;
25 use Friendica\Content\Feature;
26 use Friendica\Core\ACL;
27 use Friendica\Core\Hook;
28 use Friendica\Core\Renderer;
29 use Friendica\Core\Theme;
30 use Friendica\DI;
31 use Friendica\Model\Item;
32 use Friendica\Model\User;
33 use Friendica\Module\Security\Login;
34 use Friendica\Network\HTTPException\NotImplementedException;
35 use Friendica\Util\Crypto;
36
37 class Compose extends BaseModule
38 {
39         public static function post(array $parameters = [])
40         {
41                 if (!empty($_REQUEST['body'])) {
42                         $_REQUEST['return'] = 'network';
43                         require_once 'mod/item.php';
44                         item_post(DI::app());
45                 } else {
46                         notice(DI::l10n()->t('Please enter a post body.'));
47                 }
48         }
49
50         public static function content(array $parameters = [])
51         {
52                 if (!local_user()) {
53                         return Login::form('compose', false);
54                 }
55
56                 $a = DI::app();
57
58                 if ($a->getCurrentTheme() !== 'frio') {
59                         throw new NotImplementedException(DI::l10n()->t('This feature is only available with the frio theme.'));
60                 }
61
62                 /// @TODO Retrieve parameter from router
63                 $posttype = $parameters['type'] ?? Item::PT_ARTICLE;
64                 if (!in_array($posttype, [Item::PT_ARTICLE, Item::PT_PERSONAL_NOTE])) {
65                         switch ($posttype) {
66                                 case 'note':
67                                         $posttype = Item::PT_PERSONAL_NOTE;
68                                         break;
69                                 default:
70                                         $posttype = Item::PT_ARTICLE;
71                                         break;
72                         }
73                 }
74
75                 $user = User::getById(local_user(), ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'default-location']);
76
77                 $aclFormatter = DI::aclFormatter();
78
79                 $contact_allow_list = $aclFormatter->expand($user['allow_cid']);
80                 $group_allow_list   = $aclFormatter->expand($user['allow_gid']);
81                 $contact_deny_list  = $aclFormatter->expand($user['deny_cid']);
82                 $group_deny_list    = $aclFormatter->expand($user['deny_gid']);
83
84                 switch ($posttype) {
85                         case Item::PT_PERSONAL_NOTE:
86                                 $compose_title = DI::l10n()->t('Compose new personal note');
87                                 $type = 'note';
88                                 $doesFederate = false;
89                                 $contact_allow_list = [$a->contact['id']];
90                                 $group_allow_list = [];
91                                 $contact_deny_list = [];
92                                 $group_deny_list = [];
93                                 break;
94                         default:
95                                 $compose_title = DI::l10n()->t('Compose new post');
96                                 $type = 'post';
97                                 $doesFederate = true;
98
99                                 $contact_allow = $_REQUEST['contact_allow'] ?? '';
100                                 $group_allow = $_REQUEST['group_allow'] ?? '';
101                                 $contact_deny = $_REQUEST['contact_deny'] ?? '';
102                                 $group_deny = $_REQUEST['group_deny'] ?? '';
103
104                                 if ($contact_allow
105                                         . $group_allow
106                                         . $contact_deny
107                                     . $group_deny)
108                                 {
109                                         $contact_allow_list = $contact_allow ? explode(',', $contact_allow) : [];
110                                         $group_allow_list   = $group_allow   ? explode(',', $group_allow)   : [];
111                                         $contact_deny_list  = $contact_deny  ? explode(',', $contact_deny)  : [];
112                                         $group_deny_list    = $group_deny    ? explode(',', $group_deny)    : [];
113                                 }
114
115                                 break;
116                 }
117
118                 $title         = $_REQUEST['title']         ?? '';
119                 $category      = $_REQUEST['category']      ?? '';
120                 $body          = $_REQUEST['body']          ?? '';
121                 $location      = $_REQUEST['location']      ?? $user['default-location'];
122                 $wall          = $_REQUEST['wall']          ?? $type == 'post';
123
124                 $jotplugins = '';
125                 Hook::callAll('jot_tool', $jotplugins);
126
127                 // Output
128                 DI::page()->registerFooterScript(Theme::getPathForFile('js/ajaxupload.js'));
129                 DI::page()->registerFooterScript(Theme::getPathForFile('js/linkPreview.js'));
130                 DI::page()->registerFooterScript(Theme::getPathForFile('js/compose.js'));
131
132                 $tpl = Renderer::getMarkupTemplate('item/compose.tpl');
133                 return Renderer::replaceMacros($tpl, [
134                         '$compose_title'=> $compose_title,
135                         '$visibility_title'=> DI::l10n()->t('Visibility'),
136                         '$id'           => 0,
137                         '$posttype'     => $posttype,
138                         '$type'         => $type,
139                         '$wall'         => $wall,
140                         '$default'      => '',
141                         '$mylink'       => DI::baseUrl()->remove($a->contact['url']),
142                         '$mytitle'      => DI::l10n()->t('This is you'),
143                         '$myphoto'      => DI::baseUrl()->remove($a->contact['thumb']),
144                         '$submit'       => DI::l10n()->t('Submit'),
145                         '$edbold'       => DI::l10n()->t('Bold'),
146                         '$editalic'     => DI::l10n()->t('Italic'),
147                         '$eduline'      => DI::l10n()->t('Underline'),
148                         '$edquote'      => DI::l10n()->t('Quote'),
149                         '$edcode'       => DI::l10n()->t('Code'),
150                         '$edimg'        => DI::l10n()->t('Image'),
151                         '$edurl'        => DI::l10n()->t('Link'),
152                         '$edattach'     => DI::l10n()->t('Link or Media'),
153                         '$prompttext'   => DI::l10n()->t('Please enter a image/video/audio/webpage URL:'),
154                         '$preview'      => DI::l10n()->t('Preview'),
155                         '$location_set' => DI::l10n()->t('Set your location'),
156                         '$location_clear' => DI::l10n()->t('Clear the location'),
157                         '$location_unavailable' => DI::l10n()->t('Location services are unavailable on your device'),
158                         '$location_disabled' => DI::l10n()->t('Location services are disabled. Please check the website\'s permissions on your device'),
159                         '$wait'         => DI::l10n()->t('Please wait'),
160                         '$placeholdertitle' => DI::l10n()->t('Set title'),
161                         '$placeholdercategory' => (Feature::isEnabled(local_user(),'categories') ? DI::l10n()->t('Categories (comma-separated list)') : ''),
162
163                         '$title'        => $title,
164                         '$category'     => $category,
165                         '$body'         => $body,
166                         '$location'     => $location,
167
168                         '$contact_allow'=> implode(',', $contact_allow_list),
169                         '$group_allow'  => implode(',', $group_allow_list),
170                         '$contact_deny' => implode(',', $contact_deny_list),
171                         '$group_deny'   => implode(',', $group_deny_list),
172
173                         '$jotplugins'   => $jotplugins,
174                         '$sourceapp'    => DI::l10n()->t($a->sourcename),
175                         '$rand_num'     => Crypto::randomDigits(12),
176                         '$acl_selector'  => ACL::getFullSelectorHTML(DI::page(), $a->user, $doesFederate, [
177                                 'allow_cid' => $contact_allow_list,
178                                 'allow_gid' => $group_allow_list,
179                                 'deny_cid'  => $contact_deny_list,
180                                 'deny_gid'  => $group_deny_list,
181                         ]),
182                 ]);
183         }
184 }