-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsavePage.php
61 lines (49 loc) · 1.58 KB
/
savePage.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
<?php
require 'bin/h2o/h2o.php';
// load db functions
include('model.php');
// connect to the DB in insert mode
db_connect(1);
// make sure we're logged in
include_once("Alibaba.class.php");
Alibaba::forceAuthentication();
// grab and sanitize posted params
/* ============================================================================
NOTE: this is WAY too simple, and likely still leaves us exposed to some varieties of malicious attack.
Better to use argument binding, via PDO or mysqli:
mysqli : http://uk.php.net/manual/en/mysqli.prepare.php
PDO : http://uk.php.net/manual/en/book.pdo.php
============================================================================ */
$name = mysql_real_escape_string($_POST["name"]);
$content = mysql_real_escape_string($_POST["content"]);
$pubDate = strtotime( $_POST["pubDate"] );
$standalone = $_POST["standalone"];
if (!$pubDate) {
$dateStr = date('Y-m-d H:i:s');
} else {
$dateStr = date('Y-m-d H:i:s', $pubDate);
}
if ($standalone) {
$sa = 1;
} else {
$sa = 0;
}
$err = savePage($name, $dateStr, $content, $sa);
db_close();
if (!$err) {
$data = array(
'blog' => $blog,
'status' => 'SUCCESS',
'message' => 'Your page has been published/saved.',
'body' => "<a href='/code/page/$name'>View page</a> | <a href='pages'>Back to control panel</a>"
);
} else {
$data = array(
'blog' => $blog,
'status' => 'FAILED',
'message' => 'Failed to save your page. Details: $err'
);
}
header('Content-type: application/json');
echo json_encode($data);
?>