session_start();
require($_SERVER['DOCUMENT_ROOT']."/includes/config.php");
require($_SERVER['DOCUMENT_ROOT']."/includes/database.php");
require($_SERVER['DOCUMENT_ROOT']."/classes/Classes.php");
$all_entries = array();
// remove page number so it doesn't duplicate
$page_num_cleaner = preg_replace("/&page=[0-9]/", '', $_SERVER['QUERY_STRING']);
// how many rows to show per page
$rows_per_page = (int) 13;
// by default we show first page
$page_num = (int) 1;
// if $_GET['page'] defined, use it as page number
if (isset($_REQUEST['page']) && is_numeric($_REQUEST['page'])) {
$page_num = (int) strip_tags(trim($_GET['page']));
}
// counting the offset
$offset = (int)($page_num - 1) * $rows_per_page;
if (isset($_GET['cat_id']) && is_numeric($_GET['cat_id']))
{
$cat_id = strip_tags(trim($_GET['cat_id']));
// get all the latest entries
$query_entries = "SELECT DISTINCT e.entry_id, e.title, e.content, e.summary, e.featured_image, e.entry_date_time, u.user_id, u.fullname AS author FROM EntriesCategoriesLinker ecl, Entries e LEFT JOIN Users u ON u.user_id = e.user_id WHERE e.status = :status AND ecl.cat_id = :cat_id AND e.entry_id = ecl.entry_id AND e.entry_date_time <= :entry_date_time GROUP BY e.entry_id ORDER BY e.entry_date_time DESC LIMIT :offset, :rows_per_page";
$result_entries = $conn->prepare($query_entries);
$result_entries->bindValue(':status', 'published');
$result_entries->bindValue(':cat_id', $cat_id);
$result_entries->bindValue(':entry_date_time', CURRENT_TIME);
$result_entries->bindValue(':offset', $offset, PDO::PARAM_INT);
$result_entries->bindValue(':rows_per_page', $rows_per_page, PDO::PARAM_INT);
$result_entries->execute();
$num_entries = $result_entries->rowCount();
// get the total for paging purposes
$query_total = "SELECT DISTINCT e.entry_id FROM EntriesCategoriesLinker ecl, Entries e LEFT JOIN Users u ON u.user_id = e.user_id WHERE e.status = :status AND ecl.cat_id = :cat_id AND e.entry_id = ecl.entry_id AND e.entry_date_time <= :entry_date_time GROUP BY e.entry_id ORDER BY e.entry_date_time DESC";
$result_total = $conn->prepare($query_total);
$result_total->bindValue(':cat_id', $cat_id);
$result_total->bindValue(':entry_date_time', CURRENT_TIME);
$result_total->bindValue(':status', 'published');
$result_total->execute();
$num_total = $result_total->rowCount();
// get category name
$query_category_name = "SELECT DISTINCT ec.cat_name FROM EntriesCategories ec WHERE ec.cat_id = :cat_id LIMIT 1";
$result_category_name = $conn->prepare($query_category_name);
$result_category_name->execute(array(':cat_id'=>$cat_id));
$rows_category_name = $result_category_name->fetch();
$this_sub = $rows_category_name['cat_name'];
}
elseif (isset($_GET['author_id']) && is_numeric($_GET['author_id']))
{
$user_id = strip_tags(trim($_GET['author_id']));
$query_entries = "SELECT e.entry_id, e.title, e.content, e.summary, e.featured_image, e.entry_date_time, u.user_id, u.fullname AS author FROM Entries e LEFT JOIN Users u ON u.user_id = e.user_id WHERE e.status = :status AND u.user_id = :user_id AND e.entry_date_time <= :entry_date_time GROUP BY e.entry_id ORDER BY e.entry_date_time DESC LIMIT :offset, :rows_per_page";
$result_entries = $conn->prepare($query_entries);
$result_entries->bindValue(':status', 'published');
$result_entries->bindValue(':user_id', $user_id);
$result_entries->bindValue(':entry_date_time', CURRENT_TIME);
$result_entries->bindValue(':offset', $offset, PDO::PARAM_INT);
$result_entries->bindValue(':rows_per_page', $rows_per_page, PDO::PARAM_INT);
$result_entries->execute();
$num_entries = $result_entries->rowCount();
// get author name
$query_author_name = "SELECT u.fullname FROM Users u WHERE u.user_id = :user_id AND u.author = 'Y' LIMIT 1";
$result_author_name = $conn->prepare($query_author_name);
$result_author_name->execute(array(':user_id'=>$user_id,
':author'=>CURRENT_TIME
));
$rows_author_name = $result_author_name->fetch();
$this_sub = $rows_author_name['fullname']." Entries";
// get the total for paging purposes
$query_total = "SELECT e.entry_id, e.title, e.content, e.summary, e.featured_image, e.entry_date_time, u.user_id, u.fullname AS author FROM Entries e LEFT JOIN Users u ON u.user_id = e.user_id WHERE e.status = :status AND u.user_id = :user_id AND e.entry_date_time <= :entry_date_time GROUP BY e.entry_id ORDER BY e.entry_date_time DESC";
$result_total = $conn->prepare($query_total);
$result_total->bindValue(':user_id', $user_id);
$result_total->bindValue(':entry_date_time', CURRENT_TIME);
$result_total->bindValue(':status', 'published');
$result_total->execute();
$num_total = $result_total->rowCount();
}
elseif (isset($_GET['date']))
{
$date = strip_tags(trim($_GET['date']));
$date_array = explode("-", $date);
$date_to_display = date('F Y',mktime(0,0,0,$date_array[1],1,$date_array[0]));
$this_sub = $date_to_display." Entries";
$query_entries = "SELECT e.entry_id, e.title, e.content, e.summary, e.featured_image, e.entry_date_time, u.user_id, u.fullname AS author FROM Entries e LEFT JOIN Users u ON u.user_id = e.user_id WHERE e.status = :status AND YEAR(e.entry_date_time) = :selected_year AND MONTH(e.entry_date_time) = :selected_month GROUP BY e.entry_id ORDER BY e.entry_date_time DESC LIMIT :offset, :rows_per_page";
$result_entries = $conn->prepare($query_entries);
$result_entries->bindValue(':status', 'published');
$result_entries->bindValue(':selected_year', $date_array[0]);
$result_entries->bindValue(':selected_month', $date_array[1]);
$result_entries->bindValue(':offset', $offset, PDO::PARAM_INT);
$result_entries->bindValue(':rows_per_page', $rows_per_page, PDO::PARAM_INT);
$result_entries->execute();
$num_entries = $result_entries->rowCount();
// get the total for paging purposes
$query_total = "SELECT e.entry_id FROM Entries e LEFT JOIN Users u ON u.user_id = e.user_id WHERE e.status = :status AND YEAR(e.entry_date_time) = :selected_year AND YEAR(e.entry_date_time) = :selected_month GROUP BY e.entry_id ORDER BY e.entry_date_time DESC";
$result_total = $conn->prepare($query_total);
$result_total->bindValue(':selected_year', $date_array[0]);
$result_total->bindValue(':selected_month', $date_array[1]);
$result_total->bindValue(':status', 'published');
$result_total->execute();
$num_total = $result_total->rowCount();
}
elseif (isset($_GET['tag']))
{
$tag = strip_tags(trim($_GET['tag']));
$query_entries = "SELECT DISTINCT e.entry_id, e.title, e.content, e.summary, e.featured_image, e.entry_date_time, u.user_id, u.fullname AS author FROM Entries e LEFT JOIN Users u ON u.user_id = e.user_id WHERE e.entry_id IN (SELECT tl.id FROM TagsLinker tl, Tags t WHERE t.tag = :tag AND tl.type = :type AND tl.tag_id = t.tag_id) AND e.status = :status AND e.entry_date_time <= :entry_date_time GROUP BY e.entry_id ORDER BY e.entry_date_time DESC LIMIT :offset, :rows_per_page";
$result_entries = $conn->prepare($query_entries);
$result_entries->bindValue(':tag', $tag);
$result_entries->bindValue(':type', 'blog');
$result_entries->bindValue(':status', 'published');
$result_entries->bindValue(':entry_date_time', CURRENT_TIME);
$result_entries->bindValue(':offset', $offset, PDO::PARAM_INT);
$result_entries->bindValue(':rows_per_page', $rows_per_page, PDO::PARAM_INT);
$result_entries->execute();
$num_entries = $result_entries->rowCount();
// get the total for paging purposes
$query_total = "SELECT e.entry_id FROM Entries e LEFT JOIN Users u ON u.user_id = e.user_id WHERE e.entry_id IN (SELECT tl.id FROM TagsLinker tl, Tags t WHERE t.tag = :tag AND tl.type = :type AND tl.tag_id = t.tag_id) AND e.status = 'published' AND e.entry_date_time <= :entry_date_time GROUP BY e.entry_id ORDER BY e.entry_date_time DESC";
$result_total = $conn->prepare($query_total);
$result_total->bindValue(':tag', $tag);
$result_total->bindValue(':type', 'blog');
$result_total->bindValue(':status', 'published');
$result_total->bindValue(':entry_date_time', CURRENT_TIME);
$result_total->execute();
$num_total = $result_total->rowCount();
}
else
{
$query_entries = "SELECT e.entry_id, e.title, e.content, e.summary, e.featured_image, e.entry_date_time, u.user_id, u.fullname AS author FROM Entries e LEFT JOIN Users u ON u.user_id = e.user_id WHERE e.status = :status AND e.entry_date_time <= :entry_date_time GROUP BY e.entry_id ORDER BY e.entry_date_time DESC LIMIT :offset, :rows_per_page";
$result_entries = $conn->prepare($query_entries);
$result_entries->bindValue(':entry_date_time', CURRENT_TIME);
$result_entries->bindValue(':status', 'published');
$result_entries->bindValue(':offset', $offset, PDO::PARAM_INT);
$result_entries->bindValue(':rows_per_page', $rows_per_page, PDO::PARAM_INT);
$result_entries->execute();
$num_entries = $result_entries->rowCount();
// get the total for paging purposes
$query_total = "SELECT e.entry_id FROM Entries e LEFT JOIN Users u ON u.user_id = e.user_id WHERE e.status = :status AND e.entry_date_time <= :entry_date_time ORDER BY e.entry_date_time DESC";
$result_total = $conn->prepare($query_total);
$result_total->bindValue(':entry_date_time', CURRENT_TIME);
$result_total->bindValue(':status', 'published');
$result_total->execute();
$num_total = $result_total->rowCount();
}
$all_entries = array();
while ($rows_entries = $result_entries->fetch())
{
array_push($all_entries, $rows_entries);
}
if (count($all_entries) > 0)
{
// grab tags for entry
$values = array();
foreach($all_entries as $entries_key => $this_entries)
{
$values[] = $this_entries['entry_id'];
}
$query_search = implode(",",$values);
$query_entries_tags = "SELECT t.tag_id, t.tag, tl.id FROM Tags t, TagsLinker tl WHERE FIND_IN_SET(tl.id, :query_search) AND tl.tag_id = t.tag_id AND tl.type = :type ORDER BY tl.id ASC";
$result_entries_tags = $conn->prepare($query_entries_tags);
$result_entries_tags->execute(array(':query_search'=>$query_search,
':type'=>'blog'));
$num_entries_tags = $result_entries_tags->rowCount();
$all_entries_tags = array();
while ($rows_entries_tags = $result_entries_tags->fetch())
{
array_push($all_entries_tags, $rows_entries_tags);
}
$query_entries_categories = "SELECT ec.cat_id, ec.cat_name, ecl.entry_id FROM EntriesCategories ec, EntriesCategoriesLinker ecl WHERE FIND_IN_SET(ecl.entry_id, :query_search) AND ecl.cat_id = ec.cat_id ORDER BY ecl.entry_id ASC";
$result_entries_categories = $conn->prepare($query_entries_categories);
$result_entries_categories->execute(array(':query_search'=>$query_search));
$num_entries_categories = $result_entries_categories->rowCount();
$all_entries_categories = array();
while ($rows_entries_categories = $result_entries_categories->fetch())
{
array_push($all_entries_categories, $rows_entries_categories);
}
$query_comments_count = "SELECT COUNT(*) AS total, c.id FROM Comments c WHERE FIND_IN_SET(c.id, :query_search) AND c.status = :status GROUP BY (c.id) ORDER BY c.id ASC";
$result_comments_count = $conn->prepare($query_comments_count);
$result_comments_count->execute(array(':query_search'=>$query_search,
':status'=>'approved'));
$num_comments_count = $result_comments_count->rowCount();
$all_comments_count = array();
while ($rows_comments_count = $result_comments_count->fetch())
{
array_push($all_comments_count, $rows_comments_count);
}
}
// continue paging navigation
// total number of pages
$max_page = ceil($num_total/$rows_per_page);
// print the link to access each page
$self = $_SERVER['PHP_SELF']."?".$page_num_cleaner."&";
$nav = '';
if ($max_page > 1) {
for($page = 1; $page <= $max_page; $page++) {
if ($page == $page_num) {
$current_page_class = "current";
}
$nav .= " ".$page."";
//echo 'page is equal to '.$page.' ';
//echo 'page num is equal to '.$page_num.' ';
unset($current_page_class);
}
// creating previous and next link plus the link to go straight to the first and last page
if ($page_num > 1) {
$page = $page_num - 1;
$prev = "« Previous";
$first = " « First Page ";
} else {
$prev = ' '; // we're on page one, don't print previous link
$first = ''; // nor the first page link
}
if ($page_num < $max_page) {
$page = $page_num + 1;
$next = "Next »";
$last = " Last Page »";
} else {
$next = ' '; // we're on the last page, don't print next link
$last = ''; // nor the last page link
}
}
$this_section = "";
$this_sub = "";
$this_page = "";
$canonical = SITE_URL;
$page_title = pageTitles("Contact - Doodlers Anonymous");
$meta_description = metaDescriptions("Contact Doodlers Anonymous");
?>
I can't get involved! I've got work to do! It's not that I like the Empire, I hate it, but there's nothing I can do about it right now. It's such a long way from here. Hokey religions and ancient weapons are no match for a good blaster at your side, kid. I'm surprised you had the courage to take the responsibility yourself.