public function query($keyword = '')
 {
     $weixin_count = weixin_robot_get_setting('weixin_count');
     // 获取除 page 和 attachmet 之外的所有日志类型
     $post_types = get_post_types(array('exclude_from_search' => false));
     unset($post_types['page']);
     unset($post_types['attachment']);
     $weixin_query_array = array('s' => $keyword, 'ignore_sticky_posts' => true, 'posts_per_page' => $weixin_count, 'post_status' => 'publish', 'post_type' => $post_types);
     $weixin_query_array = apply_filters('weixin_query', $weixin_query_array);
     if (empty($this->response)) {
         if (isset($weixin_query_array['s'])) {
             $this->response = 'query';
         } elseif (isset($weixin_query_array['cat'])) {
             $this->response = 'cat';
         } elseif (isset($weixin_query_array['tag_id'])) {
             $this->response = 'tag';
         }
     }
     global $wp_the_query;
     $wp_the_query->query($weixin_query_array);
     $items = '';
     $counter = 0;
     if ($wp_the_query->have_posts()) {
         while ($wp_the_query->have_posts()) {
             $wp_the_query->the_post();
             $title = apply_filters('weixin_title', get_the_title());
             $excerpt = apply_filters('weixin_description', get_post_excerpt('', apply_filters('weixin_description_length', 150)));
             $url = apply_filters('weixin_url', get_permalink());
             if ($counter == 0) {
                 $thumb = get_post_weixin_thumb('', array(640, 320));
             } else {
                 $thumb = get_post_weixin_thumb('', array(80, 80));
             }
             $items = $items . $this->get_item($title, $excerpt, $thumb, $url);
             $counter++;
         }
     }
     $articleCount = count($wp_the_query->posts);
     if ($articleCount > $weixin_count) {
         $articleCount = $weixin_count;
     }
     if ($articleCount) {
         echo sprintf($this->get_picTpl(), $articleCount, $items);
     } else {
         weixin_robot_not_found_reply($keyword);
     }
 }
function weixin_robot_custom_keyword($false, $keyword)
{
    global $wechatObj;
    if (empty($keyword) || strpos($keyword, '#') !== false) {
        echo "";
        $wechatObj->set_response('need-manual');
        return true;
    } elseif ($keyword == 'subscribe') {
        $weixin_openid = $wechatObj->get_fromUsername();
        if ($weixin_openid) {
            $weixin_user = array('subscribe' => 1);
            weixin_robot_update_user($weixin_openid, $weixin_user);
        }
    }
    // 前缀匹配,只支持2个字
    $prefix_keyword = mb_substr($keyword, 0, 2);
    $weixin_custom_keywords = weixin_robot_get_custom_keywords();
    $weixin_custom_keywords_prefix = weixin_robot_get_custom_keywords('prefix');
    if (isset($weixin_custom_keywords[$keyword])) {
        $weixin_custom_reply = $weixin_custom_keywords[$keyword];
    } elseif (isset($weixin_custom_keywords_prefix[$prefix_keyword])) {
        $weixin_custom_reply = $weixin_custom_keywords_prefix[$prefix_keyword];
    } else {
        $weixin_custom_reply = '';
    }
    if ($weixin_custom_reply) {
        weixin_robot_custom_reply($weixin_custom_reply, $keyword);
        return true;
    }
    //内置回复 -- 完全匹配
    $weixin_builtin_replies = weixin_robot_get_builtin_replies('full');
    //内置回复 -- 前缀匹配
    $weixin_builtin_replies_prefix = weixin_robot_get_builtin_replies('prefix');
    if (isset($weixin_builtin_replies[$keyword])) {
        $weixin_reply_function = $weixin_builtin_replies[$keyword]['function'];
    } elseif (isset($weixin_builtin_replies_prefix[$prefix_keyword])) {
        $weixin_reply_function = $weixin_builtin_replies_prefix[$prefix_keyword]['function'];
    }
    if (isset($weixin_reply_function)) {
        call_user_func($weixin_reply_function, $keyword);
        return true;
    }
    if (weixin_robot_get_setting('weixin_disable_search')) {
        weixin_robot_not_found_reply($keyword);
        return true;
    } else {
        // 检测关键字是不是太长了
        if (!weixin_robot_get_setting('weixin_3rd_search')) {
            $keyword_length = mb_strwidth(preg_replace('/[\\x00-\\x7F]/', '', $keyword), 'utf-8') + str_word_count($keyword) * 2;
            $weixin_keyword_allow_length = weixin_robot_get_setting('weixin_keyword_allow_length');
            if ($keyword_length > $weixin_keyword_allow_length) {
                $weixin_keyword_too_long = weixin_robot_str_replace(weixin_robot_get_setting('weixin_keyword_too_long'), $wechatObj);
                if ($weixin_keyword_too_long) {
                    echo sprintf($wechatObj->get_textTpl(), $weixin_keyword_too_long);
                }
                $wechatObj->set_response('too-long');
                return true;
            }
        }
    }
    return $false;
}