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