From bba2c49bb59767ebf06228717b6c841ff3c36a8e Mon Sep 17 00:00:00 2001 From: Gnieark Date: Tue, 20 Feb 2018 19:42:42 +0100 Subject: [PATCH] wip --- _admin.php | 9 +++ _define.php | 5 +- _prepend.php | 12 ++++ entry_points.yaml | 180 ++++++++++++++++++++++++++++++++++++++++++++++ index.php | 79 ++++++++++++++++++++ rest_api.png | Bin 0 -> 675 bytes 6 files changed, 281 insertions(+), 4 deletions(-) create mode 100644 _admin.php create mode 100644 _prepend.php create mode 100644 entry_points.yaml create mode 100644 index.php create mode 100755 rest_api.png 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 0000000000000000000000000000000000000000..04d37a07217c584de17a176eff50c90e067da731 GIT binary patch literal 675 zcmV;U0$lxxP)UxH-@e5F33&0XjQv}Xi+Vq zML|VaL1tlCFqZGMP;?wq6CaZg8s|Eu-q9KFqs5e9En2neEYHU|=i>+eT83f#;dOi* zZtVEvsRoe#RxmX+Rn^$q+4Asp=Nr$+$SHt~l)b8Lcl;#)^Y4Mt=~?o#GMSrS$nnc7 zbtmq0Um046fPn0j*vgmf{UzD^((CR&Yb^v2zk*!@W0V%=VT3m_8(w^v==H5yX95aC z{>>c&r;9T%tlXCV{RS_}4a(*TV$X!>oiNEUky}Ei2JAi<#S< zGtRNm@k-N1NV!~ft?6c*RYKEr{EEu(tc=GeBP5A{62UtkWG)y&R>IpXG$E)j%j%IH zbx+n6=cE#f=+qp{fQSYr351}bwut;R8+Kb91@^=pFpoLYX?FMZOBGK0(EEuc4rQk@ zw)j1IRdsUH_Hg``n=MV}Ro54$18bn_5K+muCvtLs!qf9-YX=0tXWzHy?vbx9v&ACJ zQk1KKfk2=e29hK&3

$q6yCBi^{{bmrYiFRF!mPg?lT^#eto>7RO3M=$^Y002ov JPDHLkV1i}|E?WQq literal 0 HcmV?d00001