1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
12:
13: if ( ! defined( 'ABSPATH' ) ) {
14: exit;
15: }
16:
17: if (! class_exists('WxRobot_Install')) :
18:
19: 20: 21:
22: class WxRobot_Install{
23:
24: 25: 26:
27: public static $table_prefix = 'midoks_';
28:
29:
30: 31: 32: 33: 34:
35: public function __construct(){
36: $this->create_options();
37: $this->create_tables();
38: }
39:
40: 41: 42: 43: 44:
45: public function weixin_init_help(){
46: $text = "提供的方式:\n?(提供帮助)\nn5(最新文章五篇)\nh5(热门文章五篇)\nr5(随机文章五篇)";
47: return $text;
48: }
49:
50: 51: 52: 53: 54:
55: public function create_options(){
56:
57:
58: $weixin_robot_options['subscribe'] = '欢迎订阅,回复?提供帮助信息';
59:
60:
61: $weixin_robot_options['opt_pic_show'] = 'false';
62: $weixin_robot_options['opt_big_show'] = '';
63: $weixin_robot_options['opt_small_show'] = '';
64:
65:
66: $weixin_robot_options['weixin_robot_debug'] = 'true';
67:
68: $weixin_robot_options['weixin_robot_record'] = 'true';
69:
70: $weixin_robot_options['weixin_robot_helper'] = $this->weixin_init_help();
71:
72: $weixin_robot_options['weixin_robot_helper_is'] = 'false';
73:
74: $weixin_robot_options['weixin_robot_push_today'] = '';
75:
76:
77: $weixin_robot_options['ai'] = '';
78: $weixin_robot_options['as'] = '';
79:
80:
81: $weixin_robot_options['token'] = 'midoks';
82: $weixin_robot_options['token_url'] = 'midoks';
83:
84:
85: $weixin_robot_options['weixin_robot_token'] = '';
86:
87: add_option(WEIXIN_ROBOT_OPTIONS, $weixin_robot_options);
88: }
89:
90: 91: 92: 93: 94:
95: public function create_tables(){
96: global $wpdb;
97: $wpdb->hide_errors();
98: require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
99:
100: $wpdb->query(self::get_schema_weixin_robot());
101: $wpdb->query(self::get_schema_weixin_robot_reply());
102: $wpdb->query(self::get_schema_weixin_robot_menu());
103: $wpdb->query(self::get_schema_weixin_robot_extends());
104:
105:
106:
107:
108: }
109:
110: 111: 112:
113: public static function get_schema_attr(){
114: global $wpdb;
115: $collate = '';
116: if ( $wpdb->has_cap( 'collation' ) ) {
117: if ( ! empty( $wpdb->charset ) ) {
118: $collate .= " DEFAULT CHARACTER SET $wpdb->charset";
119: }
120: if ( ! empty( $wpdb->collate ) ) {
121: $collate .= " COLLATE $wpdb->collate";
122: }
123: }
124: return $collate;
125: }
126:
127: 128: 129: 130: 131:
132: public static function get_schema_weixin_robot(){
133:
134: $prefix = self::$table_prefix;
135: $collate = self::get_schema_attr();
136:
137: return "
138: create table if not exists {$prefix}weixin_robot (
139: `id` bigint(20) not null auto_increment,
140: `from` varchar(64) not null,
141: `to` varchar(32) not null,
142: `msgid` char(64) not null,
143: `msgtype` varchar(10) not null,
144: `createtime` varchar(13) not null,
145: `content` varchar(100) not null,
146: `picurl` varchar(100) not null,
147: `location_x` double(10,6) not null,
148: `location_y` double(10,6) not null,
149: `scale` double(10,6) not null,
150: `label` varchar(255) not null,
151: `title` text not null,
152: `description` longtext not null,
153: `url` varchar(255) not null,
154: `event` varchar(255) not null,
155: `eventkey` varchar(255) not null,
156: `format` varchar(255) not null,
157: `recognition` varchar(255) not null,
158: `mediaid` varchar(255) not null,
159: `thumbmediaid` varchar(255) not null,
160: `response` varchar(255) not null,
161: `response_time` double(10,6) not null,
162: primary key(`id`)
163: ) $collate;
164: ";
165: }
166:
167: 168: 169: 170: 171:
172: public static function get_schema_weixin_robot_reply(){
173:
174: $prefix = self::$table_prefix;
175: $collate = self::get_schema_attr();
176:
177: return "
178: create table if not exists {$prefix}weixin_robot_reply (
179: `id` bigint(20) not null auto_increment,
180: `keyword` varchar(255) not null,
181: `relpy` text not null,
182: `status` char(64) not null,
183: `time` datetime not null,
184: `type` varchar(100) not null,
185: `sort` int(10) not null default 0,
186: primary key(`id`)
187: ) $collate;
188: ";
189: }
190:
191: 192: 193: 194: 195:
196: public static function get_schema_weixin_robot_menu(){
197:
198: $prefix = self::$table_prefix;
199: $collate = self::get_schema_attr();
200:
201: return "
202: create table if not exists {$prefix}weixin_robot_menu (
203: `id` bigint(20) not null auto_increment,
204: `menu_name` varchar(255) not null,
205: `menu_type` varchar(100) not null,
206: `menu_key` text not null,
207: `menu_callback` varchar(180) not null,
208: `menu_sort` int(10) not null default 0,
209: `pid` int(10) not null,
210: primary key(`id`)
211: ) $collate;
212: ";
213: }
214:
215: 216: 217: 218: 219:
220: public static function get_schema_weixin_robot_extends(){
221:
222: $prefix = self::$table_prefix;
223: $collate = self::get_schema_attr();
224:
225: return "
226: create table if not exists {$prefix}weixin_robot_extends (
227: `id` bigint(20) not null auto_increment,
228: `ext_name` varchar(180) not null,
229: `ext_type` varchar(100) not null,
230: `ext_sort` int(10) default 0,
231: `ext_int` int not null,
232: primary key(`id`),
233: UNIQUE KEY `ext_name` (`ext_name`)
234: ) $collate;
235: ";
236: }
237:
238: }
239:
240: endif;
241:
242: return new WxRobot_Install();
243: ?>
244: