<?php
$jt = new jt;
class jt {
	//切换城市
	function bus_all(){
		$arr=loadcache("bus/prvArr.txt");
		$zt='';
		foreach($arr as $k=>$v){
			$tmp='';
			foreach($v as $kk=>$vv){
				$tmp.="<a href=index.php?{$kk}.html>{$vv}</a> ";
			}
			$zt.="<li><span>{$k}：</span>{$tmp}</li>\n";
		}
		return $zt;
	}
	//线路url
	function lineurl($v){
		global $city,$rewrite;
		$url=curl($v);
		if($rewrite){
			return "/x_{$city}-{$url}.html";
		}else{
			return "x.php?{$city}-{$url}.html";
		}
	}
	//站点url
	function zdurl($v){
		global $city,$rewrite;
		$url=curl($v);
		if($rewrite){
			return "/z_{$city}-{$url}.html";
		}else{
			return "z.php?{$city}-{$url}.html";
		}
	}
	//相关城市
	function prv_about(){
		global $city,$cityname;
		$arr=loadcache("bus/prvArr.txt");
		$prvname='';
		foreach($arr as $k=>$v){
			if(in_array($cityname,$v)){
				$prvname=$k;
				break;
			}
		}
		if(empty($prvname)) return;
		$tmp='';
		foreach($arr[$prvname] as $k=>$v){
			$tmp.="<a href=index.php?{$k}.html>{$v}</a>";
		}
		return $tmp;
	}
	//热门线路
	function hotline(){
		global $city,$cityname;
		$arr=loadcache("bus/{$city}/line.txt");
		$arr=array_slice($arr,0,20);
		$tmp='';
		foreach($arr as $v){
			$tmp1=$this->lineurl($v);
			$tmp.="<a href={$tmp1}>{$v}</a>";
		}
		return $tmp;
	}
	//热门站点
	function hotzd(){
		global $city,$cityname;
		$arr=loadcache("bus/{$city}/zd.txt");
		$arr=array_slice($arr,0,20);
		$tmp='';
		foreach($arr as $v){
			$tmp1=$this->zdurl($v);
			$tmp.="<a href={$tmp1}>{$v}</a>";
		}
		return $tmp;
	}
	//线路速查
	function line_site(){
		global $city,$cityname;
		$arr=loadcache("bus/{$city}/lineS.txt");
		$tmp='';
		foreach($arr as $v){
			$tmp.="<a href=lineS.php?{$city}-{$v}.html>{$v}</a>";
		}
		return $tmp;
	}
	//站点速查
	function zd_site(){
		global $city,$cityname;
		$arr=loadcache("bus/{$city}/zdS.txt");
		$tmp='';
		foreach($arr as $v){
			$tmp.="<a href=zdS.php?{$city}-{$v}.html>{$v}</a>";
		}
		return $tmp;
	}

	//公交线路名称
	function bus_linename( $tmpline ) {
		if ( substr($tmpline,-3)=="行]") {
			$line=substr($tmpline,0,-6);//去除线路上下行、单行的后缀
		} else {
			$line=$tmpline;
		}
		return $line;
	}
	//线路经过的站点
	function bus_zds( $arr ) {
		global $city;
		$total=count($arr);
		$zt=array();
		foreach ($arr as $v) {
			$zt[]="<a href=".$this->zdurl($v).">{$v}</a>";
		}
		$zt=implode(" → ",$zt);
		$zt="{$zt} <font class=red>(共{$total}站)</font>";
		return $zt;
	}
	//公交线路
	function bus_line(){
		global $city,$cityname,$line;
		$a_all=loadcache("bus/{$city}/a_all.txt");//导入缓存
		$remarks=loadcache("bus/{$city}/remarks.txt");//导入缓存
		if (!empty($a_all[$line.'[上行]'])) {
			$zd1 = $this->bus_zds($a_all[$line.'[上行]']);//经过站点
			$zd2 = $this->bus_zds($a_all[$line.'[下行]']);//经过站点
			$zd="<h4>{$line}[上行]</h4>
				{$zd1}<br/>
				<h4>{$line}[下行]</h4>
				{$zd2}<br/>\n";
		}else{
			$zd = $this->bus_zds($a_all[$line.'[单行]']);//经过站点
			$zd="<h4>[单行]</h4>{$zd} \n";
		}
		$remarks=$remarks[$line];
		$list="<p>{$zd}</p><p>{$remarks}</p>\n";
		return $list;	
	}
	//公交站点
	function bus_zd() {
		global $city,$zd;
		$a_all=loadcache("bus/{$city}/a_all.txt");//导入缓存
		$list="";
		foreach ((array)$a_all as $k=>$v) {
			if(in_array($zd,$v)){//站点在线路中
				$line=$this->bus_linename($k);
				$tmp=$this->bus_zds($v);
				$tmp=str_replace($zd,"<span class=red>{$zd}</span>",$tmp);
				$list.="<h4><a href=".$this->lineurl($line).">{$k}</a></h4>";
				$list.=$tmp;
			}
		}
		return $list;
	}
	//公交数据检查
	function bus_check($xing) {
		$zt=array();
		$zt1=explode("|",$xing);
		foreach ($zt1 as $v) {
			$zt[]=check($v);
		}
		$zt=implode("|",$zt);
		return $zt;
	}
}
?>