1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
12:
13: if ( ! defined( 'ABSPATH' ) ) {
14: exit;
15: }
16:
17: 18: 19:
20: class WxRobot_Table_Extends{
21:
22: 23: 24:
25: public $table_prefix = 'midoks_';
26:
27: 28: 29:
30: public static $_instance = null;
31:
32:
33: 34: 35: 36: 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: 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: 80: 81: 82: 83: 84: 85: 86: 87: 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: 152: 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: 164:
165: private function get_table_name(){
166: return $this->table_prefix.'weixin_robot_extends';
167: }
168:
169:
170: 171: 172: 173: 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: 199: 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: 213: 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: 236: 237: 238: 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: 252: 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: 265: 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: 282: 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: 303: 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: