Merge branch 'master' of github.com:dignajar/bludit

This commit is contained in:
dignajar 2016-12-01 20:51:57 -03:00
commit 0dc4dbdebf
3 changed files with 52 additions and 34 deletions

View File

@ -3,7 +3,7 @@
// Load plugins rules // Load plugins rules
include(PATH_RULES.'60.plugins.php'); include(PATH_RULES.'60.plugins.php');
// Plugins before rules loaded, except plugins rules // Plugins before rules loaded
Theme::plugins('beforeRulesLoad'); Theme::plugins('beforeRulesLoad');
// Load rules // Load rules

View File

@ -143,42 +143,47 @@ class pluginAPI extends Plugin {
} }
if( $inputs['token']!=$this->getDbField('token') ) { if( $inputs['token']!=$this->getDbField('token') ) {
return false; $this->response(array(
'status'=>'1',
'message'=>'Invalid token.'
));
} }
} }
// Default JSON
$json = json_encode(array(
'status'=>'0', // 0 = ok, 1 = error
'bludit'=>'Bludit API plugin',
'message'=>'Missing parameters, check the URL.'
));
// /api/posts // /api/posts
if( ($method==='GET') && ($parameters[0]==='posts') && empty($parameters[1]) ) { if( ($method==='GET') && ($parameters[0]==='posts') && empty($parameters[1]) ) {
$json = $this->getAllPosts(); $data = $this->getAllPosts();
$this->response($data);
} }
// /api/pages // /api/pages
elseif( ($method==='GET') && ($parameters[0]==='pages') && empty($parameters[1]) ) { elseif( ($method==='GET') && ($parameters[0]==='pages') && empty($parameters[1]) ) {
$json = $this->getAllPages(); $data = $this->getAllPages();
$this->response($data);
} }
// /api/posts/{slug} // /api/posts/{slug}
elseif( ($method==='GET') && ($parameters[0]==='posts') && !empty($parameters[1]) ) { elseif( ($method==='GET') && ($parameters[0]==='posts') && !empty($parameters[1]) ) {
$json = $this->getPost($key); $data = $this->getPost($parameters[1]);
$this->response($data);
} }
// /api/pages/{slug} // /api/pages/{slug}
elseif( ($method==='GET') && ($parameters[0]==='pages') && !empty($parameters[1]) ) { elseif( ($method==='GET') && ($parameters[0]==='pages') && !empty($parameters[1]) ) {
$json = $this->getPage($key); $data = $this->getPage($parameters[1]);
$this->response($data);
} }
// Print the JSON
header('Content-Type: application/json');
exit($json);
} }
// FUNCTIONS // FUNCTIONS
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
private function response($data=array())
{
$json = json_encode($data);
header('Content-Type: application/json');
exit($json);
}
private function ping() private function ping()
{ {
if($this->getDbField('ping')) { if($this->getDbField('ping')) {
@ -223,27 +228,33 @@ class pluginAPI extends Plugin {
$Post = buildPost($key); $Post = buildPost($key);
if(!$Post) { if(!$Post) {
return json_encode(array( return array(
'status'=>'0', 'status'=>'1',
'bludit'=>'Bludit API plugin', 'message'=>'Post not found.'
'message'=>'The post doesn\'t exist' );
));
} }
return $Post->json(); $data = $Post->json(true);
$data['status'] = '0';
$data['message'] = '';
return $data;
} }
private function getAllPosts() private function getAllPosts()
{ {
$posts = buildPostsForPage(0, $this->getDbField('showAllAmount'), true, false); $posts = buildPostsForPage(0, $this->getDbField('showAllAmount'), true, false);
$tmp = array(); $tmp = array(
'status'=>'0',
'message'=>''
);
foreach($posts as $Post) { foreach($posts as $Post) {
array_push($tmp, $Post->json( $returnsArray=true )); array_push($tmp, $Post->json( $returnsArray=true ));
} }
return json_encode($tmp); return $tmp;
} }
private function getPage($key) private function getPage($key)
@ -252,21 +263,27 @@ class pluginAPI extends Plugin {
$Page = buildPage($key); $Page = buildPage($key);
if(!$Page) { if(!$Page) {
return json_encode(array( return array(
'status'=>'0', 'status'=>'1',
'bludit'=>'Bludit API plugin', 'message'=>'Page not found.'
'message'=>'The page doesn\'t exist' );
));
} }
return $Page->json(); $data = $Page->json(true);
$data['status'] = '0';
$data['message'] = '';
return $data;
} }
private function getAllPages() private function getAllPages()
{ {
$pages = buildAllPages(); $pages = buildAllPages();
$tmp = array(); $tmp = array(
'status'=>'0',
'message'=>''
);
foreach($pages as $Page) { foreach($pages as $Page) {
if($Page->published()) { if($Page->published()) {
@ -274,7 +291,7 @@ class pluginAPI extends Plugin {
} }
} }
return json_encode($tmp); return $tmp;
} }
} }

View File

@ -6,5 +6,6 @@
}, },
"home": "Начало", "home": "Начало",
"show-home-link": "Покажи връзка към начало" "show-home-link": "Покажи връзка към начало",
} "show-children": "Покажи подменю"
}