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 0000000..04d37a0 Binary files /dev/null and b/rest_api_256x256.png differ