<?php

/*
+--------------------------------------------------------------------------
|   Invision Power Board v1.2
|   ========================================
|   by Matthew Mecham
|   (c) 2001 - 2003 Invision Power Services
|   http://www.invisionpower.com
|   ========================================
|   Web: http://www.invisionboard.com
|   Email: matt@invisionpower.com
|   Licence Info: http://www.invisionboard.com/?license
+---------------------------------------------------------------------------
|
|   > Spider (MAN) Logs
|   > Module written by Matt Mecham
|   > Date started: 28th May 2003
|
|	> Module Version Number: 1.0.0
+--------------------------------------------------------------------------
*/


$idx = new ad_spiderlogs();


class ad_spiderlogs {

	var $base_url;

	function ad_spiderlogs() {
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		//---------------------------------------
		// Kill globals - globals bad, Homer good.
		//---------------------------------------
		
		$tmp_in = array_merge( $_GET, $_POST, $_COOKIE );
		
		foreach ( $tmp_in as $k => $v )
		{
			unset($$k);
		}
		
		$ADMIN->nav[] = array( 'act=spiderlog', '搜索引擎蜘蛛日志' );
		
		//---------------------------------------

		switch($IN['code'])
		{
		
			case 'view':
				$this->view();
				break;
				
			case 'remove':
				$this->remove();
				break;
				
				
			//-------------------------
			default:
				$this->list_current();
				break;
		}
		
	}
	
	//---------------------------------------------
	// Remove archived files
	//---------------------------------------------
	
	function view()
	{
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		$start = $IN['st'] ? $IN['st'] : 0;
		
		$ADMIN->page_detail = "检视所有搜索引擎蜘蛛的行为";
		$ADMIN->page_title  = "搜索引擎日志经理";
		
		$botty = urldecode($IN['bid']);
	
		if ($IN['search_string'] == "")
		{
			$DB->query("SELECT COUNT(sid) as count FROM ibf_spider_logs WHERE bot='$botty'");
			
			$row = $DB->fetch_row();
			
			$row_count = $row['count'];
			
			$query = "&act=spiderlog&bid={$IN['bid']}&code=view";
			
			$DB->query("SELECT * FROM ibf_spider_logs WHERE bot='$botty' ORDER BY entry_date DESC LIMIT $start, 20");
			
		}
		else
		{
			$IN['search_string'] = urldecode($IN['search_string']);
		
			$DB->query("SELECT COUNT(sid) as count FROM ibf_spider_logs WHERE query_string LIKE '%{$IN['search_string']}%'");
			
			$row = $DB->fetch_row();
			
			$row_count = $row['count'];
			
			$query = "&act=spiderlog&code=view&search_string=".urlencode($IN['search_string']);
			
			$DB->query("SELECT * FROM ibf_spider_logs WHERE query_string LIKE '%{$IN['search_string']}%' ORDER BY entry_date DESC LIMIT $start, 20");
			
		
		
		}
		
		$links = $std->build_pagelinks( array( 'TOTAL_POSS'  => $row_count,
											   'PER_PAGE'    => 20,
											   'CUR_ST_VAL'  => $start,
											   'L_SINGLE'    => "单页",
											   'L_MULTI'     => "分页： ",
											   'BASE_URL'    => $ADMIN->base_url.$query,
											 )
									  );
									  
		$ADMIN->page_detail = "您可以检视及移除由搜索引擎机器人所完成的动作";
		$ADMIN->page_title  = "搜索引擎日志经理";
		
		//+-------------------------------
		
		$SKIN->td_header[] = array( "机器人名称"            , "15%" );
		$SKIN->td_header[] = array( "查询字串"        , "15%" );
		$SKIN->td_header[] = array( "行为时间"      , "20%" );
		$SKIN->td_header[] = array( "IP 位址"          , "10%" );
		
		$ADMIN->html .= $SKIN->start_table( "储存的搜索引擎日志" );
		$ADMIN->html .= $SKIN->add_td_basic($links, 'right', 'pformstrip');
		
		if ( $DB->get_num_rows() )
		{
			while ( $row = $DB->fetch_row() )
			{
			
				$ADMIN->html .= $SKIN->add_td_row( array( "<b>".$INFO[ 'sp_'.$row['bot'] ]."</b>",
														  "<a href='{$INFO['board_url']}/index.{$INFO['php_ext']}?{$row['query_string']}' target='_blank'>{$row['query_string']}</a>",
														  $ADMIN->get_date( $row['entry_date'], 'LONG' ),
														  "{$row['ip_address']}",
												 )      );
			
			}
		}
		else
		{
			$ADMIN->html .= $SKIN->add_td_basic("<center>无结果</center>");
		}
		
		$ADMIN->html .= $SKIN->add_td_basic($links, 'right', 'pformstrip');
		
		$ADMIN->html .= $SKIN->end_table();
		
		
		//+-------------------------------
		//+-------------------------------
		
		$ADMIN->output();
		
	}
	
