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_Admin_Menu_Records{
21:
22: 23: 24: 25: 26:
27: public function init(){}
28:
29:
30: 31: 32: 33: 34:
35: public function menu(){
36: add_submenu_page('weixin-robot',
37: 'weixin-robot',
38: '微信机器人记录',
39: 'manage_options',
40: 'weixin-robot-records',
41: array($this, 'weixin_robot_records'));
42: }
43:
44: 45: 46:
47: public function weixin_robot_records(){
48:
49: $paged = isset($_GET['paged']) ? $_GET['paged'] : 1;
50:
51: $pageNum = 20;
52: $c = WxRobot_Table_Records::instance()->weixin_get_count();
53: $pagePos = ceil($c/$pageNum);
54: if($paged > $c){
55: $paged = $c;
56: }
57: if($paged < 1){
58: $page = 1;
59: }
60:
61: echo '<h2>微信机器人记录</h2>';
62:
63: do_action('weixin_robot_records_footer');
64:
65: $trTpl = "<tr class='wp_weixin_robot_table_head_tr'>
66: <td class='wp_weixin_robot_table_head_td' style='text-align:center;color:#21759b;' scope='col'>%s</td>
67: <td class='wp_weixin_robot_table_head_td' style='text-align:center;color:#21759b;' scope='col'>%s</td>
68: <td class='wp_weixin_robot_table_head_td' style='text-align:center;color:#21759b;' scope='col'>%s</td>
69: <td class='wp_weixin_robot_table_head_td' style='text-align:center;color:#21759b;' scope='col'>%s</td>
70: <td class='wp_weixin_robot_table_head_td' style='text-align:center;color:#21759b;' scope='col'>%s</td>
71: <td class='wp_weixin_robot_table_head_td' style='text-align:center;color:#21759b;' scope='col'>%s</td>
72: <td class='wp_weixin_robot_table_head_td' style='text-align:center;color:#21759b;' scope='col'>%s</td>
73: <td class='wp_weixin_robot_table_head_td' style='text-align:center;color:#21759b;' scope='col'>%s</td></tr>";
74: $tableHeadTpl = sprintf($trTpl, '序号ID', '开发者ID', '用户ID',
75: '消息类型', '消息内容', '消息时间', '回复', '响应时间');
76:
77:
78: $tableTrTpl = "<tr class='in_out_event'>
79: <td class='wp_weixin_robot_table_head_td' style='text-align:center;width:40px;'>%s</td>
80: <td class='wp_weixin_robot_table_head_td' style='text-align:center;width:100px;'>%s</td>
81: <td class='wp_weixin_robot_table_head_td' style='text-align:center;width:180px;'>%s</td>
82: <td class='wp_weixin_robot_table_head_td' style='text-align:center;width:50px;'>%s</td>
83: <td class='wp_weixin_robot_table_head_td' style='text-align:center;'>%s</td>
84: <td class='wp_weixin_robot_table_head_td' style='text-align:center;width:130px'>%s</td>
85: <td class='wp_weixin_robot_table_head_td' style='text-align:center;width:100px'>%s</td>
86: <td title='超过5s,则代表失败!!!' style='text-align:center;width:100px'>%s</td></tr>";
87: $tableBodyTpl = '';
88: $data = WxRobot_Table_Records::instance()->weixin_get_data($paged);
89:
90: foreach($data as $k=>$v){
91:
92: $tableHeadTpl .= sprintf($tableTrTpl, $v['id'], $v['to'], $v['from'],
93: $this->type_replace($v['msgtype']), $v['content'], $v['createtime'], $v['response'], $v['response_time']);
94: }
95:
96:
97: echo '<div class="metabox-holder"><div class="wrap">';
98: echo '<table class="wp-list-table widefat fixed" id="user_info">';
99: echo '<thead>';
100: echo($tableHeadTpl);
101: echo '</thead>';
102:
103: echo '<tbody>';
104: echo($tableBodyTpl);
105: echo '</tbody>';
106:
107: echo '<tfoot>';
108:
109: echo '<tr><td colspan="8" class="wp_weixin_robot_table_head_td">';
110: echo($this->weixin_info_page($c, $paged, $pageNum));
111: echo '</td></tr></tfoot></table></div></div>';
112:
113: do_action('weixin_robot_records_footer');
114: do_action('weixin_midoks_push');
115: }
116:
117: 118: 119: 120: 121: 122:
123: public function type_replace($type){
124: switch($type){
125:
126: case 'text':return '文本';break;
127:
128: case 'image':return '图片';break;
129:
130: case 'voice':return '语音';break;
131:
132: case 'video':return '视频';break;
133:
134: case 'event':return '事件';break;
135:
136: case 'location': return '地理';break;
137: case 'link':return '连接';break;
138:
139: default:return '文本';break;
140: }
141: return '你傻了吧';
142: }
143:
144: 145: 146: 147: 148: 149: 150: 151: 152:
153: public function weixin_info_page($total, $position, $page=5, $show=7){
154: $prev = $position-1;
155: $next = $position+1;
156:
157: $big = ceil($show/2);
158: $small = floor($show/2);
159: $total_page = ceil($total/$page);
160:
161: if($next > $total_page){$next = $total_page;}
162: if($position > $total_page){$position = $total_page;}
163: if(0 != $total_page){
164: echo "<div>";
165: echo("<span>总共{$total}条数据/当前第{$position}页<span>");
166:
167: echo("<span style='margin-left:30px'><a href='".get_pagenum_link(1)."#' class='fixed'>首页</a></span>");
168: echo("<span style='margin-left:30px'><a class='p_prev' href='".get_pagenum_link($prev)."#'><<</a></span>");
169: $j=0;
170: for($i=1;$i<=$total_page;$i++){
171: $url = get_pagenum_link($i);
172: if($position==$i)
173: $strli = "<span style='margin-left:30px'><a href='".$url."#' class='current' >".$i.'</a></span>';
174: else
175: $strli = "<span style='margin-left:30px'><a href='".$url."#' class='inactive' >".$i.'</a></span>';
176: if($total_page<=$show){echo $strli;}
177: if(($position+$small)>=$total_page){
178:
179:
180: if(($j<$show) && ($total_page>$show) && ($i>=($total_page-(2*$small)))){echo($strli);++$j;}
181: }else{if(($j<$show) && ($total_page>$show) && ($i>=($position-$small))){echo($strli);++$j;}}
182: }
183: echo("<span style='margin-left:30px'><a class='p_next' href='".get_pagenum_link($next)."#'>>></a></span>");
184: echo("<span style='margin-left:30px'><a href='".get_pagenum_link($total_page)."#'>尾页</a></span>");
185:
186: echo '</div>';
187: }
188: }
189:
190: }
191:
192: ?>
193: