-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview-category.php
148 lines (144 loc) · 5.68 KB
/
view-category.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
try {
$root = dirname(__FILE__);
require "$root/includes/init.php";
require "$root/includes/formatting.php";
switch($_SERVER['REQUEST_METHOD']) {
case 'GET': break;
default: throw new invalid_request_method_error(__FILE__, __LINE__);
}
$category_id = isset($_GET['id']) ? (int)$_GET['id'] : null;
if ($category_id) {
$category = $da->get_category($category_id);
} else {
throw new page_not_found_error(__FILE__, __LINE__);
}
$tags = $da->get_tags(24);
$categories = $da->get_categories(12);
$posts = $da->get_discussions_by_category_id($category_id);
} catch(Exception $e) {
if (method_exists($e, 'process_error')) { // check if custom error
$e->process_error();
}
error_log($e);
die('Unexpected error occurred. Please try again in a few minutes.');
}
?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<title>wheel - Home</title>
<link rel="icon" type="image/png" sizes="32x32" href="/images/favicons/32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="/images/favicons/96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="/images/favicons/16x16.png">
<link rel="shortcut icon" type="image/x-icon" href="/images/favicons/favicon.ico">
<link href="/fonts/font-awesome/css/fontawesome-all.css" rel="stylesheet" type="text/css">
<link href="/css/wheel_v2.css?v=<?php echo time();?>" rel="stylesheet" type="text/css">
<script src='/js/wheel.js' type='text/javascript'></script>
<script src='/js/event_handlers.js' type='text/javascript'></script>
</head>
<body>
<div class='site-header'>
<div class='inner'>
<div class='grid'>
<div class='site-logo'>
<a href='/'></a>
</div> <!-- .site-logo -->
<div class='site-search'>
<form action='/search.php' method='get'>
<input type='text' name='q' placeholder='Search'>
<button type='submit'>
<i class="fas fa-search"></i>
</button>
</form>
</div>
<div class='nav-menu'>
<ul class='list list-inline'>
<li><a href='new-discussion.php'>New Discussion</a></li>
<?php
if (!isset($_SESSION['user_id'])) {
echo "<li><a href='/register.php'>Register</a></li>
<li><a href='/login.php'>Login</a></li>";
} else {
echo "<li><a href='/account.php'>Account</a></li>
<li><a href='/logout.php'>Logout</a></li>";
}
?>
</ul>
</div>
</div> <!-- .grid -->
</div> <!-- .inner -->
</div> <!-- .site-header -->
<div class='site-content'>
<div class='site-main-grid'>
<div class='col-left'>
<div class='block-title'>Feed</div>
<a class='feed-link <?php echo ($active_link==1?'selected':''); ?>' href='/'>Latest Discussions</a>
<a class='feed-link <?php echo ($active_link==2?'selected':''); ?>' href='?rc'>Saved Discussions</a>
<a class='feed-link <?php echo ($active_link==3?'selected':''); ?>' href='?tr'>Top Trending</a>
</div>
<div class='col-middle'>
<div class='block-title'>Discussions on '<?php echo $category['category_name']; ?>' <span class='text-mute text-bold clickable' data-category-id='<?php echo $category_id; ?>' data-state='-' id='subscription'></span></div>
<?php
foreach($posts as $post) {
echo "<div class='card-post-list'>
<div class='post-list-title'>
<a href='view-discussion.php?id={$post['post_id']}'>
<span>{$post['post_title']}</span>
</a>
</div>
<div class='text-mute'>Submitted " . time_elapsed_string($post['submitted_ts']) .
" · by " . ($post['author_id']?'Someone' : 'Guest') .
" · <span class='text-bold' id='rc{$post['post_id']}'>-</span></div>
<div class='post-list-footer' id='post{$post['post_id']}'>
<span class='badge badge-cat'>Category: <a class='text-bold' href='view-category.php?id={$post['category_id']}'>{$post['category_name']}</a></span>
</div>
</div>";
}
?>
</div>
<div class='col-right'>
<div class='card'>
<div class='card-header'>Categories</div>
<?php
foreach($categories as $cat) {
echo "<a class='category' href='/view-category.php?id={$cat['category_id']}'>{$cat['category_name']}</a>";
}
?>
<a class='category' href='/view-categories.php'><b>View all categories</b></a>
</div> <!-- .card -->
<div class='card'>
<div class='card-header'>Tags</div>
<div class='card-body tags'>
<?php
foreach($tags as $tag) {
echo "<a class='tag' href='/view-tag.php?t={$tag['tag']}'>{$tag['tag']}</a>";
}
?>
</div>
<a class='category' href='/view-tags.php'><b>View all tags</b></a>
</div> <!-- .card -->
</div>
</div> <!-- .site-main-grid -->
</div> <!-- .site-content -->
<div class='site-footer'>
<a href='About'>About</a>
<a href='About'>Privacy</a>
<br>
© 2018 wheel.
Timezone: <?php echo $_SESSION['timezone_name']; ?>,
Country: <?php echo $_SESSION['country_name']; ?>
(<a class='text-bold' href=''>Change</a>)
</div> <!-- .site-footer -->
<script type='text/javascript'>
(function() {
<?php
if (isset($_SESSION['user_id'])) {
echo "ID('subscription').addEventListener('click', subscription_handler);ID('subscription').click();";
}
?>
})();
</script>
</body>
</html>