forked from RmK9/Wanderblog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthor.php
54 lines (39 loc) · 1.43 KB
/
author.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
<?php
require_once 'functions.php';
try {
$loggedIn = loggedIn();
$oConn = loginToDB();
$author = $_GET["username"];
$user = [];
$adventures = [];
//Prepare statement, substitute keyword with the submitted query
$query = $oConn->prepare("SELECT Username, UserType, FirstName, LastName, Country, Twitter FROM User WHERE Username = '$author'");
$query->execute();
$user = $query->fetchAll(PDO::FETCH_ASSOC);
//Prevent querying DB about non existent author
if(!empty($user)) {
$user = $user[0];
//Prepare statement, substitute keyword with the submitted query
$query = $oConn->prepare("SELECT * FROM Adventures WHERE Username = '$author' ORDER BY DatePosted ASC");
$query->execute();
$adventures = $query->fetchAll(PDO::FETCH_ASSOC);
$adventuresJson = json_encode(utf8ize($adventures));
}
//Templating
require_once 'vendor/autoload.php';
$loader = new Twig_Loader_Filesystem('views');
$twig = new Twig_environment($loader);
$template = $twig->loadTemplate('author.twig');
//Return the template specified above with the following variables filled in
echo $template->render(array(
'user' => $user,
'adventures' => $adventures,
'adventuresJson' => $adventuresJson,
'loggedIn' => $loggedIn
));
} catch (PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
finally{
$oConn = null;
}