-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrafts.php
More file actions
58 lines (44 loc) · 1.94 KB
/
Copy pathdrafts.php
File metadata and controls
58 lines (44 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
declare(strict_types=1);
require __DIR__ . '/src/init.php';
Auth::requireLogin();
$draft_id = (int) ($_GET['draft'] ?? 0);
// /drafts - everything staged, waiting.
if ($draft_id === 0) {
$page = new Page(['title' => (string) (Strings::for('PageTitle')['drafts'] ?? '')]);
$page -> addContent(new StagedPostList(['userId' => (int) Auth::id()]));
$page -> send();
exit;
}
// /drafts/{id} - the composer itself, holding this draft. The whole composer,
// so a draft is edited with everything a post is written with rather than a
// lesser form standing in for it.
$draft = StagedPost::load($draft_id);
if ($draft === null || (int) $draft -> userId !== (int) Auth::id()) {
require __DIR__ . '/404.php';
exit;
}
$page = new Page([
'title' => $draft -> publishAt === null
? (string) (Strings::for('PageTitle')['draftsEditDraft'] ?? '')
: (string) (Strings::for('PageTitle')['draftsEditScheduled'] ?? ''),
'needsEditor' => true,
'needsEmoji' => true,
'needsMath' => true,
]);
$composer = new PostComposer();
$composer -> attributes['data-staged-post-id'] = (string) $draft -> stagedPostId;
$composer -> attributes['data-title'] = (string) ($draft -> title ?? '');
$composer -> attributes['data-description-delta'] = (string) ($draft -> descriptionDelta ?? '');
$composer -> attributes['data-link-url'] = (string) ($draft -> linkURL ?? '');
$composer -> attributes['data-sensitive'] = (string) $draft -> sensitive;
$composer -> attributes['data-content-warning'] = (string) ($draft -> contentWarning ?? '');
if ($draft -> publishAt !== null) {
$composer -> attributes['data-publish-at-epoch'] = (string) strtotime((string) $draft -> publishAt);
}
if ($draft -> latitude !== null && $draft -> longitude !== null) {
$composer -> attributes['data-latitude'] = (string) $draft -> latitude;
$composer -> attributes['data-longitude'] = (string) $draft -> longitude;
}
$page -> addContent($composer);
$page -> send();