Issue 7142: Prevent respawn of "remote self" items
[friendica.git/.git] / mod / editpost.php
1 <?php
2 /**
3  * @file mod/editpost.php
4  */
5
6 use Friendica\App;
7 use Friendica\Content\Feature;
8 use Friendica\Core\Hook;
9 use Friendica\Core\L10n;
10 use Friendica\Core\Renderer;
11 use Friendica\Model\FileTag;
12 use Friendica\Model\Item;
13 use Friendica\Database\DBA;
14 use Friendica\Util\Crypto;
15
16 function editpost_content(App $a)
17 {
18         $o = '';
19
20         if (!local_user()) {
21                 notice(L10n::t('Permission denied.') . EOL);
22                 return;
23         }
24
25         $post_id = (($a->argc > 1) ? intval($a->argv[1]) : 0);
26
27         if (!$post_id) {
28                 notice(L10n::t('Item not found') . EOL);
29                 return;
30         }
31
32         $fields = ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
33                 'type', 'body', 'title', 'file', 'wall', 'post-type', 'guid'];
34
35         $item = Item::selectFirstForUser(local_user(), $fields, ['id' => $post_id, 'uid' => local_user()]);
36
37         if (!DBA::isResult($item)) {
38                 notice(L10n::t('Item not found') . EOL);
39                 return;
40         }
41
42         $geotag = '';
43
44         $o .= Renderer::replaceMacros(Renderer::getMarkupTemplate("section_title.tpl"), [
45                 '$title' => L10n::t('Edit post')
46         ]);
47
48         $tpl = Renderer::getMarkupTemplate('jot-header.tpl');
49         $a->page['htmlhead'] .= Renderer::replaceMacros($tpl, [
50                 '$ispublic' => '&nbsp;', // L10n::t('Visible to <strong>everybody</strong>'),
51                 '$geotag' => $geotag,
52                 '$nickname' => $a->user['nickname']
53         ]);
54
55         if (strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])) {
56                 $lockstate = 'lock';
57         } else {
58                 $lockstate = 'unlock';
59         }
60
61         $jotplugins = '';
62         $jotnets = '';
63
64         Hook::callAll('jot_tool', $jotplugins);
65
66         $tpl = Renderer::getMarkupTemplate("jot.tpl");
67         $o .= Renderer::replaceMacros($tpl, [
68                 '$is_edit' => true,
69                 '$return_path' => '/display/' . $item['guid'],
70                 '$action' => 'item',
71                 '$share' => L10n::t('Save'),
72                 '$upload' => L10n::t('Upload photo'),
73                 '$shortupload' => L10n::t('upload photo'),
74                 '$attach' => L10n::t('Attach file'),
75                 '$shortattach' => L10n::t('attach file'),
76                 '$weblink' => L10n::t('Insert web link'),
77                 '$shortweblink' => L10n::t('web link'),
78                 '$video' => L10n::t('Insert video link'),
79                 '$shortvideo' => L10n::t('video link'),
80                 '$audio' => L10n::t('Insert audio link'),
81                 '$shortaudio' => L10n::t('audio link'),
82                 '$setloc' => L10n::t('Set your location'),
83                 '$shortsetloc' => L10n::t('set location'),
84                 '$noloc' => L10n::t('Clear browser location'),
85                 '$shortnoloc' => L10n::t('clear location'),
86                 '$wait' => L10n::t('Please wait'),
87                 '$permset' => L10n::t('Permission settings'),
88                 '$wall' => $item['wall'],
89                 '$posttype' => $item['post-type'],
90                 '$content' => undo_post_tagging($item['body']),
91                 '$post_id' => $post_id,
92                 '$defloc' => $a->user['default-location'],
93                 '$visitor' => 'none',
94                 '$pvisit' => 'none',
95                 '$emailcc' => L10n::t('CC: email addresses'),
96                 '$public' => L10n::t('Public post'),
97                 '$jotnets' => $jotnets,
98                 '$title' => $item['title'],
99                 '$placeholdertitle' => L10n::t('Set title'),
100                 '$category' => FileTag::fileToList($item['file'], 'category'),
101                 '$placeholdercategory' => (Feature::isEnabled(local_user(),'categories') ? L10n::t("Categories \x28comma-separated list\x29") : ''),
102                 '$emtitle' => L10n::t('Example: bob@example.com, mary@example.com'),
103                 '$lockstate' => $lockstate,
104                 '$acl' => '', // populate_acl((($group) ? $group_acl : $a->user)),
105                 '$bang' => ($lockstate === 'lock' ? '!' : ''),
106                 '$profile_uid' => $_SESSION['uid'],
107                 '$preview' => L10n::t('Preview'),
108                 '$jotplugins' => $jotplugins,
109                 '$sourceapp' => L10n::t($a->sourcename),
110                 '$cancel' => L10n::t('Cancel'),
111                 '$rand_num' => Crypto::randomDigits(12),
112
113                 //jot nav tab (used in some themes)
114                 '$message' => L10n::t('Message'),
115                 '$browser' => L10n::t('Browser'),
116                 '$shortpermset' => L10n::t('permissions'),
117         ]);
118
119         return $o;
120 }