| | 45 | // SELECT count(*) as posts, count(distinct topic_id) as topics, count(distinct poster_id) as members FROM `bb_posts` WHERE post_status=0 |
|---|
| | 46 | // SELECT count(*) as posts, count(distinct t1.topic_id) as topics, count(distinct poster_id) as members FROM `bb_posts` as t1 LEFT JOIN `bb_topics` as t2 ON t1.topic_id=t2.topic_id WHERE post_status=0 AND topic_status=0 |
|---|
| | 47 | |
|---|
| | 48 | $results=$bbdb->get_results("SELECT COUNT(*) as forums, SUM(posts) as posts, SUM(topics) as topics FROM $bbdb->forums"); |
|---|
| | 49 | $my_views_statistics["total_forums"]=$results[0]->forums; |
|---|
| | 50 | $my_views_statistics["total_posts"]=$results[0]->posts; |
|---|
| | 51 | $my_views_statistics["total_topics"]=$results[0]->topics; |
|---|
| | 52 | |
|---|
| 46 | | $my_views_statistics["total_posts"]=$bbdb->get_var("SELECT SUM(posts) FROM $bbdb->forums"); |
|---|
| 47 | | $my_views_statistics["total_topics"]=$bbdb->get_var("SELECT SUM(topics) FROM $bbdb->forums"); |
|---|
| | 54 | $my_views_statistics["total_days_old"]=round((time()-strtotime($bbdb->get_var("SELECT topic_start_time FROM $bbdb->topics ORDER BY topic_start_time LIMIT 1"))) / (3600 * 24),2); |
|---|
| | 55 | |
|---|
| | 56 | if (bb_get_option('bb_db_version')>1600) { // bbPress 1.0 vs 0.9 |
|---|
| | 57 | $my_views_statistics["total_topic_views"]= $bbdb->get_var("SELECT SUM(meta_value) FROM $bbdb->meta LEFT JOIN $bbdb->topics ON $bbdb->meta.object_id = $bbdb->topics.topic_id WHERE $bbdb->topics.topic_status=0 AND $bbdb->meta.meta_key='views' AND $bbdb->meta.object_type='bb_topic' "); |
|---|
| | 58 | $my_views_statistics["total_tags"]=$bbdb->get_var("SELECT COUNT(*) FROM $bbdb->terms"); |
|---|
| | 59 | } else { // 0.9 |
|---|
| 63 | | $my_views_statistics["top_posters"] = $bbdb->get_results("SELECT poster_id, COUNT(poster_id) AS post_count FROM $bbdb->posts WHERE post_status != 1 GROUP BY poster_id ORDER BY post_count DESC LIMIT $userlimit"); |
|---|
| 64 | | $my_views_statistics["top_topic_starters"]=$bbdb->get_results("SELECT topic_poster, topic_poster_name, COUNT(topic_id) AS post_count FROM $bbdb->topics WHERE topic_status=0 GROUP BY topic_poster_name ORDER BY post_count DESC LIMIT $userlimit"); |
|---|
| | 72 | $my_views_statistics["top_posters"] = $bbdb->get_results("SELECT DISTINCT poster_id, COUNT(poster_id) AS post_count FROM $bbdb->posts WHERE post_status != 1 GROUP BY poster_id ORDER BY post_count DESC LIMIT $userlimit"); |
|---|
| | 73 | $my_views_statistics["top_topic_starters"]=$bbdb->get_results("SELECT DISTINCT topic_poster, topic_poster_name, COUNT(topic_id) AS post_count FROM $bbdb->topics WHERE topic_status=0 GROUP BY topic_poster_name ORDER BY post_count DESC LIMIT $userlimit"); |
|---|
| 234 | | function stats_most_views( $view ) { |
|---|
| 235 | | global $bbdb, $topics, $view_count; |
|---|
| 236 | | if ($view=='most-views') {$sort="DESC";} |
|---|
| 237 | | if ($view=='least-views') {$sort="ASC";} |
|---|
| 238 | | if ($view=='least-views' || $view=='most-views') { |
|---|
| 239 | | $limit = bb_get_option('page_topics'); |
|---|
| 240 | | $most_views = $bbdb->get_results("SELECT topic_id FROM $bbdb->topicmeta WHERE meta_key='views' ORDER BY cast(meta_value as UNSIGNED) $sort LIMIT $limit"); |
|---|
| 241 | | foreach (array_keys($most_views) as $i) {$trans[$most_views[$i]->topic_id] =& $most_views[$i];} $ids = join(',', array_keys($trans)); |
|---|
| 242 | | $where = apply_filters('get_latest_topics_where',"WHERE topic_status=0 AND topic_id IN ($ids) "); |
|---|
| 243 | | $topics ="SELECT * FROM $bbdb->topics $where ORDER BY FIELD(topic_id, $ids)"; |
|---|
| 244 | | $topics = $bbdb->get_results($topics); |
|---|
| 245 | | $view_count = count($topics); |
|---|
| 246 | | $topics = bb_append_meta( $topics, 'topic' ); |
|---|
| 247 | | } |
|---|
| 248 | | // else {do_action( 'bb_custom_view', $view );} |
|---|
| 249 | | } |
|---|
| 250 | | |
|---|
| 251 | | function stats_forums_views_append($forums) { |
|---|
| 252 | | if (is_front() || is_forum()) { |
|---|
| 253 | | global $bbdb, $forums_views; $sum_meta_value="SUM(meta_value)"; |
|---|
| 254 | | if (!isset($forums_views)) { |
|---|
| 255 | | $forums_views = $bbdb->get_results(" SELECT $sum_meta_value,forum_id FROM $bbdb->topicmeta LEFT JOIN $bbdb->topics ON $bbdb->topicmeta.topic_id = $bbdb->topics.topic_id WHERE $bbdb->topics.topic_status=0 AND $bbdb->topicmeta.meta_key='views' GROUP BY $bbdb->topics.forum_id"); |
|---|
| 256 | | } foreach ($forums_views as $forum_views) { |
|---|
| 257 | | // echo " <!-- ".$forum_views->forum_id." - ".$sum_meta_value." -->"; |
|---|
| 258 | | if ($forum_views->forum_id) {$forums[$forum_views->forum_id]->views=$forum_views->$sum_meta_value;} |
|---|
| 259 | | } |
|---|
| 260 | | } |
|---|
| 261 | | return $forums; |
|---|
| 262 | | } |
|---|
| 263 | | |
|---|