From b943ab9fadf4d79939d7e1feefc01d5f77b2ef87 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 3 Nov 2010 13:36:56 +0000 Subject: [PATCH] Added statistics block --- .../mods/portal/portal_statistics_module.php | 52 +++++ root/portal/modules/portal_statistics.php | 200 ++++++++++++++++++ .../portal/modules/statistics_side.html | 21 ++ .../theme/images/portal/portal_statistics.png | Bin 0 -> 1166 bytes 4 files changed, 273 insertions(+) create mode 100644 root/language/en/mods/portal/portal_statistics_module.php create mode 100644 root/portal/modules/portal_statistics.php create mode 100644 root/styles/prosilver/template/portal/modules/statistics_side.html create mode 100644 root/styles/prosilver/theme/images/portal/portal_statistics.png diff --git a/root/language/en/mods/portal/portal_statistics_module.php b/root/language/en/mods/portal/portal_statistics_module.php new file mode 100644 index 00000000..97e7357a --- /dev/null +++ b/root/language/en/mods/portal/portal_statistics_module.php @@ -0,0 +1,52 @@ + 'Totals', + 'ST_TOP_ANNS' => 'Total Announcements:', + 'ST_TOP_STICKYS'=> 'Total Stickies:', + 'ST_TOT_ATTACH' => 'Total Attachments:', + 'TOPICS_PER_DAY_OTHER' => 'Topics per day: %d', + 'TOPICS_PER_DAY_ZERO' => 'Topics per day: 0', + 'POSTS_PER_DAY_OTHER' => 'Posts per day: %d', + 'POSTS_PER_DAY_ZERO' => 'Posts per day: 0', + 'USERS_PER_DAY_OTHER' => 'Users per day: %d', + 'USERS_PER_DAY_ZERO' => 'Users per day: 0', + 'TOPICS_PER_USER_OTHER' => 'Topics per user: %d', + 'TOPICS_PER_USER_ZERO' => 'Topics per user: 0', + 'POSTS_PER_USER_OTHER' => 'Posts per user: %d', + 'POSTS_PER_USER_ZERO' => 'Posts per user: 0', + 'POSTS_PER_TOPIC_OTHER' => 'Posts per topic: %d', + 'POSTS_PER_TOPIC_ZERO' => 'Posts per topic: 0', +)); + +?> \ No newline at end of file diff --git a/root/portal/modules/portal_statistics.php b/root/portal/modules/portal_statistics.php new file mode 100644 index 00000000..fd52400e --- /dev/null +++ b/root/portal/modules/portal_statistics.php @@ -0,0 +1,200 @@ +lang}/mods/portal/" + */ + var $language = 'portal_statistics_module'; + + /** + * custom acp template + * file must be in "adm/style/portal/" + */ + var $custom_acp_tpl = ''; + + function get_template_side($module_id) + { + global $config, $template, $user; + + // Set some stats, get posts count from forums data if we... hum... retrieve all forums data + $total_posts = $config['num_posts']; + $total_topics = $config['num_topics']; + $total_users = $config['num_users']; + $total_files = $config['num_files']; + + $l_total_user_s = ($total_users == 0) ? 'TOTAL_USERS_ZERO' : 'TOTAL_USERS_OTHER'; + $l_total_post_s = ($total_posts == 0) ? 'TOTAL_POSTS_ZERO' : 'TOTAL_POSTS_OTHER'; + $l_total_topic_s = ($total_topics == 0) ? 'TOTAL_TOPICS_ZERO' : 'TOTAL_TOPICS_OTHER'; + + // avarage stat + $board_days = (time() - $config['board_startdate']) / 86400; + + $topics_per_day = ($total_topics) ? round($total_topics / $board_days, 0) : 0; + $posts_per_day = ($total_posts) ? round($total_posts / $board_days, 0) : 0; + $users_per_day = round($total_users / $board_days, 0); + $topics_per_user = ($total_topics) ? round($total_topics / $total_users, 0) : 0; + $posts_per_user = ($total_posts) ? round($total_posts / $total_users, 0) : 0; + $posts_per_topic = ($total_topics) ? round($total_posts / $total_topics, 0) : 0; + + if ($topics_per_day > $total_topics) + { + $topics_per_day = $total_topics; + } + + if ($posts_per_day > $total_posts) + { + $posts_per_day = $total_posts; + } + + if ($users_per_day > $total_users) + { + $users_per_day = $total_users; + } + + if ($topics_per_user > $total_topics) + { + $topics_per_user = $total_topics; + } + + if ($posts_per_user > $total_posts) + { + $posts_per_user = $total_posts; + } + + if ($posts_per_topic > $total_posts) + { + $posts_per_topic = $total_posts; + } + + $l_topics_per_day_s = ($total_topics == 0) ? 'TOPICS_PER_DAY_ZERO' : 'TOPICS_PER_DAY_OTHER'; + $l_posts_per_day_s = ($total_posts == 0) ? 'POSTS_PER_DAY_ZERO' : 'POSTS_PER_DAY_OTHER'; + $l_users_per_day_s = ($total_users == 0) ? 'USERS_PER_DAY_ZERO' : 'USERS_PER_DAY_OTHER'; + $l_topics_per_user_s = ($total_topics == 0) ? 'TOPICS_PER_USER_ZERO' : 'TOPICS_PER_USER_OTHER'; + $l_posts_per_user_s = ($total_posts == 0) ? 'POSTS_PER_USER_ZERO' : 'POSTS_PER_USER_OTHER'; + $l_posts_per_topic_s = ($total_posts == 0) ? 'POSTS_PER_TOPIC_ZERO' : 'POSTS_PER_TOPIC_OTHER'; + + $topics_count = $this->get_topics_count(); + + + // Assign specific vars + $template->assign_vars(array( + 'S_DISPLAY_ADVANCED_STAT' => true, + 'TOTAL_POSTS' => sprintf($user->lang[$l_total_post_s], $total_posts), + 'TOTAL_TOPICS' => sprintf($user->lang[$l_total_topic_s], $total_topics), + 'TOTAL_USERS' => sprintf($user->lang[$l_total_user_s], $total_users), + 'NEWEST_USER' => sprintf($user->lang['NEWEST_USER'], get_username_string('full', $config['newest_user_id'], $config['newest_username'], $config['newest_user_colour'])), + 'S_ANN' => $topics_count[POST_ANNOUNCE], + 'S_SCT' => $topics_count[POST_STICKY], + 'S_TOT_ATTACH' => ($config['allow_attachments']) ? $total_files : 0, + + // avarage stat + 'TOPICS_PER_DAY' => sprintf($user->lang[$l_topics_per_day_s], $topics_per_day), + 'POSTS_PER_DAY' => sprintf($user->lang[$l_posts_per_day_s], $posts_per_day), + 'USERS_PER_DAY' => sprintf($user->lang[$l_users_per_day_s], $users_per_day), + 'TOPICS_PER_USER' => sprintf($user->lang[$l_topics_per_user_s], $topics_per_user), + 'POSTS_PER_USER' => sprintf($user->lang[$l_posts_per_user_s], $posts_per_user), + 'POSTS_PER_TOPIC' => sprintf($user->lang[$l_posts_per_topic_s], $posts_per_topic), + )); + return 'statistics_side.html'; + } + + function get_template_acp($module_id) + { + return array( + 'title' => 'STATISTICS', + 'vars' => array(), + ); + } + + /** + * API functions + */ + function install($module_id) + { + return true; + } + + function uninstall($module_id) + { + return true; + } + + // Better function with only one query + function get_topics_count() + { + global $db, $user; + + $return_ary = array( + POST_ANNOUNCE => 0, + POST_STICKY => 0, + ); + + $sql_in = array( + POST_ANNOUNCE, + POST_STICKY, + ); + + $sql = 'SELECT DISTINCT(topic_id) AS topic_id, topic_type AS type + FROM ' . TOPICS_TABLE . ' + WHERE ' . $db->sql_in_set('topic_type', $sql_in, false); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + switch($row['type']) + { + case POST_ANNOUNCE: + ++$return_ary[POST_ANNOUNCE]; + break; + + case POST_STICKY: + ++$return_ary[POST_STICKY]; + break; + } + } + $db->sql_freeresult($result); + + return $return_ary; + } +} + +?> \ No newline at end of file diff --git a/root/styles/prosilver/template/portal/modules/statistics_side.html b/root/styles/prosilver/template/portal/modules/statistics_side.html new file mode 100644 index 00000000..07f15090 --- /dev/null +++ b/root/styles/prosilver/template/portal/modules/statistics_side.html @@ -0,0 +1,21 @@ + +{$LR_BLOCK_H_L} {L_STATISTICS}{$LR_BLOCK_H_R} + {L_ST_TOP}
+ {TOTAL_POSTS}
+ {TOTAL_TOPICS}
+ {L_ST_TOP_ANNS} {S_ANN}
+ {L_ST_TOP_STICKYS} {S_SCT}
+ {L_ST_TOT_ATTACH} {S_TOT_ATTACH}
+ +
+ {TOPICS_PER_DAY}
+ {POSTS_PER_DAY}
+ {USERS_PER_DAY}
+ {TOPICS_PER_USER}
+ {POSTS_PER_USER}
+ {POSTS_PER_TOPIC}
+
+ + {TOTAL_USERS}
+ {NEWEST_USER} +{$LR_BLOCK_F_L}{$LR_BLOCK_F_R} \ No newline at end of file diff --git a/root/styles/prosilver/theme/images/portal/portal_statistics.png b/root/styles/prosilver/theme/images/portal/portal_statistics.png new file mode 100644 index 0000000000000000000000000000000000000000..82e15c17900e2a6b387b7f7a9731382651451dc3 GIT binary patch literal 1166 zcmX9+eNdBi9RIRsdwAKiSTSY8qj75LVadi)x$|XA@r4rQ)O^VjHks2a56~qemARCG zU8R)y8f|%3W~pSJ*x`a_Zoqhvd0I>@gb6YS2oH?OvlpIUtN!?YKll0L^S$qVKA&T` zYgh5&lHve>m%Tb`eFXXcP7EH|VjogQfUQyFC;)043pt;9BV43iu|>O~aHqCJxmOK} zf~NTy>1yklsw#uQEw{;WTylqO zY$B=PqR`D#H1iX7fi z;ThWS2p#szBvPs6&}g;WF=HBDOQtuivP>stAJ-S;S|k(tFRZC6`!6QeFRmNCKPBbx z79o@VW9+3-ZXCWJKJrF&Q5+RuGMn{?STrx&E74t&NEYAX3Z8g0TkMRZ zi)werb(C^m$b*VdZFO-kVIX*eI{rF0%w_ zlUv}~YDA`PS$MLLqfNbwGGDVE-z+`3y1IaW>T7kr&R?#mICk3o)a#rAQJ{c�Crx z4v)tpsv`sZgE$Nea9Dr^;qlM_JRGG!z()|mq9B z&z$p|Te1)k`KDJ3iP>Owb2K;~T#h2^%CbOX=8GQO^?a zmASjpCDJg8?OVQq8%bl=R*P#%0l$&zGbUi?d)~)8eet4KlZ?{J*k2`Kx`|97o1I0T zr}4%bxuF=>issA`o;|A&IQT0gWl}2p^S|8mM3djsuc6I9cTgOm>jJ4mxE&b+Zm}%k zNc*h~gvyjAJIJ)y$!2Ri%&&0I&5g|jY4wuuknOsQJR04eVId#%VM%Q)?YwCxoK_o2 zJ!{!!Ecz~o$gWBhJ@z6sP5Gu_z8XZVD?ck*TY3E|E9O7{Flu0afByh0CpuBUV#Qz( zW&i>RVC;n-I_~rU?~a*KO|3=#5JG-#82vHmMGu2P7+>%b