-
Notifications
You must be signed in to change notification settings - Fork 0
/
blog.php
391 lines (364 loc) · 14.9 KB
/
blog.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
<?php
require_once("includes/session.php");
require_once("includes/functions.php");
if(isset($_GET['delpost'])&&$_GET['delpost']!=''){
if(check_permission("Blog","delete_blog")||(isset($_SESSION['user_id'])&&$galleryid['poster']==$_SESSION['user_id'])){
$query="SELECT * FROM `blog` WHERE id={$_GET['delpost']}";
$result = mysqli_query( $connection, $query);
confirm_query($result);
if(mysqli_num_rows($result)!=0){
$galleryid=mysqli_fetch_array($result);
//Get blog gallery name for folder deletion
$query="SELECT `name` FROM `galleries` WHERE `id` = {$galleryid['gallery_id']}";
$result=mysqli_query($connection, $query);
confirm_query($result);
$gallname = mysqli_fetch_array($result);
$gallname = $gallname['name'];
//Delete gallery from DB
$query="DELETE FROM `galleries` WHERE `id` = {$galleryid['gallery_id']}";
$result=mysqli_query($connection, $query);
confirm_query($result);
//Delete gallery items from DB
$query="DELETE FROM `site_gallery_items` WHERE `gallery_id` = {$galleryid['gallery_id']}";
$result=mysqli_query($connection, $query);
confirm_query($result);
//Delete blog post
$query="DELETE FROM `blog` WHERE `id` = {$_GET['delpost']}";
$result=mysqli_query($connection, $query);
confirm_query($result);
//Delete comments for that blog
$query="DELETE FROM `blog_comments` WHERE `blog_id` = {$_GET['delpost']}";
$result=mysqli_query($connection, $query);
confirm_query($result);
//Specify the target directory and add forward slash
$dir = USER_DIR."blog-galleries/".$gallname."/gallery/";
foreach (scandir($dir) as $item) {
if ($item == '.' || $item == '..') continue;
unlink($dir.DIRECTORY_SEPARATOR.$item);
}
rmdir($dir);
$dir = USER_DIR."blog-galleries/".$gallname."/gallery-thumbs/";
foreach (scandir($dir) as $item) {
if ($item == '.' || $item == '..') continue;
unlink($dir.DIRECTORY_SEPARATOR.$item);
}
rmdir($dir);
$dir = USER_DIR."blog-galleries/".$gallname."/";
rmdir($dir);
$success="Blog post deleted!";
}else{
$error="Blog post does not exist!";
}
}else{
$error="You do not have permission to delete this post!";
}
}
if(isset($_GET['pg'])&&$_GET['pg']<=0){
//redirect_to($GLOBALS['HOST']."/blog?page=1");
}
$flag = TRUE;
foreach(get_included_files() as $index => $string) {
if (strpos($string, 'index.php') !== FALSE){
$flag = FALSE;
break;
}
}
if($flag === TRUE){
redirect_to($GLOBALS['HOST'].'/page/'.$GLOBALS['blog_page']);
}
$query="SELECT * FROM `blog`";
$result=mysqli_query( $connection, $query);
$num_posts = mysqli_num_rows($result);
$num_pages = ceil($num_posts/10);
if(isset($_GET['pg'])&&$_GET['pg']>=1){
$current_page = $_GET['pg'];
}else{
$current_page = 1;
}
$query="SELECT * FROM `blog` ORDER BY `datecreated` DESC LIMIT ";
$query.=(($current_page * 10)-10).",".($current_page * 10);
$blogresult=mysqli_query( $connection, $query);
$query="SELECT * FROM `pages` WHERE `type` = 'Blog'";
$result_page_prop=mysqli_query( $connection, $query);
$page_properties = mysqli_fetch_array($result_page_prop);
?>
<script type="text/javascript">
$(document).ready(function () {
$(".btn-click-action").click(function(){
$("#del_button").attr("href", "<?php echo $GLOBALS['HOST'].'/page/'.$GLOBALS['blog_page']; ?>&delpost="+$(this).attr('name'));
});
});
function sendComment(postId){
$('#comment-sendbtn-'+postId).html('<img src="<?php echo $GLOBALS['HOST'];?>/images/ajax-load.gif" style="margin-left:10px; margin-top:10px;"/>');
$.post("<?php echo $GLOBALS['HOST'];?>/ajax_processing/post_blog_comment.php",
{
commentData: $('#blog-comment-'+postId).val(),
blogId: postId,
},
function(data, status){
if(status == 'success'){
switch(data){
case 'empty':
Materialize.toast('Comment cannot be empty.', 8000, 'red');
$('#comment-sendbtn-'+postId).html('<i class="material-icons">send</i>');
$('#blog-comment-'+postId).val("");
$('#blog-comment-'+postId).attr('rows', '1');
$('#blog-comment-'+postId).height('auto');
break;
case 'permission':
Materialize.toast('You do not have permission to post comments.', 8000, 'red');
$('#comment-sendbtn-'+postId).html('<i class="material-icons">send</i>');
break;
case 'disabled':
Materialize.toast('Comments have been disabled for this post.', 8000, 'red');
$('#comment-sendbtn-'+postId).html('<i class="material-icons">send</i>');
break;
case 'deleted':
Materialize.toast('Blog post has been deleted.', 8000, 'red');
$('#comment-sendbtn-'+postId).html('<i class="material-icons">send</i>');
break;
default:
$("#comment-block-"+postId).append(data);
$('#blog-comment-'+postId).val("");
$('#blog-comment-'+postId).attr('rows', '1');
$('#blog-comment-'+postId).height('auto');
$('#comment-sendbtn-'+postId).html('<i class="material-icons">send</i>');
break;
}
}else{
Materialize.toast('An error has occured. Try again later.', 8000, 'red');
$('#comment-sendbtn-'+postId).html('<i class="material-icons">send</i>');
}
});
}
function viewMore(postId, numComments){
$.get("<?php echo $GLOBALS['HOST'];?>/ajax_processing/get_blog_comments.php?blogid="+postId+"&commlimit="+numComments, function(data, status){
if(status == 'success'){
$('#comment-wrap-'+postId).html(data);
}else{
Materialize.toast('An error has occured. Try again later.', 8000, 'red');
}
});
}
function delComment(postId){
$.post("<?php echo $GLOBALS['HOST'];?>/ajax_processing/delete_blog_comment.php",
{
id: postId,
},
function(data, status){
if(status == 'success'){
switch(data){
case 'invalPerms':
Materialize.toast('Insufficient permission.', 8000, 'red');
break;
case 'notExist':
Materialize.toast('Comment does not exist.', 8000, 'red');
break;
default:
$('#del-comment-'+postId).parent().remove();
Materialize.toast('Comment deleted!', 8000, 'green');
break;
}
}else{
Materialize.toast('An error has occured. Try again later.', 8000, 'red');
}
});
}
</script>
<h1><?php echo $page['name']; ?></h1>
<?php if (logged_in()){?>
<div style="float: right;">
Subscribe <?php echo_subscription_checkbox('blog', 1); ?>
</div>
<?php
}
if (mysqli_num_rows($result)!=0){
if(check_permission("Blog","post_blog")){?>
<a class="btn-floating green" href="../new_blog_post"><i class="material-icons">add</i></a>
<?php }?>
</div>
<div id="blog">
<div class="row">
<?php
if($num_pages>1){
echo_page($num_pages, $current_page, 'page/'.$page['name']);
}
?>
</div>
<?php
//counter to separate galleries from each other
$gall_num = 0;
//Default limit number blog comments
$_GET['commlimit']=5;
while($post=mysqli_fetch_array($blogresult)){
$query="SELECT * FROM `users` WHERE `id` = ".$post['poster'];
$userresult=mysqli_query( $connection, $query);
$userdata=mysqli_fetch_array($userresult);
$createdtimestamp = strtotime($post['datecreated']);
$lasteditedtimestamp = strtotime($post['datecreated']);
if(!file_exists(USER_DIR."blog-galleries/".$post['id'])){
mkdir(USER_DIR."blog-galleries/".$post['id']);
}
if(!file_exists(USER_DIR."blog-galleries/".$post['id']."/gallery/")){
mkdir(USER_DIR."blog-galleries/".$post['id']."/gallery/");
}
if(!file_exists(USER_DIR."blog-galleries/".$post['id']."/gallery-thumbs/")){
mkdir(USER_DIR."blog-galleries/".$post['id']."/gallery-thumbs/");
}
?>
<table width="100%" height="100%" class="blog card">
<tr>
<td colspan="2">
<div class="title" width="100%" height="100%">
<h2><a href="<?php echo $GLOBALS['HOST']?>/view_blog_post?post=<?php echo $post['id']; ?>"><?php echo $post['title']; ?></a></h2>
<div class="container">
<div class="row right blog-btn">
<div class="col l12 s12">
<?php if(check_permission("Blog","edit_blog")||(isset($_SESSION['user_id'])&&$post['poster']==$_SESSION['user_id'])){?><a class="btn-floating blue" href="<?php echo $GLOBALS['HOST']; ?>/edit_blog_post.php?post=<?php echo $post['id'] ?>"><i class="material-icons">edit</i></a><?php } ?>
<?php if(check_permission("Blog","delete_blog")||(isset($_SESSION['user_id'])&&$post['poster']==$_SESSION['user_id'])){?>
<a class="modal-trigger btn-floating red btn-click-action" href="#modal1" name="<?php echo $post['id'] ?>"><i class="material-icons">delete</i></a><?php } ?>
</div>
</div>
</div>
</div>
</td>
</tr>
<tr>
<td width="80%" valign="top">
<table width="100%" height="100%">
<tr>
<div class="blogname">
<div class="row">
<div class="col l2 s4">
<i class="mdi-device-access-time"></i> <?php echo date("g:i A", $createdtimestamp);
/* if($post['lastedited']!="0000-00-00 00:00:00"){
$lasteditedtimestamp = strtotime($post['lastedited']);
echo '<i class="mdi-editor-mode-edit"></i> '.date("g:i A", $lasteditedtimestamp);
}
else{
echo '<i class="mdi-device-access-time"></i> ' .date("M jS 'y", $createdtimestamp);
}*/
?>
</div>
<div class="col l2 s4">
<i class="mdi-action-today"></i> <?php echo date("M jS 'y", $createdtimestamp);
/* if($post['lastedited']!="0000-00-00 00:00:00"){
$lasteditedtimestamp = strtotime($post['lastedited']);
echo '<i class="mdi-editor-mode-edit"></i> '.date("M jS 'y", $lasteditedtimestamp);
}
else{
echo '<i class="mdi-action-today"></i> ' .date("M jS 'y", $createdtimestamp);
}*/
?>
</div>
<div class="col s4">
<img src="<?php echo get_user_profile_pic($userdata['id']); ?>" alt="<?php echo $userdata['username']; ?>" style="margin-top: 3px; width:18px; height: 18px;" />
<a href="<?php echo $GLOBALS['HOST'].'/profile/'.urlencode($userdata['username']); ?>"><b><?php echo $userdata['username']; ?></b></a>
</div>
</div>
</div>
</tr>
<tr>
<td class="blogbody" valign="top">
<?php if($GLOBALS['site_info']['user_profile_pictures']){ ?>
<a href="<?php echo $GLOBALS['HOST'].'/profile/'.urlencode($userdata['username']); ?>" class="blog-profile-pic" style="float: left; margin: 0px 10px 10px 0px;"><img src="<?php echo get_user_profile_pic($userdata['id']); ?>"></a>
<?php } ?>
<?php $content = $post['content'];
if (strlen($content) > 1200) {
// truncate string
$stringCut = substr($content, 0, 600);
// make sure it ends in a word so assassinate doesn't become ass...
$content = substr($stringCut, 0, strrpos($stringCut, ' ')).'... <a class="waves-effect waves-blue btn-flat" href="'.$GLOBALS['HOST'].'/view_blog_post?post='.$post['id'].'">Read More</a>';
}
echo $content;
//echo print_r(unserialize($userdata['subscriptions']));
?>
</td>
</tr>
<tr>
<td colspan="2">
<?php
$i = 0;
$files = glob(USER_DIR."blog-galleries/".$post['id']."/gallery/" . "*");
if ($files){
$i = count($files);
}
if($i>0){gallery($post['gallery_id'], $gall_num, 7);}
$gall_num++;?>
</td>
</tr>
<?php if($post['comments_allowed'] == 1){?>
<tr>
<td colspan="2">
<div class="blog-comments">
<div id="comment-wrap-<?php echo $post['id']; ?>">
<?php
$_GET['blogid'] = $post['id'];
include("ajax_processing/get_blog_comments.php"); ?>
</div>
<?php if(check_permission("Blog","post_comment")){?>
<br />
<div>
<textarea id="blog-comment-<?php echo $post['id'];?>" maxlength="1000" rows="1" placeholder="Write a comment..." style="width:300px; height:30px; resize:none; border-bottom:1px solid; margin-right:5px; float:left;" /></textarea>
<a onclick="sendComment(<?php echo $post['id'];?>)" id="comment-sendbtn-<?php echo $post['id'];?>" class="btn-floating green" style="float:left; margin-top:8px; margin-bottom:8px;"><i class="material-icons">send</i></a>
</div>
<?php } ?>
</div>
</td>
</tr>
<?php } ?>
</table>
</td>
</tr>
<tr>
<td>
<!--
<div class="container">
<div class="row right">
<div class="col l12 s12">
<?php if(check_permission("Blog","edit_blog")||(isset($_SESSION['user_id'])&&$post['poster']==$_SESSION['user_id'])){?><a class="btn-floating blue blog-btn" href="edit_blog_post.php?post=<?php echo $post['id'] ?>"><i class="mdi-editor-mode-edit"></i></a><?php } ?>
<?php if(check_permission("Blog","delete_blog")||(isset($_SESSION['user_id'])&&$post['poster']==$_SESSION['user_id'])){?>
<a class="modal-trigger blog-btn btn-floating red btn-click-action" href="#modal1" name="<?php echo $post['id'] ?>"><i class="mdi-action-delete"></i></a><?php } ?>
</div>
</div>
</div>
-->
</td>
</tr>
</tr>
</table>
<?php } ?>
<div id="modal1" class="modal">
<div class="modal-content">
<h4>Are you sure you want to delete?</h4>
<p>Once you delete this post there will be no way to recover it</p>
</div>
<div class="modal-footer">
<div class="row right">
<div class="col l12 s12">
<a href="#!" class="modal-close waves-effect waves-blue btn blue ">Cancel</a>
<a href="blog.php?delpost=" id="del_button" class="modal-close waves-effect waves-red btn red ">Delete</a>
</div>
</div>
</div>
</div>
<?php
}else{
if(check_permission("Blog","post_blog")){?>
<br><a class="btn green" href="new_blog_post.php">New</a><br /><br />
<?php } ?>
<p>There are no blog posts!</p>
<?php }
?>
<div>
<div class="row">
<?php
if($num_pages>1){
echo_page($num_pages, $current_page, 'page/'.$page['name']);
}
?>
</div>
</div>
<?php
require_once("includes/end_html.php");
?>