Skip to content
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
60 changes: 40 additions & 20 deletions controllers/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

class JSON_API_Core_Controller {

public function info() {
global $json_api;
$php = '';
Expand Down Expand Up @@ -35,13 +35,13 @@ public function info() {
);
}
}

public function get_recent_posts() {
global $json_api;
$posts = $json_api->introspector->get_posts();
return $this->posts_result($posts);
}

public function get_post() {
global $json_api, $post;
extract($json_api->query->get(array('id', 'slug', 'post_id', 'post_slug')));
Expand Down Expand Up @@ -102,7 +102,7 @@ public function get_page() {
} else {
$json_api->error("Include 'id' or 'slug' var in your request.");
}

// Workaround for https://core.trac.wordpress.org/ticket/12647
if (empty($posts)) {
$url = $_SERVER['REQUEST_URI'];
Expand All @@ -117,7 +117,7 @@ public function get_page() {
}
$posts = $json_api->introspector->get_posts(array('pagename' => $path));
}

if (count($posts) == 1) {
if (!empty($children)) {
$json_api->introspector->attach_child_posts($posts[0]);
Expand All @@ -129,7 +129,7 @@ public function get_page() {
$json_api->error("Not found.");
}
}

public function get_date_posts() {
global $json_api;
if ($json_api->query->date) {
Expand All @@ -150,7 +150,7 @@ public function get_date_posts() {
}
return $this->posts_result($posts);
}

public function get_category_posts() {
global $json_api;
$category = $json_api->introspector->get_current_category();
Expand All @@ -162,7 +162,7 @@ public function get_category_posts() {
));
return $this->posts_object_result($posts, $category);
}

public function get_tag_posts() {
global $json_api;
$tag = $json_api->introspector->get_current_tag();
Expand All @@ -174,7 +174,7 @@ public function get_tag_posts() {
));
return $this->posts_object_result($posts, $tag);
}

public function get_author_posts() {
global $json_api;
$author = $json_api->introspector->get_current_author();
Expand All @@ -186,7 +186,7 @@ public function get_author_posts() {
));
return $this->posts_object_result($posts, $author);
}

public function get_search_results() {
global $json_api;
if ($json_api->query->search) {
Expand All @@ -198,7 +198,7 @@ public function get_search_results() {
}
return $this->posts_result($posts);
}

public function get_date_index() {
global $json_api;
$permalinks = $json_api->introspector->get_date_archive_permalinks();
Expand All @@ -208,7 +208,7 @@ public function get_date_index() {
'tree' => $tree
);
}

public function get_category_index() {
global $json_api;
$categories = $json_api->introspector->get_categories();
Expand All @@ -217,7 +217,7 @@ public function get_category_index() {
'categories' => $categories
);
}

public function get_tag_index() {
global $json_api;
$tags = $json_api->introspector->get_tags();
Expand All @@ -226,7 +226,7 @@ public function get_tag_index() {
'tags' => $tags
);
}

public function get_author_index() {
global $json_api;
$authors = $json_api->introspector->get_authors();
Expand All @@ -235,7 +235,7 @@ public function get_author_index() {
'authors' => array_values($authors)
);
}

public function get_page_index() {
global $json_api;
$pages = array();
Expand All @@ -258,7 +258,27 @@ public function get_page_index() {
'pages' => $pages
);
}


public function get_menu() {

global $json_api;
$menu = $json_api->introspector->get_menu();
return array(
'menu' => $menu
);

}

public function get_list_menu() {

global $json_api;
$menu = $json_api->introspector->get_list_menu();
return array(
'menus' => $menu
);

}

public function get_nonce() {
global $json_api;
extract($json_api->query->get(array('controller', 'method')));
Expand All @@ -281,7 +301,7 @@ public function get_nonce() {
$json_api->error("Include 'controller' and 'method' vars in your request.");
}
}

protected function get_object_posts($object, $id_var, $slug_var) {
global $json_api;
$object_id = "{$type}_id";
Expand All @@ -306,7 +326,7 @@ protected function get_object_posts($object, $id_var, $slug_var) {
}
return $posts;
}

protected function posts_result($posts) {
global $wp_query;
return array(
Expand All @@ -316,7 +336,7 @@ protected function posts_result($posts) {
'posts' => $posts
);
}

protected function posts_object_result($posts, $object) {
global $wp_query;
// Convert something like "JSON_API_Category" into "category"
Expand All @@ -328,7 +348,7 @@ protected function posts_object_result($posts, $object) {
'posts' => $posts
);
}

}

?>
Loading