Changeset 1301

Show
Ignore:
Timestamp:
08/20/08 11:22:08 (3 months ago)
Author:
_ck_
Message:

statistics update to support bbPress 1.0

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • my-views/trunk/my-views-statistics.php

    r998 r1301  
    66Author: _ck_ 
    77Author URI: http://bbShowcase.org 
    8 Version: 0.1.1 
     8Version: 0.1.2 
    99*/  
    1010 
     
    4343$userlimit=10;  // top users 10,15,20 etc. 
    4444 
     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 
    4553$my_views_statistics["total_members"]=$bbdb->get_var("SELECT COUNT(*) FROM $bbdb->users"); 
    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 
     56if (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 
    4860$my_views_statistics["total_topic_views"]= $bbdb->get_var("SELECT SUM(meta_value) 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' "); 
    4961$my_views_statistics["total_tags"]=$bbdb->get_var("SELECT COUNT(*) FROM $bbdb->tags"); 
    50 $my_views_statistics["total_forums"]=$bbdb->get_var("SELECT COUNT(*) FROM $bbdb->forums"); 
    51 $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); 
     62
    5263 
    5364$my_views_statistics["average_registrations"]=$my_views_statistics["total_members"]/$my_views_statistics["total_days_old"]; 
     
    5667$my_views_statistics["average_topic_views"]=$my_views_statistics["total_topic_views"]/$my_views_statistics["total_days_old"]; 
    5768 
    58 $my_views_statistics["total_days_old"]=$my_views_statistics["total_days_old"]; 
    59  
    6069$my_views_statistics["oldest_members"] = $bbdb->get_results("SELECT ID,user_registered FROM $bbdb->users ORDER BY user_registered ASC LIMIT $userlimit"); 
    6170$my_views_statistics["newest_members"] = $bbdb->get_results("SELECT ID,user_registered FROM $bbdb->users ORDER BY user_registered DESC LIMIT $userlimit"); 
    6271 
    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"); 
    6574 
    6675$topics=$bbdb->get_results("SELECT * FROM $bbdb->topics WHERE topic_status=0 ORDER BY topic_posts DESC LIMIT $topiclimit");     // topic_id,topic_title,topic_posts 
    6776$my_views_statistics["top_topics_by_posts"] = bb_append_meta( $topics, 'topic' ); 
    6877         
     78if ($my_views_statistics["total_topic_views"]) { 
     79        if (bb_get_option('bb_db_version')>1600) { // bbPress 1.0 vs 0.9 
     80        $most_views = $bbdb->get_results("SELECT object_id as topic_id FROM $bbdb->meta WHERE meta_key='views' AND object_type='bb_topic' ORDER BY cast(meta_value as UNSIGNED) DESC LIMIT $topiclimit"); 
     81        } else { 
    6982        $most_views = $bbdb->get_results("SELECT topic_id FROM $bbdb->topicmeta WHERE meta_key='views' ORDER BY cast(meta_value as UNSIGNED) DESC LIMIT $topiclimit"); 
     83        } 
    7084        foreach (array_keys($most_views) as $i) {$trans[$most_views[$i]->topic_id] =& $most_views[$i];} $ids = join(',', array_keys($trans)); 
    7185        $where = apply_filters('get_latest_topics_where',"WHERE topic_status=0 AND topic_id IN ($ids) "); 
     
    7387        $topics = $bbdb->get_results($topics); 
    7488$my_views_statistics["top_topics_by_views"] = bb_append_meta( $topics, 'topic' ); 
    75  
     89} else {$my_views_statistics["top_topics_by_views"] = array();} 
    7690 
    7791?> 
     
    232246} 
    233247 
    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  
    264248// endif; 
    265249?>