Overview

Packages

  • None
  • WxRobot
    • Admin
    • Cmd
    • CoreFunctions
    • Exends
    • Install
    • Table
    • Uninstall
    • WxSDK

Classes

  • ErrorCode
  • PKCS7Encoder
  • Prpcrypt
  • SHA1
  • Weixin_BaseCore
  • WeiXin_SDK
  • Weixin_Template
  • WXBizMsgCrypt
  • WxRobot_Admin
  • WxRobot_Admin_Menu_Extends
  • WxRobot_Admin_Menu_Instro
  • WxRobot_Admin_Menu_Menu
  • WxRobot_Admin_Menu_Records
  • WxRobot_Admin_Menu_Reply
  • WxRobot_Admin_Menu_Setting
  • WxRobot_Admin_Menu_Statistics
  • WxRobot_Cmd
  • WxRobot_Cmd_Event
  • WxRobot_Cmd_Event_User
  • WxRobot_Cmd_Text
  • WxRobot_Extends
  • WxRobot_Install
  • WxRobot_Robot
  • WxRobot_SDK
  • WxRobot_Table_Extends
  • WxRobot_Table_Menu
  • WxRobot_Table_Records
  • WxRobot_Table_Reply
  • WxRobot_Uninstall
  • WxRobot_Wp
  • XMLParse

