-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathposts.php
61 lines (45 loc) · 1.36 KB
/
posts.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 readonly mode
db_connect();
// make sure we're logged in
include_once("Alibaba.class.php");
Alibaba::forceAuthentication();
# get all posts; comment summary is okay, and no need for tags
$query = "SELECT guid, title, pubDate, author, draft, seoName " .
"FROM posts " .
"ORDER BY pubDate DESC LIMIT 50";
# get result
$result=mysql_query($query) or die("Unable to retrieve selected post(s)");
$posts = array();
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
# reformat date
$dateStamp = strtotime( $row['pubDate'] );
$row['pubDate'] = strftime( "%m/%d/%y", $dateStamp );
array_push($posts, $row);
}
for ( $i = 0; $i < count($posts); $i++ ) {
# get tags
$postguid = $posts[$i]['guid'];
$query = "SELECT tag FROM tags WHERE post_guid='$postguid' ORDER BY tag";
# get result
$result=mysql_query($query) or die("Unable to retrieve post tags");
$tags = array();
while ($row = mysql_fetch_row($result)) {
array_push($tags, $row[0]);
}
$posts[$i]['tags'] = implode(", ", $tags);
}
db_close();
# init template engine
$h2o = new h2o('tmpl/panel-posts.html');
# data to hand to the template
$data = array(
'blog' => $blog,
'posts' => $posts
);
# render the page
echo $h2o->render(compact('data'));
?>