diff --git a/_admin.php b/_admin.php new file mode 100644 index 0000000..e2ac150 --- /dev/null +++ b/_admin.php @@ -0,0 +1,9 @@ +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)); diff --git a/_define.php b/_define.php index 8a929a9..50db728 100755 --- a/_define.php +++ b/_define.php @@ -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' ); diff --git a/_prepend.php b/_prepend.php new file mode 100644 index 0000000..9dadc96 --- /dev/null +++ b/_prepend.php @@ -0,0 +1,12 @@ +url->register('rest','rest','^rest(?:/(.*))?$',array('rest','makeResponse')); +class rest extends dcUrlHandlers +{ + + public function makeResponse(){ + + + } +} \ No newline at end of file diff --git a/entry_points.yaml b/entry_points.yaml new file mode 100644 index 0000000..96de17f --- /dev/null +++ b/entry_points.yaml @@ -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"), +), + +); \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..d41c2d7 --- /dev/null +++ b/index.php @@ -0,0 +1,79 @@ +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; + + +?> + + <?php echo __('REST API configuration'); ?> + + + +

+ auth->isSuperAdmin()): + ?> +

+
+ formNonce(); ?> +

+ + +

+

+ + +

+

To do: list here all api access points and acl

+ + +

+
+ + + +

+ + + diff --git a/rest_api.png b/rest_api.png new file mode 100755 index 0000000..04d37a0 Binary files /dev/null and b/rest_api.png differ