Exemple #1
0
 public function info()
 {
     global $json_api;
     $php = '';
     if (!empty($json_api->query->controller)) {
         return $json_api->controller_info($json_api->query->controller);
     } else {
         $dir = json_api_dir();
         if (file_exists("{$dir}/json-api.php")) {
             $php = file_get_contents("{$dir}/json-api.php");
         } else {
             // Check one directory up, in case json-api.php was moved
             $dir = dirname($dir);
             if (file_exists("{$dir}/json-api.php")) {
                 $php = file_get_contents("{$dir}/json-api.php");
             }
         }
         if (preg_match('/^\\s*Version:\\s*(.+)$/m', $php, $matches)) {
             $version = $matches[1];
         } else {
             $version = '(Unknown)';
         }
         $active_controllers = explode(',', get_option('json_api_controllers', 'core'));
         $controllers = array_intersect($json_api->get_controllers(), $active_controllers);
         return array('json_api_version' => $version, 'controllers' => array_values($controllers));
     }
 }
Exemple #2
0
 function get_json($data, $status = 'ok')
 {
     // Include a status value with the response
     if (is_array($data)) {
         $data = array_merge(array('status' => $status), $data);
     } else {
         if (is_object($data)) {
             $data = get_object_vars($data);
             $data = array_merge(array('status' => $status), $data);
         }
     }
     $data = apply_filters('json_api_encode', $data);
     if (function_exists('json_encode')) {
         // Use the built-in json_encode function if it's available
         return json_encode($data);
     } else {
         // Use PEAR's Services_JSON encoder otherwise
         if (!class_exists('Services_JSON')) {
             $dir = json_api_dir();
             require_once "{$dir}/library/JSON.php";
         }
         $json = new Services_JSON();
         return $json->encode($data);
     }
 }
 function get_json($data, $status = 'ok')
 {
     global $json_api;
     // Include a status value with the response
     if (is_array($data)) {
         $data = array_merge(array('status' => $status), $data);
     } else {
         if (is_object($data)) {
             $data = get_object_vars($data);
             $data = array_merge(array('status' => $status), $data);
         }
     }
     $data = apply_filters('json_api_encode', $data);
     if (function_exists('json_encode')) {
         // Use the built-in json_encode function if it's available
         if (version_compare(PHP_VERSION, '5.3') < 0) {
             $json = json_encode($data);
         } else {
             $json_encode_options = 0;
             if ($json_api->query->json_encode_options) {
                 $json_encode_options = $json_api->query->json_encode_options;
             }
             $json = json_encode($data, $json_encode_options);
         }
     } else {
         // Use PEAR's Services_JSON encoder otherwise
         if (!class_exists('Services_JSON')) {
             $dir = json_api_dir();
             require_once "{$dir}/library/JSON.php";
         }
         $json_service = new Services_JSON();
         $json = $json_service->encode($data);
     }
     // Thanks to Stack Overflow user Gumbo stackoverflow.com/questions/2934563
     if ($json_api->query->json_unescaped_unicode) {
         $callback = array($this, 'replace_unicode_escape_sequence');
         $json = preg_replace_callback('/\\\\u([0-9a-f]{4})/i', $callback, $json);
     }
     return $json;
 }
Exemple #4
0
 function controller_path($controller)
 {
     $dir = json_api_dir();
     $controller_class = $this->controller_class($controller);
     return apply_filters("{$controller_class}_path", "{$dir}/controllers/{$controller}.php");
 }
Exemple #5
0
 function controller_path($controller)
 {
     $json_api_dir = json_api_dir();
     $json_api_path = "{$json_api_dir}/controllers/{$controller}.php";
     $theme_dir = get_stylesheet_directory();
     $theme_path = "{$theme_dir}/{$controller}.php";
     if (file_exists($theme_path)) {
         $path = $theme_path;
     } else {
         if (file_exists($json_api_path)) {
             $path = $json_api_path;
         } else {
             $path = null;
         }
     }
     $controller_class = $this->controller_class($controller);
     return apply_filters("{$controller_class}_path", $path);
 }
<?php

/*
Plugin Name: JSON API
Plugin URI: http://wordpress.org/plugins/json-api/
Description: A RESTful API for WordPress
Version: 1.1.1
Author: Dan Phiffer
Author URI: http://phiffer.org/
*/
$dir = json_api_dir();
@(include_once "{$dir}/singletons/api.php");
@(include_once "{$dir}/singletons/query.php");
@(include_once "{$dir}/singletons/introspector.php");
@(include_once "{$dir}/singletons/response.php");
@(include_once "{$dir}/models/post.php");
@(include_once "{$dir}/models/comment.php");
@(include_once "{$dir}/models/category.php");
@(include_once "{$dir}/models/tag.php");
@(include_once "{$dir}/models/author.php");
@(include_once "{$dir}/models/attachment.php");
function json_api_init()
{
    global $json_api;
    if (phpversion() < 5) {
        add_action('admin_notices', 'json_api_php_version_warning');
        return;
    }
    if (!class_exists('JSON_API')) {
        add_action('admin_notices', 'json_api_class_warning');
        return;