12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?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));
|