This repository has been archived by the owner on Dec 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathfunctions.php
113 lines (94 loc) · 2.44 KB
/
functions.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
<?php
function custom_excerpt_length( $length ) {
return 100;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
/* no use for get_the_excerpt
function new_excerpt_more( $more ) {
return '[.....]';
}
add_filter('excerpt_more', 'new_excerpt_more');
*/
/**
*
* 返回摘要,50个汉字加省略号
*
* @raw_excerpt 由调用函数传来的未经处理的excerpt
*
*/
function wechat_get_excerpt($raw_excerpt) {
$excerpt = wp_strip_all_tags( $raw_excerpt );
$excerpt = trim( preg_replace( "/[\n\r\t ]+/", ' ', $excerpt ), ' ' );
$excerpt = mb_substr($excerpt, 0, 50, 'utf8');
$excerpt = $excerpt . '...';
return $excerpt;
}
/**
*
* 返回post缩略图
*
*/
function wechat_get_thumb( $post, $size ){
$thumbnail_id = get_post_thumbnail_id($post->ID);
if ( $thumbnail_id ) {
$thumb = wp_get_attachment_image_src($thumbnail_id, $size);
$thumb = $thumb[0];
}
if (empty($thumb)) {
$thumb = 'http://www.freebuf.com/buf/themes/freebuf/images/logo2.jpg';
}
return $thumb;
}
/**
* GET 请求
* @param string $url
* @return string $result
*/
function http_get($url) {
$oCurl = curl_init();
if(stripos($url,"https://")!==FALSE) {
curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false);
}
curl_setopt($oCurl, CURLOPT_URL, $url);
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($oCurl);
$status = curl_getinfo($oCurl);
curl_close($oCurl);
if(intval($status["http_code"])==200)
return $result;
return $status["http_code"];
}
/**
* POST 请求
* @param string $url
* @param array $param
* @return string $result
*/
function http_post($url, $param) {
$oCurl = curl_init();
if(stripos($url,"https://")!==FALSE){
curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false);
}
if (is_string($param)) {
$strPOST = $param;
} else {
$aPOST = array();
foreach($param as $key=>$val) {
$aPOST[] = $key."=".urlencode($val);
}
$strPOST = join("&", $aPOST);
}
curl_setopt($oCurl, CURLOPT_URL, $url);
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($oCurl, CURLOPT_POST,true);
curl_setopt($oCurl, CURLOPT_POSTFIELDS,$strPOST);
$result = curl_exec($oCurl);
$status = curl_getinfo($oCurl);
curl_close($oCurl);
if(intval($status["http_code"])==200)
return $result;
return $status["http_code"];
}
?>