A-A+

dedecms 百度ping 增强功能版 修改方法

2014年09月09日 13:16 学习笔记 暂无评论 阅读 303 views 次

【注意:此文章为博主原创文章!转载需注意,请带原文链接,至少也要是txt格式!】

最近在用这个织梦的百度ping插件,觉得不是太完善,自己完善了一下,下面是ping.RPC2.php源码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
 
class ping_RPC2{
 
	var $url;
	var $param1;
	var $param2;
	var $param3;
	var $param4;
	var $xml,$headers;
 
	function makexml(){
		$this->xml = '<?xml version="1.0" encoding="UTF-8"?><methodCall>
			<methodName>weblogUpdates.extendedPing</methodName>
			<params>
				<param>
					<value><string>'.$this->param1.'</string></value>
				</param>
				<param>
					<value><string>'.$this->param2.'</string></value>
				</param>
				<param>
					<value><string>'.$this->param3.'</string></value>
				</param>
				<param>
					<value><string>'.$this->param4.'</string></value>
				</param>
			</params>
		</methodCall>';
	}
 
	function headers(){
		$this->headers = array( 
			"POST ".$this->url." HTTP/1.0",
			"User-Agent: request",
			"Content-type: text/xml; charset=\"utf-8\"", 
			"Accept: text/xml", 
			"Content-length: ".strlen($this->xml) 
		);
	}
 
	function ping(){
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $this->url);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_HEADER, 1);
		curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $this->xml);
		$output = curl_exec($ch);
		curl_close($ch);
		return $output;
	}
 
	function dedeping($id){
		global $dsql,$cfg_basehost,$cfg_cmspath,$cfg_multi_site,$cfg_ping_urls;
		$id = intval($id);
		$time = time();
		$one = GetOneArchive($id);
		$arcurl = $cfg_multi_site=='Y'?$one['arcurl']:$cfg_basehost.$one['arcurl'];
		$this->param1 = $one['title'];		
		$this->param2 = $cfg_basehost;		
		$this->param3 = $arcurl;		
		$this->param4 = $cfg_basehost.$cfg_cmspath.'/sitemap.xml';
		$dsql->ExecuteNoneQuery("insert into #@__pinglog (aid, status, uptime) values ($id, 1, $time)");
		$urls = explode("\n",$cfg_ping_urls);
		foreach($urls as $key => $url){
			$this->url = trim($url);
			$this->makexml();
			$this->headers();
			$rs = $this->ping();
			if(strpos($rs,'200 OK')===false){
				$dsql->ExecuteNoneQuery("update #@__pinglog set status=0 where aid=$id");
			}
			if(strpos($rs,'<int>0</int>')==true){  //此处增加了一个判断,如果成功就把成功的URL地址入库。
				$dsql->ExecuteNoneQuery("update #@__pinglog set	pingurl='$arcurl' where aid=$id");
			}
		}
	}
 
}
 
if(defined('DEDEADMIN') || mt_rand(0,10)==0){
	$test_install = DEDEDATA."/module/f8386d67d2a0abe1340f31168481c175-readme.php";
	if(is_file($test_install)){
		$pgr = $dsql->GetOne("select * from #@__pinglog order by aid desc");
		if($pgr){
			$pgr_max_aid = $pgr['aid'];
			$pgr_dedeping = $dsql->GetOne("select * from #@__arctiny where id>$pgr_max_aid AND arcrank=0 order by id asc");
		}else{
			$pgr_dedeping = $dsql->GetOne("select * from #@__arctiny where arcrank=0 order by id desc");
		}
		if($pgr_dedeping){
			$rpc = new ping_RPC2;
			$rpc->dedeping($pgr_dedeping['id']);
		}
	}
}

下面是数据库

1
2
3
4
5
6
7
CREATE TABLE IF NOT EXISTS `dede_pinglog` (
  `aid` int(11) NOT NULL AUTO_INCREMENT,
  `uptime` int(11) DEFAULT NULL,
  `status` tinyint(1) DEFAULT NULL,
  `pingurl` varchar(250) DEFAULT NULL,
  PRIMARY KEY (`aid`)
) ENGINE=MyISAM  DEFAULT CHARSET=gbk AUTO_INCREMENT=1 ;

数据库只是多增加了一个pingurl的字段。

这里是修改模板模板位置后台模板文件夹的ping_log.htm这个文件:

{dede:field.title/}

更改为

{dede:field.title/}:{dede:field.pingurl/}
标签:

给我留言