-
Notifications
You must be signed in to change notification settings - Fork 0
/
approve_blog.php
68 lines (59 loc) · 2.01 KB
/
approve_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
<?php
//debug info
//comment this block
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);
// trespasser
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
if(!(isset($_SESSION['create'])) || !(isset($_SESSION['approve'])) || !(isset($_SESSION['brand']))){
if(!(isset($_SESSION['shortcut'])) || !(isset($_SESSION['brand']))){
header("Location: 404.php");
die("wrong entry!");
}
}
$brand = ($_SESSION['brand'] == 1)? "grt" : "ultra";
$init = file_get_contents("static/blogs/$brand/log.json");
$log = json_decode($init, true);
if (in_array($_POST['id'], $log['pending'])) {
$old_id = $_POST['id'];
// add new post id
$id = end($log['posts']);
$id += 1;
array_push($log['posts'], $id);
// increase total post entries
$total = $log['total'];
$total += 1;
$log['total'] = $total;
// delete pending blog id
if(($key = array_search($old_id, $log['pending'])) !== false)
array_splice($log['pending'], $key, 1);
// decrease pending entries
$total = $log['pending_total'];
$total -= 1;
$log['pending_total'] = $total;
$blog = json_decode(file_get_contents("static/blogs/$brand/$old_id.json"), true);
$blog['bid'] = $id;
$old_name = $blog['image'];
$extension = explode('.', $blog['image']);
$blog['image'] = "$id.".end($extension);
// rename image
rename("img/blogs/$brand/$old_name", "img/blogs/$brand/".$blog['image']);
// rename blog
file_put_contents("static/blogs/$brand/$old_id.json", json_encode($blog), LOCK_EX);
rename("static/blogs/$brand/$old_id.json", "static/blogs/$brand/$id.json");
// update log
file_put_contents("static/blogs/$brand/log.json", json_encode($log), LOCK_EX);
// clearing shorcut
if(isset($_SESSION['shortcut'])){
unset($_SESSION['shortcut']);
unset($_SESSION['brand']);
}
die("ok");
}
else{
die("Blog ID not in list!");
}
?>