-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost.php
83 lines (70 loc) · 1.78 KB
/
post.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
*
* This is a small demonstration of how you can use Acorn without a controller, view, and router.
* You could even skip the views and models, but then what are you left with?
* If you're going to leave out all that, stick with regular PHP (i.e. without Acorn).
*
* Why would you use Acorn this way? It reduces file clutter and is also faster (performance-wise).
* There also might be a script where you want to use all the power of Acorn without
* all the extras (i.e. controllers, router, etc.), this is how you'd do that!
*
*/
?>
<html>
<head>
<title>Acorn - Demo</title>
</head>
<body>
<?php if (empty($_GET['id'])) : ?>
<h1>Welcome to Acorn</h1>
<p>This is a demonstration of Acorn. You like?</p>
<?php endif;
ini_set('date.timezone', 'America/New_York');
/*
* Start up Acorn
*
*/
define('ROOT_DIR', '.');
require('acorn/acorn.php');
$time = microtime(true);
/*
* Get the post(s)
*
*/
Acorn::database(array('user' => 'root', 'password' => 'beer', 'host' => 'localhost', 'database' => 'blog', 'adapter' => 'mysql'));
Acorn::defineModel('Post');
if (empty($_GET['id']) === false)
{
$posts = Post::query("SELECT * FROM #table WHERE id = ? ORDER BY date DESC", $_GET['id']);
}
else
{
$posts = Post::query("SELECT * FROM #table ORDER BY date DESC");
}
/*
* Loop through the post(s) and diplay 'em
*
*/
foreach ($posts as $post)
{
$link = (isset($_GET['id']) && $_GET['id'] == $post->id) ? $post->title : "<a href='?id={$post->id}'>{$post->title}</a>";
$date = date('l, \t\h\e jS \of F, Y', strtotime($post->date));
echo <<<EOT
<h2>{$link}</h2>
<p>
<small>Written on {$date}</small>
<br/>
{$post->body}
</p>
<hr/>
EOT;
}
if (isset($_GET['id']))
{
echo "<a href='post.php'>Go back to full listing</a>";
}
echo '<pre>'.(microtime(true) - $time).'</pre>';
?>
</body>
</html>