Version Description
(2010-01-18): = * Added an attachment model and instance variable for post objects
Download this release
Release Info
Developer | dphiffer |
Plugin | JSON API |
Version | 0.8 |
Comparing to | |
See all releases |
Code changes from version 0.7.3 to 0.8
- json-api.php +1 -1
- models/attachment.php +53 -0
- models/post.php +9 -0
- readme.txt +23 -2
- singletons/controller.php +1 -0
- singletons/introspector.php +11 -0
json-api.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: JSON API
|
4 |
Plugin URI: http://wordpress.org/extend/plugins/json-api/
|
5 |
Description: A RESTful API for WordPress
|
6 |
-
Version: 0.
|
7 |
Author: Dan Phiffer
|
8 |
Author URI: http://phiffer.org/
|
9 |
*/
|
3 |
Plugin Name: JSON API
|
4 |
Plugin URI: http://wordpress.org/extend/plugins/json-api/
|
5 |
Description: A RESTful API for WordPress
|
6 |
+
Version: 0.8
|
7 |
Author: Dan Phiffer
|
8 |
Author URI: http://phiffer.org/
|
9 |
*/
|
models/attachment.php
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class JSON_API_Attachment {
|
4 |
+
|
5 |
+
var $id; // Integer
|
6 |
+
var $url; // String
|
7 |
+
var $slug; // String
|
8 |
+
var $title; // String
|
9 |
+
var $description; // String
|
10 |
+
var $caption; // String
|
11 |
+
var $parent; // Integer
|
12 |
+
var $mime_type; // String
|
13 |
+
|
14 |
+
function JSON_API_Attachment($wp_attachment = null) {
|
15 |
+
if ($wp_attachment) {
|
16 |
+
$this->import_wp_object($wp_attachment);
|
17 |
+
if ($this->is_image()) {
|
18 |
+
$this->query_images();
|
19 |
+
}
|
20 |
+
}
|
21 |
+
}
|
22 |
+
|
23 |
+
function import_wp_object($wp_attachment) {
|
24 |
+
$this->id = (int) $wp_attachment->ID;
|
25 |
+
$this->url = $wp_attachment->guid;
|
26 |
+
$this->slug = $wp_attachment->post_name;
|
27 |
+
$this->title = $wp_attachment->post_title;
|
28 |
+
$this->description = $wp_attachment->post_content;
|
29 |
+
$this->caption = $wp_attachment->post_excerpt;
|
30 |
+
$this->parent = (int) $wp_attachment->post_parent;
|
31 |
+
$this->mime_type = $wp_attachment->post_mime_type;
|
32 |
+
}
|
33 |
+
|
34 |
+
function is_image() {
|
35 |
+
return (substr($this->mime_type, 0, 5) == 'image');
|
36 |
+
}
|
37 |
+
|
38 |
+
function query_images() {
|
39 |
+
$sizes = array('thumbnail', 'medium', 'large', 'full');
|
40 |
+
$this->images = array();
|
41 |
+
foreach ($sizes as $size) {
|
42 |
+
list($url, $width, $height) = wp_get_attachment_image_src($this->id, $size);
|
43 |
+
$this->images[$size] = (object) array(
|
44 |
+
'url' => $url,
|
45 |
+
'width' => $width,
|
46 |
+
'height' => $height
|
47 |
+
);
|
48 |
+
}
|
49 |
+
}
|
50 |
+
|
51 |
+
}
|
52 |
+
|
53 |
+
?>
|
models/post.php
CHANGED
@@ -18,6 +18,7 @@ class JSON_API_Post {
|
|
18 |
var $tags; // Array of objects
|
19 |
var $author; // Object
|
20 |
var $comments; // Array of objects
|
|
|
21 |
var $comment_count; // Integer
|
22 |
var $comment_status; // String ("open" or "closed")
|
23 |
var $custom_fields; // Object (included by using custom_fields query var)
|
@@ -38,6 +39,7 @@ class JSON_API_Post {
|
|
38 |
$this->set_tags_value();
|
39 |
$this->set_author_value();
|
40 |
$this->set_comments_value();
|
|
|
41 |
$this->set_value('comment_count', (int) $post->comment_count);
|
42 |
$this->set_value('comment_status', $post->comment_status);
|
43 |
$this->set_custom_fields_value();
|
@@ -105,6 +107,13 @@ class JSON_API_Post {
|
|
105 |
}
|
106 |
}
|
107 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
function set_custom_fields_value() {
|
109 |
global $json_api;
|
110 |
if ($json_api->include_value('custom_fields') &&
|
18 |
var $tags; // Array of objects
|
19 |
var $author; // Object
|
20 |
var $comments; // Array of objects
|
21 |
+
var $attachments; // Array of objects
|
22 |
var $comment_count; // Integer
|
23 |
var $comment_status; // String ("open" or "closed")
|
24 |
var $custom_fields; // Object (included by using custom_fields query var)
|
39 |
$this->set_tags_value();
|
40 |
$this->set_author_value();
|
41 |
$this->set_comments_value();
|
42 |
+
$this->set_attachments_value();
|
43 |
$this->set_value('comment_count', (int) $post->comment_count);
|
44 |
$this->set_value('comment_status', $post->comment_status);
|
45 |
$this->set_custom_fields_value();
|
107 |
}
|
108 |
}
|
109 |
|
110 |
+
function set_attachments_value() {
|
111 |
+
global $json_api;
|
112 |
+
if ($json_api->include_value('attachments')) {
|
113 |
+
$this->attachments = $json_api->introspector->get_attachments($this->id);
|
114 |
+
}
|
115 |
+
}
|
116 |
+
|
117 |
function set_custom_fields_value() {
|
118 |
global $json_api;
|
119 |
if ($json_api->include_value('custom_fields') &&
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: dphiffer
|
|
3 |
Tags: json, api, ajax, cms, admin, integration, moma
|
4 |
Requires at least: 2.8
|
5 |
Tested up to: 2.9
|
6 |
-
Stable tag: 0.
|
7 |
|
8 |
A RESTful API for WordPress
|
9 |
|
@@ -162,6 +162,7 @@ Developers familiar with WordPress may notice that many names for properties and
|
|
162 |
* `tags` - Array of tag objects
|
163 |
* `author` Author object
|
164 |
* `comments` - Array of comment objects
|
|
|
165 |
* `comment_count` - Integer
|
166 |
* `comment_status` - String (`"open"` or `"closed"`)
|
167 |
* `custom_fields` - Object (included by setting the `custom_fields` argument to a comma-separated list of custom field names)
|
@@ -196,7 +197,7 @@ Developers familiar with WordPress may notice that many names for properties and
|
|
196 |
|
197 |
Note: You can include additional values by setting the `author_meta` argument to a comma-separated list of metadata fields.
|
198 |
|
199 |
-
|
200 |
|
201 |
* `id` - Integer
|
202 |
* `name` - String
|
@@ -206,6 +207,18 @@ Note: You can include additional values by setting the `author_meta` argument to
|
|
206 |
* `parent` - Integer
|
207 |
* `author` - Object (only set if the comment author was registered & logged in)
|
208 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
209 |
== Redirects ==
|
210 |
|
211 |
The `redirect` response style is useful for when you need the user's browser to make a request directly rather than making proxy requests using a tool like cURL. Setting a `redirect` argument causes the user's browser to redirect back to the specified URL instead of returning a JSON object. The resulting `status` value is included as an extra query variable.
|
@@ -559,6 +572,9 @@ Submits a comment to a WordPress post.
|
|
559 |
|
560 |
== Changelog ==
|
561 |
|
|
|
|
|
|
|
562 |
= 0.7.3 (2010-01-15): =
|
563 |
* Added a `count` request parameter to control the number of posts returned
|
564 |
|
@@ -579,3 +595,8 @@ Submits a comment to a WordPress post.
|
|
579 |
|
580 |
= 0.5 (2009-11-17): =
|
581 |
* Initial Public Release
|
|
|
|
|
|
|
|
|
|
3 |
Tags: json, api, ajax, cms, admin, integration, moma
|
4 |
Requires at least: 2.8
|
5 |
Tested up to: 2.9
|
6 |
+
Stable tag: 0.8
|
7 |
|
8 |
A RESTful API for WordPress
|
9 |
|
162 |
* `tags` - Array of tag objects
|
163 |
* `author` Author object
|
164 |
* `comments` - Array of comment objects
|
165 |
+
* `attachments` - Array of attachment objects
|
166 |
* `comment_count` - Integer
|
167 |
* `comment_status` - String (`"open"` or `"closed"`)
|
168 |
* `custom_fields` - Object (included by setting the `custom_fields` argument to a comma-separated list of custom field names)
|
197 |
|
198 |
Note: You can include additional values by setting the `author_meta` argument to a comma-separated list of metadata fields.
|
199 |
|
200 |
+
= Comment response object =
|
201 |
|
202 |
* `id` - Integer
|
203 |
* `name` - String
|
207 |
* `parent` - Integer
|
208 |
* `author` - Object (only set if the comment author was registered & logged in)
|
209 |
|
210 |
+
= Attachment response object =
|
211 |
+
|
212 |
+
* `id` - Integer
|
213 |
+
* `url` - String
|
214 |
+
* `slug` - String
|
215 |
+
* `title` - String
|
216 |
+
* `description` - String
|
217 |
+
* `caption` - String
|
218 |
+
* `parent` - Integer
|
219 |
+
* `mime_type` - String
|
220 |
+
* `images` - Object with values `thumbnail`, `medium`, `large`, `full`, each of which are objects with values `url`, `width` and `height` (only set if the attachment is an image)
|
221 |
+
|
222 |
== Redirects ==
|
223 |
|
224 |
The `redirect` response style is useful for when you need the user's browser to make a request directly rather than making proxy requests using a tool like cURL. Setting a `redirect` argument causes the user's browser to redirect back to the specified URL instead of returning a JSON object. The resulting `status` value is included as an extra query variable.
|
572 |
|
573 |
== Changelog ==
|
574 |
|
575 |
+
= 0.8 (2010-01-18): =
|
576 |
+
* Added an attachment model and instance variable for post objects
|
577 |
+
|
578 |
= 0.7.3 (2010-01-15): =
|
579 |
* Added a `count` request parameter to control the number of posts returned
|
580 |
|
595 |
|
596 |
= 0.5 (2009-11-17): =
|
597 |
* Initial Public Release
|
598 |
+
|
599 |
+
== Upgrade Notice ==
|
600 |
+
|
601 |
+
= 0.8 =
|
602 |
+
Added what may be the last introspection feature: post attachments. You can now see images and other media that have been added to posts.
|
singletons/controller.php
CHANGED
@@ -45,6 +45,7 @@ class JSON_API_Controller {
|
|
45 |
require_once "$json_api_dir/models/category.php";
|
46 |
require_once "$json_api_dir/models/tag.php";
|
47 |
require_once "$json_api_dir/models/author.php";
|
|
|
48 |
}
|
49 |
|
50 |
function error($message, $status = 'error') {
|
45 |
require_once "$json_api_dir/models/category.php";
|
46 |
require_once "$json_api_dir/models/tag.php";
|
47 |
require_once "$json_api_dir/models/author.php";
|
48 |
+
require_once "$json_api_dir/models/attachment.php";
|
49 |
}
|
50 |
|
51 |
function error($message, $status = 'error') {
|
singletons/introspector.php
CHANGED
@@ -191,6 +191,17 @@ class JSON_API_Introspector {
|
|
191 |
return $comments;
|
192 |
}
|
193 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
194 |
}
|
195 |
|
196 |
?>
|
191 |
return $comments;
|
192 |
}
|
193 |
|
194 |
+
function get_attachments($post_id) {
|
195 |
+
$wp_attachments = get_children("post_type=attachment&post_parent=$post_id");
|
196 |
+
$attachments = array();
|
197 |
+
if (!empty($wp_attachments)) {
|
198 |
+
foreach ($wp_attachments as $wp_attachment) {
|
199 |
+
$attachments[] = new JSON_API_Attachment($wp_attachment);
|
200 |
+
}
|
201 |
+
}
|
202 |
+
return $attachments;
|
203 |
+
}
|
204 |
+
|
205 |
}
|
206 |
|
207 |
?>
|