[ Index ] |
PHP Cross Reference of MyBB |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * MyBB 1.6 4 * Copyright 2010 MyBB Group, All Rights Reserved 5 * 6 * Website: http://mybb.com 7 * License: http://mybb.com/about/license 8 * 9 * $Id: stats.php 5297 2010-12-28 22:01:14Z Tomm $ 10 */ 11 12 define("IN_MYBB", 1); 13 define('THIS_SCRIPT', 'stats.php'); 14 15 $templatelist = "stats,stats_thread"; 16 require_once "./global.php"; 17 require_once MYBB_ROOT."inc/functions_post.php"; 18 require_once MYBB_ROOT."inc/class_parser.php"; 19 $parser = new postParser; 20 21 // Load global language phrases 22 $lang->load("stats"); 23 24 add_breadcrumb($lang->nav_stats); 25 26 $stats = $cache->read("stats"); 27 28 if($stats['numthreads'] < 1 || $stats['numusers'] < 1) 29 { 30 error($lang->not_enough_info_stats); 31 } 32 33 $plugins->run_hooks("stats_start"); 34 35 $repliesperthread = my_number_format(round((($stats['numposts'] - $stats['numthreads']) / $stats['numthreads']), 2)); 36 $postspermember = my_number_format(round(($stats['numposts'] / $stats['numusers']), 2)); 37 38 // Get number of days since board start (might need improvement) 39 $query = $db->simple_select("users", "regdate", "", array('order_by' => 'regdate', 'limit' => 1)); 40 $result = $db->fetch_array($query); 41 $days = (TIME_NOW - $result['regdate']) / 86400; 42 if($days < 1) 43 { 44 $days = 1; 45 } 46 // Get "per day" things 47 $postsperday = my_number_format(round(($stats['numposts'] / $days), 2)); 48 $threadsperday = my_number_format(round(($stats['numthreads'] / $days), 2)); 49 $membersperday = my_number_format(round(($stats['numusers'] / $days), 2)); 50 51 // Get forum permissions 52 $unviewableforums = get_unviewable_forums(true); 53 $fidnot = '1=1'; 54 $unviewableforumsarray = array(); 55 if($unviewableforums) 56 { 57 $fidnot = "fid NOT IN ($unviewableforums)"; 58 $unviewableforumsarray = explode(',', $unviewableforums); 59 } 60 61 // Most replied-to threads 62 $most_replied = $cache->read("most_replied_threads"); 63 64 if(!$most_replied) 65 { 66 $cache->update_most_replied_threads(); 67 $most_replied = $cache->read("most_replied_threads", true); 68 } 69 70 if(!empty($most_replied)) 71 { 72 foreach($most_replied as $key => $thread) 73 { 74 if(!in_array("'{$thread['fid']}'", $unviewableforumsarray)) 75 { 76 $thread['subject'] = htmlspecialchars_uni($parser->parse_badwords($thread['subject'])); 77 $numberbit = my_number_format($thread['replies']); 78 $numbertype = $lang->replies; 79 $thread['threadlink'] = get_thread_link($thread['tid']); 80 eval("\$mostreplies .= \"".$templates->get("stats_thread")."\";"); 81 } 82 } 83 } 84 85 // Most viewed threads 86 $most_viewed = $cache->read("most_viewed_threads"); 87 88 if(!$most_viewed) 89 { 90 $cache->update_most_viewed_threads(); 91 $most_viewed = $cache->read("most_viewed_threads", true); 92 } 93 94 if(!empty($most_viewed)) 95 { 96 foreach($most_viewed as $key => $thread) 97 { 98 if(!in_array("'{$thread['fid']}'", $unviewableforumsarray)) 99 { 100 $thread['subject'] = htmlspecialchars_uni($parser->parse_badwords($thread['subject'])); 101 $numberbit = my_number_format($thread['views']); 102 $numbertype = $lang->views; 103 $thread['threadlink'] = get_thread_link($thread['tid']); 104 eval("\$mostviews .= \"".$templates->get("stats_thread")."\";"); 105 } 106 } 107 } 108 109 // Top forum 110 if(!empty($fidnot)) 111 { 112 $fidnot .= " AND"; 113 } 114 $query = $db->simple_select("forums", "fid, name, threads, posts", "$fidnot type='f'", array('order_by' => 'posts', 'order_dir' => 'DESC', 'limit' => 1)); 115 $forum = $db->fetch_array($query); 116 if(!$forum['posts']) 117 { 118 $topforum = $lang->none; 119 $topforumposts = $lang->no; 120 $topforumthreads = $lang->no; 121 } 122 else 123 { 124 $topforum = "<a href=\"".get_forum_link($forum['fid'])."\">{$forum['name']}</a>"; 125 $topforumposts = $forum['posts']; 126 $topforumthreads = $forum['threads']; 127 } 128 129 // Today's top poster 130 $timesearch = TIME_NOW - 86400; 131 switch($db->type) 132 { 133 case "pgsql": 134 $query = $db->query(" 135 SELECT u.uid, u.username, COUNT(*) AS poststoday 136 FROM ".TABLE_PREFIX."posts p 137 LEFT JOIN ".TABLE_PREFIX."users u ON (p.uid=u.uid) 138 WHERE p.dateline > $timesearch 139 GROUP BY ".$db->build_fields_string("users", "u.")." ORDER BY poststoday DESC 140 LIMIT 1 141 "); 142 break; 143 default: 144 $query = $db->query(" 145 SELECT u.uid, u.username, COUNT(*) AS poststoday 146 FROM ".TABLE_PREFIX."posts p 147 LEFT JOIN ".TABLE_PREFIX."users u ON (p.uid=u.uid) 148 WHERE p.dateline > $timesearch 149 GROUP BY p.uid ORDER BY poststoday DESC 150 LIMIT 1 151 "); 152 } 153 $user = $db->fetch_array($query); 154 if(!$user['poststoday']) 155 { 156 $topposter = $lang->nobody; 157 $topposterposts = $lang->no_posts; 158 } 159 else 160 { 161 if(!$user['uid']) 162 { 163 $topposter = $lang->guest; 164 } 165 else 166 { 167 $topposter = build_profile_link($user['username'], $user['uid']); 168 } 169 $topposterposts = $user['poststoday']; 170 } 171 172 // What percent of members have posted? 173 $query = $db->simple_select("users", "COUNT(*) AS count", "postnum > 0"); 174 $posters = $db->fetch_field($query, "count"); 175 $havepostedpercent = my_number_format(round((($posters / $stats['numusers']) * 100), 2)) . "%"; 176 177 $lang->todays_top_poster = $lang->sprintf($lang->todays_top_poster, $topposter, my_number_format($topposterposts)); 178 $lang->popular_forum = $lang->sprintf($lang->popular_forum, $topforum, my_number_format($topforumposts), my_number_format($topforumthreads)); 179 180 $stats['numposts'] = my_number_format($stats['numposts']); 181 $stats['numthreads'] = my_number_format($stats['numthreads']); 182 $stats['numusers'] = my_number_format($stats['numusers']); 183 $stats['newest_user'] = build_profile_link($stats['lastusername'], $stats['lastuid']); 184 185 $plugins->run_hooks("stats_end"); 186 187 eval("\$stats = \"".$templates->get("stats")."\";"); 188 output_page($stats); 189 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Oct 8 19:19:50 2013 | Cross-referenced by PHPXref 0.7.1 |