JSON API - Version 1.0.6

Version Description

Minor bugfix/improvement release

Download this release

Release Info

Developer dphiffer
Plugin Icon wp plugin JSON API
Version 1.0.6
Comparing to
See all releases

Code changes from version 1.0.5 to 1.0.6

Files changed (4) hide show
  1. controllers/core.php +4 -1
  2. json-api.php +1 -1
  3. readme.txt +15 -3
  4. singletons/response.php +17 -5
controllers/core.php CHANGED
@@ -228,11 +228,14 @@ class JSON_API_Core_Controller {
228
  public function get_page_index() {
229
  global $json_api;
230
  $pages = array();
 
 
231
  $wp_posts = get_posts(array(
232
  'post_type' => 'page',
233
  'post_parent' => 0,
234
  'order' => 'ASC',
235
- 'orderby' => 'menu_order'
 
236
  ));
237
  foreach ($wp_posts as $wp_post) {
238
  $pages[] = new JSON_API_Post($wp_post);
228
  public function get_page_index() {
229
  global $json_api;
230
  $pages = array();
231
+ // Thanks to blinder for the fix!
232
+ $numberposts = empty($json_api->query->count) ? -1 : $json_api->query->count;
233
  $wp_posts = get_posts(array(
234
  'post_type' => 'page',
235
  'post_parent' => 0,
236
  'order' => 'ASC',
237
+ 'orderby' => 'menu_order',
238
+ 'numberposts' => $numberposts
239
  ));
240
  foreach ($wp_posts as $wp_post) {
241
  $pages[] = new JSON_API_Post($wp_post);
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.5
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: 1.0.6
7
  Author: Dan Phiffer
8
  Author URI: http://phiffer.org/
9
  */
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.5
8
 
9
  A RESTful API for WordPress
10
 
@@ -539,7 +539,7 @@ Returns a WordPress nonce value, required to call some data manipulation methods
539
  __Further reading__
540
  To learn more about how nonces are used in WordPress, see [Mark Jaquith's article on the subject](http://markjaquith.wordpress.com/2006/06/02/wordpress-203-nonces/).
541
 
542
- = 2.2. Pages controller methods =
543
 
544
  == Method: create_post ==
545
 
@@ -561,7 +561,7 @@ Creates a new post.
561
  Note: including a file upload field called `attachment` will cause an attachment to be stored with your new post.
562
 
563
 
564
- = 2.3. Respond controller methods =
565
 
566
  == Method: submit_comment ==
567
 
@@ -898,6 +898,7 @@ It is recommended that custom controllers are kept outside of `json-api/controll
898
 
899
  function add_hello_controller($controllers) {
900
  $controllers[] = 'hello';
 
901
  }
902
  add_filter('json_api_controllers', 'add_hello_controller');
903
 
@@ -915,6 +916,14 @@ The following are constants you can define in your `wp-config.php` folder:
915
 
916
  == Changelog ==
917
 
 
 
 
 
 
 
 
 
918
  = 1.0.5 (2010-07-08): =
919
  * Added an check so that `json-api.php` can be moved one level above the `json-api` directory
920
  * Added more documentation about using nonces
@@ -1008,6 +1017,9 @@ The following are constants you can define in your `wp-config.php` folder:
1008
 
1009
  == Upgrade Notice ==
1010
 
 
 
 
1011
  = 1.0.5 =
1012
  Minor improvement release
1013
 
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.6
8
 
9
  A RESTful API for WordPress
10
 
539
  __Further reading__
540
  To learn more about how nonces are used in WordPress, see [Mark Jaquith's article on the subject](http://markjaquith.wordpress.com/2006/06/02/wordpress-203-nonces/).
541
 
542
+ == 2.2. Pages controller methods ==
543
 
544
  == Method: create_post ==
545
 
561
  Note: including a file upload field called `attachment` will cause an attachment to be stored with your new post.
562
 
563
 
564
+ == 2.3. Respond controller methods ==
565
 
566
  == Method: submit_comment ==
567
 
898
 
899
  function add_hello_controller($controllers) {
900
  $controllers[] = 'hello';
901
+ return $controllers;
902
  }
903
  add_filter('json_api_controllers', 'add_hello_controller');
904
 
916
 
917
  == Changelog ==
918
 
919
+ = 1.0.6 (2011-01-13): =
920
+ * Fixed a bug in `exclude` query parameter (big props to ikesyo and archon810)
921
+ * Fix for `get_page_index` that where it only returned 5 pages -- it now responds to `count` query param (props to npavkovic and blinder)
922
+ * Removed `Content-Disposition` header from response (props mimecine, kjwierenga)
923
+ * Fixed an incompatibility issue with Disqus plugin (props joshcanhelp)
924
+ * Fixed a bug where `submit_comment` was resulting in a HTTP 404 status (props @tdweston)
925
+ * Fixed an error in the documentation, external controller example (props jli)
926
+
927
  = 1.0.5 (2010-07-08): =
928
  * Added an check so that `json-api.php` can be moved one level above the `json-api` directory
929
  * Added more documentation about using nonces
1017
 
1018
  == Upgrade Notice ==
1019
 
1020
+ = 1.0.6 =
1021
+ Minor bugfix/improvement release
1022
+
1023
  = 1.0.5 =
1024
  Minor improvement release
1025
 
singletons/response.php CHANGED
@@ -5,13 +5,18 @@ class JSON_API_Response {
5
  function setup() {
6
  global $json_api;
7
  $this->include_values = array();
 
8
  if ($json_api->query->include) {
9
  $this->include_values = explode(',', $json_api->query->include);
10
  }
 
11
  if ($json_api->query->exclude) {
12
- $exclude = explode(',', $json_api->query->exclude);
13
- $this->include_values = array_diff($this->include_values, $exclude);
14
  }
 
 
 
15
  }
16
 
17
  function get_json($data, $status = 'ok') {
@@ -40,10 +45,15 @@ class JSON_API_Response {
40
  }
41
 
42
  function is_value_included($key) {
43
- if (empty($this->include_values)) {
 
44
  return true;
45
  } else {
46
- return in_array($key, $this->include_values);
 
 
 
 
47
  }
48
  }
49
 
@@ -54,6 +64,7 @@ class JSON_API_Response {
54
  if ($json_api->query->dev || !empty($_REQUEST['dev'])) {
55
  // Output the result in a human-redable format
56
  if (!headers_sent()) {
 
57
  header('Content-Type: text/plain; charset: UTF-8', true);
58
  } else {
59
  echo '<pre>';
@@ -77,8 +88,8 @@ class JSON_API_Response {
77
  function output($result) {
78
  $charset = get_option('blog_charset');
79
  if (!headers_sent()) {
 
80
  header("Content-Type: application/json; charset=$charset", true);
81
- header("Content-Disposition: attachment; filename=\"json_api.json\"", true);
82
  }
83
  echo $result;
84
  }
@@ -86,6 +97,7 @@ class JSON_API_Response {
86
  function callback($callback, $result) {
87
  $charset = get_option('blog_charset');
88
  if (!headers_sent()) {
 
89
  header("Content-Type: application/javascript; charset=$charset", true);
90
  }
91
  echo "$callback($result)";
5
  function setup() {
6
  global $json_api;
7
  $this->include_values = array();
8
+ $this->exclude_values = array();
9
  if ($json_api->query->include) {
10
  $this->include_values = explode(',', $json_api->query->include);
11
  }
12
+ // Props to ikesyo for submitting a fix!
13
  if ($json_api->query->exclude) {
14
+ $this->exclude_values = explode(',', $json_api->query->exclude);
15
+ $this->include_values = array_diff($this->include_values, $this->exclude_values);
16
  }
17
+
18
+ // Compatibility with Disqus plugin
19
+ remove_action('loop_end', 'dsq_loop_end');
20
  }
21
 
22
  function get_json($data, $status = 'ok') {
45
  }
46
 
47
  function is_value_included($key) {
48
+ // Props to ikesyo for submitting a fix!
49
+ if (empty($this->include_values) && empty($this->exclude_values)) {
50
  return true;
51
  } else {
52
+ if (empty($this->exclude_values)) {
53
+ return in_array($key, $this->include_values);
54
+ } else {
55
+ return !in_array($key, $this->exclude_values);
56
+ }
57
  }
58
  }
59
 
64
  if ($json_api->query->dev || !empty($_REQUEST['dev'])) {
65
  // Output the result in a human-redable format
66
  if (!headers_sent()) {
67
+ header('HTTP/1.1 200 OK');
68
  header('Content-Type: text/plain; charset: UTF-8', true);
69
  } else {
70
  echo '<pre>';
88
  function output($result) {
89
  $charset = get_option('blog_charset');
90
  if (!headers_sent()) {
91
+ header('HTTP/1.1 200 OK', true);
92
  header("Content-Type: application/json; charset=$charset", true);
 
93
  }
94
  echo $result;
95
  }
97
  function callback($callback, $result) {
98
  $charset = get_option('blog_charset');
99
  if (!headers_sent()) {
100
+ header('HTTP/1.1 200 OK', true);
101
  header("Content-Type: application/javascript; charset=$charset", true);
102
  }
103
  echo "$callback($result)";