diff --git a/e107_plugins/forum/e_url/forum.php b/e107_plugins/forum/e_url/forum.php index caba6ec81..883505cf4 100644 --- a/e107_plugins/forum/e_url/forum.php +++ b/e107_plugins/forum/e_url/forum.php @@ -2,10 +2,11 @@ // $Id$ function url_forum_forum($parms) { + $amp = isset($parms['raw']) ? '&' : '&'; switch($parms['func']) { case 'view': - $page = (varset($parms['page']) ? '&p='.$parms['page'] : ''); + $page = (varset($parms['page']) ? $amp.'p='.$parms['page'] : ''); return e_PLUGIN_ABS."forum/forum_viewforum.php?id={$parms['id']}{$page}"; break; @@ -26,7 +27,7 @@ function url_forum_forum($parms) break; case 'mfar': - return e_PLUGIN_ABS.'forum/forum.php?f=mfar&id='.$parms['id']; + return e_PLUGIN_ABS.'forum/forum.php?f=mfar'.$amp.'id='.$parms['id']; break; } diff --git a/e107_plugins/forum/e_url/thread.php b/e107_plugins/forum/e_url/thread.php index 30199e748..d1f5a5b85 100644 --- a/e107_plugins/forum/e_url/thread.php +++ b/e107_plugins/forum/e_url/thread.php @@ -2,69 +2,70 @@ // $Id$ function url_forum_thread($parms) { + $amp = isset($parms['raw']) ? '&' : '&'; switch($parms['func']) { case 'nt': - return e_PLUGIN_ABS."forum/forum_post.php?f=nt&id={$parms['id']}"; + return e_PLUGIN_ABS."forum/forum_post.php?f=nt{$amp}id={$parms['id']}"; break; case 'rp': - return e_PLUGIN_ABS."forum/forum_post.php?f=rp&id={$parms['id']}"; + return e_PLUGIN_ABS."forum/forum_post.php?f=rp{$amp}id={$parms['id']}"; break; case 'view': - $page = (varset($parms['page']) ? '&p='.$parms['page'] : ''); + $page = (varset($parms['page']) ? $amp.'p='.$parms['page'] : ''); return e_PLUGIN_ABS."forum/forum_viewtopic.php?id={$parms['id']}{$page}"; break; case 'last': - return e_PLUGIN_ABS."forum/forum_viewtopic.php?id={$parms['id']}&last=1"; + return e_PLUGIN_ABS."forum/forum_viewtopic.php?id={$parms['id']}{$amp}last=1"; break; case 'post': - return e_PLUGIN_ABS."forum/forum_viewtopic.php?f=post&id={$parms['id']}"; + return e_PLUGIN_ABS."forum/forum_viewtopic.php?f=post{$amp}id={$parms['id']}"; break; case 'report': $page = (isset($parms['page']) ? (int)$parms['page'] : 0 ); - return e_PLUGIN_ABS."forum/forum_viewtopic.php?f=report&id={$parms['id']}&post={$parms['post']}&p={$page}"; + return e_PLUGIN_ABS."forum/forum_viewtopic.php?f=report{$amp}id={$parms['id']}{$amp}post={$parms['post']}{$amp}p={$page}"; break; case 'edit': - return e_PLUGIN_ABS."forum/forum_post.php?f=edit&id={$parms['id']}"; + return e_PLUGIN_ABS."forum/forum_post.php?f=edit{$amp}id={$parms['id']}"; break; case 'move': - return e_PLUGIN_ABS."forum/forum_conf.php?f=move&id={$parms['id']}"; + return e_PLUGIN_ABS."forum/forum_conf.php?f=move{$amp}id={$parms['id']}"; break; case 'split': - return e_PLUGIN_ABS."forum/forum_conf.php?f=split&id={$parms['id']}"; + return e_PLUGIN_ABS."forum/forum_conf.php?f=split{$amp}id={$parms['id']}"; break; case 'quote': - return e_PLUGIN_ABS."forum/forum_post.php?f=quote&id={$parms['id']}"; + return e_PLUGIN_ABS."forum/forum_post.php?f=quote{$amp}id={$parms['id']}"; break; case 'next': - return e_PLUGIN_ABS."forum/forum_viewtopic.php?f=next&id={$parms['id']}"; + return e_PLUGIN_ABS."forum/forum_viewtopic.php?f=next{$amp}id={$parms['id']}"; break; case 'prev': - return e_PLUGIN_ABS."forum/forum_viewtopic.php?f=prev&id={$parms['id']}"; + return e_PLUGIN_ABS."forum/forum_viewtopic.php?f=prev{$amp}id={$parms['id']}"; break; case 'track': - return e_PLUGIN_ABS."forum/forum_viewtopic.php?f=track&id={$parms['id']}"; + return e_PLUGIN_ABS."forum/forum_viewtopic.php?f=track{$amp}id={$parms['id']}"; break; case 'untrack': - return e_PLUGIN_ABS."forum/forum_viewtopic.php?f=untrack&id={$parms['id']}"; + return e_PLUGIN_ABS."forum/forum_viewtopic.php?f=untrack{$amp}id={$parms['id']}"; break; case 'track_toggle': - return e_PLUGIN_ABS."forum/forum_viewtopic.php?f=track_toggle&id={$parms['id']}"; + return e_PLUGIN_ABS."forum/forum_viewtopic.php?f=track_toggle{$amp}id={$parms['id']}"; break; } diff --git a/e107_plugins/forum/forum.php b/e107_plugins/forum/forum.php index caf9f86cf..81c90a269 100644 --- a/e107_plugins/forum/forum.php +++ b/e107_plugins/forum/forum.php @@ -17,7 +17,7 @@ if(!defined('e107_INIT')) require_once('../../class2.php'); } $e107 = e107::getInstance(); -if (!$e107->isInstalled('forum')) +if (!$e107->isInstalled('forum')) { header('Location: '.e_BASE.'index.php'); exit; @@ -86,8 +86,8 @@ if($rules_text != '') { $fVars->USERINFO .= " | ".LAN_433.''; } -$total_topics = $sql->db_Count("forum_t", "(*)", " WHERE thread_parent='0' "); -$total_replies = $sql->db_Count("forum_t", "(*)", " WHERE thread_parent!='0' "); +$total_topics = $sql->db_Count("forum_thread", "(*)"); +$total_replies = $sql->db_Count("forum_post", "(*)"); $total_members = $sql->db_Count("user"); $newest_member = $sql->db_Select("user", "*", "user_ban='0' ORDER BY user_join DESC LIMIT 0,1"); list($nuser_id, $nuser_name) = $sql->db_Fetch(); @@ -136,7 +136,7 @@ $fVars->PERMS = (USER == TRUE || ANON == TRUE ? LAN_204." - ".LAN_206." - ".LAN_ $fVars->INFO = ""; if (USER == TRUE) { - $total_new_threads = $sql->db_Count('forum_t', '(*)', "WHERE thread_datestamp>'".USERLV."' "); + $total_new_threads = $sql->db_Count('forum_thread', '(*)', "WHERE thread_datestamp>'".USERLV."' "); if (USERVIEWED != "") { $tmp = explode(".", USERVIEWED); // List of numbers, separated by single period diff --git a/e107_plugins/forum/forum_post.php b/e107_plugins/forum/forum_post.php index 0c2c5084c..ea841ddd5 100644 --- a/e107_plugins/forum/forum_post.php +++ b/e107_plugins/forum/forum_post.php @@ -20,7 +20,7 @@ $ns = e107::getRender(); if (!$e107->isInstalled('forum')) { - header('Location: '.e_BASE.'index.php'); + header('Location: '.SITEURL.'index.php'); exit; } @@ -28,7 +28,7 @@ include_lan(e_PLUGIN.'forum/languages/'.e_LANGUAGE.'/lan_forum_post.php'); if (isset($_POST['fjsubmit'])) { - header('location:'.$e107->url->getUrl('forum', 'thread', array('func' => 'view', 'id'=>$_POST['forumjump']))); + header('Location:'.$e107->url->getUrl('forum', 'thread', array('func' => 'view', 'id'=>$_POST['forumjump'], 'raw' => true))); exit; } @@ -37,7 +37,7 @@ $forum = new e107forum(); if (!e_QUERY || !isset($_GET['id'])) { - header('Location:'.$e107->url->getUrl('forum', 'forum', array('func' => 'main'))); + header('Location:'.$e107->url->getUrl('forum', 'forum', array('func' => 'main', 'raw' => true))); exit; } @@ -66,7 +66,7 @@ switch($action) break; default: - header("Location:".$e107->url->getUrl('forum', 'forum', array('func' => 'main'))); + header("Location:".$e107->url->getUrl('forum', 'forum', array('func' => 'main', 'raw' => true))); exit; } @@ -332,7 +332,7 @@ if (isset($_POST['newthread']) || isset($_POST['reply'])) $forumLink = $e107->url->getUrl('forum', 'forum', array('func' => 'view', 'id' => $forumId)); if ($forum->prefs->get('redirect')) { - header('location:'.$threadLink); + header('location:'.$e107->url->getUrl('forum', 'thread', array('func' => 'last', 'id' => $threadId, 'raw' => true))); exit; } else diff --git a/e107_plugins/forum/forum_stats.php b/e107_plugins/forum/forum_stats.php index 57f6a747c..c8d298d14 100644 --- a/e107_plugins/forum/forum_stats.php +++ b/e107_plugins/forum/forum_stats.php @@ -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 = " diff --git a/e107_plugins/forum/forum_viewtopic.php b/e107_plugins/forum/forum_viewtopic.php index 4dc19b97d..243c3c07e 100644 --- a/e107_plugins/forum/forum_viewtopic.php +++ b/e107_plugins/forum/forum_viewtopic.php @@ -46,6 +46,11 @@ include_once(e_PLUGIN . 'forum/templates/forum_icons_template.php'); $forum = new e107forum(); $thread = new e107ForumThread(); +if (isset($_GET['last'])) +{ + $_GET['f'] = 'last'; +} + if(isset($_GET['f']) && $_GET['f'] == 'post') { $thread->processFunction(); @@ -523,6 +528,7 @@ class e107ForumThread { global $forum, $thread; $e107 = e107::getInstance(); + if (!isset($_GET['f'])) { return; @@ -543,7 +549,7 @@ class e107ForumThread case 'last': $pages = ceil(($thread->threadInfo['thread_total_replies'] + 1) / $thread->perPage); - $thread->page = ($pages - 1); + $thread->page = ($pages); break; case 'next':