|
From: Jon O. <jon...@us...> - 2006-07-04 22:34:07
|
Update of /cvsroot/mxbb/mx_kb/kb/includes In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv12783/modules/mx_kb/kb/includes Modified Files: functions.php functions_kb.php Log Message: lots of optimizations Index: functions.php =================================================================== RCS file: /cvsroot/mxbb/mx_kb/kb/includes/functions.php,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** functions.php 1 Jul 2006 21:30:30 -0000 1.9 --- functions.php 4 Jul 2006 22:33:31 -0000 1.10 *************** *** 202,205 **** --- 202,248 ---- } } + + /** + * Enter description here... + * + * @param unknown_type $link_id + * @param unknown_type $link_rating + * @return unknown + */ + function get_rating( $article_id, $article_rating = '' ) + { + global $db, $lang; + + $sql = "SELECT AVG(rate_point) AS rating + FROM " . KB_VOTES_TABLE . " + WHERE votes_article = '" . $article_id . "'"; + + if ( !( $result = $db->sql_query( $sql ) ) ) + { + mx_message_die( GENERAL_ERROR, 'Couldnt rating info for the giving article', '', __LINE__, __FILE__, $sql ); + } + + $row = $db->sql_fetchrow( $result ); + $db->sql_freeresult( $result ); + $link_rating = $row['rating']; + + return ( $link_rating != 0 ) ? round( $link_rating, 2 ) . ' / 10' : $lang['Not_rated']; + } + + /** + * Enter description here... + * + * @param unknown_type $query + * @param unknown_type $total + * @param unknown_type $offset + * @return unknown + */ + function sql_query_limit( $query, $total, $offset = 0, $sql_cache = false ) + { + global $db; + + $query .= ' LIMIT ' . ( ( !empty( $offset ) ) ? $offset . ', ' . $total : $total ); + return $sql_cache ? $db->sql_query( $query, $sql_cache ) : $db->sql_query( $query ); + } } *************** *** 369,387 **** * Enter description here... * ! * @param unknown_type $file_id * @param unknown_type $rating */ ! function update_voter_info( $file_id, $rating ) { ! global $user_ip, $db, $userdata, $lang, $mx_kb; ! $mx_kb->debug('user_info->update_voter_info', basename( __FILE__ )); ! $where_sql = ( $userdata['user_id'] != ANONYMOUS ) ? "user_id = '" . $userdata['user_id'] . "'" : "votes_ip = '" . $user_ip . "'"; $sql = "SELECT user_id, votes_ip ! FROM " . PA_VOTES_TABLE . " WHERE $where_sql - AND votes_file = '" . $file_id . "' LIMIT 1"; --- 412,445 ---- * Enter description here... * ! * @param unknown_type $article_id * @param unknown_type $rating */ ! function update_voter_info( $article_id, $rating ) { ! global $db, $userdata, $lang, $kb_config; ! $ipaddy = getenv ( "REMOTE_ADDR" ); ! if ($kb_config['votes_check_ip'] && $kb_config['votes_check_userid']) ! { ! $where_sql = ( $userdata['user_id'] != ANONYMOUS ) ? "(user_id = '" . $userdata['user_id'] . "' OR votes_ip = '" . $ipaddy . "')": "votes_ip = '" . $ipaddy . "'"; ! } ! else if($kb_config['votes_check_ip']) ! { ! $where_sql = ( $kb_config['votes_check_ip'] ) ? "votes_ip = '" . $ipaddy . "'" : ''; ! } ! else if($kb_config['votes_check_userid']) ! { ! $where_sql = ( $userdata['user_id'] != ANONYMOUS ) ? "user_id = '" . $userdata['user_id'] . "'" : ''; ! } ! else ! { ! $where_sql = "user_id = '-99'"; ! } ! $where_sql .= !empty($where_sql) ? " AND votes_article = '" . $article_id . "'" : "votes_article = '" . $article_id . "'"; $sql = "SELECT user_id, votes_ip ! FROM " . KB_VOTES_TABLE . " WHERE $where_sql LIMIT 1"; *************** *** 391,398 **** } if ( !$db->sql_numrows( $result ) ) { ! $sql = "INSERT INTO " . PA_VOTES_TABLE . " (user_id, votes_ip, votes_file, rate_point, voter_os, voter_browser, browser_version) ! VALUES('" . $userdata['user_id'] . "', '" . $user_ip . "', '" . $file_id . "','" . $rating . "', '" . $this->platform . "', '" . $this->agent . "', '" . $this->ver . "')"; if ( !( $db->sql_query( $sql ) ) ) { --- 449,460 ---- } + // + // Has already voted. Should we care? + // if ( !$db->sql_numrows( $result ) ) { ! $sql = "INSERT INTO " . KB_VOTES_TABLE . " (user_id, votes_ip, votes_article, rate_point) ! VALUES('" . $userdata['user_id'] . "', '" . $ipaddy . "', '" . $article_id . "','" . $rating . "')"; ! if ( !( $db->sql_query( $sql ) ) ) { *************** *** 402,406 **** else { ! mx_message_die( GENERAL_MESSAGE, $lang['Rerror'] ); } --- 464,469 ---- else { ! $message = $lang['Rerror'] . "<br /><br />" . sprintf( $lang['Click_return'], "<a href=\"" . append_sid( linkdb_this_mxurl( "action=link&link_id=$article_id" ) ) . "\">", "</a>" ); ! mx_message_die( GENERAL_MESSAGE, $message ); } *************** *** 888,894 **** { 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 = r.votes_file(+) AND a.article_author_id = u.user_id(+) AND a.article_id = cm.article_id(+) --- 951,957 ---- { 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 = r.votes_article(+) AND a.article_author_id = u.user_id(+) AND a.article_id = cm.article_id(+) *************** *** 899,905 **** 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 --- 962,968 ---- 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 Index: functions_kb.php =================================================================== RCS file: /cvsroot/mxbb/mx_kb/kb/includes/functions_kb.php,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** functions_kb.php 3 Jul 2006 20:12:06 -0000 1.11 --- functions_kb.php 4 Jul 2006 22:33:31 -0000 1.12 *************** *** 685,755 **** /** ! * Get all category articles. * - * @param unknown_type $id - * @param unknown_type $approve - * @param unknown_type $block_name * @param unknown_type $start ! * @param unknown_type $articles_in_cat ! * @return unknown */ ! function display_articles( $id = false, $approve, $block_name, $start = -1, $articles_in_cat = 0 ) { ! global $db, $template, $images, $phpEx, $module_root_path, $phpbb_root_path, $mx_root_path, $board_config, $lang, $is_block, $page_id, $is_admin, $userdata; ! global $kb_config; ! ! $this->debug('mx_kb->display_articles', basename( __FILE__ )); ! $sql = "SELECT t.*, u.user_id, u.user_rank, u.user_sig, u.user_sig_bbcode_uid, u.user_allowsmile ! FROM " . KB_ARTICLES_TABLE . " t, " . USERS_TABLE . " u ! WHERE "; ! if ( $id ) { ! $sql .= " t.article_category_id = " . $id . " AND"; } ! $sql .= " u.user_id = t.article_author_id"; ! ! if ( !$this->auth_user[$id]['auth_mod'] ) { ! $sql .= " AND t.approved = " . $approve; } if ( defined( 'IN_ADMIN' ) ) { ! $sql .= " ORDER BY t.article_id"; } else { ! $sql .= " ORDER BY " . $this->sort_method_extra . $this->sort_method . " " . $this->sort_order; } ! if ( $start > -1 && $articles_in_cat > 0 ) { ! $sql .= " LIMIT $start, $articles_in_cat"; } ! if ( !( $article_result = $db->sql_query( $sql ) ) ) { ! mx_message_die( GENERAL_ERROR, "Could not obtain article data", '', __LINE__, __FILE__, $sql ); } ! $i = 0; ! while ( $article = $db->sql_fetchrow( $article_result ) ) { ! $i++; ! $article_description = $article['article_description'] ; ! $article_cat = $article['article_category_id']; ! $article_approved = $article['approved']; // type ! $type_id = $article['article_type']; $article_type = $this->get_kb_type( $type_id ); ! $article_date = create_date( $board_config['default_dateformat'], $article['article_date'], $board_config['board_timezone'] ); // author information ! $author_id = $article['article_author_id']; if ( $author_id == -1 ) { ! $author = ( $article['username'] == '' ) ? $lang['Guest'] : $article['username']; } else --- 685,835 ---- /** ! * Enter description here... * * @param unknown_type $start ! * @param unknown_type $cat_id */ ! function display_articles( $start, $cat_id = false, $block_name = 'articlerow', $approve = '1' ) { ! global $db, $kb_config, $template, $board_config; ! global $images, $lang, $phpEx, $mx_kb_functions; ! global $phpbb_root_path, $mx_root_path, $module_root_path, $is_block, $phpEx; ! $filelist = false; ! $approved_sql = ''; ! if ( empty( $cat_id ) ) { ! $approved_sql = " t.approved = '1'"; ! $cat_where = ''; } ! else { ! if ( !$this->auth_user[$cat_id]['auth_mod'] ) ! { ! $approved_sql = " t.approved = " . $approve; ! } ! $cat_where = !empty($approved_sql) ? "AND t.article_category_id = $cat_id" : " t.article_category_id = $cat_id"; } + $order_sql = ''; if ( defined( 'IN_ADMIN' ) ) { ! $order_sql = " ORDER BY t.article_id"; } else { ! $order_sql = " ORDER BY " . $this->sort_method_extra . $this->sort_method . " " . $this->sort_order; } ! ! switch ( SQL_LAYER ) { ! case 'oracle': ! $sql = "SELECT t.*, t.article_id, r.votes_article, AVG(r.rate_point) AS rating, COUNT(r.votes_article) AS total_votes, u.user_id, u.username, COUNT(c.comments_id) AS total_comments, cat.cat_allow_ratings, cat.cat_allow_comments ! FROM " . KB_ARTICLES_TABLE . " AS t, " . KB_VOTES_TABLE . " AS r, " . USERS_TABLE . " AS u, " . KB_COMMENTS_TABLE . " AS c, " . KB_CATEGORIES_TABLE . " AS cat ! WHERE t.article_id = r.votes_article(+) ! AND t.article_author_id = u.user_id(+) ! AND t.article_id = c.article_id(+) ! $approved_sql ! AND t.article_category_id = cat.category_id ! $cat_where ! GROUP BY t.article_id ! $order_sql"; ! break; ! ! default: ! $sql = "SELECT t.*, t.article_id, r.votes_article, AVG(r.rate_point) AS rating, COUNT(r.votes_article) AS total_votes, u.user_id, u.username, COUNT(c.comments_id) AS total_comments, cat.cat_allow_ratings, cat.cat_allow_comments ! FROM " . KB_ARTICLES_TABLE . " AS t ! LEFT JOIN " . KB_VOTES_TABLE . " AS r ON t.article_id = r.votes_article ! LEFT JOIN " . USERS_TABLE . " AS u ON t.article_author_id = u.user_id ! LEFT JOIN " . KB_COMMENTS_TABLE . " AS c ON t.article_id = c.article_id ! LEFT JOIN " . KB_CATEGORIES_TABLE . " AS cat ON t.article_category_id = cat.category_id ! WHERE $approved_sql ! $cat_where ! GROUP BY t.article_id ! $order_sql"; ! break; } ! if ( !( $result = $mx_kb_functions->sql_query_limit( $sql, $kb_config['pagination'], $start ) ) ) { ! mx_message_die( GENERAL_ERROR, 'Couldn\'t get file info for this category', '', __LINE__, __FILE__, $sql ); } ! $file_rowset = array(); ! $total_file = 0; ! while ( $row = $db->sql_fetchrow( $result ) ) { ! if ( $this->auth_user[$row['article_category_id']]['auth_view'] ) ! { ! $file_rowset[] = $row; ! } ! } ! ! $db->sql_freeresult( $result ); ! ! $where_sql = ( !empty( $cat_id ) ) ? "AND article_category_id = $cat_id" : ''; ! $sql = "SELECT COUNT(article_id) as total_articles ! FROM " . KB_ARTICLES_TABLE . " ! WHERE approved='1' ! $where_sql"; ! ! if ( !( $result = $db->sql_query( $sql ) ) ) ! { ! mx_message_die( GENERAL_ERROR, 'Couldn\'t get number of article', '', __LINE__, __FILE__, $sql ); ! } ! ! $row = $db->sql_fetchrow( $result ); ! $db->sql_freeresult( $result ); ! ! $total_file = $row['total_articles']; ! unset( $row ); ! ! // ! // Ratings ! // ! $pa_use_ratings = false; ! for ( $i = 0; $i < count( $file_rowset ); $i++ ) ! { ! if ( $this->ratings[$file_rowset[$i]['article_category_id']]['activated'] ) ! { ! $pa_use_ratings = true; ! break; ! } ! } ! ! for ( $i = 0; $i < count( $file_rowset ); $i++ ) ! { ! // =================================================== ! // Format the date for the given file ! // =================================================== ! $article_date = create_date( $board_config['default_dateformat'], $file_rowset[$i]['article_date'], $board_config['board_timezone'] ); ! // =================================================== ! // Get rating for the file and format it ! // =================================================== ! $rating_message = ( $file_rowset[$i]['rating'] != 0 ) ? round( $file_rowset[$i]['rating'], 2 ) . ' / 10' : $lang['Not_rated']; ! ! $cat_name = ( empty( $cat_id ) ) ? $this->cat_rowset[$file_rowset[$i]['file_catid']]['category_name'] : ''; ! $cat_url = append_sid( this_kb_mxurl( 'action=category&cat_id=' . $file_rowset[$i]['article_category_id'] ) ); ! ! $article_description = $file_rowset[$i]['article_description'] ; ! $article_cat_id = $file_rowset[$i]['article_category_id']; ! $article_approved = $file_rowset[$i]['approved']; ! ! // // type ! // ! $type_id = $file_rowset[$i]['article_type']; $article_type = $this->get_kb_type( $type_id ); ! // // author information ! // ! $author_id = $file_rowset[$i]['article_author_id']; ! if ( $author_id == -1 ) { ! $author = ( $file_rowset[$i]['username'] == '' ) ? $lang['Guest'] : $file_rowset[$i]['username']; } else *************** *** 761,768 **** } ! $article_id = $article['article_id']; ! $views = $article['views']; ! $article_title = $article['article_title']; $temp_url = append_sid( this_kb_mxurl( "mode=article&k=$article_id" ) ); $article = '<a href="' . $temp_url . '" class="gen">' . $article_title . '</a>'; --- 841,848 ---- } ! $article_id = $file_rowset[$i]['article_id']; ! $views = $file_rowset[$i]['views']; ! $article_title = $file_rowset[$i]['article_title']; $temp_url = append_sid( this_kb_mxurl( "mode=article&k=$article_id" ) ); $article = '<a href="' . $temp_url . '" class="gen">' . $article_title . '</a>'; *************** *** 770,776 **** $approve = ''; $delete = ''; - $category_name = ''; - $category = $this->cat_rowset[$article_cat]; - $category_name = $category['category_name']; if ( defined( 'IN_ADMIN' ) ) --- 850,853 ---- *************** *** 779,783 **** { // approve ! $temp_url = append_sid( $module_root_path . "admin/admin_kb_art.$phpEx?mode=approve&a=$article_id&cat=$article_cat" . "&start=" . $start); $approve = '<a href="' . $temp_url . '"><img src="' . $images['kb_icon_approve'] . '" border="0" alt="' . $lang['Approve'] . '"></a>'; } --- 856,860 ---- { // approve ! $temp_url = append_sid( $module_root_path . "admin/admin_kb_art.$phpEx?mode=approve&a=$article_id&cat=$article_cat_id" . "&start=" . $start); $approve = '<a href="' . $temp_url . '"><img src="' . $images['kb_icon_approve'] . '" border="0" alt="' . $lang['Approve'] . '"></a>'; } *************** *** 785,803 **** { // unapprove ! $temp_url = append_sid( $module_root_path . "admin/admin_kb_art.$phpEx?mode=unapprove&a=$article_id&cat=$article_cat" . "&start=" . $start); $approve = '<a href="' . $temp_url . '"><img src="' . $images['kb_icon_unapprove'] . '" border="0" alt="' . $lang['Un_approve'] . '"></a>'; } // delete ! $temp_url = append_sid( $module_root_path . "admin/admin_kb_art.$phpEx?mode=delete&a=$article_id&cat=$article_cat" . "&start=" . $start); $delete = '<a href="' . $temp_url . '"><img src="' . $images['kb_icon_delpost'] . '" border="0" alt="' . $lang['Delete'] . '"></a>'; } else { ! if ( $this->auth_user[$id]['auth_mod'] ) { if ( $article_approved == 2 || $article_approved == 0 ) { // approve ! $temp_url = append_sid( this_kb_mxurl( "mode=moderate&action=approve&a=$article_id&cat=$article_cat&page=$page_id" . "&start=" . $start) ); $approve = '<a href="' . $temp_url . '"><img src="' . $images['kb_icon_approve'] . '" border="0" alt="' . $lang['Approve'] . '"></a>'; } --- 862,880 ---- { // unapprove ! $temp_url = append_sid( $module_root_path . "admin/admin_kb_art.$phpEx?mode=unapprove&a=$article_id&cat=$article_cat_id" . "&start=" . $start); $approve = '<a href="' . $temp_url . '"><img src="' . $images['kb_icon_unapprove'] . '" border="0" alt="' . $lang['Un_approve'] . '"></a>'; } // delete ! $temp_url = append_sid( $module_root_path . "admin/admin_kb_art.$phpEx?mode=delete&a=$article_id&cat=$article_cat_id" . "&start=" . $start); $delete = '<a href="' . $temp_url . '"><img src="' . $images['kb_icon_delpost'] . '" border="0" alt="' . $lang['Delete'] . '"></a>'; } else { ! if ( $this->auth_user[$cat_id]['auth_mod'] ) { if ( $article_approved == 2 || $article_approved == 0 ) { // approve ! $temp_url = append_sid( this_kb_mxurl( "mode=moderate&action=approve&a=$article_id&cat=$article_cat_id&page=$page_id" . "&start=" . $start) ); $approve = '<a href="' . $temp_url . '"><img src="' . $images['kb_icon_approve'] . '" border="0" alt="' . $lang['Approve'] . '"></a>'; } *************** *** 805,934 **** { // unapprove ! $temp_url = append_sid( this_kb_mxurl( "mode=moderate&action=unapprove&a=$article_id&cat=$article_cat&page=$page_id" . "&start=" . $start) ); $approve = '<a href="' . $temp_url . '"><img src="' . $images['kb_icon_unapprove'] . '" border="0" alt="' . $lang['Un_approve'] . '"></a>'; } } ! if ( $this->auth_user[$id]['auth_delete'] || $this->auth_user[$id]['auth_mod']) { // delete ! $temp_url = append_sid( this_kb_mxurl( "mode=moderate&action=delete&a=$article_id&cat=$article_cat&page=$page_id" . "&start=" . $start) ); $delete = '<a href="' . $temp_url . '"><img src="' . $images['kb_icon_delpost'] . '" border="0" alt="' . $lang['Delete'] . '"></a>'; } } ! if ( $article['article_rating'] == 0 || $article['article_totalvotes'] == 0 ) ! { ! $rating = 0; ! $rating_votes = 0; ! $rating_message = ''; ! } ! else ! { ! $rating = round( $postrow[$i]['link_rating'] / $postrow[$i]['link_totalvotes'], 2 ); ! $rating_votes = $postrow[$i]['link_totalvotes']; ! $rating_message = '(' . $rating . '/10, </span><span class="gensmall">' . $rating_votes . ' votes)'; ! } ! $template->assign_block_vars( $block_name, array( 'ARTICLE' => $article , ! 'ARTICLE_DESCRIPTION' => $article_description, ! 'ARTICLE_TYPE' => $article_type, ! 'ARTICLE_DATE' => $article_date, ! 'ARTICLE_AUTHOR' => $author, ! 'CATEGORY' => $category_name, ! 'ART_VIEWS' => $views, ! 'ART_VOTES' => $rating_message, ! 'U_APPROVE' => $approve, ! 'U_DELETE' => $delete ) ! ); ! } // end loop ! if ( $i == 0 ) { $template->assign_block_vars( 'no_articles', array( 'COMMENT' => $lang['No_Articles'] ) ); } - - return $i; } /** ! * Get Stats. * - * @param unknown_type $type - * @param unknown_type $approve - * @param unknown_type $block_name * @param unknown_type $start ! * @param unknown_type $articles_in_cat */ ! function display_stats( $type = false, $approve, $block_name, $start = -1, $articles_in_cat = 0 ) { ! global $db, $template, $images, $phpEx, $module_root_path, $phpbb_root_path, $mx_root_path, $board_config, $lang, $is_block, $page_id, $is_admin, $userdata; ! ! $this->debug('mx_kb->display_stats', basename( __FILE__ )); ! $sql = "SELECT * FROM " . KB_ARTICLES_TABLE . " WHERE"; ! $sql .= " approved = " . $approve; if ( $type ) { if ( $type == 'toprated' ) { ! $sql .= " AND article_totalvotes > 0"; ! $sql .= " ORDER BY article_rating/article_totalvotes DESC"; ! }elseif ( $type == 'latest' ) { ! $sql .= " ORDER BY article_date DESC"; ! }elseif ( $type == 'mostpopular' ) { ! $sql .= " AND views > 0"; ! $sql .= " ORDER BY views DESC"; } } ! if ( $start > -1 && $articles_in_cat > 0 ) { ! $sql .= " LIMIT $start, $articles_in_cat"; } ! if ( !( $article_result = $db->sql_query( $sql ) ) ) { ! mx_message_die( GENERAL_ERROR, "Could not obtain article data", '', __LINE__, __FILE__, $sql ); } ! $i = 0; ! while ( $article = $db->sql_fetchrow( $article_result ) ) { ! if ( $i == $articles_in_cat ) { break; } ! $article_description = $article['article_description']; ! $article_cat = $article['article_category_id']; ! $article_approved = $article['approved']; // type ! $type_id = $article['article_type']; $article_type = $this->get_kb_type( $type_id ); ! $article_date = create_date( $board_config['default_dateformat'], $article['article_date'], $board_config['board_timezone'] ); // author information ! $author_id = $article['article_author_id']; if ( $author_id == -1 ) { ! $author = ( $article['username'] == '' ) ? $lang['Guest'] : $article['username']; } else { ! $author = $this->get_kb_author( $author_id ); $temp_url = append_sid( $phpbb_root_path . "profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=$author_id" ); ! $author = '<a href="' . $temp_url . '" class="gen">' . $author . '</a>'; } ! $article_id = $article['article_id']; ! $views = $article['views']; ! $article_title = $article['article_title']; $temp_url = append_sid( this_kb_mxurl( "mode=article&k=$article_id" ) ); $article = '<a href="' . $temp_url . '" class="gen">' . $article_title . '</a>'; --- 882,1099 ---- { // unapprove ! $temp_url = append_sid( this_kb_mxurl( "mode=moderate&action=unapprove&a=$article_id&cat=$article_cat_id&page=$page_id" . "&start=" . $start) ); $approve = '<a href="' . $temp_url . '"><img src="' . $images['kb_icon_unapprove'] . '" border="0" alt="' . $lang['Un_approve'] . '"></a>'; } } ! if ( $this->auth_user[$cat_id]['auth_delete'] || $this->auth_user[$cat_id]['auth_mod']) { // delete ! $temp_url = append_sid( this_kb_mxurl( "mode=moderate&action=delete&a=$article_id&cat=$article_cat_id&page=$page_id" . "&start=" . $start) ); $delete = '<a href="' . $temp_url . '"><img src="' . $images['kb_icon_delpost'] . '" border="0" alt="' . $lang['Delete'] . '"></a>'; } } ! // =================================================== ! // Assign Vars ! // =================================================== ! $template->assign_block_vars( $block_name, array( ! 'ARTICLE' => $article , ! 'ARTICLE_DESCRIPTION' => $article_description, ! 'ARTICLE_TYPE' => $article_type, ! 'ARTICLE_DATE' => $article_date, ! 'ARTICLE_AUTHOR' => $author, ! 'CATEGORY' => $cat_name, ! 'ART_VIEWS' => $views, ! 'ART_VOTES' => $rating_message, ! 'U_APPROVE' => $approve, ! 'U_DELETE' => $delete ) ! ); ! $filelist = true; ! $pa_use_ratings = $this->ratings[$file_rowset[$i]['file_catid']]['activated']; ! } ! ! if ( !$filelist ) { $template->assign_block_vars( 'no_articles', array( 'COMMENT' => $lang['No_Articles'] ) ); } } /** ! * Enter description here... * * @param unknown_type $start ! * @param unknown_type $cat_id */ ! function display_stats( $start, $type = false, $cat_id = false, $block_name = 'articlerow', $approve = '1' ) { ! global $db, $kb_config, $template, $board_config; ! global $images, $lang, $phpEx, $mx_kb_functions; ! global $phpbb_root_path, $mx_root_path, $module_root_path, $is_block, $phpEx; ! $filelist = false; ! $approved_sql = ''; ! if ( empty( $cat_id ) ) ! { ! $approved_sql = " t.approved = '1'"; ! $cat_where = ''; ! } ! else ! { ! if ( !$this->auth_user[$cat_id]['auth_mod'] ) ! { ! $approved_sql = " t.approved = " . $approve; ! } ! $cat_where = !empty($approved_sql) ? "AND t.article_category_id = $cat_id" : " t.article_category_id = $cat_id"; ! } + $order_sql = ''; if ( $type ) { if ( $type == 'toprated' ) { ! $order_sql = " ORDER BY rating DESC "; ! } ! elseif ( $type == 'latest' ) { ! $order_sql = " ORDER BY article_date DESC "; ! } ! elseif ( $type == 'mostpopular' ) { ! $order_xtra = !empty($cat_where) || !empty($approved_sql)? " AND views > 0" : " views > 0 "; ! $order_sql = " ORDER BY views DESC "; } } + else + { ! } ! ! switch ( SQL_LAYER ) { ! case 'oracle': ! $sql = "SELECT t.*, t.article_id, r.votes_article, AVG(r.rate_point) AS rating, COUNT(r.votes_article) AS total_votes, u.user_id, u.username, COUNT(c.comments_id) AS total_comments, cat.cat_allow_ratings, cat.cat_allow_comments ! FROM " . KB_ARTICLES_TABLE . " AS t, " . KB_VOTES_TABLE . " AS r, " . USERS_TABLE . " AS u, " . KB_COMMENTS_TABLE . " AS c, " . KB_CATEGORIES_TABLE . " AS cat ! WHERE t.article_id = r.votes_article(+) ! AND t.article_author_id = u.user_id(+) ! AND t.article_id = c.article_id(+) ! AND t.article_category_id = cat.category_id ! $approved_sql ! $cat_where ! $order_xtra ! GROUP BY t.article_id ! $order_sql"; ! break; ! ! default: ! $sql = "SELECT t.*, t.article_id, r.votes_article, AVG(r.rate_point) AS rating, COUNT(r.votes_article) AS total_votes, u.user_id, u.username, COUNT(c.comments_id) AS total_comments, cat.cat_allow_ratings, cat.cat_allow_comments ! FROM " . KB_ARTICLES_TABLE . " AS t ! LEFT JOIN " . KB_VOTES_TABLE . " AS r ON t.article_id = r.votes_article ! LEFT JOIN " . USERS_TABLE . " AS u ON t.article_author_id = u.user_id ! LEFT JOIN " . KB_COMMENTS_TABLE . " AS c ON t.article_id = c.article_id ! LEFT JOIN " . KB_CATEGORIES_TABLE . " AS cat ON t.article_category_id = cat.category_id ! WHERE $approved_sql ! $cat_where ! $order_xtra ! GROUP BY t.article_id ! $order_sql"; ! break; } ! if ( !( $result = $mx_kb_functions->sql_query_limit( $sql, $kb_config['pagination'], $start ) ) ) { ! mx_message_die( GENERAL_ERROR, 'Couldn\'t get file info for this category', '', __LINE__, __FILE__, $sql ); } ! $file_rowset = array(); ! $total_file = 0; ! while ( $row = $db->sql_fetchrow( $result ) ) { ! if ( $this->auth_user[$row['article_category_id']]['auth_view'] ) ! { ! $file_rowset[] = $row; ! } ! } ! ! $db->sql_freeresult( $result ); ! ! $where_sql = ( !empty( $cat_id ) ) ? "AND article_category_id = $cat_id" : ''; ! $sql = "SELECT COUNT(article_id) as total_articles ! FROM " . KB_ARTICLES_TABLE . " ! WHERE approved='1' ! $where_sql"; ! ! if ( !( $result = $db->sql_query( $sql ) ) ) ! { ! mx_message_die( GENERAL_ERROR, 'Couldn\'t get number of article', '', __LINE__, __FILE__, $sql ); ! } ! ! $row = $db->sql_fetchrow( $result ); ! $db->sql_freeresult( $result ); ! ! $total_file = $row['total_articles']; ! unset( $row ); ! ! // ! // Ratings ! // ! $pa_use_ratings = false; ! for ( $i = 0; $i < count( $file_rowset ); $i++ ) ! { ! if ( $this->ratings[$file_rowset[$i]['article_category_id']]['activated'] ) { + $pa_use_ratings = true; break; } + } ! for ( $i = 0; $i < count( $file_rowset ); $i++ ) ! { ! // =================================================== ! // Format the date for the given file ! // =================================================== ! $article_date = create_date( $board_config['default_dateformat'], $file_rowset[$i]['article_date'], $board_config['board_timezone'] ); ! // =================================================== ! // Get rating for the file and format it ! // =================================================== ! $rating_message = ( $file_rowset[$i]['rating'] != 0 ) ? round( $file_rowset[$i]['rating'], 2 ) . ' / 10' : $lang['Not_rated']; ! ! $cat_name = ( empty( $cat_id ) ) ? $this->cat_rowset[$file_rowset[$i]['file_catid']]['category_name'] : ''; ! $cat_url = append_sid( this_kb_mxurl( 'action=category&cat_id=' . $file_rowset[$i]['article_category_id'] ) ); ! ! $article_description = $file_rowset[$i]['article_description'] ; ! $article_cat_id = $file_rowset[$i]['article_category_id']; ! $article_approved = $file_rowset[$i]['approved']; ! ! // // type ! // ! $type_id = $file_rowset[$i]['article_type']; $article_type = $this->get_kb_type( $type_id ); ! // // author information ! // ! $author_id = $file_rowset[$i]['article_author_id']; ! if ( $author_id == -1 ) { ! $author = ( $file_rowset[$i]['username'] == '' ) ? $lang['Guest'] : $file_rowset[$i]['username']; } else { ! $author_name = $this->get_kb_author( $author_id ); $temp_url = append_sid( $phpbb_root_path . "profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=$author_id" ); ! $author = '<a href="' . $temp_url . '" class="gen">' . $author_name . '</a>'; } ! $article_id = $file_rowset[$i]['article_id']; ! $views = $file_rowset[$i]['views']; ! $article_title = $file_rowset[$i]['article_title']; $temp_url = append_sid( this_kb_mxurl( "mode=article&k=$article_id" ) ); $article = '<a href="' . $temp_url . '" class="gen">' . $article_title . '</a>'; *************** *** 936,958 **** $approve = ''; $delete = ''; - $category_name = ''; ! //$category = $this->get_kb_cat( $article_cat ); ! $category = $this->cat_rowset[$article_cat]; ! $category_id = $category['category_id']; ! $category_name = $category['category_name']; ! $category_temp = append_sid( this_kb_mxurl( "mode=cat&cat=$category_id" ) ); ! $category_url = '<a href="' . $category_temp . '" class="genmed">' . $category_name . '</a>'; ! ! if ( defined( 'IN_ADMIN' ) || $userdata['user_level'] == ADMIN ) { - //$category = $this->get_kb_cat( $article_cat ); - $category = $this->cat_rowset[$article_cat]; - $category_name = $category['category_name']; - if ( $article_approved == 2 || $article_approved == 0 ) { // approve ! $temp_url = append_sid( $module_root_path . "admin/admin_kb_art.$phpEx?mode=approve&a=$article_id" ); $approve = '<a href="' . $temp_url . '"><img src="' . $images['kb_icon_approve'] . '" border="0" alt="' . $lang['Approve'] . '"></a>'; } --- 1101,1111 ---- $approve = ''; $delete = ''; ! if ( defined( 'IN_ADMIN' ) ) { if ( $article_approved == 2 || $article_approved == 0 ) { // approve ! $temp_url = append_sid( $module_root_path . "admin/admin_kb_art.$phpEx?mode=approve&a=$article_id&cat=$article_cat_id" . "&start=" . $start); $approve = '<a href="' . $temp_url . '"><img src="' . $images['kb_icon_approve'] . '" border="0" alt="' . $lang['Approve'] . '"></a>'; } *************** *** 960,1006 **** { // unapprove ! $temp_url = append_sid( $module_root_path . "admin/admin_kb_art.$phpEx?mode=unapprove&a=$article_id" ); $approve = '<a href="' . $temp_url . '"><img src="' . $images['kb_icon_unapprove'] . '" border="0" alt="' . $lang['Un_approve'] . '"></a>'; } // delete ! $temp_url = append_sid( $module_root_path . "admin/admin_kb_art.$phpEx?mode=delete&a=$article_id" ); $delete = '<a href="' . $temp_url . '"><img src="' . $images['kb_icon_delpost'] . '" border="0" alt="' . $lang['Delete'] . '"></a>'; } - - if ( $article['article_rating'] == 0 || $article['article_totalvotes'] == 0 ) - { - $rating = 0; - $rating_votes = 0; - $rating_message = ''; - } else { ! $rating = round( $postrow[$i]['link_rating'] / $postrow[$i]['link_totalvotes'], 2 ); ! $rating_votes = $postrow[$i]['link_totalvotes']; ! $rating_message = '(' . $rating . '/10, </span><span class="gensmall">' . $rating_votes . ' votes)'; } ! if ( $this->ns_auth_cat( $article_cat ) && $this->auth_user[$article_cat]['auth_view'] ) ! { ! $i++; ! $template->assign_block_vars( $block_name, array( 'ARTICLE' => $article , ! 'ARTICLE_DESCRIPTION' => $article_description, ! 'ARTICLE_TYPE' => $article_type, ! 'ARTICLE_DATE' => $article_date, ! 'ARTICLE_AUTHOR' => $author, ! 'CATEGORY' => $category_url, ! 'ART_VIEWS' => $views, ! 'ART_VOTES' => $rating_message, ! 'U_APPROVE' => $approve, ! 'U_DELETE' => $delete ) ! ); ! } } ! if ( $i == 0 ) { $template->assign_block_vars( 'no_articles', array( 'COMMENT' => $lang['No_Articles'] ) ); } - } --- 1113,1173 ---- { // unapprove ! $temp_url = append_sid( $module_root_path . "admin/admin_kb_art.$phpEx?mode=unapprove&a=$article_id&cat=$article_cat_id" . "&start=" . $start); $approve = '<a href="' . $temp_url . '"><img src="' . $images['kb_icon_unapprove'] . '" border="0" alt="' . $lang['Un_approve'] . '"></a>'; } // delete ! $temp_url = append_sid( $module_root_path . "admin/admin_kb_art.$phpEx?mode=delete&a=$article_id&cat=$article_cat_id" . "&start=" . $start); $delete = '<a href="' . $temp_url . '"><img src="' . $images['kb_icon_delpost'] . '" border="0" alt="' . $lang['Delete'] . '"></a>'; } else { ! if ( $this->auth_user[$cat_id]['auth_mod'] ) ! { ! if ( $article_approved == 2 || $article_approved == 0 ) ! { ! // approve ! $temp_url = append_sid( this_kb_mxurl( "mode=moderate&action=approve&a=$article_id&cat=$article_cat_id&page=$page_id" . "&start=" . $start) ); ! $approve = '<a href="' . $temp_url . '"><img src="' . $images['kb_icon_approve'] . '" border="0" alt="' . $lang['Approve'] . '"></a>'; ! } ! elseif ( $article_approved == 1 ) ! { ! // unapprove ! $temp_url = append_sid( this_kb_mxurl( "mode=moderate&action=unapprove&a=$article_id&cat=$article_cat_id&page=$page_id" . "&start=" . $start) ); ! $approve = '<a href="' . $temp_url . '"><img src="' . $images['kb_icon_unapprove'] . '" border="0" alt="' . $lang['Un_approve'] . '"></a>'; ! } ! } ! if ( $this->auth_user[$cat_id]['auth_delete'] || $this->auth_user[$cat_id]['auth_mod']) ! { ! // delete ! $temp_url = append_sid( this_kb_mxurl( "mode=moderate&action=delete&a=$article_id&cat=$article_cat_id&page=$page_id" . "&start=" . $start) ); ! $delete = '<a href="' . $temp_url . '"><img src="' . $images['kb_icon_delpost'] . '" border="0" alt="' . $lang['Delete'] . '"></a>'; ! } } ! // =================================================== ! // Assign Vars ! // =================================================== ! $template->assign_block_vars( $block_name, array( ! 'ARTICLE' => $article , ! 'ARTICLE_DESCRIPTION' => $article_description, ! 'ARTICLE_TYPE' => $article_type, ! 'ARTICLE_DATE' => $article_date, ! 'ARTICLE_AUTHOR' => $author, ! 'CATEGORY' => $cat_name, ! 'ART_VIEWS' => $views, ! 'ART_VOTES' => $rating_message, ! 'U_APPROVE' => $approve, ! 'U_DELETE' => $delete ) ! ); ! ! $filelist = true; ! $pa_use_ratings = $this->ratings[$file_rowset[$i]['file_catid']]['activated']; } ! ! if ( !$filelist ) { $template->assign_block_vars( 'no_articles', array( 'COMMENT' => $lang['No_Articles'] ) ); } } |