forked from mikhnyuk/Story
-
Notifications
You must be signed in to change notification settings - Fork 0
/
process.php
43 lines (36 loc) · 1.55 KB
/
process.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
<?php
include_once("config.php");
include_once("utility.php");
// SQL Connect
$sql = mysqli_connect($config["MySQL_host"],$config["MySQL_user"],$config["MySQL_pass"],$config["MySQL_db"]);
if ($config["Debug"] && mysqli_connect_errno()){
exit("Failed to connect to MySQL");
}
if (!empty($_POST)) {
// Insert into database
$stmt = $sql->prepare("INSERT INTO stories (title, url_title, author, content, date, hits) VALUES (?, ?, ?, ?, ?, ?)");
$title = dataFilter($_POST["title"], $sql);
$title = !empty($title) ? $title : "Untitled";
// Generate SEO URL with transliteration
$ut_recipe = transliterate($title);
$ut_recipe = strlen($ut_recipe) > 30 ? substr($ut_recipe, 0, 30) . "-" . date("m-d") : $ut_recipe . "-" . date("m-d");
$ut_result = $sql->query("SELECT url_title FROM stories WHERE url_title='$ut_recipe'");
if ($ut_result->num_rows > 0) {
$url_title = strlen($ut_recipe) > 30 ? substr($ut_recipe, 0, 30) . "-" . date("m-d") . $ut_result->num_rows : $ut_recipe . "-" . date("m-d") . "-" . $ut_result->num_rows;
} else {
$url_title = $ut_recipe;
}
$author = dataFilter($_POST["author"], $sql);
$author = !empty($author) ? $author : "Anonymous";
$content = $_POST["content"];
$date = date("Y-m-d H:i:s");
$hits = 0;
$stmt->bind_param("sssssi", $title, $url_title, $author, $content, $date, $hits);
if ($stmt->execute()) {
exit($url_title);
}
$stmt->close();
} else {
exit("new");
}
mysqli_close($sql);