Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade to be Version 1.1.1 #15

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
tests/*.log
tests/*.diff
tests/*.exp
tests/*.out
tests/*.php
53 changes: 29 additions & 24 deletions controllers/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,30 @@ public function get_recent_posts() {
return $this->posts_result($posts);
}

public function get_posts() {
global $json_api;
$url = parse_url($_SERVER['REQUEST_URI']);
$defaults = array(
'ignore_sticky_posts' => true
);
$query = wp_parse_args($url['query']);
unset($query['json']);
unset($query['post_status']);
$query = array_merge($defaults, $query);
$posts = $json_api->introspector->get_posts($query);
$result = $this->posts_result($posts);
$result['query'] = $query;
return $result;
}

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];
$post = $json_api->introspector->get_current_post();
if ($post) {
$previous = get_adjacent_post(false, '', true);
$next = get_adjacent_post(false, '', false);
$post = new JSON_API_Post($post);
$response = array(
'post' => $post
'post' => new JSON_API_Post($post)
);
if ($previous) {
$response['previous_url'] = get_permalink($previous->ID);
Expand Down Expand Up @@ -211,7 +208,13 @@ public function get_date_index() {

public function get_category_index() {
global $json_api;
$categories = $json_api->introspector->get_categories();
$args = null;
if (!empty($json_api->query->parent)) {
$args = array(
'parent' => $json_api->query->parent
);
}
$categories = $json_api->introspector->get_categories($args);
return array(
'count' => count($categories),
'categories' => $categories
Expand Down Expand Up @@ -239,10 +242,12 @@ public function get_author_index() {
public function get_page_index() {
global $json_api;
$pages = array();
$post_type = $json_api->query->post_type ? $json_api->query->post_type : 'page';

// 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_type' => $post_type,
'post_parent' => 0,
'order' => 'ASC',
'orderby' => 'menu_order',
Expand Down
Loading