diff --git a/src/apps/rss.php b/src/apps/rss.php
new file mode 100644
index 00000000..f20620c1
--- /dev/null
+++ b/src/apps/rss.php
@@ -0,0 +1,17 @@
+Display();
+?>
\ No newline at end of file
diff --git a/src/system/archive/rssview.class.php b/src/system/archive/rssview.class.php
new file mode 100644
index 00000000..209bff10
--- /dev/null
+++ b/src/system/archive/rssview.class.php
@@ -0,0 +1,210 @@
+TypeID = $typeid;
+ $this->dtp = new DedeTagParse();
+ $this->dtp->refObj = $this;
+ $templetfiles = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/plus/rss.htm";
+ $this->dtp->LoadTemplate($templetfiles);
+ $this->dsql = $GLOBALS['dsql'];
+ $this->TypeLink = new TypeLink($typeid);
+ $this->TypeFields = $this->TypeLink->TypeInfos;
+ $this->MaxRow = $max_row;
+ $this->TypeFields['title'] = $this->TypeLink->GetPositionLink(false);
+ $this->TypeFields['title'] = preg_replace("/[<>]/", " / ", $this->TypeFields['title']);
+ $this->TypeFields['typelink'] = $GLOBALS['cfg_basehost'].$this->TypeLink->GetOneTypeUrl($this->TypeFields);
+ $this->TypeFields['powerby'] = $GLOBALS['cfg_powerby'];
+ $this->TypeFields['adminemail'] = $GLOBALS['cfg_adminemail'];
+ $this->remoteDir = '';
+ foreach ($this->TypeFields as $k => $v) {
+ $this->TypeFields[$k] = dede_htmlspecialchars($v);
+ }
+ $this->ParseTemplet();
+ }
+ //php4构造函数
+ function RssView($typeid, $max_row = 50)
+ {
+ $this->__construct($typeid, $max_row);
+ }
+ //关闭相关资源
+ function Close()
+ {
+ }
+ /**
+ * 显示列表
+ *
+ * @access public
+ * @return void
+ */
+ function Display()
+ {
+ $this->dtp->Display();
+ }
+ /**
+ * 开始创建列表
+ *
+ * @access public
+ * @param string $isremote 是否远程
+ * @return string
+ */
+ function MakeRss($isremote = 0)
+ {
+ $murl = $GLOBALS['cfg_cmspath']."/static/rss/".$this->TypeID.".xml";
+ $mfile = $GLOBALS['cfg_basedir'].$murl;
+ $this->dtp->SaveTo($mfile);
+ return $murl;
+ }
+ /**
+ * 解析模板
+ *
+ * @access public
+ * @return void
+ */
+ function ParseTemplet()
+ {
+ foreach ($this->dtp->CTags as $tid => $ctag) {
+ if ($ctag->GetName() == "field") {
+ $this->dtp->Assign($tid, $this->TypeFields[$ctag->GetAtt('name')]);
+ } else if ($ctag->GetName() == "rssitem") {
+ $this->dtp->Assign(
+ $tid,
+ $this->GetArcList($ctag->GetInnerText())
+ );
+ }
+ }
+ }
+ /**
+ * 获得文档列表
+ *
+ * @access public
+ * @param string $innertext 底层模板
+ * @return string
+ */
+ function GetArcList($innertext = "")
+ {
+ $typeid = $this->TypeID;
+ $innertext = trim($innertext);
+ if ($innertext == "") {
+ $innertext = GetSysTemplets("rss.htm");
+ }
+ $orwhere = " arc.arcrank > -1 ";
+ $orwhere .= " AND (arc.typeid in (".GetSonIds($this->TypeID, $this->TypeFields['channeltype']).") ) ";
+ $ordersql = " ORDER BY arc.id desc";
+ $query = "SELECT arc.*,tp.typedir,tp.typename,tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath FROM `#@__archives` arc LEFT JOIN `#@__arctype` tp ON arc.typeid=tp.id WHERE $orwhere $ordersql LIMIT 0,".$this->MaxRow;
+ $this->dsql->SetQuery($query);
+ $this->dsql->Execute('al');
+ $artlist = '';
+ $dtp2 = new DedeTagParse();
+ $dtp2->SetNameSpace('field', '[', ']');
+ $dtp2->LoadSource($innertext);
+ while ($row = $this->dsql->GetArray('al')) {
+ //处理一些特殊字段
+ if ($row['litpic'] == '-' || $row['litpic'] == '') {
+ $row['litpic'] = $GLOBALS['cfg_cmspath'].'/static/web/img/thumbnail.jpg';
+ }
+ if (!preg_match("/^http:\/\//", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y') {
+ $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];
+ }
+ $row['picname'] = $row['litpic'];
+ $row["arcurl"] = GetFileUrl(
+ $row["id"],
+ $row["typeid"],
+ $row["senddate"],
+ $row["title"],
+ $row["ismake"],
+ $row["arcrank"],
+ $row["namerule"],
+ $row["typedir"],
+ $row["money"],
+ $row['filename'],
+ $row["moresite"],
+ $row["siteurl"],
+ $row["sitepath"]
+ );
+ $row["typeurl"] = GetTypeUrl(
+ $row["typeid"],
+ $row["typedir"],
+ $row["isdefault"],
+ $row["defaultname"],
+ $row["ispart"],
+ $row["namerule2"],
+ $row["moresite"],
+ $row["siteurl"],
+ $row["sitepath"]
+ );
+ $row["info"] = $row["description"];
+ $row["filename"] = $row["arcurl"];
+ $row["stime"] = GetDateMK($row["pubdate"]);
+ $row["image"] = "
";
+ $row["fullurl"] = $GLOBALS["cfg_basehost"].$row["arcurl"];
+ if ($GLOBALS['cfg_multi_site'] == 'Y') $row["fullurl"] = $row["arcurl"];
+ $row["phpurl"] = $GLOBALS["cfg_plus_dir"];
+ $row["templeturl"] = $GLOBALS["cfg_templets_dir"];
+ if ($row["source"] == '') {
+ $row["source"] = $GLOBALS['cfg_webname'];
+ }
+ if ($row["writer"] == '') {
+ $row["writer"] = "张生";
+ }
+ foreach ($row as $k => $v) {
+ $row[$k] = dede_htmlspecialchars($v);
+ }
+ if (is_array($dtp2->CTags)) {
+ foreach ($dtp2->CTags as $k => $ctag) {
+ if ($ctag->GetName() == 'array') {
+ //传递整个数组,在runphp模式中有特殊作用
+ $dtp2->Assign($k, $row);
+ } else {
+ if (isset($row[$ctag->GetName()])) {
+ $dtp2->Assign($k, $row[$ctag->GetName()]);
+ } else {
+ $dtp2->Assign($k, '');
+ }
+ }
+ }
+ }
+ $artlist .= $dtp2->GetResult()."\r\n";
+ }
+ $this->dsql->FreeResult('al');
+ return $artlist;
+ }
+}//End Class
+?>
\ No newline at end of file
diff --git a/src/system/common.func.php b/src/system/common.func.php
index 59675228..37a4fa7b 100755
--- a/src/system/common.func.php
+++ b/src/system/common.func.php
@@ -420,6 +420,71 @@ function IsSSL()
}
return false;
}
+//获取对应版本号的更新SQL
+function GetUpdateSQL()
+{
+ global $cfg_dbprefix,$cfg_dbtype,$cfg_db_language;
+ $result = array();
+ $query = '';
+ $sql4tmp = "ENGINE=MyISAM DEFAULT CHARSET=".$cfg_db_language;
+ $fp = fopen(DEDEROOT.'/install/update.txt','r');
+ $sqls = array();
+ $current_ver = "";
+ while(!feof($fp))
+ {
+ $line = rtrim(fgets($fp,1024));
+ if (preg_match("/\-\- ([\d\.]+)/",$line,$matches)) {
+ if (count($sqls) > 0) {
+ $result[$current_ver] = $sqls;
+ }
+ $sqls = array();
+ $current_ver = $matches[1];
+ }
+ if (preg_match("#;$#", $line))
+ {
+ $query .= $line."\n";
+ $query = str_replace('#@__',$cfg_dbprefix,$query);
+ if ( $cfg_dbtype == 'sqlite' )
+ {
+ $query = preg_replace('/character set (.*?) /i','',$query);
+ $query = preg_replace('/unsigned/i','',$query);
+ $query = str_replace('TYPE=MyISAM','',$query);
+ $query = preg_replace ('/TINYINT\(([\d]+)\)/i','INTEGER',$query);
+ $query = preg_replace ('/mediumint\(([\d]+)\)/i','INTEGER',$query);
+ $query = preg_replace ('/smallint\(([\d]+)\)/i','INTEGER',$query);
+ $query = preg_replace('/int\(([\d]+)\)/i','INTEGER',$query);
+ $query = preg_replace('/auto_increment/i','PRIMARY KEY AUTOINCREMENT',$query);
+ $query = preg_replace('/,([\t\s ]+)KEY(.*?)MyISAM;/','',$query);
+ $query = preg_replace('/,([\t\s ]+)KEY(.*?);/',');',$query);
+ $query = preg_replace('/,([\t\s ]+)UNIQUE KEY(.*?);/',');',$query);
+ $query = preg_replace('/set\(([^\)]*?)\)/','varchar',$query);
+ $query = preg_replace('/enum\(([^\)]*?)\)/','varchar',$query);
+ if ( preg_match("/PRIMARY KEY AUTOINCREMENT/",$query) )
+ {
+ $query = preg_replace('/,([\t\s ]+)PRIMARY KEY([\t\s ]+)\(`([0-9a-zA-Z]+)`\)/i','',$query);
+ }
+ $sqls[] = $query;
+ // $db->exec($query);
+ } else {
+ if (preg_match('#CREATE#i', $query))
+ {
+ $sqls[] = preg_replace("#TYPE=MyISAM#i",$sql4tmp,$query);
+ } else {
+ $sqls[] = $query;
+ }
+ }
+ $query='';
+ } else if (!preg_match("#^(\/\/|--)#", $line))
+ {
+ $query .= $line;
+ }
+ }
+ if (count($sqls) > 0) {
+ $result[$current_ver] = $sqls;
+ }
+ fclose($fp);
+ return $result;
+}
//用户名称标签{dede:field.mid function="GetMemberInfos('uname',@me)"/}和[field:mid function="GetMemberInfos('uname',@me)"/]
function GetMemberInfos($fields, $mid)
{
@@ -451,7 +516,7 @@ function face($mid)
}
return $face;
}
-//调用标签[field:id function='GetMyTags(@me,2)'/]2表示输出2个文档
+//标签调用标签[field:id function='GetMyTags(@me,2)'/]2表示输出2个文档
if (!function_exists('GetMyTags')) {
function GetMyTags($aid, $num=3) {
global $dsql,$cfg_cmspath;
@@ -465,7 +530,7 @@ if (!function_exists('GetMyTags')) {
return $tags;
}
}
-/*调用主题模板*/
+/*用户中心调用默认模板*/
if (!function_exists('pasterTempletDiy')) {
function pasterTempletDiy($path) {
global $cfg_basedir,$cfg_templets_dir,$cfg_df_style;
@@ -486,7 +551,7 @@ function litimgurls($imgid = 0)
$lit_imglist = $ChannelUnit->GetlitImgLinks($row['imgurls']);
return $lit_imglist;
}
-//字符过滤函数安全
+//联动单筛选字符过滤函数
function string_filter($str, $stype = "inject")
{
if ($stype == "inject") {
@@ -507,7 +572,7 @@ function string_filter($str, $stype = "inject")
}
return $str;
}
-//联动单筛选自定义表单发布
+//联动单筛选发布三种类型
function AddFilter($channelid, $type=1, $fieldsnamef=array(), $defaulttid=0, $toptid=0, $loadtype='autofield')
{
global $tid, $dsql, $id, $aid;
@@ -517,53 +582,53 @@ function AddFilter($channelid, $type=1, $fieldsnamef=array(), $defaulttid=0, $to
$tidsq = $dsql->GetOne("SELECT * FROM `#@__archives` WHERE id='$arcid'");
$tid = $toptid==0 ? $tidsq["typeid"] : $tidsq["topid"];
}
- $fieldsnamef = count($fieldsnamef) > 0 ? implode(",", $fieldsnamef) : $fieldsnamef;
$nofilter = (isset($_REQUEST['TotalResult']) ? "&TotalResult=".$_REQUEST['TotalResult'] : '').(isset($_REQUEST['PageNo']) ? "&PageNo=".$_REQUEST['PageNo'] : '');
- $filterarr = string_filter(stripos($_SERVER['REQUEST_URI'], "list.php?tid=") ? str_replace($nofilter, '', $_SERVER['REQUEST_URI']) : $GLOBALS['cfg_cmsurl']."/apps/list.php?tid=".$tid);
- $cInfos = $dsql->GetOne("SELECT * FROM `#@__channeltype` WHERE id='$channelid'");
+ $filterarr = string_filter(stripos($_SERVER['REQUEST_URI'], "list.php?tid=") ? str_replace($nofilter, '', $_SERVER['REQUEST_URI']) : $GLOBALS['cfg_cmsurl']."/plus/list.php?tid=".$tid);
+ $cInfos = $dsql->GetOne("SELECT * FROM `#@__channeltype` WHERE id='$channelid'");
$fieldset=$cInfos['fieldset'];
$dtp = new DedeTagParse();
$dtp->SetNameSpace('field', '<', '>');
$dtp->LoadSource($fieldset);
$dede_addonfields = '';
- if(is_array($dtp->CTags)) {
+ if (is_array($dtp->CTags)) {
foreach($dtp->CTags as $tida=>$ctag)
{
$fieldsname = $fieldsnamef ? explode(",", $fieldsnamef) : explode(",", $ctag->GetName());
- if(($loadtype!='autofield' || ($loadtype=='autofield' && $ctag->GetAtt('autofield')==1)) && in_array($ctag->GetName(), $fieldsname) ) {
+ if (($loadtype!='autofield' || ($loadtype=='autofield' && $ctag->GetAtt('autofield')==1)) && in_array($ctag->GetName(), $fieldsname)) {
$href1 = explode($ctag->GetName().'=', $filterarr);
$href2 = explode('&', $href1[1]);
$fields_value = $href2[0];
switch ($type) {
case 1:
- $dede_addonfields .= (preg_match("/&".$ctag->GetName()."=/is",$filterarr,$regm) ? 'GetName()."=".$fields_value,"",$filterarr).'" class="btn btn-outline-success btn-sm">全部' : 'GetName()."=".$fields_value,"",$filterarr).'" class="btn btn-outline-success btn-sm">全部');
- $addonfields_items = explode(",",$ctag->GetAtt('default'));
- for ($i=0; $iGetName().'=') ? str_replace("=".$fields_value,"=".urlencode($addonfields_items[$i]),$filterarr) : $filterarr.'&'.$ctag->GetName().'='.urlencode($addonfields_items[$i]);
- $dede_addonfields .= ($fields_value!=urlencode($addonfields_items[$i]) ? ''.$addonfields_items[$i].'' : ''.$addonfields_items[$i].'');
- }
+ $dede_addonfields .= (preg_match("/&".$ctag->GetName()."=/is",$filterarr,$regm) ? 'GetName()."=".$fields_value,"",$filterarr).'" class="btn btn-outline-success btn-sm">全部' : 'GetName()."=".$fields_value,"",$filterarr).'" class="btn btn-success btn-sm">全部');
+ $addonfields_items = explode(",",$ctag->GetAtt('default'));
+ for ($i=0; $iGetName().'=') ? str_replace("=".$fields_value,"=".urlencode($addonfields_items[$i]),$filterarr) : $filterarr.'&'.$ctag->GetName().'='.urlencode($addonfields_items[$i]);
+ $dede_addonfields .= ($fields_value!=urlencode($addonfields_items[$i]) ? ''.$addonfields_items[$i].'' : ''.$addonfields_items[$i].'');
+ }
break;
case 2:
- $dede_addonfields .= '';
break;
case 3:
- $dede_addonfields .= (preg_match("/&".$ctag->GetName()."=/is",$filterarr,$regm) ? 'GetName()."=".$fields_value,"",$filterarr).'" title="全部">GetName()."=".$fields_value,"",$filterarr).'" onclick="window.location=this.value">全部' : '全部');
- $addonfields_items = explode(",",$ctag->GetAtt('default'));
- for ($i=0; $iGetName().'=') ? str_replace("=".$fields_value,"=".urlencode($addonfields_items[$i]),$filterarr) : $filterarr.'&'.$ctag->GetName().'='.urlencode($addonfields_items[$i]);
- $dede_addonfields .= ($fields_value!=urlencode($addonfields_items[$i]) ? ''.$addonfields_items[$i].'' : ''.$addonfields_items[$i].'');
- }
+ $dede_addonfields .= (preg_match("/&".$ctag->GetName()."=/is",$filterarr,$regm) ? 'GetName()."=".$fields_value,"",$filterarr).'">GetName()."=".$fields_value,"",$filterarr).'" onclick="window.location=this.value">全部' : '全部');
+ $addonfields_items = explode(",",$ctag->GetAtt('default'));
+ for ($i=0; $iGetName().'=') ? str_replace("=".$fields_value,"=".urlencode($addonfields_items[$i]),$filterarr) : $filterarr.'&'.$ctag->GetName().'='.urlencode($addonfields_items[$i]);
+ $dede_addonfields .= ($fields_value!=urlencode($addonfields_items[$i]) ? ''.$addonfields_items[$i].'' : ''.$addonfields_items[$i].'');
+ }
break;
}
}
@@ -571,78 +636,8 @@ function AddFilter($channelid, $type=1, $fieldsnamef=array(), $defaulttid=0, $to
}
echo $dede_addonfields;
}
-
-/**
- * 获取对应版本号的更新SQL
- *
- * @return array
- */
-function GetUpdateSQL()
-{
- global $cfg_dbprefix,$cfg_dbtype,$cfg_db_language;
- $result = array();
- $query = '';
- $sql4tmp = "ENGINE=MyISAM DEFAULT CHARSET=".$cfg_db_language;
- $fp = fopen(DEDEROOT.'/install/update.txt','r');
- $sqls = array();
- $current_ver = "";
- while(!feof($fp))
- {
- $line = rtrim(fgets($fp,1024));
- if (preg_match("/\-\- ([\d\.]+)/",$line,$matches)) {
- if (count($sqls) > 0) {
- $result[$current_ver] = $sqls;
- }
- $sqls = array();
- $current_ver = $matches[1];
- }
- if (preg_match("#;$#", $line))
- {
- $query .= $line."\n";
- $query = str_replace('#@__',$cfg_dbprefix,$query);
- if ( $cfg_dbtype == 'sqlite' )
- {
- $query = preg_replace('/character set (.*?) /i','',$query);
- $query = preg_replace('/unsigned/i','',$query);
- $query = str_replace('TYPE=MyISAM','',$query);
- $query = preg_replace ('/TINYINT\(([\d]+)\)/i','INTEGER',$query);
- $query = preg_replace ('/mediumint\(([\d]+)\)/i','INTEGER',$query);
- $query = preg_replace ('/smallint\(([\d]+)\)/i','INTEGER',$query);
- $query = preg_replace('/int\(([\d]+)\)/i','INTEGER',$query);
- $query = preg_replace('/auto_increment/i','PRIMARY KEY AUTOINCREMENT',$query);
- $query = preg_replace('/,([\t\s ]+)KEY(.*?)MyISAM;/','',$query);
- $query = preg_replace('/,([\t\s ]+)KEY(.*?);/',');',$query);
- $query = preg_replace('/,([\t\s ]+)UNIQUE KEY(.*?);/',');',$query);
- $query = preg_replace('/set\(([^\)]*?)\)/','varchar',$query);
- $query = preg_replace('/enum\(([^\)]*?)\)/','varchar',$query);
- if ( preg_match("/PRIMARY KEY AUTOINCREMENT/",$query) )
- {
- $query = preg_replace('/,([\t\s ]+)PRIMARY KEY([\t\s ]+)\(`([0-9a-zA-Z]+)`\)/i','',$query);
- }
- $sqls[] = $query;
- // $db->exec($query);
- } else {
- if (preg_match('#CREATE#i', $query))
- {
- $sqls[] = preg_replace("#TYPE=MyISAM#i",$sql4tmp,$query);
- } else {
- $sqls[] = $query;
- }
- }
- $query='';
- } else if (!preg_match("#^(\/\/|--)#", $line))
- {
- $query .= $line;
- }
- }
- if (count($sqls) > 0) {
- $result[$current_ver] = $sqls;
- }
- fclose($fp);
- return $result;
-}
-
//自定义函数接口
if (file_exists(DEDEINC.'/extend.func.php')) {
require_once(DEDEINC.'/extend.func.php');
}
+?>
\ No newline at end of file
diff --git a/src/system/dedecollection.func.php b/src/system/dedecollection.func.php
new file mode 100644
index 00000000..5376ce08
--- /dev/null
+++ b/src/system/dedecollection.func.php
@@ -0,0 +1,496 @@
+ 100) {
+ break;
+ }
+ $hkey = "";
+ $hvalue = "";
+ $v = 0;
+ for ($i = 0; $i < strlen($line); $i++) {
+ if ($v == 1) {
+ $hvalue .= $line[$i];
+ }
+ if ($line[$i] == ":") {
+ $v = 1;
+ }
+ if ($v == 0) {
+ $hkey .= $line[$i];
+ }
+ }
+ $hkey = trim($hkey);
+ if ($hkey != "") {
+ $m_httphead[strtolower($hkey)] = trim($hvalue);
+ }
+ }
+ //分析返回记录
+ if (preg_match("/^3/", $m_httphead["http-state"])) {
+ if (isset($m_httphead["location"]) && $JumpCount < 3) {
+ $JumpCount++;
+ DownImageKeep($gurl, $rfurl, $filename, $gcookie, $JumpCount);
+ } else {
+ return FALSE;
+ }
+ }
+ if (!preg_match("/^2/", $m_httphead["http-state"])) {
+ return FALSE;
+ }
+ if (!isset($m_httphead)) {
+ return FALSE;
+ }
+ $contentLength = $m_httphead['content-length'];
+ //保存文件
+ $fp = fopen($filename, "w") or die("写入文件:{$filename} 失败");
+ $i = 0;
+ $okdata = "";
+ $starttime = time();
+ while (!feof($m_fp)) {
+ $okdata .= fgetc($m_fp);
+ $i++;
+ //超时结束
+ if (time() - $starttime > $maxtime) {
+ break;
+ }
+ //到达指定大小结束
+ if ($i >= $contentLength) {
+ break;
+ }
+ }
+ if ($okdata != "") {
+ fwrite($fp, $okdata);
+ }
+ fclose($fp);
+ if ($okdata == "") {
+ @unlink($filename);
+ fclose($m_fp);
+ return FALSE;
+ }
+ fclose($m_fp);
+ return TRUE;
+}
+/**
+ * 获得某页面返回的Cookie信息
+ *
+ * @access public
+ * @param string $gurl 调整地址
+ * @return string
+ */
+function RefurlCookie($gurl)
+{
+ global $gcookie, $lastRfurl;
+ $gurl = trim($gurl);
+ if (!empty($gcookie) && $lastRfurl == $gurl) {
+ return $gcookie;
+ } else {
+ $lastRfurl = $gurl;
+ }
+ if (trim($gurl) == '') {
+ return '';
+ }
+ $urlinfos = GetHostInfo($gurl);
+ $ghost = $urlinfos['host'];
+ $gquery = $urlinfos['query'];
+ $sessionQuery = "GET $gquery HTTP/1.1\r\n";
+ $sessionQuery .= "Host: $ghost\r\n";
+ $sessionQuery .= "Accept: */*\r\n";
+ $sessionQuery .= "User-Agent: Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)\r\n";
+ $sessionQuery .= "Connection: Close\r\n\r\n";
+ $errno = "";
+ $errstr = "";
+ $m_fp = fsockopen($ghost, 80, $errno, $errstr, 10) or die($ghost.'
');
+ fwrite($m_fp, $sessionQuery);
+ $lnum = 0;
+ //获取详细应答头
+ $gcookie = "";
+ while (!feof($m_fp)) {
+ $line = trim(fgets($m_fp, 256));
+ if ($line == "" || $lnum > 100) {
+ break;
+ } else {
+ if (preg_match("/^cookie/i", $line)) {
+ $gcookie = $line;
+ break;
+ }
+ }
+ }
+ fclose($m_fp);
+ return $gcookie;
+}
+/**
+ * 获得网址的host和query部份
+ *
+ * @access public
+ * @param string $gurl 调整地址
+ * @return string
+ */
+function GetHostInfo($gurl)
+{
+ $gurl = preg_replace("/^http:\/\//i", "", trim($gurl));
+ $garr['host'] = preg_replace("/\/(.*)$/i", "", $gurl);
+ $garr['query'] = "/".preg_replace("/^([^\/]*)\//i", "", $gurl);
+ return $garr;
+}
+
+/**
+ * HTML里的网址格式转换
+ *
+ * @access public
+ * @param string $body 文档
+ * @return string
+ */
+function TurnLinkTag(&$body)
+{
+ $ttx = '';
+ $handid = '服务器';
+ preg_match_all("/]+?)>(.+?)<\/a>/is", $body, $match);
+ if (is_array($match[1]) && count($match[1]) > 0) {
+ for ($i = 0; isset($match[1][$i]); $i++) {
+ $servername = (isset($match[3][$i]) ? str_replace("'", "`", $match[3][$i]) : $handid.($i + 1));
+ if (preg_match("/[<>]/", $servername) || strlen($servername) > 40) {
+ $servername = $handid.($i + 1);
+ }
+ $ttx .= "{dede:link text='$servername'} {$match[1][$i]} {/dede:link}\r\n";
+ }
+ }
+ return $ttx;
+}
+/**
+ * 替换XML的CDATA
+ *
+ * @access public
+ * @param string $str 字符串
+ * @return string
+ */
+function RpCdata($str)
+{
+ $str = str_replace('', '', $str);
+ return $str;
+}
+/**
+ * 分析RSS里的链接
+ *
+ * @access public
+ * @param string $rssurl rss地址
+ * @return string
+ */
+function GetRssLinks($rssurl)
+{
+ global $cfg_soft_lang;
+ $dhd = new DedeHttpDown();
+ $dhd->OpenUrl($rssurl);
+ $rsshtml = $dhd->GetHtml();
+ //分析编码
+ preg_match("/encoding=[\"']([^\"']*)[\"']/is", $rsshtml, $infos);
+ if (isset($infos[1])) {
+ $pcode = strtolower(trim($infos[1]));
+ } else {
+ $pcode = strtolower($cfg_soft_lang);
+ }
+ if ($cfg_soft_lang == 'gb2312') {
+ if ($pcode == 'utf-8') {
+ $rsshtml = utf82gb($rsshtml);
+ } else if ($pcode == 'big5') {
+ $rsshtml = big52gb($rsshtml);
+ }
+ } else if ($cfg_soft_lang == 'utf-8') {
+ if ($pcode == 'gbk' || $pcode == 'gb2312') {
+ $rsshtml = gb2utf8($rsshtml);
+ } else if ($pcode == 'big5') {
+ $rsshtml = gb2utf8(big52gb($rsshtml));
+ }
+ }
+ $rsarr = array();
+ preg_match_all("/- (.*)<\/title>/isU", $rsshtml, $titles);
+ preg_match_all("/
- (.*)<\/link>/isU", $rsshtml, $links);
+ preg_match_all("/
- (.*)<\/description>/isU", $rsshtml, $descriptions);
+ if (!isset($links[2])) {
+ return '';
+ }
+ foreach ($links[2] as $k => $v) {
+ $rsarr[$k]['link'] = RpCdata($v);
+
+ if (isset($titles[2][$k])) {
+ $rsarr[$k]['title'] = RpCdata($titles[2][$k]);
+ } else {
+ $rsarr[$k]['title'] = preg_replace("/^(.*)\//i", "", RpCdata($titles[2][$k]));
+ }
+ if (isset($descriptions[2][$k])) {
+ $rsarr[$k]['image'] = GetddImgFromRss($descriptions[2][$k], $rssurl);
+ } else {
+ $rsarr[$k]['image'] = '';
+ }
+ }
+ return $rsarr;
+}
+/**
+ * 从RSS摘要获取图片信息
+ *
+ * @access public
+ * @param string $descriptions 描述
+ * @param string $refurl 来源地址
+ * @return string
+ */
+function GetddImgFromRss($descriptions, $refurl)
+{
+ if ($descriptions == '') {
+ return '';
+ }
+ preg_match_all("/
\r\n\t]{1,}/isU", $descriptions, $imgs);
+ if (isset($imgs[2][0])) {
+ $imgs[2][0] = preg_replace("/[\"']/", '', $imgs[2][0]);
+ $imgs[2][0] = preg_replace("/\/{1,}/", '/', $imgs[2][0]);
+ return FillUrl($refurl, $imgs[2][0]);
+ } else {
+ return '';
+ }
+}
+/**
+ * 补全网址
+ *
+ * @access public
+ * @param string $refurl 来源地址
+ * @param string $surl 站点地址
+ * @return string
+ */
+function FillUrl($refurl, $surl)
+{
+ $i = $pathStep = 0;
+ $dstr = $pstr = $okurl = '';
+ $refurl = trim($refurl);
+ $surl = trim($surl);
+ $urls = @parse_url($refurl);
+ $basehost = ((!isset($urls['port']) || $urls['port'] == '80') ? $urls['host'] : $urls['host'].':'.$urls['port']);
+ //$basepath = $basehost.(!isset($urls['path']) ? '' : '/'.$urls['path']);
+ //由于直接获得的path在处理 http://xxxx/nnn/aaa?fdsafd 这种情况时会有错误,因此用其它方式处理
+ $basepath = $basehost;
+ $paths = explode('/', preg_replace("/^http:\/\//i", "", $refurl));
+ $n = count($paths);
+ for ($i = 1; $i < ($n - 1); $i++) {
+ if (!preg_match("/[\?]/", $paths[$i])) $basepath .= '/'.$paths[$i];
+ }
+ if (!preg_match("/[\?\.]/", $paths[$n - 1])) {
+ $basepath .= '/'.$paths[$n - 1];
+ }
+ if ($surl == '') {
+ return $basepath;
+ }
+ $pos = strpos($surl, "#");
+ if ($pos > 0) {
+ $surl = substr($surl, 0, $pos);
+ }
+ //用 '/' 表示网站根的网址
+ if ($surl[0] == '/') {
+ $okurl = $basehost.$surl;
+ } else if ($surl[0] == '.') {
+ if (strlen($surl) <= 2) {
+ return '';
+ } else if ($surl[1] == '/') {
+ $okurl = $basepath.preg_replace('/^./', '', $surl);
+ } else {
+ $okurl = $basepath.'/'.$surl;
+ }
+ } else {
+ if (strlen($surl) < 7) {
+ $okurl = $basepath.'/'.$surl;
+ } else if (preg_match("/^http:\/\//i", $surl)) {
+ $okurl = $surl;
+ } else {
+ $okurl = $basepath.'/'.$surl;
+ }
+ }
+ $okurl = preg_replace("/^http:\/\//i", '', $okurl);
+ $okurl = 'http://'.preg_replace("/\/{1,}/", '/', $okurl);
+ return $okurl;
+}
+/**
+ * 从匹配规则中获取列表网址
+ *
+ * @access public
+ * @param string $regxurl 正则地址
+ * @param string $handurl 操作地址
+ * @param string $startid 开始id
+ * @param string $endid 结束id
+ * @param string $addv 增值
+ * @param string $usemore 使用更多
+ * @param string $batchrule 列表规则
+ * @return string
+ */
+function GetUrlFromListRule($regxurl = '', $handurl = '', $startid = 0, $endid = 0, $addv = 1, $usemore = 0, $batchrule = '')
+{
+ global $dsql, $islisten;
+ $lists = array();
+ $n = 0;
+ $islisten = (empty($islisten) ? 0 : $islisten);
+ if ($handurl != '') {
+ $handurls = explode("\n", $handurl);
+ foreach ($handurls as $handurl) {
+ $handurl = trim($handurl);
+ if (preg_match("/^http:\/\//i", $handurl)) {
+ $lists[$n][0] = $handurl;
+ $lists[$n][1] = 0;
+ $n++;
+ if ($islisten == 1) {
+ break;
+ }
+ }
+ }
+ }
+ if ($regxurl != '') {
+ //没指定(#)和(*)
+ if (!preg_match("/\(\*\)/i", $regxurl) && !preg_match("/\(#\)/", $regxurl)) {
+ $lists[$n][0] = $regxurl;
+ $lists[$n][1] = 0;
+ $n++;
+ } else {
+ if ($addv <= 0) {
+ $addv = 1;
+ }
+ //没指定多栏目匹配规则
+ if ($usemore == 0) {
+ while ($startid <= $endid) {
+ $lists[$n][0] = str_replace("(*)", sprintf('%0'.strlen($startid).'d', $startid), $regxurl);
+ $lists[$n][1] = 0;
+ $startid = sprintf('%0'.strlen($startid).'d', $startid + $addv);
+ $n++;
+ if ($n > 2000 || $islisten == 1) {
+ break;
+ }
+ }
+ }
+ //匹配多个栏目
+ //规则表达式 [(#)=>(#)匹配的网址; (*)=>(*)的范围,如:1-20; typeid=>栏目id; addurl=>附加的网址(用|分开多个)]
+ else {
+ $nrules = explode(']', trim($batchrule));
+ foreach ($nrules as $nrule) {
+ $nrule = trim($nrule);
+ $nrule = preg_replace("/^\[|\]$/", '', $nrule);
+ $nrules = explode(';', $nrule);
+ if (count($nrules) < 3) {
+ continue;
+ }
+ $brtag = '';
+ $startid = 0;
+ $endid = 0;
+ $typeid = 0;
+ $addurls = array();
+ foreach ($nrules as $nrule) {
+ $nrule = trim($nrule);
+ list($k, $v) = explode('=>', $nrule);
+ if (trim($k) == '(#)') {
+ $brtag = trim($v);
+ } else if (trim($k) == 'typeid') {
+ $typeid = trim($v);
+ } else if (trim($k) == 'addurl') {
+ $addurl = trim($v);
+ $addurls = explode('|', $addurl);
+ } else if (trim($k) == '(*)') {
+ $v = preg_replace("/[ \r\n\t]/", '', trim($v));
+ list($startid, $endid) = explode('-', $v);
+ }
+ }
+ //如果栏目用栏目名称
+ if (preg_match('/[^0-9]/', $typeid)) {
+ $arr = $dsql->GetOne("SELECT id FROM `#@__arctype` WHERE typename LIKE '$typeid' ");
+ if (is_array($arr)) {
+ $typeid = $arr['id'];
+ } else {
+ $typeid = 0;
+ }
+ }
+ //附加网址优先
+ $mjj = 0;
+ if (isset($addurls[0])) {
+ foreach ($addurls as $addurl) {
+ $addurl = trim($addurl);
+ if ($addurl == '') {
+ continue;
+ }
+ $lists[$n][0] = $addurl;
+ $lists[$n][1] = $typeid;
+ $n++;
+ $mjj++;
+ if ($islisten == 1) {
+ break;
+ }
+ }
+ }
+ //如果为非监听模式或监听模式没手工指定的附加网址
+ if ($islisten != 1 || $mjj == 0) {
+ //匹配规则里的网址,注:(#)的网址是是允许使用(*)的
+ while ($startid <= $endid) {
+ $lists[$n][0] = str_replace("(#)", $brtag, $regxurl);
+ $lists[$n][0] = str_replace("(*)", sprintf('%0'.strlen($startid).'d', $startid), $lists[$n][0]);
+ $lists[$n][1] = $typeid;
+ $startid = sprintf('%0'.strlen($startid).'d', $startid + $addv);
+ $n++;
+ if ($islisten == 1) {
+ break;
+ }
+ if ($n > 20000) {
+ break;
+ }
+ }
+ }
+ }
+ } //End 匹配多栏目
+ } //End使用规则匹配的情况
+ }
+ return $lists;
+}//End
+?>
\ No newline at end of file