⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 search.php

📁 极限网络智能办公系统—MYOA26—100%—源程序。
💻 PHP
📖 第 1 页 / 共 3 页
字号:
		else
		{
			return $this->html->start_as_post( array(
				"SHOW_PAGES" => $this->links
			) );
		}
	}

	function get_active( )
	{
		global $ibforums;
		global $DB;
		global $std;
		global $HTTP_POST_VARS;
		if ( !isset( $ibforums->input['searchid'] ) )
		{
			if ( $ibforums->input['st_day'] == "" )
			{
				$ibforums->input['st_day'] = 1;
				$this->st_stamp = time( ) - 86400;
			}
			else
			{
				$ibforums->input['st_day'] = preg_replace( "/s/", "", $ibforums->input['st_day'] );
				$this->st_stamp = time( ) - 86400 * $ibforums->input['st_day'];
			}
			if ( $ibforums->input['end_day'] == "" )
			{
				$this->end_stamp = time( );
				$ibforums->input['end_day'] = 0;
			}
			else
			{
				$ibforums->input['end_day'] = preg_replace( "/e/", "", $ibforums->input['end_day'] );
				$this->end_stamp = time( ) - 86400 * $ibforums->input['end_day'];
			}
			$ibforums->input['cat_forum'] = "cat";
			$ibforums->input['cats'] = "all";
			$forums = $this->get_searchable_forums( );
			if ( $forums == "" )
			{
				$std->error( array( "LEVEL" => 1, "MSG" => "no_search_forum" ) );
			}
			$query = "SELECT DISTINCT(t.tid)\n\t\t\t\t\t  FROM ibf_posts p\n\t\t\t\t\t    LEFT JOIN ibf_topics t ON (p.topic_id=t.tid)\n\t\t\t\t\t  WHERE p.post_date BETWEEN ".$this->st_stamp." AND ".$this->end_stamp."\n\t\t\t\t\t    AND p.forum_id IN({$forums})\n\t\t\t\t\t    AND p.queued <> 1\n\t\t\t\t\t  ORDER BY t.last_post DESC\n\t\t\t\t\t  LIMIT 0,200";
			$DB->query( $query );
			$max_hits = $DB->get_num_rows( );
			$topics = "";
			while ( $row = $DB->fetch_row( ) )
			{
				$topics .= $row['tid'].",";
			}
			$DB->free_result( );
			$topics = preg_replace( "/,\$/", "", $topics );
			if ( $topics == "" )
			{
				$this->output .= $this->html->active_start( array( "SHOW_PAGES" => "" ) );
				$this->output .= $this->html->active_none( );
				$this->output .= $this->html->end( "" );
				$this->page_title = $ibforums->lang['search_results'];
				$this->nav = array(
					"<a href='{$this->base_url}&act=Search'>{$ibforums->lang['search_form']}</a>",
					$ibforums->lang['search_title']
				);
				return "";
			}
			$unique_id = md5( uniqid( microtime( ), 1 ) );
			$str = $DB->compile_db_insert_string( array(
				"id" => $unique_id,
				"search_date" => time( ),
				"topic_id" => $topics,
				"topic_max" => $max_hits,
				"sort_key" => $this->sort_key,
				"sort_order" => $this->sort_order,
				"member_id" => $ibforums->member['id'],
				"ip_address" => $ibforums->input['IP_ADDRESS']
			) );
			$DB->query( "INSERT INTO ibf_search_results ({$str['FIELD_NAMES']}) VALUES ({$str['FIELD_VALUES']})" );
		}
		else
		{
			$t_time = time( ) - 86400;
			$this->first = intval( $ibforums->input['st'] ) != "" ? intval( $ibforums->input['st'] ) : 0;
			$DB->query( "DELETE FROM ibf_search_results WHERE search_date < '{$t_time}'" );
			$unique_id = $ibforums->input['searchid'];
			$DB->query( "SELECT * FROM ibf_search_results WHERE id='{$unique_id}'" );
			$sr = $DB->fetch_row( );
			$topics = $sr['topic_id'];
			$max_hits = $sr['topic_max'];
			$this->sort_order = $sr['sort_order'];
			$this->sort_key = $sr['sort_key'];
			if ( $topics == "" )
			{
				$std->error( array( "LEVEL" => 1, "MSG" => "no_search_results" ) );
			}
		}
		$topic_string = implode( ",", array_slice( explode( ",", $topics ), $this->first, 25 ) );
		$topic_string = str_replace( " ", "", $topic_string );
		$topic_string = preg_replace( "/,\$/", "", $topic_string );
		$url_words = urlencode( trim( $keywords ) );
		$links = $std->build_pagelinks( array(
			TOTAL_POSS => $max_hits,
			25,
			CUR_ST_VAL => $this->first,
			"",
			"",
			BASE_URL => $this->base_url."&act=Search&CODE=getactive&searchid={$unique_id}"
		) );
		$this->output .= $this->html->active_start( array(
			"SHOW_PAGES" => $links
		) );
		$this->output = preg_replace( "/(<option value='s".$ibforums->input['st_day']."')/", "\\1 selected", $this->output );
		$this->output = preg_replace( "/(<option value='e".$ibforums->input['end_day']."')/", "\\1 selected", $this->output );
		$DB->query( "SELECT t.*, f.id as forum_id, f.name as forum_name FROM ibf_topics t, ibf_forums f WHERE t.tid IN({$topic_string}) and f.id=t.forum_id ORDER BY ".$this->sort_key." ".$this->sort_order." LIMIT 0,25" );
		while ( $row = $DB->fetch_row( ) )
		{
			$row['keywords'] = $url_words;
			$this->output .= $this->html->renderrow( $this->parse_entry( $row ) );
		}
		$this->page_title = $ibforums->lang['search_results'];
		$this->nav = array(
			"<a href='{$this->base_url}&act=Search'>{$ibforums->lang['search_form']}</a>",
			$ibforums->lang['search_title']
		);
		$this->output .= $this->html->end( array(
			"SHOW_PAGES" => $links
		) );
	}

	function parse_entry( $topic, $view_as_post = 0 )
	{
		global $DB;
		global $std;
		global $ibforums;
		$topic['last_text'] = $ibforums->lang[last_post_by];
		$topic['last_time'] = $ibforums->lang[last_updated];
		$topic['last_poster'] = $topic['last_poster_id'] != 0 ? "<b><a href='{$this->base_url}&act=Profile&CODE=03&MID={$topic['last_poster_id']}'>{$topic['last_poster_name']}</a></b>" : "-".$topic['last_poster_name']."-";
		$topic['starter'] = $topic['starter_id'] != 0 ? "<a href='{$this->base_url}&act=Profile&CODE=03&MID={$topic['starter_id']}'>{$topic['starter_name']}</a>" : "-".$topic['starter_name']."-";
		if ( $topic['poll_state'] )
		{
			$topic['prefix'] = $ibforums->vars['pre_polls']." ";
		}
		$topic['folder_img'] = $std->folder_icon( $topic );
		$topic['topic_icon'] = $topic['icon_id'] ? "<img src=\"".$ibforums->vars['img_url']."/icon".$topic['icon_id'].".gif\" border=\"0\" alt=\"\">" : "&nbsp;";
		if ( $topic['attached'] == 1 )
		{
			$topic['topic_attach_icon'] = "<img src=\"".$ibforums->vars['img_url']."/clip1.gif\" border=\"0\" alt=\"此主题有一个附件\">&nbsp;";
		}
		else if ( 1 <= $topic['attached'] )
		{
			$topic['topic_attach_icon'] = "<img src=\"".$ibforums->vars['img_url']."/clip2.gif\" border=\"0\" alt=\"此主题有多个附件\">&nbsp;";
		}
		else
		{
			$topic['topic_attach_icon'] = "";
		}
		if ( $topic['pinned'] )
		{
			$topic['topic_icon'] = "<{B_PIN}>";
		}
		$topic['topic_start_date'] = $std->get_date( $topic['start_date'], "LONG" );
		$pages = 1;
		if ( $topic['posts'] )
		{
			if ( ( $topic['posts'] + 1 ) % $ibforums->vars['display_max_posts'] == 0 )
			{
				$pages = ( $topic['posts'] + 1 ) / $ibforums->vars['display_max_posts'];
			}
			else
			{
				$number = ( $topic['posts'] + 1 ) / $ibforums->vars['display_max_posts'];
				$pages = ceil( $number );
			}
		}
		if ( 1 < $pages )
		{
			$topic['PAGES'] = "<span class='small'>({$ibforums->lang['topic_sp_pages']} ";
			$i = 0;
			for ( ;	$i < $pages;	++$i	)
			{
				$real_no = $i * $ibforums->vars['display_max_posts'];
				$page_no = $i + 1;
				if ( $page_no == 4 )
				{
					$topic['PAGES'] .= "<a href='{$this->base_url}&act=ST&f={$topic['forum_id']}&t={$topic['tid']}&st=".( $pages - 1 ) * $ibforums->vars['display_max_posts']."&hl={$topic['keywords']}'>...{$pages} </a>";
					break;
				}
				else
				{
					$topic['PAGES'] .= "<a href='{$this->base_url}&act=ST&f={$topic['forum_id']}&t={$topic['tid']}&st={$real_no}&hl={$topic['keywords']}'>{$page_no} </a>";
				}
			}
			$topic['PAGES'] .= ")</span>";
		}
		if ( $topic['posts'] < 0 )
		{
			$topic['posts'] = 0;
		}
		$last_time = $ibforums->input['last_visit'] < $this->read_array[$topic['tid']] ? $this->read_array[$topic['tid']] : $ibforums->input['last_visit'];
		if ( $last_time && $last_time < $topic['last_post'] )
		{
			$topic['go_last_page'] = "<a href='{$this->base_url}&act=ST&f={$topic['forum_id']}&t={$topic['tid']}&view=getlastpost'><{GO_LAST_ON}></a>";
			$topic['go_new_post'] = "<a href='{$this->base_url}&act=ST&f={$topic['forum_id']}&t={$topic['tid']}&view=getnewpost'><{NEW_POST}></a>";
		}
		else
		{
			$topic['go_last_page'] = "<a href='{$this->base_url}&act=ST&f={$topic['forum_id']}&t={$topic['tid']}&view=getlastpost'><{GO_LAST_OFF}></a>";
			$topic['go_new_post'] = "";
		}
		$maxpages = ( $pages - 1 ) * $ibforums->vars['display_max_posts'];
		if ( $maxpages < 0 )
		{
			$maxpages = 0;
		}
		$topic['last_post'] = $std->get_date( $topic['last_post'], "LONG" );
		if ( $topic['state'] == "link" )
		{
			$t_array = explode( "&", $topic['moved_to'] );
			$topic['tid'] = $t_array[0];
			$topic['forum_id'] = $t_array[1];
			$topic['title'] = $topic['title'];
			$topic['views'] = "--";
			$topic['posts'] = "--";
			$topic['prefix'] = $ibforums->vars['pre_moved']." ";
			$topic['go_new_post'] = "";
		}
		if ( $topic['pinned'] == 1 )
		{
			$topic['prefix'] = $ibforums->vars['pre_pinned'];
			$topic['topic_icon'] = "<{B_PIN}>";
		}
		if ( $view_as_post == 1 )
		{
			$ibforums->vars['search_post_cut'] = $ibforums->vars['search_post_cut'] != "" ? $ibforums->vars['search_post_cut'] : 100;
			$topic['post'] = substr( $this->parser->unconvert( $topic['post'] ), 0, $ibforums->vars['search_post_cut'] )."...";
			$topic['post'] = str_replace( "\n", "<br/>", $topic['post'] );
			if ( $topic['author_id'] )
			{
				$topic['author_name'] = "<b><a href='{$this->base_url}&act=Profile&CODE=03&MID={$topic['author_id']}'>{$topic['author_name']}</a></b>";
			}
		}
		return $topic;
	}

	function filter_keywords( $words = "", $name = 0 )
	{
		$words = trim( strtolower( str_replace( "%", "\\%", $words ) ) );
		$words = preg_replace( "/\\s+(and|or)\$/", "", $words );
		$words = str_replace( "_", "\\_", $words );
		if ( $name == 0 )
		{
			$words = preg_replace( "/[\\|\\[\\]\\{\\}\\(\\)\\.,:;\\?\\-\\+\\#\\\\\\/\"']/", "", $words );
		}
		return " ".preg_quote( $words )." ";
	}

	function convert_highlite_words( $words = "" )
	{
		$words = trim( urldecode( $words ) );
		$words = preg_replace( "/\\s+(and|or)(\\s+|\$)/i", ",\\1,", $words );
		$words = preg_replace( "/\\s/", "+", $words );
		return $words;
	}

	function get_searchable_forums( )
	{
		global $ibforums;
		global $DB;
		global $std;
		global $HTTP_POST_VARS;
		$forum_array = array( );
		$forum_string = "";
		$sql_query = "";
		$check_sub = 0;
		if ( $ibforums->input['cat_forum'] == "cat" )
		{
			if ( $ibforums->input['cats'] == "all" )
			{
				$sql_query = "SELECT id, read_perms, password from ibf_forums";
			}
			else if ( !preg_match( "/^(?:\\d+)\$/", $ibforums->input['cats'] ) )
			{
				return;
			}
			else
			{
				$sql_query = "SELECT id, read_perms, password from ibf_forums WHERE category='".$ibforums->input['cats']."'";
			}
		}
		else if ( $ibforums->input['forums'] == "all" )
		{
			$sql_query = "SELECT id, read_perms, password from ibf_forums";
		}
		else
		{
			if ( !preg_match( "/^(?:\\d+)\$/", $ibforums->input['forums'] ) )
			{
				return;
			}
			else
			{
				if ( $ibforums->input['searchsubs'] == 1 )
				{
					$check_sub = 1;
				}
				$sql_query = "SELECT id, read_perms, password, subwrap from ibf_forums WHERE id='".$ibforums->input['forums']."'";
			}
		}
		if ( $sql_query != "" )
		{
			$DB->query( $sql_query );
			if ( $check_sub == 1 )
			{
				$r = $DB->fetch_row( );
				if ( $this->check_access( $r ) )
				{
					if ( $r['subwrap'] == 1 )
					{
						$DB->query( "SELECT id, read_perms, password FROM ibf_forums WHERE parent_id={$r['id']} or id={$r['id']}" );
					}
					else
					{
						$forum_array[] = $r['id'];
					}
				}
			}
			while ( count( $forum_array ) < 1 && ( $i = $DB->fetch_row( ) ) )
			{
				if ( $this->check_access( $i ) )
				{
					$forum_array[] = $i['id'];
				}
			}
		}
		$forum_string = implode( ",", $forum_array );
		return $forum_string;
	}

	function check_access( $i )
	{
		global $std;
		global $ibforums;
		$can_read = TRUE;
		if ( $i['password'] != "" )
		{
			if ( !( $c_pass = $std->my_getcookie( "iBForum".$i['id'] ) ) )
			{
				$can_read = FALSE;
			}
			if ( $c_pass == $i['password'] )
			{
				$can_read = TRUE;
			}
			else
			{
				$can_read = FALSE;
			}
		}
		if ( $can_read == TRUE )
		{
			if ( $i['read_perms'] == "*" )
			{
				$can_read = TRUE;
			}
			else if ( preg_match( "/(^|,)".$ibforums->member['mgroup']."(,|\$)/", $i['read_perms'] ) )
			{
				$can_read = TRUE;
			}
			else
			{
				$can_read = FALSE;
			}
		}
		return $can_read;
	}

}

$idx = new search( );
?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -