WIP
This commit is contained in:
parent
f4cfc47384
commit
c75a707d28
10
_admin.php
10
_admin.php
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
if (!defined('DC_CONTEXT_ADMIN')) { return; }
|
||||
// dead but useful code, in order to have translations
|
||||
|
||||
$_menu['Blog']->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));
|
17
_public.php
17
_public.php
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
if (!defined('DC_RC_PATH')) { return; }
|
||||
|
||||
$core->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;
|
||||
}
|
||||
}
|
5
documentation/index.php
Normal file
5
documentation/index.php
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
|
||||
|
||||
?>
|
||||
<h1>Hey</h1>
|
67
index.php
Normal file
67
index.php
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?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 {
|
||||
// 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());
|
||||
}
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Rest API config</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Rest API configuration</h2>
|
||||
<form method="post" action="<?php http::getSelfURI(); ?>">
|
||||
<p>
|
||||
<?php echo form::checkbox('active', 1, $active); ?>
|
||||
<label class="classic" for="active"> <?php echo __('Enable REST API');?></label>
|
||||
</p>
|
||||
<p>
|
||||
<?php echo form::checkbox('open', 1, $openApi); ?>
|
||||
<label class="classic" for="open"> <?php echo __('API is open');?></label>
|
||||
</p>
|
||||
<p class="info">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.</p>
|
||||
<?php echo $core->formNonce(); ?>
|
||||
<p>
|
||||
<input type="submit" name="saveconfig" value="<?php echo __('Save configuration'); ?>" />
|
||||
</p>
|
||||
|
||||
</from>
|
||||
</body>
|
||||
</html>
|
BIN
rest_api_256x256.png
Normal file
BIN
rest_api_256x256.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 675 B |
Loading…
Reference in New Issue
Block a user