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 Table Extends 
  4:  * 
  5:  * WP微信机器人 扩展表的相关功能
  6:  *
  7:  * @author      midoks
  8:  * @category    Table
  9:  * @package     WxRobot/Table
 10:  * @since       5.3.0
 11:  */
 12: 
 13: if ( ! defined( 'ABSPATH' ) ) {
 14:     exit;
 15: }
 16: 
 17: /**
 18:  *  WxRobot_Table_Extends 扩展表模型
 19:  */
 20: class WxRobot_Table_Extends{
 21: 
 22:     /**
 23:      * 表前缀
 24:      */
 25:     public $table_prefix = 'midoks_';
 26: 
 27:     /**
 28:      * Table Extends Instance
 29:      */
 30:     public static $_instance = null;
 31:     
 32: 
 33:     /**
 34:      * WxRobot 扩展表类实例化
 35:      * 
 36:      * @return WxRobot_Table_Extends - Table Extends instance
 37:      */
 38:     public static function instance(){
 39:         if( is_null (self::$_instance)){
 40:             self::$_instance = new self();
 41:         }
 42:         return self::$_instance;
 43:     }
 44: 
 45:     /**
 46:      * 获取所有可用的插件
 47:      * 
 48:      * @return array
 49:      */
 50:     public function get_all_plugins(){
 51:         $a = array();
 52:         if($h = opendir(WEIXIN_PLUGINS)){
 53:             while($f = readdir($h)){
 54:                 if($f =='.' || $f=='..'){
 55:                 }else if(is_file(WEIXIN_PLUGINS.$f)){
 56:                     if('php' == $this->get_file_suffix($f)){
 57:                         $d = WEIXIN_PLUGINS.$f;
 58:                         $data = $this->get_plugins_info($d);
 59:                         if(!$data){
 60:                             continue;
 61:                         }
 62:                         $a['info'][] = $data;
 63:                         $a['abspath'][] = $d;
 64:                         $a['path'][] = $f;
 65:                         $q = explode('_', $f);
 66:                         $a['type'][] = $q[1];
 67:                         $b = explode('.', $f);
 68:                         $a['classname'][] = $b[0];
 69:                     }
 70:                 }
 71:             }
 72:         }
 73:         return $a;
 74:     }
 75: 
 76:     /**
 77:      *  获取插件的信息
 78:      *  
 79:      *  @param string $file 插件位置
 80:      *  @return array
 81:      *  {
 82:      *      extend_name:扩展名称
 83:      *      plugin_url:开发扩展的地址
 84:      *      author: 作者
 85:      *      version:版本信息
 86:      *      email:邮件地址
 87:      *      description: 描述信息
 88:      *  }
 89:      */
 90:     private function get_plugins_info($file){
 91:         $content = file_get_contents($file);
 92:         preg_match('/\/\*(.*?)\*\//is', $content, $info);
 93: 
 94:         if(!isset($info[1])){
 95:             return false;
 96:         }
 97: 
 98:         $e = trim(trim($info[1]), '*');
 99:         $list = explode("\n", $e);
100:         $nString = array();
101: 
102:         foreach($list as $k=>$v){
103:             $tmp = trim(str_replace(array('*', ' '), '', $v));
104:             
105:             //分割":"、 " "
106:             $tmp_E = explode(' ', $tmp, 2);
107:             if(count($tmp_E)<2){
108:                 $tmp_E = explode(':', $tmp, 2);
109:             }
110:             
111:             if(!empty($tmp_E[0])){
112:                 $nString[strtolower($tmp_E[0])] = trim($tmp_E[1]);
113:             }
114:         }
115: 
116:         //扩展名称(必选)
117:         if(!isset($nString['extend_name'])){
118:             return false;
119:         }
120: 
121:         //扩展地址(必选)
122:         if(!isset($nString['extend_url'])){
123:             return false;
124:         }
125: 
126:         //作者昵称(必选)
127:         if(!isset($nString['author'])){
128:             return false;
129:         }
130: 
131:         //扩展版本信息(必选)
132:         if(!isset($nString['version'])){
133:             return false;
134:         }
135: 
136:         //扩展联系邮件地址(必选)
137:         if(!isset($nString['email'])){
138:             return false;
139:         }
140: 
141:         //扩展描述信息
142:         if(!isset($nString['description'])){
143:             return false;
144:         }
145:         return $nString;
146:     }
147: 
148:     /**
149:      * 获取文件的后缀
150:      *
151:      * @param string $file 文件名
152:      * @return string
153:      */
154:     private function get_file_suffix($file){
155:         $l = explode('.', $file);
156:         $c = count($l);
157:         return $l[$c-1];
158:     }
159: 
160:     /**
161:      * 获取表名
162:      *
163:      * @return string
164:      */
165:     private function get_table_name(){
166:         return $this->table_prefix.'weixin_robot_extends';
167:     }
168: 
169: 
170:     /**
171:      * 获取已经启动的扩展
172:      *
173:      * @return mixed
174:      */
175:     public function select_extends(){
176:         global $wpdb;
177:         $table_name = $this->get_table_name();
178:         $sql = "select `id`,`ext_name`,`ext_type`,`ext_int` from `{$table_name}`";
179:         $data  = $wpdb->get_results($sql);
180:         if($data){
181:             $ret = array();
182:             foreach($data as $k=>$v){
183:                 $a['ext_name'] = $v->ext_name;
184:                 $b = explode('.',$v->ext_name);
185:                 $a['ext_cn'] = $b[0];
186:                 $a['ext_type'] = $v->ext_type;
187:                 $ret[] = $a;
188:             }
189:             return $ret;
190:         }
191:         return false;
192:     }
193: 
194: 
195:     /**
196:      * 检查扩展是否存在
197:      *
198:      * @param string $name 扩展名
199:      * @return bool 
200:      */
201:     public function select_extends_name($name){
202:         global $wpdb;
203:         $table_name = $this->get_table_name();
204:         $sql = "select `id`,`ext_name`,`ext_type`,`ext_int` from `{$table_name}` where ext_name='{$name}'";
205:         $result = $wpdb->query($sql);
206:         return $result;
207:     }
208: 
209:     /**
210:      *  获取启动指定类型的扩展
211:      *
212:      *  @param string $type 扩展的类型
213:      *  @return mixed
214:      */
215:     public function select_extends_type($type){
216:         global $wpdb;
217:         $table_name = $this->get_table_name();
218:         $sql = "select `id`,`ext_name`,`ext_type`,`ext_int` from `{$table_name}` where ext_type='{$type}'";
219:         $data = $wpdb->get_results($sql);
220:         if($data){
221:             $ret = array();
222:             foreach($data as $k=>$v){
223:                 $a['ext_name'] = $v->ext_name;
224:                 $a['ext_type'] = $v->ext_type;
225:                 $ret[] = $a;
226:             }
227:             return $ret;
228:         }
229:         return false;
230:     }
231: 
232:     /**
233:      * 添加扩展
234:      *
235:      * @param string $ext_name 扩展名
236:      * @param string $ext_type 扩展类型
237:      * @param string $ext_int  扩展是否启动
238:      * @return bool
239:      */
240:     public function insert_extends($ext_name, $ext_type, $ext_int){
241:         global $wpdb;
242:         $table_name = $this->get_table_name();
243:         $sql = "INSERT INTO `{$table_name}` (`id`, `ext_name`, `ext_type`, `ext_int`)"
244:             ." VALUES(null,'{$ext_name}','{$ext_type}','{$ext_int}')";
245:         return $wpdb->query($sql);
246:     }
247: 
248:     /**
249:      * 在数据库删除扩展
250:      *
251:      * @parma stirng $name 扩展名
252:      * @return bool
253:      */
254:     public function delete_extends_name($name){
255:         global $wpdb;
256:         $table_name = $this->get_table_name();
257:         $sql = "delete from {$table_name} where `ext_name`='{$name}'";
258:         return $wpdb->query($sql);
259:     }
260: 
261:     /**
262:      * 获取扩展文件名
263:      *
264:      * @parma string $f 扩展绝对地址
265:      * @return bool
266:      */
267:     private function _c($f){
268:         if(!file_exists($f)){
269:             $fn = basename($f);
270:             $this->delete_extends_name($fn);
271:             return false;
272:         }else{
273:             include_once($f);
274:             return true;
275:         }
276:     }
277: 
278:     /**
279:      * 扩展安装
280:      * 
281:      * @param string $fn 扩展名
282:      * @param void
283:      */
284:     public function install($fn){
285:         $abspath = WEIXIN_PLUGINS.$fn;
286:         if($this->_c($abspath)){
287:             $tt = explode('.', $fn);
288:             $cn = $tt[0];
289:             if(!class_exists($cn)){
290:                 wx_notice_msg('此文件名和类名不一致!!!');exit;
291:             }
292:             $obj = new $cn($this);
293:             if(method_exists($obj, 'install')){
294:                 return $obj->install();
295:             }
296:         }
297:     }
298: 
299:     /**
300:      * 扩展卸载
301:      *
302:      * @param string $fn 扩展名
303:      * @return void
304:      */
305:     public function uninstall($fn){
306:         $abspath = WEIXIN_PLUGINS.$fn;
307:         if($this->_c($abspath)){
308:             $tt = explode('.', $fn);
309:             $cn = $tt[0];
310:             $obj = new $cn($this);
311:             if(method_exists($obj, 'uninstall')){
312:                 return $obj->uninstall();
313:             }
314:         }
315:     }
316:     
317: 
318:     
319: 
320: }
321: ?>
322: 
API documentation generated by ApiGen