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