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
include(PATH_RULES.'60.plugins.php');
// Plugins before rules loaded, except plugins rules
// Plugins before rules loaded
Theme::plugins('beforeRulesLoad');
// Load rules

View File

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

View File

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