forked from andyblarblar/assignment6cis435
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_static.php
More file actions
42 lines (36 loc) · 921 Bytes
/
create_static.php
File metadata and controls
42 lines (36 loc) · 921 Bytes
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
<?php
include('db.php');
include('function.php');
$title = $_GET["title"];
$id = $_GET["id"];
$statement = $connection->prepare(
"SELECT * FROM articles WHERE id=:id"
);
$statement->execute(array(
":id" => $id
));
// Grab article info
$article = $statement->fetchObject("ArticleDTO");
$swap_var = array(
"{NAME}" => $article->author_name,
"{TEXT}" => $article->article_text
);
if (file_exists("template.php")) {
$html = file_get_contents("template.php");
} else {
die ("Unable to locate template file");
}
foreach (array_keys($swap_var) as $key) {
if (strlen($key) > 2 && trim($swap_var[$key]) != '')
$html = str_replace($key, $swap_var[$key], $html);
}
if(!is_dir("static")) {
$old = umask(0);
mkdir("static", 0777);
umask($old);
}
if (!file_exists("static" . $title)) {
file_put_contents("static/" . $title . ".html", $html);
}
header("location: index.php");
?>