<?php
require_once(dirname(__FILE__)."/../inc/common.php");
defined('IN_DJCMS') or exit('Access Denied');
//升级服务器，如果有变动，请到 http://www.djcms.net 查询
$updateUrl = "http://www.djcms.net/update/djcms";
$versionXml ="http://www.djcms.net/update/djcms/djcmsver3.0.xml";
$selfMenuXml ="imgs/selfmenu.xml";
$customMenuXml ="imgs/custommenu.xml";
$menuList = getBigMenuInfo(0);

function viewFoot() {
	echo "<div align=center>";
	echo getRunTime();
	echo "</div><div align=center >Copyright 2005-2011 All rights reserved. <a target=\"_blank\" href=\"http://www.djcms.net/\">DjCms3.0</a></div>" .chr(10). "</body>" .chr(10). "</html>";
}

function viewHead($str){
	checkPower();
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gbk" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<TITLE><?=$str?>-DjCms后台管理</TITLE>
<link href="imgs/admin.css" rel="stylesheet" type="text/css" />
<script src="../js/common.js" type="text/javascript"></script>
<script src="imgs/main.js" type="text/javascript"></script>
<style type="text/css">
.btn{border:1px solid;border-color:#fff #999 #999 #fff;}
</style>
</head>
<body>
<?php
}

function getBigMenuInfo($level) {
	switch (intval($level)) {
		case "0" :
			$bigMenu[0][0]='首页' ; $bigMenu[0][1]='common' ; $bigMenu[0][2]='index.php?action=notice';
			$bigMenu[1][0]="数据" ; $bigMenu[1][1]="content" ; $bigMenu[1][2]="admin_video.php?action=else";
			$bigMenu[2][0]="模板" ; $bigMenu[2][1]="template" ; $bigMenu[2][2]="admin_template.php?action=main";
			$bigMenu[3][0]="生成" ; $bigMenu[3][1]="make" ; $bigMenu[3][2]="admin_makehtml.php?action=main";
			$bigMenu[4][0]="工具" ; $bigMenu[4][1]="tool" ; $bigMenu[4][2]="admin_datarelate.php?action=repeat";
			$bigMenu[5][0]="广告" ; $bigMenu[5][1]="ads" ; $bigMenu[5][2]="admin_ads.php?action=main";
			$bigMenu[6][0]="采集" ; $bigMenu[6][1]="gathersoft" ; $bigMenu[6][2]="admin_collect.php?action=main";
			$bigMenu[7][0]="扩展" ; $bigMenu[7][1]="webhelper" ; $bigMenu[7][2]="admin_gbook.php?action=comment&where=gbook";
			$bigMenu[8][0]="系统" ; $bigMenu[8][1]="system" ; $bigMenu[8][2]="admin_config.php";
			break;
		case "1" :
			$bigMenu[0][0]="数据管理" ; $bigMenu[0][1]="common" ; $bigMenu[0][2]="admin_video.php?action=else";
			break;
	}
	return $bigMenu;
}

function getSmallMenuInfo($level) {
	switch (intval($level)) {
		case 0:
			$smallMenu[0]="后台首页,index.php?action=notice|快捷菜单,admin_selfmenu.php|".getSelfMenu(0);
			$smallMenu[1]="资源采集管理,admin_reslib.php|临时表管理,admin_tempvideo.php||分类管理,admin_type.php||数据管理,admin_video.php?action=else|添加数据,admin_video.php?action=add|连载管理,admin_video.php?m_state=ok|推荐管理,admin_video.php?m_commend=ok|数据回收站,admin_video.php?action=recycle||专题管理,admin_topic.php||新闻分类,admin_newstype.php|新闻管理,admin_news.php|新闻添加,admin_news.php?action=add|新闻回收站,admin_news.php?action=recycle||报错数据,admin_gbook.php?action=reporterror&where=reporterror";
			$smallMenu[2]="模板管理,admin_template.php?action=main|管理自定义模板,admin_template.php?action=custom||自定义标签,admin_selflabel.php||标签向导,admin_labelguide.php";
			$smallMenu[3]="生成选项,admin_makehtml.php?action=main||生成百度地图,admin_makehtml.php?action=baidu|生成谷歌地图,admin_makehtml.php?action=google|生成RSS,admin_makehtml.php?action=rss";
			$smallMenu[4]="重复数据检测,admin_datarelate.php?action=repeat|数据批量替换,admin_datarelate.php?action=batch|删除指定来源,admin_datarelate.php?action=delvideoform|批量设置点击量,admin_datarelate.php?action=randomset||无效图片清除,admin_datarelate.php?action=checkpic||SQL高级助手,admin_datarelate.php?action=sql||数据库备份,admin_database.php|数据库还原,admin_database.php?action=restore|数据库优化,admin_database.php?action=repair";
			$smallMenu[5]="广告管理,admin_ads.php?action=main|添加广告,admin_ads.php?action=add||友情链接,admin_link.php";
			$smallMenu[6]="视频项目列表,admin_collect.php?action=main|添加视频项目,admin_collect.php?action=wizard|视频分类转换,admin_collect.php?action=customercls|视频地区转换,admin_collect.php?action=cregion|视频信息过滤,admin_collect.php?action=filters|视频采集数据库,admin_collect.php?action=tempdatabase||新闻项目列表,admin_collectnews.php?action=main|添加新闻项目,admin_collectnews.php?action=wizard|新闻分类转换,admin_collectnews.php?action=customercls|新闻信息过滤,admin_collectnews.php?action=filters|新闻采集数据库,admin_collectnews.php?action=tempdatabase";
			$smallMenu[7]="留言管理,admin_gbook.php?action=comment&where=gbook|回复留言,../gbook.php|视频评论管理,admin_comment.php?action=comment&where=1|新闻评论管理,admin_comment.php?action=comment&where=2|幻灯片管理,admin_expand.php";
			$smallMenu[8]="网站配置,admin_config.php||播放器设置,admin_player.php|播放来源管理,admin_player.php?action=boardsource||系统账号管理,admin_manager.php";
			break;
		case 1:
		    $smallMenu[0]="后台首页,index.php?action=notice|快捷菜单,admin_selfmenu.php|数据管理,admin_video.php?action=else|添加数据,admin_video.php?action=add|生成选项,admin_makehtml.php?action=main|".getSelfMenu(1);
			break;
	}
	return $smallMenu;
}

function getSelfMenu($level) {
	global $selfMenuXml,$customMenuXml;
	$path=$selfMenuXml;
	if ($level==1) $path=$customMenuXml;
	$xml = file_get_contents($path);
	$nodes=getrulevaluearr($xml,'menu');
	foreach($nodes as $v){
		$menuName = StrSlice($v,'<name><![CDATA[',']]></name>');
		$menuLink = StrSlice($v,'<link><![CDATA[',']]></link>');
		if (!empty($menuName) && !empty($menuLink)){
			$menuStr.=$menuName.",".$menuLink."|";
		}else{
			$menuStr.="|";
		}
	}
	if (!empty($menuStr)) return rtrim("|".$menuStr,'|');
}

function checkPower() {
	$loginValidate = "djcms";
	$row = DB::fetch_first("SELECT m_username,m_random,m_level FROM ".DB::table('manager')." WHERE m_username='".getcookie("m_username")."'");
	if (!is_array($row)) { 
	    clearPower();die("");
	} else {
	    $loginValidate = md5(getAgent().getIp().$row['m_random']);
	    if (getcookie("check".getcookie("m_username")) != $loginValidate){
		   clearPower();die("");
	    }
	    checkManagerLevel($row['m_level']);
	}
}

function selfManageDir() {
	if ($_SERVER["SERVER_PORT"]<>"80"){
        $dir = "http://".$_SERVER['SERVER_NAME']. ":" .$_SERVER["SERVER_PORT"]. $_SERVER['SCRIPT_NAME'];
    } else {
    	$dir = "http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME'];
	}
	$strt = explode('/',$dir);$l = count($strt)-2;
	$dir = $strt[$l]."/";
	return $dir;
}

function checkManagerLevel($level) {
	$curUrl = $_SERVER['SCRIPT_NAME'];
	if ((strpos($curUrl, "admin_video.php") == 0) && (strpos($curUrl, "index.php") == 0) && (strpos($curUrl, "admin_ajax.php") == 0) && (strpos($curUrl, "admin_webgather.php") == 0) && (strpos($curUrl, "admin_makehtml.php") == 0) && (strpos($curUrl, "admin_selfmenu.php") == 0)) {
		if (intval($level) != 0) alertMsg("没有权限","index.php");
    }
}

function clearPower() {
	dsetcookie("check".getcookie("m_username"));
	dsetcookie("m_username");
	dsetcookie("m_id");
	dsetcookie("m_level");
	dsetcookie("loginflag");
	echo "<script>top.location.href='index.php?action=login';</script>";
}

function getReferedId($str) {
	if (isExistStr($str,"优酷")) return "youku";
	if (isExistStr($str,"土豆")) return "tudou";
	if (isExistStr($str,"搜狐")) return "sohu";
	if (isExistStr($str,"新浪")) return "iask";
	if (isExistStr($str,"qq")) return "qq";
	if (isExistStr($str,"ku6视频")) return "ku6";
	if (isExistStr($str,"FLV")) return "flv";
	if (isExistStr($str,"SWF")) return "swf";
	if (isExistStr($str,"real")) return "real";
	if (isExistStr($str,"media")) return "media";
	if (isExistStr($str,"qvod")) return "qvod";
	if (isExistStr($str,"迅播高清")) return "gvod";
	if (isExistStr($str,"闪播Pvod")) return "pvod";
	if (isExistStr($str,"皮皮影音")) return "pipi";
	if (isExistStr($str,"奇艺")) return "qiyi";
	if (isExistStr($str,"激动")) return "joy";
	if (isExistStr($str,"百度影音")) return "bdhd";
	if (isExistStr($str,"久久影音")) return "web9";
	if (isExistStr($str,"PPTV视频")) return "pptv";
	if (isExistStr($str,"乐视视频")) return "letv";
}

function downSinglePic($picUrl,$vid,$vname,$filePath,$infotype) {
	if ($infotype=="") $spanstr=""; else $spanstr="<br/>";
	if (empty($picUrl) || substr($picUrl,0,7) != 'http://') {
		echo "数据<font color=red>".$vname."</font>的图片路径错误1,请检查是否有效  ".$spanstr;
		return false;
	}
	$fileext = getFileFormat($filePath);
	$ps = explode("/",$picUrl);
	$filename = $ps[count($ps)-1];
	if (strpos($picUrl, ".ykimg.com/") > 0) {
		$fileext = ".gif";
		$filePath = $filePath.$fileext;
	}
	if (!empty($fileext) && strpos("|.jpg|.gif|.png|.bmp|.jpeg|",strtolower($fileext)) > 0) {
		if (!(strpos($picUrl, ".ykimg.com/") > 0)) {
			if (empty($filename) || strpos(' '.$filename,'www.') > 0 || strpos($filename,".") == 0) {
				echo "数据<font color=red>".$vname."</font>的图片路径错误2,请检查是否有效  ".$spanstr;
				return false;
			}
		}
		$imgStream = getRemoteContent($picUrl);
		$createStreamFileFlag = createTextFile($imgStream,$filePath);
		if ($createStreamFileFlag) {
			$streamLen = strlen($imgStream);
			if ($streamLen < 2048) {
				echo "数据<font color=red>".$vname."</font>的图片下载发生错误5,请检查是否有效  ".$spanstr;
				return false;
			} else {
				echo "数据<font color=red>".$vname."</font>的图片下载成功,大小为<font color=red>".number_format($streamLen/1024,2)."</font>KB <a target=_blank href=../".$filePath.">预览图片</a>  ".$spanstr;
				return true;
			}
		} else {
			if (empty($vid)) {
				echo "数据<font color=red>".$vname."</font>的图片下载发生错误3,请检查是否有效  ".$spanstr;
				return false;
			} else {
				echo "数据<font color=red>".$vname."</font>的图片下载发生错误4,id为<font color=red>".$vid."</font>,请检查是否有效  ".$spanstr;
				return false;
			}
		}
	} else {
		echo "数据<font color=red>".$vname."</font>的图片下载发生错误6,图片格式不对  ".$spanstr;
		return false;
	}
}

function gatherIntoLibTransfer($data, $str, $typeset) {
	$str1 = $data;$str2 = $str;
	$transtr = '';
	if ($str1 != '' && $str2 != ''){
		switch ($typeset) {
			case 0: //智能覆盖
				$str1Array = explode("$$$",$str1);$str2Array = explode("$$$",$str2);$m = count($str1Array);$n = count($str2Array);
				for ($k = 0;$k < $n;$k++) {
					$str2fromarray = explode("$$", $str2Array[$k]);
					$x = findIsExistFrom($str1Array, $str2fromarray[0]);
					if (is_numeric($x)) $str1Array[$x] = $str2Array[$k]; else $transtr .= $str2Array[$k]."$$$";
				}
				for ($j = 0;$j < $m;$j++) {
					$transtr .= $str1Array[$j]."$$$";
				}
				$transtr = rtrim($transtr,"$$$");
			break;
			case 1: //追加为第一个来源
				$transtr = $str."$$$".$data;
			break;
			case 2: //追加为最后一个来源
				$transtr = $data."$$$".$str;
			break;
			case 3: //完全覆盖
				$transtr = $str;
			break;
		}
	} else if ($str1!='' && empty($str2)){
		$transtr=$str1;
	} else if (empty($str1) && $str2!=''){
		$transtr = $str2;
	}
	return $transtr;
}

function findIsExistFrom($array1, $from) {
	$str1 = $array1;$str2 = $from;
	$m = count($str1);
	for ($i = 0;$i < $m;$i++) {
		$array1fromarray = explode("$$",$str1[$i]);
		if (trim($array1fromarray[0]) == trim($str2)) return $i;
	}
	return "";
}

function GetEditor($fname, $fvalue) {
	require 'fckeditor/fckeditor.php';
    $oFCKeditor = new FCKeditor($fname);
    $oFCKeditor->Value = $fvalue;
    $oFCKeditor->Create();
}

function makeTypeOptionSelected($topId, $separateStr, $span="", $compareValue) {
	$tlist = getTypeLists();
	if ($topId != 0){$span .= $separateStr;} else {$span = "";}
	foreach ($tlist as $row) {
		if ($row['m_upid'] == $topId) {
			if ($row['m_id'] == $compareValue){$selectedStr = " selected";} else {$selectedStr = "";}
			echo "<option value='".$row['m_id']."'".$selectedStr.">".$span."&nbsp;|—".$row['m_name']."</option>";
			makeTypeOptionSelected($row['m_id'], $separateStr, $span, $compareValue);
		}
	}
}

function makenewsTypeOptionSelected($topId, $separateStr, $span="", $compareValue="") {
	$tlist = getNewsTypeLists();
	if ($topId != 0){$span .= $separateStr;} else {$span = "";}
	foreach ($tlist as $row) {
		if ($row['m_upid'] == $topId) {
			if ($row['m_id'] == $compareValue){$selectedStr = " selected";} else {$selectedStr = "";}
			echo "<option value='".$row['m_id']."'".$selectedStr.">".$span."&nbsp;|—".$row['m_name']."</option>";
			makeTypeOptionSelected($row['m_id'], $separateStr, $span, $compareValue);
		}
	}
}

function isCurrentDay($timeStr) {
	if (empty($timeStr)) return "";
	if (date("Y-m-d", $timeStr) == date("Y-m-d", time())) {
		return "<span style='color:red;font-size:10px'>".date('Y-m-d H:i:s',$timeStr)."</span>";
	} else {
		return "<span style='font-size:10px'>".date('Y-m-d H:i:s',$timeStr)."</span>";
	}
}

function fPageCount($TotalResult, $numPerPage, $Page) {
    $NaviLength = '10' ;
	$showMorePageGo_Type_ = 1;
    $int_showNumberLink_ = '十';
    $nonLinkColor_ = "#999999"; 
    $toF_ = "<font face=webdings title='首页'>9</font>" ;
    $toP10_ = " <font face=webdings title='上十页'>7</font>";
    $toP1_ = " <font face=webdings title='上一页'>3</font>";
    $toN1_ = " <font face=webdings title='下一页'>4</font>";
    $toN10_ = " <font face=webdings title='下十页'>8</font>"; 
    $toL_ = "<font face=webdings title='最后一页'>:</font>"; 
    $page_index = "";
	
    $tpagecount = ceil($TotalResult / $numPerPage);
	$nowCoolPage = ceil($Page/$NaviLength);
    $toPage_ = $_SERVER['QUERY_STRING'];
    if ($toPage_ == '' ) {
       $toPage_ = "?page=";
    } else {
       $toPage_ = preg_replace("/&?page=\d+/", '', $toPage_);
       $toPage_ = "?".$toPage_."&page=";
    }
	if ($nowCoolPage == 1) {
        $page_index .= "<font color=".$nonLinkColor_." title='首页'>".$toF_."</font> ";
        $page_index .= "<font color=".$nonLinkColor_." title='上".$int_showNumberLink_."页'>".$toP10_."</font> ";
    } else {
        $preRow =  $Page-$NaviLength;
		$page_index .= "<a href=".$toPage_."1 title='首页'>".$toF_."</a> ";
		$page_index .= "<a href=".$toPage_.$preRow." title='上".$int_showNumberLink_."页'>".$toP10_."</a> ";
    } 
    $upRow   = $Page - 1;
    $downRow = $Page + 1;
    if ($upRow > 0) {
       $page_index .= "<a href=".$toPage_.$upRow." title='上一页'>".$toP1_."</a> ";
    } else {
       $page_index .= "<font color=".$nonLinkColor_." title='上一页'>".$toP1_."</font> ";
    } 
     
	for ($i = 1;$i <= $NaviLength;$i++) {
         $nowPage = ($nowCoolPage-1)*$NaviLength+$i;
         if ($nowPage != $Page) {
             if ($nowPage <= $tpagecount) {
                 $page_index .= "  <a href=".$toPage_.$nowPage.">" .$nowPage. "</a> ";
             } else {
                 break;
             }
         } else {
             if ($tpagecount != 1) {
                $page_index .= "<b>".$nowPage."</b>";
             }
         }
      }
     if ($downRow <= $tpagecount) {
         $page_index .= "<a href=".$toPage_.$downRow." title='下一页'>".$toN1_."</a> ";
     } else {
         $page_index .= "<font color=".$nonLinkColor_." title='下一页'>".$toN1_."</font> ";
     }
     if ($Page >= $tpagecount) {
         $page_index .= " <font color=".$nonLinkColor_." title='下".$int_showNumberLink_."页'>".$toN10_."</font> ";
         $page_index .= "<font color=".$nonLinkColor_." title='尾页'>".$toL_."</font>";
     } else {
         $nextRow = $Page+$NaviLength;
         $theEndRow = $tpagecount;
         $page_index .= " <a href=".$toPage_.$nextRow." title='下".$int_showNumberLink_."页'>".$toN10_."</a> ";
         $page_index .= "<a href=".$toPage_.$theEndRow." title='尾页'>".$toL_."</a>";
     }

    if ($showMorePageGo_Type_ == 1) {
        $Show_Page_i = $Page + 1 ;
    if ($Show_Page_i > $tpagecount) $Show_Page_i = 1; 
	    $page_index .= "&nbsp;&nbsp;<input type=\"text\" size=\"4\" maxlength=\"10\" name=\"Func_Input_Page\" onmouseover=\"this.focus();\" onfocus=\"this.value='$Show_Page_i';\" onKeyUp=\"value=value.replace(/[^0-9]/g,'')\" onbeforepaste=\"clipboardData.setData('text',clipboardData.getData('text').replace(/[^0-9]/g,''))\">&nbsp;&nbsp;<input type=\"button\" value=\"Go\" class=\"btn\" onmouseover=\"Func_Input_Page.focus();\" onclick=\"javascript:var Js_JumpValue;Js_JumpValue=document.all.Func_Input_Page.value;if(Js_JumpValue=='' || !isNaN(Js_JumpValue)) location='$toPage_'+Js_JumpValue; else location='".$toPage_."1';\">\n";
    } else {
        $page_index .= " 跳转:<select name='select' size='1' style='font-size: 12px' onchange='javascript:window.location.href=this.options[this.selectedIndex].value'>"; 
        for ($i = 1;$i <= $tpagecount;$i++) {
	       if ($Page == $i) {
	           $selected = " selected";
	       } else {
	           $selected = "";
           }
           $page_index .= " <option value=".$toPage_.$i; 
           $page_index .= $selected." style='color:#FF0000'"; 
           $page_index .= ">第".$i."页</option>";
       }
       $page_index .= "</select>";

   }
        $page_index .= "  每页<b>".$numPerPage."</b>个记录，现在是:<b><span class='tx'>".$Page."</span>/".$tpagecount."</b>页，共<b><span id='recordcount'>".$TotalResult."</span></b>个记录。"; 
    return $page_index; 
}

function getAreaSelect($selectName, $strSelect, $areaId) {
    // 加载Xml文件 
	$xml = file_get_contents(DJ_ROOT."inc/areaKinds.xml");
	// 获取所有的area标签 
	$nodes = getruleval($xml,'area');
	$str = "<select name='".$selectName."' >";
	if (!empty($strSelect)) $str .= "<option value=''>".$strSelect."</option>";
	foreach($nodes as $v){ 
		$area = StrSlice($v,'<area>','</area>');
		if(!empty($areaId) && ($area == $areaId)) $str .= "<option value='".$area."' selected>$area</option>";
		$str .= "<option value='".$area."'>$area</option>";
	}
	$str .= "</select>";
	return $str;
}

function makePlayerSelect($flag) {
    // 加载Xml文件 
	$xml = file_get_contents(DJ_ROOT."inc/playerKinds.xml");
    // 获取所有的post标签
	$nodes = getruleval($xml,'player');
	foreach($nodes as $v){
		$vstr = StrSlice($v,'flag="','"');
		$des = StrSlice($v,'des="','"');
	    if($flag == $vstr) {
			 $selectstr = " selected";
	    } else {
			 $selectstr = "";
	    }
		$allstr .= "<option value='$vstr'$selectstr>$vstr--$des</option>";
	}
	return $allstr;
}

function makeDownSelect($flag) {
    // 加载Xml文件 
	$xml = file_get_contents(DJ_ROOT."inc/downKinds.xml");
    // 获取所有的post标签
	$nodes = getruleval($xml,'source');
	foreach($nodes as $v){
		$vstr = StrSlice($v,'flag="','"');
		$des = StrSlice($v,'des="','"');
	    if ($flag == $vstr) {
			$selectstr = " selected";
	    } else {
			$selectstr = "";
	    }
		$allstr .= "<option value='$vstr'$selectstr>$vstr--$des</option>";
	}
	return $allstr;
}

function repairUrlForm($vstr, $formstr) {
	foreach($vstr as $k=>$v){
		$vstr[$k] = replaceStr($v, ",", "@");
    }
	$strlen = count($vstr);
	$formlen  = count($formstr);
	$rstr = '';
	if ($strlen != $formlen) {
		die("未为每个数据选择数据来源");
	} else {
		foreach ($vstr as $k => $v) {
		    if (trim($v)<>"") $rstr = $rstr.repairStr($v, getReferedId($formstr[$k])).", "; else $rstr = $rstr.", ";
	    }
	}
	return rtrim($rstr, ", ");
}

function repairDownUrl($vstr, $formstr) {
	$strlen = count($vstr);
	$formlen  = count($formstr);
	$rstr = "";
	if ($strlen != $formlen) {
		die("未为每个下载项选择数据来源");
	} else {
		foreach ($vstr as $k => $v) {
			 if (trim($v)<>"") $rstr = $rstr.repairStr($v, "down").", "; else $rstr = $rstr.", ";
	    }
	}
	return rtrim($rstr,", ");
}

function repairStr($vstr, $playfrom) {
	$vstr = str_replace(chr(10), "", $vstr);
	$vstr = explode(chr(13), $vstr);
	$stru = "";
	foreach ($vstr as $j => $playurl) {
	    $strurl = explode('$', $playurl);
	    $i = count($strurl);
	    if ($i == 1) {
	        $jj = $j + 1;
	        $stru = $stru.'第'.$jj.'集$'.$playurl.'$'.$playfrom.chr(13).chr(10);
	    } else if($i == 2) {
	        $stru = $stru.$playurl.'$'.$playfrom.chr(13).chr(10);
	    } else {
	        $stru = $stru.$playurl.chr(13).chr(10);
	    }
	}
    return $stru;
}

function transferUrl($fromStr, $playStr) {
	if (empty($fromStr) && empty($playStr)) return "";
	$resultStr = "";
	$fromStr = replaceStr($fromStr, "$$", "") ; $playStr = replaceStr(replaceStr($playStr, "#", ""), "$$", "");
	$playStr = replaceStr($playStr, chr(10), "");
	$playStr = replaceStr($playStr, chr(13), "#");
	$playStr = rtrim($playStr, "#");
	$playStr = rtrim($playStr, ",");
	$fromArray = $fromStr ; $fromLen = count($fromArray);
	$playArray = explode(", ", $playStr) ; $playLen = count($playArray);
	if ($fromLen<>$playLen) die("来源或者地址没有填写完整");
	if ($fromLen == 0) {
		$transferUrl = trim($fromArray[0])."$$".trim($playArray[0]);return  $transferUrl;
    }
	for ($i = 1;$i <= $fromLen;$i++) {
		$j = $i - 1;
		if (!empty($fromArray[$i]) &&  !empty($playArray[$j])) {
			$resultStr = trim($resultStr).trim($fromArray[$i])."$$".trim(rtrim($playArray[$j], "#"))."$$$";
        } else if(empty($fromArray[$i]) &&  !empty($playArray[$j])) {
			die("来源没有填写完整");
        }
    }
	$resultStr = replaceStr($resultStr, "@", ",");
	return rtrim($resultStr, "$$$");
}
?>