Functions

  • wx_admin_log
  • wx_is_xml
  • wx_notice_msg
  • wx_parse_xml
  • wx_random_big_pic
  • wx_random_small_pic
  • wx_request_array
  • wx_request_decode
  • wx_request_is_encode
  • wx_request_xml
  • wx_send_encode
  • Overview
  • Package
  • Class
  1: <?php
  2: /**
  3:  * WxRobot_Wp WordPress文章查询相关功能
  4:  *
  5:  * @author      midoks
  6:  * @category    WxRobot
  7:  * @package     WxRobot/Table
  8:  * @since       5.3.0
  9:  */
 10: 
 11: /**
 12:  * WxRobot_Wp WordPress文章查询相关功能
 13:  */
 14: class WxRobot_Wp{
 15: 
 16: 
 17:     public $opt_big_show = array();
 18:     public $opt_small_show = array();
 19: 
 20: 
 21:     /**
 22:      * 构造函数
 23:      */
 24:     public function __construct(){
 25:         //最优图片选择是否开启
 26:         $this->options  = get_option(WEIXIN_ROBOT_OPTIONS);
 27:         $this->obj      = WxRobot_SDK::instance();
 28:         
 29:         if($this->options['opt_pic_show']){
 30:             $this->opt_pic_sign = true;
 31:             $this->option_pic_to_array();
 32: 
 33:         }else{
 34:             $this->opt_pic_sign = false;
 35:         }
 36:     }
 37: 
 38:     /**
 39:      * Table Extends Instance
 40:      */
 41:     public static $_instance = null;
 42:     
 43:     /**
 44:      * WxRobot 扩展表类实例化
 45:      * 
 46:      * @return WxRobot_Table_Extends - Table Extends instance
 47:      */
 48:     public static function instance(){
 49:         if( is_null (self::$_instance)){
 50:             self::$_instance = new self();
 51:         }
 52:         return self::$_instance;
 53:     }
 54: 
 55:     /**
 56:      * 把配置中图片变成变为数据处理
 57:      * 
 58:      * @return void
 59:      */
 60:     public function option_pic_to_array(){
 61:         //小图
 62:         $small = $this->options['opt_small_show'];
 63:         if(!empty($small)){
 64:             $this->opt_small_show = false;
 65:         }
 66:         $s_arr = explode("\r\n", $small);
 67:         $tmp = array();
 68:         foreach($s_arr as $k=>$v){
 69:             $tmp[] = trim($v);
 70:         }
 71:         $this->opt_small_show = $tmp;
 72:         //大图
 73:         $big = $this->options['opt_big_show'];
 74:         if(!empty($big)){
 75:             $this->opt_big_show = false;
 76:         }
 77:         $s_arr = explode("\r\n", $big);
 78:         $tmp = array();
 79:         foreach($s_arr as $k=>$v){
 80:             $tmp[] = trim($v);
 81:         }
 82:         $this->opt_big_show = $tmp;
 83:     }
 84: 
 85:     /**
 86:      * 对中文名的图片路径进行urlencode编码
 87:      *
 88:      * @return string $thumb 图片路径
 89:      * @return string
 90:      */
 91:     public function path_url_encode($thumb){
 92:         $pos = strrpos($thumb,'/');
 93:         return substr($thumb, 0,$pos+1).urlencode(substr($thumb, $pos+1));
 94:     }
 95: 
 96:     /**
 97:      * 获取文章中的图片
 98:      *
 99:      * @param string $c 文章内容
100:      * @param string $type 图片类型
101:      * @return string
102:      */
103:     public function get_opt_pic($c, $type){
104:         $u2 = '/(<img[^>]+src\s*=\s*\"?([^>\"\s]+)\"?[^>]*>)/im';
105:         //echo $u2;
106:         $p_sign = preg_match($u2 ,$c, $match);
107:         if($p_sign){
108:             return $this->path_url_encode($match[2]);
109:         }
110: 
111:         //上面执行过,选择默认自定义的图片
112:         if('small' == $type){
113:             $num = count($this->opt_small_show);
114:             $t = $num - 1;
115:             $mt = mt_rand(0, $t);
116:             if($num){
117:                 return $this->opt_small_show[$mt];
118:             }
119:         }else if('big' == $type){
120:             $num = count($this->opt_big_show);
121:             $t = $num - 1;
122:             $mt = mt_rand(0, $t);
123:             if($num){
124:                 return $this->opt_big_show[$mt];
125:             }
126:         }
127:         return false;
128:     }
129: 
130: 
131:     /**
132:      *  获取最优图片地址
133:      *
134:      *  @param string $content 文章内容
135:      *  @return string
136:      */
137:     public function get_opt_pic_small($content = ''){
138:         if($this->opt_pic_sign){
139:             $pic = $this->get_opt_pic($content, 'small');
140:             if(!empty($pic)){
141:                 return $pic;
142:             }
143:         }
144:         return wx_random_small_pic();
145:     }
146: 
147:     /**
148:      *  获取最优图片地址
149:      *
150:      *  @param string $content 文章内容
151:      *  @return string
152:      */
153:     public function get_opt_pic_big($content = ''){
154:         if($this->opt_pic_sign){
155:             $pic = $this->get_opt_pic($content, 'big');
156:             if(!empty($pic)){
157:                 return $pic;
158:             }
159:         }
160:         return wx_random_big_pic();
161:     }
162: 
163:     /**
164:      * 对每个第一条消息,进行处理字符截取
165:      * 
166:      * @param string $c
167:      * @return string
168:      */
169:     public function head_one_line($c){  
170:         $c = html_entity_decode($c, ENT_NOQUOTES, 'utf-8');
171:         $c = strip_tags($c);
172:         $c = mb_substr($c, 0, 50, 'utf-8').'...';
173:         return $c;
174:     }
175: 
176: 
177:     /**
178:      * 指定文章回复
179:      *
180:      * @param int $id 文章的ID
181:      * @return array
182:      */
183:     public function Qid($id){
184:         query_posts('p='.$id);
185:         $info = array();
186:         $i = 0;
187:         while(have_posts()){the_post();
188:             ++$i;
189:             if($i==1){
190:                 $a['title'] = get_the_title();
191:                 $a['desc'] = $this->head_one_line(get_the_content());
192:                 $a['pic'] = $this->get_opt_pic_big(get_the_content());
193:                 $a['link'] = get_permalink();
194:             }else{
195:                 $a['title'] = get_the_title();
196:                 $a['desc'] = get_the_title();
197:                 $a['pic'] = $this->get_opt_pic_small(get_the_content());
198:                 $a['link'] = get_permalink();
199:             }
200:             $info[] = $a;
201:         }
202:         if(!empty($info)){
203:             return $this->obj->toMsgTextPic($info);//图文
204:         }else{
205:             return false;
206:         }
207:     }
208: 
209:     /**
210:      * 指定文章回复
211:      *
212:      * @param int $id 文章的ID
213:      * @return array
214:      */
215:     public function QidResult($id){
216:         $wp = new WP_query('p='.$id);
217:         $info = array();
218:         
219:         while($wp->have_posts()){$wp->the_post();
220:             $a['title'] = get_the_title();
221:             $a['desc'] = get_the_content();
222:             $a['pic'] = get_the_content();
223:             $a['link'] = get_permalink();
224:             $info = $a;
225:         }
226:         return $info;
227:     }
228: 
229: 
230:     /**
231:      * 指定文章回复
232:      *
233:      * @param array $id 文章的ID
234:      * @return array
235:      */
236:     public function Qids($id){
237:         $string = array();
238:         $i = 0;
239:         foreach($id as $k){
240:             $res = $this->QidResult($k);
241:             if($res){
242:                 ++$i;
243:                 if(1 == $i){
244:                     $a['title'] = $res['title'];
245:                     $a['desc'] = $this->head_one_line($res['desc']);
246:                     $a['pic'] = $this->get_opt_pic_big($res['desc']);
247:                     $a['link'] = $res['link'];
248:                 }else{
249:                     $a['title'] = $res['title'];
250:                     $a['desc'] = $res['desc'];
251:                     $a['pic'] = $this->get_opt_pic_small($res['desc']);
252:                     $a['link'] = $res['link'];
253:                 }
254:             }
255:             $string[] = $a;
256:         }
257:         return $this->obj->toMsgTextPic($string);//图文
258:     }
259: 
260:     /**
261:      * 获取今日发布的文章
262:      *
263:      * @return xml
264:      */
265:     public function today(){
266:         $sql = 'showposts=10'.'&year='.date('Y').'&monthnum='.date('m').'&day='.date('d');
267:         $wp = new WP_query($sql);
268:         $info = array();
269:         $i = 0;
270:         while($wp->have_posts()){$wp->the_post();
271:             ++$i;
272:             if($i==1){
273:                 $a['title'] = get_the_title();
274:                 $a['desc'] = $this->head_one_line(get_the_content());
275:                 $a['pic'] = $this->get_opt_pic_big(get_the_content());
276:                 $a['link'] = get_permalink();
277:             }else{
278:                 $a['title'] = get_the_title();
279:                 $a['desc'] = get_the_title();
280:                 $a['pic'] = $this->get_opt_pic_small(get_the_content());
281:                 $a['link'] = get_permalink();
282:             }
283:             $info[] = $a;
284:         }
285:         if(empty($info)){
286:             return $this->obj->toMsgText('今日暂未发表文章!!!');
287:         }
288:         return $this->obj->toMsgTextPic($info);//图文
289:     }
290: 
291:     /**
292:      * 获取最热文章
293:      * 
294:      * @param int $int 数量
295:      * @return xml
296:      */
297:     public function hot($int){
298:         $wp = new WP_query(array(
299:             'post_status' => 'publish',     //选择公开的文章
300:             'post_not_in' => array(),       //排除当前文章
301:             'ignore_sticky_posts'=> 1,      //排除顶置文章
302:             'orderby' => 'comment_count',   //依据评论排序
303:             'showposts' => $int,            //调用的数量
304:         ));
305:         $info = array();
306:         $i = 0;
307:         while($wp->have_posts()){$wp->the_post();
308:             ++$i;
309:             if($i==1){
310:                 $a['title'] = get_the_title();
311:                 $a['desc'] = $this->head_one_line(get_the_content());
312:                 $a['pic'] = $this->get_opt_pic_big(get_the_content());
313:                 $a['link'] = get_permalink();
314:             }else{
315:                 $a['title'] = get_the_title();
316:                 $a['desc'] = get_the_title();
317:                 $a['pic'] = $this->get_opt_pic_small(get_the_content());
318:                 $a['link'] = get_permalink();
319:             }
320:             $info[] = $a;
321:         }
322:         return $this->obj->toMsgTextPic($info);//图文
323:     }
324: 
325:     
326:     /**
327:      * 获取最新文章
328:      * 
329:      * @param int $int 数量
330:      * @return xml
331:      */
332:     public function news($int){
333:         $wp = new WP_query('showposts='.$int);
334:         $info = array();
335:         $i = 0;
336:         while($wp->have_posts()){$wp->the_post();
337:             ++$i;
338:             if($i==1){
339:                 $a['title'] = get_the_title();
340:                 $a['desc'] = $this->head_one_line(get_the_content());
341:                 $a['pic'] = $this->get_opt_pic_big(get_the_content());
342:                 $a['link'] = get_permalink();
343:             }else{
344:                 $a['title'] = get_the_title();
345:                 $a['desc'] = get_the_title();
346:                 $a['pic'] = $this->get_opt_pic_small(get_the_content());
347:                 $a['link'] = get_permalink();
348:             }
349:             $info[] = $a;
350:         }
351:         return $this->obj->toMsgTextPic($info);//图文
352:     }
353: 
354:     /**
355:      * 获取随机文章
356:      * 
357:      * @param int $int 数量
358:      * @return xml
359:      */
360:     public function rand($int){
361:         $wp = new WP_query("showposts={$int}&orderby=rand");
362:         $info = array();
363:         $i = 0;
364:         while($wp->have_posts()){$wp->the_post();
365:             ++$i;
366:             if($i==1){
367:                 $a['title'] = get_the_title();
368:                 $a['desc'] = $this->head_one_line(get_the_content());
369:                 $a['pic'] = $this->get_opt_pic_big(get_the_content());
370:                 $a['link'] = get_permalink();
371:             }else{
372:                 $a['title'] = get_the_title();
373:                 $a['desc'] = get_the_title();
374:                 $a['pic'] = $this->get_opt_pic_small(get_the_content());
375:                 $a['link'] = get_permalink();
376:             }
377:             $info[] = $a;
378:         }
379:         return $this->obj->toMsgTextPic($info);//图文
380:     }
381: 
382: 
383: }
384: ?>
385: 
API documentation generated by ApiGen