Version Description
Minor bugfix release
Download this release
Release Info
Developer | dphiffer |
Plugin | JSON API |
Version | 1.0.2 |
Comparing to | |
See all releases |
Code changes from version 1.0.1 to 1.0.2
- controllers/core.php +2 -2
- controllers/posts.php +2 -3
- controllers/respond.php +2 -3
- json-api.php +25 -7
- readme.txt +51 -12
controllers/core.php
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?php
|
2 |
/*
|
3 |
-
|
4 |
-
|
5 |
*/
|
6 |
|
7 |
class JSON_API_Core_Controller {
|
1 |
<?php
|
2 |
/*
|
3 |
+
Controller name: Core
|
4 |
+
Controller description: Basic introspection methods
|
5 |
*/
|
6 |
|
7 |
class JSON_API_Core_Controller {
|
controllers/posts.php
CHANGED
@@ -1,8 +1,7 @@
|
|
1 |
<?php
|
2 |
/*
|
3 |
-
|
4 |
-
|
5 |
-
URL:
|
6 |
*/
|
7 |
|
8 |
class JSON_API_Posts_Controller {
|
1 |
<?php
|
2 |
/*
|
3 |
+
Controller name: Posts
|
4 |
+
Controller description: Data manipulation methods for posts
|
|
|
5 |
*/
|
6 |
|
7 |
class JSON_API_Posts_Controller {
|
controllers/respond.php
CHANGED
@@ -1,8 +1,7 @@
|
|
1 |
<?php
|
2 |
/*
|
3 |
-
|
4 |
-
|
5 |
-
URL:
|
6 |
*/
|
7 |
|
8 |
class JSON_API_Respond_Controller {
|
1 |
<?php
|
2 |
/*
|
3 |
+
Controller name: Respond
|
4 |
+
Controller description: Comment/trackback submission methods
|
|
|
5 |
*/
|
6 |
|
7 |
class JSON_API_Respond_Controller {
|
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: 1.0.
|
7 |
Author: Dan Phiffer
|
8 |
Author URI: http://phiffer.org/
|
9 |
*/
|
@@ -204,9 +204,21 @@ class JSON_API {
|
|
204 |
|
205 |
foreach ($available_controllers as $controller) {
|
206 |
|
|
|
207 |
$active = in_array($controller, $active_controllers);
|
208 |
$info = $this->controller_info($controller);
|
209 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
210 |
?>
|
211 |
<tr class="<?php echo ($active ? 'active' : 'inactive'); ?>">
|
212 |
<th class="check-column" scope="row">
|
@@ -219,7 +231,7 @@ class JSON_API {
|
|
219 |
|
220 |
if ($active) {
|
221 |
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>';
|
222 |
-
} else {
|
223 |
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>';
|
224 |
}
|
225 |
|
@@ -332,7 +344,8 @@ class JSON_API {
|
|
332 |
$controllers[] = $matches[1];
|
333 |
}
|
334 |
}
|
335 |
-
|
|
|
336 |
}
|
337 |
|
338 |
function controller_is_active($controller) {
|
@@ -358,21 +371,26 @@ class JSON_API {
|
|
358 |
);
|
359 |
if (file_exists($path)) {
|
360 |
$source = file_get_contents($path);
|
361 |
-
if (preg_match('/^\s*
|
362 |
$response['name'] = trim($matches[1]);
|
363 |
}
|
364 |
-
if (preg_match('/^\s*
|
365 |
$response['description'] = trim($matches[1]);
|
366 |
}
|
367 |
-
if (preg_match('/^\s*
|
368 |
$response['docs'] = trim($matches[1]);
|
369 |
}
|
370 |
-
|
|
|
|
|
371 |
$response['methods'] = get_class_methods($class);
|
372 |
return $response;
|
|
|
|
|
373 |
} else {
|
374 |
$this->error("Unknown controller '$controller'.");
|
375 |
}
|
|
|
376 |
}
|
377 |
|
378 |
function controller_class($controller) {
|
3 |
Plugin Name: JSON API
|
4 |
Plugin URI: http://wordpress.org/extend/plugins/json-api/
|
5 |
Description: A RESTful API for WordPress
|
6 |
+
Version: 1.0.2
|
7 |
Author: Dan Phiffer
|
8 |
Author URI: http://phiffer.org/
|
9 |
*/
|
204 |
|
205 |
foreach ($available_controllers as $controller) {
|
206 |
|
207 |
+
$error = false;
|
208 |
$active = in_array($controller, $active_controllers);
|
209 |
$info = $this->controller_info($controller);
|
210 |
|
211 |
+
if (is_string($info)) {
|
212 |
+
$active = false;
|
213 |
+
$error = true;
|
214 |
+
$info = array(
|
215 |
+
'name' => $controller,
|
216 |
+
'description' => "<p><strong>Error</strong>: $info</p>",
|
217 |
+
'methods' => array(),
|
218 |
+
'url' => null
|
219 |
+
);
|
220 |
+
}
|
221 |
+
|
222 |
?>
|
223 |
<tr class="<?php echo ($active ? 'active' : 'inactive'); ?>">
|
224 |
<th class="check-column" scope="row">
|
231 |
|
232 |
if ($active) {
|
233 |
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>';
|
234 |
+
} else if (!$error) {
|
235 |
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>';
|
236 |
}
|
237 |
|
344 |
$controllers[] = $matches[1];
|
345 |
}
|
346 |
}
|
347 |
+
$controllers = apply_filters('json_api_controllers', $controllers);
|
348 |
+
return array_map('strtolower', $controllers);
|
349 |
}
|
350 |
|
351 |
function controller_is_active($controller) {
|
371 |
);
|
372 |
if (file_exists($path)) {
|
373 |
$source = file_get_contents($path);
|
374 |
+
if (preg_match('/^\s*Controller name:(.+)$/im', $source, $matches)) {
|
375 |
$response['name'] = trim($matches[1]);
|
376 |
}
|
377 |
+
if (preg_match('/^\s*Controller description:(.+)$/im', $source, $matches)) {
|
378 |
$response['description'] = trim($matches[1]);
|
379 |
}
|
380 |
+
if (preg_match('/^\s*Controller URI:(.+)$/im', $source, $matches)) {
|
381 |
$response['docs'] = trim($matches[1]);
|
382 |
}
|
383 |
+
if (!class_exists($class)) {
|
384 |
+
require_once($path);
|
385 |
+
}
|
386 |
$response['methods'] = get_class_methods($class);
|
387 |
return $response;
|
388 |
+
} else if (is_admin()) {
|
389 |
+
return "Cannot find controller class '$class' (filtered path: $path).";
|
390 |
} else {
|
391 |
$this->error("Unknown controller '$controller'.");
|
392 |
}
|
393 |
+
return $response;
|
394 |
}
|
395 |
|
396 |
function controller_class($controller) {
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
|
|
4 |
Tags: json, api, ajax, cms, admin, integration, moma
|
5 |
Requires at least: 2.8
|
6 |
Tested up to: 3.0
|
7 |
-
Stable tag: 1.0.
|
8 |
|
9 |
A RESTful API for WordPress
|
10 |
|
@@ -42,7 +42,7 @@ See the [Other Notes](http://wordpress.org/extend/plugins/json-api/other_notes/)
|
|
42 |
3. Request arguments
|
43 |
3.1. Output-modifying arguments
|
44 |
3.2. Content-modifying arguments
|
45 |
-
3.3. Using
|
46 |
4. Response objects
|
47 |
4.1. Post response object
|
48 |
4.2. Category response object
|
@@ -616,15 +616,12 @@ These arguments are available to modify all introspection methods:
|
|
616 |
* `comment_count`
|
617 |
* `meta_key`, `meta_value`, `meta_compare` - Retrieve posts (or Pages) based on a custom field key or value.
|
618 |
|
619 |
-
== 3.3. Using
|
620 |
-
|
621 |
-
__Additional arguments__
|
622 |
-
JSON API is based on the same rules as the [`query_posts` template tag](http://codex.wordpress.org/Template_Tags/query_posts). Any query arguments that can be used to augment a call to `query_posts` can also be passed as a URL query variable to achieve the same results.
|
623 |
|
624 |
__About `include`/`exclude` arguments__
|
625 |
By default you get all values included with each post object. Specify a list of `include` values will cause the post object to filter out the values absent from the list. Specifying `exclude` causes post objects to include all values except the fields you list. For example, the query `exclude=comments` includes everything *except* the comments.
|
626 |
|
627 |
-
__About the `redirect` argument__
|
628 |
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.
|
629 |
|
630 |
For example calling an API method with `redirect` set to `http://www.example.com/foo` will result in a redirection to one of the following:
|
@@ -753,13 +750,16 @@ If you your controller file in the `json-api/controllers` folder JSON API will f
|
|
753 |
|
754 |
= Example =
|
755 |
|
756 |
-
//
|
757 |
-
add_filter('
|
758 |
|
759 |
-
function
|
760 |
-
return '/path/to/
|
761 |
}
|
762 |
|
|
|
|
|
|
|
763 |
== Filter: json_api_encode ==
|
764 |
|
765 |
This is called just before the output is encoded into JSON format. The value passed will always be an associative array, according to the format described in each method's documentation. Those items described in the *Response objects* section are passed as PHP objects, not associative arrays.
|
@@ -845,12 +845,48 @@ Now append the `name` query var to the method call: `http://www.example.org/api/
|
|
845 |
"message": "Hello, Alice"
|
846 |
}
|
847 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
848 |
|
849 |
== Changelog ==
|
850 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
851 |
= 1.0.1 (2010-07-01): =
|
852 |
* Fixed some typos in readme.txt
|
853 |
-
* Expanded developer documentation in readme.txt
|
854 |
* Switched `get_tag_posts` to query on tag instead of tag_id (maybe a WordPress issue?)
|
855 |
|
856 |
= 1.0 (2010-06-29): =
|
@@ -918,6 +954,9 @@ Now append the `name` query var to the method call: `http://www.example.org/api/
|
|
918 |
|
919 |
== Upgrade Notice ==
|
920 |
|
|
|
|
|
|
|
921 |
= 1.0.1 =
|
922 |
Bugfix release, possibly stemming from a bug in WordPress 3.0
|
923 |
|
4 |
Tags: json, api, ajax, cms, admin, integration, moma
|
5 |
Requires at least: 2.8
|
6 |
Tested up to: 3.0
|
7 |
+
Stable tag: 1.0.2
|
8 |
|
9 |
A RESTful API for WordPress
|
10 |
|
42 |
3. Request arguments
|
43 |
3.1. Output-modifying arguments
|
44 |
3.2. Content-modifying arguments
|
45 |
+
3.3. Using include/exclude and redirects
|
46 |
4. Response objects
|
47 |
4.1. Post response object
|
48 |
4.2. Category response object
|
616 |
* `comment_count`
|
617 |
* `meta_key`, `meta_value`, `meta_compare` - Retrieve posts (or Pages) based on a custom field key or value.
|
618 |
|
619 |
+
== 3.3. Using include/exclude and redirects ==
|
|
|
|
|
|
|
620 |
|
621 |
__About `include`/`exclude` arguments__
|
622 |
By default you get all values included with each post object. Specify a list of `include` values will cause the post object to filter out the values absent from the list. Specifying `exclude` causes post objects to include all values except the fields you list. For example, the query `exclude=comments` includes everything *except* the comments.
|
623 |
|
624 |
+
__About the `redirect` argument__
|
625 |
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.
|
626 |
|
627 |
For example calling an API method with `redirect` set to `http://www.example.com/foo` will result in a redirection to one of the following:
|
750 |
|
751 |
= Example =
|
752 |
|
753 |
+
// Register the source file for JSON_API_Widgets_Controller
|
754 |
+
add_filter('json_api_widgets_controller_path', 'widgets_controller_path');
|
755 |
|
756 |
+
function widgets_controller_path($default_path) {
|
757 |
+
return '/path/to/widgets.php';
|
758 |
}
|
759 |
|
760 |
+
__Capitalization__
|
761 |
+
Your filter hook must be all-lowercase to work correctly. The above example would fail with the filter `json_api_Widgets_Controller_path`, even if that's how the class is capitalized in the PHP source.
|
762 |
+
|
763 |
== Filter: json_api_encode ==
|
764 |
|
765 |
This is called just before the output is encoded into JSON format. The value passed will always be an associative array, according to the format described in each method's documentation. Those items described in the *Response objects* section are passed as PHP objects, not associative arrays.
|
845 |
"message": "Hello, Alice"
|
846 |
}
|
847 |
|
848 |
+
= Introspector and data models =
|
849 |
+
|
850 |
+
Your controller can use any of the [existing WordPress functions](http://codex.wordpress.org/Function_Reference) to collect data, but JSON API also includes an introspector that wraps data in objects defined in the `json-api/models` directory. These are the same data models described in *Section 4: Response objects*.
|
851 |
+
|
852 |
+
Here is an example of how you might use the introspector:
|
853 |
+
|
854 |
+
// Retrieve posts based on custom field key/value pair
|
855 |
+
public function get_custom_posts() {
|
856 |
+
global $json_api;
|
857 |
+
|
858 |
+
// Make sure we have key/value query vars
|
859 |
+
if (!$json_api->query->key || !$json_api->query->value) {
|
860 |
+
$json_api->error("Include a 'key' and 'value' query var.");
|
861 |
+
}
|
862 |
+
|
863 |
+
// See also: http://codex.wordpress.org/Template_Tags/query_posts
|
864 |
+
$posts = $json_api->introspector->get_posts(array(
|
865 |
+
'meta_key' => $json_api->query->key,
|
866 |
+
'meta_value' => $json_api->query->value
|
867 |
+
));
|
868 |
+
|
869 |
+
return array(
|
870 |
+
'key' => $key,
|
871 |
+
'value' => $value,
|
872 |
+
'posts' => $posts
|
873 |
+
);
|
874 |
+
}
|
875 |
+
|
876 |
|
877 |
== Changelog ==
|
878 |
|
879 |
+
= 1.0.2 (2007-07-02): =
|
880 |
+
* Removed an inaccurate section from readme.txt about supporting `query_posts` arguments
|
881 |
+
* Changed controller info block format to use "Controller name" and "Controller description"
|
882 |
+
* Made admin page more robust about handling errors loading controllers
|
883 |
+
* Changed `JSON_API::get_controllers` method to lowercase all entries
|
884 |
+
* Added introspector section to developer documentation
|
885 |
+
* Fixed incorrect example for `json_api_[controller]_controller_path`
|
886 |
+
* Thanks to Tim Nash for early feedback on writing external controllers
|
887 |
+
|
888 |
= 1.0.1 (2010-07-01): =
|
889 |
* Fixed some typos in readme.txt
|
|
|
890 |
* Switched `get_tag_posts` to query on tag instead of tag_id (maybe a WordPress issue?)
|
891 |
|
892 |
= 1.0 (2010-06-29): =
|
954 |
|
955 |
== Upgrade Notice ==
|
956 |
|
957 |
+
= 1.0.2 =
|
958 |
+
Minor bugfix release
|
959 |
+
|
960 |
= 1.0.1 =
|
961 |
Bugfix release, possibly stemming from a bug in WordPress 3.0
|
962 |
|