コード例 #1
0
 public static function set_response($result = null)
 {
     if (empty($result)) {
         $result = array("error_code" => 0, "error_msg" => "success", "data" => array());
     }
     global $bigapp_common;
     $bigapp_common = Bigapp_Common::getInstance();
     $bigapp_common->setResponse($result);
 }
コード例 #2
0
 public function writeLog($str, $path = null)
 {
     if (!BigAppConf::$debug) {
         return;
     }
     if (null === $path) {
         $path = dirname(dirname(__FILE__)) . "/log/debug.log";
     }
     $fd = @fopen($path, "a+");
     if (is_resource($fd)) {
         fputs($fd, $str);
         fclose($fd);
         self::$print = true;
     }
 }
コード例 #3
0
 /**
  * Load the JSON API.
  * @todo Extract code that should be unit tested into isolated methods such as
  *       the wp_json_server_class filter and serving requests. This would also
  *       help for code re-use by `wp-json` endpoint. Note that we can't unit
  *       test any method that calls die().
  * /home/work/webroot/wordpress/wp-includes/template-loader.php:1
  * 在所有数据初始化完成时,给一个机会,让我们去获取数据
  * 在本插件中,直接获取所有数据,然后json,最后die,不再返回
  */
 public static function bigapp_json_api_loaded()
 {
     if (empty($GLOBALS['wp']->query_vars[BigAppConf::$app_prefix])) {
         return;
     }
     /**
      * Whether this is a XML-RPC Request.
      *
      * @var bool
      * @todo Remove me in favour of JSON_REQUEST
      */
     define('XMLRPC_REQUEST', false);
     /**
      * Whether this is a JSON Request.
      *
      * @var bool
      */
     define('JSON_REQUEST', true);
     //快速评论
     add_action('comment_flood_trigger', array('mobileplugin_bigapp', 'bigapp_json_api_flood_comment'));
     //重复评论的钩子
     add_action('comment_duplicate_trigger', array('mobileplugin_bigapp', 'bigapp_json_api_duplicate_comment'));
     //缩略图,初始化
     global $bigapp_support_thumb;
     if (version_compare($GLOBALS['wp_version'], BigAppConf::$thumbnail_wp_version) >= 0 && BigAppConf::$thumbnail_support == true) {
         $thumbnail_size_w = get_option('thumbnail_size_w');
         if (get_theme_support('post-thumbnails') && $thumbnail_size_w > 0) {
             #add_theme_support( 'post-thumbnails' ,array('post','page'));
             #add_image_size("list",BigAppConf::$thumb_width,BigAppConf::$thumb_height,true);
             #add_image_size("recom",BigAppConf::$thumb_width,BigAppConf::$thumb_height,true);
             #set_post_thumbnail_size( BigAppConf::$thumb_width,BigAppConf::$thumb_height,true);  //post-thumbnails
             $bigapp_support_thumb = true;
         }
     }
     //初始化
     global $bigapp_common;
     $bigapp_common = Bigapp_Common::getInstance();
     global $wp_json_server;
     // Allow for a plugin to insert a different class to handle requests.
     //允许替换json服务器
     $wp_json_server_class = apply_filters('wp_json_server_class', 'WP_JSON_Server');
     $wp_json_server = new $wp_json_server_class();
     /**
      * Fires when preparing to serve an API request.
      *
      * Endpoint objects should be created and register their hooks on this
      * action rather than another action to ensure they're only loaded when
      * needed.
      *
      * @param WP_JSON_ResponseHandler $wp_json_server Response handler object.
      */
     //初始化所有默认的和各个类型相关的、json勾子
     do_action('wp_json_server_before_serve', $wp_json_server);
     // Fire off the request.
     $wp_json_server->serve_request($GLOBALS['wp']->query_vars[BigAppConf::$route_prefix]);
     // We're done.
     die;
 }
コード例 #4
0
ファイル: util.inc.php プロジェクト: Mushan3420/BigApp-PHP7
/**
 * 公共的出错函数,返回json格式数据,再退出
 */
function json_error($code, $msg = '', $data = '')
{
    $result = array('error_code' => $code, 'error_msg' => __lan($msg), 'data' => $data);
    $req = Bigapp_Common::getInstance();
    $req->setResponse($result);
}