function weixin_robot_custom_reply_page() { global $wpdb, $id, $plugin_page; ?> <h3>自定义回复列表</h3> <?php $weixin_robot_custom_replies = $wpdb->get_results("SELECT * FROM {$wpdb->weixin_custom_replies};"); $custom_reply_types = weixin_robot_get_custom_reply_types(); ?> <?php if ($weixin_robot_custom_replies) { ?> <table class="widefat" cellspacing="0"> <thead> <tr> <?php /*<th style="width:40px">ID</th>*/ ?> <th>关键字</th> <th>回复类型</th> <th style="width:40%;min-width:200px;">回复内容</th> <th>添加时间</th> <th>状态</th> <th>操作</th> </tr> </thead> <tbody> <?php $alternate = ''; ?> <?php foreach ($weixin_robot_custom_replies as $weixin_robot_custom_reply) { ?> <?php $alternate = $alternate ? '' : 'alternate'; $type = $weixin_robot_custom_reply->type; $reply = $weixin_robot_custom_reply->reply; $time = $weixin_robot_custom_reply->time; $status = $weixin_robot_custom_reply->status; $keyword = $weixin_robot_custom_reply->keyword; $match = $weixin_robot_custom_reply->match; $match = $match == 'prefix' ? '前缀匹配' : '完全匹配'; if ($type == 'function') { $reply = $match . ':' . $reply; } elseif ($type == '3rd') { $reply = $match; } ?> <tr class="<?php echo $alternate; ?> "> <?php /*<td><?php echo $weixin_robot_custom_reply->id; ?></td>*/ ?> <td><?php echo $weixin_robot_custom_reply->keyword; ?> </td> <td><?php echo $custom_reply_types[$type]; ?> </td> <td><?php echo $reply; ?> </td> <td><?php echo $time; ?> </td> <td><?php echo $status ? '使用中' : '未使用'; ?> </td> <td><span><a href="<?php echo admin_url('admin.php?page=' . $plugin_page . '&tab=custom-reply &edit&id=' . $weixin_robot_custom_reply->id . "#edit"); ?> ">编辑</a></span> | <span class="delete"><a href="<?php echo admin_url('admin.php?page=' . $plugin_page . '&tab=custom-reply &delete&id=' . $weixin_robot_custom_reply->id); ?> ">删除</a></span></td> </tr> <?php } ?> </tbody> </table> <?php } else { ?> <p>你还没有添加自定义回复,开始添加第一条自定义回复!</p> <?php } ?> <?php if (!empty($id)) { $weixin_robot_custom_reply = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->weixin_custom_replies} WHERE id=%d LIMIT 1", $id)); $type = $weixin_robot_custom_reply->type; $keyword = $weixin_robot_custom_reply->keyword; $reply = $weixin_robot_custom_reply->reply; $time = $weixin_robot_custom_reply->time; $match = $weixin_robot_custom_reply->match; $status = $weixin_robot_custom_reply->status; } else { $id = ''; } ?> <h3 id="edit"><?php echo $id ? '修改' : '新增'; ?> 自定义回复 <?php if ($id) { ?> <a href="<?php echo admin_url('admin.php?page=' . $plugin_page . '&tab=custom-reply&add#edit'); ?> " class="add-new-h2">新增另外一条自定义回复</a> <?php } ?> </h3> <?php $form_fields = array('keyword' => array('title' => '关键字', 'type' => 'text', 'value' => $id ? $keyword : '', 'description' => '多个关键字请用英文逗号区分开,如:<code>七牛, qiniu, 七牛云存储, 七牛镜像存储</code>'), 'type' => array('title' => '回复类型', 'type' => 'select', 'value' => $id ? $type : '', 'options' => weixin_robot_get_custom_reply_types()), 'reply' => array('title' => '回复内容', 'type' => 'textarea', 'value' => $id ? $reply : '', 'description' => '回复类型为图文时,请输入构成图文回复的单篇或者多篇日志的ID,并用英文逗号区分开,如:<code>123,234,345</code>,并且 ID 数量不要超过基本设置里面的返回结果最大条数。<br />回复类型为函数时,请输入相应的处理函数'), 'match' => array('title' => '匹配方式', 'type' => 'select', 'value' => $id ? $match : '', 'options' => array('full' => '完全匹配', 'prefix' => '前缀匹配'), 'description' => '前缀匹配方式只支持匹配前两个中文字或者字母。'), 'time' => array('title' => '添加时间', 'type' => 'datetime', 'value' => $id ? $time : current_time('mysql')), 'status' => array('title' => '状态', 'type' => 'checkbox', 'value' => $id ? $status : '', 'description' => '是否激活')); ?> <form method="post" action="<?php echo admin_url('admin.php?page=' . $plugin_page . '&tab=custom-reply &edit&id=' . $id); ?> " enctype="multipart/form-data" id="form"> <?php wpjam_admin_display_fields($form_fields); ?> <?php wp_nonce_field('weixin_robot', 'weixin_robot_custom_reply_nonce'); ?> <input type="hidden" name="action" value="edit" /> <p class="submit"><input class="button-primary" type="submit" value=" <?php echo $id ? '修改' : '新增'; ?> " /></p> </form> <script type="text/javascript"> jQuery(function(){ <?php if ($id && $type == 'function') { ?> jQuery('#tr_match').show(); <?php } elseif ($id && $type == '3rd') { ?> jQuery('#tr_match').show(); jQuery('#tr_reply').hide(); <?php } else { ?> jQuery('#tr_match').hide(); <?php } ?> jQuery("select#type").change(function(){ var selected = jQuery("select#type").val(); jQuery('#tr_match').hide(); jQuery('#tr_reply').show(); if(selected == '3rd'){ jQuery('#tr_reply').hide(); jQuery('#tr_match').show(); }else if(selected == 'function'){ jQuery('#tr_match').show(); } }); }); </script> <?php }
function weixin_robot_credit_add() { global $plugin_page; $form_fields = array('weixin_openid' => array('title' => '微信 OpenID', 'value' => '', 'type' => 'text', 'description' => ''), 'credit_change' => array('title' => '积分', 'value' => '', 'type' => 'text', 'description' => ''), 'note' => array('title' => '备注', 'value' => '', 'type' => 'textarea', 'description' => '')); ?> <form method="post" action="<?php echo admin_url('admin.php?page=' . $plugin_page); ?> " enctype="multipart/form-data" id="form"> <?php wpjam_admin_display_fields($form_fields); ?> <?php wp_nonce_field('weixin_robot', 'weixin_robot_credit_nonce'); ?> <p class="submit"><input class="button-primary" type="submit" value="手工修改" /></p> </form> <?php }
function wpjam_post_options_callback($post, $meta_box) { if (isset($meta_box['args']['meta_box'])) { $meta_box = $meta_box['args']['meta_box']; } else { $meta_box = ''; } $wpjam_options = wpjam_get_post_options(); foreach ($wpjam_options[$meta_box]['fields'] as $key => $wpjam_field) { if (isset($_REQUEST[$key])) { $value = $_REQUEST[$key]; } else { $value = get_post_meta($post->ID, $key, true); } $wpjam_options[$meta_box]['fields'][$key]['value'] = $value; } $fields_type = isset($wpjam_options[$meta_box]['context']) && $wpjam_options[$meta_box]['context'] == 'side' ? 'list' : 'table'; wpjam_admin_display_fields($wpjam_options[$meta_box]['fields'], $fields_type); ?> <script type="text/javascript"> jQuery(function(){ jQuery("form#post").attr('enctype','multipart/form-data'); }); </script> <?php }
function weixin_robot_custom_menu_add() { global $id, $plugin_page; $weixin_robot_custom_menus = get_option('weixin-robot-custom-menus'); if ($id && $weixin_robot_custom_menus && isset($weixin_robot_custom_menus[$id])) { $weixin_robot_custom_menu = $weixin_robot_custom_menus[$id]; } $parent_options = array('0' => '', '1' => '1', '2' => '2', '3' => '3'); $position_options = array('1' => '1', '2' => '2', '3' => '3'); $sub_position_options = array('0' => '', '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5'); $type_options = array('click' => '点击事件', 'view' => '访问网页'); $form_fields = array('name' => array('title' => '按钮名称', 'type' => 'text', 'value' => $id ? $weixin_robot_custom_menu['name'] : '', 'description' => '按钮描述,既按钮名字,不超过16个字节,子菜单不超过40个字节'), 'type' => array('title' => '按钮类型', 'type' => 'select', 'value' => $id ? $weixin_robot_custom_menu['type'] : '', 'description' => '', 'options' => $type_options), 'key' => array('title' => '按钮KEY值/URL', 'type' => 'text', 'value' => $id ? $weixin_robot_custom_menu['key'] : '', 'description' => '用于消息接口(event类型)推送,不超过128字节,如果按钮还有子按钮,可以不填,其他必填,否则报错。<br />如果类型为点击事件时候,则为按钮KEY值,如果类型为浏览网页,则为URL。<br />KEY值可以为搜索关键字,或者自定义回复定义的关键字。'), 'is_sub' => array('title' => '子按钮', 'type' => 'checkbox', 'value' => $id ? $weixin_robot_custom_menu['parent'] ? 1 : 0 : '', 'description' => '是否激活'), 'position' => array('title' => '位置', 'type' => 'select', 'value' => $id ? $weixin_robot_custom_menu['position'] : '', 'description' => '设置按钮的位置', 'options' => $position_options), 'parent' => array('title' => '所属父按钮位置', 'type' => 'select', 'value' => $id ? $weixin_robot_custom_menu['parent'] : '', 'description' => '如果是子按钮则需要设置所属父按钮的位置', 'options' => $parent_options), 'sub_position' => array('title' => '子按钮的位置', 'type' => 'select', 'value' => $id ? $weixin_robot_custom_menu['sub_position'] : '', 'description' => '设置子按钮的位置', 'options' => $sub_position_options)); ?> <h3 id="edit"><?php echo $id ? '修改' : '新增'; ?> 自定义菜单 <?php if ($id) { ?> <a href="<?php echo admin_url('admin.php?page=' . $plugin_page . '&add'); ?> " class="add-new-h2">新增另外一条自定义菜单</a> <?php } ?> </h3> <form method="post" action="<?php echo admin_url('admin.php?page=' . $plugin_page . '&edit&id=' . $id . '#edit'); ?> " enctype="multipart/form-data" id="form"> <?php wpjam_admin_display_fields($form_fields); ?> <?php wp_nonce_field('weixin_robot', 'weixin_robot_custom_menu_nonce'); ?> <input type="hidden" name="action" value="edit" /> <p class="submit"><input class="button-primary" type="submit" value=" <?php echo $id ? '修改' : '新增'; ?> " /></p> </form> <script type="text/javascript"> jQuery(function(){ <?php if ($id && $weixin_robot_custom_menu['parent']) { ?> jQuery('#tr_position').hide(); <?php } else { ?> jQuery('#tr_parent').hide(); jQuery('#tr_sub_position').hide(); <?php } ?> jQuery('#is_sub').mousedown(function(){ jQuery('#tr_parent').toggle(); jQuery('#tr_sub_position').toggle(); jQuery('#tr_position').toggle(); }); }); </script> <?php }
function weixin_robot_qrcode_add() { global $wpdb, $id, $plugin_page; if (isset($id)) { $weixin_robot_qrcode = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->weixin_qrcodes} WHERE id=%d LIMIT 1", $id)); $type = $weixin_robot_qrcode->type; $scene = $weixin_robot_qrcode->scene; $name = $weixin_robot_qrcode->name; $expire = $weixin_robot_qrcode->expire - time(); } else { $id = ''; } ?> <h3 id="edit"><?php echo $id ? '修改' : '新增'; ?> 带参数的二维码 <?php if ($id) { ?> <a href="<?php echo admin_url('admin.php?page=' . $plugin_page . '&add'); ?> " class="add-new-h2">新增另外一条自定义回复</a> <?php } ?> </h3> <?php $form_fields = array('scene' => array('title' => '场景 ID', 'type' => 'text', 'value' => $id ? $scene : '', 'description' => '临时二维码时为32位非0整型,永久二维码时最大值为100000(目前参数只支持1--100000)'), 'name' => array('title' => '名称', 'type' => 'text', 'value' => $id ? $name : '', 'description' => '二维码名称无实际用途,仅用于更加容易区分。'), 'type' => array('title' => '类型', 'type' => 'select', 'value' => $id ? $type : '', 'options' => weixin_robot_get_qrcode_types()), 'expire' => array('title' => '过期时间', 'type' => 'text', 'value' => $id ? $expire : '', 'description' => '二维码有效时间,以秒为单位。最大不超过1800')); ?> <form method="post" action="<?php echo admin_url('admin.php?page=' . $plugin_page . '&edit&id=' . $id); ?> " enctype="multipart/form-data" id="form"> <?php wpjam_admin_display_fields($form_fields); ?> <?php wp_nonce_field('weixin_robot', 'weixin_robot_qrcode_nonce'); ?> <input type="hidden" name="action" value="edit" /> <p class="submit"><input class="button-primary" type="submit" value=" <?php echo $id ? '修改' : '新增'; ?> " /></p> </form> <script type="text/javascript"> jQuery(function(){ jQuery('#tr_expire').hide(); <?php if ($id) { ?> jQuery('#scene').attr('readonly','readonly'); <?php if ($type == 'QR_SCENE') { ?> jQuery('#tr_expire').show(); <?php } ?> <?php } ?> jQuery("select#type").change(function(){ var selected = jQuery("select#type").val(); if(selected == 'QR_LIMIT_SCENE'){ jQuery('#tr_expire').hide(); }else if(selected == 'QR_SCENE'){ jQuery('#tr_expire').show(); } }); }); </script> <?php }