<?php require_once 'config/config.php'; require_once DIR_DATABASE . 'mysqli-db-obj.php'; $db = new Database(); if (isset($_SESSION['username'])) { $logged = true; $username = $_SESSION['username']; } else { $logged = false; } // Form the dates sidebar $date_stmt = "SELECT DISTINCT DATE_FORMAT(Time, '%M %Y') AS Date,\nDATE_FORMAT(Time, '%M') AS Month,\nDATE_FORMAT(Time, '%Y') AS Year\nFROM _posts\nORDER BY Date DESC"; $date_result = $db->simple_fetch($date_stmt); $dates_sidebar = ""; foreach ($date_result as $key => $value) { $month = $value['Month']; $year = $value['Year']; $date = $value['Date']; $date_query = http_build_query(array('Month' => $month, 'Year' => $year)); $date_with_link = "<a href='?" . $date_query . "'>" . $date . "</a>"; $dates_sidebar .= "<li>{$date_with_link}</li>"; } // Form the site, according to whether one is logged or not if ($logged) { $desc = 'Welcome to Bloghub, ' . $username . '!'; } else { $desc = 'Welcome to Bloghub!'; } function site_header($navbar) {
} } $condition_stmt = substr($condition_stmt, 0, -4); // Remove the final AND $stmt .= $condition_stmt; } $stmt .= " ORDER BY Time DESC LIMIT 5"; $start = 0; if (isset($query_array['start'])) { $start = $query_array['start']; $stmt .= ' OFFSET ?'; $types .= 'i'; $array_of_binds[] = $start; } if ($types === '') { $result = $db->simple_fetch($stmt); } else { $result = $db->fetch($stmt, $types, $array_of_binds); } // Form the navbar accordingly if ($logged) { $navbar = "<a class='blog-nav-item active' href='index.php'>Home</a>"; $navbar .= "<a class='blog-nav-item' href='addpost.php'>Add Post</a>"; $navbar .= "<a class='blog-nav-item' href='logout.php'>Logout</a>"; } else { $navbar = "<a class='blog-nav-item active' href='index.php'>Home</a>"; $navbar .= "<a class='blog-nav-item' href='login.php'>Login</a>"; $navbar .= "<a class='blog-nav-item' href='register.php'>Register</a>"; } // Form the main contents $main = "";