]> git.mxchange.org Git - friendica.git/blob - mod/editpost.php
UserSession class [2] - Refactor mod/ files
[friendica.git] / mod / editpost.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, 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 use Friendica\App;
23 use Friendica\Content\Feature;
24 use Friendica\Core\Hook;
25 use Friendica\Core\Renderer;
26 use Friendica\Core\Session;
27 use Friendica\Database\DBA;
28 use Friendica\DI;
29 use Friendica\Model\Contact;
30 use Friendica\Model\Post;
31 use Friendica\Model\User;
32 use Friendica\Util\Crypto;
33
34 function editpost_content(App $a)
35 {
36         $o = '';
37
38         if (!DI::userSession()->getLocalUserId()) {
39                 DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.'));
40                 return;
41         }
42
43         $post_id = ((DI::args()->getArgc() > 1) ? intval(DI::args()->getArgv()[1]) : 0);
44
45         if (!$post_id) {
46                 DI::sysmsg()->addNotice(DI::l10n()->t('Item not found'));
47                 return;
48         }
49
50         $fields = ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
51                 'body', 'title', 'uri-id', 'wall', 'post-type', 'guid'];
52
53         $item = Post::selectFirstForUser(DI::userSession()->getLocalUserId(), $fields, ['id' => $post_id, 'uid' => DI::userSession()->getLocalUserId()]);
54
55         if (!DBA::isResult($item)) {
56                 DI::sysmsg()->addNotice(DI::l10n()->t('Item not found'));
57                 return;
58         }
59
60         $user = User::getById(DI::userSession()->getLocalUserId());
61
62         $geotag = '';
63
64         $o .= Renderer::replaceMacros(Renderer::getMarkupTemplate("section_title.tpl"), [
65                 '$title' => DI::l10n()->t('Edit post')
66         ]);
67
68         $tpl = Renderer::getMarkupTemplate('jot-header.tpl');
69         DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl, [
70                 '$ispublic' => '&nbsp;', // DI::l10n()->t('Visible to <strong>everybody</strong>'),
71                 '$geotag' => $geotag,
72                 '$nickname' => $a->getLoggedInUserNickname(),
73                 '$is_mobile' => DI::mode()->isMobile(),
74         ]);
75
76         if (strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])) {
77                 $lockstate = 'lock';
78         } else {
79                 $lockstate = 'unlock';
80         }
81
82         $jotplugins = '';
83         $jotnets = '';
84
85         Hook::callAll('jot_tool', $jotplugins);
86
87         $tpl = Renderer::getMarkupTemplate('jot.tpl');
88         $o .= Renderer::replaceMacros($tpl, [
89                 '$is_edit' => true,
90                 '$return_path' => '/display/' . $item['guid'],
91                 '$action' => 'item',
92                 '$share' => DI::l10n()->t('Save'),
93                 '$loading' => DI::l10n()->t('Loading...'),
94                 '$upload' => DI::l10n()->t('Upload photo'),
95                 '$shortupload' => DI::l10n()->t('upload photo'),
96                 '$attach' => DI::l10n()->t('Attach file'),
97                 '$shortattach' => DI::l10n()->t('attach file'),
98                 '$weblink' => DI::l10n()->t('Insert web link'),
99                 '$shortweblink' => DI::l10n()->t('web link'),
100                 '$video' => DI::l10n()->t('Insert video link'),
101                 '$shortvideo' => DI::l10n()->t('video link'),
102                 '$audio' => DI::l10n()->t('Insert audio link'),
103                 '$shortaudio' => DI::l10n()->t('audio link'),
104                 '$setloc' => DI::l10n()->t('Set your location'),
105                 '$shortsetloc' => DI::l10n()->t('set location'),
106                 '$noloc' => DI::l10n()->t('Clear browser location'),
107                 '$shortnoloc' => DI::l10n()->t('clear location'),
108                 '$wait' => DI::l10n()->t('Please wait'),
109                 '$permset' => DI::l10n()->t('Permission settings'),
110                 '$wall' => $item['wall'],
111                 '$posttype' => $item['post-type'],
112                 '$content' => undo_post_tagging($item['body']),
113                 '$post_id' => $post_id,
114                 '$defloc' => $user['default-location'],
115                 '$visitor' => 'none',
116                 '$pvisit' => 'none',
117                 '$emailcc' => DI::l10n()->t('CC: email addresses'),
118                 '$public' => DI::l10n()->t('Public post'),
119                 '$jotnets' => $jotnets,
120                 '$title' => $item['title'],
121                 '$placeholdertitle' => DI::l10n()->t('Set title'),
122                 '$category' => Post\Category::getCSVByURIId($item['uri-id'], DI::userSession()->getLocalUserId(), Post\Category::CATEGORY),
123                 '$placeholdercategory' => (Feature::isEnabled(DI::userSession()->getLocalUserId(),'categories') ? DI::l10n()->t("Categories \x28comma-separated list\x29") : ''),
124                 '$emtitle' => DI::l10n()->t('Example: bob@example.com, mary@example.com'),
125                 '$lockstate' => $lockstate,
126                 '$acl' => '', // populate_acl((($group) ? $group_acl : $a->user)),
127                 '$bang' => ($lockstate === 'lock' ? '!' : ''),
128                 '$profile_uid' => $_SESSION['uid'],
129                 '$preview' => DI::l10n()->t('Preview'),
130                 '$jotplugins' => $jotplugins,
131                 '$cancel' => DI::l10n()->t('Cancel'),
132                 '$rand_num' => Crypto::randomDigits(12),
133
134                 // Formatting button labels
135                 '$edbold'   => DI::l10n()->t('Bold'),
136                 '$editalic' => DI::l10n()->t('Italic'),
137                 '$eduline'  => DI::l10n()->t('Underline'),
138                 '$edquote'  => DI::l10n()->t('Quote'),
139                 '$edcode'   => DI::l10n()->t('Code'),
140                 '$edurl'    => DI::l10n()->t('Link'),
141                 '$edattach' => DI::l10n()->t('Link or Media'),
142
143                 //jot nav tab (used in some themes)
144                 '$message' => DI::l10n()->t('Message'),
145                 '$browser' => DI::l10n()->t('Browser'),
146                 '$shortpermset' => DI::l10n()->t('Permissions'),
147
148                 '$compose_link_title' => DI::l10n()->t('Open Compose page'),
149         ]);
150
151         return $o;
152 }
153
154 function undo_post_tagging($s) {
155         $matches = null;
156         $cnt = preg_match_all('/([!#@])\[url=(.*?)\](.*?)\[\/url\]/ism', $s, $matches, PREG_SET_ORDER);
157         if ($cnt) {
158                 foreach ($matches as $mtch) {
159                         if (in_array($mtch[1], ['!', '@'])) {
160                                 $contact = Contact::getByURL($mtch[2], false, ['addr']);
161                                 $mtch[3] = empty($contact['addr']) ? $mtch[2] : $contact['addr'];
162                         }
163                         $s = str_replace($mtch[0], $mtch[1] . $mtch[3],$s);
164                 }
165         }
166         return $s;
167 }