]> git.mxchange.org Git - friendica.git/blob - mod/editpost.php
Move random Digits to Crypto class
[friendica.git] / mod / editpost.php
1 <?php
2 /**
3  * @file mod/editpost.php
4  */
5 use Friendica\App;
6 use Friendica\Content\Feature;
7 use Friendica\Core\Addon;
8 use Friendica\Core\Config;
9 use Friendica\Core\L10n;
10 use Friendica\Core\Renderer;
11 use Friendica\Core\System;
12 use Friendica\Model\FileTag;
13 use Friendica\Model\Item;
14 use Friendica\Database\DBA;
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                 '$baseurl' => System::baseUrl(),
52                 '$ispublic' => '&nbsp;', // L10n::t('Visible to <strong>everybody</strong>'),
53                 '$geotag' => $geotag,
54                 '$nickname' => $a->user['nickname']
55         ]);
56
57         $tpl = Renderer::getMarkupTemplate("jot.tpl");
58
59         if (strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])) {
60                 $lockstate = 'lock';
61         } else {
62                 $lockstate = 'unlock';
63         }
64
65         $jotplugins = '';
66         $jotnets = '';
67
68         $mail_disabled = ((function_exists('imap_open') && !Config::get('system', 'imap_disabled')) ? 0 : 1);
69
70         $mail_enabled = false;
71         $pubmail_enabled = false;
72
73         if (!$mail_disabled) {
74                 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
75                         intval(local_user())
76                 );
77
78                 if (DBA::isResult($r)) {
79                         $mail_enabled = true;
80
81                         if (intval($r[0]['pubmail'])) {
82                                 $pubmail_enabled = true;
83                         }
84                 }
85         }
86
87         Addon::callHooks('jot_tool', $jotplugins);
88         //Addon::callHooks('jot_networks', $jotnets);
89
90         $o .= Renderer::replaceMacros($tpl, [
91                 '$is_edit' => true,
92                 '$return_path' => '/display/' . $item['guid'],
93                 '$action' => 'item',
94                 '$share' => L10n::t('Save'),
95                 '$upload' => L10n::t('Upload photo'),
96                 '$shortupload' => L10n::t('upload photo'),
97                 '$attach' => L10n::t('Attach file'),
98                 '$shortattach' => L10n::t('attach file'),
99                 '$weblink' => L10n::t('Insert web link'),
100                 '$shortweblink' => L10n::t('web link'),
101                 '$video' => L10n::t('Insert video link'),
102                 '$shortvideo' => L10n::t('video link'),
103                 '$audio' => L10n::t('Insert audio link'),
104                 '$shortaudio' => L10n::t('audio link'),
105                 '$setloc' => L10n::t('Set your location'),
106                 '$shortsetloc' => L10n::t('set location'),
107                 '$noloc' => L10n::t('Clear browser location'),
108                 '$shortnoloc' => L10n::t('clear location'),
109                 '$wait' => L10n::t('Please wait'),
110                 '$permset' => L10n::t('Permission settings'),
111                 '$wall' => $item['wall'],
112                 '$posttype' => $item['post-type'],
113                 '$content' => undo_post_tagging($item['body']),
114                 '$post_id' => $post_id,
115                 '$baseurl' => System::baseUrl(),
116                 '$defloc' => $a->user['default-location'],
117                 '$visitor' => 'none',
118                 '$pvisit' => 'none',
119                 '$emailcc' => L10n::t('CC: email addresses'),
120                 '$public' => L10n::t('Public post'),
121                 '$jotnets' => $jotnets,
122                 '$title' => htmlspecialchars($item['title']),
123                 '$placeholdertitle' => L10n::t('Set title'),
124                 '$category' => FileTag::fileToList($item['file'], 'category'),
125                 '$placeholdercategory' => (Feature::isEnabled(local_user(),'categories') ? L10n::t("Categories \x28comma-separated list\x29") : ''),
126                 '$emtitle' => L10n::t('Example: bob@example.com, mary@example.com'),
127                 '$lockstate' => $lockstate,
128                 '$acl' => '', // populate_acl((($group) ? $group_acl : $a->user)),
129                 '$bang' => ($lockstate === 'lock' ? '!' : ''),
130                 '$profile_uid' => $_SESSION['uid'],
131                 '$preview' => L10n::t('Preview'),
132                 '$jotplugins' => $jotplugins,
133                 '$sourceapp' => L10n::t($a->sourcename),
134                 '$cancel' => L10n::t('Cancel'),
135                 '$rand_num' => Crypto::randomDigits(12),
136
137                 //jot nav tab (used in some themes)
138                 '$message' => L10n::t('Message'),
139                 '$browser' => L10n::t('Browser'),
140                 '$shortpermset' => L10n::t('permissions'),
141         ]);
142
143         return $o;
144 }