get_var("select count(*) from $table_threads where forum_id = $forum");
}
function forum_get_forums($group){
global $wpdb, $table_forums;
return $wpdb->get_results("SELECT * FROM $table_forums WHERE parent_id = $group ORDER BY sort DESC");
}
function forum_get_sticky_threads($forum){
global $wpdb, $table_threads;
return $wpdb->get_results("SELECT * FROM $table_threads WHERE forum_id = $forum AND status = 'sticky'
ORDER BY date DESC");
}
function forum_get_all_forums(){
global $wpdb, $table_forums;
return $wpdb->get_results("SELECT * FROM $table_forums ORDER BY sort DESC");
}
function forum_get_threads($forum){
global $wpdb, $table_threads;
$tpp = get_option('forum_threads_per_page');
if(!isset($_GET['threadstart'])){
$start = 0;
}
else{
$start = $_GET['threadstart'];
}
$end = $start+$ppp;
return $wpdb->get_results("SELECT * FROM $table_threads WHERE forum_id = $forum AND status <> 'sticky' ORDER BY date DESC LIMIT $start, $tpp");
}
function forum_get_thread_subject($thread){
global $wpdb, $table_threads;
return $wpdb->get_var("SELECT subject FROM $table_threads WHERE id = $thread");
}
function forum_get_forum_from_post($thread){
global $wpdb, $table_threads;
return $wpdb->get_var("SELECT forum_id FROM $table_threads WHERE id = $thread");
}
function forum_set_thread_status($thread, $status){
global $wpdb, $table_threads;
$wpdb->query("UPDATE $table_threads SET status = '$status' WHERE id = $thread");
}
function forum_get_thread_status($thread){
global $wpdb, $table_threads;
return $wpdb->get_var("SELECT status FROM $table_threads WHERE id = $thread");
}
function forum_get_forumname_from_post($thread){
global $wpdb, $table_threads, $table_forums;
$f = $wpdb->get_var("SELECT forum_id FROM $table_threads WHERE id = $thread");
return $wpdb->get_var("SELECT name FROM $table_forums WHERE id = $f");
}
function forum_get_link_from_post($thread, $post = '', $start = 0){
global $wpdb, $table_threads, $table_forums, $forum_page_id;
$forum = $wpdb->get_var("SELECT forum_id FROM $table_threads WHERE id = $thread");
return get_bloginfo('wpurl')."/?page_id=$forum_page_id&forumaction=showposts&forum=$forum&thread=$thread&start=$start";
}
function forum_get_posts($thread, $start){
global $wpdb, $table_posts;
$ppp = get_option('forum_posts_per_page');
$end = $start+$ppp;
//echo "SELECT * FROM $table_posts WHERE thread_id = $thread ORDER BY date ASC limit $start, $ppp";
return $wpdb->get_results("SELECT * FROM $table_posts WHERE thread_id = $thread ORDER BY date ASC limit $start, $ppp");
}
function forum_get_single_post($post){
global $wpdb, $table_posts;
return $wpdb->get_row("SELECT * FROM $table_posts WHERE id = $post");
}
function forum_get_single_thread($thread){
global $wpdb, $table_threads;
return $wpdb->get_row("SELECT subject, status, id, forum_id FROM $table_threads WHERE id = $thread");
}
function forum_get_post_text($post){
global $wpdb, $table_posts;
return $wpdb->get_var("SELECT text FROM $table_posts WHERE id = $post");
}
function forum_get_groups(){
global $wpdb, $table_groups;
return $wpdb->get_results("select * from $table_groups ORDER BY sort DESC");
}
function forum_get_posts_in_forum_count($forum){
global $wpdb, $table_threads, $table_posts;
$threads = $wpdb->get_results("select id from $table_threads where forum_id = $forum");
if(!$threads) return 0;
foreach($threads as $thread)
$c += $wpdb->get_var("select count(*) from $table_posts where thread_id = $thread->id");
return $c;
}
function forum_get_posts_in_thread_count($thread){
global $wpdb, $table_posts;
return $wpdb->get_var("select count(*) from $table_posts where thread_id = $thread");
}
function forum_get_lastpost($thread, $f = true){
global $wpdb, $table_posts;
$date = $wpdb->get_var("select date from $table_posts where thread_id = $thread order by date desc limit 1");
if($f)
return date(get_option('forum_date_format'), strtotime($date));
else
return $date;
}
function forum_get_lastpost_id($thread){
global $wpdb, $table_posts;
$id = $wpdb->get_var("select id from $table_posts where thread_id = $thread order by date desc limit 1");
return $id;
}
function forum_get_lastpost_poster($thread){
global $wpdb, $table_posts, $profile;
$u = $wpdb->get_row("select author_id from $table_posts where thread_id = $thread order by date desc limit 1");
if(!$u->author_id)
return "Guest";
$user = new WP_user($u->author_id);
$r = "$user->nickname";
return $r;
}
function forum_get_lastpost_in_forum($forum_id){
global $wpdb, $table_posts, $profile, $table_threads;
$date = $wpdb->get_var("SELECT $table_posts.date FROM $table_posts INNER JOIN $table_threads ON $table_posts.thread_id=$table_threads.id WHERE $table_threads.forum_id = $forum_id ORDER BY $table_posts.date DESC");
return date(get_option('forum_date_format'), strtotime($date));
}
function forum_get_lastpost_poster_in_forum($forum_id){
global $wpdb, $table_posts, $profile, $table_threads;
$u = $wpdb->get_row("SELECT author_id FROM $table_posts INNER JOIN $table_threads ON $table_posts.thread_id=$table_threads.id WHERE $table_threads.forum_id = $forum_id ORDER BY $table_posts.date DESC");
if(!$u->author_id)
return $u->author_id;
$user = new WP_user($u->author_id);
$r = "$user->nickname";
return $r;
}
function forum_get_lastpost_poster_id($thread){
global $wpdb, $table_posts;
$u = $wpdb->get_var("select author_id from $table_posts where thread_id = $thread order by date desc limit 1");
return $u;
}
function forum_get_gravatar($email){
global $PLUGIN_PATH;
if(get_option('forum_use_gravatar') == 'true'){
$default = urlencode($PLUGIN_PATH."/$skin_dir/images/gravatar_default.png");
$md5sum = md5($email);
return "
";
}
}
function forum_get_group_name($group){
global $wpdb, $table_groups;
return $wpdb->get_var("SELECT name FROM $table_groups WHERE id = $group");
}
function forum_get_group_from_post($tread_id){
return forum_get_group_name(forum_get_parent(forum_get_forum_from_post($tread_id)));
}
function forum_get_parent($forum){
global $wpdb, $table_forums;
return $wpdb->get_var("SELECT parent_id FROM $table_forums WHERE id = $forum");
}
function forum_get_forum_name($forum){
global $wpdb, $table_forums;
return $wpdb->get_var("SELECT name FROM $table_forums WHERE id = $forum");
}
function forum_get_forum_desc($forum){
global $wpdb, $table_forums;
return $wpdb->get_var("SELECT description FROM $table_forums WHERE id = $forum");
}
function forum_get_trail($forum="", $thread=""){
global $forum_page_id, $PLUGIN_PATH, $skin_dir;
$blog_url = get_bloginfo('home');
$blog_name = get_bloginfo('name');
$page = get_option('forum_page_title');
$main_link_ = get_bloginfo('wpurl')."/?page_id=$forum_page_id";
$blog = "$blog_name";
$page = "$page";
$trail = "
";
return $out;
}
function forum_get_user_desc($user){
return get_usermeta($user, 'description');
}
function forum_get_posts_by_user($user_id, $limit){
global $wpdb, $table_posts, $forum_page_id, $user_ID, $PLUGIN_PATH, $search_link, $skin_dir;
$posts = $wpdb->get_results("SELECT * FROM $table_posts WHERE author_id = $user_id ORDER BY date DESC LIMIT $limit");
$o = "