-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjournal.php
More file actions
105 lines (88 loc) · 3.67 KB
/
journal.php
File metadata and controls
105 lines (88 loc) · 3.67 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
require_once 'db.php';
//Default settings $_GET request
$sHeader = "<h2>What a great day for journaling!</h2>\n";
$sContent = '<p>Start typing...</p>';
$sContentDisplay = $sContent;
$db = new JournalDatabase();
//Get database version
$version = $db->getDBVersion();
//Get all journal entries to display
$displayEntries = $db->fetchDisplayJournalEntries();
if (count($displayEntries) < 1) {
$sContentPostDisplay = "No content to display.<br />";
} else {
$sContentPostDisplay = "<h2>Journal Entries - " . "<small><i>Showing " . count($displayEntries) . " entries of " . $db->fetchNumberOfJournalEntries() . " total:</i></small></h2>";
}
//Allowed input
$allowedTags = '<p><strong><em><u><h1><h2><h3><h4><h5><h6><img>';
$allowedTags .= '<li><ol><ul><span><div><br><ins><del>';
//$_POST request processing
if (isset($_POST['tinyContent']) && $_POST['tinyContent'] != '') {
$sTitle = strip_tags(stripslashes($_POST['title']), $allowedTags);
$sContent = strip_tags(stripslashes($_POST['tinyContent']), $allowedTags) . "\n";
$sContentPostDisplay = "<b><i>Preview: <br />" . substr($sContent, 0, 250) . "</i></b>"; //only show a snippet of the new post, TODO
//Saving new journal entry to database
//Set page header to output status of database operation
$sHeader = $db->insertJournalEntry(journalEntry: (new JournalEntry(title: $sTitle, contentBody: $sContent)));
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script src="https://cdn.tiny.cloud/1/hahp7c2g5bvxi9592n0tg3nut01jw5ywe7pdkonv19qpfnp0/tinymce/6/tinymce.min.js" referrerpolicy="origin"></script>
<script src="https://cdn.jsdelivr.net/npm/@tinymce/tinymce-jquery@1/dist/tinymce-jquery.min.js"></script>
</head>
<body>
<?php echo $sHeader; ?>
<?php echo "\n <strong><em>Database version: " . $version . "</em></strong>"; ?>
<?php echo "<br />"; ?>
<?php echo "<hr />"; ?>
<a href='login.php'>Login </a><small>|</small>
<a href='logout.php'>Logout </a><small>|</small>
<a href='/dbinfo'>Database Info </a>
<div>
<form method="POST" action="<?= $_SERVER['REQUEST_URI'] ?>">
<br />
<label>New Post Title:</label>
<br />
<textarea id="title" name="title"></textarea>
<textarea id="tinyContent" name="tinyContent"><?php echo $sContentDisplay; ?></textarea>
<br />
<input type="submit" name="save" value="Submit" />
<!--<input type="reset" name="reset" value="Reset" />-->
</form>
</div>
<script>
$('textarea#tinyContent').tinymce({
height: 500,
menubar: false,
plugins: [
'a11ychecker', 'advlist', 'advcode', 'advtable', 'autolink', 'checklist', 'export',
'lists', 'link', 'image', 'charmap', 'preview', 'anchor', 'searchreplace', 'visualblocks',
'powerpaste', 'fullscreen', 'formatpainter', 'insertdatetime', 'media', 'table', 'help', 'wordcount'
],
toolbar: 'undo redo | a11ycheck casechange blocks | bold italic backcolor | alignleft aligncenter alignright alignjustify | bullist numlist checklist outdent indent | removeformat | code table help'
});
</script>
<hr />
<?php echo $sContentPostDisplay; ?>
<?php
foreach ($displayEntries as $entry) {
echo "<hr />";
echo "<br />";
echo "<br />";
echo "<strong>Title: </strong>" . $entry['title'];
echo "<br />";
echo $entry['contentBody'];
echo "<br />";
echo "<strong>Time Posted</strong>: " . $entry['created_time'];
echo "<br />";
echo "<hr />";
}
?>
</body>
</html>