|
From: Jon O. <jon...@us...> - 2005-12-13 20:04:38
|
Update of /cvsroot/mxbb/core/modules/mx_coreblocks In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8996/modules/mx_coreblocks Modified Files: mx_search.php mx_site_log.php Log Message: updated mxBB search block and utilities Index: mx_site_log.php =================================================================== RCS file: /cvsroot/mxbb/core/modules/mx_coreblocks/mx_site_log.php,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** mx_site_log.php 23 Oct 2005 18:48:21 -0000 1.5 --- mx_site_log.php 13 Dec 2005 20:04:27 -0000 1.6 *************** *** 25,28 **** --- 25,35 ---- // + // Block Info + // + // This block does 3 db queries to find latest standard, dynamic and sub block. Then it sorts the result arrays and display by offset. + // - not very efficient atm + // - to be optimized + + // // Read Block Settings // *************** *** 34,39 **** $template->set_filenames( array( "sitelog" => "mx_site_log.tpl" ) ); // Read block Configuration ! $log_numberOfEvents = $mx_block->get_parameters( 'numOfEvents' ) > 0 ? intval( $mx_block->get_parameters( 'numOfEvents' ) ) : '5'; $log_filter_time = $mx_block->get_parameters( 'log_filter_date' ); // no limit, last day, 2 days, 3 days, week, 2 weeks, 3 weeks, month, 2 months, 3 months, 6 months, i year, --- 41,47 ---- $template->set_filenames( array( "sitelog" => "mx_site_log.tpl" ) ); + // // Read block Configuration ! // $log_numberOfEvents = $mx_block->get_parameters( 'numOfEvents' ) > 0 ? intval( $mx_block->get_parameters( 'numOfEvents' ) ) : '5'; $log_filter_time = $mx_block->get_parameters( 'log_filter_date' ); // no limit, last day, 2 days, 3 days, week, 2 weeks, 3 weeks, month, 2 months, 3 months, 6 months, i year, *************** *** 55,62 **** $searchset = ''; - while ( $page_row = $db->sql_fetchrow( $result )) { // Page auth $page_auth_ary = array(); $page_auth_ary = page_auth( AUTH_VIEW, $userdata, $page_row['auth_view'], $page_row['auth_view_group'] ); --- 63,71 ---- $searchset = ''; while ( $page_row = $db->sql_fetchrow( $result )) { + // // Page auth + // $page_auth_ary = array(); $page_auth_ary = page_auth( AUTH_VIEW, $userdata, $page_row['auth_view'], $page_row['auth_view_group'] ); *************** *** 115,141 **** } // Generate page_blocks data // Find all Block Page_ids $sql = "SELECT pag.page_id, pag.page_name, pag.page_desc, blk.block_id, blk.block_title, blk.block_time, blk.block_editor_id FROM " . COLUMN_BLOCK_TABLE . " bct, ! " . PAGE_TABLE . " pag, ! " . COLUMN_TABLE . " col, ! " . BLOCK_TABLE . " blk WHERE pag.page_id = col.page_id ! AND bct.column_id = col.column_id ! ! AND bct.block_id = blk.block_id ! ! AND blk.show_stats = '1' ! AND blk.block_time <> '' ! AND blk.block_editor_id > 0 ! AND col.page_id IN ($valid_page_ids)"; if ( $log_time_filter_lo != 'no' && !empty($log_time_filter_lo) ) ! { ! $sql .= " AND blk.block_time > " . $log_time_filter_lo ; ! } if ( !$result = $db->sql_query( $sql ) ) --- 124,152 ---- } + // // Generate page_blocks data + // + // // Find all Block Page_ids + // $sql = "SELECT pag.page_id, pag.page_name, pag.page_desc, blk.block_id, blk.block_title, blk.block_time, blk.block_editor_id FROM " . COLUMN_BLOCK_TABLE . " bct, ! " . PAGE_TABLE . " pag, ! " . COLUMN_TABLE . " col, ! " . BLOCK_TABLE . " blk WHERE pag.page_id = col.page_id ! AND bct.column_id = col.column_id ! AND bct.block_id = blk.block_id ! AND blk.show_stats = '1' ! AND blk.block_time <> '' ! AND blk.block_editor_id > 0 ! AND col.page_id IN ($valid_page_ids)"; if ( $log_time_filter_lo != 'no' && !empty($log_time_filter_lo) ) ! { ! $sql .= " AND blk.block_time > " . $log_time_filter_lo ; ! } if ( !$result = $db->sql_query( $sql ) ) *************** *** 144,162 **** } ! $postrow_blocks = $db->sql_fetchrowset( $result ); ! //echo(var_export($postrow_blocks) . '<br>'. '<br>'); // Find all dynamic block Page_ids $sql = "SELECT pag.page_id, pag.page_name, pag.page_desc, blk.block_id, blk.block_title, blk.block_time, blk.block_editor_id, nav.menu_name ! FROM " . PAGE_TABLE . " pag, " . BLOCK_TABLE . " blk, " . MENU_NAV_TABLE . " nav, " . MENU_CAT_TABLE . " nac ! ! WHERE pag.page_id = nav.page_id ! AND nac.cat_id = nav.cat_id AND nav.block_id = blk.block_id - AND blk.show_stats = '1' AND blk.block_time <> '' --- 155,175 ---- } ! $postrow_blocks = array(); ! if( $total_rows = $db->sql_numrows($result) ) ! { ! $postrow_blocks = $db->sql_fetchrowset( $result ); ! } + // // Find all dynamic block Page_ids + // $sql = "SELECT pag.page_id, pag.page_name, pag.page_desc, blk.block_id, blk.block_title, blk.block_time, blk.block_editor_id, nav.menu_name ! FROM " . PAGE_TABLE . " pag, " . BLOCK_TABLE . " blk, " . MENU_NAV_TABLE . " nav, " . MENU_CAT_TABLE . " nac ! WHERE pag.page_id = nav.page_id AND nac.cat_id = nav.cat_id AND nav.block_id = blk.block_id AND blk.show_stats = '1' AND blk.block_time <> '' *************** *** 165,171 **** if ( $log_time_filter_lo != 'no' && !empty($log_time_filter_lo) ) ! { ! $sql .= " AND blk.block_time > " . $log_time_filter_lo ; ! } if ( !$result = $db->sql_query( $sql ) ) --- 178,184 ---- if ( $log_time_filter_lo != 'no' && !empty($log_time_filter_lo) ) ! { ! $sql .= " AND blk.block_time > " . $log_time_filter_lo ; ! } if ( !$result = $db->sql_query( $sql ) ) *************** *** 174,187 **** } ! $postrow_dynamic = $db->sql_fetchrowset( $result ); ! //echo(var_export($postrow_dynamic) . '<br>'. '<br>'); ! // Merge common and dynamic blocks ! $postrow = array_merge($postrow_blocks, $postrow_dynamic); ! //echo(var_export($postrow) . '<br>'. '<br>'); // Sort by block_time ! $postrow = qsort_multiarray($postrow, $num = 'block_time', $order = "DESC", $left = 0, $right = -1); ! //echo(var_export($postrow) . '<br>'. '<br>'); $dynamic_ids = ''; --- 187,241 ---- } ! $postrow_dynamic = array(); ! if( $total_rows = $db->sql_numrows($result) ) ! { ! $postrow_dynamic = $db->sql_fetchrowset( $result ); ! } ! // ! // Find all subblock page_ids ! // ! $sql = "SELECT pag.page_id, pag.page_name, pag.page_desc, blk.block_id, blk.block_title, blk.block_time, blk.block_editor_id ! FROM " . COLUMN_BLOCK_TABLE . " bct, ! " . PAGE_TABLE . " pag, ! " . COLUMN_TABLE . " col, ! " . BLOCK_TABLE . " blk, ! " . BLOCK_SYSTEM_PARAMETER_TABLE . " sys, ! " . PARAMETER_TABLE . " par ! WHERE pag.page_id = col.page_id ! AND bct.column_id = col.column_id ! AND bct.block_id = sys.block_id ! AND sys.parameter_id = par.parameter_id ! AND par.parameter_name = 'block_ids' ! AND blk.show_stats = '1' ! AND blk.block_time <> '' ! AND blk.block_editor_id > 0 ! AND col.page_id IN ($valid_page_ids)"; ! ! if ( $log_time_filter_lo != 'no' && !empty($log_time_filter_lo) ) ! { ! $sql .= " AND blk.block_time > " . $log_time_filter_lo ; ! } ! ! if ( !$result = $db->sql_query( $sql ) ) ! { ! mx_message_die( GENERAL_ERROR, 'Could not obtain search results', '', __LINE__, __FILE__, $sql ); ! } ! ! $postrow_sub = array(); ! if( $total_rows = $db->sql_numrows($result) ) ! { ! $postrow_sub = $db->sql_fetchrowset( $result ); ! } + // + // Merge common, dynamic and sub blocks + // + $postrow = array_merge($postrow_blocks, $postrow_dynamic, $postrow_sub); + + // // Sort by block_time ! // ! $postrow = qsort_multiarray($postrow, 'block_time', "DESC"); $dynamic_ids = ''; *************** *** 194,210 **** $log_total_match_count = intval( count( $postrow ) ); $base_url = mx_this_url(); $template->assign_vars( array( ! 'L_TITLE' => ( !empty( $title ) ? $title : 'Last Message' ), ! 'BLOCK_SIZE' => $block_size, ! 'U_URL_NEXT' => $url_next, ! 'U_URL_PREV' => $url_prev, ! 'U_PHPBB_ROOT_PATH' => PHPBB_URL, ! 'U_PORTAL_ROOT_PATH' => PORTAL_URL, ! 'TEMPLATE_ROOT_PATH' => TEMPLATE_ROOT_PATH, ! 'L_MSG_PREV' => $lang['Previous'], ! 'L_MSG_NEXT' => $lang['Next'], ! 'PAGINATION' => mx_generate_pagination( $base_url, $log_total_match_count, $log_numberOfEvents, $log_start,true,true, true,false,'log_start' ), ! 'PAGE_NUMBER' => sprintf( $lang['Page_of'], ( floor( $log_start / $log_numberOfEvents ) + 1 ), ceil( $log_total_match_count / $log_numberOfEvents ) ) ! ) ); if ( $log_total_match_count == 0 || $log_total_match_count == '') --- 248,265 ---- $log_total_match_count = intval( count( $postrow ) ); $base_url = mx_this_url(); + $template->assign_vars( array( ! 'L_TITLE' => ( !empty( $title ) ? $title : 'Last Message' ), ! 'BLOCK_SIZE' => $block_size, ! 'U_URL_NEXT' => $url_next, ! 'U_URL_PREV' => $url_prev, ! 'U_PHPBB_ROOT_PATH' => PHPBB_URL, ! 'U_PORTAL_ROOT_PATH' => PORTAL_URL, ! 'TEMPLATE_ROOT_PATH' => TEMPLATE_ROOT_PATH, ! 'L_MSG_PREV' => $lang['Previous'], ! 'L_MSG_NEXT' => $lang['Next'], ! 'PAGINATION' => mx_generate_pagination( $base_url, $log_total_match_count, $log_numberOfEvents, $log_start,true,true, true,false,'log_start' ), ! 'PAGE_NUMBER' => sprintf( $lang['Page_of'], ( floor( $log_start / $log_numberOfEvents ) + 1 ), ceil( $log_total_match_count / $log_numberOfEvents ) ) ! )); if ( $log_total_match_count == 0 || $log_total_match_count == '') *************** *** 212,217 **** $template->assign_block_vars("no_row", array( 'L_NO_ITEMS' => $lang['No_items_found'] ! ) ! ); } --- 267,271 ---- $template->assign_block_vars("no_row", array( 'L_NO_ITEMS' => $lang['No_items_found'] ! )); } *************** *** 245,265 **** $edit_time = create_date( $board_config['default_dateformat'], $postrow[$row_count]['block_time'], $board_config['board_timezone'] ); - - $template->assign_block_vars("msg_row", array( ! 'L_BLOCK_UPDATED' => $lang['Block_updated_by'], ! "ROW_COLOR" => "#" . $row_color, ! "ROW_CLASS" => $row_class, ! "EDIT_TIME" => $edit_time, ! "LAST_PAGE" => $sitelog_page, ! "LAST_BLOCK" => $sitelog_block, ! "EXTRA" => $x_title, ! "U_PAGE" => $sitelog_page_url, ! "U_BLOCK" => $sitelog_page_url , ! 'FOLDER_IMG' => $folder_image, ! 'EDITOR' => $editor_name ! ) ! ); } --- 299,316 ---- $edit_time = create_date( $board_config['default_dateformat'], $postrow[$row_count]['block_time'], $board_config['board_timezone'] ); $template->assign_block_vars("msg_row", array( ! 'L_BLOCK_UPDATED' => $lang['Block_updated_by'], ! "ROW_COLOR" => "#" . $row_color, ! "ROW_CLASS" => $row_class, ! "EDIT_TIME" => $edit_time, ! "LAST_PAGE" => $sitelog_page, ! "LAST_BLOCK" => $sitelog_block, ! "EXTRA" => $x_title, ! "U_PAGE" => $sitelog_page_url, ! "U_BLOCK" => $sitelog_page_url , ! 'FOLDER_IMG' => $folder_image, ! 'EDITOR' => $editor_name ! )); } Index: mx_search.php =================================================================== RCS file: /cvsroot/mxbb/core/modules/mx_coreblocks/mx_search.php,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** mx_search.php 11 Dec 2005 16:13:40 -0000 1.9 --- mx_search.php 13 Dec 2005 20:04:27 -0000 1.10 *************** *** 18,66 **** * (at your option) any later version. */ - - define( 'IN_PORTAL', true ); - $mx_root_path = '../../'; - - include( $mx_root_path . 'extension.inc' ); - include( $mx_root_path . 'common.' . $phpEx ); - - include_once( $phpbb_root_path . 'includes/functions_post.' . $phpEx ); - include_once( $phpbb_root_path . 'includes/functions_search.' . $phpEx ); - - // Start session management ! $userdata = session_pagestart( $user_ip, PAGE_INDEX ); ! mx_init_userprefs( $userdata ); ! ! // End session management ! ! $mx_mode = 'mx'; ! ! switch ( $mx_mode ) { ! case 'mx': ! $search_match_table = MX_MATCH_TABLE; ! $search_word_table = MX_WORD_TABLE; ! $search_results_table = MX_SEARCH_TABLE; ! $db_key = 'block_id'; ! break; ! case 'kb': ! $search_match_table = $search_match_table; ! $search_word_table = $search_word_table; ! $search_results_table = $search_results_table; ! $db_key = 'article_id'; ! break; } ! // Define initial vars ! if ( isset( $HTTP_POST_VARS['mode'] ) || isset( $HTTP_GET_VARS['mode'] ) ) ! { ! $mode = ( isset( $HTTP_POST_VARS['mode'] ) ) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode']; ! } ! else ! { ! $mode = ''; ! } if ( isset( $HTTP_POST_VARS['search_keywords'] ) || isset( $HTTP_GET_VARS['search_keywords'] ) ) --- 18,39 ---- * (at your option) any later version. */ ! if( !defined('IN_PORTAL') || !is_object($mx_block)) { ! die("Hacking attempt"); } ! // ! // Read Block Settings ! // ! $title = $mx_block->block_info['block_title']; ! include_once( $phpbb_root_path . 'includes/functions_post.' . $phpEx ); ! include_once( $phpbb_root_path . 'includes/functions_search.' . $phpEx ); ! ! // ! // Define initial vars ! // ! $mode = $mx_request_vars->request('mode', MX_TYPE_NO_TAGS, ''); if ( isset( $HTTP_POST_VARS['search_keywords'] ) || isset( $HTTP_GET_VARS['search_keywords'] ) ) *************** *** 78,82 **** } ! $search_id = ( isset( $HTTP_GET_VARS['search_id'] ) ) ? $HTTP_GET_VARS['search_id'] : ''; if ( $search_id ) --- 51,55 ---- } ! $search_id = $mx_request_vars->get('search_id', MX_TYPE_INT, ''); if ( $search_id ) *************** *** 118,532 **** $start = ( isset( $HTTP_GET_VARS['start'] ) ) ? intval( $HTTP_GET_VARS['start'] ) : 0; switch ( $mode ) { case "results": ! $store_vars = array('search_results', 'total_match_count', 'split_search', 'sort_by', 'sort_dir', 'show_results', 'return_chars'); ! if ( $search_id == '' || $search_keywords != '' ) ! { ! $stopword_array = @file( $phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/search_stopwords.txt' ); ! $synonym_array = @file( $phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/search_synonyms.txt' ); ! $split_search = array(); ! $split_search = ( !strstr( $multibyte_charset, $lang['ENCODING'] ) ) ? split_words( clean_words( 'search', stripslashes( $search_keywords ), $stopword_array, $synonym_array ), 'search' ) : split( ' ', $search_keywords ); ! $search_msg_only = ( !$search_fields ) ? "AND m.title_match = 0" : ( ( strstr( $multibyte_charset, $lang['ENCODING'] ) ) ? '' : '' ); ! $word_count = 0; ! $current_match_type = 'or'; ! $word_match = array(); ! $result_list = array(); ! for( $i = 0; $i < count( $split_search ); $i++ ) { ! if (preg_match('#^[\*%]+$#', trim($split_search[$i])) || preg_match('#^[^\*]{1,2}$#', str_replace(array('*', '%'), '', trim($split_search[$i])))) ! { ! $split_search[$i] = ''; ! continue; ! } ! switch ( $split_search[$i] ) ! { ! case 'and': ! $current_match_type = 'and'; ! break; ! case 'or': ! $current_match_type = 'or'; ! break; ! case 'not': ! $current_match_type = 'not'; ! break; ! default: ! if ( !empty( $search_terms ) ) ! { ! $current_match_type = 'and'; ! } ! if ( !strstr( $multibyte_charset, $lang['ENCODING'] ) ) ! { ! $match_word = str_replace( '*', '%', $split_search[$i] ); ! $sql = "SELECT m.block_id ! FROM " . $search_word_table . " w, " . $search_match_table . " m ! WHERE w.word_text LIKE '$match_word' ! AND m.word_id = w.word_id ! AND w.word_common <> 1 ! $search_msg_only"; ! } ! else { ! die('wrong charset'); ! // $match_word = addslashes( '%' . str_replace( '*', '', $split_search[$i] ) . '%' ); ! // $search_msg_only = ( $search_fields ) ? "OR article_title LIKE '$match_word'" : ''; ! // $sql = "SELECT article_id ! // FROM " . KB_ARTICLE_TABLE . " ! // WHERE article_body LIKE '$match_word' ! // $search_msg_only"; } ! if ( !( $result = $db->sql_query( $sql ) ) ) { ! mx_message_die( GENERAL_ERROR, 'Could not obtain matched articles list', '', __LINE__, __FILE__, $sql ); } ! ! $row = array(); ! while ( $temp_row = $db->sql_fetchrow( $result ) ) { ! $row[$temp_row['post_id']] = 1; ! ! if ( !$word_count ) ! { ! $result_list[$temp_row[$db_key]] = 1; ! } ! else if ( $current_match_type == 'or' ) ! { ! $result_list[$temp_row[$db_key]] = 1; ! } ! else if ( $current_match_type == 'not' ) ! { ! $result_list[$temp_row[$db_key]] = 0; ! } } ! if ( $current_match_type == 'and' && $word_count ) { ! @reset( $result_list ); ! while ( list( $article_id, $match_count ) = @each( $result_list ) ) { ! if ( !$row[$post_id] ) ! { ! $result_list[$post_id] = 0; ! } } } ! $word_count++; ! $db->sql_freeresult( $result ); ! } } ! @reset( $result_list ); ! $search_ids = array(); ! while ( list( $article_id, $matches ) = each( $result_list ) ) { ! if ( $matches ) ! { ! $search_ids[] = $article_id; ! } } ! unset( $result_list ); ! // $total_match_count = count( $search_ids ); // Added below after mx query ! ! // Store new result data ! $search_results = implode( ', ', $search_ids ); ! $per_page = $board_config['topics_per_page']; ! // Combine both results and search data (apart from original query) ! // so we can serialize it and place it in the DB ! $store_search_data = array(); ! // Limit the character length (and with this the results displayed at all following pages) to prevent ! // truncated result arrays. Normally, search results above 12000 are affected. ! // - to include or not to include ! /* ! $max_result_length = 60000; ! if (strlen($search_results) > $max_result_length) ! { ! $search_results = substr($search_results, 0, $max_result_length); ! $search_results = substr($search_results, 0, strrpos($search_results, ',')); ! $total_match_count = count(explode(', ', $search_results)); ! } ! */ ! ! for( $i = 0; $i < count( $store_vars ); $i++ ) { ! $store_search_data[$store_vars[$i]] = $$store_vars[$i]; ! } ! $result_array = serialize( $store_search_data ); ! unset( $store_search_data ); ! mt_srand ( ( double ) microtime() * 1000000 ); ! $search_id = mt_rand(); ! $sql = "UPDATE " . $search_results_table . " ! SET search_id = $search_id, search_array = '" . str_replace( "\'", "''", $result_array ) . "' ! WHERE session_id = '" . $userdata['session_id'] . "'"; ! if ( !( $result = $db->sql_query( $sql ) ) || !$db->sql_affectedrows() ) ! { ! $sql = "INSERT INTO " . $search_results_table . " (search_id, session_id, search_array) ! VALUES($search_id, '" . $userdata['session_id'] . "', '" . str_replace( "\'", "''", $result_array ) . "')"; ! if ( !( $result = $db->sql_query( $sql ) ) ) ! { ! mx_message_die( GENERAL_ERROR, 'Could not insert search results', '', __LINE__, __FILE__, $sql ); ! } ! } ! } ! else { ! $search_id = intval($search_id); ! if ( $search_id ) { ! $sql = "SELECT search_array ! FROM " . $search_results_table . " ! WHERE search_id = $search_id ! AND session_id = '" . $userdata['session_id'] . "'"; ! if ( !( $result = $db->sql_query( $sql ) ) ) ! { ! mx_message_die( GENERAL_ERROR, 'Could not obtain search results', '', __LINE__, __FILE__, $sql ); ! } ! ! if ( $row = $db->sql_fetchrow( $result ) ) ! { ! $search_data = unserialize( $row['search_array'] ); ! for( $i = 0; $i < count( $store_vars ); $i++ ) ! { ! $$store_vars[$i] = $search_data[$store_vars[$i]]; ! } ! } } ! } ! ! // Look up data ... ! if ( count($search_ids) > 0 ) { ! // ! // Get all pages with view access ! // ! $sql = "SELECT * FROM " . PAGE_TABLE; if ( !( $result = $db->sql_query( $sql ) ) ) { ! mx_message_die( GENERAL_ERROR, "Couldn't get list of page", "", __LINE__, __FILE__, $sql ); } ! ! ! $valid_page_ids = ''; ! while ( $page_row = $db->sql_fetchrow( $result )) { ! // Page auth ! $page_auth_ary = array(); ! $page_auth_ary = page_auth( AUTH_VIEW, $userdata, $page_row['auth_view'], $page_row['auth_view_group'] ); ! ! if ( $page_auth_ary[auth_view] ) { ! $valid_page_ids[] = $page_row['page_id']; } } // ! // Now find the associated pages // ! $page_ids = array(); ! foreach($search_ids as $key => $block_id) ! { ! $temp_page_id = get_page_id($block_id); ! if (in_array($temp_page_id, $valid_page_ids)) ! { ! $page_ids[$block_id] = $temp_page_id; ! } ! } ! ! /* ! $valid_page_ids = implode( ', ', $searchset ); ! ! // Generate page_blocks data ! $sql = "SELECT pag.page_id, pag.page_name, pag.page_desc, bct.block_id, blk.block_title, blk.block_time ! FROM " . COLUMN_BLOCK_TABLE . " bct, ! " . PAGE_TABLE . " pag, ! " . COLUMN_TABLE . " col, ! " . BLOCK_TABLE . " blk ! WHERE pag.page_id = col.page_id ! AND bct.column_id = col.column_id ! AND bct.block_id = blk.block_id ! AND bct.block_id IN (" . $search_results . ") ! AND col.page_id IN ($valid_page_ids)"; ! ! // $per_page = $board_config['topics_per_page']; ! // $per_page = 3; ! ! //$sql .= " ORDER BY pag.page_name LIMIT $start, " . $per_page; ! $sql .= " ORDER BY blk.block_time"; ! ! if ( !$result = $db->sql_query( $sql ) ) ! { ! mx_message_die( GENERAL_ERROR, 'Could not obtain search results', '', __LINE__, __FILE__, $sql ); ! } ! $searchset = array(); ! while ( $row = $db->sql_fetchrow( $result ) ) { ! $searchset[] = $row; } ! ! $db->sql_freeresult( $result ); ! ! // Find all dynamic block Page_ids ! $sql = "SELECT pag.page_id, pag.page_name, pag.page_desc, blk.block_id, blk.block_title, blk.block_time, blk.block_editor_id, nav.menu_name ! FROM " . PAGE_TABLE . " pag, ! " . BLOCK_TABLE . " blk, ! " . MENU_NAV_TABLE . " nav, ! " . MENU_CAT_TABLE . " nac ! ! WHERE pag.page_id = nav.page_id AND nav.page_id > 0 ! ! AND nac.cat_id = nav.cat_id ! AND nav.block_id = blk.block_id ! ! AND nav.block_id IN (" . $search_results . ") ! AND nav.page_id IN ($valid_page_ids)"; ! //$sql .= " ORDER BY pag.page_name LIMIT $start, " . $per_page; ! $sql .= " ORDER BY blk.block_time"; ! if ( !$result = $db->sql_query( $sql ) ) ! { ! mx_message_die( GENERAL_ERROR, 'Could not obtain search results', '', __LINE__, __FILE__, $sql ); ! } ! ! while ( $row = $db->sql_fetchrow( $result ) ) { ! $searchset[] = $row; } ! ! // Sort by block_time ! $searchset = qsort_multiarray($searchset, $num = 'block_time', $order = "DESC", $left = 0, $right = -1); ! ! $db->sql_freeresult( $result ); ! // Define censored word matches ! $orig_word = array(); ! $replacement_word = array(); ! obtain_word_list( $orig_word, $replacement_word ); ! */ ! } ! // Output header ! ! $mx_page->page_title = $lang['Search']; ! ! include( $mx_root_path . 'includes/page_header.' . $phpEx ); ! ! $template->set_filenames( array( 'body' => 'mx_search_results.tpl' ) ); ! $total_match_count = count( $searchset ); ! ! $l_search_matches = ( $total_match_count == 1 ) ? sprintf( $lang['Found_search_match'], $total_match_count ) : sprintf( $lang['Found_search_matches'], $total_match_count ); ! $template->assign_vars( array( ! 'L_SEARCH_MATCHES' => $l_search_matches, ! 'L_ARTICLE' => $lang['Mx_Page'] ) ! ); ! $highlight_active = ''; ! $highlight_match = array(); ! for( $j = 0; $j < count( $split_search ); $j++ ) { ! $split_word = $split_search[$j]; ! if ( $split_word != 'and' && $split_word != 'or' && $split_word != 'not' ) { ! $highlight_match[] = '#\b(' . str_replace( "*", "([\w]+)?", $split_word ) . ')\b#is'; ! $highlight_active .= " " . $split_word; ! for ( $k = 0; $k < count( $synonym_array ); $k++ ) { ! list( $replace_synonym, $match_synonym ) = split( ' ', trim( strtolower( $synonym_array[$k] ) ) ); ! ! if ( $replace_synonym == $split_word ) ! { ! $highlight_match[] = '#\b(' . str_replace( "*", "([\w]+)?", $replace_synonym ) . ')\b#is'; ! $highlight_active .= ' ' . $match_synonym; ! } } } } ! $highlight_active = urlencode( trim( $highlight_active ) ); ! ! // die( var_export($searchset) . var_export($search_ids) ); ! // die ( 'f'.count( $searchset ) ); ! // for( $i = 0; $i < count( $searchset ); $i++ ) ! for( $i = $start; $i < $start + $per_page && $i < count( $searchset ); $i++ ) { ! $page_id = $searchset[$i]['page_id']; ! $article_url = append_sid( mx_this_url() ); ! ! $post_date = create_date( $board_config['default_dateformat'], $searchset[$i]['article_date'], $board_config['board_timezone'] ); ! ! $message = $searchset[$i]['article_body']; ! $article_title = $searchset[$i]['page_name']; ! $article_id = $searchset[$i]['article_id']; ! ! // $kb_cat = mx_get_info(BLOCK_TABLE, 'block_id', $searchset[$i]['block_id'] ); ! $temp_url = !empty($searchset[$i]['menu_name']) ? append_sid( PORTAL_URL . 'index.php?page=' . $page_id . '&dynamic_block=' . $searchset[$i]['block_id'] ) : append_sid( PORTAL_URL . 'index.php?page=' . $page_id ); ! $category = '<a href="' . $temp_url . '" class="name">' .$searchset[$i]['block_title'] . '</a>' . ( !empty($searchset[$i]['menu_name']) ? ' (' . $searchset[$i]['menu_name'] . ')': '' ); ! ! // $type = get_kb_type( $searchset[$i]['article_type'] ); ! ! $message = ''; ! ! if ( count( $orig_word ) ) ! { ! $article_title = preg_replace( $orig_word, $replacement_word, $searchset[$i]['article_title'] ); ! } ! $article_author = '<a href="' . append_sid(PHPBB_URL . "profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . '=' . $searchset[$i]['user_id']) . '" class="name">'; ! $article_author .= $searchset[$i]['username']; ! $article_author .= '</a>'; ! $template->assign_block_vars( 'searchresults', array( 'ARTICLE_ID' => $article_id, ! 'ARTICLE_AUTHOR' => $article_author, ! 'ARTICLE_TITLE' => $article_title, ! 'ARTICLE_DESCRIPTION' => $searchset[$i]['article_description'], ! 'ARTICLE_CATEGORY' => $category, ! 'ARTICLE_TYPE' => $type, ! 'U_VIEW_ARTICLE' => $article_url ) ! ); } ! $base_url = mx_this_url( "search_id=$search_id", true, 'mx_search.php' ); ! $template->assign_vars( array( 'PAGINATION' => generate_pagination( $base_url, $total_match_count, $per_page, $start ), ! 'PAGE_NUMBER' => sprintf( $lang['Page_of'], ( floor( $start / $per_page ) + 1 ), ceil( $total_match_count / $per_page ) ), ! 'L_AUTHOR' => $lang['Author'], ! 'L_MESSAGE' => $lang['Message'], ! 'L_TOPICS' => $lang['Article'], ! 'L_TYPE' => $lang['Article_type'], ! 'L_CATEGORY' => $lang['Mx_Block'] ) ! ); break; --- 91,483 ---- $start = ( isset( $HTTP_GET_VARS['start'] ) ) ? intval( $HTTP_GET_VARS['start'] ) : 0; + $per_page = $board_config['topics_per_page']; + switch ( $mode ) { case "results": ! $store_vars = array('search_results', 'total_match_count', 'split_search', 'sort_by', 'sort_dir', 'show_results', 'return_chars'); ! if ( $search_id == '' || $search_keywords != '' ) ! { ! $stopword_array = @file( $phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/search_stopwords.txt' ); ! $synonym_array = @file( $phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/search_synonyms.txt' ); ! $split_search = array(); ! $split_search = ( !strstr( $multibyte_charset, $lang['ENCODING'] ) ) ? split_words( clean_words( 'search', stripslashes( $search_keywords ), $stopword_array, $synonym_array ), 'search' ) : split( ' ', $search_keywords ); ! $search_msg_only = ( !$search_fields ) ? "AND m.title_match = 0" : ( ( strstr( $multibyte_charset, $lang['ENCODING'] ) ) ? '' : '' ); ! $word_count = 0; ! $current_match_type = 'or'; ! $word_match = array(); ! $result_list = array(); ! for( $i = 0; $i < count( $split_search ); $i++ ) ! { ! if (preg_match('#^[\*%]+$#', trim($split_search[$i])) || preg_match('#^[^\*]{1,2}$#', str_replace(array('*', '%'), '', trim($split_search[$i])))) { ! $split_search[$i] = ''; ! continue; ! } ! switch ( $split_search[$i] ) ! { ! case 'and': ! $current_match_type = 'and'; ! break; ! case 'or': ! $current_match_type = 'or'; ! break; ! case 'not': ! $current_match_type = 'not'; ! break; ! default: ! if ( !empty( $search_terms ) ) ! { ! $current_match_type = 'and'; ! } ! if ( !strstr( $multibyte_charset, $lang['ENCODING'] ) ) ! { ! $match_word = str_replace( '*', '%', $split_search[$i] ); ! $sql = "SELECT m.block_id ! FROM " . MX_WORD_TABLE . " w, " . MX_MATCH_TABLE . " m ! WHERE w.word_text LIKE '$match_word' ! AND m.word_id = w.word_id ! AND w.word_common <> 1 ! $search_msg_only"; ! } ! else ! { ! die('wrong charset'); ! // $match_word = addslashes( '%' . str_replace( '*', '', $split_search[$i] ) . '%' ); ! // $search_msg_only = ( $search_fields ) ? "OR article_title LIKE '$match_word'" : ''; ! // $sql = "SELECT article_id ! // FROM " . KB_ARTICLE_TABLE . " ! // WHERE article_body LIKE '$match_word' ! // $search_msg_only"; ! } ! if ( !( $result = $db->sql_query( $sql ) ) ) ! { ! mx_message_die( GENERAL_ERROR, 'Could not obtain matched articles list', '', __LINE__, __FILE__, $sql ); ! } ! ! $row = array(); ! while ( $temp_row = $db->sql_fetchrow( $result ) ) ! { ! $row[$temp_row['post_id']] = 1; ! ! if ( !$word_count ) { ! $result_list[$temp_row['block_id']] = 1; } ! else if ( $current_match_type == 'or' ) { ! $result_list[$temp_row['block_id']] = 1; } ! else if ( $current_match_type == 'not' ) { ! $result_list[$temp_row['block_id']] = 0; } + } ! if ( $current_match_type == 'and' && $word_count ) ! { ! @reset( $result_list ); ! while ( list( $block_id, $match_count ) = @each( $result_list ) ) { ! if ( !$row[$post_id] ) { ! $result_list[$post_id] = 0; } } + } ! $word_count++; ! $db->sql_freeresult( $result ); } + } ! @reset( $result_list ); ! $search_ids = array(); ! while ( list( $block_id, $matches ) = each( $result_list ) ) ! { ! if ( $matches ) { ! $search_ids[] = $block_id; } + } ! unset( $result_list ); ! // $total_match_count = count( $search_ids ); // Added below after mx query ! // Store new result data ! $search_results = implode( ',', $search_ids ); ! ! // Combine both results and search data (apart from original query) ! // so we can serialize it and place it in the DB ! $store_search_data = array(); ! // Limit the character length (and with this the results displayed at all following pages) to prevent ! // truncated result arrays. Normally, search results above 12000 are affected. ! // - to include or not to include ! /* ! $max_result_length = 60000; ! if (strlen($search_results) > $max_result_length) { ! $search_results = substr($search_results, 0, $max_result_length); ! $search_results = substr($search_results, 0, strrpos($search_results, ',')); ! $total_match_count = count(explode(', ', $search_results)); ! } ! */ ! for( $i = 0; $i < count( $store_vars ); $i++ ) ! { ! $store_search_data[$store_vars[$i]] = $$store_vars[$i]; ! } ! $result_array = serialize( $store_search_data ); ! unset( $store_search_data ); ! mt_srand ( ( double ) microtime() * 1000000 ); ! $search_id = mt_rand(); ! ! $sql = "UPDATE " . MX_SEARCH_TABLE . " ! SET search_id = $search_id, search_array = '" . str_replace( "\'", "''", $result_array ) . "' ! WHERE session_id = '" . $userdata['session_id'] . "'"; ! if ( !( $result = $db->sql_query( $sql ) ) || !$db->sql_affectedrows() ) { ! $sql = "INSERT INTO " . MX_SEARCH_TABLE . " (search_id, session_id, search_array) ! VALUES($search_id, '" . $userdata['session_id'] . "', '" . str_replace( "\'", "''", $result_array ) . "')"; ! ! if ( !( $result = $db->sql_query( $sql ) ) ) { ! mx_message_die( GENERAL_ERROR, 'Could not insert search results', '', __LINE__, __FILE__, $sql ); } ! } ! } ! else ! { ! $search_id = intval($search_id); ! if ( $search_id ) { ! $sql = "SELECT search_array ! FROM " . MX_SEARCH_TABLE . " ! WHERE search_id = $search_id ! AND session_id = '" . $userdata['session_id'] . "'"; ! if ( !( $result = $db->sql_query( $sql ) ) ) { ! mx_message_die( GENERAL_ERROR, 'Could not obtain search results', '', __LINE__, __FILE__, $sql ); } ! ! if ( $row = $db->sql_fetchrow( $result ) ) { ! $search_data = unserialize( $row['search_array'] ); ! for( $i = 0; $i < count( $store_vars ); $i++ ) { ! $$store_vars[$i] = $search_data[$store_vars[$i]]; } } + } + + $search_ids = explode(',', $search_results); + } + + // + // Look up data ... + // + if ( count($search_ids) > 0 ) + { + // + // Get all pages with view access + // + $sql = "SELECT * FROM " . PAGE_TABLE; + if ( !( $result = $db->sql_query( $sql ) ) ) + { + mx_message_die( GENERAL_ERROR, "Couldn't get list of page", "", __LINE__, __FILE__, $sql ); + } + $valid_page_ids_array = array(); + while ( $page_row = $db->sql_fetchrow( $result )) + { // ! // Page auth // ! $page_auth_ary = array(); ! $page_auth_ary = page_auth( AUTH_VIEW, $userdata, $page_row['auth_view'], $page_row['auth_view_group'] ); ! if ( $page_auth_ary['auth_view'] ) { ! $valid_page_ids_array[] = $page_row['page_id']; } ! } ! // ! // Now find the associated pages ! // ! $page_ids = array(); ! $block_ids = array(); ! $valid_page_ids = ''; ! foreach($search_ids as $key => $block_id) ! { ! $page_id_array = get_page_id($block_id, false, true); ! if (in_array($page_id_array['page_id'], $valid_page_ids_array)) { ! $page_ids[$block_id] = $page_id_array; ! $block_ids[] = $block_id; } ! } ! $valid_block_ids = implode( ', ', $block_ids ); ! // ! // Generate page_blocks data ! // ! $sql = "SELECT block_id, block_desc, block_title, block_time, block_editor_id ! FROM " . BLOCK_TABLE . " ! WHERE block_id IN (" . $valid_block_ids . ") ! ORDER BY block_time DESC ! LIMIT ".$start.", ".$per_page; ! ! if ( !( $result = $db->sql_query( $sql ) ) ) ! { ! mx_message_die( GENERAL_ERROR, 'Could not obtain search results', '', __LINE__, __FILE__, $sql ); ! } ! ! } + // + // Output header + // + $mx_page->page_title = $lang['Search']; + $template->set_filenames( array( 'body' => 'mx_search_results.tpl' ) ); ! $total_match_count = count($block_ids); ! ! $l_search_matches = ( $total_match_count == 1 ) ? sprintf( $lang['Found_search_match'], $total_match_count ) : sprintf( $lang['Found_search_matches'], $total_match_count ); ! $template->assign_vars( array( ! 'L_SEARCH_MATCHES' => $l_search_matches, ! 'L_ARTICLE' => $lang['Mx_Page'] ) ! ); ! $highlight_active = ''; ! $highlight_match = array(); ! for( $j = 0; $j < count( $split_search ); $j++ ) ! { ! $split_word = $split_search[$j]; ! if ( $split_word != 'and' && $split_word != 'or' && $split_word != 'not' ) { ! $highlight_match[] = '#\b(' . str_replace( "*", "([\w]+)?", $split_word ) . ')\b#is'; ! $highlight_active .= " " . $split_word; ! for ( $k = 0; $k < count( $synonym_array ); $k++ ) { ! list( $replace_synonym, $match_synonym ) = split( ' ', trim( strtolower( $synonym_array[$k] ) ) ); ! if ( $replace_synonym == $split_word ) { ! $highlight_match[] = '#\b(' . str_replace( "*", "([\w]+)?", $replace_synonym ) . ')\b#is'; ! $highlight_active .= ' ' . $match_synonym; } } } + } ! $highlight_active = urlencode( trim( $highlight_active ) ); ! // ! // Dump out the results ! // ! while( $searchdata = $db->sql_fetchrow($result) ) ! { ! $search_block_id = $searchdata['block_id']; ! ! if (is_array($page_ids[$search_block_id]) && !empty($page_ids[$search_block_id]['block_id'])) { ! $dynamic_block_id = $page_ids[$search_block_id]['block_id']; ! $pageid = $page_ids[$search_block_id]['page_id']; ! } ! else if (is_array($page_ids[$search_block_id])) ! { ! $dynamic_block_id = ''; ! $pageid = $page_ids[$search_block_id]['page_id']; ! } ! else ! { ! $dynamic_block_id = ''; ! $pageid = $page_ids[$search_block_id]; ! } ! $page_title = $page_ids[$search_block_id]['page_name']; ! $page_desc = $page_ids[$search_block_id]['page_desc']; ! ! $temp_url = !empty($dynamic_block_id) ? append_sid( PORTAL_URL . 'index.php?page=' . $pageid . '&dynamic_block=' . $dynamic_block_id ) : append_sid( PORTAL_URL . 'index.php?page=' . $pageid ); ! ! $editor_name_tmp = get_userdata( $searchdata['block_editor_id'] ); ! $editor_name = $editor_name_tmp['username']; ! ! $edit_time = !empty($searchdata['block_time']) ? '(' . create_date( $board_config['default_dateformat'], $searchdata['block_time'], $board_config['board_timezone'] ) . ')' : ''; ! $block_editor = '<a href="' . append_sid(PHPBB_URL . "profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . '=' . $searchdata['block_editor_id']) . '" class="name">'; ! $block_editor .= $editor_name; ! $block_editor .= '</a>'; ! ! $block_title = $searchdata['block_title']; ! $block_desc = $searchdata['block_desc']; ! ! $block_title_url = '<a href="' . $temp_url . '" class="name">' . $block_title . '</a>'; ! $page_title_url = '<a href="' . $temp_url . '" class="name">' .$page_title . '</a>'; ! /* ! $message = ''; ! if ( count( $orig_word ) ) ! { ! $article_title = preg_replace( $orig_word, $replacement_word, $searchset[$i]['article_title'] ); } + */ ! $template->assign_block_vars( 'searchresults', array( ! 'BLOCK_ID' => $block_id, ! ! 'L_BLOCK_UPDATED' => !empty($edit_time) ? '<br />' . $lang['Block_updated_by'] : '', ! 'BLOCK_EDITOR' => !empty($edit_time) ? $block_editor : '', ! "EDIT_TIME" => !empty($edit_time) ? $edit_time : '', ! ! 'BLOCK_TITLE_URL' => $block_title_url, ! 'BLOCK_DESC' => !empty($block_desc) ? '<br />' . $block_desc : '', ! ! 'PAGE_TITLE_URL' => $page_title_url, ! 'PAGE_DESC' => !empty($page_desc) ? '<br />' . $page_desc : '', ! )); ! } ! $base_url = mx_this_url( "search_id=$search_id" ); ! $new_search_url = append_sid( PORTAL_URL . 'index.php?page=' . $page_id ); ! $template->assign_vars( array( ! 'PAGINATION' => generate_pagination( $base_url, $total_match_count, $per_page, $start ), ! 'PAGE_NUMBER' => sprintf( $lang['Page_of'], ( floor( $start / $per_page ) + 1 ), ceil( $total_match_count / $per_page ) ), ! ! 'L_AUTHOR' => $lang['Author'], ! 'L_PAGE' => $lang['Mx_Page'], ! 'L_BLOCK' => $lang['Mx_Block'], ! 'L_NEW_SEARCH' => $lang['Mx_new_search'], ! ! 'U_NEW_SEARCH' => $new_search_url ! )); break; *************** *** 534,555 **** default: // Output the basic page ! $mx_page->page_title = $lang['Search']; - - include( $mx_root_path . 'includes/page_header.' . $phpEx ); $template->set_filenames( array( 'body' => 'mx_search_body.tpl' ) ); ! $template->assign_vars( array( 'L_SEARCH_QUERY' => $lang['Search_query'], ! 'L_SEARCH_KEYWORDS' => $lang['Search_keywords'], ! 'L_SEARCH_KEYWORDS_EXPLAIN' => $lang['Search_keywords_explain'], ! 'L_SEARCH_ANY_TERMS' => $lang['Search_for_any'], ! 'L_SEARCH_ALL_TERMS' => $lang['Search_for_all'], ! 'S_SEARCH_ACTION' => append_sid( mx_this_url( "mode=results", true, 'mx_search.php' ) ), ! 'S_HIDDEN_FIELDS' => '', ! 'S_SEARCH' => $lang['Search'] ) ! ); break; --- 485,506 ---- default: + // // Output the basic page ! // $mx_page->page_title = $lang['Search']; $template->set_filenames( array( 'body' => 'mx_search_body.tpl' ) ); ! $template->assign_vars( array( ! 'L_SEARCH_QUERY' => $lang['Search_query'], ! 'L_SEARCH_KEYWORDS' => $lang['Search_keywords'], ! 'L_SEARCH_KEYWORDS_EXPLAIN' => $lang['Search_keywords_explain'], ! 'L_SEARCH_ANY_TERMS' => $lang['Search_for_any'], ! 'L_SEARCH_ALL_TERMS' => $lang['Search_for_all'], ! 'S_SEARCH_ACTION' => append_sid( mx_this_url( "mode=results" ) ), ! 'S_HIDDEN_FIELDS' => '', ! 'S_SEARCH' => $lang['Search'] ! )); break; *************** *** 557,563 **** $template->pparse( 'body' ); - // load footer - - include( $phpbb_root_path . 'includes/page_tail.' . $phpEx ); ?> \ No newline at end of file --- 508,511 ---- |