try-Again
Gnieark 6 years ago
parent 134c8f8618
commit bba2c49bb5

@ -0,0 +1,9 @@
<?php
if (!defined('DC_CONTEXT_ADMIN')) { return; }
$_menu['Blog']->addItem(__('Rest API'),
'plugin.php?p=rest',
urldecode(dcPage::getPF('rest/rest_api.png')),
preg_match('/plugin.php\?p=rest(&.*)?$/',$_SERVER['REQUEST_URI']),
$core->auth->check('contentadmin',$core->blog->id));

@ -16,8 +16,5 @@ $this->registerModule(
/* Description*/ "A JSON/REST API for Dotclear",
/* Author */ "Gnieark",
/* Version */ '0.0.6',
array(
'permissions' => 'usage,contentadmin',
'type' => 'plugin',
)
/* Permissions */ 'usage,contentadmin'
);

@ -0,0 +1,12 @@
<?php
if (!defined('DC_RC_PATH')) { return; }
$core->url->register('rest','rest','^rest(?:/(.*))?$',array('rest','makeResponse'));
class rest extends dcUrlHandlers
{
public function makeResponse(){
}
}

@ -0,0 +1,180 @@
blogs:
description: SCRUD (search create update delete Blogs)
swaggerDoc: blogs.yaml
entryPoints:
getBlogs:
title: Get blogs
method: GET
pattern: /^blogs($|/(.*)$)/
class: blogs
function: getBlogs
params:
- args
specs:
description: Return this API swagger definitions.
swaggerDoc: specs.yaml
entryPoints:
getSpecs: get the swagger specification
method: GET
/*
array("method" =>"GET",
"URLmatch" => "/^blogs$/",
"object" => "RestQueryGetBlogs",
"arguments" => array(),
"limit_results" => true,
"title" => "list blogs"
),
array("method" => "GET",
"URLmatch" => "/^specs($|\/(.*)$)/",
"object" => "RestQueryGetSpecs",
"arguments" => array("args"),
),
array("method" => "GET",
"URLmatch" => '/^blogs\/(.*)$/',
"object" => "RestQueryGetBlog",
"arguments" => array("args"),
),
array("method" => "GET",
"URLmatch" => '/^documentation($|\/)/',
"object" => "RestDocumentation",
"arguments" => array("args")
),
array("method" => "GET",
"URLmatch" => '/^((.*)\/settings|(.*)\/settings\/(.*))$/',
"object" => "RestQueryGetBlogSettings",
"arguments" => array("args"),
"limit_results" => true,
"title" => "list settings"
),
array("method" => "GET",
"URLmatch" => '/^(.*)\/posts$/',
"object" => "RestQueryGetPosts",
"arguments" => array("args"),
"limit_results" => true,
"title" => "list posts"
),
array("method" => "GET",
"URLmatch" => '/^(.*)\/post\/(.*)$/',
"object" => "RestQueryGetPosts",
"arguments" => array("args")
),
array("method" => "GET",
"URLmatch" => '/^(.*)\/metas$/',
"object" => "RestQueryGetMetas",
"arguments" => array("args"),
"limit_results" => true,
"title" => "list metas"
),
array("method" => "GET",
"URLmatch" => '/^(.*)\/categories($|\/(.*)$)/',
"object" => "RestQueryGetCategories",
"arguments" => array("args"),
"limit_results" => true,
"title" => "list categories"
),
array("method" => "GET",
"URLmatch" => '/^(.*)\/comments($|\/(.*)$)/',
"object" => "RestQueryGetComments",
"arguments" => array("args")
),
array("method" => "POST",
"URLmatch" => '/^blogs$/',
"object" => "RestQueryPostBlogs",
"arguments" => array("body"),
),
array("method" => "POST",
"URLmatch" => '/^(.*)\/settings\/(.*)$/',
"object" => "RestQueryPostBlogSettings",
"arguments" => array("args","body")
),
array(
"method" => "POST",
"URLmatch" => '/^(.*)\/post$/',
"object" => "RestQueryPostPost",
"arguments" => array("args","body")
),
array(
"method" => "POST",
"URLmatch" => '/^(.*)\/categories$/',
"object" => "RestQueryPostCategories",
"arguments" => array("args","body"),
),
array(
"method" => "POST",
"URLmatch" => '/^(.*)\/metas$/',
"object" => "RestQueryPostMetas",
"arguments" => array("args", "body")
),
array(
"method" => "POST",
"URLmatch" => '/^(.*)\/(.*)\/comments$/',
"object" => "RestQueryPostComments",
"arguments" => array("args","body")
),
array(
"method" => "PUT",
"URLmatch" => '/^blogs\/(.*)$/',
"object" => "ResQueryPutBlogs",
"arguments" => array("args","body")
),
array(
"method" => "PATCH",
"URLmatch" => '/^blogs\/(.*)$/',
"object" => "ResQueryPatchBlogs",
"arguments" => array("args","body")
),
array(
"method" => "PATCH",
"URLmatch" => '/^(.*)\/(.*)\/meta\/(.*)$/',
"object" => "ResQueryPatchMeta",
"arguments" => array("args","body")
),
array(
"method" => "PATCH",
"URLmatch" => '/^(.*)\/categories\/(.*)$/',
"object" => "RestQueryPatchCategories",
"arguments" => array("args","body")
),
array(
"method" => "DELETE",
"URLmatch" => '/^blogs\/(.*)$/',
"object" => "ResQueryDeleteBlogs",
"arguments" => array("args", "body")
),
array(
"method" => "DELETE",
"URLmatch" => '/^(.*)\/settings\/(.*)$/',
"object" => "RestQueryDeleteBlogSettings",
"arguments" => array("args","body")
),
array(
"method" => "DELETE",
"URLmatch" => '/^(.*)\/(.*)\/metas$/',
"object" => "RestQueryDeletePostMeta",
"arguments" => array("args","body")
),
array(
"method" => "DELETE",
"URLmatch" => '/^(.*)\/(.*)\/meta\/(.*)$/',
"object" => "RestQueryDeletePostMeta",
"arguments" => array("args")
),
array(
"method" => "DELETE",
"URLmatch" => '/^(.*)\/categories\/(.*)$/',
"object" => "RestQueryDeleteCategories",
"arguments" => array("args","body")
),
array(
"method" => "DELETE",
"URLmatch" => '/(^(.*)\/comments\/(.*)|^(.*)\/comments)$/',
"object" => "RestQueryDeleteComments",
"arguments" => array("args","body"),
),
);

@ -0,0 +1,79 @@
<?php
if (!defined('DC_CONTEXT_ADMIN')) { return; }
// Setting default parameters if missing configuration
$core->blog->settings->addNamespace('rest');
if (is_null($core->blog->settings->rest->rest_active)) {
try {
$core->blog->settings->rest->put('rest_active',false,'boolean',true);
$core->blog->settings->rest->put('rest_send_cors_headers',true,'boolean',true);
$core->blog->triggerBlog();
http::redirect($p_url);
}
catch (Exception $e) {
$core->error->add($e->getMessage());
}
}
//a form is submitted
if (!empty($_POST['saveconfig'])){
try
{
$core->blog->settings->addNameSpace('rest');
$active = (empty($_POST['active'])) ? false : true;
$core->blog->settings->rest->put('rest_active',$active,'boolean');
$sendHeaders = (empty($_POST['sendHeaders'])) ? false : true;
$core->blog->settings->rest->put('rest_send_cors_headers',$sendHeaders,'boolean');
dcPage::addSuccessNotice(__('Configuration successfully updated.'));
http::redirect($p_url);
}catch (Exception $e)
{
$core->error->add($e->getMessage());
}
http::redirect($p_url.'&saveconfig=1');
}
// Getting current parameters
$active = (boolean)$core->blog->settings->rest->rest_active;
$sendHeaders =(boolean)$core->blog->settings->rest->rest_send_cors_headers;
?><html>
<head>
<title><?php echo __('REST API configuration'); ?></title>
</head>
<body>
<h2><?php echo __('Your API key');?></h2>
<?php
// Settings form is only available for super admins.
if($core->auth->isSuperAdmin()):
?>
<h2><?php echo __('API Settings');?></h2>
<form method="post" action="<?php http::getSelfURI(); ?>">
<?php echo $core->formNonce(); ?>
<p>
<?php echo form::checkbox('active', 1, $active); ?>
<label class="classic" for="active">&nbsp;<?php echo __('Enable REST API');?></label>
</p>
<p>
<?php echo form::checkbox('sendHeaders', 1, $sendHeaders); ?>
<label class="classic" for="sendHeaders">&nbsp;<?php echo __('Send the Cross Origin Domain http headers');?></label>
</p>
<p> To do: list here all api access points and acl</p>
<p><input type="submit" name="saveconfig" value="<?php echo __('Save configuration'); ?>" /></p>
</form>
<?php endif; ?>
<h2><?php echo __('Documentation');?></h2>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 675 B

Loading…
Cancel
Save