Archived
Initial commit
This commit is contained in:
commit
86c1e5f82b
40 files changed
+4362
No files matched your search
@@ -0,0 +1,334 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
Controller name: Core
|
||||||
|
Controller description: Basic introspection methods
|
||||||
|
*/
|
||||||
|
|
||||||
|
class JSON_API_Core_Controller {
|
||||||
|
|
||||||
|
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)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_recent_posts() {
|
||||||
|
global $json_api;
|
||||||
|
$posts = $json_api->introspector->get_posts();
|
||||||
|
return $this->posts_result($posts);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_post() {
|
||||||
|
global $json_api, $post;
|
||||||
|
extract($json_api->query->get(array('id', 'slug', 'post_id', 'post_slug')));
|
||||||
|
if ($id || $post_id) {
|
||||||
|
if (!$id) {
|
||||||
|
$id = $post_id;
|
||||||
|
}
|
||||||
|
$posts = $json_api->introspector->get_posts(array(
|
||||||
|
'p' => $id
|
||||||
|
), true);
|
||||||
|
} else if ($slug || $post_slug) {
|
||||||
|
if (!$slug) {
|
||||||
|
$slug = $post_slug;
|
||||||
|
}
|
||||||
|
$posts = $json_api->introspector->get_posts(array(
|
||||||
|
'name' => $slug
|
||||||
|
), true);
|
||||||
|
} else {
|
||||||
|
$json_api->error("Include 'id' or 'slug' var in your request.");
|
||||||
|
}
|
||||||
|
if (count($posts) == 1) {
|
||||||
|
$post = $posts[0];
|
||||||
|
$previous = get_adjacent_post(false, '', true);
|
||||||
|
$next = get_adjacent_post(false, '', false);
|
||||||
|
$post = new JSON_API_Post($post);
|
||||||
|
$response = array(
|
||||||
|
'post' => $post
|
||||||
|
);
|
||||||
|
if ($previous) {
|
||||||
|
$response['previous_url'] = get_permalink($previous->ID);
|
||||||
|
}
|
||||||
|
if ($next) {
|
||||||
|
$response['next_url'] = get_permalink($next->ID);
|
||||||
|
}
|
||||||
|
return $response;
|
||||||
|
} else {
|
||||||
|
$json_api->error("Not found.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_page() {
|
||||||
|
global $json_api;
|
||||||
|
extract($json_api->query->get(array('id', 'slug', 'page_id', 'page_slug', 'children')));
|
||||||
|
if ($id || $page_id) {
|
||||||
|
if (!$id) {
|
||||||
|
$id = $page_id;
|
||||||
|
}
|
||||||
|
$posts = $json_api->introspector->get_posts(array(
|
||||||
|
'page_id' => $id
|
||||||
|
));
|
||||||
|
} else if ($slug || $page_slug) {
|
||||||
|
if (!$slug) {
|
||||||
|
$slug = $page_slug;
|
||||||
|
}
|
||||||
|
$posts = $json_api->introspector->get_posts(array(
|
||||||
|
'pagename' => $slug
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
$json_api->error("Include 'id' or 'slug' var in your request.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Workaround for https://core.trac.wordpress.org/ticket/12647
|
||||||
|
if (empty($posts)) {
|
||||||
|
$url = $_SERVER['REQUEST_URI'];
|
||||||
|
$parsed_url = parse_url($url);
|
||||||
|
$path = $parsed_url['path'];
|
||||||
|
if (preg_match('#^http://[^/]+(/.+)$#', get_bloginfo('url'), $matches)) {
|
||||||
|
$blog_root = $matches[1];
|
||||||
|
$path = preg_replace("#^$blog_root#", '', $path);
|
||||||
|
}
|
||||||
|
if (substr($path, 0, 1) == '/') {
|
||||||
|
$path = substr($path, 1);
|
||||||
|
}
|
||||||
|
$posts = $json_api->introspector->get_posts(array('pagename' => $path));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($posts) == 1) {
|
||||||
|
if (!empty($children)) {
|
||||||
|
$json_api->introspector->attach_child_posts($posts[0]);
|
||||||
|
}
|
||||||
|
return array(
|
||||||
|
'page' => $posts[0]
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$json_api->error("Not found.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_date_posts() {
|
||||||
|
global $json_api;
|
||||||
|
if ($json_api->query->date) {
|
||||||
|
$date = preg_replace('/\D/', '', $json_api->query->date);
|
||||||
|
if (!preg_match('/^\d{4}(\d{2})?(\d{2})?$/', $date)) {
|
||||||
|
$json_api->error("Specify a date var in one of 'YYYY' or 'YYYY-MM' or 'YYYY-MM-DD' formats.");
|
||||||
|
}
|
||||||
|
$request = array('year' => substr($date, 0, 4));
|
||||||
|
if (strlen($date) > 4) {
|
||||||
|
$request['monthnum'] = (int) substr($date, 4, 2);
|
||||||
|
}
|
||||||
|
if (strlen($date) > 6) {
|
||||||
|
$request['day'] = (int) substr($date, 6, 2);
|
||||||
|
}
|
||||||
|
$posts = $json_api->introspector->get_posts($request);
|
||||||
|
} else {
|
||||||
|
$json_api->error("Include 'date' var in your request.");
|
||||||
|
}
|
||||||
|
return $this->posts_result($posts);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_category_posts() {
|
||||||
|
global $json_api;
|
||||||
|
$category = $json_api->introspector->get_current_category();
|
||||||
|
if (!$category) {
|
||||||
|
$json_api->error("Not found.");
|
||||||
|
}
|
||||||
|
$posts = $json_api->introspector->get_posts(array(
|
||||||
|
'cat' => $category->id
|
||||||
|
));
|
||||||
|
return $this->posts_object_result($posts, $category);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_tag_posts() {
|
||||||
|
global $json_api;
|
||||||
|
$tag = $json_api->introspector->get_current_tag();
|
||||||
|
if (!$tag) {
|
||||||
|
$json_api->error("Not found.");
|
||||||
|
}
|
||||||
|
$posts = $json_api->introspector->get_posts(array(
|
||||||
|
'tag' => $tag->slug
|
||||||
|
));
|
||||||
|
return $this->posts_object_result($posts, $tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_author_posts() {
|
||||||
|
global $json_api;
|
||||||
|
$author = $json_api->introspector->get_current_author();
|
||||||
|
if (!$author) {
|
||||||
|
$json_api->error("Not found.");
|
||||||
|
}
|
||||||
|
$posts = $json_api->introspector->get_posts(array(
|
||||||
|
'author' => $author->id
|
||||||
|
));
|
||||||
|
return $this->posts_object_result($posts, $author);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_search_results() {
|
||||||
|
global $json_api;
|
||||||
|
if ($json_api->query->search) {
|
||||||
|
$posts = $json_api->introspector->get_posts(array(
|
||||||
|
's' => $json_api->query->search
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
$json_api->error("Include 'search' var in your request.");
|
||||||
|
}
|
||||||
|
return $this->posts_result($posts);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_date_index() {
|
||||||
|
global $json_api;
|
||||||
|
$permalinks = $json_api->introspector->get_date_archive_permalinks();
|
||||||
|
$tree = $json_api->introspector->get_date_archive_tree($permalinks);
|
||||||
|
return array(
|
||||||
|
'permalinks' => $permalinks,
|
||||||
|
'tree' => $tree
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_category_index() {
|
||||||
|
global $json_api;
|
||||||
|
$categories = $json_api->introspector->get_categories();
|
||||||
|
return array(
|
||||||
|
'count' => count($categories),
|
||||||
|
'categories' => $categories
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_tag_index() {
|
||||||
|
global $json_api;
|
||||||
|
$tags = $json_api->introspector->get_tags();
|
||||||
|
return array(
|
||||||
|
'count' => count($tags),
|
||||||
|
'tags' => $tags
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_author_index() {
|
||||||
|
global $json_api;
|
||||||
|
$authors = $json_api->introspector->get_authors();
|
||||||
|
return array(
|
||||||
|
'count' => count($authors),
|
||||||
|
'authors' => array_values($authors)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_page_index() {
|
||||||
|
global $json_api;
|
||||||
|
$pages = array();
|
||||||
|
// Thanks to blinder for the fix!
|
||||||
|
$numberposts = empty($json_api->query->count) ? -1 : $json_api->query->count;
|
||||||
|
$wp_posts = get_posts(array(
|
||||||
|
'post_type' => 'page',
|
||||||
|
'post_parent' => 0,
|
||||||
|
'order' => 'ASC',
|
||||||
|
'orderby' => 'menu_order',
|
||||||
|
'numberposts' => $numberposts
|
||||||
|
));
|
||||||
|
foreach ($wp_posts as $wp_post) {
|
||||||
|
$pages[] = new JSON_API_Post($wp_post);
|
||||||
|
}
|
||||||
|
foreach ($pages as $page) {
|
||||||
|
$json_api->introspector->attach_child_posts($page);
|
||||||
|
}
|
||||||
|
return array(
|
||||||
|
'pages' => $pages
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_nonce() {
|
||||||
|
global $json_api;
|
||||||
|
extract($json_api->query->get(array('controller', 'method')));
|
||||||
|
if ($controller && $method) {
|
||||||
|
$controller = strtolower($controller);
|
||||||
|
if (!in_array($controller, $json_api->get_controllers())) {
|
||||||
|
$json_api->error("Unknown controller '$controller'.");
|
||||||
|
}
|
||||||
|
require_once $json_api->controller_path($controller);
|
||||||
|
if (!method_exists($json_api->controller_class($controller), $method)) {
|
||||||
|
$json_api->error("Unknown method '$method'.");
|
||||||
|
}
|
||||||
|
$nonce_id = $json_api->get_nonce_id($controller, $method);
|
||||||
|
return array(
|
||||||
|
'controller' => $controller,
|
||||||
|
'method' => $method,
|
||||||
|
'nonce' => wp_create_nonce($nonce_id)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$json_api->error("Include 'controller' and 'method' vars in your request.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function get_object_posts($object, $id_var, $slug_var) {
|
||||||
|
global $json_api;
|
||||||
|
$object_id = "{$type}_id";
|
||||||
|
$object_slug = "{$type}_slug";
|
||||||
|
extract($json_api->query->get(array('id', 'slug', $object_id, $object_slug)));
|
||||||
|
if ($id || $$object_id) {
|
||||||
|
if (!$id) {
|
||||||
|
$id = $$object_id;
|
||||||
|
}
|
||||||
|
$posts = $json_api->introspector->get_posts(array(
|
||||||
|
$id_var => $id
|
||||||
|
));
|
||||||
|
} else if ($slug || $$object_slug) {
|
||||||
|
if (!$slug) {
|
||||||
|
$slug = $$object_slug;
|
||||||
|
}
|
||||||
|
$posts = $json_api->introspector->get_posts(array(
|
||||||
|
$slug_var => $slug
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
$json_api->error("No $type specified. Include 'id' or 'slug' var in your request.");
|
||||||
|
}
|
||||||
|
return $posts;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function posts_result($posts) {
|
||||||
|
global $wp_query;
|
||||||
|
return array(
|
||||||
|
'count' => count($posts),
|
||||||
|
'count_total' => (int) $wp_query->found_posts,
|
||||||
|
'pages' => $wp_query->max_num_pages,
|
||||||
|
'posts' => $posts
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function posts_object_result($posts, $object) {
|
||||||
|
global $wp_query;
|
||||||
|
// Convert something like "JSON_API_Category" into "category"
|
||||||
|
$object_key = strtolower(substr(get_class($object), 9));
|
||||||
|
return array(
|
||||||
|
'count' => count($posts),
|
||||||
|
'pages' => (int) $wp_query->max_num_pages,
|
||||||
|
$object_key => $object,
|
||||||
|
'posts' => $posts
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
Controller name: Posts
|
||||||
|
Controller description: Data manipulation methods for posts
|
||||||
|
*/
|
||||||
|
|
||||||
|
class JSON_API_Posts_Controller {
|
||||||
|
|
||||||
|
public function create_post() {
|
||||||
|
global $json_api;
|
||||||
|
if (!current_user_can('edit_posts')) {
|
||||||
|
$json_api->error("You need to login with a user capable of creating posts.");
|
||||||
|
}
|
||||||
|
if (!$json_api->query->nonce) {
|
||||||
|
$json_api->error("You must include a 'nonce' value to create posts. Use the `get_nonce` Core API method.");
|
||||||
|
}
|
||||||
|
$nonce_id = $json_api->get_nonce_id('posts', 'create_post');
|
||||||
|
if (!wp_verify_nonce($json_api->query->nonce, $nonce_id)) {
|
||||||
|
$json_api->error("Your 'nonce' value was incorrect. Use the 'get_nonce' API method.");
|
||||||
|
}
|
||||||
|
nocache_headers();
|
||||||
|
$post = new JSON_API_Post();
|
||||||
|
$id = $post->create($_REQUEST);
|
||||||
|
if (empty($id)) {
|
||||||
|
$json_api->error("Could not create post.");
|
||||||
|
}
|
||||||
|
return array(
|
||||||
|
'post' => $post
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
Controller name: Respond
|
||||||
|
Controller description: Comment/trackback submission methods
|
||||||
|
*/
|
||||||
|
|
||||||
|
class JSON_API_Respond_Controller {
|
||||||
|
|
||||||
|
function submit_comment() {
|
||||||
|
global $json_api;
|
||||||
|
nocache_headers();
|
||||||
|
if (empty($_REQUEST['post_id'])) {
|
||||||
|
$json_api->error("No post specified. Include 'post_id' var in your request.");
|
||||||
|
} else if (empty($_REQUEST['name']) ||
|
||||||
|
empty($_REQUEST['email']) ||
|
||||||
|
empty($_REQUEST['content'])) {
|
||||||
|
$json_api->error("Please include all required arguments (name, email, content).");
|
||||||
|
} else if (!is_email($_REQUEST['email'])) {
|
||||||
|
$json_api->error("Please enter a valid email address.");
|
||||||
|
}
|
||||||
|
$pending = new JSON_API_Comment();
|
||||||
|
return $pending->handle_submission();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
Plugin Name: JSON API
|
||||||
|
Plugin URI: http://wordpress.org/extend/plugins/json-api/
|
||||||
|
Description: A RESTful API for WordPress
|
||||||
|
Version: 1.0.7
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
add_filter('rewrite_rules_array', 'json_api_rewrites');
|
||||||
|
$json_api = new JSON_API();
|
||||||
|
}
|
||||||
|
|
||||||
|
function json_api_php_version_warning() {
|
||||||
|
echo "<div id=\"json-api-warning\" class=\"updated fade\"><p>Sorry, JSON API requires PHP version 5.0 or greater.</p></div>";
|
||||||
|
}
|
||||||
|
|
||||||
|
function json_api_class_warning() {
|
||||||
|
echo "<div id=\"json-api-warning\" class=\"updated fade\"><p>Oops, JSON_API class not found. If you've defined a JSON_API_DIR constant, double check that the path is correct.</p></div>";
|
||||||
|
}
|
||||||
|
|
||||||
|
function json_api_activation() {
|
||||||
|
// Add the rewrite rule on activation
|
||||||
|
global $wp_rewrite;
|
||||||
|
add_filter('rewrite_rules_array', 'json_api_rewrites');
|
||||||
|
$wp_rewrite->flush_rules();
|
||||||
|
}
|
||||||
|
|
||||||
|
function json_api_deactivation() {
|
||||||
|
// Remove the rewrite rule on deactivation
|
||||||
|
global $wp_rewrite;
|
||||||
|
$wp_rewrite->flush_rules();
|
||||||
|
}
|
||||||
|
|
||||||
|
function json_api_rewrites($wp_rules) {
|
||||||
|
$base = get_option('json_api_base', 'api');
|
||||||
|
if (empty($base)) {
|
||||||
|
return $wp_rules;
|
||||||
|
}
|
||||||
|
$json_api_rules = array(
|
||||||
|
"$base\$" => 'index.php?json=info',
|
||||||
|
"$base/(.+)\$" => 'index.php?json=$matches[1]'
|
||||||
|
);
|
||||||
|
return array_merge($json_api_rules, $wp_rules);
|
||||||
|
}
|
||||||
|
|
||||||
|
function json_api_dir() {
|
||||||
|
if (defined('JSON_API_DIR') && file_exists(JSON_API_DIR)) {
|
||||||
|
return JSON_API_DIR;
|
||||||
|
} else {
|
||||||
|
return dirname(__FILE__);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add initialization and activation hooks
|
||||||
|
add_action('init', 'json_api_init');
|
||||||
|
register_activation_hook("$dir/json-api.php", 'json_api_activation');
|
||||||
|
register_deactivation_hook("$dir/json-api.php", 'json_api_deactivation');
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,861 @@
|
|||||||
|
<?php
|
||||||
|
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||||
|
/**
|
||||||
|
* Converts to and from JSON format.
|
||||||
|
*
|
||||||
|
* JSON (JavaScript Object Notation) is a lightweight data-interchange
|
||||||
|
* format. It is easy for humans to read and write. It is easy for machines
|
||||||
|
* to parse and generate. It is based on a subset of the JavaScript
|
||||||
|
* Programming Language, Standard ECMA-262 3rd Edition - December 1999.
|
||||||
|
* This feature can also be found in Python. JSON is a text format that is
|
||||||
|
* completely language independent but uses conventions that are familiar
|
||||||
|
* to programmers of the C-family of languages, including C, C++, C#, Java,
|
||||||
|
* JavaScript, Perl, TCL, and many others. These properties make JSON an
|
||||||
|
* ideal data-interchange language.
|
||||||
|
*
|
||||||
|
* This package provides a simple encoder and decoder for JSON notation. It
|
||||||
|
* is intended for use with client-side Javascript applications that make
|
||||||
|
* use of HTTPRequest to perform server communication functions - data can
|
||||||
|
* be encoded into JSON notation for use in a client-side javascript, or
|
||||||
|
* decoded from incoming Javascript requests. JSON format is native to
|
||||||
|
* Javascript, and can be directly eval()'ed with no further parsing
|
||||||
|
* overhead
|
||||||
|
*
|
||||||
|
* All strings should be in ASCII or UTF-8 format!
|
||||||
|
*
|
||||||
|
* LICENSE: Redistribution and use in source and binary forms, with or
|
||||||
|
* without modification, are permitted provided that the following
|
||||||
|
* conditions are met: Redistributions of source code must retain the
|
||||||
|
* above copyright notice, this list of conditions and the following
|
||||||
|
* disclaimer. Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||||
|
* NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||||
|
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
||||||
|
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
||||||
|
* DAMAGE.
|
||||||
|
*
|
||||||
|
* @category
|
||||||
|
* @package Services_JSON
|
||||||
|
* @author Michal Migurski <mike-json@teczno.com>
|
||||||
|
* @author Matt Knapp <mdknapp[at]gmail[dot]com>
|
||||||
|
* @author Brett Stimmerman <brettstimmerman[at]gmail[dot]com>
|
||||||
|
* @copyright 2005 Michal Migurski
|
||||||
|
* @version CVS: $Id: JSON.php 288200 2009-09-09 15:41:29Z alan_k $
|
||||||
|
* @license http://www.opensource.org/licenses/bsd-license.php
|
||||||
|
* @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marker constant for Services_JSON::decode(), used to flag stack state
|
||||||
|
*/
|
||||||
|
define('SERVICES_JSON_SLICE', 1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marker constant for Services_JSON::decode(), used to flag stack state
|
||||||
|
*/
|
||||||
|
define('SERVICES_JSON_IN_STR', 2);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marker constant for Services_JSON::decode(), used to flag stack state
|
||||||
|
*/
|
||||||
|
define('SERVICES_JSON_IN_ARR', 3);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marker constant for Services_JSON::decode(), used to flag stack state
|
||||||
|
*/
|
||||||
|
define('SERVICES_JSON_IN_OBJ', 4);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marker constant for Services_JSON::decode(), used to flag stack state
|
||||||
|
*/
|
||||||
|
define('SERVICES_JSON_IN_CMT', 5);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Behavior switch for Services_JSON::decode()
|
||||||
|
*/
|
||||||
|
define('SERVICES_JSON_LOOSE_TYPE', 16);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Behavior switch for Services_JSON::decode()
|
||||||
|
*/
|
||||||
|
define('SERVICES_JSON_SUPPRESS_ERRORS', 32);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts to and from JSON format.
|
||||||
|
*
|
||||||
|
* Brief example of use:
|
||||||
|
*
|
||||||
|
* <code>
|
||||||
|
* // create a new instance of Services_JSON
|
||||||
|
* $json = new Services_JSON();
|
||||||
|
*
|
||||||
|
* // convert a complexe value to JSON notation, and send it to the browser
|
||||||
|
* $value = array('foo', 'bar', array(1, 2, 'baz'), array(3, array(4)));
|
||||||
|
* $output = $json->encode($value);
|
||||||
|
*
|
||||||
|
* print($output);
|
||||||
|
* // prints: ["foo","bar",[1,2,"baz"],[3,[4]]]
|
||||||
|
*
|
||||||
|
* // accept incoming POST data, assumed to be in JSON notation
|
||||||
|
* $input = file_get_contents('php://input', 1000000);
|
||||||
|
* $value = $json->decode($input);
|
||||||
|
* </code>
|
||||||
|
*/
|
||||||
|
class Services_JSON
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* constructs a new JSON instance
|
||||||
|
*
|
||||||
|
* @param int $use object behavior flags; combine with boolean-OR
|
||||||
|
*
|
||||||
|
* possible values:
|
||||||
|
* - SERVICES_JSON_LOOSE_TYPE: loose typing.
|
||||||
|
* "{...}" syntax creates associative arrays
|
||||||
|
* instead of objects in decode().
|
||||||
|
* - SERVICES_JSON_SUPPRESS_ERRORS: error suppression.
|
||||||
|
* Values which can't be encoded (e.g. resources)
|
||||||
|
* appear as NULL instead of throwing errors.
|
||||||
|
* By default, a deeply-nested resource will
|
||||||
|
* bubble up with an error, so all return values
|
||||||
|
* from encode() should be checked with isError()
|
||||||
|
*/
|
||||||
|
function Services_JSON($use = 0)
|
||||||
|
{
|
||||||
|
$this->use = $use;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* convert a string from one UTF-16 char to one UTF-8 char
|
||||||
|
*
|
||||||
|
* Normally should be handled by mb_convert_encoding, but
|
||||||
|
* provides a slower PHP-only method for installations
|
||||||
|
* that lack the multibye string extension.
|
||||||
|
*
|
||||||
|
* @param string $utf16 UTF-16 character
|
||||||
|
* @return string UTF-8 character
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
function utf162utf8($utf16)
|
||||||
|
{
|
||||||
|
// oh please oh please oh please oh please oh please
|
||||||
|
if(function_exists('mb_convert_encoding')) {
|
||||||
|
return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16');
|
||||||
|
}
|
||||||
|
|
||||||
|
$bytes = (ord($utf16{0}) << 8) | ord($utf16{1});
|
||||||
|
|
||||||
|
switch(true) {
|
||||||
|
case ((0x7F & $bytes) == $bytes):
|
||||||
|
// this case should never be reached, because we are in ASCII range
|
||||||
|
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||||
|
return chr(0x7F & $bytes);
|
||||||
|
|
||||||
|
case (0x07FF & $bytes) == $bytes:
|
||||||
|
// return a 2-byte UTF-8 character
|
||||||
|
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||||
|
return chr(0xC0 | (($bytes >> 6) & 0x1F))
|
||||||
|
. chr(0x80 | ($bytes & 0x3F));
|
||||||
|
|
||||||
|
case (0xFFFF & $bytes) == $bytes:
|
||||||
|
// return a 3-byte UTF-8 character
|
||||||
|
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||||
|
return chr(0xE0 | (($bytes >> 12) & 0x0F))
|
||||||
|
. chr(0x80 | (($bytes >> 6) & 0x3F))
|
||||||
|
. chr(0x80 | ($bytes & 0x3F));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ignoring UTF-32 for now, sorry
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* convert a string from one UTF-8 char to one UTF-16 char
|
||||||
|
*
|
||||||
|
* Normally should be handled by mb_convert_encoding, but
|
||||||
|
* provides a slower PHP-only method for installations
|
||||||
|
* that lack the multibye string extension.
|
||||||
|
*
|
||||||
|
* @param string $utf8 UTF-8 character
|
||||||
|
* @return string UTF-16 character
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
function utf82utf16($utf8)
|
||||||
|
{
|
||||||
|
// oh please oh please oh please oh please oh please
|
||||||
|
if(function_exists('mb_convert_encoding')) {
|
||||||
|
return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8');
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(strlen($utf8)) {
|
||||||
|
case 1:
|
||||||
|
// this case should never be reached, because we are in ASCII range
|
||||||
|
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||||
|
return $utf8;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
// return a UTF-16 character from a 2-byte UTF-8 char
|
||||||
|
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||||
|
return chr(0x07 & (ord($utf8{0}) >> 2))
|
||||||
|
. chr((0xC0 & (ord($utf8{0}) << 6))
|
||||||
|
| (0x3F & ord($utf8{1})));
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
// return a UTF-16 character from a 3-byte UTF-8 char
|
||||||
|
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||||
|
return chr((0xF0 & (ord($utf8{0}) << 4))
|
||||||
|
| (0x0F & (ord($utf8{1}) >> 2)))
|
||||||
|
. chr((0xC0 & (ord($utf8{1}) << 6))
|
||||||
|
| (0x7F & ord($utf8{2})));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ignoring UTF-32 for now, sorry
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* encodes an arbitrary variable into JSON format (and sends JSON Header)
|
||||||
|
*
|
||||||
|
* @param mixed $var any number, boolean, string, array, or object to be encoded.
|
||||||
|
* see argument 1 to Services_JSON() above for array-parsing behavior.
|
||||||
|
* if var is a strng, note that encode() always expects it
|
||||||
|
* to be in ASCII or UTF-8 format!
|
||||||
|
*
|
||||||
|
* @return mixed JSON string representation of input var or an error if a problem occurs
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function encode($var)
|
||||||
|
{
|
||||||
|
header('Content-type: application/json');
|
||||||
|
return $this->_encode($var);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* encodes an arbitrary variable into JSON format without JSON Header - warning - may allow CSS!!!!)
|
||||||
|
*
|
||||||
|
* @param mixed $var any number, boolean, string, array, or object to be encoded.
|
||||||
|
* see argument 1 to Services_JSON() above for array-parsing behavior.
|
||||||
|
* if var is a strng, note that encode() always expects it
|
||||||
|
* to be in ASCII or UTF-8 format!
|
||||||
|
*
|
||||||
|
* @return mixed JSON string representation of input var or an error if a problem occurs
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function encodeUnsafe($var)
|
||||||
|
{
|
||||||
|
return $this->_encode($var);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* PRIVATE CODE that does the work of encodes an arbitrary variable into JSON format
|
||||||
|
*
|
||||||
|
* @param mixed $var any number, boolean, string, array, or object to be encoded.
|
||||||
|
* see argument 1 to Services_JSON() above for array-parsing behavior.
|
||||||
|
* if var is a strng, note that encode() always expects it
|
||||||
|
* to be in ASCII or UTF-8 format!
|
||||||
|
*
|
||||||
|
* @return mixed JSON string representation of input var or an error if a problem occurs
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function _encode($var)
|
||||||
|
{
|
||||||
|
|
||||||
|
switch (gettype($var)) {
|
||||||
|
case 'boolean':
|
||||||
|
return $var ? 'true' : 'false';
|
||||||
|
|
||||||
|
case 'NULL':
|
||||||
|
return 'null';
|
||||||
|
|
||||||
|
case 'integer':
|
||||||
|
return (int) $var;
|
||||||
|
|
||||||
|
case 'double':
|
||||||
|
case 'float':
|
||||||
|
return (float) $var;
|
||||||
|
|
||||||
|
case 'string':
|
||||||
|
// STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
|
||||||
|
$ascii = '';
|
||||||
|
$strlen_var = strlen($var);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Iterate over every character in the string,
|
||||||
|
* escaping with a slash or encoding to UTF-8 where necessary
|
||||||
|
*/
|
||||||
|
for ($c = 0; $c < $strlen_var; ++$c) {
|
||||||
|
|
||||||
|
$ord_var_c = ord($var{$c});
|
||||||
|
|
||||||
|
switch (true) {
|
||||||
|
case $ord_var_c == 0x08:
|
||||||
|
$ascii .= '\b';
|
||||||
|
break;
|
||||||
|
case $ord_var_c == 0x09:
|
||||||
|
$ascii .= '\t';
|
||||||
|
break;
|
||||||
|
case $ord_var_c == 0x0A:
|
||||||
|
$ascii .= '\n';
|
||||||
|
break;
|
||||||
|
case $ord_var_c == 0x0C:
|
||||||
|
$ascii .= '\f';
|
||||||
|
break;
|
||||||
|
case $ord_var_c == 0x0D:
|
||||||
|
$ascii .= '\r';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case $ord_var_c == 0x22:
|
||||||
|
case $ord_var_c == 0x2F:
|
||||||
|
case $ord_var_c == 0x5C:
|
||||||
|
// double quote, slash, slosh
|
||||||
|
$ascii .= '\\'.$var{$c};
|
||||||
|
break;
|
||||||
|
|
||||||
|
case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)):
|
||||||
|
// characters U-00000000 - U-0000007F (same as ASCII)
|
||||||
|
$ascii .= $var{$c};
|
||||||
|
break;
|
||||||
|
|
||||||
|
case (($ord_var_c & 0xE0) == 0xC0):
|
||||||
|
// characters U-00000080 - U-000007FF, mask 110XXXXX
|
||||||
|
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||||
|
if ($c+1 >= $strlen_var) {
|
||||||
|
$c += 1;
|
||||||
|
$ascii .= '?';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$char = pack('C*', $ord_var_c, ord($var{$c + 1}));
|
||||||
|
$c += 1;
|
||||||
|
$utf16 = $this->utf82utf16($char);
|
||||||
|
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case (($ord_var_c & 0xF0) == 0xE0):
|
||||||
|
if ($c+2 >= $strlen_var) {
|
||||||
|
$c += 2;
|
||||||
|
$ascii .= '?';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// characters U-00000800 - U-0000FFFF, mask 1110XXXX
|
||||||
|
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||||
|
$char = pack('C*', $ord_var_c,
|
||||||
|
@ord($var{$c + 1}),
|
||||||
|
@ord($var{$c + 2}));
|
||||||
|
$c += 2;
|
||||||
|
$utf16 = $this->utf82utf16($char);
|
||||||
|
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case (($ord_var_c & 0xF8) == 0xF0):
|
||||||
|
if ($c+3 >= $strlen_var) {
|
||||||
|
$c += 3;
|
||||||
|
$ascii .= '?';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// characters U-00010000 - U-001FFFFF, mask 11110XXX
|
||||||
|
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||||
|
$char = pack('C*', $ord_var_c,
|
||||||
|
ord($var{$c + 1}),
|
||||||
|
ord($var{$c + 2}),
|
||||||
|
ord($var{$c + 3}));
|
||||||
|
$c += 3;
|
||||||
|
$utf16 = $this->utf82utf16($char);
|
||||||
|
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case (($ord_var_c & 0xFC) == 0xF8):
|
||||||
|
// characters U-00200000 - U-03FFFFFF, mask 111110XX
|
||||||
|
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||||
|
if ($c+4 >= $strlen_var) {
|
||||||
|
$c += 4;
|
||||||
|
$ascii .= '?';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$char = pack('C*', $ord_var_c,
|
||||||
|
ord($var{$c + 1}),
|
||||||
|
ord($var{$c + 2}),
|
||||||
|
ord($var{$c + 3}),
|
||||||
|
ord($var{$c + 4}));
|
||||||
|
$c += 4;
|
||||||
|
$utf16 = $this->utf82utf16($char);
|
||||||
|
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case (($ord_var_c & 0xFE) == 0xFC):
|
||||||
|
if ($c+5 >= $strlen_var) {
|
||||||
|
$c += 5;
|
||||||
|
$ascii .= '?';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// characters U-04000000 - U-7FFFFFFF, mask 1111110X
|
||||||
|
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||||
|
$char = pack('C*', $ord_var_c,
|
||||||
|
ord($var{$c + 1}),
|
||||||
|
ord($var{$c + 2}),
|
||||||
|
ord($var{$c + 3}),
|
||||||
|
ord($var{$c + 4}),
|
||||||
|
ord($var{$c + 5}));
|
||||||
|
$c += 5;
|
||||||
|
$utf16 = $this->utf82utf16($char);
|
||||||
|
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return '"'.$ascii.'"';
|
||||||
|
|
||||||
|
case 'array':
|
||||||
|
/*
|
||||||
|
* As per JSON spec if any array key is not an integer
|
||||||
|
* we must treat the the whole array as an object. We
|
||||||
|
* also try to catch a sparsely populated associative
|
||||||
|
* array with numeric keys here because some JS engines
|
||||||
|
* will create an array with empty indexes up to
|
||||||
|
* max_index which can cause memory issues and because
|
||||||
|
* the keys, which may be relevant, will be remapped
|
||||||
|
* otherwise.
|
||||||
|
*
|
||||||
|
* As per the ECMA and JSON specification an object may
|
||||||
|
* have any string as a property. Unfortunately due to
|
||||||
|
* a hole in the ECMA specification if the key is a
|
||||||
|
* ECMA reserved word or starts with a digit the
|
||||||
|
* parameter is only accessible using ECMAScript's
|
||||||
|
* bracket notation.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// treat as a JSON object
|
||||||
|
if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) {
|
||||||
|
$properties = array_map(array($this, 'name_value'),
|
||||||
|
array_keys($var),
|
||||||
|
array_values($var));
|
||||||
|
|
||||||
|
foreach($properties as $property) {
|
||||||
|
if(Services_JSON::isError($property)) {
|
||||||
|
return $property;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return '{' . join(',', $properties) . '}';
|
||||||
|
}
|
||||||
|
|
||||||
|
// treat it like a regular array
|
||||||
|
$elements = array_map(array($this, '_encode'), $var);
|
||||||
|
|
||||||
|
foreach($elements as $element) {
|
||||||
|
if(Services_JSON::isError($element)) {
|
||||||
|
return $element;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return '[' . join(',', $elements) . ']';
|
||||||
|
|
||||||
|
case 'object':
|
||||||
|
$vars = get_object_vars($var);
|
||||||
|
|
||||||
|
$properties = array_map(array($this, 'name_value'),
|
||||||
|
array_keys($vars),
|
||||||
|
array_values($vars));
|
||||||
|
|
||||||
|
foreach($properties as $property) {
|
||||||
|
if(Services_JSON::isError($property)) {
|
||||||
|
return $property;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return '{' . join(',', $properties) . '}';
|
||||||
|
|
||||||
|
default:
|
||||||
|
return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS)
|
||||||
|
? 'null'
|
||||||
|
: new Services_JSON_Error(gettype($var)." can not be encoded as JSON string");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* array-walking function for use in generating JSON-formatted name-value pairs
|
||||||
|
*
|
||||||
|
* @param string $name name of key to use
|
||||||
|
* @param mixed $value reference to an array element to be encoded
|
||||||
|
*
|
||||||
|
* @return string JSON-formatted name-value pair, like '"name":value'
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
function name_value($name, $value)
|
||||||
|
{
|
||||||
|
$encoded_value = $this->_encode($value);
|
||||||
|
|
||||||
|
if(Services_JSON::isError($encoded_value)) {
|
||||||
|
return $encoded_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->_encode(strval($name)) . ':' . $encoded_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* reduce a string by removing leading and trailing comments and whitespace
|
||||||
|
*
|
||||||
|
* @param $str string string value to strip of comments and whitespace
|
||||||
|
*
|
||||||
|
* @return string string value stripped of comments and whitespace
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
function reduce_string($str)
|
||||||
|
{
|
||||||
|
$str = preg_replace(array(
|
||||||
|
|
||||||
|
// eliminate single line comments in '// ...' form
|
||||||
|
'#^\s*//(.+)$#m',
|
||||||
|
|
||||||
|
// eliminate multi-line comments in '/* ... */' form, at start of string
|
||||||
|
'#^\s*/\*(.+)\*/#Us',
|
||||||
|
|
||||||
|
// eliminate multi-line comments in '/* ... */' form, at end of string
|
||||||
|
'#/\*(.+)\*/\s*$#Us'
|
||||||
|
|
||||||
|
), '', $str);
|
||||||
|
|
||||||
|
// eliminate extraneous space
|
||||||
|
return trim($str);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* decodes a JSON string into appropriate variable
|
||||||
|
*
|
||||||
|
* @param string $str JSON-formatted string
|
||||||
|
*
|
||||||
|
* @return mixed number, boolean, string, array, or object
|
||||||
|
* corresponding to given JSON input string.
|
||||||
|
* See argument 1 to Services_JSON() above for object-output behavior.
|
||||||
|
* Note that decode() always returns strings
|
||||||
|
* in ASCII or UTF-8 format!
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function decode($str)
|
||||||
|
{
|
||||||
|
$str = $this->reduce_string($str);
|
||||||
|
|
||||||
|
switch (strtolower($str)) {
|
||||||
|
case 'true':
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'false':
|
||||||
|
return false;
|
||||||
|
|
||||||
|
case 'null':
|
||||||
|
return null;
|
||||||
|
|
||||||
|
default:
|
||||||
|
$m = array();
|
||||||
|
|
||||||
|
if (is_numeric($str)) {
|
||||||
|
// Lookie-loo, it's a number
|
||||||
|
|
||||||
|
// This would work on its own, but I'm trying to be
|
||||||
|
// good about returning integers where appropriate:
|
||||||
|
// return (float)$str;
|
||||||
|
|
||||||
|
// Return float or int, as appropriate
|
||||||
|
return ((float)$str == (integer)$str)
|
||||||
|
? (integer)$str
|
||||||
|
: (float)$str;
|
||||||
|
|
||||||
|
} elseif (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) {
|
||||||
|
// STRINGS RETURNED IN UTF-8 FORMAT
|
||||||
|
$delim = substr($str, 0, 1);
|
||||||
|
$chrs = substr($str, 1, -1);
|
||||||
|
$utf8 = '';
|
||||||
|
$strlen_chrs = strlen($chrs);
|
||||||
|
|
||||||
|
for ($c = 0; $c < $strlen_chrs; ++$c) {
|
||||||
|
|
||||||
|
$substr_chrs_c_2 = substr($chrs, $c, 2);
|
||||||
|
$ord_chrs_c = ord($chrs{$c});
|
||||||
|
|
||||||
|
switch (true) {
|
||||||
|
case $substr_chrs_c_2 == '\b':
|
||||||
|
$utf8 .= chr(0x08);
|
||||||
|
++$c;
|
||||||
|
break;
|
||||||
|
case $substr_chrs_c_2 == '\t':
|
||||||
|
$utf8 .= chr(0x09);
|
||||||
|
++$c;
|
||||||
|
break;
|
||||||
|
case $substr_chrs_c_2 == '\n':
|
||||||
|
$utf8 .= chr(0x0A);
|
||||||
|
++$c;
|
||||||
|
break;
|
||||||
|
case $substr_chrs_c_2 == '\f':
|
||||||
|
$utf8 .= chr(0x0C);
|
||||||
|
++$c;
|
||||||
|
break;
|
||||||
|
case $substr_chrs_c_2 == '\r':
|
||||||
|
$utf8 .= chr(0x0D);
|
||||||
|
++$c;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case $substr_chrs_c_2 == '\\"':
|
||||||
|
case $substr_chrs_c_2 == '\\\'':
|
||||||
|
case $substr_chrs_c_2 == '\\\\':
|
||||||
|
case $substr_chrs_c_2 == '\\/':
|
||||||
|
if (($delim == '"' && $substr_chrs_c_2 != '\\\'') ||
|
||||||
|
($delim == "'" && $substr_chrs_c_2 != '\\"')) {
|
||||||
|
$utf8 .= $chrs{++$c};
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case preg_match('/\\\u[0-9A-F]{4}/i', substr($chrs, $c, 6)):
|
||||||
|
// single, escaped unicode character
|
||||||
|
$utf16 = chr(hexdec(substr($chrs, ($c + 2), 2)))
|
||||||
|
. chr(hexdec(substr($chrs, ($c + 4), 2)));
|
||||||
|
$utf8 .= $this->utf162utf8($utf16);
|
||||||
|
$c += 5;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F):
|
||||||
|
$utf8 .= $chrs{$c};
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ($ord_chrs_c & 0xE0) == 0xC0:
|
||||||
|
// characters U-00000080 - U-000007FF, mask 110XXXXX
|
||||||
|
//see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||||
|
$utf8 .= substr($chrs, $c, 2);
|
||||||
|
++$c;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ($ord_chrs_c & 0xF0) == 0xE0:
|
||||||
|
// characters U-00000800 - U-0000FFFF, mask 1110XXXX
|
||||||
|
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||||
|
$utf8 .= substr($chrs, $c, 3);
|
||||||
|
$c += 2;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ($ord_chrs_c & 0xF8) == 0xF0:
|
||||||
|
// characters U-00010000 - U-001FFFFF, mask 11110XXX
|
||||||
|
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||||
|
$utf8 .= substr($chrs, $c, 4);
|
||||||
|
$c += 3;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ($ord_chrs_c & 0xFC) == 0xF8:
|
||||||
|
// characters U-00200000 - U-03FFFFFF, mask 111110XX
|
||||||
|
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||||
|
$utf8 .= substr($chrs, $c, 5);
|
||||||
|
$c += 4;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ($ord_chrs_c & 0xFE) == 0xFC:
|
||||||
|
// characters U-04000000 - U-7FFFFFFF, mask 1111110X
|
||||||
|
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||||
|
$utf8 .= substr($chrs, $c, 6);
|
||||||
|
$c += 5;
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return $utf8;
|
||||||
|
|
||||||
|
} elseif (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) {
|
||||||
|
// array, or object notation
|
||||||
|
|
||||||
|
if ($str{0} == '[') {
|
||||||
|
$stk = array(SERVICES_JSON_IN_ARR);
|
||||||
|
$arr = array();
|
||||||
|
} else {
|
||||||
|
if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
|
||||||
|
$stk = array(SERVICES_JSON_IN_OBJ);
|
||||||
|
$obj = array();
|
||||||
|
} else {
|
||||||
|
$stk = array(SERVICES_JSON_IN_OBJ);
|
||||||
|
$obj = new stdClass();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
array_push($stk, array('what' => SERVICES_JSON_SLICE,
|
||||||
|
'where' => 0,
|
||||||
|
'delim' => false));
|
||||||
|
|
||||||
|
$chrs = substr($str, 1, -1);
|
||||||
|
$chrs = $this->reduce_string($chrs);
|
||||||
|
|
||||||
|
if ($chrs == '') {
|
||||||
|
if (reset($stk) == SERVICES_JSON_IN_ARR) {
|
||||||
|
return $arr;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return $obj;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//print("\nparsing {$chrs}\n");
|
||||||
|
|
||||||
|
$strlen_chrs = strlen($chrs);
|
||||||
|
|
||||||
|
for ($c = 0; $c <= $strlen_chrs; ++$c) {
|
||||||
|
|
||||||
|
$top = end($stk);
|
||||||
|
$substr_chrs_c_2 = substr($chrs, $c, 2);
|
||||||
|
|
||||||
|
if (($c == $strlen_chrs) || (($chrs{$c} == ',') && ($top['what'] == SERVICES_JSON_SLICE))) {
|
||||||
|
// found a comma that is not inside a string, array, etc.,
|
||||||
|
// OR we've reached the end of the character list
|
||||||
|
$slice = substr($chrs, $top['where'], ($c - $top['where']));
|
||||||
|
array_push($stk, array('what' => SERVICES_JSON_SLICE, 'where' => ($c + 1), 'delim' => false));
|
||||||
|
//print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
|
||||||
|
|
||||||
|
if (reset($stk) == SERVICES_JSON_IN_ARR) {
|
||||||
|
// we are in an array, so just push an element onto the stack
|
||||||
|
array_push($arr, $this->decode($slice));
|
||||||
|
|
||||||
|
} elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
|
||||||
|
// we are in an object, so figure
|
||||||
|
// out the property name and set an
|
||||||
|
// element in an associative array,
|
||||||
|
// for now
|
||||||
|
$parts = array();
|
||||||
|
|
||||||
|
if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
|
||||||
|
// "name":value pair
|
||||||
|
$key = $this->decode($parts[1]);
|
||||||
|
$val = $this->decode($parts[2]);
|
||||||
|
|
||||||
|
if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
|
||||||
|
$obj[$key] = $val;
|
||||||
|
} else {
|
||||||
|
$obj->$key = $val;
|
||||||
|
}
|
||||||
|
} elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
|
||||||
|
// name:value pair, where name is unquoted
|
||||||
|
$key = $parts[1];
|
||||||
|
$val = $this->decode($parts[2]);
|
||||||
|
|
||||||
|
if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
|
||||||
|
$obj[$key] = $val;
|
||||||
|
} else {
|
||||||
|
$obj->$key = $val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != SERVICES_JSON_IN_STR)) {
|
||||||
|
// found a quote, and we are not inside a string
|
||||||
|
array_push($stk, array('what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c}));
|
||||||
|
//print("Found start of string at {$c}\n");
|
||||||
|
|
||||||
|
} elseif (($chrs{$c} == $top['delim']) &&
|
||||||
|
($top['what'] == SERVICES_JSON_IN_STR) &&
|
||||||
|
((strlen(substr($chrs, 0, $c)) - strlen(rtrim(substr($chrs, 0, $c), '\\'))) % 2 != 1)) {
|
||||||
|
// found a quote, we're in a string, and it's not escaped
|
||||||
|
// we know that it's not escaped becase there is _not_ an
|
||||||
|
// odd number of backslashes at the end of the string so far
|
||||||
|
array_pop($stk);
|
||||||
|
//print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n");
|
||||||
|
|
||||||
|
} elseif (($chrs{$c} == '[') &&
|
||||||
|
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
|
||||||
|
// found a left-bracket, and we are in an array, object, or slice
|
||||||
|
array_push($stk, array('what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false));
|
||||||
|
//print("Found start of array at {$c}\n");
|
||||||
|
|
||||||
|
} elseif (($chrs{$c} == ']') && ($top['what'] == SERVICES_JSON_IN_ARR)) {
|
||||||
|
// found a right-bracket, and we're in an array
|
||||||
|
array_pop($stk);
|
||||||
|
//print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
|
||||||
|
|
||||||
|
} elseif (($chrs{$c} == '{') &&
|
||||||
|
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
|
||||||
|
// found a left-brace, and we are in an array, object, or slice
|
||||||
|
array_push($stk, array('what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false));
|
||||||
|
//print("Found start of object at {$c}\n");
|
||||||
|
|
||||||
|
} elseif (($chrs{$c} == '}') && ($top['what'] == SERVICES_JSON_IN_OBJ)) {
|
||||||
|
// found a right-brace, and we're in an object
|
||||||
|
array_pop($stk);
|
||||||
|
//print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
|
||||||
|
|
||||||
|
} elseif (($substr_chrs_c_2 == '/*') &&
|
||||||
|
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
|
||||||
|
// found a comment start, and we are in an array, object, or slice
|
||||||
|
array_push($stk, array('what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false));
|
||||||
|
$c++;
|
||||||
|
//print("Found start of comment at {$c}\n");
|
||||||
|
|
||||||
|
} elseif (($substr_chrs_c_2 == '*/') && ($top['what'] == SERVICES_JSON_IN_CMT)) {
|
||||||
|
// found a comment end, and we're in one now
|
||||||
|
array_pop($stk);
|
||||||
|
$c++;
|
||||||
|
|
||||||
|
for ($i = $top['where']; $i <= $c; ++$i)
|
||||||
|
$chrs = substr_replace($chrs, ' ', $i, 1);
|
||||||
|
|
||||||
|
//print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reset($stk) == SERVICES_JSON_IN_ARR) {
|
||||||
|
return $arr;
|
||||||
|
|
||||||
|
} elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
|
||||||
|
return $obj;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @todo Ultimately, this should just call PEAR::isError()
|
||||||
|
*/
|
||||||
|
function isError($data, $code = null)
|
||||||
|
{
|
||||||
|
if (class_exists('pear')) {
|
||||||
|
return PEAR::isError($data, $code);
|
||||||
|
} elseif (is_object($data) && (get_class($data) == 'services_json_error' ||
|
||||||
|
is_subclass_of($data, 'services_json_error'))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (class_exists('PEAR_Error')) {
|
||||||
|
|
||||||
|
class Services_JSON_Error extends PEAR_Error
|
||||||
|
{
|
||||||
|
function Services_JSON_Error($message = 'unknown error', $code = null,
|
||||||
|
$mode = null, $options = null, $userinfo = null)
|
||||||
|
{
|
||||||
|
parent::PEAR_Error($message, $code, $mode, $options, $userinfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @todo Ultimately, this class shall be descended from PEAR_Error
|
||||||
|
*/
|
||||||
|
class Services_JSON_Error
|
||||||
|
{
|
||||||
|
function Services_JSON_Error($message = 'unknown error', $code = null,
|
||||||
|
$mode = null, $options = null, $userinfo = null)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class JSON_API_Attachment {
|
||||||
|
|
||||||
|
var $id; // Integer
|
||||||
|
var $url; // String
|
||||||
|
var $slug; // String
|
||||||
|
var $title; // String
|
||||||
|
var $description; // String
|
||||||
|
var $caption; // String
|
||||||
|
var $parent; // Integer
|
||||||
|
var $mime_type; // String
|
||||||
|
|
||||||
|
function JSON_API_Attachment($wp_attachment = null) {
|
||||||
|
if ($wp_attachment) {
|
||||||
|
$this->import_wp_object($wp_attachment);
|
||||||
|
if ($this->is_image()) {
|
||||||
|
$this->query_images();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function import_wp_object($wp_attachment) {
|
||||||
|
$this->id = (int) $wp_attachment->ID;
|
||||||
|
$this->url = $wp_attachment->guid;
|
||||||
|
$this->slug = $wp_attachment->post_name;
|
||||||
|
$this->title = $wp_attachment->post_title;
|
||||||
|
$this->description = $wp_attachment->post_content;
|
||||||
|
$this->caption = $wp_attachment->post_excerpt;
|
||||||
|
$this->parent = (int) $wp_attachment->post_parent;
|
||||||
|
$this->mime_type = $wp_attachment->post_mime_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
function is_image() {
|
||||||
|
return (substr($this->mime_type, 0, 5) == 'image');
|
||||||
|
}
|
||||||
|
|
||||||
|
function query_images() {
|
||||||
|
$sizes = array('thumbnail', 'medium', 'large', 'full');
|
||||||
|
if (function_exists('get_intermediate_image_sizes')) {
|
||||||
|
$sizes = array_merge(array('full'), get_intermediate_image_sizes());
|
||||||
|
}
|
||||||
|
$this->images = array();
|
||||||
|
foreach ($sizes as $size) {
|
||||||
|
list($url, $width, $height) = wp_get_attachment_image_src($this->id, $size);
|
||||||
|
$this->images[$size] = (object) array(
|
||||||
|
'url' => $url,
|
||||||
|
'width' => $width,
|
||||||
|
'height' => $height
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class JSON_API_Author {
|
||||||
|
|
||||||
|
var $id; // Integer
|
||||||
|
var $slug; // String
|
||||||
|
var $name; // String
|
||||||
|
var $first_name; // String
|
||||||
|
var $last_name; // String
|
||||||
|
var $nickname; // String
|
||||||
|
var $url; // String
|
||||||
|
var $description; // String
|
||||||
|
|
||||||
|
// Note:
|
||||||
|
// JSON_API_Author objects can include additional values by using the
|
||||||
|
// author_meta query var.
|
||||||
|
|
||||||
|
function JSON_API_Author($id = null) {
|
||||||
|
if ($id) {
|
||||||
|
$this->id = (int) $id;
|
||||||
|
} else {
|
||||||
|
$this->id = (int) get_the_author_meta('ID');
|
||||||
|
}
|
||||||
|
$this->set_value('slug', 'user_nicename');
|
||||||
|
$this->set_value('name', 'display_name');
|
||||||
|
$this->set_value('first_name', 'first_name');
|
||||||
|
$this->set_value('last_name', 'last_name');
|
||||||
|
$this->set_value('nickname', 'nickname');
|
||||||
|
$this->set_value('url', 'user_url');
|
||||||
|
$this->set_value('description', 'description');
|
||||||
|
$this->set_author_meta();
|
||||||
|
//$this->raw = get_userdata($this->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_value($key, $wp_key = false) {
|
||||||
|
if (!$wp_key) {
|
||||||
|
$wp_key = $key;
|
||||||
|
}
|
||||||
|
$this->$key = get_the_author_meta($wp_key, $this->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_author_meta() {
|
||||||
|
global $json_api;
|
||||||
|
if (!$json_api->query->author_meta) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$protected_vars = array(
|
||||||
|
'user_login',
|
||||||
|
'user_pass',
|
||||||
|
'user_email',
|
||||||
|
'user_activation_key'
|
||||||
|
);
|
||||||
|
$vars = explode(',', $json_api->query->author_meta);
|
||||||
|
$vars = array_diff($vars, $protected_vars);
|
||||||
|
foreach ($vars as $var) {
|
||||||
|
$this->set_value($var);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class JSON_API_Category {
|
||||||
|
|
||||||
|
var $id; // Integer
|
||||||
|
var $slug; // String
|
||||||
|
var $title; // String
|
||||||
|
var $description; // String
|
||||||
|
var $parent; // Integer
|
||||||
|
var $post_count; // Integer
|
||||||
|
|
||||||
|
function JSON_API_Category($wp_category = null) {
|
||||||
|
if ($wp_category) {
|
||||||
|
$this->import_wp_object($wp_category);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function import_wp_object($wp_category) {
|
||||||
|
$this->id = (int) $wp_category->term_id;
|
||||||
|
$this->slug = $wp_category->slug;
|
||||||
|
$this->title = $wp_category->name;
|
||||||
|
$this->description = $wp_category->description;
|
||||||
|
$this->parent = (int) $wp_category->parent;
|
||||||
|
$this->post_count = (int) $wp_category->count;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class JSON_API_Comment {
|
||||||
|
|
||||||
|
var $id; // Integer
|
||||||
|
var $name; // String
|
||||||
|
var $url; // String
|
||||||
|
var $date; // String
|
||||||
|
var $content; // String
|
||||||
|
var $parent; // Integer
|
||||||
|
var $author; // Object (only if the user was registered & logged in)
|
||||||
|
|
||||||
|
function JSON_API_Comment($wp_comment = null) {
|
||||||
|
if ($wp_comment) {
|
||||||
|
$this->import_wp_object($wp_comment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function import_wp_object($wp_comment) {
|
||||||
|
global $json_api;
|
||||||
|
|
||||||
|
$date_format = $json_api->query->date_format;
|
||||||
|
$content = apply_filters('comment_text', $wp_comment->comment_content);
|
||||||
|
|
||||||
|
$this->id = (int) $wp_comment->comment_ID;
|
||||||
|
$this->name = $wp_comment->comment_author;
|
||||||
|
$this->url = $wp_comment->comment_author_url;
|
||||||
|
$this->date = date($date_format, strtotime($wp_comment->comment_date));
|
||||||
|
$this->content = $content;
|
||||||
|
$this->parent = (int) $wp_comment->comment_parent;
|
||||||
|
//$this->raw = $wp_comment;
|
||||||
|
|
||||||
|
if (!empty($wp_comment->user_id)) {
|
||||||
|
$this->author = new JSON_API_Author($wp_comment->user_id);
|
||||||
|
} else {
|
||||||
|
unset($this->author);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handle_submission() {
|
||||||
|
global $comment, $wpdb;
|
||||||
|
add_action('comment_id_not_found', array(&$this, 'comment_id_not_found'));
|
||||||
|
add_action('comment_closed', array(&$this, 'comment_closed'));
|
||||||
|
add_action('comment_on_draft', array(&$this, 'comment_on_draft'));
|
||||||
|
add_filter('comment_post_redirect', array(&$this, 'comment_post_redirect'));
|
||||||
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
||||||
|
$_POST['comment_post_ID'] = $_REQUEST['post_id'];
|
||||||
|
$_POST['author'] = $_REQUEST['name'];
|
||||||
|
$_POST['email'] = $_REQUEST['email'];
|
||||||
|
$_POST['url'] = empty($_REQUEST['url']) ? '' : $_REQUEST['url'];
|
||||||
|
$_POST['comment'] = $_REQUEST['content'];
|
||||||
|
$_POST['parent'] = $_REQUEST['parent'];
|
||||||
|
include ABSPATH . 'wp-comments-post.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
function comment_id_not_found() {
|
||||||
|
global $json_api;
|
||||||
|
$json_api->error("Post ID '{$_REQUEST['post_id']}' not found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
function comment_closed() {
|
||||||
|
global $json_api;
|
||||||
|
$json_api->error("Post is closed for comments.");
|
||||||
|
}
|
||||||
|
|
||||||
|
function comment_on_draft() {
|
||||||
|
global $json_api;
|
||||||
|
$json_api->error("You cannot comment on unpublished posts.");
|
||||||
|
}
|
||||||
|
|
||||||
|
function comment_post_redirect() {
|
||||||
|
global $comment, $json_api;
|
||||||
|
$status = ($comment->comment_approved) ? 'ok' : 'pending';
|
||||||
|
$new_comment = new JSON_API_Comment($comment);
|
||||||
|
$json_api->response->respond($new_comment, $status);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
+283
@@ -0,0 +1,283 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class JSON_API_Post {
|
||||||
|
|
||||||
|
// Note:
|
||||||
|
// JSON_API_Post objects must be instantiated within The Loop.
|
||||||
|
|
||||||
|
var $id; // Integer
|
||||||
|
var $type; // String
|
||||||
|
var $slug; // String
|
||||||
|
var $url; // String
|
||||||
|
var $status; // String ("draft", "published", or "pending")
|
||||||
|
var $title; // String
|
||||||
|
var $title_plain; // String
|
||||||
|
var $content; // String (modified by read_more query var)
|
||||||
|
var $excerpt; // String
|
||||||
|
var $date; // String (modified by date_format query var)
|
||||||
|
var $modified; // String (modified by date_format query var)
|
||||||
|
var $categories; // Array of objects
|
||||||
|
var $tags; // Array of objects
|
||||||
|
var $author; // Object
|
||||||
|
var $comments; // Array of objects
|
||||||
|
var $attachments; // Array of objects
|
||||||
|
var $comment_count; // Integer
|
||||||
|
var $comment_status; // String ("open" or "closed")
|
||||||
|
var $thumbnail; // String
|
||||||
|
var $custom_fields; // Object (included by using custom_fields query var)
|
||||||
|
|
||||||
|
function JSON_API_Post($wp_post = null) {
|
||||||
|
if (!empty($wp_post)) {
|
||||||
|
$this->import_wp_object($wp_post);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function create($values = null) {
|
||||||
|
unset($values['id']);
|
||||||
|
if (empty($values) || empty($values['title'])) {
|
||||||
|
$values = array(
|
||||||
|
'title' => 'Untitled',
|
||||||
|
'content' => ''
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return $this->save($values);
|
||||||
|
}
|
||||||
|
|
||||||
|
function update($values) {
|
||||||
|
$values['id'] = $this->id;
|
||||||
|
return $this->save($values);
|
||||||
|
}
|
||||||
|
|
||||||
|
function save($values = null) {
|
||||||
|
global $json_api, $user_ID;
|
||||||
|
|
||||||
|
$wp_values = array();
|
||||||
|
|
||||||
|
if (!empty($values['id'])) {
|
||||||
|
$wp_values['ID'] = $values['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($values['type'])) {
|
||||||
|
$wp_values['post_type'] = $values['type'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($values['status'])) {
|
||||||
|
$wp_values['post_status'] = $values['status'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($values['title'])) {
|
||||||
|
$wp_values['post_title'] = $values['title'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($values['content'])) {
|
||||||
|
$wp_values['post_content'] = $values['content'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($values['author'])) {
|
||||||
|
$author = $json_api->introspector->get_author_by_login($values['author']);
|
||||||
|
$wp_values['post_author'] = $author->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($values['categories'])) {
|
||||||
|
$categories = explode(',', $values['categories']);
|
||||||
|
foreach ($categories as $category_slug) {
|
||||||
|
$category_slug = trim($category_slug);
|
||||||
|
$category = $json_api->introspector->get_category_by_slug($category_slug);
|
||||||
|
if (empty($wp_values['post_category'])) {
|
||||||
|
$wp_values['post_category'] = array($category->id);
|
||||||
|
} else {
|
||||||
|
array_push($wp_values['post_category'], $category->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($values['tags'])) {
|
||||||
|
$tags = explode(',', $values['tags']);
|
||||||
|
foreach ($tags as $tag_slug) {
|
||||||
|
$tag_slug = trim($tag_slug);
|
||||||
|
if (empty($wp_values['tags_input'])) {
|
||||||
|
$wp_values['tags_input'] = array($tag_slug);
|
||||||
|
} else {
|
||||||
|
array_push($wp_values['tags_input'], $tag_slug);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($wp_values['ID'])) {
|
||||||
|
$this->id = wp_update_post($wp_values);
|
||||||
|
} else {
|
||||||
|
$this->id = wp_insert_post($wp_values);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($_FILES['attachment'])) {
|
||||||
|
include_once ABSPATH . '/wp-admin/includes/file.php';
|
||||||
|
include_once ABSPATH . '/wp-admin/includes/media.php';
|
||||||
|
include_once ABSPATH . '/wp-admin/includes/image.php';
|
||||||
|
$attachment_id = media_handle_upload('attachment', $this->id);
|
||||||
|
$this->attachments[] = new JSON_API_Attachment($attachment_id);
|
||||||
|
unset($_FILES['attachment']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$wp_post = get_post($this->id);
|
||||||
|
$this->import_wp_object($wp_post);
|
||||||
|
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
function import_wp_object($wp_post) {
|
||||||
|
global $json_api, $post;
|
||||||
|
$date_format = $json_api->query->date_format;
|
||||||
|
$this->id = (int) $wp_post->ID;
|
||||||
|
setup_postdata($wp_post);
|
||||||
|
$this->set_value('type', $wp_post->post_type);
|
||||||
|
$this->set_value('slug', $wp_post->post_name);
|
||||||
|
$this->set_value('url', get_permalink($this->id));
|
||||||
|
$this->set_value('status', $wp_post->post_status);
|
||||||
|
$this->set_value('title', get_the_title($this->id));
|
||||||
|
$this->set_value('title_plain', strip_tags(@$this->title));
|
||||||
|
$this->set_content_value();
|
||||||
|
$this->set_value('excerpt', get_the_excerpt());
|
||||||
|
$this->set_value('date', get_the_time($date_format));
|
||||||
|
$this->set_value('modified', date($date_format, strtotime($wp_post->post_modified)));
|
||||||
|
$this->set_categories_value();
|
||||||
|
$this->set_tags_value();
|
||||||
|
$this->set_author_value($wp_post->post_author);
|
||||||
|
$this->set_comments_value();
|
||||||
|
$this->set_attachments_value();
|
||||||
|
$this->set_value('comment_count', (int) $wp_post->comment_count);
|
||||||
|
$this->set_value('comment_status', $wp_post->comment_status);
|
||||||
|
$this->set_thumbnail_value();
|
||||||
|
$this->set_custom_fields_value();
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_value($key, $value) {
|
||||||
|
global $json_api;
|
||||||
|
if ($json_api->include_value($key)) {
|
||||||
|
$this->$key = $value;
|
||||||
|
} else {
|
||||||
|
unset($this->$key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_content_value() {
|
||||||
|
global $json_api;
|
||||||
|
if ($json_api->include_value('content')) {
|
||||||
|
$content = get_the_content($json_api->query->read_more);
|
||||||
|
$content = apply_filters('the_content', $content);
|
||||||
|
$content = str_replace(']]>', ']]>', $content);
|
||||||
|
$this->content = $content;
|
||||||
|
} else {
|
||||||
|
unset($this->content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_categories_value() {
|
||||||
|
global $json_api;
|
||||||
|
if ($json_api->include_value('categories')) {
|
||||||
|
$this->categories = array();
|
||||||
|
if ($wp_categories = get_the_category($this->id)) {
|
||||||
|
foreach ($wp_categories as $wp_category) {
|
||||||
|
$category = new JSON_API_Category($wp_category);
|
||||||
|
if ($category->id == 1 && $category->slug == 'uncategorized') {
|
||||||
|
// Skip the 'uncategorized' category
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$this->categories[] = $category;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
unset($this->categories);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_tags_value() {
|
||||||
|
global $json_api;
|
||||||
|
if ($json_api->include_value('tags')) {
|
||||||
|
$this->tags = array();
|
||||||
|
if ($wp_tags = get_the_tags($this->id)) {
|
||||||
|
foreach ($wp_tags as $wp_tag) {
|
||||||
|
$this->tags[] = new JSON_API_Tag($wp_tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
unset($this->tags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_author_value($author_id) {
|
||||||
|
global $json_api;
|
||||||
|
if ($json_api->include_value('author')) {
|
||||||
|
$this->author = new JSON_API_Author($author_id);
|
||||||
|
} else {
|
||||||
|
unset($this->author);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_comments_value() {
|
||||||
|
global $json_api;
|
||||||
|
if ($json_api->include_value('comments')) {
|
||||||
|
$this->comments = $json_api->introspector->get_comments($this->id);
|
||||||
|
} else {
|
||||||
|
unset($this->comments);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_attachments_value() {
|
||||||
|
global $json_api;
|
||||||
|
if ($json_api->include_value('attachments')) {
|
||||||
|
$this->attachments = $json_api->introspector->get_attachments($this->id);
|
||||||
|
} else {
|
||||||
|
unset($this->attachments);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_thumbnail_value() {
|
||||||
|
global $json_api;
|
||||||
|
if (!$json_api->include_value('thumbnail') ||
|
||||||
|
!function_exists('get_post_thumbnail_id')) {
|
||||||
|
unset($this->thumbnail);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$attachment_id = get_post_thumbnail_id($this->id);
|
||||||
|
if (!$attachment_id) {
|
||||||
|
unset($this->thumbnail);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$thumbnail_size = $this->get_thumbnail_size();
|
||||||
|
list($thumbnail) = wp_get_attachment_image_src($attachment_id, $thumbnail_size);
|
||||||
|
$this->thumbnail = $thumbnail;
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_custom_fields_value() {
|
||||||
|
global $json_api;
|
||||||
|
if ($json_api->include_value('custom_fields') &&
|
||||||
|
$json_api->query->custom_fields) {
|
||||||
|
$keys = explode(',', $json_api->query->custom_fields);
|
||||||
|
$wp_custom_fields = get_post_custom($this->id);
|
||||||
|
$this->custom_fields = new stdClass();
|
||||||
|
foreach ($keys as $key) {
|
||||||
|
if (isset($wp_custom_fields[$key])) {
|
||||||
|
$this->custom_fields->$key = $wp_custom_fields[$key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
unset($this->custom_fields);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_thumbnail_size() {
|
||||||
|
global $json_api;
|
||||||
|
if ($json_api->query->thumbnail_size) {
|
||||||
|
return $json_api->query->thumbnail_size;
|
||||||
|
} else if (function_exists('get_intermediate_image_sizes')) {
|
||||||
|
$sizes = get_intermediate_image_sizes();
|
||||||
|
if (in_array('post-thumbnail', $sizes)) {
|
||||||
|
return 'post-thumbnail';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 'thumbnail';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class JSON_API_Tag {
|
||||||
|
|
||||||
|
var $id; // Integer
|
||||||
|
var $slug; // String
|
||||||
|
var $title; // String
|
||||||
|
var $description; // String
|
||||||
|
|
||||||
|
function JSON_API_Tag($wp_tag = null) {
|
||||||
|
if ($wp_tag) {
|
||||||
|
$this->import_wp_object($wp_tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function import_wp_object($wp_tag) {
|
||||||
|
$this->id = (int) $wp_tag->term_id;
|
||||||
|
$this->slug = $wp_tag->slug;
|
||||||
|
$this->title = $wp_tag->name;
|
||||||
|
$this->description = $wp_tag->description;
|
||||||
|
$this->post_count = (int) $wp_tag->count;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
+1117
File diff suppressed because it is too large.
Load diff
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
@@ -0,0 +1,371 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class JSON_API {
|
||||||
|
|
||||||
|
function __construct() {
|
||||||
|
$this->query = new JSON_API_Query();
|
||||||
|
$this->introspector = new JSON_API_Introspector();
|
||||||
|
$this->response = new JSON_API_Response();
|
||||||
|
add_action('template_redirect', array(&$this, 'template_redirect'));
|
||||||
|
add_action('admin_menu', array(&$this, 'admin_menu'));
|
||||||
|
add_action('update_option_json_api_base', array(&$this, 'flush_rewrite_rules'));
|
||||||
|
add_action('pre_update_option_json_api_controllers', array(&$this, 'update_controllers'));
|
||||||
|
}
|
||||||
|
|
||||||
|
function template_redirect() {
|
||||||
|
// Check to see if there's an appropriate API controller + method
|
||||||
|
$controller = strtolower($this->query->get_controller());
|
||||||
|
$available_controllers = $this->get_controllers();
|
||||||
|
$enabled_controllers = explode(',', get_option('json_api_controllers', 'core'));
|
||||||
|
$active_controllers = array_intersect($available_controllers, $enabled_controllers);
|
||||||
|
|
||||||
|
if ($controller) {
|
||||||
|
|
||||||
|
if (!in_array($controller, $active_controllers)) {
|
||||||
|
$this->error("Unknown controller '$controller'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$controller_path = $this->controller_path($controller);
|
||||||
|
if (file_exists($controller_path)) {
|
||||||
|
require_once $controller_path;
|
||||||
|
}
|
||||||
|
$controller_class = $this->controller_class($controller);
|
||||||
|
|
||||||
|
if (!class_exists($controller_class)) {
|
||||||
|
$this->error("Unknown controller '$controller_class'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->controller = new $controller_class();
|
||||||
|
$method = $this->query->get_method($controller);
|
||||||
|
|
||||||
|
if ($method) {
|
||||||
|
|
||||||
|
$this->response->setup();
|
||||||
|
|
||||||
|
// Run action hooks for method
|
||||||
|
do_action("json_api-{$controller}-$method");
|
||||||
|
|
||||||
|
// Error out if nothing is found
|
||||||
|
if ($method == '404') {
|
||||||
|
$this->error('Not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run the method
|
||||||
|
$result = $this->controller->$method();
|
||||||
|
|
||||||
|
// Handle the result
|
||||||
|
$this->response->respond($result);
|
||||||
|
|
||||||
|
// Done!
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function admin_menu() {
|
||||||
|
add_options_page('JSON API Settings', 'JSON API', 'manage_options', 'json-api', array(&$this, 'admin_options'));
|
||||||
|
}
|
||||||
|
|
||||||
|
function admin_options() {
|
||||||
|
if (!current_user_can('manage_options')) {
|
||||||
|
wp_die( __('You do not have sufficient permissions to access this page.') );
|
||||||
|
}
|
||||||
|
|
||||||
|
$available_controllers = $this->get_controllers();
|
||||||
|
$active_controllers = explode(',', get_option('json_api_controllers', 'core'));
|
||||||
|
|
||||||
|
if (count($active_controllers) == 1 && empty($active_controllers[0])) {
|
||||||
|
$active_controllers = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($_REQUEST['_wpnonce']) && wp_verify_nonce($_REQUEST['_wpnonce'], "update-options")) {
|
||||||
|
if ((!empty($_REQUEST['action']) || !empty($_REQUEST['action2'])) &&
|
||||||
|
(!empty($_REQUEST['controller']) || !empty($_REQUEST['controllers']))) {
|
||||||
|
if (!empty($_REQUEST['action'])) {
|
||||||
|
$action = $_REQUEST['action'];
|
||||||
|
} else {
|
||||||
|
$action = $_REQUEST['action2'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($_REQUEST['controllers'])) {
|
||||||
|
$controllers = $_REQUEST['controllers'];
|
||||||
|
} else {
|
||||||
|
$controllers = array($_REQUEST['controller']);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($controllers as $controller) {
|
||||||
|
if (in_array($controller, $available_controllers)) {
|
||||||
|
if ($action == 'activate' && !in_array($controller, $active_controllers)) {
|
||||||
|
$active_controllers[] = $controller;
|
||||||
|
} else if ($action == 'deactivate') {
|
||||||
|
$index = array_search($controller, $active_controllers);
|
||||||
|
if ($index !== false) {
|
||||||
|
unset($active_controllers[$index]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->save_option('json_api_controllers', implode(',', $active_controllers));
|
||||||
|
}
|
||||||
|
if (isset($_REQUEST['json_api_base'])) {
|
||||||
|
$this->save_option('json_api_base', $_REQUEST['json_api_base']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
<div class="wrap">
|
||||||
|
<div id="icon-options-general" class="icon32"><br /></div>
|
||||||
|
<h2>JSON API Settings</h2>
|
||||||
|
<form action="options-general.php?page=json-api" method="post">
|
||||||
|
<?php wp_nonce_field('update-options'); ?>
|
||||||
|
<h3>Controllers</h3>
|
||||||
|
<?php $this->print_controller_actions(); ?>
|
||||||
|
<table id="all-plugins-table" class="widefat">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th class="manage-column check-column" scope="col"><input type="checkbox" /></th>
|
||||||
|
<th class="manage-column" scope="col">Controller</th>
|
||||||
|
<th class="manage-column" scope="col">Description</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<th class="manage-column check-column" scope="col"><input type="checkbox" /></th>
|
||||||
|
<th class="manage-column" scope="col">Controller</th>
|
||||||
|
<th class="manage-column" scope="col">Description</th>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
<tbody class="plugins">
|
||||||
|
<?php
|
||||||
|
|
||||||
|
foreach ($available_controllers as $controller) {
|
||||||
|
|
||||||
|
$error = false;
|
||||||
|
$active = in_array($controller, $active_controllers);
|
||||||
|
$info = $this->controller_info($controller);
|
||||||
|
|
||||||
|
if (is_string($info)) {
|
||||||
|
$active = false;
|
||||||
|
$error = true;
|
||||||
|
$info = array(
|
||||||
|
'name' => $controller,
|
||||||
|
'description' => "<p><strong>Error</strong>: $info</p>",
|
||||||
|
'methods' => array(),
|
||||||
|
'url' => null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
<tr class="<?php echo ($active ? 'active' : 'inactive'); ?>">
|
||||||
|
<th class="check-column" scope="row">
|
||||||
|
<input type="checkbox" name="controllers[]" value="<?php echo $controller; ?>" />
|
||||||
|
</th>
|
||||||
|
<td class="plugin-title">
|
||||||
|
<strong><?php echo $info['name']; ?></strong>
|
||||||
|
<div class="row-actions-visible">
|
||||||
|
<?php
|
||||||
|
|
||||||
|
if ($active) {
|
||||||
|
echo '<a href="' . wp_nonce_url('options-general.php?page=json-api&action=deactivate&controller=' . $controller, 'update-options') . '" title="' . __('Deactivate this controller') . '" class="edit">' . __('Deactivate') . '</a>';
|
||||||
|
} else if (!$error) {
|
||||||
|
echo '<a href="' . wp_nonce_url('options-general.php?page=json-api&action=activate&controller=' . $controller, 'update-options') . '" title="' . __('Activate this controller') . '" class="edit">' . __('Activate') . '</a>';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($info['url']) {
|
||||||
|
echo ' | ';
|
||||||
|
echo '<a href="' . $info['url'] . '" target="_blank">Docs</a></div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
</td>
|
||||||
|
<td class="desc">
|
||||||
|
<p><?php echo $info['description']; ?></p>
|
||||||
|
<p>
|
||||||
|
<?php
|
||||||
|
|
||||||
|
foreach($info['methods'] as $method) {
|
||||||
|
$url = $this->get_method_url($controller, $method, array('dev' => 1));
|
||||||
|
if ($active) {
|
||||||
|
echo "<code><a href=\"$url\">$method</a></code> ";
|
||||||
|
} else {
|
||||||
|
echo "<code>$method</code> ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php } ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<?php $this->print_controller_actions('action2'); ?>
|
||||||
|
<h3>Address</h3>
|
||||||
|
<p>Specify a base URL for JSON API. For example, using <code>api</code> as your API base URL would enable the following <code><?php bloginfo('url'); ?>/api/get_recent_posts/</code>. If you assign a blank value the API will only be available by setting a <code>json</code> query variable.</p>
|
||||||
|
<table class="form-table">
|
||||||
|
<tr valign="top">
|
||||||
|
<th scope="row">API base</th>
|
||||||
|
<td><code><?php bloginfo('url'); ?>/</code><input type="text" name="json_api_base" value="<?php echo get_option('json_api_base', 'api'); ?>" size="15" /></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<?php if (!get_option('permalink_structure', '')) { ?>
|
||||||
|
<br />
|
||||||
|
<p><strong>Note:</strong> User-friendly permalinks are not currently enabled. <a target="_blank" class="button" href="options-permalink.php">Change Permalinks</a>
|
||||||
|
<?php } ?>
|
||||||
|
<p class="submit">
|
||||||
|
<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
|
||||||
|
</p>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
function print_controller_actions($name = 'action') {
|
||||||
|
?>
|
||||||
|
<div class="tablenav">
|
||||||
|
<div class="alignleft actions">
|
||||||
|
<select name="<?php echo $name; ?>">
|
||||||
|
<option selected="selected" value="-1">Bulk Actions</option>
|
||||||
|
<option value="activate">Activate</option>
|
||||||
|
<option value="deactivate">Deactivate</option>
|
||||||
|
</select>
|
||||||
|
<input type="submit" class="button-secondary action" id="doaction" name="doaction" value="Apply">
|
||||||
|
</div>
|
||||||
|
<div class="clear"></div>
|
||||||
|
</div>
|
||||||
|
<div class="clear"></div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_method_url($controller, $method, $options = '') {
|
||||||
|
$url = get_bloginfo('url');
|
||||||
|
$base = get_option('json_api_base', 'api');
|
||||||
|
$permalink_structure = get_option('permalink_structure', '');
|
||||||
|
if (!empty($options) && is_array($options)) {
|
||||||
|
$args = array();
|
||||||
|
foreach ($options as $key => $value) {
|
||||||
|
$args[] = urlencode($key) . '=' . urlencode($value);
|
||||||
|
}
|
||||||
|
$args = implode('&', $args);
|
||||||
|
} else {
|
||||||
|
$args = $options;
|
||||||
|
}
|
||||||
|
if ($controller != 'core') {
|
||||||
|
$method = "$controller/$method";
|
||||||
|
}
|
||||||
|
if (!empty($base) && !empty($permalink_structure)) {
|
||||||
|
if (!empty($args)) {
|
||||||
|
$args = "?$args";
|
||||||
|
}
|
||||||
|
return "$url/$base/$method/$args";
|
||||||
|
} else {
|
||||||
|
return "$url?json=$method&$args";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function save_option($id, $value) {
|
||||||
|
$option_exists = (get_option($id, null) !== null);
|
||||||
|
if ($option_exists) {
|
||||||
|
update_option($id, $value);
|
||||||
|
} else {
|
||||||
|
add_option($id, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_controllers() {
|
||||||
|
$controllers = array();
|
||||||
|
$dir = json_api_dir();
|
||||||
|
$dh = opendir("$dir/controllers");
|
||||||
|
while ($file = readdir($dh)) {
|
||||||
|
if (preg_match('/(.+)\.php$/', $file, $matches)) {
|
||||||
|
$controllers[] = $matches[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$controllers = apply_filters('json_api_controllers', $controllers);
|
||||||
|
return array_map('strtolower', $controllers);
|
||||||
|
}
|
||||||
|
|
||||||
|
function controller_is_active($controller) {
|
||||||
|
if (defined('JSON_API_CONTROLLERS')) {
|
||||||
|
$default = JSON_API_CONTROLLERS;
|
||||||
|
} else {
|
||||||
|
$default = 'core';
|
||||||
|
}
|
||||||
|
$active_controllers = explode(',', get_option('json_api_controllers', $default));
|
||||||
|
return (in_array($controller, $active_controllers));
|
||||||
|
}
|
||||||
|
|
||||||
|
function update_controllers($controllers) {
|
||||||
|
if (is_array($controllers)) {
|
||||||
|
return implode(',', $controllers);
|
||||||
|
} else {
|
||||||
|
return $controllers;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function controller_info($controller) {
|
||||||
|
$path = $this->controller_path($controller);
|
||||||
|
$class = $this->controller_class($controller);
|
||||||
|
$response = array(
|
||||||
|
'name' => $controller,
|
||||||
|
'description' => '(No description available)',
|
||||||
|
'methods' => array()
|
||||||
|
);
|
||||||
|
if (file_exists($path)) {
|
||||||
|
$source = file_get_contents($path);
|
||||||
|
if (preg_match('/^\s*Controller name:(.+)$/im', $source, $matches)) {
|
||||||
|
$response['name'] = trim($matches[1]);
|
||||||
|
}
|
||||||
|
if (preg_match('/^\s*Controller description:(.+)$/im', $source, $matches)) {
|
||||||
|
$response['description'] = trim($matches[1]);
|
||||||
|
}
|
||||||
|
if (preg_match('/^\s*Controller URI:(.+)$/im', $source, $matches)) {
|
||||||
|
$response['docs'] = trim($matches[1]);
|
||||||
|
}
|
||||||
|
if (!class_exists($class)) {
|
||||||
|
require_once($path);
|
||||||
|
}
|
||||||
|
$response['methods'] = get_class_methods($class);
|
||||||
|
return $response;
|
||||||
|
} else if (is_admin()) {
|
||||||
|
return "Cannot find controller class '$class' (filtered path: $path).";
|
||||||
|
} else {
|
||||||
|
$this->error("Unknown controller '$controller'.");
|
||||||
|
}
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
function controller_class($controller) {
|
||||||
|
return "json_api_{$controller}_controller";
|
||||||
|
}
|
||||||
|
|
||||||
|
function controller_path($controller) {
|
||||||
|
$dir = json_api_dir();
|
||||||
|
$controller_class = $this->controller_class($controller);
|
||||||
|
return apply_filters("{$controller_class}_path", "$dir/controllers/$controller.php");
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_nonce_id($controller, $method) {
|
||||||
|
$controller = strtolower($controller);
|
||||||
|
$method = strtolower($method);
|
||||||
|
return "json_api-$controller-$method";
|
||||||
|
}
|
||||||
|
|
||||||
|
function flush_rewrite_rules() {
|
||||||
|
global $wp_rewrite;
|
||||||
|
$wp_rewrite->flush_rules();
|
||||||
|
}
|
||||||
|
|
||||||
|
function error($message = 'Unknown error', $status = 'error') {
|
||||||
|
$this->response->respond(array(
|
||||||
|
'error' => $message
|
||||||
|
), $status);
|
||||||
|
}
|
||||||
|
|
||||||
|
function include_value($key) {
|
||||||
|
return $this->response->is_value_included($key);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,299 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class JSON_API_Introspector {
|
||||||
|
|
||||||
|
public function get_posts($query = false, $wp_posts = false) {
|
||||||
|
global $post;
|
||||||
|
$this->set_posts_query($query);
|
||||||
|
$output = array();
|
||||||
|
while (have_posts()) {
|
||||||
|
the_post();
|
||||||
|
if ($wp_posts) {
|
||||||
|
$output[] = $post;
|
||||||
|
} else {
|
||||||
|
$output[] = new JSON_API_Post($post);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_date_archive_permalinks() {
|
||||||
|
$archives = wp_get_archives('echo=0');
|
||||||
|
preg_match_all("/href='([^']+)'/", $archives, $matches);
|
||||||
|
return $matches[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_date_archive_tree($permalinks) {
|
||||||
|
$tree = array();
|
||||||
|
foreach ($permalinks as $url) {
|
||||||
|
if (preg_match('#(\d{4})/(\d{2})#', $url, $date)) {
|
||||||
|
$year = $date[1];
|
||||||
|
$month = $date[2];
|
||||||
|
} else if (preg_match('/(\d{4})(\d{2})/', $url, $date)) {
|
||||||
|
$year = $date[1];
|
||||||
|
$month = $date[2];
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$count = $this->get_date_archive_count($year, $month);
|
||||||
|
if (empty($tree[$year])) {
|
||||||
|
$tree[$year] = array(
|
||||||
|
$month => $count
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$tree[$year][$month] = $count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $tree;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_date_archive_count($year, $month) {
|
||||||
|
if (!isset($this->month_archives)) {
|
||||||
|
global $wpdb;
|
||||||
|
$post_counts = $wpdb->get_results("
|
||||||
|
SELECT DATE_FORMAT(post_date, '%Y%m') AS month,
|
||||||
|
COUNT(ID) AS post_count
|
||||||
|
FROM $wpdb->posts
|
||||||
|
WHERE post_status = 'publish'
|
||||||
|
AND post_type = 'post'
|
||||||
|
GROUP BY month
|
||||||
|
");
|
||||||
|
$this->month_archives = array();
|
||||||
|
foreach ($post_counts as $post_count) {
|
||||||
|
$this->month_archives[$post_count->month] = $post_count->post_count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this->month_archives["$year$month"];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_categories() {
|
||||||
|
$wp_categories = get_categories();
|
||||||
|
$categories = array();
|
||||||
|
foreach ($wp_categories as $wp_category) {
|
||||||
|
if ($wp_category->term_id == 1 && $wp_category->slug == 'uncategorized') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$categories[] = $this->get_category_object($wp_category);
|
||||||
|
}
|
||||||
|
return $categories;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_current_category() {
|
||||||
|
global $json_api;
|
||||||
|
extract($json_api->query->get(array('id', 'slug', 'category_id', 'category_slug')));
|
||||||
|
if ($id || $category_id) {
|
||||||
|
if (!$id) {
|
||||||
|
$id = $category_id;
|
||||||
|
}
|
||||||
|
return $this->get_category_by_id($id);
|
||||||
|
} else if ($slug || $category_slug) {
|
||||||
|
if (!$slug) {
|
||||||
|
$slug = $category_slug;
|
||||||
|
}
|
||||||
|
return $this->get_category_by_slug($slug);
|
||||||
|
} else {
|
||||||
|
$json_api->error("Include 'id' or 'slug' var in your request.");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_category_by_id($category_id) {
|
||||||
|
$wp_category = get_term_by('id', $category_id, 'category');
|
||||||
|
return $this->get_category_object($wp_category);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_category_by_slug($category_slug) {
|
||||||
|
$wp_category = get_term_by('slug', $category_slug, 'category');
|
||||||
|
return $this->get_category_object($wp_category);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_tags() {
|
||||||
|
$wp_tags = get_tags();
|
||||||
|
return array_map(array(&$this, 'get_tag_object'), $wp_tags);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_current_tag() {
|
||||||
|
global $json_api;
|
||||||
|
extract($json_api->query->get(array('id', 'slug', 'tag_id', 'tag_slug')));
|
||||||
|
if ($id || $tag_id) {
|
||||||
|
if (!$id) {
|
||||||
|
$id = $tag_id;
|
||||||
|
}
|
||||||
|
return $this->get_tag_by_id($id);
|
||||||
|
} else if ($slug || $tag_slug) {
|
||||||
|
if (!$slug) {
|
||||||
|
$slug = $tag_slug;
|
||||||
|
}
|
||||||
|
return $this->get_tag_by_slug($slug);
|
||||||
|
} else {
|
||||||
|
$json_api->error("Include 'id' or 'slug' var in your request.");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_tag_by_id($tag_id) {
|
||||||
|
$wp_tag = get_term_by('id', $tag_id, 'post_tag');
|
||||||
|
return $this->get_tag_object($wp_tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_tag_by_slug($tag_slug) {
|
||||||
|
$wp_tag = get_term_by('slug', $tag_slug, 'post_tag');
|
||||||
|
return $this->get_tag_object($wp_tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_authors() {
|
||||||
|
global $wpdb;
|
||||||
|
$author_ids = $wpdb->get_col($wpdb->prepare("
|
||||||
|
SELECT u.ID, m.meta_value AS last_name
|
||||||
|
FROM $wpdb->users AS u,
|
||||||
|
$wpdb->usermeta AS m
|
||||||
|
WHERE m.user_id = u.ID
|
||||||
|
AND m.meta_key = 'last_name'
|
||||||
|
ORDER BY last_name
|
||||||
|
"));
|
||||||
|
$all_authors = array_map(array(&$this, 'get_author_by_id'), $author_ids);
|
||||||
|
$active_authors = array_filter($all_authors, array(&$this, 'is_active_author'));
|
||||||
|
return $active_authors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_current_author() {
|
||||||
|
global $json_api;
|
||||||
|
extract($json_api->query->get(array('id', 'slug', 'author_id', 'author_slug')));
|
||||||
|
if ($id || $author_id) {
|
||||||
|
if (!$id) {
|
||||||
|
$id = $author_id;
|
||||||
|
}
|
||||||
|
return $this->get_author_by_id($id);
|
||||||
|
} else if ($slug || $author_slug) {
|
||||||
|
if (!$slug) {
|
||||||
|
$slug = $author_slug;
|
||||||
|
}
|
||||||
|
return $this->get_author_by_login($slug);
|
||||||
|
} else {
|
||||||
|
$json_api->error("Include 'id' or 'slug' var in your request.");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_author_by_id($id) {
|
||||||
|
$id = get_the_author_meta('ID', $id);
|
||||||
|
if (!$id) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new JSON_API_Author($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_author_by_login($login) {
|
||||||
|
global $wpdb;
|
||||||
|
$id = $wpdb->get_var($wpdb->prepare("
|
||||||
|
SELECT ID
|
||||||
|
FROM $wpdb->users
|
||||||
|
WHERE user_nicename = %s
|
||||||
|
", $login));
|
||||||
|
return $this->get_author_by_id($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_comments($post_id) {
|
||||||
|
global $wpdb;
|
||||||
|
$wp_comments = $wpdb->get_results($wpdb->prepare("
|
||||||
|
SELECT *
|
||||||
|
FROM $wpdb->comments
|
||||||
|
WHERE comment_post_ID = %d
|
||||||
|
AND comment_approved = 1
|
||||||
|
AND comment_type = ''
|
||||||
|
ORDER BY comment_date
|
||||||
|
", $post_id));
|
||||||
|
$comments = array();
|
||||||
|
foreach ($wp_comments as $wp_comment) {
|
||||||
|
$comments[] = new JSON_API_Comment($wp_comment);
|
||||||
|
}
|
||||||
|
return $comments;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_attachments($post_id) {
|
||||||
|
$wp_attachments = get_children(array(
|
||||||
|
'post_type' => 'attachment',
|
||||||
|
'post_parent' => $post_id,
|
||||||
|
'orderby' => 'menu_order',
|
||||||
|
'order' => 'ASC'
|
||||||
|
));
|
||||||
|
$attachments = array();
|
||||||
|
if (!empty($wp_attachments)) {
|
||||||
|
foreach ($wp_attachments as $wp_attachment) {
|
||||||
|
$attachments[] = new JSON_API_Attachment($wp_attachment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $attachments;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function attach_child_posts(&$post) {
|
||||||
|
$post->children = array();
|
||||||
|
$wp_children = get_posts(array(
|
||||||
|
'post_type' => $post->type,
|
||||||
|
'post_parent' => $post->id,
|
||||||
|
'order' => 'ASC',
|
||||||
|
'orderby' => 'menu_order'
|
||||||
|
));
|
||||||
|
foreach ($wp_children as $wp_post) {
|
||||||
|
$post->children[] = new JSON_API_Post($wp_post);
|
||||||
|
}
|
||||||
|
foreach ($post->children as $child) {
|
||||||
|
$this->attach_child_posts($child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function get_category_object($wp_category) {
|
||||||
|
if (!$wp_category) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new JSON_API_Category($wp_category);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function get_tag_object($wp_tag) {
|
||||||
|
if (!$wp_tag) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new JSON_API_Tag($wp_tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function is_active_author($author) {
|
||||||
|
if (!isset($this->active_authors)) {
|
||||||
|
$this->active_authors = explode(',', wp_list_authors(array(
|
||||||
|
'html' => false,
|
||||||
|
'echo' => false,
|
||||||
|
'exclude_admin' => false
|
||||||
|
)));
|
||||||
|
$this->active_authors = array_map('trim', $this->active_authors);
|
||||||
|
}
|
||||||
|
return in_array($author->name, $this->active_authors);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function set_posts_query($query = false) {
|
||||||
|
global $json_api, $wp_query;
|
||||||
|
|
||||||
|
if (!$query) {
|
||||||
|
$query = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = array_merge($query, $wp_query->query);
|
||||||
|
|
||||||
|
if ($json_api->query->page) {
|
||||||
|
$query['paged'] = $json_api->query->page;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($json_api->query->count) {
|
||||||
|
$query['posts_per_page'] = $json_api->query->count;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($json_api->query->post_type) {
|
||||||
|
$query['post_type'] = $json_api->query->post_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($query)) {
|
||||||
|
query_posts($query);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,194 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class JSON_API_Query {
|
||||||
|
|
||||||
|
// Default values
|
||||||
|
protected $defaults = array(
|
||||||
|
'date_format' => 'Y-m-d H:i:s',
|
||||||
|
'read_more' => 'Read more'
|
||||||
|
);
|
||||||
|
|
||||||
|
function __construct() {
|
||||||
|
// Register JSON API query vars
|
||||||
|
add_filter('query_vars', array(&$this, 'query_vars'));
|
||||||
|
}
|
||||||
|
|
||||||
|
function get($key) {
|
||||||
|
if (is_array($key)) {
|
||||||
|
$result = array();
|
||||||
|
foreach ($key as $k) {
|
||||||
|
$result[$k] = $this->get($k);
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
$query_var = (isset($_REQUEST[$key])) ? $_REQUEST[$key] : null;
|
||||||
|
$wp_query_var = $this->wp_query_var($key);
|
||||||
|
if ($wp_query_var) {
|
||||||
|
return $wp_query_var;
|
||||||
|
} else if ($query_var) {
|
||||||
|
return $this->strip_magic_quotes($query_var);
|
||||||
|
} else if (isset($this->defaults[$key])) {
|
||||||
|
return $this->defaults[$key];
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function __get($key) {
|
||||||
|
return $this->get($key);
|
||||||
|
}
|
||||||
|
|
||||||
|
function __isset($key) {
|
||||||
|
return ($this->get($key) !== null);
|
||||||
|
}
|
||||||
|
|
||||||
|
function wp_query_var($key) {
|
||||||
|
$wp_translation = array(
|
||||||
|
'json' => 'json',
|
||||||
|
'post_id' => 'p',
|
||||||
|
'post_slug' => 'name',
|
||||||
|
'page_id' => 'page_id',
|
||||||
|
'page_slug' => 'name',
|
||||||
|
'category_id' => 'cat',
|
||||||
|
'category_slug' => 'category_name',
|
||||||
|
'tag_id' => 'tag_id',
|
||||||
|
'tag_slug' => 'tag',
|
||||||
|
'author_id' => 'author',
|
||||||
|
'author_slug' => 'author_name',
|
||||||
|
'search' => 's',
|
||||||
|
'order' => 'order',
|
||||||
|
'order_by' => 'orderby'
|
||||||
|
);
|
||||||
|
if ($key == 'date') {
|
||||||
|
$date = null;
|
||||||
|
if (get_query_var('year')) {
|
||||||
|
$date = get_query_var('year');
|
||||||
|
}
|
||||||
|
if (get_query_var('monthnum')) {
|
||||||
|
$month = get_query_var('monthnum');
|
||||||
|
if ($month < 10) {
|
||||||
|
$month = "0$month";
|
||||||
|
}
|
||||||
|
$date .= $month;
|
||||||
|
}
|
||||||
|
if (get_query_var('day')) {
|
||||||
|
$day = get_query_var('day');
|
||||||
|
if ($day < 10) {
|
||||||
|
$day = "0$day";
|
||||||
|
}
|
||||||
|
$date .= $day;
|
||||||
|
}
|
||||||
|
return $date;
|
||||||
|
} else if (isset($wp_translation[$key])) {
|
||||||
|
return get_query_var($wp_translation[$key]);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function strip_magic_quotes($value) {
|
||||||
|
if (get_magic_quotes_gpc()) {
|
||||||
|
return stripslashes($value);
|
||||||
|
} else {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function query_vars($wp_vars) {
|
||||||
|
$wp_vars[] = 'json';
|
||||||
|
return $wp_vars;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_controller() {
|
||||||
|
$json = $this->get('json');
|
||||||
|
if (empty($json)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (preg_match('/^[a-zA-Z_]+$/', $json)) {
|
||||||
|
return $this->get_legacy_controller($json);
|
||||||
|
} else if (preg_match('/^([a-zA-Z_]+)(\/|\.)[a-zA-Z_]+$/', $json, $matches)) {
|
||||||
|
return $matches[1];
|
||||||
|
} else {
|
||||||
|
return 'core';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_legacy_controller($json) {
|
||||||
|
global $json_api;
|
||||||
|
if ($json == 'submit_comment') {
|
||||||
|
if ($json_api->controller_is_active('respond')) {
|
||||||
|
return 'respond';
|
||||||
|
} else {
|
||||||
|
$json_api->error("The 'submit_comment' method has been removed from the Core controller. To use this method you must enable the Respond controller from WP Admin > Settings > JSON API.");
|
||||||
|
}
|
||||||
|
} else if ($json == 'create_post') {
|
||||||
|
if ($json_api->controller_is_active('posts')) {
|
||||||
|
return 'posts';
|
||||||
|
} else {
|
||||||
|
$json_api->error("The 'create_post' method has been removed from the Core controller. To use this method you must enable the Posts controller from WP Admin > Settings > JSON API.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return 'core';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_method($controller) {
|
||||||
|
|
||||||
|
global $json_api;
|
||||||
|
|
||||||
|
// Returns an appropriate API method name or false. Four possible outcomes:
|
||||||
|
// 1. API isn't being invoked at all (return false)
|
||||||
|
// 2. A specific API method was requested (return method name)
|
||||||
|
// 3. A method is chosen implicitly on a given WordPress page
|
||||||
|
// 4. API invoked incorrectly (return "error" method)
|
||||||
|
//
|
||||||
|
// Note:
|
||||||
|
// The implicit outcome (3) is invoked by setting the json query var to a
|
||||||
|
// non-empty value on any WordPress page:
|
||||||
|
// * http://example.org/2009/11/10/hello-world/?json=1 (get_post)
|
||||||
|
// * http://example.org/2009/11/?json=1 (get_date_posts)
|
||||||
|
// * http://example.org/category/foo?json=1 (get_category_posts)
|
||||||
|
|
||||||
|
$method = $this->get('json');
|
||||||
|
if (strpos($method, '/') !== false) {
|
||||||
|
$method = substr($method, strpos($method, '/') + 1);
|
||||||
|
} else if (strpos($method, '.') !== false) {
|
||||||
|
$method = substr($method, strpos($method, '.') + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($method)) {
|
||||||
|
// Case 1: we're not being invoked (done!)
|
||||||
|
return false;
|
||||||
|
} else if (method_exists("JSON_API_{$controller}_Controller", $method)) {
|
||||||
|
// Case 2: an explicit method was specified
|
||||||
|
return $method;
|
||||||
|
} else if ($controller == 'core') {
|
||||||
|
// Case 3: choose the method implicitly based on which page we're on...
|
||||||
|
if (is_search()) {
|
||||||
|
return 'get_search_results';
|
||||||
|
} else if (is_home()) {
|
||||||
|
if (empty($_GET['json'])) {
|
||||||
|
$json_api->error("Uknown method '$method'.");
|
||||||
|
}
|
||||||
|
return 'get_recent_posts';
|
||||||
|
} else if (is_page()) {
|
||||||
|
return 'get_page';
|
||||||
|
} else if (is_single()) {
|
||||||
|
return 'get_post';
|
||||||
|
} else if (is_category()) {
|
||||||
|
return 'get_category_posts';
|
||||||
|
} else if (is_tag()) {
|
||||||
|
return 'get_tag_posts';
|
||||||
|
} else if (is_author()) {
|
||||||
|
return 'get_author_posts';
|
||||||
|
} else if (is_date()) {
|
||||||
|
return 'get_date_posts';
|
||||||
|
} else if (is_404()) {
|
||||||
|
return '404';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Case 4: either the method doesn't exist or we don't support the page implicitly
|
||||||
|
return 'error';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,184 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class JSON_API_Response {
|
||||||
|
|
||||||
|
function setup() {
|
||||||
|
global $json_api;
|
||||||
|
$this->include_values = array();
|
||||||
|
$this->exclude_values = array();
|
||||||
|
if ($json_api->query->include) {
|
||||||
|
$this->include_values = explode(',', $json_api->query->include);
|
||||||
|
}
|
||||||
|
// Props to ikesyo for submitting a fix!
|
||||||
|
if ($json_api->query->exclude) {
|
||||||
|
$this->exclude_values = explode(',', $json_api->query->exclude);
|
||||||
|
$this->include_values = array_diff($this->include_values, $this->exclude_values);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compatibility with Disqus plugin
|
||||||
|
remove_action('loop_end', 'dsq_loop_end');
|
||||||
|
}
|
||||||
|
|
||||||
|
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 is_value_included($key) {
|
||||||
|
// Props to ikesyo for submitting a fix!
|
||||||
|
if (empty($this->include_values) && empty($this->exclude_values)) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
if (empty($this->exclude_values)) {
|
||||||
|
return in_array($key, $this->include_values);
|
||||||
|
} else {
|
||||||
|
return !in_array($key, $this->exclude_values);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function respond($result, $status = 'ok') {
|
||||||
|
global $json_api;
|
||||||
|
$json = $this->get_json($result, $status);
|
||||||
|
$status_redirect = "redirect_$status";
|
||||||
|
if ($json_api->query->dev || !empty($_REQUEST['dev'])) {
|
||||||
|
// Output the result in a human-redable format
|
||||||
|
if (!headers_sent()) {
|
||||||
|
header('HTTP/1.1 200 OK');
|
||||||
|
header('Content-Type: text/plain; charset: UTF-8', true);
|
||||||
|
} else {
|
||||||
|
echo '<pre>';
|
||||||
|
}
|
||||||
|
echo $this->prettify($json);
|
||||||
|
} else if (!empty($_REQUEST[$status_redirect])) {
|
||||||
|
wp_redirect($_REQUEST[$status_redirect]);
|
||||||
|
} else if ($json_api->query->redirect) {
|
||||||
|
$url = $this->add_status_query_var($json_api->query->redirect, $status);
|
||||||
|
wp_redirect($url);
|
||||||
|
} else if ($json_api->query->callback) {
|
||||||
|
// Run a JSONP-style callback with the result
|
||||||
|
$this->callback($json_api->query->callback, $json);
|
||||||
|
} else {
|
||||||
|
// Output the result
|
||||||
|
$this->output($json);
|
||||||
|
}
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
function output($result) {
|
||||||
|
$charset = get_option('blog_charset');
|
||||||
|
if (!headers_sent()) {
|
||||||
|
header('HTTP/1.1 200 OK', true);
|
||||||
|
header("Content-Type: application/json; charset=$charset", true);
|
||||||
|
}
|
||||||
|
echo $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function callback($callback, $result) {
|
||||||
|
$charset = get_option('blog_charset');
|
||||||
|
if (!headers_sent()) {
|
||||||
|
header('HTTP/1.1 200 OK', true);
|
||||||
|
header("Content-Type: application/javascript; charset=$charset", true);
|
||||||
|
}
|
||||||
|
echo "$callback($result)";
|
||||||
|
}
|
||||||
|
|
||||||
|
function add_status_query_var($url, $status) {
|
||||||
|
if (strpos($url, '#')) {
|
||||||
|
// Remove the anchor hash for now
|
||||||
|
$pos = strpos($url, '#');
|
||||||
|
$anchor = substr($url, $pos);
|
||||||
|
$url = substr($url, 0, $pos);
|
||||||
|
}
|
||||||
|
if (strpos($url, '?')) {
|
||||||
|
$url .= "&status=$status";
|
||||||
|
} else {
|
||||||
|
$url .= "?status=$status";
|
||||||
|
}
|
||||||
|
if (!empty($anchor)) {
|
||||||
|
// Add the anchor hash back in
|
||||||
|
$url .= $anchor;
|
||||||
|
}
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
|
|
||||||
|
function prettify($ugly) {
|
||||||
|
$pretty = "";
|
||||||
|
$indent = "";
|
||||||
|
$last = '';
|
||||||
|
$pos = 0;
|
||||||
|
$level = 0;
|
||||||
|
$string = false;
|
||||||
|
while ($pos < strlen($ugly)) {
|
||||||
|
$char = substr($ugly, $pos++, 1);
|
||||||
|
if (!$string) {
|
||||||
|
if ($char == '{' || $char == '[') {
|
||||||
|
if ($char == '[' && substr($ugly, $pos, 1) == ']') {
|
||||||
|
$pretty .= "[]";
|
||||||
|
$pos++;
|
||||||
|
} else if ($char == '{' && substr($ugly, $pos, 1) == '}') {
|
||||||
|
$pretty .= "{}";
|
||||||
|
$pos++;
|
||||||
|
} else {
|
||||||
|
$pretty .= "$char\n";
|
||||||
|
$indent = str_repeat(' ', ++$level);
|
||||||
|
$pretty .= "$indent";
|
||||||
|
}
|
||||||
|
} else if ($char == '}' || $char == ']') {
|
||||||
|
$indent = str_repeat(' ', --$level);
|
||||||
|
if ($last != '}' && $last != ']') {
|
||||||
|
$pretty .= "\n$indent";
|
||||||
|
} else if (substr($pretty, -2, 2) == ' ') {
|
||||||
|
$pretty = substr($pretty, 0, -2);
|
||||||
|
}
|
||||||
|
$pretty .= $char;
|
||||||
|
if (substr($ugly, $pos, 1) == ',') {
|
||||||
|
$pretty .= ",";
|
||||||
|
$last = ',';
|
||||||
|
$pos++;
|
||||||
|
}
|
||||||
|
$pretty .= "\n$indent";
|
||||||
|
} else if ($char == ':') {
|
||||||
|
$pretty .= ": ";
|
||||||
|
} else if ($char == ',') {
|
||||||
|
$pretty .= ",\n$indent";
|
||||||
|
} else if ($char == '"') {
|
||||||
|
$pretty .= '"';
|
||||||
|
$string = true;
|
||||||
|
} else {
|
||||||
|
$pretty .= $char;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($last != '\\' && $char == '"') {
|
||||||
|
$string = false;
|
||||||
|
}
|
||||||
|
$pretty .= $char;
|
||||||
|
}
|
||||||
|
$last = $char;
|
||||||
|
}
|
||||||
|
return $pretty;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
--TEST--
|
||||||
|
core.get_author_index
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTTP/Client.php';
|
||||||
|
$http = new HTTP_Client();
|
||||||
|
$http->get('http://wordpress.test/?json=core.get_author_index');
|
||||||
|
$response = $http->currentResponse();
|
||||||
|
echo $response['body'];
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
{"status":"ok","count":2,"authors":[{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},{"id":4,"slug":"ian-stewart","name":"Ian Stewart","first_name":"","last_name":"","nickname":"Ian Stewart","url":"","description":""}]}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
--TEST--
|
||||||
|
core.get_author_posts by slug
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTTP/Client.php';
|
||||||
|
$http = new HTTP_Client();
|
||||||
|
$http->get('http://wordpress.test/?json=core.get_author_posts&slug=chip-bennett');
|
||||||
|
$response = $http->currentResponse();
|
||||||
|
echo $response['body'];
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
{"status":"ok","count":10,"pages":3,"author":{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},"posts":[{"id":358,"type":"post","slug":"readability-test","url":"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/","status":"publish","title":"Readability Test","title_plain":"Readability Test","content":"<p>All children, except one, grow up. They soon know that they will grow up, and the way Wendy knew was this. One day when she was two years old she was playing in a garden, and she plucked another flower and ran with it to her mother. I suppose she must have looked rather delightful, for Mrs. Darling put her hand to her heart and cried, “Oh, why can’t you remain like this for ever!” This was all that passed between them on the subject, but henceforth Wendy knew that she must grow up. You always know after you are two. Two is the beginning of the end.<\/p>\n<p> <a href=\"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/#more-358\" class=\"more-link\">Read more<\/a><\/p>\n","excerpt":"All children, except one, grow up. They soon know that they will grow up, and the way Wendy knew was this. One day when she was two years old she was playing in a garden, and she plucked another flower … <a href=\"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/\">Continue reading <span class=\"meta-nav\">→<\/span><\/a>","date":"2008-09-05 00:27:25","modified":"2008-09-05 00:27:25","categories":[{"id":9,"slug":"cat-a","title":"Cat A","description":"","parent":0,"post_count":2}],"tags":[{"id":53,"slug":"chattels","title":"chattels","description":"","post_count":2},{"id":82,"slug":"privation","title":"privation","description":"","post_count":2}],"author":{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},"comments":[],"attachments":[],"comment_count":0,"comment_status":"closed"},{"id":188,"type":"post","slug":"layout-test","url":"http:\/\/wordpress.test\/2008\/09\/04\/layout-test\/","status":"publish","title":"Layout Test","title_plain":"Layout Test","content":"<p>This is a sticky post!!! Make sure it sticks!<\/p>\n<p>This should then split into other pages with layout, images, HTML tags, and other things.<\/p>\n","excerpt":"This is a sticky post!!! Make sure it sticks! This should then split into other pages with layout, images, HTML tags, and other things.","date":"2008-09-04 23:02:20","modified":"2008-09-04 23:02:20","categories":[{"id":3,"slug":"aciform","title":"aciform","description":"","parent":0,"post_count":2},{"id":9,"slug":"cat-a","title":"Cat A","description":"","parent":0,"post_count":2},{"id":10,"slug":"cat-b","title":"Cat B","description":"","parent":0,"post_count":1},{"id":11,"slug":"cat-c","title":"Cat C","description":"","parent":0,"post_count":1},{"id":41,"slug":"sub","title":"sub","description":"","parent":3,"post_count":1}],"tags":[{"id":93,"slug":"tag1","title":"tag1","description":"","post_count":1},{"id":94,"slug":"tag2","title":"tag2","description":"","post_count":1},{"id":95,"slug":"tag3","title":"tag3","description":"","post_count":1}],"author":{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},"comments":[],"attachments":[],"comment_count":0,"comment_status":"closed"},{"id":128,"type":"post","slug":"images-test","url":"http:\/\/wordpress.test\/2008\/09\/03\/images-test\/","status":"publish","title":"Images Test","title_plain":"Images Test","content":"<h2>Image Alignment Tests: Un-Captioned Images<\/h2>\n<h3 id=\"center-align-no-caption\">Center-align, no caption<\/h3>\n<p>Center-aligned image with no caption, and text before and after. <img src=\"http:\/\/wordpress.test\/wp-content\/uploads\/2010\/08\/test-image-landscape1.jpg\" alt=\"\" title=\"test-image-landscape\" width=\"300\" height=\"199\" class=\"aligncenter size-full wp-image-535\" \/> ALorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed odio nibh, tincidunt adipiscing, pretium nec, tincidunt id, enim. Fusce scelerisque nunc vitae nisl. Quisque quis urna in velit dictum pellentesque. Vivamus a quam. Curabitur eu tortor id turpis tristique adipiscing. Morbi blandit. Maecenas vel est. Nunc aliquam, orci at accumsan commodo, libero nibh euismod augue, a ullamcorper velit dui et purus. Aenean volutpat, ipsum ac imperdiet fermentum, dui dui suscipit arcu, vitae dictum purus diam ac ligula.<\/p>\n<h3 id=\"left-align-no-caption\">Left-align, no caption<\/h3>\n<p>Left-aligned image with no caption, and text before and after. <img src=\"http:\/\/wordpress.test\/wp-content\/uploads\/2010\/08\/test-image-landscape1.jpg\" alt=\"\" title=\"test-image-landscape\" width=\"300\" height=\"199\" class=\"alignleft size-full wp-image-535\" \/> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed odio nibh, tincidunt adipiscing, pretium nec, tLine truncated
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
--TEST--
|
||||||
|
core.get_author_posts by author_slug
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTTP/Client.php';
|
||||||
|
$http = new HTTP_Client();
|
||||||
|
$http->get('http://wordpress.test/?json=core.get_author_posts&author_slug=chip-bennett');
|
||||||
|
$response = $http->currentResponse();
|
||||||
|
echo $response['body'];
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
{"status":"ok","count":10,"pages":3,"author":{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},"posts":[{"id":358,"type":"post","slug":"readability-test","url":"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/","status":"publish","title":"Readability Test","title_plain":"Readability Test","content":"<p>All children, except one, grow up. They soon know that they will grow up, and the way Wendy knew was this. One day when she was two years old she was playing in a garden, and she plucked another flower and ran with it to her mother. I suppose she must have looked rather delightful, for Mrs. Darling put her hand to her heart and cried, “Oh, why can’t you remain like this for ever!” This was all that passed between them on the subject, but henceforth Wendy knew that she must grow up. You always know after you are two. Two is the beginning of the end.<\/p>\n<p> <a href=\"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/#more-358\" class=\"more-link\">Read more<\/a><\/p>\n","excerpt":"All children, except one, grow up. They soon know that they will grow up, and the way Wendy knew was this. One day when she was two years old she was playing in a garden, and she plucked another flower … <a href=\"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/\">Continue reading <span class=\"meta-nav\">→<\/span><\/a>","date":"2008-09-05 00:27:25","modified":"2008-09-05 00:27:25","categories":[{"id":9,"slug":"cat-a","title":"Cat A","description":"","parent":0,"post_count":2}],"tags":[{"id":53,"slug":"chattels","title":"chattels","description":"","post_count":2},{"id":82,"slug":"privation","title":"privation","description":"","post_count":2}],"author":{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},"comments":[],"attachments":[],"comment_count":0,"comment_status":"closed"},{"id":188,"type":"post","slug":"layout-test","url":"http:\/\/wordpress.test\/2008\/09\/04\/layout-test\/","status":"publish","title":"Layout Test","title_plain":"Layout Test","content":"<p>This is a sticky post!!! Make sure it sticks!<\/p>\n<p>This should then split into other pages with layout, images, HTML tags, and other things.<\/p>\n","excerpt":"This is a sticky post!!! Make sure it sticks! This should then split into other pages with layout, images, HTML tags, and other things.","date":"2008-09-04 23:02:20","modified":"2008-09-04 23:02:20","categories":[{"id":3,"slug":"aciform","title":"aciform","description":"","parent":0,"post_count":2},{"id":9,"slug":"cat-a","title":"Cat A","description":"","parent":0,"post_count":2},{"id":10,"slug":"cat-b","title":"Cat B","description":"","parent":0,"post_count":1},{"id":11,"slug":"cat-c","title":"Cat C","description":"","parent":0,"post_count":1},{"id":41,"slug":"sub","title":"sub","description":"","parent":3,"post_count":1}],"tags":[{"id":93,"slug":"tag1","title":"tag1","description":"","post_count":1},{"id":94,"slug":"tag2","title":"tag2","description":"","post_count":1},{"id":95,"slug":"tag3","title":"tag3","description":"","post_count":1}],"author":{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},"comments":[],"attachments":[],"comment_count":0,"comment_status":"closed"},{"id":128,"type":"post","slug":"images-test","url":"http:\/\/wordpress.test\/2008\/09\/03\/images-test\/","status":"publish","title":"Images Test","title_plain":"Images Test","content":"<h2>Image Alignment Tests: Un-Captioned Images<\/h2>\n<h3 id=\"center-align-no-caption\">Center-align, no caption<\/h3>\n<p>Center-aligned image with no caption, and text before and after. <img src=\"http:\/\/wordpress.test\/wp-content\/uploads\/2010\/08\/test-image-landscape1.jpg\" alt=\"\" title=\"test-image-landscape\" width=\"300\" height=\"199\" class=\"aligncenter size-full wp-image-535\" \/> ALorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed odio nibh, tincidunt adipiscing, pretium nec, tincidunt id, enim. Fusce scelerisque nunc vitae nisl. Quisque quis urna in velit dictum pellentesque. Vivamus a quam. Curabitur eu tortor id turpis tristique adipiscing. Morbi blandit. Maecenas vel est. Nunc aliquam, orci at accumsan commodo, libero nibh euismod augue, a ullamcorper velit dui et purus. Aenean volutpat, ipsum ac imperdiet fermentum, dui dui suscipit arcu, vitae dictum purus diam ac ligula.<\/p>\n<h3 id=\"left-align-no-caption\">Left-align, no caption<\/h3>\n<p>Left-aligned image with no caption, and text before and after. <img src=\"http:\/\/wordpress.test\/wp-content\/uploads\/2010\/08\/test-image-landscape1.jpg\" alt=\"\" title=\"test-image-landscape\" width=\"300\" height=\"199\" class=\"alignleft size-full wp-image-535\" \/> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed odio nibh, tincidunt adipiscing, pretium nec, tLine truncated
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
--TEST--
|
||||||
|
core.get_author_posts by id
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTTP/Client.php';
|
||||||
|
$http = new HTTP_Client();
|
||||||
|
$http->get('http://wordpress.test/?json=core.get_author_posts&id=3');
|
||||||
|
$response = $http->currentResponse();
|
||||||
|
echo $response['body'];
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
{"status":"ok","count":10,"pages":3,"author":{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},"posts":[{"id":358,"type":"post","slug":"readability-test","url":"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/","status":"publish","title":"Readability Test","title_plain":"Readability Test","content":"<p>All children, except one, grow up. They soon know that they will grow up, and the way Wendy knew was this. One day when she was two years old she was playing in a garden, and she plucked another flower and ran with it to her mother. I suppose she must have looked rather delightful, for Mrs. Darling put her hand to her heart and cried, “Oh, why can’t you remain like this for ever!” This was all that passed between them on the subject, but henceforth Wendy knew that she must grow up. You always know after you are two. Two is the beginning of the end.<\/p>\n<p> <a href=\"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/#more-358\" class=\"more-link\">Read more<\/a><\/p>\n","excerpt":"All children, except one, grow up. They soon know that they will grow up, and the way Wendy knew was this. One day when she was two years old she was playing in a garden, and she plucked another flower … <a href=\"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/\">Continue reading <span class=\"meta-nav\">→<\/span><\/a>","date":"2008-09-05 00:27:25","modified":"2008-09-05 00:27:25","categories":[{"id":9,"slug":"cat-a","title":"Cat A","description":"","parent":0,"post_count":2}],"tags":[{"id":53,"slug":"chattels","title":"chattels","description":"","post_count":2},{"id":82,"slug":"privation","title":"privation","description":"","post_count":2}],"author":{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},"comments":[],"attachments":[],"comment_count":0,"comment_status":"closed"},{"id":188,"type":"post","slug":"layout-test","url":"http:\/\/wordpress.test\/2008\/09\/04\/layout-test\/","status":"publish","title":"Layout Test","title_plain":"Layout Test","content":"<p>This is a sticky post!!! Make sure it sticks!<\/p>\n<p>This should then split into other pages with layout, images, HTML tags, and other things.<\/p>\n","excerpt":"This is a sticky post!!! Make sure it sticks! This should then split into other pages with layout, images, HTML tags, and other things.","date":"2008-09-04 23:02:20","modified":"2008-09-04 23:02:20","categories":[{"id":3,"slug":"aciform","title":"aciform","description":"","parent":0,"post_count":2},{"id":9,"slug":"cat-a","title":"Cat A","description":"","parent":0,"post_count":2},{"id":10,"slug":"cat-b","title":"Cat B","description":"","parent":0,"post_count":1},{"id":11,"slug":"cat-c","title":"Cat C","description":"","parent":0,"post_count":1},{"id":41,"slug":"sub","title":"sub","description":"","parent":3,"post_count":1}],"tags":[{"id":93,"slug":"tag1","title":"tag1","description":"","post_count":1},{"id":94,"slug":"tag2","title":"tag2","description":"","post_count":1},{"id":95,"slug":"tag3","title":"tag3","description":"","post_count":1}],"author":{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},"comments":[],"attachments":[],"comment_count":0,"comment_status":"closed"},{"id":128,"type":"post","slug":"images-test","url":"http:\/\/wordpress.test\/2008\/09\/03\/images-test\/","status":"publish","title":"Images Test","title_plain":"Images Test","content":"<h2>Image Alignment Tests: Un-Captioned Images<\/h2>\n<h3 id=\"center-align-no-caption\">Center-align, no caption<\/h3>\n<p>Center-aligned image with no caption, and text before and after. <img src=\"http:\/\/wordpress.test\/wp-content\/uploads\/2010\/08\/test-image-landscape1.jpg\" alt=\"\" title=\"test-image-landscape\" width=\"300\" height=\"199\" class=\"aligncenter size-full wp-image-535\" \/> ALorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed odio nibh, tincidunt adipiscing, pretium nec, tincidunt id, enim. Fusce scelerisque nunc vitae nisl. Quisque quis urna in velit dictum pellentesque. Vivamus a quam. Curabitur eu tortor id turpis tristique adipiscing. Morbi blandit. Maecenas vel est. Nunc aliquam, orci at accumsan commodo, libero nibh euismod augue, a ullamcorper velit dui et purus. Aenean volutpat, ipsum ac imperdiet fermentum, dui dui suscipit arcu, vitae dictum purus diam ac ligula.<\/p>\n<h3 id=\"left-align-no-caption\">Left-align, no caption<\/h3>\n<p>Left-aligned image with no caption, and text before and after. <img src=\"http:\/\/wordpress.test\/wp-content\/uploads\/2010\/08\/test-image-landscape1.jpg\" alt=\"\" title=\"test-image-landscape\" width=\"300\" height=\"199\" class=\"alignleft size-full wp-image-535\" \/> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed odio nibh, tincidunt adipiscing, pretium nec, tLine truncated
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
--TEST--
|
||||||
|
core.get_author_posts by author_id
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTTP/Client.php';
|
||||||
|
$http = new HTTP_Client();
|
||||||
|
$http->get('http://wordpress.test/?json=core.get_author_posts&author_id=3');
|
||||||
|
$response = $http->currentResponse();
|
||||||
|
echo $response['body'];
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
{"status":"ok","count":10,"pages":3,"author":{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},"posts":[{"id":358,"type":"post","slug":"readability-test","url":"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/","status":"publish","title":"Readability Test","title_plain":"Readability Test","content":"<p>All children, except one, grow up. They soon know that they will grow up, and the way Wendy knew was this. One day when she was two years old she was playing in a garden, and she plucked another flower and ran with it to her mother. I suppose she must have looked rather delightful, for Mrs. Darling put her hand to her heart and cried, “Oh, why can’t you remain like this for ever!” This was all that passed between them on the subject, but henceforth Wendy knew that she must grow up. You always know after you are two. Two is the beginning of the end.<\/p>\n<p> <a href=\"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/#more-358\" class=\"more-link\">Read more<\/a><\/p>\n","excerpt":"All children, except one, grow up. They soon know that they will grow up, and the way Wendy knew was this. One day when she was two years old she was playing in a garden, and she plucked another flower … <a href=\"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/\">Continue reading <span class=\"meta-nav\">→<\/span><\/a>","date":"2008-09-05 00:27:25","modified":"2008-09-05 00:27:25","categories":[{"id":9,"slug":"cat-a","title":"Cat A","description":"","parent":0,"post_count":2}],"tags":[{"id":53,"slug":"chattels","title":"chattels","description":"","post_count":2},{"id":82,"slug":"privation","title":"privation","description":"","post_count":2}],"author":{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},"comments":[],"attachments":[],"comment_count":0,"comment_status":"closed"},{"id":188,"type":"post","slug":"layout-test","url":"http:\/\/wordpress.test\/2008\/09\/04\/layout-test\/","status":"publish","title":"Layout Test","title_plain":"Layout Test","content":"<p>This is a sticky post!!! Make sure it sticks!<\/p>\n<p>This should then split into other pages with layout, images, HTML tags, and other things.<\/p>\n","excerpt":"This is a sticky post!!! Make sure it sticks! This should then split into other pages with layout, images, HTML tags, and other things.","date":"2008-09-04 23:02:20","modified":"2008-09-04 23:02:20","categories":[{"id":3,"slug":"aciform","title":"aciform","description":"","parent":0,"post_count":2},{"id":9,"slug":"cat-a","title":"Cat A","description":"","parent":0,"post_count":2},{"id":10,"slug":"cat-b","title":"Cat B","description":"","parent":0,"post_count":1},{"id":11,"slug":"cat-c","title":"Cat C","description":"","parent":0,"post_count":1},{"id":41,"slug":"sub","title":"sub","description":"","parent":3,"post_count":1}],"tags":[{"id":93,"slug":"tag1","title":"tag1","description":"","post_count":1},{"id":94,"slug":"tag2","title":"tag2","description":"","post_count":1},{"id":95,"slug":"tag3","title":"tag3","description":"","post_count":1}],"author":{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},"comments":[],"attachments":[],"comment_count":0,"comment_status":"closed"},{"id":128,"type":"post","slug":"images-test","url":"http:\/\/wordpress.test\/2008\/09\/03\/images-test\/","status":"publish","title":"Images Test","title_plain":"Images Test","content":"<h2>Image Alignment Tests: Un-Captioned Images<\/h2>\n<h3 id=\"center-align-no-caption\">Center-align, no caption<\/h3>\n<p>Center-aligned image with no caption, and text before and after. <img src=\"http:\/\/wordpress.test\/wp-content\/uploads\/2010\/08\/test-image-landscape1.jpg\" alt=\"\" title=\"test-image-landscape\" width=\"300\" height=\"199\" class=\"aligncenter size-full wp-image-535\" \/> ALorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed odio nibh, tincidunt adipiscing, pretium nec, tincidunt id, enim. Fusce scelerisque nunc vitae nisl. Quisque quis urna in velit dictum pellentesque. Vivamus a quam. Curabitur eu tortor id turpis tristique adipiscing. Morbi blandit. Maecenas vel est. Nunc aliquam, orci at accumsan commodo, libero nibh euismod augue, a ullamcorper velit dui et purus. Aenean volutpat, ipsum ac imperdiet fermentum, dui dui suscipit arcu, vitae dictum purus diam ac ligula.<\/p>\n<h3 id=\"left-align-no-caption\">Left-align, no caption<\/h3>\n<p>Left-aligned image with no caption, and text before and after. <img src=\"http:\/\/wordpress.test\/wp-content\/uploads\/2010\/08\/test-image-landscape1.jpg\" alt=\"\" title=\"test-image-landscape\" width=\"300\" height=\"199\" class=\"alignleft size-full wp-image-535\" \/> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed odio nibh, tincidunt adipiscing, pretium nec, tLine truncated
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
--TEST--
|
||||||
|
core.get_category_index
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTTP/Client.php';
|
||||||
|
$http = new HTTP_Client();
|
||||||
|
$http->get('http://wordpress.test/?json=core.get_category_index');
|
||||||
|
$response = $http->currentResponse();
|
||||||
|
echo $response['body'];
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
{"status":"ok","count":44,"categories":[{"id":3,"slug":"aciform","title":"aciform","description":"","parent":0,"post_count":2},{"id":4,"slug":"antiquarianism","title":"antiquarianism","description":"","parent":0,"post_count":1},{"id":5,"slug":"arrangement","title":"arrangement","description":"","parent":0,"post_count":1},{"id":6,"slug":"asmodeus","title":"asmodeus","description":"","parent":0,"post_count":1},{"id":7,"slug":"broder","title":"broder","description":"","parent":0,"post_count":1},{"id":8,"slug":"buying","title":"buying","description":"","parent":0,"post_count":1},{"id":9,"slug":"cat-a","title":"Cat A","description":"","parent":0,"post_count":2},{"id":10,"slug":"cat-b","title":"Cat B","description":"","parent":0,"post_count":1},{"id":11,"slug":"cat-c","title":"Cat C","description":"","parent":0,"post_count":1},{"id":12,"slug":"championship","title":"championship","description":"","parent":0,"post_count":1},{"id":13,"slug":"chastening","title":"chastening","description":"","parent":0,"post_count":1},{"id":14,"slug":"clerkship","title":"clerkship","description":"","parent":0,"post_count":1},{"id":15,"slug":"disinclination","title":"disinclination","description":"","parent":0,"post_count":1},{"id":16,"slug":"disinfection","title":"disinfection","description":"","parent":0,"post_count":1},{"id":17,"slug":"dispatch","title":"dispatch","description":"","parent":0,"post_count":1},{"id":18,"slug":"echappee","title":"echappee","description":"","parent":0,"post_count":1},{"id":19,"slug":"enphagy","title":"enphagy","description":"","parent":0,"post_count":1},{"id":20,"slug":"equipollent","title":"equipollent","description":"","parent":0,"post_count":1},{"id":21,"slug":"fatuity","title":"fatuity","description":"","parent":0,"post_count":1},{"id":24,"slug":"gaberlunzie","title":"gaberlunzie","description":"","parent":0,"post_count":1},{"id":25,"slug":"illtempered","title":"illtempered","description":"","parent":0,"post_count":1},{"id":26,"slug":"insubordination","title":"insubordination","description":"","parent":0,"post_count":1},{"id":27,"slug":"lender","title":"lender","description":"","parent":0,"post_count":1},{"id":28,"slug":"monosyllable","title":"monosyllable","description":"","parent":0,"post_count":1},{"id":29,"slug":"packthread","title":"packthread","description":"","parent":0,"post_count":1},{"id":30,"slug":"palter","title":"palter","description":"","parent":0,"post_count":1},{"id":31,"slug":"papilionaceous","title":"papilionaceous","description":"","parent":0,"post_count":1},{"id":33,"slug":"personable","title":"personable","description":"","parent":0,"post_count":1},{"id":34,"slug":"propylaeum","title":"propylaeum","description":"","parent":0,"post_count":1},{"id":35,"slug":"pustule","title":"pustule","description":"","parent":0,"post_count":1},{"id":36,"slug":"quartern","title":"quartern","description":"","parent":0,"post_count":1},{"id":37,"slug":"scholarship","title":"scholarship","description":"","parent":0,"post_count":1},{"id":38,"slug":"selfconvicted","title":"selfconvicted","description":"","parent":0,"post_count":1},{"id":39,"slug":"showshoe","title":"showshoe","description":"","parent":0,"post_count":1},{"id":40,"slug":"sloyd","title":"sloyd","description":"","parent":0,"post_count":1},{"id":41,"slug":"sub","title":"sub","description":"","parent":3,"post_count":1},{"id":42,"slug":"sublunary","title":"sublunary","description":"","parent":0,"post_count":1},{"id":43,"slug":"tamtam","title":"tamtam","description":"","parent":0,"post_count":1},{"id":44,"slug":"weakhearted","title":"weakhearted","description":"","parent":0,"post_count":1},{"id":45,"slug":"ween","title":"ween","description":"","parent":0,"post_count":1},{"id":46,"slug":"wellhead","title":"wellhead","description":"","parent":0,"post_count":1},{"id":47,"slug":"wellintentioned","title":"wellintentioned","description":"","parent":0,"post_count":1},{"id":48,"slug":"whetstone","title":"whetstone","description":"","parent":0,"post_count":1},{"id":49,"slug":"years","title":"years","description":"","parent":0,"post_count":1}]}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
--TEST--
|
||||||
|
core.get_category_posts default
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTTP/Client.php';
|
||||||
|
$http = new HTTP_Client();
|
||||||
|
$http->get('http://wordpress.test/?json=core.get_category_posts&slug=cat-a');
|
||||||
|
$response = $http->currentResponse();
|
||||||
|
echo $response['body'];
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
{"status":"ok","count":2,"pages":1,"category":{"id":9,"slug":"cat-a","title":"Cat A","description":"","parent":0,"post_count":2},"posts":[{"id":358,"type":"post","slug":"readability-test","url":"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/","status":"publish","title":"Readability Test","title_plain":"Readability Test","content":"<p>All children, except one, grow up. They soon know that they will grow up, and the way Wendy knew was this. One day when she was two years old she was playing in a garden, and she plucked another flower and ran with it to her mother. I suppose she must have looked rather delightful, for Mrs. Darling put her hand to her heart and cried, “Oh, why can’t you remain like this for ever!” This was all that passed between them on the subject, but henceforth Wendy knew that she must grow up. You always know after you are two. Two is the beginning of the end.<\/p>\n<p> <a href=\"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/#more-358\" class=\"more-link\">Read more<\/a><\/p>\n","excerpt":"All children, except one, grow up. They soon know that they will grow up, and the way Wendy knew was this. One day when she was two years old she was playing in a garden, and she plucked another flower … <a href=\"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/\">Continue reading <span class=\"meta-nav\">→<\/span><\/a>","date":"2008-09-05 00:27:25","modified":"2008-09-05 00:27:25","categories":[{"id":9,"slug":"cat-a","title":"Cat A","description":"","parent":0,"post_count":2}],"tags":[{"id":53,"slug":"chattels","title":"chattels","description":"","post_count":2},{"id":82,"slug":"privation","title":"privation","description":"","post_count":2}],"author":{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},"comments":[],"attachments":[],"comment_count":0,"comment_status":"closed"},{"id":188,"type":"post","slug":"layout-test","url":"http:\/\/wordpress.test\/2008\/09\/04\/layout-test\/","status":"publish","title":"Layout Test","title_plain":"Layout Test","content":"<p>This is a sticky post!!! Make sure it sticks!<\/p>\n<p>This should then split into other pages with layout, images, HTML tags, and other things.<\/p>\n","excerpt":"This is a sticky post!!! Make sure it sticks! This should then split into other pages with layout, images, HTML tags, and other things.","date":"2008-09-04 23:02:20","modified":"2008-09-04 23:02:20","categories":[{"id":3,"slug":"aciform","title":"aciform","description":"","parent":0,"post_count":2},{"id":9,"slug":"cat-a","title":"Cat A","description":"","parent":0,"post_count":2},{"id":10,"slug":"cat-b","title":"Cat B","description":"","parent":0,"post_count":1},{"id":11,"slug":"cat-c","title":"Cat C","description":"","parent":0,"post_count":1},{"id":41,"slug":"sub","title":"sub","description":"","parent":3,"post_count":1}],"tags":[{"id":93,"slug":"tag1","title":"tag1","description":"","post_count":1},{"id":94,"slug":"tag2","title":"tag2","description":"","post_count":1},{"id":95,"slug":"tag3","title":"tag3","description":"","post_count":1}],"author":{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},"comments":[],"attachments":[],"comment_count":0,"comment_status":"closed"}]}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
--TEST--
|
||||||
|
core.get_search_posts default
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTTP/Client.php';
|
||||||
|
$http = new HTTP_Client();
|
||||||
|
$http->get('http://wordpress.test/?json=core.get_date_index');
|
||||||
|
$response = $http->currentResponse();
|
||||||
|
echo $response['body'];
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
{"status":"ok","permalinks":["http:\/\/wordpress.test\/2008\/09\/","http:\/\/wordpress.test\/2008\/06\/","http:\/\/wordpress.test\/2008\/05\/","http:\/\/wordpress.test\/2008\/04\/","http:\/\/wordpress.test\/2008\/03\/"],"tree":{"2008":{"09":"3","06":"10","05":"5","04":"1","03":"3"}}}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
--TEST--
|
||||||
|
core.get_date_posts by day
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTTP/Client.php';
|
||||||
|
$http = new HTTP_Client();
|
||||||
|
$http->get('http://wordpress.test/?json=core.get_date_posts&date=2008-09-05');
|
||||||
|
$response = $http->currentResponse();
|
||||||
|
echo $response['body'];
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
{"status":"ok","count":1,"count_total":1,"pages":1,"posts":[{"id":358,"type":"post","slug":"readability-test","url":"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/","status":"publish","title":"Readability Test","title_plain":"Readability Test","content":"<p>All children, except one, grow up. They soon know that they will grow up, and the way Wendy knew was this. One day when she was two years old she was playing in a garden, and she plucked another flower and ran with it to her mother. I suppose she must have looked rather delightful, for Mrs. Darling put her hand to her heart and cried, “Oh, why can’t you remain like this for ever!” This was all that passed between them on the subject, but henceforth Wendy knew that she must grow up. You always know after you are two. Two is the beginning of the end.<\/p>\n<p> <a href=\"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/#more-358\" class=\"more-link\">Read more<\/a><\/p>\n","excerpt":"All children, except one, grow up. They soon know that they will grow up, and the way Wendy knew was this. One day when she was two years old she was playing in a garden, and she plucked another flower … <a href=\"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/\">Continue reading <span class=\"meta-nav\">→<\/span><\/a>","date":"2008-09-05 00:27:25","modified":"2008-09-05 00:27:25","categories":[{"id":9,"slug":"cat-a","title":"Cat A","description":"","parent":0,"post_count":2}],"tags":[{"id":53,"slug":"chattels","title":"chattels","description":"","post_count":2},{"id":82,"slug":"privation","title":"privation","description":"","post_count":2}],"author":{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},"comments":[],"attachments":[],"comment_count":0,"comment_status":"closed"}]}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
--TEST--
|
||||||
|
core.get_date_posts by month
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTTP/Client.php';
|
||||||
|
$http = new HTTP_Client();
|
||||||
|
$http->get('http://wordpress.test/?json=core.get_date_posts&date=2008-09');
|
||||||
|
$response = $http->currentResponse();
|
||||||
|
echo $response['body'];
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
{"status":"ok","count":3,"count_total":3,"pages":1,"posts":[{"id":358,"type":"post","slug":"readability-test","url":"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/","status":"publish","title":"Readability Test","title_plain":"Readability Test","content":"<p>All children, except one, grow up. They soon know that they will grow up, and the way Wendy knew was this. One day when she was two years old she was playing in a garden, and she plucked another flower and ran with it to her mother. I suppose she must have looked rather delightful, for Mrs. Darling put her hand to her heart and cried, “Oh, why can’t you remain like this for ever!” This was all that passed between them on the subject, but henceforth Wendy knew that she must grow up. You always know after you are two. Two is the beginning of the end.<\/p>\n<p> <a href=\"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/#more-358\" class=\"more-link\">Read more<\/a><\/p>\n","excerpt":"All children, except one, grow up. They soon know that they will grow up, and the way Wendy knew was this. One day when she was two years old she was playing in a garden, and she plucked another flower … <a href=\"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/\">Continue reading <span class=\"meta-nav\">→<\/span><\/a>","date":"2008-09-05 00:27:25","modified":"2008-09-05 00:27:25","categories":[{"id":9,"slug":"cat-a","title":"Cat A","description":"","parent":0,"post_count":2}],"tags":[{"id":53,"slug":"chattels","title":"chattels","description":"","post_count":2},{"id":82,"slug":"privation","title":"privation","description":"","post_count":2}],"author":{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},"comments":[],"attachments":[],"comment_count":0,"comment_status":"closed"},{"id":188,"type":"post","slug":"layout-test","url":"http:\/\/wordpress.test\/2008\/09\/04\/layout-test\/","status":"publish","title":"Layout Test","title_plain":"Layout Test","content":"<p>This is a sticky post!!! Make sure it sticks!<\/p>\n<p>This should then split into other pages with layout, images, HTML tags, and other things.<\/p>\n","excerpt":"This is a sticky post!!! Make sure it sticks! This should then split into other pages with layout, images, HTML tags, and other things.","date":"2008-09-04 23:02:20","modified":"2008-09-04 23:02:20","categories":[{"id":3,"slug":"aciform","title":"aciform","description":"","parent":0,"post_count":2},{"id":9,"slug":"cat-a","title":"Cat A","description":"","parent":0,"post_count":2},{"id":10,"slug":"cat-b","title":"Cat B","description":"","parent":0,"post_count":1},{"id":11,"slug":"cat-c","title":"Cat C","description":"","parent":0,"post_count":1},{"id":41,"slug":"sub","title":"sub","description":"","parent":3,"post_count":1}],"tags":[{"id":93,"slug":"tag1","title":"tag1","description":"","post_count":1},{"id":94,"slug":"tag2","title":"tag2","description":"","post_count":1},{"id":95,"slug":"tag3","title":"tag3","description":"","post_count":1}],"author":{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},"comments":[],"attachments":[],"comment_count":0,"comment_status":"closed"},{"id":128,"type":"post","slug":"images-test","url":"http:\/\/wordpress.test\/2008\/09\/03\/images-test\/","status":"publish","title":"Images Test","title_plain":"Images Test","content":"<h2>Image Alignment Tests: Un-Captioned Images<\/h2>\n<h3 id=\"center-align-no-caption\">Center-align, no caption<\/h3>\n<p>Center-aligned image with no caption, and text before and after. <img src=\"http:\/\/wordpress.test\/wp-content\/uploads\/2010\/08\/test-image-landscape1.jpg\" alt=\"\" title=\"test-image-landscape\" width=\"300\" height=\"199\" class=\"aligncenter size-full wp-image-535\" \/> ALorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed odio nibh, tincidunt adipiscing, pretium nec, tincidunt id, enim. Fusce scelerisque nunc vitae nisl. Quisque quis urna in velit dictum pellentesque. Vivamus a quam. Curabitur eu tortor id turpis tristique adipiscing. Morbi blandit. Maecenas vel est. Nunc aliquam, orci at accumsan commodo, libero nibh euismod augue, a ullamcorper velit dui et purus. Aenean volutpat, ipsum ac imperdiet fermentum, dui dui suscipit arcu, vitae dictum purus diam ac ligula.<\/p>\n<h3 id=\"left-align-no-caption\">Left-align, no caption<\/h3>\n<p>Left-aligned image with no caption, and text before and after. <img src=\"http:\/\/wordpress.test\/wp-content\/uploads\/2010\/08\/test-image-landscape1.jpg\" alt=\"\" title=\"test-image-landscape\" width=\"300\" height=\"199\" class=\"alignleft size-full wp-image-535\" \/> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed odio nibh, tincidunt adipiscing, pretium nec, tincidunt id, enim. Fusce scelerisque nunc vitae nisl. Quisque quis urna in velit dictum pellentesque. Vivamus a quam. Curabitur euLine truncated
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
--TEST--
|
||||||
|
core.get_date_posts by year
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTTP/Client.php';
|
||||||
|
$http = new HTTP_Client();
|
||||||
|
$http->get('http://wordpress.test/?json=core.get_date_posts&date=2008-09');
|
||||||
|
$response = $http->currentResponse();
|
||||||
|
echo $response['body'];
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
{"status":"ok","count":3,"count_total":3,"pages":1,"posts":[{"id":358,"type":"post","slug":"readability-test","url":"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/","status":"publish","title":"Readability Test","title_plain":"Readability Test","content":"<p>All children, except one, grow up. They soon know that they will grow up, and the way Wendy knew was this. One day when she was two years old she was playing in a garden, and she plucked another flower and ran with it to her mother. I suppose she must have looked rather delightful, for Mrs. Darling put her hand to her heart and cried, “Oh, why can’t you remain like this for ever!” This was all that passed between them on the subject, but henceforth Wendy knew that she must grow up. You always know after you are two. Two is the beginning of the end.<\/p>\n<p> <a href=\"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/#more-358\" class=\"more-link\">Read more<\/a><\/p>\n","excerpt":"All children, except one, grow up. They soon know that they will grow up, and the way Wendy knew was this. One day when she was two years old she was playing in a garden, and she plucked another flower … <a href=\"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/\">Continue reading <span class=\"meta-nav\">→<\/span><\/a>","date":"2008-09-05 00:27:25","modified":"2008-09-05 00:27:25","categories":[{"id":9,"slug":"cat-a","title":"Cat A","description":"","parent":0,"post_count":2}],"tags":[{"id":53,"slug":"chattels","title":"chattels","description":"","post_count":2},{"id":82,"slug":"privation","title":"privation","description":"","post_count":2}],"author":{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},"comments":[],"attachments":[],"comment_count":0,"comment_status":"closed"},{"id":188,"type":"post","slug":"layout-test","url":"http:\/\/wordpress.test\/2008\/09\/04\/layout-test\/","status":"publish","title":"Layout Test","title_plain":"Layout Test","content":"<p>This is a sticky post!!! Make sure it sticks!<\/p>\n<p>This should then split into other pages with layout, images, HTML tags, and other things.<\/p>\n","excerpt":"This is a sticky post!!! Make sure it sticks! This should then split into other pages with layout, images, HTML tags, and other things.","date":"2008-09-04 23:02:20","modified":"2008-09-04 23:02:20","categories":[{"id":3,"slug":"aciform","title":"aciform","description":"","parent":0,"post_count":2},{"id":9,"slug":"cat-a","title":"Cat A","description":"","parent":0,"post_count":2},{"id":10,"slug":"cat-b","title":"Cat B","description":"","parent":0,"post_count":1},{"id":11,"slug":"cat-c","title":"Cat C","description":"","parent":0,"post_count":1},{"id":41,"slug":"sub","title":"sub","description":"","parent":3,"post_count":1}],"tags":[{"id":93,"slug":"tag1","title":"tag1","description":"","post_count":1},{"id":94,"slug":"tag2","title":"tag2","description":"","post_count":1},{"id":95,"slug":"tag3","title":"tag3","description":"","post_count":1}],"author":{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},"comments":[],"attachments":[],"comment_count":0,"comment_status":"closed"},{"id":128,"type":"post","slug":"images-test","url":"http:\/\/wordpress.test\/2008\/09\/03\/images-test\/","status":"publish","title":"Images Test","title_plain":"Images Test","content":"<h2>Image Alignment Tests: Un-Captioned Images<\/h2>\n<h3 id=\"center-align-no-caption\">Center-align, no caption<\/h3>\n<p>Center-aligned image with no caption, and text before and after. <img src=\"http:\/\/wordpress.test\/wp-content\/uploads\/2010\/08\/test-image-landscape1.jpg\" alt=\"\" title=\"test-image-landscape\" width=\"300\" height=\"199\" class=\"aligncenter size-full wp-image-535\" \/> ALorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed odio nibh, tincidunt adipiscing, pretium nec, tincidunt id, enim. Fusce scelerisque nunc vitae nisl. Quisque quis urna in velit dictum pellentesque. Vivamus a quam. Curabitur eu tortor id turpis tristique adipiscing. Morbi blandit. Maecenas vel est. Nunc aliquam, orci at accumsan commodo, libero nibh euismod augue, a ullamcorper velit dui et purus. Aenean volutpat, ipsum ac imperdiet fermentum, dui dui suscipit arcu, vitae dictum purus diam ac ligula.<\/p>\n<h3 id=\"left-align-no-caption\">Left-align, no caption<\/h3>\n<p>Left-aligned image with no caption, and text before and after. <img src=\"http:\/\/wordpress.test\/wp-content\/uploads\/2010\/08\/test-image-landscape1.jpg\" alt=\"\" title=\"test-image-landscape\" width=\"300\" height=\"199\" class=\"alignleft size-full wp-image-535\" \/> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed odio nibh, tincidunt adipiscing, pretium nec, tincidunt id, enim. Fusce scelerisque nunc vitae nisl. Quisque quis urna in velit dictum pellentesque. Vivamus a quam. Curabitur euLine truncated
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
--TEST--
|
||||||
|
core.get_page default
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTTP/Client.php';
|
||||||
|
$http = new HTTP_Client();
|
||||||
|
$http->get('http://wordpress.test/?json=core.get_page&slug=about');
|
||||||
|
$response = $http->currentResponse();
|
||||||
|
echo $response['body'];
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
{"status":"ok","page":{"id":686,"type":"page","slug":"about","url":"http:\/\/wordpress.test\/about\/","status":"publish","title":"About The Tests","title_plain":"About The Tests","content":"<p>This site is using the standard WordPress Theme Unit Test Data for content. The Theme Unit Test is a series of posts and pages that match up with a checklist on the WordPress codex. You can use the data and checklist together to test your theme.<\/p>\n<h2>WordPress Theme Development Resources<\/h2>\n<ol>\n<li>See <a href=\"http:\/\/codex.wordpress.org\/Theme_Development\">Theme Development<\/a> for <a href=\"http:\/\/codex.wordpress.org\/Theme_Development#Code_Standards\">code standards<\/a>, examples of best practices, and <a href=\"http:\/\/codex.wordpress.org\/Theme_Development#Resources_and_References\">resources for Theme development<\/a>.<\/li>\n<li>See <a href=\"http:\/\/codex.wordpress.org\/Theme_Unit_Test\">Theme Unit Test<\/a> for a robust test suite for your Theme and get the latest version of the test data you see here.<\/li>\n<li>See <a href=\"http:\/\/codex.wordpress.org\/Theme_Review\">Theme Review<\/a> for a guide to submitting your Theme to the <a href=\"http:\/\/wordpress.org\/extend\/themes\/\">Themes Directory<\/a>.<\/li>\n<\/ol>\n","excerpt":"This site is using the standard WordPress Theme Unit Test Data for content. The Theme Unit Test is a series of posts and pages that match up with a checklist on the WordPress codex. You can use the data and … <a href=\"http:\/\/wordpress.test\/about\/\">Continue reading <span class=\"meta-nav\">→<\/span><\/a>","date":"2010-07-25 19:40:01","modified":"2010-07-25 19:40:01","categories":[],"tags":[],"author":{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},"comments":[],"attachments":[],"comment_count":0,"comment_status":"closed"}}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
--TEST--
|
||||||
|
core.get_page children argument
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTTP/Client.php';
|
||||||
|
$http = new HTTP_Client();
|
||||||
|
$http->get('http://wordpress.test/?json=core.get_page&slug=level-1&children=1');
|
||||||
|
$response = $http->currentResponse();
|
||||||
|
echo $response['body'];
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
{"status":"ok","page":{"id":174,"type":"page","slug":"level-1","url":"http:\/\/wordpress.test\/level-1\/","status":"publish","title":"Level 1","title_plain":"Level 1","content":"<p>Level 1 of the reverse hierarchy test. This is to make sure the importer correctly assigns parents and children even when the children come first in the export file.<\/p>\n","excerpt":"Level 1 of the reverse hierarchy test. This is to make sure the importer correctly assigns parents and children even when the children come first in the export file.","date":"2007-12-11 16:25:40","modified":"2007-12-11 16:25:40","categories":[],"tags":[],"author":{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},"comments":[],"attachments":[],"comment_count":0,"comment_status":"closed","children":[{"id":173,"type":"page","slug":"level-2","url":"http:\/\/wordpress.test\/level-1\/level-2\/","status":"publish","title":"Level 2","title_plain":"Level 2","content":"<p>Level 2 of the reverse hierarchy test.<\/p>\n","excerpt":"Level 2 of the reverse hierarchy test.","date":"2007-12-11 16:25:40","modified":"2007-12-11 16:23:33","categories":[],"tags":[],"author":{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},"comments":[],"attachments":[],"comment_count":0,"comment_status":"closed","children":[{"id":172,"type":"page","slug":"level-3","url":"http:\/\/wordpress.test\/level-1\/level-2\/level-3\/","status":"publish","title":"Level 3","title_plain":"Level 3","content":"<p>Level 3 of the reverse hierarchy test.<\/p>\n","excerpt":"Level 3 of the reverse hierarchy test.","date":"2007-12-11 16:25:40","modified":"2007-12-11 16:23:16","categories":[],"tags":[],"author":{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},"comments":[],"attachments":[],"comment_count":0,"comment_status":"closed","children":[]}]}]}}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
--TEST--
|
||||||
|
core.get_post default
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTTP/Client.php';
|
||||||
|
$http = new HTTP_Client();
|
||||||
|
$http->get('http://wordpress.test/?json=core.get_post&slug=readability-test');
|
||||||
|
$response = $http->currentResponse();
|
||||||
|
echo $response['body'];
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
{"status":"ok","post":{"id":358,"type":"post","slug":"readability-test","url":"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/","status":"publish","title":"Readability Test","title_plain":"Readability Test","content":"<p>All children, except one, grow up. They soon know that they will grow up, and the way Wendy knew was this. One day when she was two years old she was playing in a garden, and she plucked another flower and ran with it to her mother. I suppose she must have looked rather delightful, for Mrs. Darling put her hand to her heart and cried, “Oh, why can’t you remain like this for ever!” This was all that passed between them on the subject, but henceforth Wendy knew that she must grow up. You always know after you are two. Two is the beginning of the end.<\/p>\n<p><span id=\"more-358\"><\/span><\/p>\n<p>Mrs. Darling first heard of Peter when she was tidying up her children’s minds. It is the nightly custom of every good mother after her children are asleep to rummage in their minds and put things straight for next morning, repacking into their proper places the many articles that have wandered during the day.<\/p>\n<p>If you could keep awake (but of course you can’t) you would see your own mother doing this, and you would find it very interesting to watch her. It is quite like tidying up drawers. You would see her on her knees, I expect, lingering humorously over some of your contents, wondering where on earth you had picked this thing up, making discoveries sweet and not so sweet, pressing this to her cheek as if it were as nice as a kitten, and hurriedly stowing that out of sight. When you wake in the morning, the naughtiness and evil passions with which you went to bed have been folded up small and placed at the bottom of your mind and on the top, beautifully aired, are spread out your prettier thoughts, ready for you to put on.<\/p>\n<p>I don’t know whether you have ever seen a map of a person’s mind. Doctors sometimes draw maps of other parts of you, and your own map can become intensely interesting, but catch them trying to draw a map of a child’s mind, which is not only confused, but keeps going round all the time. There are zigzag lines on it, just like your temperature on a card, and these are probably roads in the island, for the Neverland is always more or less an island, with astonishing splashes of colour here and there, and coral reefs and rakish-looking craft in the offing, and savages and lonely lairs, and gnomes who are mostly tailors, and caves through which a river runs, and princes with six elder brothers, and a hut fast going to decay, and one very small old lady with a hooked nose. It would be an easy map if that were all, but there is also first day at school, religion, fathers, the round pond, needle-work, murders, hangings, verbs that take the dative, chocolate pudding day, getting into braces, say ninety-nine, three-pence for pulling out your tooth yourself, and so on, and either these are part of the island or they are another map showing through, and it is all rather confusing, especially as nothing will stand still.<\/p>\n<p>Of course the Neverlands vary a good deal. John’s, for instance, had a lagoon with flamingoes flying over it at which John was shooting, while Michael, who was very small, had a flamingo with lagoons flying over it. John lived in a boat turned upside down on the sands, Michael in a wigwam, Wendy in a house of leaves deftly sewn together. John had no friends, Michael had friends at night, Wendy had a pet wolf forsaken by its parents, but on the whole the Neverlands have a family resemblance, and if they stood still in a row you could say of them that they have each other’s nose, and so forth. On these magic shores children at play are for ever beaching their coracles [simple boat]. We too have been there; we can still hear the sound of the surf, though we shall land no more.<\/p>\n<p>Of all delectable islands the Neverland is the snuggest and most compact, not large and sprawly, you know, with tedious distances between one adventure and another, but nicely crammed. When you play at it by day with the chairs and table-cloth, it is not in the least alarming, but in the two minutes before you go to sleep it becomes very real. That is why there are night-lights.<\/p>\n<p>Occasionally in her travels through her children’s minds Mrs. Darling found things she could not understand, and of these quite the most perplexing was the word Peter. She knew of no Peter, and yet he was here and there in John and Michael’s minds, while Wendy’s began to be scrawled all over with him. The name stood out in bolder letters than any of the other words, and as Mrs. Darling gazed she felt that it had an oddly cocky appearance.<\/p>\n","excerpt":"All children, except one, grow up. They soon know that they will grow up, and the way Wendy knew was this. One day when she was two years old shLine truncated
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
--TEST--
|
||||||
|
core.get_recent_posts default
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTTP/Client.php';
|
||||||
|
$http = new HTTP_Client();
|
||||||
|
$http->get('http://wordpress.test/?json=core.get_recent_posts');
|
||||||
|
$response = $http->currentResponse();
|
||||||
|
echo $response['body'];
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
{"status":"ok","count":10,"count_total":22,"pages":3,"posts":[{"id":188,"type":"post","slug":"layout-test","url":"http:\/\/wordpress.test\/2008\/09\/04\/layout-test\/","status":"publish","title":"Layout Test","title_plain":"Layout Test","content":"<p>This is a sticky post!!! Make sure it sticks!<\/p>\n<p>This should then split into other pages with layout, images, HTML tags, and other things.<\/p>\n","excerpt":"This is a sticky post!!! Make sure it sticks! This should then split into other pages with layout, images, HTML tags, and other things.","date":"2008-09-04 23:02:20","modified":"2008-09-04 23:02:20","categories":[{"id":3,"slug":"aciform","title":"aciform","description":"","parent":0,"post_count":2},{"id":9,"slug":"cat-a","title":"Cat A","description":"","parent":0,"post_count":2},{"id":10,"slug":"cat-b","title":"Cat B","description":"","parent":0,"post_count":1},{"id":11,"slug":"cat-c","title":"Cat C","description":"","parent":0,"post_count":1},{"id":41,"slug":"sub","title":"sub","description":"","parent":3,"post_count":1}],"tags":[{"id":93,"slug":"tag1","title":"tag1","description":"","post_count":1},{"id":94,"slug":"tag2","title":"tag2","description":"","post_count":1},{"id":95,"slug":"tag3","title":"tag3","description":"","post_count":1}],"author":{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},"comments":[],"attachments":[],"comment_count":0,"comment_status":"closed"},{"id":358,"type":"post","slug":"readability-test","url":"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/","status":"publish","title":"Readability Test","title_plain":"Readability Test","content":"<p>All children, except one, grow up. They soon know that they will grow up, and the way Wendy knew was this. One day when she was two years old she was playing in a garden, and she plucked another flower and ran with it to her mother. I suppose she must have looked rather delightful, for Mrs. Darling put her hand to her heart and cried, “Oh, why can’t you remain like this for ever!” This was all that passed between them on the subject, but henceforth Wendy knew that she must grow up. You always know after you are two. Two is the beginning of the end.<\/p>\n<p> <a href=\"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/#more-358\" class=\"more-link\">Read more<\/a><\/p>\n","excerpt":"All children, except one, grow up. They soon know that they will grow up, and the way Wendy knew was this. One day when she was two years old she was playing in a garden, and she plucked another flower … <a href=\"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/\">Continue reading <span class=\"meta-nav\">→<\/span><\/a>","date":"2008-09-05 00:27:25","modified":"2008-09-05 00:27:25","categories":[{"id":9,"slug":"cat-a","title":"Cat A","description":"","parent":0,"post_count":2}],"tags":[{"id":53,"slug":"chattels","title":"chattels","description":"","post_count":2},{"id":82,"slug":"privation","title":"privation","description":"","post_count":2}],"author":{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},"comments":[],"attachments":[],"comment_count":0,"comment_status":"closed"},{"id":128,"type":"post","slug":"images-test","url":"http:\/\/wordpress.test\/2008\/09\/03\/images-test\/","status":"publish","title":"Images Test","title_plain":"Images Test","content":"<h2>Image Alignment Tests: Un-Captioned Images<\/h2>\n<h3 id=\"center-align-no-caption\">Center-align, no caption<\/h3>\n<p>Center-aligned image with no caption, and text before and after. <img src=\"http:\/\/wordpress.test\/wp-content\/uploads\/2010\/08\/test-image-landscape1.jpg\" alt=\"\" title=\"test-image-landscape\" width=\"300\" height=\"199\" class=\"aligncenter size-full wp-image-535\" \/> ALorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed odio nibh, tincidunt adipiscing, pretium nec, tincidunt id, enim. Fusce scelerisque nunc vitae nisl. Quisque quis urna in velit dictum pellentesque. Vivamus a quam. Curabitur eu tortor id turpis tristique adipiscing. Morbi blandit. Maecenas vel est. Nunc aliquam, orci at accumsan commodo, libero nibh euismod augue, a ullamcorper velit dui et purus. Aenean volutpat, ipsum ac imperdiet fermentum, dui dui suscipit arcu, vitae dictum purus diam ac ligula.<\/p>\n<h3 id=\"left-align-no-caption\">Left-align, no caption<\/h3>\n<p>Left-aligned image with no caption, and text before and after. <img src=\"http:\/\/wordpress.test\/wp-content\/uploads\/2010\/08\/test-image-landscape1.jpg\" alt=\"\" title=\"test-image-landscape\" width=\"300\" height=\"199\" class=\"alignleft size-full wp-image-535\" \/> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed odio nibh, tincidunt adipiscing, pretium nec, tincidunt id, enim. Fusce scelerisque nunc vitae nisl. Quisque quis urna in velit dictum pellentesque. Vivamus a quam. Curabitur Line truncated
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
--TEST--
|
||||||
|
core.get_recent_posts count argument
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTTP/Client.php';
|
||||||
|
$http = new HTTP_Client();
|
||||||
|
$http->get('http://wordpress.test/?json=core.get_recent_posts&count=3');
|
||||||
|
$response = $http->currentResponse();
|
||||||
|
echo $response['body'];
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
{"status":"ok","count":3,"count_total":22,"pages":8,"posts":[{"id":188,"type":"post","slug":"layout-test","url":"http:\/\/wordpress.test\/2008\/09\/04\/layout-test\/","status":"publish","title":"Layout Test","title_plain":"Layout Test","content":"<p>This is a sticky post!!! Make sure it sticks!<\/p>\n<p>This should then split into other pages with layout, images, HTML tags, and other things.<\/p>\n","excerpt":"This is a sticky post!!! Make sure it sticks! This should then split into other pages with layout, images, HTML tags, and other things.","date":"2008-09-04 23:02:20","modified":"2008-09-04 23:02:20","categories":[{"id":3,"slug":"aciform","title":"aciform","description":"","parent":0,"post_count":2},{"id":9,"slug":"cat-a","title":"Cat A","description":"","parent":0,"post_count":2},{"id":10,"slug":"cat-b","title":"Cat B","description":"","parent":0,"post_count":1},{"id":11,"slug":"cat-c","title":"Cat C","description":"","parent":0,"post_count":1},{"id":41,"slug":"sub","title":"sub","description":"","parent":3,"post_count":1}],"tags":[{"id":93,"slug":"tag1","title":"tag1","description":"","post_count":1},{"id":94,"slug":"tag2","title":"tag2","description":"","post_count":1},{"id":95,"slug":"tag3","title":"tag3","description":"","post_count":1}],"author":{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},"comments":[],"attachments":[],"comment_count":0,"comment_status":"closed"},{"id":358,"type":"post","slug":"readability-test","url":"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/","status":"publish","title":"Readability Test","title_plain":"Readability Test","content":"<p>All children, except one, grow up. They soon know that they will grow up, and the way Wendy knew was this. One day when she was two years old she was playing in a garden, and she plucked another flower and ran with it to her mother. I suppose she must have looked rather delightful, for Mrs. Darling put her hand to her heart and cried, “Oh, why can’t you remain like this for ever!” This was all that passed between them on the subject, but henceforth Wendy knew that she must grow up. You always know after you are two. Two is the beginning of the end.<\/p>\n<p> <a href=\"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/#more-358\" class=\"more-link\">Read more<\/a><\/p>\n","excerpt":"All children, except one, grow up. They soon know that they will grow up, and the way Wendy knew was this. One day when she was two years old she was playing in a garden, and she plucked another flower … <a href=\"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/\">Continue reading <span class=\"meta-nav\">→<\/span><\/a>","date":"2008-09-05 00:27:25","modified":"2008-09-05 00:27:25","categories":[{"id":9,"slug":"cat-a","title":"Cat A","description":"","parent":0,"post_count":2}],"tags":[{"id":53,"slug":"chattels","title":"chattels","description":"","post_count":2},{"id":82,"slug":"privation","title":"privation","description":"","post_count":2}],"author":{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},"comments":[],"attachments":[],"comment_count":0,"comment_status":"closed"},{"id":128,"type":"post","slug":"images-test","url":"http:\/\/wordpress.test\/2008\/09\/03\/images-test\/","status":"publish","title":"Images Test","title_plain":"Images Test","content":"<h2>Image Alignment Tests: Un-Captioned Images<\/h2>\n<h3 id=\"center-align-no-caption\">Center-align, no caption<\/h3>\n<p>Center-aligned image with no caption, and text before and after. <img src=\"http:\/\/wordpress.test\/wp-content\/uploads\/2010\/08\/test-image-landscape1.jpg\" alt=\"\" title=\"test-image-landscape\" width=\"300\" height=\"199\" class=\"aligncenter size-full wp-image-535\" \/> ALorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed odio nibh, tincidunt adipiscing, pretium nec, tincidunt id, enim. Fusce scelerisque nunc vitae nisl. Quisque quis urna in velit dictum pellentesque. Vivamus a quam. Curabitur eu tortor id turpis tristique adipiscing. Morbi blandit. Maecenas vel est. Nunc aliquam, orci at accumsan commodo, libero nibh euismod augue, a ullamcorper velit dui et purus. Aenean volutpat, ipsum ac imperdiet fermentum, dui dui suscipit arcu, vitae dictum purus diam ac ligula.<\/p>\n<h3 id=\"left-align-no-caption\">Left-align, no caption<\/h3>\n<p>Left-aligned image with no caption, and text before and after. <img src=\"http:\/\/wordpress.test\/wp-content\/uploads\/2010\/08\/test-image-landscape1.jpg\" alt=\"\" title=\"test-image-landscape\" width=\"300\" height=\"199\" class=\"alignleft size-full wp-image-535\" \/> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed odio nibh, tincidunt adipiscing, pretium nec, tincidunt id, enim. Fusce scelerisque nunc vitae nisl. Quisque quis urna in velit dictum pellentesque. Vivamus a quam. Curabitur eLine truncated
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
--TEST--
|
||||||
|
core.get_recent_posts page argument
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTTP/Client.php';
|
||||||
|
$http = new HTTP_Client();
|
||||||
|
$http->get('http://wordpress.test/?json=core.get_recent_posts&page=2');
|
||||||
|
$response = $http->currentResponse();
|
||||||
|
echo $response['body'];
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
{"status":"ok","count":10,"count_total":22,"pages":3,"posts":[{"id":579,"type":"post","slug":"post-format-test-status","url":"http:\/\/wordpress.test\/2008\/06\/04\/post-format-test-status\/","status":"publish","title":"Post Format Test: Status","title_plain":"Post Format Test: Status","content":"<p>WordPress, how do I love thee? Let me count the ways (in 140 characters or less).<\/p>\n","excerpt":"WordPress, how do I love thee? Let me count the ways (in 140 characters or less).","date":"2008-06-04 08:21:24","modified":"2008-06-04 08:21:24","categories":[],"tags":[{"id":80,"slug":"post-formats","title":"Post Formats","description":"","post_count":10}],"author":{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},"comments":[],"attachments":[],"comment_count":0,"comment_status":"closed"},{"id":582,"type":"post","slug":"post-format-test-video","url":"http:\/\/wordpress.test\/2008\/06\/03\/post-format-test-video\/","status":"publish","title":"Post Format Test: Video","title_plain":"Post Format Test: Video","content":"<p><embed src=\"http:\/\/v.wordpress.com\/hrPKeL5t\" type=\"application\/x-shockwave-flash\" width=\"640\" height=\"360\" allowscriptaccess=\"always\" allowfullscreen=\"true\" wmode=\"transparent\"><\/embed><\/p>\n<p>Posted as per the <a href=\"http:\/\/codex.wordpress.org\/Embeds\" target=\"_blank\">instructions in the Codex<\/a>.<\/p>\n","excerpt":"Posted as per the instructions in the Codex.","date":"2008-06-03 08:25:58","modified":"2008-06-03 08:25:58","categories":[],"tags":[{"id":80,"slug":"post-formats","title":"Post Formats","description":"","post_count":10}],"author":{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},"comments":[],"attachments":[],"comment_count":0,"comment_status":"closed"},{"id":587,"type":"post","slug":"post-format-test-audio","url":"http:\/\/wordpress.test\/2008\/06\/02\/post-format-test-audio\/","status":"publish","title":"Post Format Test: Audio","title_plain":"Post Format Test: Audio","content":"<p><a href='http:\/\/wordpress.test\/wp-content\/uploads\/2011\/01\/hayseedrag-thedizzytrio_vbr3.mp3'>Hayseed Rag \u2013 The Dizzy Trio<\/a><\/p>\n","excerpt":"Hayseed Rag \u2013 The Dizzy Trio","date":"2008-06-02 08:36:44","modified":"2008-06-02 08:36:44","categories":[],"tags":[{"id":80,"slug":"post-formats","title":"Post Formats","description":"","post_count":10}],"author":{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},"comments":[],"attachments":[{"id":622,"url":"http:\/\/wordpress.test\/wp-content\/uploads\/2011\/01\/hayseedrag-thedizzytrio_vbr3.mp3","slug":"hayseedrag-thedizzytrio_vbr-2","title":"Hayseed Rag \u2013 The Dizzy Trio","description":"Victor # 19421-B The dizzy trio -novelty fox trot \u2013 Harmonica specialty by Borrah Minevitch \u2013 Harmonica,guitar,banjo, with Jew\u2019s harp and piano \u2013 issue date: May 1924. (<a href=\"http:\/\/www.archive.org\/details\/HayseedRag\">public domain<\/a>)","caption":"Hayseed Rag \u2013 The Dizzy Trio","parent":587,"mime_type":"audio\/mpeg"}],"comment_count":0,"comment_status":"closed"},{"id":494,"type":"post","slug":"if-you-say-it-loud-enough-you%e2%80%99ll-always-sound-precocious-supercalifragilisticexpialidocious","url":"http:\/\/wordpress.test\/2008\/05\/06\/if-you-say-it-loud-enough-you%e2%80%99ll-always-sound-precocious-supercalifragilisticexpialidocious\/","status":"publish","title":"If you say it loud enough, you\u2019ll always sound precocious; Supercalifragilisticexpialidocious!","title_plain":"If you say it loud enough, you\u2019ll always sound precocious; Supercalifragilisticexpialidocious!","content":"<p>A post with an exceptionally long title and single word (supercalifragilisticexpialidocious\u2014it’s the biggest word you ever heard) useful for testing title line heights and potential overflow issues on posts with small title areas. <img src='http:\/\/wordpress.test\/wp-includes\/images\/smilies\/icon_smile.gif' alt=':)' class='wp-smiley' \/> <\/p>\n","excerpt":"A post with an exceptionally long title and single word (supercalifragilisticexpialidocious\u2014it’s the biggest word you ever heard) useful for testing title line heights and potential overflow issues on posts with small title areas.","date":"2008-05-06 12:23:00","modified":"2008-05-06 12:23:00","categories":[],"tags":[],"author":{"id":4,"slug":"ian-stewart","name":"Ian Stewart","first_name":"","last_name":"","nickname":"Ian Stewart","url":"","description":""},"comments":[],"attachments":[],"comment_count":0,"comment_status":"closed"},{"id":134,"type":"post","slug":"this-post-has-no-body","url":"http:\/\/wordpress.test\/2008\/05\/05\/this-post-has-no-body\/","status":"publish","title":"This post has no body","title_plain":"This post has no body","content":"","excerpt":"","dateLine truncated
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
--TEST--
|
||||||
|
core.get_search_posts default
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTTP/Client.php';
|
||||||
|
$http = new HTTP_Client();
|
||||||
|
$http->get('http://wordpress.test/?json=core.get_search_posts&search=wordpress');
|
||||||
|
$response = $http->currentResponse();
|
||||||
|
echo $response['body'];
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
{"status":"ok","count":10,"count_total":22,"pages":3,"posts":[{"id":188,"type":"post","slug":"layout-test","url":"http:\/\/wordpress.test\/2008\/09\/04\/layout-test\/","status":"publish","title":"Layout Test","title_plain":"Layout Test","content":"<p>This is a sticky post!!! Make sure it sticks!<\/p>\n<p>This should then split into other pages with layout, images, HTML tags, and other things.<\/p>\n","excerpt":"This is a sticky post!!! Make sure it sticks! This should then split into other pages with layout, images, HTML tags, and other things.","date":"2008-09-04 23:02:20","modified":"2008-09-04 23:02:20","categories":[{"id":3,"slug":"aciform","title":"aciform","description":"","parent":0,"post_count":2},{"id":9,"slug":"cat-a","title":"Cat A","description":"","parent":0,"post_count":2},{"id":10,"slug":"cat-b","title":"Cat B","description":"","parent":0,"post_count":1},{"id":11,"slug":"cat-c","title":"Cat C","description":"","parent":0,"post_count":1},{"id":41,"slug":"sub","title":"sub","description":"","parent":3,"post_count":1}],"tags":[{"id":93,"slug":"tag1","title":"tag1","description":"","post_count":1},{"id":94,"slug":"tag2","title":"tag2","description":"","post_count":1},{"id":95,"slug":"tag3","title":"tag3","description":"","post_count":1}],"author":{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},"comments":[],"attachments":[],"comment_count":0,"comment_status":"closed"},{"id":358,"type":"post","slug":"readability-test","url":"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/","status":"publish","title":"Readability Test","title_plain":"Readability Test","content":"<p>All children, except one, grow up. They soon know that they will grow up, and the way Wendy knew was this. One day when she was two years old she was playing in a garden, and she plucked another flower and ran with it to her mother. I suppose she must have looked rather delightful, for Mrs. Darling put her hand to her heart and cried, “Oh, why can’t you remain like this for ever!” This was all that passed between them on the subject, but henceforth Wendy knew that she must grow up. You always know after you are two. Two is the beginning of the end.<\/p>\n<p> <a href=\"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/#more-358\" class=\"more-link\">Read more<\/a><\/p>\n","excerpt":"All children, except one, grow up. They soon know that they will grow up, and the way Wendy knew was this. One day when she was two years old she was playing in a garden, and she plucked another flower … <a href=\"http:\/\/wordpress.test\/2008\/09\/05\/readability-test\/\">Continue reading <span class=\"meta-nav\">→<\/span><\/a>","date":"2008-09-05 00:27:25","modified":"2008-09-05 00:27:25","categories":[{"id":9,"slug":"cat-a","title":"Cat A","description":"","parent":0,"post_count":2}],"tags":[{"id":53,"slug":"chattels","title":"chattels","description":"","post_count":2},{"id":82,"slug":"privation","title":"privation","description":"","post_count":2}],"author":{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},"comments":[],"attachments":[],"comment_count":0,"comment_status":"closed"},{"id":128,"type":"post","slug":"images-test","url":"http:\/\/wordpress.test\/2008\/09\/03\/images-test\/","status":"publish","title":"Images Test","title_plain":"Images Test","content":"<h2>Image Alignment Tests: Un-Captioned Images<\/h2>\n<h3 id=\"center-align-no-caption\">Center-align, no caption<\/h3>\n<p>Center-aligned image with no caption, and text before and after. <img src=\"http:\/\/wordpress.test\/wp-content\/uploads\/2010\/08\/test-image-landscape1.jpg\" alt=\"\" title=\"test-image-landscape\" width=\"300\" height=\"199\" class=\"aligncenter size-full wp-image-535\" \/> ALorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed odio nibh, tincidunt adipiscing, pretium nec, tincidunt id, enim. Fusce scelerisque nunc vitae nisl. Quisque quis urna in velit dictum pellentesque. Vivamus a quam. Curabitur eu tortor id turpis tristique adipiscing. Morbi blandit. Maecenas vel est. Nunc aliquam, orci at accumsan commodo, libero nibh euismod augue, a ullamcorper velit dui et purus. Aenean volutpat, ipsum ac imperdiet fermentum, dui dui suscipit arcu, vitae dictum purus diam ac ligula.<\/p>\n<h3 id=\"left-align-no-caption\">Left-align, no caption<\/h3>\n<p>Left-aligned image with no caption, and text before and after. <img src=\"http:\/\/wordpress.test\/wp-content\/uploads\/2010\/08\/test-image-landscape1.jpg\" alt=\"\" title=\"test-image-landscape\" width=\"300\" height=\"199\" class=\"alignleft size-full wp-image-535\" \/> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed odio nibh, tincidunt adipiscing, pretium nec, tincidunt id, enim. Fusce scelerisque nunc vitae nisl. Quisque quis urna in velit dictum pellentesque. Vivamus a quam. Curabitur Line truncated
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
--TEST--
|
||||||
|
core.get_tag_index
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTTP/Client.php';
|
||||||
|
$http = new HTTP_Client();
|
||||||
|
$http->get('http://wordpress.test/?json=core.get_tag_index');
|
||||||
|
$response = $http->currentResponse();
|
||||||
|
echo $response['body'];
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
{"status":"ok","count":40,"tags":[{"id":53,"slug":"chattels","title":"chattels","description":"","post_count":2},{"id":54,"slug":"cienaga","title":"cienaga","description":"","post_count":1},{"id":55,"slug":"claycold","title":"claycold","description":"","post_count":1},{"id":56,"slug":"crushing","title":"crushing","description":"","post_count":1},{"id":58,"slug":"dinarchy","title":"dinarchy","description":"","post_count":1},{"id":59,"slug":"doolie","title":"doolie","description":"","post_count":1},{"id":60,"slug":"energumen","title":"energumen","description":"","post_count":1},{"id":61,"slug":"ephialtes","title":"ephialtes","description":"","post_count":1},{"id":62,"slug":"eudiometer","title":"eudiometer","description":"","post_count":1},{"id":63,"slug":"figuriste","title":"figuriste","description":"","post_count":1},{"id":66,"slug":"habergeon","title":"habergeon","description":"","post_count":1},{"id":67,"slug":"hapless","title":"hapless","description":"","post_count":1},{"id":68,"slug":"hartshorn","title":"hartshorn","description":"","post_count":1},{"id":69,"slug":"hostility-impregnability","title":"hostility impregnability","description":"","post_count":1},{"id":70,"slug":"impropriation","title":"impropriation","description":"","post_count":1},{"id":72,"slug":"knave","title":"knave","description":"","post_count":1},{"id":73,"slug":"misinformed","title":"misinformed","description":"","post_count":1},{"id":74,"slug":"moil","title":"moil","description":"","post_count":1},{"id":75,"slug":"mornful","title":"mornful","description":"","post_count":1},{"id":76,"slug":"outlaw","title":"outlaw","description":"","post_count":1},{"id":77,"slug":"pamphjlet","title":"pamphjlet","description":"","post_count":1},{"id":78,"slug":"pneumatics","title":"pneumatics","description":"","post_count":1},{"id":79,"slug":"portly-portreeve","title":"portly portreeve","description":"","post_count":1},{"id":80,"slug":"post-formats","title":"Post Formats","description":"","post_count":10},{"id":81,"slug":"precipitancy","title":"precipitancy","description":"","post_count":1},{"id":82,"slug":"privation","title":"privation","description":"","post_count":2},{"id":83,"slug":"programme","title":"programme","description":"","post_count":1},{"id":84,"slug":"psychological","title":"psychological","description":"","post_count":1},{"id":85,"slug":"puncher","title":"puncher","description":"","post_count":1},{"id":86,"slug":"ramose","title":"ramose","description":"","post_count":1},{"id":87,"slug":"renegade","title":"renegade","description":"","post_count":1},{"id":88,"slug":"retrocede","title":"retrocede","description":"","post_count":1},{"id":89,"slug":"stagnation-unhorsed","title":"stagnation unhorsed","description":"","post_count":1},{"id":93,"slug":"tag1","title":"tag1","description":"","post_count":1},{"id":94,"slug":"tag2","title":"tag2","description":"","post_count":1},{"id":95,"slug":"tag3","title":"tag3","description":"","post_count":1},{"id":98,"slug":"thunderheaded","title":"thunderheaded","description":"","post_count":1},{"id":99,"slug":"unculpable","title":"unculpable","description":"","post_count":1},{"id":100,"slug":"withered-brandnew","title":"withered brandnew","description":"","post_count":1},{"id":101,"slug":"xanthopsia","title":"xanthopsia","description":"","post_count":1}]}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
--TEST--
|
||||||
|
core.get_tag_posts default
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTTP/Client.php';
|
||||||
|
$http = new HTTP_Client();
|
||||||
|
$http->get('http://wordpress.test/?json=core.get_tag_posts&slug=post-formats');
|
||||||
|
$response = $http->currentResponse();
|
||||||
|
echo $response['body'];
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
{"status":"ok","count":10,"pages":1,"tag":{"id":80,"slug":"post-formats","title":"Post Formats","description":"","post_count":10},"posts":[{"id":555,"type":"post","slug":"post-format-test-gallery","url":"http:\/\/wordpress.test\/2008\/06\/10\/post-format-test-gallery\/","status":"publish","title":"Post Format Test: Gallery","title_plain":"Post Format Test: Gallery","content":"\n\t\t<div id='gallery-1' class='gallery galleryid-555 gallery-columns-3 gallery-size-thumbnail'><dl class='gallery-item'>\n\t\t\t<dt class='gallery-icon'>\n\t\t\t\t<a href='http:\/\/wordpress.test\/2008\/06\/10\/post-format-test-gallery\/canola2\/' title='canola2'><img width=\"150\" height=\"112\" src=\"http:\/\/wordpress.test\/wp-content\/uploads\/2011\/01\/canola21.jpg\" class=\"attachment-thumbnail\" alt=\"canola\" title=\"canola2\" \/><\/a>\n\t\t\t<\/dt><\/dl><dl class='gallery-item'>\n\t\t\t<dt class='gallery-icon'>\n\t\t\t\t<a href='http:\/\/wordpress.test\/2008\/06\/10\/post-format-test-gallery\/dsc20040724_152504_532\/' title='dsc20040724_152504_532'><img width=\"150\" height=\"112\" src=\"http:\/\/wordpress.test\/wp-content\/uploads\/2011\/01\/dsc20040724_152504_5321.jpg\" class=\"attachment-thumbnail\" alt=\"chunk of resinous blackboy husk\" title=\"dsc20040724_152504_532\" \/><\/a>\n\t\t\t<\/dt>\n\t\t\t\t<dd class='wp-caption-text gallery-caption'>\n\t\t\t\tChunk of resinous blackboy husk, Clarkson, Western Australia. This burns like a spinifex log.\n\t\t\t\t<\/dd><\/dl><dl class='gallery-item'>\n\t\t\t<dt class='gallery-icon'>\n\t\t\t\t<a href='http:\/\/wordpress.test\/2008\/06\/10\/post-format-test-gallery\/dsc20050315_145007_132\/' title='dsc20050315_145007_132'><img width=\"150\" height=\"112\" src=\"http:\/\/wordpress.test\/wp-content\/uploads\/2011\/01\/dsc20050315_145007_1321.jpg\" class=\"attachment-thumbnail\" alt=\"dsc20050315_145007_132\" title=\"dsc20050315_145007_132\" \/><\/a>\n\t\t\t<\/dt><\/dl><br style=\"clear: both\" \/><dl class='gallery-item'>\n\t\t\t<dt class='gallery-icon'>\n\t\t\t\t<a href='http:\/\/wordpress.test\/2008\/06\/10\/post-format-test-gallery\/dsc20050604_133440_3421\/' title='dsc20050604_133440_3421'><img width=\"150\" height=\"112\" src=\"http:\/\/wordpress.test\/wp-content\/uploads\/2011\/01\/dsc20050604_133440_34211.jpg\" class=\"attachment-thumbnail\" alt=\"dsc20050604_133440_3421\" title=\"dsc20050604_133440_3421\" \/><\/a>\n\t\t\t<\/dt><\/dl><dl class='gallery-item'>\n\t\t\t<dt class='gallery-icon'>\n\t\t\t\t<a href='http:\/\/wordpress.test\/2008\/06\/10\/post-format-test-gallery\/dsc20050727_091048_222\/' title='dsc20050727_091048_222'><img width=\"150\" height=\"112\" src=\"http:\/\/wordpress.test\/wp-content\/uploads\/2011\/01\/dsc20050727_091048_2221.jpg\" class=\"attachment-thumbnail\" alt=\"dsc20050727_091048_222\" title=\"dsc20050727_091048_222\" \/><\/a>\n\t\t\t<\/dt><\/dl><dl class='gallery-item'>\n\t\t\t<dt class='gallery-icon'>\n\t\t\t\t<a href='http:\/\/wordpress.test\/2008\/06\/10\/post-format-test-gallery\/dsc20050813_115856_52\/' title='dsc20050813_115856_52'><img width=\"150\" height=\"112\" src=\"http:\/\/wordpress.test\/wp-content\/uploads\/2011\/01\/dsc20050813_115856_521.jpg\" class=\"attachment-thumbnail\" alt=\"dsc20050813_115856_52\" title=\"dsc20050813_115856_52\" \/><\/a>\n\t\t\t<\/dt><\/dl><br style=\"clear: both\" \/><dl class='gallery-item'>\n\t\t\t<dt class='gallery-icon'>\n\t\t\t\t<a href='http:\/\/wordpress.test\/2008\/06\/10\/post-format-test-gallery\/dsc20050831_165238_332\/' title='dsc20050831_165238_332'><img width=\"150\" height=\"112\" src=\"http:\/\/wordpress.test\/wp-content\/uploads\/2011\/01\/dsc20050831_165238_3321.jpg\" class=\"attachment-thumbnail\" alt=\"dsc20050831_165238_332\" title=\"dsc20050831_165238_332\" \/><\/a>\n\t\t\t<\/dt><\/dl><dl class='gallery-item'>\n\t\t\t<dt class='gallery-icon'>\n\t\t\t\t<a href='http:\/\/wordpress.test\/2008\/06\/10\/post-format-test-gallery\/dsc20050901_105100_212\/' title='dsc20050901_105100_212'><img width=\"150\" height=\"112\" src=\"http:\/\/wordpress.test\/wp-content\/uploads\/2011\/01\/dsc20050901_105100_2121.jpg\" class=\"attachment-thumbnail\" alt=\"Seed pods on stem, Woodvale\" title=\"dsc20050901_105100_212\" \/><\/a>\n\t\t\t<\/dt>\n\t\t\t\t<dd class='wp-caption-text gallery-caption'>\n\t\t\t\tSeed pods on stem, Woodvale\n\t\t\t\t<\/dd><\/dl>\n\t\t\t<br style='clear: both;' \/>\n\t\t<\/div>\n\n","excerpt":"","date":"2008-06-10 07:24:14","modified":"2008-06-10 07:24:14","categories":[],"tags":[{"id":80,"slug":"post-formats","title":"Post Formats","description":"","post_count":10}],"author":{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},"comments":[],"attachments":[{"id":611,"url":"http:\/\/wordpress.test\/wp-content\/uploads\/2011\/01\/canola21.jpg","slug":"canola2","title":"canola2","description":"","caption":"","parent":555,"mime_type":"image\/jpeg","images":{"full":{"url":"http:\/\/wordpress.test\/wp-coLine truncated
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
--TEST--
|
||||||
|
core.info default
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTTP/Client.php';
|
||||||
|
$http = new HTTP_Client();
|
||||||
|
$http->get('http://wordpress.test/?json=core.info');
|
||||||
|
$response = $http->currentResponse();
|
||||||
|
echo $response['body'];
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
{"status":"ok","json_api_version":"1.0.7","controllers":["core","posts","respond"]}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
--TEST--
|
||||||
|
core.info controller detail
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTTP/Client.php';
|
||||||
|
$http = new HTTP_Client();
|
||||||
|
$http->get('http://wordpress.test/?json=core.info&controller=core');
|
||||||
|
$response = $http->currentResponse();
|
||||||
|
echo $response['body'];
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
{"status":"ok","name":"Core","description":"Basic introspection methods","methods":["info","get_recent_posts","get_post","get_page","get_date_posts","get_category_posts","get_tag_posts","get_author_posts","get_search_results","get_date_index","get_category_index","get_tag_index","get_author_index","get_page_index","get_nonce"]}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
--TEST--
|
||||||
|
core.get_author_index with user-friendly URLs
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTTP/Client.php';
|
||||||
|
$http = new HTTP_Client();
|
||||||
|
$http->get('http://wordpress.test/api/core/get_author_index');
|
||||||
|
$response = $http->currentResponse();
|
||||||
|
echo $response['body'];
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
{"status":"ok","count":2,"authors":[{"id":3,"slug":"chip-bennett","name":"Chip Bennett","first_name":"","last_name":"","nickname":"Chip Bennett","url":"","description":""},{"id":4,"slug":"ian-stewart","name":"Ian Stewart","first_name":"","last_name":"","nickname":"Ian Stewart","url":"","description":""}]}
|
||||||
Reference in new issue
Block a user