From c75a707d282c6c4becdb628d2bcc4f2f3aae8cd4 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Thu, 13 Apr 2017 22:46:51 +0200 Subject: [PATCH] WIP --- _admin.php | 10 ++++++ _public.php | 17 ++++++++++ documentation/index.php | 5 +++ index.php | 67 ++++++++++++++++++++++++++++++++++++++++ rest_api_256x256.png | Bin 0 -> 675 bytes 5 files changed, 99 insertions(+) create mode 100644 documentation/index.php create mode 100644 index.php create mode 100644 rest_api_256x256.png diff --git a/_admin.php b/_admin.php index e69de29..ddd6814 100644 --- a/_admin.php +++ b/_admin.php @@ -0,0 +1,10 @@ +addItem(__('Rest API'), + 'plugin.php?p=rest', + urldecode(dcPage::getPF('rest/rest_api_256x256.png')), + preg_match('/plugin.php\?p=rest(&.*)?$/',$_SERVER['REQUEST_URI']), + $core->auth->check('contentadmin',$core->blog->id)); diff --git a/_public.php b/_public.php index e69de29..7b538af 100644 --- a/_public.php +++ b/_public.php @@ -0,0 +1,17 @@ +url->register('rest','rest','^rest(?:/(.+))?$',array('rest','getResponse')); +class rest extends dcUrlHandlers +{ + public static function getResponse($args) + { + global $core; + $active = (boolean)$core->blog->settings->rest->rest_active; + if (!$active){ + self::p404(); + return; + } + echo "HELLO".$_SERVER['REQUEST_METHOD'].$args; + } +} \ No newline at end of file diff --git a/documentation/index.php b/documentation/index.php new file mode 100644 index 0000000..038219f --- /dev/null +++ b/documentation/index.php @@ -0,0 +1,5 @@ + +

Hey

\ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..c69256f --- /dev/null +++ b/index.php @@ -0,0 +1,67 @@ +blog->settings->addNamespace('rest'); +if (is_null($core->blog->settings->rest->rest_active)) { + try { + // Default state is active if the comments are configured to allow wiki syntax + $core->blog->settings->rest->put('rest_active',false,'boolean',true); + $core->blog->settings->rest->put('rest_is_open',false,'boolean',true); + $core->blog->triggerBlog(); + http::redirect($p_url); + } + catch (Exception $e) { + $core->error->add($e->getMessage()); + } +} +// Getting current parameters +$active = (boolean)$core->blog->settings->rest->rest_active; +$openApi = (boolean)$core->blog->settings->rest->rest_is_open; + +//apply +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'); + + $openApi = (empty($_POST['open'])) ? false : true; + $core->blog->settings->rest->put('rest_is_open',$openApi,'boolean'); + + dcPage::addSuccessNotice(__('Configuration successfully updated.')); + http::redirect($p_url); + }catch (Exception $e) + { + $core->error->add($e->getMessage()); + } +} +?> + + + Rest API config + + +

Rest API configuration

+
+

+ + +

+

+ + +

+

If checked, few methods as GET will be allowed to externals users without API key. + However, they won't be able to request for non public content.

+ formNonce(); ?> +

+ +

+ + + + diff --git a/rest_api_256x256.png b/rest_api_256x256.png new file mode 100644 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