3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
23 use Friendica\Content\Feature;
24 use Friendica\Core\Hook;
25 use Friendica\Core\Renderer;
26 use Friendica\Database\DBA;
28 use Friendica\Model\Contact;
29 use Friendica\Model\FileTag;
30 use Friendica\Model\Item;
31 use Friendica\Model\Post;
32 use Friendica\Util\Crypto;
34 function editpost_content(App $a)
39 notice(DI::l10n()->t('Permission denied.'));
43 $post_id = (($a->argc > 1) ? intval($a->argv[1]) : 0);
46 notice(DI::l10n()->t('Item not found'));
50 $fields = ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
51 'type', 'body', 'title', 'file', 'wall', 'post-type', 'guid'];
53 $item = Post::selectFirstForUser(local_user(), $fields, ['id' => $post_id, 'uid' => local_user()]);
55 if (!DBA::isResult($item)) {
56 notice(DI::l10n()->t('Item not found'));
62 $o .= Renderer::replaceMacros(Renderer::getMarkupTemplate("section_title.tpl"), [
63 '$title' => DI::l10n()->t('Edit post')
66 $tpl = Renderer::getMarkupTemplate('jot-header.tpl');
67 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl, [
68 '$ispublic' => ' ', // DI::l10n()->t('Visible to <strong>everybody</strong>'),
70 '$nickname' => $a->user['nickname'],
71 '$is_mobile' => DI::mode()->isMobile(),
74 if (strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])) {
77 $lockstate = 'unlock';
83 Hook::callAll('jot_tool', $jotplugins);
85 $tpl = Renderer::getMarkupTemplate("jot.tpl");
86 $o .= Renderer::replaceMacros($tpl, [
88 '$return_path' => '/display/' . $item['guid'],
90 '$share' => DI::l10n()->t('Save'),
91 '$loading' => DI::l10n()->t('Loading...'),
92 '$upload' => DI::l10n()->t('Upload photo'),
93 '$shortupload' => DI::l10n()->t('upload photo'),
94 '$attach' => DI::l10n()->t('Attach file'),
95 '$shortattach' => DI::l10n()->t('attach file'),
96 '$weblink' => DI::l10n()->t('Insert web link'),
97 '$shortweblink' => DI::l10n()->t('web link'),
98 '$video' => DI::l10n()->t('Insert video link'),
99 '$shortvideo' => DI::l10n()->t('video link'),
100 '$audio' => DI::l10n()->t('Insert audio link'),
101 '$shortaudio' => DI::l10n()->t('audio link'),
102 '$setloc' => DI::l10n()->t('Set your location'),
103 '$shortsetloc' => DI::l10n()->t('set location'),
104 '$noloc' => DI::l10n()->t('Clear browser location'),
105 '$shortnoloc' => DI::l10n()->t('clear location'),
106 '$wait' => DI::l10n()->t('Please wait'),
107 '$permset' => DI::l10n()->t('Permission settings'),
108 '$wall' => $item['wall'],
109 '$posttype' => $item['post-type'],
110 '$content' => undo_post_tagging($item['body']),
111 '$post_id' => $post_id,
112 '$defloc' => $a->user['default-location'],
113 '$visitor' => 'none',
115 '$emailcc' => DI::l10n()->t('CC: email addresses'),
116 '$public' => DI::l10n()->t('Public post'),
117 '$jotnets' => $jotnets,
118 '$title' => $item['title'],
119 '$placeholdertitle' => DI::l10n()->t('Set title'),
120 '$category' => FileTag::fileToList($item['file'], 'category'),
121 '$placeholdercategory' => (Feature::isEnabled(local_user(),'categories') ? DI::l10n()->t("Categories \x28comma-separated list\x29") : ''),
122 '$emtitle' => DI::l10n()->t('Example: bob@example.com, mary@example.com'),
123 '$lockstate' => $lockstate,
124 '$acl' => '', // populate_acl((($group) ? $group_acl : $a->user)),
125 '$bang' => ($lockstate === 'lock' ? '!' : ''),
126 '$profile_uid' => $_SESSION['uid'],
127 '$preview' => DI::l10n()->t('Preview'),
128 '$jotplugins' => $jotplugins,
129 '$sourceapp' => DI::l10n()->t($a->sourcename),
130 '$cancel' => DI::l10n()->t('Cancel'),
131 '$rand_num' => Crypto::randomDigits(12),
133 //jot nav tab (used in some themes)
134 '$message' => DI::l10n()->t('Message'),
135 '$browser' => DI::l10n()->t('Browser'),
136 '$shortpermset' => DI::l10n()->t('Permissions'),
138 '$compose_link_title' => DI::l10n()->t('Open Compose page'),
144 function undo_post_tagging($s) {
146 $cnt = preg_match_all('/([!#@])\[url=(.*?)\](.*?)\[\/url\]/ism', $s, $matches, PREG_SET_ORDER);
148 foreach ($matches as $mtch) {
149 if (in_array($mtch[1], ['!', '@'])) {
150 $contact = Contact::getByURL($mtch[2], false, ['addr']);
151 $mtch[3] = empty($contact['addr']) ? $mtch[2] : $contact['addr'];
153 $s = str_replace($mtch[0], $mtch[1] . $mtch[3],$s);