} } return 'aprox. ' . $human_diff; } foreach (array_keys($comments) as $c_key) { $comments[$c_key]['human_time_diff'] = human_time_diff($comments[$c_key]['date_added']); } $item['comments']['items'] = $comments; # Get site info (TODO: join on site table when fetching the item). # $site_query = "SELECT name, sane_name FROM sites WHERE id = {$item['site_id']}"; $site = $db->fetchRowQueryAssoc($site_query); # Feed Smarty template engine with needed data # $smarty->assign('tpl_content', 'content-item.tpl.html'); $smarty->assign('page_style', 'style-item.css'); $smarty->assign('page_title', $item['title']); $smarty->assign('page_description', "buzziest pic on the net - {$item['title']}"); $smarty->assign_by_ref('item', $item); $smarty->assign_by_ref('site', $site); # Generate the page! # if ($add_comment || $comment_error) { # if we added a comment or there was an error, clear the cache $smarty->clear_cache('index.tpl.html', $unique_page_name); } if (!$comment_error) { $smarty->caching = 2; $smarty->cache_lifetime = CACHE_TIME; } $smarty->display('index.tpl.html', $unique_page_name);
# foreach ($ESCAPE_FIELDS as $type => $escapees) { # foreach ($escapees as $escapee) { # if ($type == "html") { # $sites[$site_id]['_escaped'][$escapee] = # htmlentities($sites[$site_id]['items'][$item_idx][$escapee], ENT_QUOTES, 'UTF-8'); # } # else if ($type == "url") { # $sites[$site_id]['_escaped'][$escapee] = # urlencode($sites[$site_id]['items'][$item_idx][$escapee]); # } # else { /* TODO: ERROR, NO SUCH TYPE */ } # } # } #} } # Feed Smarty template engine with needed data # $smarty->assign('tpl_content', 'content-index.tpl.html'); $smarty->assign('page_style', 'style-index.css'); $smarty->assign_by_ref('sites', $sites); # Generate the page! # $smarty->caching = 2; $smarty->cache_lifetime = CACHE_TIME; $smarty->display('index.tpl.html', $unique_page_name); # If there was a welcome message right after registration, # remove it so it got displayed just once. # if (isset($_SESSION['welcome'])) { unset($_SESSION['welcome']); }
array_push($item_ids, $items[$item_idx]['id']); # Initially set comment count to 0, and in the next piece of code # set the correct comment count by querying database. # $site['items'][$item_idx]['comments']['count'] = 0; } $comment_count_query = "SELECT item_id, COUNT(*) as count FROM comments WHERE item_id IN " . "(" . join(',', $item_ids) . ") GROUP by item_id"; $comment_count = $db->fetchAllQueryAssoc($comment_count_query); if ($db->isError()) { $smarty->assign('tpl_content', 'content-error.tpl.html'); $smarty->assign('error', 'Database error has occured: ' . $db->getError()); $smarty->display('index.tpl.html'); exit; } foreach ($comment_count as $c_idx => $cc) { $site['items'][$cc['item_id']]['comments']['count'] = $cc['count']; } # Feed Smarty template engine with needed data # $smarty->assign('tpl_content', 'content-site.tpl.html'); $smarty->assign('page_style', 'style-page.css'); $smarty->assign('page_title', "buzziest pics from {$site['name']}!"); $smarty->assign('page_description', "these are the buzziest pictures on the net from {$site['name']}!"); $smarty->assign('current_page', $current_page); $smarty->assign('total_pages', $total_pages); $smarty->assign_by_ref('site', $site); # Generate the page! # $smarty->caching = 2; $smarty->cache_lifetime = CACHE_TIME; $smarty->display('index.tpl.html', $unique_page_name);
$comment_query = <<<EOL SELECT c.comment comment, c.date_added date_added, u.username username, i.title item_title, i.sane_title item_sane_title, i.url item_url FROM comments c LEFT JOIN items i ON c.item_id = i.id LEFT JOIN users u ON c.user_id = u.id WHERE user_id = {$_SESSION['user_id']} ORDER BY c.date_added DESC LIMIT {$comment_offset}, {$COMMENTS_PER_MY_COMMENTS} EOL; $comments = $db->fetchAllQueryAssoc($comment_query); if ($db->isError()) { $smarty->assign('tpl_content', 'content-error.tpl.html'); $smarty->assign('error', 'Database error has occured: ' . $db->getError()); $smarty->display('index.tpl.html'); exit; } foreach (array_keys($comments) as $c_key) { $comments[$c_key]['human_time_diff'] = human_time_diff($comments[$c_key]['date_added']); } $smarty->assign_by_ref('comments', $comments); $smarty->assign('current_page', $current_page); $smarty->assign('total_pages', $total_pages); $smarty->display('index.tpl.html');