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