$smarty->assign('count', count($posts)); // Calculate page count. $page_max = ceil(count($posts) / $posts_per_page); if ($page_max == 0) { $page_max = 1; } if ($page > $page_max) { // Cleanup. DataExchange::releaseResources(); display_error_page($smarty, new MaxPageError($page)); exit(1); } $pages = range(1, $page_max); // Select posts only from correspond page. $posts = array_slice($posts, ($page - 1) * $posts_per_page, $posts_per_page); $admins = users_get_admins(); // Create html code of founded posts. foreach ($posts as $p) { // Find if author of this post is admin. $author_admin = false; foreach ($admins as $admin) { if ($p['user'] == $admin['id']) { $author_admin = true; break; } } $posts_html .= post_search_generate_html($smarty, $p, $author_admin); } } // Generate html code of search page and display it. $smarty->assign('show_control', is_admin() || is_mod());
/** * Check if use is admin. * @param int $id User id. * @return boolean * TRUE if user is admin, FALSE otherwise. */ function users_is_admin($id) { static $admins = NULL; if ($admins === NULL) { $admins = users_get_admins(); } foreach ($admins as $admin) { if ($id == $admin['id']) { return TRUE; } } return FALSE; }