-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
125 lines (111 loc) · 4.32 KB
/
index.php
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<!DOCTYPE html>
<html lang="en">
<head>
<?php include('includes/globalHead.html'); ?>
<script src="https://cdn.jsdelivr.net/momentjs/2.18.1/moment.min.js"></script>
<title>Discussion Board — Main</title>
<style>
.post {
margin-bottom: 0px !important; /* Use !important to override semantic's default margin */
}
#mainHeader {
font-size: 3em;
font-weight: normal;
}
</style>
<script>
function createPostFromJSON(row) {
/*
Making DOM elements in jQuery to create a complicated html element.
See documentation to view what this output looks like in human-readable
html.
*/
var $post = $("<div/>", { // Post container
"postID" : row['postID'],
"class" : "ui stacked segment"
});
var $postHeaderContainer = $("<div/>", { // Post header
"class" : "post ui clearing basic segment"
});
// Create all "right side" header details
var $postHeaderRight = $("<h4/>", {
"class" : "ui right floated header"
});
$postHeaderRight.append($("<a/>", {
"href" : "util/bumpPostRating.php?postID="+row['postID']+"&direction=down",
"text" : "-"
}));
$postHeaderRight.append(" "+row['rating']+" ");
$postHeaderRight.append($("<a/>", {
"href" : "util/bumpPostRating.php?postID="+row['postID']+"&direction=up",
"text" : "+"
}));
var $postSubheaderRight = $("<div/>", {
"class" : "sub header",
"style" : "text-align: center"
});
/* Disabled, as reply function was removed due to lack of time.
$postSubheaderRight.append($("<a/>", {
"href" : "#",
"text" : "Reply"
}));
*/
$postHeaderRight.append($postSubheaderRight);
// End "right side" header elements
// Create all "left side" header details
var $postHeaderLeft = $("<h3/>", {
"class" : "ui left floated header",
"text" : row["title"]
});
var $parsedTimestamp = moment(row['postTime']); // Use Moment.js to display dateTime in a more human-friendly way
$postHeaderLeft.append($("<div/>", {
"class" : "sub header",
"text" : row['author']+" — "+$parsedTimestamp.format("MMMM Do, YYYY [at] h:mm a")
}));
// End "left side" header elements
// Add left and right header elements to the header container
$postHeaderContainer.append($postHeaderRight);
$postHeaderContainer.append($postHeaderLeft);
var $postContentContainer = $("<div/>", {
"class" : "ui basic attached basic segment"
});
var $postContent = $("<p/>");
$postContent.append(row['content']);
$postContentContainer.append($postContent);
// Add both containers to the post
$post.append($postHeaderContainer);
$post.append($postContentContainer);
return $post;
}
</script>
</head>
<body>
<!-- Menu bar -->
<?php
include("includes/menu.php");
drawMenu("home"); // Set Home tab active
?>
<!-- Page Contents -->
<div id="mainContainer">
<h1 class="ui block header" id="mainHeader">
<i class="huge comments icon"></i>
<div class="content">
Have something to talk about?
<div class="sub header">Let's talk about that. <a href="post.php">Share your thoughts.</a></div>
</div>
</h1>
<h2 class="ui dividing header">Most Recent Discussions</h1>
<div id="recentDiscussions"></div>
<script>
$.getJSON("/util/getPosts.php", {
"request" : "recent"
}).done(function(data) {
$.each(data, function(i, row) {
$("#recentDiscussions").append(createPostFromJSON(row));
});
});
</script>
</div>
<?php //include("includes/footer.html"); ?>
</body>
</html>