|
From: Jon O. <jon...@us...> - 2006-06-28 20:52:36
|
Update of /cvsroot/mxbb/mx_kb/kb/includes In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv11223/modules/mx_kb/kb/includes Modified Files: kb_constants.php kb_pages.php Log Message: Fixes for new last_article block new redirect class for direct links Index: kb_pages.php =================================================================== RCS file: /cvsroot/mxbb/mx_kb/kb/includes/kb_pages.php,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** kb_pages.php 7 Jun 2006 20:28:54 -0000 1.3 --- kb_pages.php 28 Jun 2006 20:52:30 -0000 1.4 *************** *** 14,156 **** } ! if ( MXBB_27x ) { ! $page_id = get_page_id( 'kb_article_reader.php', true ); ! if ( !$page_id ) ! { ! $page_id = get_page_id( 'kb.php', true ); ! } ! if ( !empty( $page_id ) ) ! { ! $kb_pages = $page_id; ! $kb_error = false; ! } ! else ! { ! $kb_error = true; ! } ! // ! // Start initial var setup ! // ! $cat_id = $article_id = ''; ! if ( isset( $HTTP_GET_VARS['cat'] ) || isset( $HTTP_POST_VARS['cat'] ) ) ! { ! $cat_id = ( isset( $HTTP_GET_VARS['cat'] ) ) ? intval( $HTTP_GET_VARS['cat'] ) : intval( $HTTP_POST_VARS['cat'] ); ! } ! else if ( isset( $HTTP_GET_VARS['k'] ) || isset( $HTTP_POST_VARS['k'] ) ) ! { ! $article_id = ( isset( $HTTP_GET_VARS['k'] ) ) ? intval( $HTTP_GET_VARS['k'] ) : intval( $HTTP_POST_VARS['k'] ); ! } ! } ! else ! { ! // ! // Note: This piece of code snippet is somewhat ugly and needs cleaning up...still it works... ! // What it does? ! // Well if given a direct kb article link, it finds on what portal page the kb block is located. ! // Since we can have different kb blocks on different portal pages displaying different kb categories/articles, this check is needed ;) ! // Oh, do not blame markus for this code ;) ! // ! if ( empty( $_SESSION['kb_setup'] ) ) { ! $news_setup = array(); ! $sql = "SELECT col.page_id, blk.block_id, sys.parameter_value, fnc.function_file ! FROM " . COLUMN_BLOCK_TABLE . " bct, ! " . COLUMN_TABLE . " col, ! " . BLOCK_TABLE . " blk, ! " . BLOCK_SYSTEM_PARAMETER_TABLE . " sys, ! " . FUNCTION_TABLE . " fnc, ! " . PARAMETER_TABLE . " par ! WHERE col.column_id = bct.column_id ! AND blk.function_id = fnc.function_id ! AND par.function_id = fnc.function_id ! AND blk.block_id = bct.block_id ! AND blk.block_id = sys.block_id ! AND par.parameter_name = 'kb_type_select' ! ORDER BY page_id, block_id"; ! if ( !$kb_result = $db->sql_query( $sql ) ) ! { ! mx_message_die( GENERAL_ERROR, "Could not query modules information", "", __LINE__, __FILE__, $sql ); ! } ! while ( $kb_rows = $db->sql_fetchrow( $kb_result ) ) { ! $page_id = $kb_rows['page_id']; ! $block_id = $kb_rows['block_id']; ! $kb_select_par = $kb_rows['parameter_value']; ! // Extract 'what posts to view info', the cool Array ;) ! $kb_type_select_data = ( !empty( $kb_select_par ) ) ? unserialize($kb_select_par) : array(); ! $kb_config['news_mode_operate'] = true; ! if ( is_array($kb_type_select_data) ) { ! $news_setup[$page_id] = $kb_type_select_data; ! $news_mode[$page_id] = $kb_rows['function_file']; } ! } ! $page_to_kb = array(); ! while ( list( $page_idd, $news_setup_roww ) = each( $news_setup ) ) ! { ! while ( list( $cat_idd, $news_forum_roww ) = each( $news_setup_roww ) ) { ! if ( $news_forum_roww['forum_news'] == 1 ) ! { ! $page_to_kb[$cat_idd] = ( empty( $page_to_kb[$cat_idd] ) || $news_mode[$page_idd] == 'kb_article_reader.php' ) ? $page_idd : $page_to_kb[$cat_idd]; ! } } ! } ! $_SESSION['kb_setup'] = $page_to_kb; ! } ! // ! // Start initial var setup ! // ! $cat_id = $article_id = $sql = ''; ! if ( isset( $HTTP_GET_VARS['cat'] ) || isset( $HTTP_POST_VARS['cat'] ) ) ! { ! $cat_id = ( isset( $HTTP_GET_VARS['cat'] ) ) ? intval( $HTTP_GET_VARS['cat'] ) : intval( $HTTP_POST_VARS['cat'] ); ! } ! else if ( isset( $HTTP_GET_VARS['k'] ) || isset( $HTTP_POST_VARS['k'] ) ) ! { ! $article_id = ( isset( $HTTP_GET_VARS['k'] ) ) ? intval( $HTTP_GET_VARS['k'] ) : intval( $HTTP_POST_VARS['k'] ); ! $sql = "SELECT article_category_id ! FROM " . KB_ARTICLES_TABLE . " ! WHERE article_id = $article_id"; ! if ( !( $result = $db->sql_query( $sql ) ) ) ! { ! mx_message_die( GENERAL_ERROR, "no info - error", '', __LINE__, __FILE__, $sql ); ! } ! if ( !( $row = $db->sql_fetchrow( $result ) ) ) ! { ! //mx_message_die( GENERAL_MESSAGE, 'article_not_exist' ); ! } ! $cat_id = $row['article_category_id']; ! } ! if ( !empty($cat_id) ) ! { ! $kb_pages = $_SESSION['kb_setup'][$cat_id]; ! $kb_error = false; ! } ! else ! { ! $kb_error = true; } } --- 14,176 ---- } ! class kb_pages { ! var $target_file = 'kb.php'; ! var $phpbb_block_map = array(); ! var $cache_key = '_pagemap_kb'; ! var $get_cat = 'cat'; ! var $get_item = 'k'; ! var $cat_id = 0; ! var $item_id = 0; ! var $page_id = ''; // To be used externally (return) ! var $error = false; // To be used externally (return) ! function init($target_file) { ! global $db, $mx_cache, $mx_root_path, $module_root_path, $phpEx, $mx_table_prefix; ! // ! // Includes ! // ! include_once( $mx_root_path . $module_root_path . 'kb/includes/kb_constants.' . $phpEx ); ! // ! // General init ! // ! $this->target_file = $target_file; ! $this->page_id = ''; ! $this->phpbb_block_map = array(); ! $this->cache_key = '_pagemap_kb_' . $this->target_file; ! if ( MXBB_27x ) { ! // ! // Simple usage, for old mxBB versions ! // ! $this->page_id = get_page_id( $this->target_file, true ); ! if ( !$this->page_id ) ! { ! $this->page_id = get_page_id( 'kb.php', true ); ! } ! $this->error = !$this->page_id ? true : false; ! // ! // Start initial var setup ! // ! $this->cat_id = $this->item_id = ''; + if ( isset( $_GET[$this->get_cat] ) || isset( $_POST[$this->get_cat] ) ) + { + $this->cat_id = ( isset( $_GET[$this->get_cat] ) ) ? intval( $_GET[$this->get_cat] ) : intval( $_POST[$this->get_cat] ); + } + else if ( isset( $_GET[$this->get_item] ) || isset( $_POST[$this->get_item] ) ) + { + $this->item_id = ( isset( $_GET[$this->get_item] ) ) ? intval( $_GET[$this->get_item] ) : intval( $_POST[$this->get_item] ); + } + } + else + { + // + // Note: This piece of code snippet is somewhat ugly and needs cleaning up...still it works... + // What it does? + // Well if given a direct kb article link, it finds on what portal page the kb block is located. + // Since we can have different kb blocks on different portal pages displaying different kb categories/articles, this check is needed ;) + // ! // ! // Try to reuse results. ! // ! if ( $mx_cache->_exists( $this->cache_key ) ) ! { ! $this->phpbb_block_map = unserialize( $mx_cache->get( $this->cache_key ) ); ! } ! else ! { ! // ! // Query to find all mappings between article categories and portal pages ! // ! $sql = "SELECT col.page_id, blk.block_id, sys.parameter_value, fnc.function_file ! FROM " . COLUMN_BLOCK_TABLE . " bct, ! " . COLUMN_TABLE . " col, ! " . BLOCK_TABLE . " blk, ! " . BLOCK_SYSTEM_PARAMETER_TABLE . " sys, ! " . FUNCTION_TABLE . " fnc, ! " . PARAMETER_TABLE . " par ! WHERE col.column_id = bct.column_id ! AND blk.function_id = fnc.function_id ! AND par.function_id = fnc.function_id ! AND blk.block_id = bct.block_id ! AND blk.block_id = sys.block_id ! AND par.parameter_type = 'kb_type_select' ! AND fnc.function_file = '".$this->target_file."' ! ORDER BY page_id, block_id"; ! if ( !$phpbb_result = $db->sql_query( $sql ) ) ! { ! mx_message_die( GENERAL_ERROR, "Could not query modules information", "", __LINE__, __FILE__, $sql ); ! } ! ! while ( $phpbb_rows = $db->sql_fetchrow( $phpbb_result ) ) ! { ! $phpbb_type_select_data = ( !empty( $phpbb_rows['parameter_value'] ) ) ? unserialize($phpbb_rows['parameter_value']) : array(); ! ! if (is_array($phpbb_type_select_data)) { ! foreach ($phpbb_type_select_data as $forum_id => $value) ! { ! if ($value == 1) ! { ! $this->phpbb_block_map[$forum_id] = $phpbb_rows['page_id']; ! } ! } } + } + $db->sql_freeresult($result); ! $mx_cache->put( $this->cache_key, serialize($this->phpbb_block_map) ); ! } ! // ! // Start initial var setup ! // ! $this->cat_id = $this->item_id = $sql = ''; ! if ( isset( $_GET[$this->get_cat] ) || isset( $_POST[$this->get_cat] ) ) { ! $this->cat_id = ( isset( $_GET[$this->get_cat] ) ) ? intval( $_GET[$this->get_cat] ) : intval( $_POST[$this->get_cat] ); } + else if ( isset( $_GET[$this->get_item] ) || isset( $_POST[$this->get_item] ) ) + { + $this->item_id = ( isset( $_GET[$this->get_item] ) ) ? intval( $_GET[$this->get_item] ) : intval( $_POST[$this->get_item] ); ! $sql = "SELECT article_category_id ! FROM " . KB_ARTICLES_TABLE . " ! WHERE article_id = $this->item_id"; ! if ( !( $result = $db->sql_query( $sql ) ) ) ! { ! mx_message_die( GENERAL_ERROR, "no info - error", '', __LINE__, __FILE__, $sql ); ! } ! $this->cat_id = $row['article_category_id']; ! } ! $this->page_id = $this->phpbb_block_map[$this->cat_id]; ! if (!$this->page_id) ! { ! $this->page_id = get_page_id( $this->target_file, true ); ! if ( !$this->page_id ) ! { ! $this->page_id = get_page_id( 'kb.php', true ); ! } ! } ! $this->error = !$this->page_id ? true : false; ! } } } Index: kb_constants.php =================================================================== RCS file: /cvsroot/mxbb/mx_kb/kb/includes/kb_constants.php,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** kb_constants.php 28 Jun 2006 13:58:08 -0000 1.6 --- kb_constants.php 28 Jun 2006 20:52:30 -0000 1.7 *************** *** 61,65 **** if ( !MXBB_MODULE || MXBB_27x ) { - echo('d'); $kb_module_version = "Knowledge Base MOD v. 2.0.x"; $kb_module_author = "Haplo/Jon"; --- 61,64 ---- *************** *** 68,72 **** else { - if (is_object($mx_page)) { --- 67,70 ---- |