	//---------------------------------------------
	// Remove archived files
	//---------------------------------------------
	
	function remove()
	{
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
	
		if ($IN['bid'] == "")
		{
			$ADMIN->error("您没有选择要移除的机器人！");
		}
		
		$botty = urldecode($IN['bid']);
		
		$DB->query("DELETE FROM ibf_spider_logs WHERE bot='$botty'");
		
		$ADMIN->save_log("移除的搜索引擎日志");
		
		$std->boink_it($ADMIN->base_url."&act=spiderlog");
		exit();
	
	
	}
	
	

	
	
	//-------------------------------------------------------------
	// SHOW ALL LANGUAGE PACKS
	//-------------------------------------------------------------
	
	function list_current()
	{
		global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
		
		$form_array = array();
	
		$ADMIN->page_detail = "您可以检视及移除蜘蛛引擎日志中的条目";
		$ADMIN->page_title  = "搜索引擎日志经理";

		//+-------------------------------
		
		$SKIN->td_header[] = array( "机器人名称"            , "20%" );
		$SKIN->td_header[] = array( "点中"                , "20%" );
		$SKIN->td_header[] = array( "开始"             , "20%" );
		$SKIN->td_header[] = array( "根据机器人全部检视"     , "20%" );
		$SKIN->td_header[] = array( "根据机器人全部移除"   , "20%" );
		
		$ADMIN->html .= $SKIN->start_table( "储存的搜索引擎蜘蛛日志" );
		
		$DB->query("SELECT count(*) as cnt, bot, entry_date, query_string FROM `ibf_spider_logs` group by bot order by entry_date DESC");
		
		while ( $r = $DB->fetch_row() )
		{
		
			$url_butt = urlencode($r['bot']);
			
			$ADMIN->html .= $SKIN->add_td_row( array( $INFO[ 'sp_'.$r['bot'] ],
													  "<center>{$r['cnt']}</center>",
													   $ADMIN->get_date( $r['entry_date'], 'SHORT' ),
													  "<center><a href='".$SKIN->base_url."&act=spiderlog&code=view&bid={$url_butt}'>检视</a></center>",
													  "<center><a href='".$SKIN->base_url."&act=spiderlog&code=remove&bid={$url_butt}'>移除</a></center>",
											 )      );
		}
			
		
		
		$ADMIN->html .= $SKIN->end_table();
		
		
		//+-------------------------------
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'view'     ),
												  2 => array( 'act'   , 'spiderlog'       ),
									     )      );
		
		$SKIN->td_header[] = array( "&nbsp;"  , "40%" );
		$SKIN->td_header[] = array( "&nbsp;"  , "60%" );
		
		$ADMIN->html .= $SKIN->start_table( "检索搜索引擎日志" );
			
		//+-------------------------------
		
		$ADMIN->html .= $SKIN->add_td_row( array( "<b>搜索...</b>" ,
										  		  $SKIN->form_input( "search_string").'... 于查询字串中'
								 )      );
		
		$ADMIN->html .= $SKIN->end_form("Search");
										 
		$ADMIN->html .= $SKIN->end_table();
		
		//+-------------------------------
		//+-------------------------------
		
		$ADMIN->output();
	
	}
	
	
	
}


?>