@@ -42,33 +42,30 @@ public function get_recent_posts() {
4242 return $ this ->posts_result ($ posts );
4343 }
4444
45+ public function get_posts () {
46+ global $ json_api ;
47+ $ url = parse_url ($ _SERVER ['REQUEST_URI ' ]);
48+ $ defaults = array (
49+ 'ignore_sticky_posts ' => true
50+ );
51+ $ query = wp_parse_args ($ url ['query ' ]);
52+ unset($ query ['json ' ]);
53+ unset($ query ['post_status ' ]);
54+ $ query = array_merge ($ defaults , $ query );
55+ $ posts = $ json_api ->introspector ->get_posts ($ query );
56+ $ result = $ this ->posts_result ($ posts );
57+ $ result ['query ' ] = $ query ;
58+ return $ result ;
59+ }
60+
4561 public function get_post () {
4662 global $ json_api , $ post ;
47- extract ($ json_api ->query ->get (array ('id ' , 'slug ' , 'post_id ' , 'post_slug ' )));
48- if ($ id || $ post_id ) {
49- if (!$ id ) {
50- $ id = $ post_id ;
51- }
52- $ posts = $ json_api ->introspector ->get_posts (array (
53- 'p ' => $ id
54- ), true );
55- } else if ($ slug || $ post_slug ) {
56- if (!$ slug ) {
57- $ slug = $ post_slug ;
58- }
59- $ posts = $ json_api ->introspector ->get_posts (array (
60- 'name ' => $ slug
61- ), true );
62- } else {
63- $ json_api ->error ("Include 'id' or 'slug' var in your request. " );
64- }
65- if (count ($ posts ) == 1 ) {
66- $ post = $ posts [0 ];
63+ $ post = $ json_api ->introspector ->get_current_post ();
64+ if ($ post ) {
6765 $ previous = get_adjacent_post (false , '' , true );
6866 $ next = get_adjacent_post (false , '' , false );
69- $ post = new JSON_API_Post ($ post );
7067 $ response = array (
71- 'post ' => $ post
68+ 'post ' => new JSON_API_Post ( $ post)
7269 );
7370 if ($ previous ) {
7471 $ response ['previous_url ' ] = get_permalink ($ previous ->ID );
@@ -211,7 +208,13 @@ public function get_date_index() {
211208
212209 public function get_category_index () {
213210 global $ json_api ;
214- $ categories = $ json_api ->introspector ->get_categories ();
211+ $ args = null ;
212+ if (!empty ($ json_api ->query ->parent )) {
213+ $ args = array (
214+ 'parent ' => $ json_api ->query ->parent
215+ );
216+ }
217+ $ categories = $ json_api ->introspector ->get_categories ($ args );
215218 return array (
216219 'count ' => count ($ categories ),
217220 'categories ' => $ categories
@@ -239,10 +242,12 @@ public function get_author_index() {
239242 public function get_page_index () {
240243 global $ json_api ;
241244 $ pages = array ();
245+ $ post_type = $ json_api ->query ->post_type ? $ json_api ->query ->post_type : 'page ' ;
246+
242247 // Thanks to blinder for the fix!
243248 $ numberposts = empty ($ json_api ->query ->count ) ? -1 : $ json_api ->query ->count ;
244249 $ wp_posts = get_posts (array (
245- 'post_type ' => ' page ' ,
250+ 'post_type ' => $ post_type ,
246251 'post_parent ' => 0 ,
247252 'order ' => 'ASC ' ,
248253 'orderby ' => 'menu_order ' ,
0 commit comments