|
From: Jon O. <jon...@us...> - 2006-07-04 22:34:07
|
Update of /cvsroot/mxbb/mx_kb/kb/modules In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv12783/modules/mx_kb/kb/modules Modified Files: kb_article.php kb_cat.php kb_rate.php kb_search.php kb_stats.php Log Message: lots of optimizations Index: kb_stats.php =================================================================== RCS file: /cvsroot/mxbb/mx_kb/kb/modules/kb_stats.php,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** kb_stats.php 7 Jun 2006 20:28:54 -0000 1.3 --- kb_stats.php 4 Jul 2006 22:33:32 -0000 1.4 *************** *** 69,73 **** )); ! $this->display_stats( $stats, '1', 'articlerow', $start, $kb_config['pagination'] ); // --- 69,74 ---- )); ! $this->display_stats( $start, $stats ); ! //$this->display_stats( $stats, '1', 'articlerow', $start, $kb_config['pagination'] ); // Index: kb_rate.php =================================================================== RCS file: /cvsroot/mxbb/mx_kb/kb/modules/kb_rate.php,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** kb_rate.php 28 Jun 2006 21:18:14 -0000 1.5 --- kb_rate.php 4 Jul 2006 22:33:32 -0000 1.6 *************** *** 27,58 **** function main( $action ) { ! global $template, $lang, $db, $phpEx, $kb_config, $mx_request_vars, $userdata; ! global $mx_root_path, $module_root_path, $is_block, $phpEx; ! // // Request vars ! // ! $start = $mx_request_vars->get('start', MX_TYPE_INT, 0); ! $article_id = $mx_request_vars->request('k', MX_TYPE_INT, 0); ! $rating = $mx_request_vars->request('rating', MX_TYPE_INT, 0); ! $rate = $mx_request_vars->request('rate', MX_TYPE_NO_TAGS, ''); if ( empty( $article_id ) ) { ! mx_message_die( GENERAL_MESSAGE, $lang['Article_not_exsist'] ); } ! $template->set_filenames( array( 'body' => 'kb_rate_body.tpl' ) ); ! $sql = "SELECT * ! FROM " . KB_ARTICLES_TABLE . " ! WHERE article_id = '" . $article_id . "'"; if ( !( $result = $db->sql_query( $sql ) ) ) { ! mx_message_die( GENERAL_ERROR, 'Couldnt Query Article info', '', __LINE__, __FILE__, $sql ); } ! if ( !$article = $db->sql_fetchrow( $result ) ) { mx_message_die( GENERAL_MESSAGE, $lang['Article_not_exsist'] ); --- 27,56 ---- function main( $action ) { ! global $template, $lang, $board_config, $phpEx, $kb_config, $db, $userdata; ! global $phpbb_root_path, $mx_kb_user, $mx_kb_functions; ! global $mx_root_path, $module_root_path, $is_block, $phpEx, $mx_request_vars; ! // ======================================================= // Request vars ! // ======================================================= ! $article_id = $mx_request_vars->request('k', MX_TYPE_INT, ''); if ( empty( $article_id ) ) { ! mx_message_die( GENERAL_MESSAGE, $lang['Link_not_exist'] ); } ! $rating = ( isset( $_POST['rating'] ) ) ? intval( $_POST['rating'] ) : ''; ! $sql = 'SELECT article_title, article_category_id ! FROM ' . KB_ARTICLES_TABLE . " ! WHERE article_id = $article_id"; if ( !( $result = $db->sql_query( $sql ) ) ) { ! mx_message_die( GENERAL_ERROR, 'Couldnt Query article info', '', __LINE__, __FILE__, $sql ); } ! if ( !$article_data = $db->sql_fetchrow( $result ) ) { mx_message_die( GENERAL_MESSAGE, $lang['Article_not_exsist'] ); *************** *** 61,183 **** $db->sql_freeresult( $result ); ! $category_id = $article['article_category_id']; ! ! if ( !$this->auth_user[$category_id]['auth_rate'] || !$kb_config['use_ratings'] ) ! { ! // ! // The user is not authed to read this cat ... ! // ! $message = $lang['Not_authorized']; ! mx_message_die(GENERAL_MESSAGE, $message); ! } ! ! $ipaddy = getenv ( "REMOTE_ADDR" ); ! ! if ( $kb_config['votes_check_ip'] == 1 ) ! { ! $sql = "SELECT * FROM " . KB_VOTES_TABLE . " WHERE votes_ip = '" . $ipaddy . "' AND votes_file = '" . $article_id . "'"; ! if ( !( $result = $db->sql_query( $sql ) ) ) ! { ! mx_message_die( GENERAL_ERROR, 'Couldnt Query rate ip', '', __LINE__, __FILE__, $sql ); ! } ! ! if ( $db->sql_numrows( $result ) > 0 ) ! { ! $template->assign_vars( array( "META" => '<meta http-equiv="refresh" content="3;url=' . append_sid( this_kb_mxurl( "action=url&k=" . $article_id ) ) . '">' ) ! ); ! $message = $lang['Rerror'] . "<br /><br />" . sprintf( $lang['Click_return_rate'], "<a href=\"" . append_sid( this_kb_mxurl( "mode=article&k=$article_id" ) ) . "\">", "</a>" ); ! mx_message_die( GENERAL_MESSAGE, $message ); ! } ! } ! ! if ( $kb_config['votes_check_userid'] == 1 ) { ! $sql = "SELECT * FROM " . KB_VOTES_TABLE . " WHERE votes_userid = '" . $userdata['user_id'] . "' AND votes_file = '" . $article_id . "'"; ! if ( !( $result = $db->sql_query( $sql ) ) ) ! { ! mx_message_die( GENERAL_ERROR, 'Couldnt Query rate ip', '', __LINE__, __FILE__, $sql ); ! } ! ! if ( $db->sql_numrows( $result ) > 0 ) { ! $template->assign_vars( array( "META" => '<meta http-equiv="refresh" content="3;url=' . append_sid( this_kb_mxurl( "action=url&k=" . $article_id ) ) . '">' ) ! ); ! $message = $lang['Rerror'] . "<br /><br />" . sprintf( $lang['Click_return_rate'], "<a href=\"" . append_sid( this_kb_mxurl( "mode=article&k=$article_id" ) ) . "\">", "</a>" ); ! mx_message_die( GENERAL_MESSAGE, $message ); } } ! if ( $rate == 'dorate' ) ! { ! $conf = str_replace( "{filename}", $article['article_title'], $lang['Rconf'] ); ! $conf = str_replace( "{rate}", $rating, $conf ); ! ! if ( $article['article_totalvotes'] == 1 ) ! { ! $add = 0; ! } ! else ! { ! $add = 1; ! } ! ! $sql = "UPDATE " . KB_ARTICLES_TABLE . " SET article_rating=article_rating+" . $rating . ", article_totalvotes=article_totalvotes+1 WHERE article_id = '" . $article_id . "'"; ! ! if ( !( $update = $db->sql_query( $sql ) ) ) ! { ! mx_message_die( GENERAL_ERROR, 'Couldnt Update rating table', '', __LINE__, __FILE__, $sql ); ! } ! ! $ipaddy = getenv ( "REMOTE_ADDR" ); ! ! $sql = "INSERT INTO " . KB_VOTES_TABLE . " VALUES('" . $ipaddy . "', '" . $userdata['user_id'] . "', '" . $article_id . "')"; ! if ( !( $insert = $db->sql_query( $sql ) ) ) ! { ! mx_message_die( GENERAL_ERROR, 'Couldnt Update rating table', '', __LINE__, __FILE__, $sql ); ! } ! $sql = "SELECT * FROM " . KB_ARTICLES_TABLE . " WHERE article_id = '" . $article_id . "'"; ! if ( !( $result = $db->sql_query( $sql ) ) ) ! { ! mx_message_die( GENERAL_ERROR, 'Couldnt Update rating table', '', __LINE__, __FILE__, $sql ); ! } ! $article = $db->sql_fetchrow( $result ); ! if ( $article['article_rating'] == 0 or $article['article_totalvotes'] == 0 ) ! { ! $nrating = 0; ! } ! else { ! $nrating = round( $article['article_rating'] / ( $article['article_totalvotes'] ), 3 ); } ! $conf = str_replace( "{newrating}", $nrating, $conf ); ! $template->assign_vars( array( "META" => '<meta http-equiv="refresh" content="3;url=' . append_sid( this_kb_mxurl( "action=url&k=" . $article_id ) ) . '">' ) ); ! if ( !$this->reader_mode ) ! { ! $message = $conf . "<br /><br />" . sprintf( $lang['Click_return_rate'], "<a href=\"" . append_sid( this_kb_mxurl( "mode=article&k=$article_id" ) ) . "\">", "</a>" ) . "<br /><br />" . sprintf( $lang['Click_return_forum'], "<a href=\"" . append_sid( "index.$phpEx?page=$page_id&mode=cat&cat=$category_id" ) . "\">", "</a>" ); ! } ! else ! { ! $message = $conf . "<br /><br />" . sprintf( $lang['Click_return_rate'], "<a href=\"" . append_sid( this_kb_mxurl( "mode=article&k=$article_id" ) ) . "\">", "</a>" ); ! } mx_message_die( GENERAL_MESSAGE, $message ); } else { ! $rateinfo = str_replace( "{filename}", $article['article_title'], $lang['Rateinfo'] ); ! ! $template->assign_block_vars( "rate", array() ); - $path_kb = $lang['Rate']; $template->assign_vars( array( ! 'S_RATE_ACTION' => append_sid( this_kb_mxurl( ) ), 'L_RATE' => $lang['Rate'], 'L_RERROR' => $lang['Rerror'], --- 59,109 ---- $db->sql_freeresult( $result ); ! if ( !$this->auth_user[$article_data['article_category_id']]['auth_rate'] ) { ! if ( !$userdata['session_logged_in'] ) { ! mx_message_die( GENERAL_MESSAGE, 'not logged in' ); } + mx_message_die( GENERAL_MESSAGE, $lang['Not_authorized'] ); } ! $template->assign_vars( array( ! 'L_INDEX' => "<<", ! 'L_RATE' => $lang['Rate'], ! 'U_INDEX' => append_sid( $mx_root_path . 'index.' . $phpEx ), ! 'U_DOWNLOAD_HOME' => append_sid( this_kb_mxurl() ), ! 'U_FILE_NAME' => append_sid( this_kb_mxurl( 'mode=article&k=' . $article_id ) ), ! 'FILE_NAME' => $article_data['file_name'], ! 'DOWNLOAD' => $kb_config['module_name'] ! )); ! if ( isset( $_POST['submit'] ) ) ! { ! $result_msg = str_replace( "{filename}", $article_data['article_title'], $lang['Rconf'] ); ! $result_msg = str_replace( "{rate}", $rating, $result_msg ); ! if ( ( $rating <= 0 ) or ( $rating > 10 ) ) { ! mx_message_die( GENERAL_ERROR, 'Bad submited value' ); } ! $mx_kb_user->update_voter_info( $article_id, $rating, $article_data['article_category_id'] ); ! $rate_info = $mx_kb_functions->get_rating( $article_id ); ! $result_msg = str_replace( "{newrating}", $rate_info, $result_msg ); + $message = $result_msg . '<br /><br />' . sprintf( $lang['Click_return'], "<a href=\"" . append_sid( this_kb_mxurl( "action=link&link_id=$article_id" ) ) . "\">", "</a>" ); mx_message_die( GENERAL_MESSAGE, $message ); } else { ! $rate_info = str_replace( "{filename}", $article_data['article_title'], $lang['Rateinfo'] ); $template->assign_vars( array( ! 'S_RATE_ACTION' => append_sid( this_kb_mxurl( 'mode=rate&k=' . $article_id ) ), 'L_RATE' => $lang['Rate'], 'L_RERROR' => $lang['Rerror'], *************** *** 192,197 **** 'L_R9' => $lang['R9'], 'L_R10' => $lang['R10'], ! 'RATEINFO' => $rateinfo, ! 'PATH' => '» ' . $path_kb, 'ID' => $article_id ) ); --- 118,122 ---- 'L_R9' => $lang['R9'], 'L_R10' => $lang['R10'], ! 'RATEINFO' => $rate_info, 'ID' => $article_id ) ); *************** *** 199,215 **** // =================================================== ! // assign var for top navigation // =================================================== ! //$this->generate_navigation( $category_id ); ! ! // ! // User authorisation levels output ! // ! $this->auth_can($category_id); ! ! // ! // Get footer quick dropdown jumpbox ! // ! $this->generate_jumpbox( 'auth_view', $category_id, $category_id, true ); } } --- 124,131 ---- // =================================================== ! // assign var for navigation // =================================================== ! $this->generate_navigation( $article_data['article_category_id'] ); ! $template->set_filenames( array( 'body' => 'kb_rate_body.tpl' ) ); } } Index: kb_article.php =================================================================== RCS file: /cvsroot/mxbb/mx_kb/kb/modules/kb_article.php,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** kb_article.php 28 Jun 2006 13:58:08 -0000 1.8 --- kb_article.php 4 Jul 2006 22:33:32 -0000 1.9 *************** *** 45,51 **** mx_message_die( GENERAL_MESSAGE, $lang['Article_not_exsist'] ); } ! $sql = "SELECT * ! FROM " . KB_ARTICLES_TABLE . " ! WHERE article_id = $article_id"; if ( !( $result = $db->sql_query( $sql ) ) ) { --- 45,75 ---- mx_message_die( GENERAL_MESSAGE, $lang['Article_not_exsist'] ); } ! ! // ======================================================= ! // article id is not set, give him/her a nice error message ! // ======================================================= ! switch ( SQL_LAYER ) ! { ! case 'oracle': ! $sql = "SELECT f.*, AVG(r.rate_point) AS rating, COUNT(r.votes_article) AS total_votes, u.user_id, u.username ! FROM " . KB_ARTICLES_TABLE . " AS f, " . KB_VOTES_TABLE . " AS r, " . USERS_TABLE . " AS u ! WHERE f.article_id = r.votes_article(+) ! AND f.article_author_id = u.user_id(+) ! AND f.article_id = $article_id ! AND f.approved = 1 ! GROUP BY f.article_id "; ! break; ! ! default: ! $sql = "SELECT f.*, AVG(r.rate_point) AS rating, COUNT(r.votes_article) AS total_votes, u.user_id, u.username ! FROM " . KB_ARTICLES_TABLE . " AS f ! LEFT JOIN " . KB_VOTES_TABLE . " AS r ON f.article_id = r.votes_article ! LEFT JOIN " . USERS_TABLE . " AS u ON f.article_author_id = u.user_id ! WHERE f.article_id = $article_id ! AND f.approved = 1 ! GROUP BY f.article_id "; ! break; ! } ! if ( !( $result = $db->sql_query( $sql ) ) ) { *************** *** 352,356 **** if ( $this->ratings[$article_category_id]['activated'] ) { ! $article_rating = ( $kb_row['article_rating'] != 0 ) ? round( $kb_row['article_rating'] / $kb_row['article_totalvotes'], 2 ) . ' / 10' : $lang['No_votes']; if ( $this->auth_user[$article_category_id]['auth_rate'] ) --- 376,380 ---- if ( $this->ratings[$article_category_id]['activated'] ) { ! $article_rating = ( $kb_row['rating'] != 0 ) ? round( $kb_row['rating'] / $kb_row['total_votes'], 2 ) . ' / 10' : $lang['No_votes']; if ( $this->auth_user[$article_category_id]['auth_rate'] ) Index: kb_cat.php =================================================================== RCS file: /cvsroot/mxbb/mx_kb/kb/modules/kb_cat.php,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** kb_cat.php 17 Jun 2006 20:11:24 -0000 1.4 --- kb_cat.php 4 Jul 2006 22:33:32 -0000 1.5 *************** *** 159,163 **** // Get articles // ! $this->display_articles( $category_id, '1', 'articlerow', $start, $kb_config['pagination'] ); // --- 159,164 ---- // Get articles // ! $this->display_articles( $start, $category_id ); ! //$this->display_articles( $category_id, '1', 'articlerow', $start, $kb_config['pagination'] ); // Index: kb_search.php =================================================================== RCS file: /cvsroot/mxbb/mx_kb/kb/modules/kb_search.php,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** kb_search.php 7 Jun 2006 20:28:54 -0000 1.4 --- kb_search.php 4 Jul 2006 22:33:32 -0000 1.5 *************** *** 95,99 **** break; case 'article_rating': ! $sort_method = 'article_rating'; break; /* --- 95,99 ---- break; case 'article_rating': ! //$sort_method = 'article_rating'; break; /* *************** *** 479,486 **** { case 'oracle': ! $sql = "SELECT a.*, a.article_rating AS rating, a.article_totalvotes AS total_votes, u.user_id, u.username, c.category_id, c.category_name, COUNT(cm.comments_id) AS total_comments FROM " . KB_ARTICLES_TABLE . " AS a, " . KB_VOTES_TABLE . " AS r, " . USERS_TABLE . " AS u, " . KB_CATEGORIES_TABLE . " AS c, " . KB_COMMENTS_TABLE . " AS cm WHERE a.article_id IN ($search_results) ! AND a.article_id = r.votes_file(+) AND a.article_author_id = u.user_id(+) AND a.article_id = cm.article_id(+) --- 479,486 ---- { case 'oracle': ! $sql = "SELECT a.*, AVG(r.rate_point) AS rating, COUNT(r.votes_article) AS total_votes, u.user_id, u.username, c.category_id, c.category_name, COUNT(cm.comments_id) AS total_comments FROM " . KB_ARTICLES_TABLE . " AS a, " . KB_VOTES_TABLE . " AS r, " . USERS_TABLE . " AS u, " . KB_CATEGORIES_TABLE . " AS c, " . KB_COMMENTS_TABLE . " AS cm WHERE a.article_id IN ($search_results) ! AND a.article_id = r.votes_article(+) AND a.article_author_id = u.user_id(+) AND a.article_id = cm.article_id(+) *************** *** 493,499 **** default: ! $sql = "SELECT a.*, a.article_rating AS rating, a.article_totalvotes AS total_votes, u.user_id, u.username, c.category_id, c.category_name, COUNT(cm.comments_id) AS total_comments FROM " . KB_ARTICLES_TABLE . " AS a, " . KB_CATEGORIES_TABLE . " AS c ! LEFT JOIN " . KB_VOTES_TABLE . " AS r ON a.article_id = r.votes_file LEFT JOIN " . USERS_TABLE . " AS u ON a.article_author_id = u.user_id LEFT JOIN " . KB_COMMENTS_TABLE . " AS cm ON a.article_id = cm.article_id --- 493,499 ---- default: ! $sql = "SELECT a.*, AVG(r.rate_point) AS rating, COUNT(r.votes_article) AS total_votes, u.user_id, u.username, c.category_id, c.category_name, COUNT(cm.comments_id) AS total_comments FROM " . KB_ARTICLES_TABLE . " AS a, " . KB_CATEGORIES_TABLE . " AS c ! LEFT JOIN " . KB_VOTES_TABLE . " AS r ON a.article_id = r.votes_article LEFT JOIN " . USERS_TABLE . " AS u ON a.article_author_id = u.user_id LEFT JOIN " . KB_COMMENTS_TABLE . " AS cm ON a.article_id = cm.article_id |