1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-31 02:00:14 +02:00

More forum problems fixed (stats, some outdated sql queries), more to do

This commit is contained in:
secretr
2011-04-25 14:13:45 +00:00
parent 1a562f6fa2
commit 5204861279
6 changed files with 115 additions and 41 deletions

View File

@@ -13,8 +13,11 @@
*/
require_once('../../class2.php');
$e107 = e107::getInstance();
if (!$e107->isInstalled('forum'))
$sql = e107::getDb();
if (!$e107->isInstalled('forum'))
{
header('Location: '.e_BASE.'index.php');
exit;
@@ -68,36 +71,98 @@ foreach($array as $table)
}
$query = "
SELECT ft.thread_id, ft.thread_user, ft.thread_name, ft.thread_total_replies, ft.thread_datestamp, f.forum_class, u.user_name, u.user_id FROM #forum_t as ft
LEFT JOIN #user AS u ON SUBSTRING_INDEX(ft.thread_user,'.',1) = u.user_id
SELECT ft.thread_id, ft.thread_user, ft.thread_name, ft.thread_total_replies, ft.thread_datestamp, f.forum_class, u.user_name, u.user_id FROM #forum_thread as ft
LEFT JOIN #user AS u ON ft.thread_user = u.user_id
LEFT JOIN #forum AS f ON f.forum_id = ft.thread_forum_id
WHERE ft.thread_parent = 0
AND ft.thread_active != 0
WHERE ft.thread_active > 0
AND f.forum_class IN (".USERCLASS_LIST.")
ORDER BY thread_total_replies DESC LIMIT 0,10";
ORDER BY ft.thread_total_replies DESC LIMIT 0,10";
$sql -> db_Select_gen($query);
$most_activeArray = $sql -> db_getList();
$query = "
SELECT ft.*, f.forum_class, u.user_name, u.user_id FROM #forum_t as ft
LEFT JOIN #user AS u ON SUBSTRING_INDEX(ft.thread_user,'.',1) = u.user_id
SELECT ft.*, f.forum_class, u.user_name, u.user_id FROM #forum_thread as ft
LEFT JOIN #user AS u ON ft.thread_user = u.user_id
LEFT JOIN #forum AS f ON f.forum_id = ft.thread_forum_id
WHERE ft.thread_parent=0
AND f.forum_class IN (".USERCLASS_LIST.")
ORDER BY thread_views DESC LIMIT 0,10";
WHERE f.forum_class IN (".USERCLASS_LIST.")
ORDER BY ft.thread_views DESC LIMIT 0,10";
$sql -> db_Select_gen($query);
$most_viewedArray = $sql -> db_getList();
$sql->db_Select("user", "user_id, user_name, user_forums", "ORDER BY user_forums DESC LIMIT 0, 10", "no_where");
/*$sql->db_Select("user", "user_id, user_name, user_forums", "ORDER BY user_forums DESC LIMIT 0, 10", "no_where");
$posters = $sql -> db_getList();
$top_posters = array();
foreach($posters as $poster)
{
$percen = round(($poster['user_forums'] / $total_posts) * 100, 2);
$top_posters[] = array("user_id" => $poster['user_id'], "user_name" => $poster['user_name'], "user_forums" => $poster['user_forums'], "percentage" => $percen);
}*/
// get all replies
$query = "
SELECT COUNT(fp.post_id) AS post_count, u.user_name, u.user_id, fp.post_thread FROM #forum_post as fp
LEFT JOIN #user AS u ON fp.post_user = u.user_id
GROUP BY fp.post_user
ORDER BY post_count DESC LIMIT 0,10";
$sql -> db_Select_gen($query);
$top_repliers_data = $sql -> db_getList('ALL', false, false, 'user_id');
// build top posters meanwhile
$top_posters = array();
foreach($top_repliers_data as $poster)
{
$percent = round(($poster['post_count'] / $total_posts) * 100, 2);
$top_posters[] = array("user_id" => $poster['user_id'], "user_name" => $poster['user_name'], "user_forums" => $poster['post_count'], "percentage" => $percent);
}
// end build top posters
$ids = implode(',', array_keys($top_repliers_data));
// find topics by top 10 users
$query = "
SELECT COUNT(ft.thread_id) AS thread_count, u.user_id FROM #forum_thread as ft
LEFT JOIN #user AS u ON ft.thread_user = u.user_id
WHERE u.user_id IN ({$ids})
GROUP BY ft.thread_user";
$sql -> db_Select_gen($query);
$top_repliers_data_c = $sql -> db_getList('ALL', false, false, 'user_id');
$top_repliers = array();
foreach($top_repliers_data as $uid => $poster)
{
$poster['post_count'] = $poster['post_count'] - $top_repliers_data_c[$uid]['thread_count'];
$percent = round(($poster['post_count'] / $total_replies) * 100, 2);
$top_repliers_sort[$uid] = $poster['post_count'];
//$top_repliers[$uid] = $poster;
$top_repliers_data[$uid]['user_forums'] = $poster['post_count'];
$top_repliers_data[$uid]['percentage'] = $percent;
//$top_repliers_data[$uid] = array("user_id" => $poster['user_id'], "user_name" => $poster['user_name'], "user_forums" => $poster['post_count'], "percentage" => $percent);
}
// sort
arsort($top_repliers_sort, SORT_NUMERIC);
// build top repliers
foreach ($top_repliers_sort as $uid => $c)
{
$top_repliers[] = $top_repliers_data[$uid];
}
// get all replies
$query = "
SELECT COUNT(ft.thread_id) AS thread_count, u.user_name, u.user_id FROM #forum_thread as ft
LEFT JOIN #user AS u ON ft.thread_user = u.user_id
GROUP BY ft.thread_user
ORDER BY thread_count DESC LIMIT 0,10";
$sql -> db_Select_gen($query);
$top_topic_starters_data = $sql -> db_getList();
$top_topic_starters = array();
foreach($top_topic_starters_data as $poster)
{
$percent = round(($poster['thread_count'] / $total_topics) * 100, 2);
$top_topic_starters[] = array("user_id" => $poster['user_id'], "user_name" => $poster['user_name'], "user_forums" => $poster['thread_count'], "percentage" => $percent);
}
/*
$query = "
SELECT SUBSTRING_INDEX(thread_user,'.',1) AS t_user, COUNT(SUBSTRING_INDEX(ft.thread_user,'.',1)) AS ucount, u.user_name, u.user_id FROM #forum_t as ft
LEFT JOIN #user AS u ON SUBSTRING_INDEX(ft.thread_user,'.',1) = u.user_id
@@ -112,8 +177,9 @@ foreach($posters as $poster)
{
$percen = round(($poster['ucount'] / $total_topics) * 100, 2);
$top_topic_starters[] = array("user_id" => $poster['user_id'], "user_name" => $poster['user_name'], "user_forums" => $poster['ucount'], "percentage" => $percen);
}
}*/
/*
$query = "
SELECT SUBSTRING_INDEX(thread_user,'.',1) AS t_user, COUNT(SUBSTRING_INDEX(ft.thread_user,'.',1)) AS ucount, u.user_name, u.user_id FROM #forum_t as ft
LEFT JOIN #user AS u ON SUBSTRING_INDEX(ft.thread_user,'.',1) = u.user_id
@@ -130,7 +196,7 @@ foreach($posters as $poster)
$percen = round(($poster['ucount'] / $total_replies) * 100, 2);
$top_repliers[] = array("user_id" => $poster['user_id'], "user_name" => $poster['user_name'], "user_forums" => $poster['ucount'], "percentage" => $percen);
}
*/
$text = "