1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- require_once 'session.php';
- require_once 'database.php';
- require_once 'date.php';
- require_once 'twig.php';
- // Open database connection
- $db = new Database ();
- $db->connect ();
- // Pagination. What page are we in?
- if (isset ($_GET['page']))
- {
- $page = intval ($_GET['page']);
-
- if ($page < 0)
- $page = 0;
- } else {
- $page = 0;
- }
- // Retrieve list of posts
- if (isset ($_GET['new']))
- $posts = $db->get_new_posts ($page);
- else
- $posts = $db->get_hot_posts ($page);
- // Retrieve a list of user votes for the posts
- $IDs = array ();
- foreach ($posts as $post)
- $IDs[] = $post['id'];
- $votes = $db->get_posts_votes (implode (',', $IDs), Session::get_userid ());
- // Render template
- echo $twig->render (
- 'index.twig',
- array(
- 'posts' => $posts,
- 'votes' => $votes,
- 'page' => $page));
|