]> git.mxchange.org Git - friendica.git/blob - src/Module/Item/Compose.php
[frio] Add jotnet fields to compose page
[friendica.git] / src / Module / Item / Compose.php
1 <?php
2
3 namespace Friendica\Module\Item;
4
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;
20
21 class Compose extends BaseModule
22 {
23         public static function post()
24         {
25                 if (!empty($_REQUEST['body'])) {
26                         $_REQUEST['return'] = 'network';
27                         require_once 'mod/item.php';
28                         item_post(self::getApp());
29                 } else {
30                         notice(L10n::t('Please enter a post body.'));
31                 }
32         }
33
34         public static function content()
35         {
36                 if (!local_user()) {
37                         return Login::form('compose', false);
38                 }
39
40                 $a = self::getApp();
41
42                 if ($a->getCurrentTheme() !== 'frio') {
43                         throw new NotImplementedException(L10n::t('This feature is only available with the frio theme.'));
44                 }
45
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])) {
49                         switch ($posttype) {
50                                 case 'note': $posttype = Item::PT_PERSONAL_NOTE; break;
51                                 default: $posttype = Item::PT_ARTICLE; break;
52                         }
53                 }
54
55                 $user = User::getById(local_user(), ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'hidewall', 'default-location']);
56
57                 switch ($posttype) {
58                         case Item::PT_PERSONAL_NOTE:
59                                 $compose_title = L10n::t('Compose new personal note');
60                                 $type = 'note';
61                                 $doesFederate = false;
62                                 $contact_allow = $a->contact['id'];
63                                 $group_allow = '';
64                                 break;
65                         default:
66                                 $compose_title = L10n::t('Compose new post');
67                                 $type = 'post';
68                                 $doesFederate = true;
69                                 $contact_allow = implode(',', expand_acl($user['allow_cid']));
70                                 $group_allow = implode(',', expand_acl($user['allow_gid'])) ?: Group::FOLLOWERS;
71                                 break;
72                 }
73
74                 $title         = $_REQUEST['title']         ?? '';
75                 $category      = $_REQUEST['category']      ?? '';
76                 $body          = $_REQUEST['body']          ?? '';
77                 $location      = $_REQUEST['location']      ?? $user['default-location'];
78                 $wall          = $_REQUEST['wall']          ?? $type == 'post';
79                 $contact_allow = $_REQUEST['contact_allow'] ?? $contact_allow;
80                 $group_allow   = $_REQUEST['group_allow']   ?? $group_allow;
81                 $contact_deny  = $_REQUEST['contact_deny']  ?? implode(',', expand_acl($user['deny_cid']));
82                 $group_deny    = $_REQUEST['group_deny']    ?? implode(',', expand_acl($user['deny_gid']));
83                 $visibility    = ($contact_allow . $user['allow_gid'] . $user['deny_cid'] . $user['deny_gid']) ? 'custom' : 'public';
84
85                 $acl_contacts = Contact::select(['id', 'name', 'addr', 'micro'], ['uid' => local_user(), 'pending' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]]);
86                 array_walk($acl_contacts, function (&$value) {
87                         $value['type'] = 'contact';
88                 });
89
90                 $acl_groups = [
91                         [
92                                 'id' => Group::FOLLOWERS,
93                                 'name' => L10n::t('Followers'),
94                                 'addr' => '',
95                                 'micro' => 'images/twopeople.png',
96                                 'type' => 'group',
97                         ],
98                         [
99                                 'id' => Group::MUTUALS,
100                                 'name' => L10n::t('Mutuals'),
101                                 'addr' => '',
102                                 'micro' => 'images/twopeople.png',
103                                 'type' => 'group',
104                         ]
105                 ];
106                 foreach (Group::getByUserId(local_user()) as $group) {
107                         $acl_groups[] = [
108                                 'id' => $group['id'],
109                                 'name' => $group['name'],
110                                 'addr' => '',
111                                 'micro' => 'images/twopeople.png',
112                                 'type' => 'group',
113                         ];
114                 }
115
116                 $acl = array_merge($acl_groups, $acl_contacts);
117
118                 $jotnets_fields = [];
119                 $mail_enabled = false;
120                 $pubmail_enabled = false;
121                 if (function_exists('imap_open') && !Config::get('system', 'imap_disabled')) {
122                         $mailacct = DBA::selectFirst('mailacct', ['pubmail'], ['`uid` = ? AND `server` != ""', local_user()]);
123                         if (DBA::isResult($mailacct)) {
124                                 $mail_enabled = true;
125                                 $pubmail_enabled = !empty($mailacct['pubmail']);
126                         }
127                 }
128
129                 if (empty($user['hidewall'])) {
130                         if ($mail_enabled) {
131                                 $jotnets_fields[] = [
132                                         'type' => 'checkbox',
133                                         'field' => [
134                                                 'pubmail_enable',
135                                                 L10n::t('Post to Email'),
136                                                 $pubmail_enabled
137                                         ]
138                                 ];
139                         }
140
141                         Hook::callAll('jot_networks', $jotnets_fields);
142                 }
143
144                 $jotplugins = '';
145                 Hook::callAll('jot_tool', $jotplugins);
146
147                 // Output
148
149                 $a->registerFooterScript('view/js/ajaxupload.js');
150                 $a->registerFooterScript('view/js/linkPreview.js');
151                 $a->registerFooterScript('view/asset/typeahead.js/dist/typeahead.bundle.js');
152                 $a->registerFooterScript('view/theme/frio/frameworks/friendica-tagsinput/friendica-tagsinput.js');
153                 $a->registerStylesheet('view/theme/frio/frameworks/friendica-tagsinput/friendica-tagsinput.css');
154                 $a->registerStylesheet('view/theme/frio/frameworks/friendica-tagsinput/friendica-tagsinput-typeahead.css');
155
156                 $tpl = Renderer::getMarkupTemplate('item/compose-footer.tpl');
157                 $a->page['footer'] .= Renderer::replaceMacros($tpl, [
158                         '$acl_contacts' => $acl_contacts,
159                         '$acl_groups' => $acl_groups,
160                         '$acl' => $acl,
161                 ]);
162
163                 $tpl = Renderer::getMarkupTemplate('item/compose.tpl');
164                 return Renderer::replaceMacros($tpl, [
165                         '$compose_title'=> $compose_title,
166                         '$id'           => 0,
167                         '$posttype'     => $posttype,
168                         '$type'         => $type,
169                         '$wall'         => $wall,
170                         '$default'      => L10n::t(''),
171                         '$mylink'       => $a->removeBaseURL($a->contact['url']),
172                         '$mytitle'      => L10n::t('This is you'),
173                         '$myphoto'      => $a->removeBaseURL($a->contact['thumb']),
174                         '$submit'       => L10n::t('Submit'),
175                         '$edbold'       => L10n::t('Bold'),
176                         '$editalic'     => L10n::t('Italic'),
177                         '$eduline'      => L10n::t('Underline'),
178                         '$edquote'      => L10n::t('Quote'),
179                         '$edcode'       => L10n::t('Code'),
180                         '$edimg'        => L10n::t('Image'),
181                         '$edurl'        => L10n::t('Link'),
182                         '$edattach'     => L10n::t('Link or Media'),
183                         '$prompttext'   => L10n::t('Please enter a image/video/audio/webpage URL:'),
184                         '$preview'      => L10n::t('Preview'),
185                         '$location_set' => L10n::t('Set your location'),
186                         '$location_clear' => L10n::t('Clear the location'),
187                         '$location_unavailable' => L10n::t('Location services are unavailable on your device'),
188                         '$location_disabled' => L10n::t('Location services are disabled. Please check the website\'s permissions on your device'),
189                         '$wait'         => L10n::t('Please wait'),
190                         '$placeholdertitle' => L10n::t('Set title'),
191                         '$placeholdercategory' => (Feature::isEnabled(local_user(),'categories') ? L10n::t('Categories (comma-separated list)') : ''),
192                         '$public_title'  => L10n::t('Public'),
193                         '$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.'),
194                         '$custom_title' => L10n::t('Custom'),
195                         '$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 be visible in the community pages nor with its link, and can\'t be sent to connectors (Twitter, Pump.io, etc...).'),
196                         '$emailcc'      => L10n::t('CC: email addresses'),
197                         '$title'        => $title,
198                         '$category'     => $category,
199                         '$body'         => $body,
200                         '$location'     => $location,
201                         '$visibility'   => $visibility,
202                         '$contact_allow'=> $contact_allow,
203                         '$group_allow'  => $group_allow,
204                         '$contact_deny' => $contact_deny,
205                         '$group_deny'   => $group_deny,
206                         '$jotplugins'   => $jotplugins,
207                         '$doesFederate' => $doesFederate,
208                         '$jotnets_fields'=> $jotnets_fields,
209                         '$sourceapp'    => L10n::t($a->sourcename),
210                         '$rand_num'     => Crypto::randomDigits(12)
211                 ]);
212         }
213 }