/bp-forums/bbpress/bb-includes/functions.bb-statistics.php

  1. <?php 
  2. /** 
  3. * bbPress Forum Content Statistics Functions 
  4. * 
  5. * @package bbPress 
  6. */ 
  7.  
  8.  
  9.  
  10. /** 
  11. * Get the total number of forums 
  12. * 
  13. * @since 1.0 
  14. * @uses $bbdb Database Object 
  15. * @uses $bb_total_forums Cache of result generated by previous run 
  16. * 
  17. * @return int 
  18. */ 
  19. function get_total_forums() { 
  20. global $bbdb, $bb_total_forums; 
  21. if ( isset($bb_total_forums) ) 
  22. return $bb_total_forums; 
  23. $bb_total_forums = $bbdb->get_var("SELECT COUNT(*) FROM $bbdb->forums USE INDEX (PRIMARY)"); 
  24. return $bb_total_forums; 
  25.  
  26. /** 
  27. * Output the number of forums 
  28. * 
  29. * @since 1.0 
  30. */ 
  31. function total_forums() { 
  32. echo apply_filters('total_forums', get_total_forums() ); 
  33.  
  34. /** 
  35. * Get the total number of users 
  36. * 
  37. * @since 1.0 
  38. * @uses $bbdb Database Object 
  39. * @uses $bb_total_users Cache of result generated by previous run 
  40. * 
  41. * @return int 
  42. */ 
  43. function bb_get_total_users() 
  44. global $bbdb, $bb_total_users; 
  45. if ( isset( $bb_total_users ) ) { 
  46. return $bb_total_users; 
  47. if ( false === $bb_total_users = apply_filters( 'bb_get_total_users', false ) ) { 
  48. $bb_total_users = $bbdb->get_var( "SELECT COUNT(*) FROM $bbdb->users USE INDEX (PRIMARY);" ); 
  49. return $bb_total_users; 
  50.  
  51. /** 
  52. * Output the number of users 
  53. * 
  54. * @since 1.0 
  55. */ 
  56. function bb_total_users() 
  57. echo apply_filters( 'total_users', bb_get_total_users() ); 
  58.  
  59. /** 
  60. * Get the total number of posts 
  61. * 
  62. * @since 0.7.2 
  63. * @uses $bbdb Database Object 
  64. * @uses $bb_total_posts Cache of result generated by previous run 
  65. * 
  66. * @return int 
  67. */ 
  68. function get_total_posts() { 
  69. global $bbdb, $bb_total_posts; 
  70. if ( isset($bb_total_posts) ) 
  71. return $bb_total_posts; 
  72. $bb_total_posts = $bbdb->get_var("SELECT SUM(posts) FROM $bbdb->forums"); 
  73. return $bb_total_posts; 
  74.  
  75. /** 
  76. * Output the number of posts 
  77. * 
  78. * @since 0.7.2 
  79. */ 
  80. function total_posts() { 
  81. echo apply_filters('total_posts', get_total_posts() ); 
  82.  
  83. /** 
  84. * Get the total number of topics 
  85. * 
  86. * @since 0.7.2 
  87. * @uses $bbdb Database Object 
  88. * @uses $bb_total_topics Cache of result generated by previous run 
  89. * 
  90. * @return int 
  91. */ 
  92. function get_total_topics() { 
  93. global $bbdb, $bb_total_topics; 
  94. if ( isset($bb_total_topics) ) 
  95. return $bb_total_topics; 
  96. $bb_total_topics = $bbdb->get_var("SELECT SUM(topics) FROM $bbdb->forums"); 
  97. return $bb_total_topics; 
  98.  
  99. /** 
  100. * Output the number of topics 
  101. * 
  102. * @since 0.7.2 
  103. */ 
  104. function total_topics() { 
  105. echo apply_filters('total_topics', get_total_topics()); 
  106.  
  107. /** 
  108. * Get the popular topics 
  109. * 
  110. * @since 0.7.2 
  111. * 
  112. * @param int $num Number of topics to return 
  113. * @return array 
  114. */ 
  115. function get_popular_topics( $num = 10 ) { 
  116. $query = new BB_Query( 'topic', array('per_page' => $num, 'order_by' => 'topic_posts', 'append_meta' => 0) ); 
  117. return $query->results; 
  118.  
  119. /** 
  120. * Output the date when current installation was created 
  121. * 
  122. * @since 0.8 
  123. * 
  124. * @param string|array $args Arguments to pass through to bb_get_inception() 
  125. */ 
  126. function bb_inception( $args = '' ) { 
  127. $args = _bb_parse_time_function_args( $args ); 
  128. $time = apply_filters( 'bb_inception', bb_get_inception( array('format' => 'mysql') + $args), $args ); 
  129. echo _bb_time_function_return( $time, $args ); 
  130.  
  131. /** 
  132. * Get the date when current installation was created 
  133. * 
  134. * @since 0.8 
  135. * @uses $bbdb Database Object 
  136. * @uses $bb_inception Result cache 
  137. * 
  138. * @param string|array $args Formatting options for the timestamp. 
  139. * @return int 
  140. */ 
  141. function bb_get_inception( $args = '' ) { 
  142. $args = _bb_parse_time_function_args( $args ); 
  143.  
  144. global $bbdb, $bb_inception; 
  145. if ( !isset($bb_inception) ) 
  146. $bb_inception = $bbdb->get_var("SELECT topic_start_time FROM $bbdb->topics ORDER BY topic_start_time LIMIT 1"); 
  147.  
  148. return apply_filters( 'bb_get_inception', _bb_time_function_return( $bb_inception, $args ) ); 
  149.  
  150. /** 
  151. * Get the average number of registrations per day 
  152. * 
  153. * @since 0.7.2 
  154. * 
  155. * @return int|float 
  156. */ 
  157. function get_registrations_per_day() 
  158. return bb_get_total_users() / ceil( ( time() - bb_get_inception( 'timestamp' ) ) / 3600 / 24 ); 
  159.  
  160. /** 
  161. * Output the average number of registrations per day 
  162. * 
  163. * @since 0.7.2 
  164. */ 
  165. function registrations_per_day() { 
  166. echo apply_filters('registrations_per_day', bb_number_format_i18n(get_registrations_per_day(), 3)); 
  167.  
  168. /** 
  169. * Get the average number of posts per day 
  170. * 
  171. * @since 0.7.2 
  172. * 
  173. * @return int|float 
  174. */ 
  175. function get_posts_per_day() { 
  176. return get_total_posts() / ceil( ( time() - bb_get_inception( 'timestamp' ) ) / 3600 / 24 ); 
  177.  
  178. /** 
  179. * Output the average number of posts per day 
  180. * 
  181. * @since 0.7.2 
  182. */ 
  183. function posts_per_day() { 
  184. echo apply_filters('posts_per_day', bb_number_format_i18n(get_posts_per_day(), 3)); 
  185.  
  186. /** 
  187. * Get the average number of topics per day 
  188. * 
  189. * @since 0.7.2 
  190. * 
  191. * @return int|float 
  192. */ 
  193. function get_topics_per_day() { 
  194. return get_total_topics() / ceil( ( time() - bb_get_inception( 'timestamp' ) ) / 3600 / 24 ); 
  195.  
  196. /** 
  197. * Output the average number of topics per day 
  198. * 
  199. * @since 0.7.2 
  200. */ 
  201. function topics_per_day() { 
  202. echo apply_filters('topics_per_day', bb_number_format_i18n(get_topics_per_day(), 3)); 
  203.  
  204. function bb_get_total_topic_tags() 
  205. global $bb_total_topic_tags; 
  206. if ( isset($bb_total_topic_tags) ) { 
  207. return $bb_total_topic_tags; 
  208. global $wp_taxonomy_object; 
  209. $bb_total_topic_tags = $wp_taxonomy_object->count_terms( 'bb_topic_tag' ); 
  210. return $bb_total_topic_tags; 
  211.  
  212. function bb_total_topic_tags() 
  213. echo apply_filters( 'bb_total_topic_tags', bb_get_total_topic_tags() ); 
  214.  
  215. function bb_get_topic_tags_per_day() 
  216. return bb_get_total_topic_tags() / ceil( ( time() - bb_get_inception( 'timestamp' ) ) / 3600 / 24 ); 
  217.  
  218. function bb_topic_tags_per_day() 
  219. echo apply_filters('bb_topic_tags_per_day', bb_number_format_i18n( bb_get_topic_tags_per_day(), 3 ) ); 
.