forked from hacktea8/q_v_o_d_p_2_p
/
function.php
executable file
·243 lines (230 loc) · 6.38 KB
/
function.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<?php
define('ROOTPATH',$APPPATH.'../');
//include_once($APPPATH.'../db.class.php');
//include_once($APPPATH.'../model.php');
require_once ROOTPATH.'phpCurl.php';
$apicurl = new phpCurl();
$apicurl->config['cookie'] = 'cookie_api';
//$model=new Model();
function trimBOM ($contents) {
$charset = array();
$charset[1] = substr($contents, 0, 1);
$charset[2] = substr($contents, 1, 1);
$charset[3] = substr($contents, 2, 1);
if (ord($charset[1]) == 239 && ord($charset[2]) == 187 && ord($charset[3]) == 191) {
return substr($contents, 3);
}
return $contents;
}
/*
获取配对的标签的内容
*/
function getTagpair(&$str,&$string,$head,$end,$same){
$str='';
$start=stripos($string, $head);
if($start===false){
return false;
}
//第一个包含head标签位置的剩下字符串
$string=substr($string,$start);
//第一次结尾的end标签的位置
$start=stripos($string, $end)+strlen($end);
if($start===false){
return false;
}
$str=substr($string,0,$start);
$others=substr($string, $start+1);
//开始标签出现的次数
$count_head=substr_count($str,$same);
//结束标签出息的次数
$count_tail=substr_count($str, $end);
//echo $others,exit;
while($count_head!=$count_tail &&$count_tail){
//$start=stripos($others, $same);
$length=stripos($others, $end)+strlen($end);
$str.=substr($others, 0,$length);
$others=substr($others, $length);
$count_head=substr_count($str,$same);
$count_tail=substr_count($str, $end);
}
}
/*
*/
function getsubcatelist(&$subcate){
global $model;
$subcate=$model->getsubcatelist();
}
function getlastgrabinfo($mode=1,$config=array()){
global $lastgrab,$cateid,$pageno;
if($mode){
if(!file_exists($lastgrab)){
return false;
}
include($lastgrab);
return true;
}
$text="<?php\r\n";
$text.="\$cateid=$config[cateid];\r\n";
$text.="\$pageno=$config[pageno];\r\n";
file_put_contents($lastgrab,$text);
return true;
}
function getCatearticle($pid=0){
if(!$pid){
return false;
}
global $model,$_root,$cid;
$cateList=$model->getCateInfoBypid($pid);
foreach($cateList as $cate){
if($cate['id']!=$cateid &&$flag){
continue;
}
if($cate['id']==$cateid){
$flag=false;
}
$cateurl=$_root.$cate['url'];
$cid=$cate['id'];
$status = getinfolist($cateurl);
if(6 == $status){
break;
}
sleep(30);
}
}
function getSubCatearticle($cate){
global $_root,$cid;
$cateurl = $_root.$cate['ourl'];
$cid = $cate['cid'];
getinfolist($cateurl);
}
function addCateByname($name,$pid,$ourl){
global $apicurl,$POST_API;
$url = $POST_API.'addCateByname';
$apicurl->config['url'] = $url;
$apicurl->postVal = array(
'cate_info' => json_encode(array('name'=>$name,'pid' => $pid, 'ourl' => $ourl))
);
$html = $apicurl->getHtml();
$return = json_decode($html,1);
return $return;
}
function checkArticleByOname($oname){
global $apicurl,$POST_API;
$url = $POST_API.'checkArticleByOname';
$apicurl->config['url'] = $url;
$apicurl->postVal = array(
'oname' => $oname
);
$html = $apicurl->getHtml();
$return = json_decode($html,1);
//var_dump($return);exit;
return $return;
}
function addArticleVols($data){
global $apicurl,$POST_API;
$url = $POST_API.'addArticleVols';
$apicurl->config['url'] = $url;
$apicurl->postVal = array(
'article_data' => json_encode($data)
);
$html = $apicurl->getHtml();
return json_decode($html,1);
}
function addArticle($data){
global $apicurl,$POST_API;
$url = $POST_API.'addArticleInfo';
$apicurl->config['url'] = $url;
$apicurl->postVal = array(
'article_data' => json_encode($data)
);
$error = json_last_error();
if($error){
var_dump($data);exit;
}
$html = $apicurl->getHtml();
//var_dump($html);exit;
return json_decode($html,1);
}
function getHtml($url){
global $http_proxy,$http_header;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36');
if($http_proxy){
//curl_setopt($curl, CURLOPT_PROXY ,"http://$http_proxy");
curl_setopt($curl, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($curl, CURLOPT_PROXY ,$http_proxy);
curl_setopt($curl, CURLOPT_PROXYTYPE, 7);
}
//curl_setopt($curl,CURLOPT_HTTPHEADER,$http_header);
curl_setopt($curl,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
curl_setopt($curl, CURLOPT_HEADER, 0);
// curl_setopt($curl, CURLOPT_COOKIEFILE, 'cookie/cookie.txt '); //读取
// curl_setopt($curl, CURLOPT_COOKIEJAR, 'cookie/cookie.txt '); //保存
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$tmpInfo = curl_exec($curl);
//var_dump($tmpInfo);exit;
if(curl_errno($curl)){
echo 'error ',curl_error($curl),"\r\n";
return false;
}
curl_close($curl);
return $tmpInfo;
}
function jsary2phpary($jsarray){
$data = preg_replace("/\]/",")",$jsarray);
$data = preg_replace("/\[/","(",$data);
$data = preg_replace("/\(/","array(",$data);
eval("\$aa = ".$data.';');
return $aa;
}
function unicode_encode($name)
{
$name = iconv('UTF-8', 'UCS-2', $name);
$len = strlen($name);
$str = '';
for ($i = 0; $i < $len - 1; $i = $i + 2)
{
$c = $name[$i];
$c2 = $name[$i + 1];
if (ord($c) > 0)
{ // 两个字节的文字
$str .= '\u'.base_convert(ord($c), 10, 16).base_convert(ord($c2), 10, 16);
}
else
{
$str .= $c2;
}
}
return $str;
}
// 将UNICODE编码后的内容进行解码,编码后的内容格式:YOKA\u738b (原始:YOKA王)
function unicode_decode($name)
{
// 转换编码,将Unicode编码转换成可以浏览的utf-8编码
$pattern = '/([\w]+)|(\\\u([\w]{4}))/i';
preg_match_all($pattern, $name, $matches);
if (!empty($matches))
{
$name = '';
for ($j = 0; $j < count($matches[0]); $j++)
{
$str = $matches[0][$j];
if (strpos($str, '\\u') === 0)
{
$code = base_convert(substr($str, 2, 2), 16, 10);
$code2 = base_convert(substr($str, 4), 16, 10);
$c = chr($code).chr($code2);
$c = iconv('UCS-2', 'UTF-8', $c);
$name .= $c;
}
else
{
$name .= $str;
}
}
}
return $name;
}
?>