synchro depot bitbucket -> github

master
Gnieark 7 years ago
parent e78c32b69e
commit 8609ec189a

@ -8,7 +8,11 @@ Real time code repository is https://bitbucket.org/gnieark/dc-rest-api
# Install:
Make a zip of this repository and install it on your Dotclear Blog.
Make a zip of this repository, rename it "rest.zip" and install it on your Dotclear Blog via the admin interface.
Or
hg clone https://bitbucket.org/gnieark/dc-rest-api /path/to/dotclear/plugins/rest
# Known bugs
@ -42,4 +46,4 @@ GNU GENERAL PUBLIC LICENSE Version 2, June 1991
## SwaggerUI
Documentation and the tool to test the API is a third party code integrated on this plugin:
Swagger-UI https://github.com/swagger-api/swagger-ui Licensed under the Apache License, Version 2.0
Swagger-UI https://github.com/swagger-api/swagger-ui Licensed under the Apache License, Version 2.0

@ -14,8 +14,8 @@ if (!defined('DC_RC_PATH')) { return; }
$this->registerModule(
/* Name */ "rest",
/* Description*/ "A JSON/REST API for Dotclear",
/* Author */ "Gnieark (hope some others contributors)",
/* Version */ '0.0.2',
/* Author */ "Gnieark",
/* Version */ '0.0.5',
array(
'permissions' => 'usage,contentadmin',
'type' => 'plugin',

@ -2,8 +2,10 @@
global $__autoload;
$__autoload['ApiKey'] = dirname(__FILE__).'/inc/class.rest.key.php';
$__autoload['RestDocumentation'] = dirname(__FILE__).'/inc/class.rest.documentation.php';
$__autoload['restAuth'] = dirname(__FILE__).'/inc/class.rest.auth.php';
$__autoload['restDcNameSpace'] = dirname(__FILE__).'/inc/class.rest.DcNameSpace.php';
$__autoload['RestCategories'] = dirname(__FILE__).'/inc/class.rest.categories.php';
$__autoload['RestQuery'] = dirname(__FILE__).'/inc/class.rest.query.php';
$__autoload['RestQueryGetBlogs'] = dirname(__FILE__).'/inc/class.rest.query.get.blogs.php';
$__autoload['RestQueryGetBlog'] = dirname(__FILE__).'/inc/class.rest.query.get.blog.php';
@ -18,6 +20,15 @@ $__autoload['RestQueryDeleteBlogSettings'] = dirname(__FILE__).'/inc/class.rest.
$__autoload['RestQueryGetPosts'] = dirname(__FILE__).'/inc/class.rest.query.get.posts.php';
$__autoload['RestQueryGetPost'] = dirname(__FILE__).'/inc/class.rest.query.get.post.php';
$__autoload['RestQueryPostPost'] = dirname(__FILE__).'/inc/class.rest.query.post.post.php';
$__autoload['RestQueryGetCategories'] = dirname(__FILE__).'/inc/class.rest.query.get.categories.php';
$__autoload['RestQueryPatchCategories'] = dirname(__FILE__).'/inc/class.rest.query.patch.categories.php';
$__autoload['RestQueryPostCategories'] = dirname(__FILE__).'/inc/class.rest.query.post.categories.php';
$__autoload['RestQueryDeleteCategories'] = dirname(__FILE__).'/inc/class.rest.query.delete.categories.php';
$__autoload['RestQueryPostMetas'] = dirname(__FILE__).'/inc/class.rest.query.post.metas.php';
$__autoload['RestQueryGetMetas'] = dirname(__FILE__).'/inc/class.rest.query.get.metas.php';
$__autoload['RestQueryGetPostMetas'] = dirname(__FILE__).'/inc/class.rest.query.get.post.metas.php';
$__autoload['RestQueryDeletePostMeta'] = dirname(__FILE__).'/inc/class.rest.query.delete.post.meta.php';
$__autoload['ResQueryPatchMeta'] = dirname(__FILE__).'/inc/class.rest.query.patch.metas.php';
$__autoload['RestQueryGetComments'] = dirname(__FILE__).'/inc/class.rest.query.get.comments.php';
$__autoload['RestQueryDeleteComments'] = dirname(__FILE__).'/inc/class.rest.query.delete.comments.php';

@ -19,10 +19,16 @@ class rest extends dcUrlHandlers
case "GET":
if($args == 'blogs')
return new RestQueryGetBlogs();
elseif($args == 'specs')
return new RestQueryGetSpecs();
elseif( $args == "specs")
return new RestQueryGetSpecs($args);
elseif(preg_match('/^specs\/(.*)$/', $args ))
return new RestQueryGetSpecs($args);
elseif(preg_match('/^blogs\/(.*)$/', $args ))
return new RestQueryGetBlog($args);
elseif($args == "documentation")
return new RestDocumentation($args);
elseif(preg_match('/^documentation\/(.*)$/', $args ))
return new RestDocumentation($args);
elseif(preg_match('/^(.*)\/settings$/', $args ))
return new RestQueryGetBlogSettings($args);
elseif(preg_match('/^(.*)\/settings\/(.*)$/', $args ))
@ -31,6 +37,19 @@ class rest extends dcUrlHandlers
return new RestQueryGetPosts($args);
elseif(preg_match('/^(.*)\/post\/(.*)$/', $args ))
return new RestQueryGetPost($args);
elseif(preg_match('/^(.*)\/metas$/', $args ))
return new RestQueryGetMetas($args);
elseif(preg_match('/^(.*)\/categories$/', $args ))
return new RestQueryGetCategories($args);
elseif(preg_match('/^(.*)\/categories\/(.*)$/', $args ))
return new RestQueryGetCategories($args);
elseif(preg_match('/^(.*)\/metas\/(.*)$/', $args ))
return new RestQueryGetPostMetas($args);
elseif(preg_match('/^(.*)\/comments\/(.*)$/', $args ))
return new RestQueryGetComments($args);
elseif(preg_match('/^(.*)\/comments$/', $args ))
return new RestQueryGetComments($args);
break;
case "POST":
@ -53,20 +72,30 @@ class rest extends dcUrlHandlers
break;
case "PATCH":
if(preg_match('/^blogs\/(.*)$/', $args )){
if(preg_match('/^blogs\/(.*)$/', $args ))
return new ResQueryPatchBlogs($args,$body);
break;
}
elseif(preg_match('/^(.*)\/(.*)\/meta\/(.*)$/', $args ))
return new ResQueryPatchMeta($args,$body);
elseif(preg_match('/^(.*)\/categories\/(.*)$/', $args ))
return new RestQueryPatchCategories($args,$body);
break;
case "DELETE":
if(preg_match('/^blogs\/(.*)$/', $args )){
if(preg_match('/^blogs\/(.*)$/', $args ))
return new ResQueryDeleteBlogs($args,$body);
break;
}elseif(preg_match('/^(.*)\/settings\/(.*)$/', $args )){
elseif(preg_match('/^(.*)\/settings\/(.*)$/', $args ))
return new RestQueryDeleteBlogSettings($args);
}
elseif(preg_match('/^(.*)\/(.*)\/metas$/', $args ))
return new RestQueryDeletePostMeta($args);
elseif(preg_match('/^(.*)\/(.*)\/meta\/(.*)$/', $args ))
return new RestQueryDeletePostMeta($args);
elseif(preg_match('/^(.*)\/categories\/(.*)$/', $args ))
return new RestQueryDeleteCategories($args,$body);
elseif(preg_match('/^(.*)\/comments\/(.*)$/', $args ))
return new RestQueryDeleteComments($args,$body);
elseif(preg_match('/^(.*)\/comments$/', $args ))
return new RestQueryDeleteComments($args,$body);
break;
default:
break;
@ -75,6 +104,9 @@ class rest extends dcUrlHandlers
}
/*
* Serve the Query response With the headers and the body
*/
public static function getResponse($args)
{
global $core;
@ -90,15 +122,7 @@ class rest extends dcUrlHandlers
header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE');
header('Access-Control-Allow-Headers: Content-Type, authorization, x_dc_key');
}
//exception pour la documentation
if($args == "documentation"){
include (dirname(__FILE__).'/documentation/swagger-ui-dist/index.php');
return;
}
header('Content-Type: application/json');
//user authentification (facultative at this step)
$apiKey = rest::get_api_key_sended();
@ -106,6 +130,7 @@ class rest extends dcUrlHandlers
if($apiKey){
$core->auth = new restAuth($core);
if($core->auth->checkUser('','',$apiKey) === false){
header('Content-Type: application/json');
header(RestQuery::get_full_code_header(403));
echo json_encode(array(
"error" => "Wrong API Key",
@ -118,13 +143,18 @@ class rest extends dcUrlHandlers
}
$r = rest::restFactoryQuery($_SERVER['REQUEST_METHOD'],$args,file_get_contents('php://input'));
header($r->get_full_code_header());
echo json_encode($r->response_message);
if(is_array($r->response_message)){
header('Content-Type: application/json');
echo json_encode($r->response_message);
}else{
echo $r->response_message;
}
}
private function get_api_key_sended()
{
//to do: test it on nginx
//to do: test it with nginx
$headers = apache_request_headers();
if(isset($headers['x_dc_key'])){
return $headers['x_dc_key'];
@ -133,4 +163,4 @@ class rest extends dcUrlHandlers
}
}
}
}

@ -0,0 +1,232 @@
swagger: '2.0'
info:
title: Dotclear API
description: Manage your(s) blogs with this API
version: 0.0.2
host: dotclear.localhost
schemes:
- http
basePath: /dotclear/index.php?rest
produces:
- application/json
paths:
/blogs:
get:
summary: Get list of availables blogs
parameters:
- name: x_dc_key
in: header
required: false
type: string
responses:
'200':
description: array serving blogs properties
schema:
type: array
items:
type: string
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
post:
summary: Create a new blog
parameters:
- name: x_dc_key
in: header
type: string
required: true
- name: blog
in: body
description: The blog you want to create
schema:
$ref: '#/definitions/blog'
required: true
responses:
'201':
description: 'Success, array containing the new blog''s identifiant'
schema:
type: object
properties:
code:
type: integer
blog_id:
type: integer
message:
type: string
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
'/blogs/{blog-id}':
get:
summary: Get a blog poperties
parameters:
- name: x_dc_key
in: header
type: string
required: false
- name: blog-id
in: path
type: string
required: true
responses:
'200':
description: 'Core blog properties. use {blog_id}/settings methods for more settings.'
schema:
$ref: '#/definitions/blogProperties'
'404':
description: this blog id does not exists
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
patch:
summary: Update part of blog properties
parameters:
- name: x_dc_key
in: header
type: string
required: true
- name: blog-id
in: path
type: string
required: true
- name: blog
in: body
description: This list of parameters is not exhaustive
required: true
schema:
$ref: '#/definitions/blogProperties'
responses:
'200':
description: array containing the edited blog's identifiant
schema:
$ref: '#/definitions/Ids'
'404':
description: this blog id does not exists
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
put:
summary: 'Overwrite blog Properties (if an optional parameter is not set, his value will be erased by the default value)'
parameters:
- name: x_dc_key
in: header
type: string
required: true
- name: blog-id
in: path
type: string
required: true
- name: blog
in: body
description: This list of parameters is not exhaustive
required: true
schema:
$ref: '#/definitions/blogPropertiesPut'
responses:
'200':
description: array containing the edited blog's identifiant
schema:
$ref: '#/definitions/Ids'
'404':
description: this blog id does not exists
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
delete:
summary: Delete this blog
parameters:
- name: x_dc_key
in: header
type: string
required: true
- name: blog-id
in: path
type: string
required: true
responses:
'200':
description: array containing the deleted blog's identifiant
schema:
$ref: '#/definitions/Ids'
'404':
description: this blog id does not exists
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
definitions:
blog:
type: object
required:
- blog_id
- blog_name
- blog_url
properties:
blog_id:
type: string
blog_name:
type: string
blog_url:
type: string
blog_desc:
type: string
lang:
type: string
blog_timezone:
type: string
url_scan:
type: string
enum:
- query_string
- path_info
Ids:
type: object
properties:
id:
type: integer
description: New blog id
blogPropertiesPut:
required:
- blog_id
- blog_name
- blog_url
- blog_desc
type: object
properties:
blog_id:
type: string
blog_name:
type: string
blog_url:
type: string
blog_desc:
type: string
blogProperties:
type: object
properties:
blog_id:
type: string
blog_name:
type: string
blog_url:
type: string
blog_desc:
type: string
Error:
type: object
properties:
code:
type: integer
format: int32
message:
type: string
fields:
type: string

@ -1,943 +0,0 @@
swagger: '2.0'
info:
title: Dotclear API
description: Manage your(s) blogs with this API
version: 0.0.1
host: dotclear.localhost
schemes:
- http
basePath: /dotclear/index.php?rest
produces:
- application/json
paths:
/specs:
get:
summary: Get this API SWAGGER documentation
responses:
'200':
description: swagger.json
schema:
title: doc
type: string
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
/blogs:
get:
summary: Get list of availables blogs
parameters:
- name: x_dc_key
in: header
required: false
type: string
responses:
'200':
description: array serving blogs properties
schema:
type: array
items:
type: string
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
post:
summary: Create a new blog
parameters:
- name: x_dc_key
in: header
type: string
required: true
- name: blog
in: body
description: The blog you want to create
schema:
$ref: '#/definitions/blog'
required: true
responses:
'201':
description: 'Success, array containing the new blog''s identifiant'
schema:
type: object
properties:
code:
type: integer
blog_id:
type: integer
message:
type: string
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
'/blogs/{blog-id}':
get:
summary: Get a blog poperties
parameters:
- name: x_dc_key
in: header
type: string
required: false
- name: blog-id
in: path
type: string
required: true
responses:
'200':
description: 'Core blog properties. use {blog_id}/settings methods for more settings.'
schema:
$ref: '#/definitions/blogProperties'
'404':
description: this blog id does not exists
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
patch:
summary: Update part of blog properties
parameters:
- name: x_dc_key
in: header
type: string
required: true
- name: blog-id
in: path
type: string
required: true
- name: blog
in: body
description: This list of parameters is not exhaustive
required: true
schema:
$ref: '#/definitions/blogProperties'
responses:
'200':
description: array containing the edited blog's identifiant
schema:
$ref: '#/definitions/Ids'
'404':
description: this blog id does not exists
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
put:
summary: 'Overwrite blog Properties (if an optional parameter is not set, his value will be erased by the default value)'
parameters:
- name: x_dc_key
in: header
type: string
required: true
- name: blog-id
in: path
type: string
required: true
- name: blog
in: body
description: This list of parameters is not exhaustive
required: true
schema:
$ref: '#/definitions/blogPropertiesPut'
responses:
'200':
description: array containing the edited blog's identifiant
schema:
$ref: '#/definitions/Ids'
'404':
description: this blog id does not exists
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
delete:
summary: Delete this blog
parameters:
- name: x_dc_key
in: header
type: string
required: true
- name: blog-id
in: path
type: string
required: true
responses:
'200':
description: array containing the deleted blog's identifiant
schema:
$ref: '#/definitions/Ids'
'404':
description: this blog id does not exists
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
'/{blog_id}/settings':
get:
summary: 'Get the about:config'
description: Get all parameters
parameters:
- name: x_dc_key
in: header
type: string
required: true
- name: blog_id
in: path
type: string
required: true
responses:
'200':
description: OK
'404':
description: this blog id does not exists
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
'/{blog_id}/settings/{name_space}':
get:
summary: 'Get the settings inside the name-space'
description: same
parameters:
- name: x_dc_key
in: header
type: string
required: true
- name: blog_id
in: path
type: string
required: true
- name: name_space
in: path
type: string
required: true
responses:
'200':
description: OK
'404':
description: this blog id does not exists
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
post:
summary: Create or edit a new namespace and or a new setting'
description: "Let body empty if you just want to create a namespace without setting. Note that if the setting already exists, it will be erased. So, PUT and PATCH methods are useless."
parameters:
- name: x_dc_key
in: header
type: string
required: true
- name: blog_id
in: path
type: string
required: true
- name: name_space
in: path
type: string
required: true
- name: setting
description: Can be empty, Can pass many settings. [{"id":"string","type":"string","value":"string","value_change":"string Optional","global":"bool optional"},{"id2":...}]
in: body
schema:
$ref: '#/definitions/settings'
responses:
'201':
description: OK
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
'/{blog_id}/settings/{name_space}/{setting_id}':
get:
summary: Get value and type for one setting'
description: ""
parameters:
- name: x_dc_key
in: header
type: string
required: true
- name: blog_id
in: path
type: string
required: true
- name: name_space
in: path
type: string
required: true
- name: setting_id
in: path
type: string
required: true
responses:
'200':
description: OK
schema:
$ref: '#/definitions/OneSetting'
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
'/{blog-id}/posts':
get:
summary: Get list of posts
parameters:
- name: x_dc_key
in: header
type: string
required: true
- name: blog-id
in: path
type: string
required: true
- name: limit-start
in: query
required: false
type: integer
- name: limit-count
in: query
type: integer
required: false
- name: cat_id
in: query
type: string
required: false
- name: post_status
type: string
in: query
required: false
- name: password
type: string
in: query
required: false
- name: post_selected
type: boolean
in: query
required: false
- name: post_open_comment
type: boolean
in: query
required: false
- name: post_open_tb
type: boolean
in: query
required: false
- name: post_month
type: string
in: query
required: false
- name: post_year
type: string
in: query
required: false
- name: post_lang
type: string
in: query
required: false
- name: post_format
type: string
in: query
required: false
- name: sortby
type: string
in: query
required: false
description: If many, separate them by a comma
responses:
'200':
description: list of posts
schema:
title: posts
type: array
items:
$ref: '#/definitions/dc_post'
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
'/{blog-id}/post':
post:
summary: Create a new post
parameters:
- name: x_dc_key
in: header
type: string
required: true
- name: blog-id
in: path
type: string
required: true
- name: properties
in: body
description: Some non required fields you don't define will be set (default value) by the API. You can post many posts once by putting them on an array like [{'post_title':'blah',...},{'post_title':'bluh',...}]
schema:
$ref: '#/definitions/new_dc_post'
responses:
'200':
description: Id of newly created post
schema:
$ref: '#/definitions/Ids'
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
'/{blog-id}/post/{post-id}':
get:
summary: Get a post entry
parameters:
- name: x_dc_key
in: header
type: string
required: false
- name: blog-id
in: path
type: string
required: true
- name: post-id
in: path
type: string
required: true
- name: fields
in: query
type: array
items:
type: string
required: false
description: 'Fields you want to get. If unset, all available fields will be get.'
responses:
'200':
description: The post values
schema:
$ref: '#/definitions/dc_post'
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
patch:
summary: Not yet developed Update part of a post entry's properties
parameters:
- name: x_dc_key
in: header
type: string
required: true
- name: blog-id
in: path
type: string
required: true
- name: post-id
in: path
type: string
required: true
- name: properties
in: body
schema:
$ref: '#/definitions/dc_post'
responses:
'200':
description: array containing the updated post's id
schema:
$ref: '#/definitions/Ids'
'404':
description: this post does not exists
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
put:
summary: Not yet developed Update full blog properties. Unsetted parameters will be erased
parameters:
- name: x_dc_key
in: header
type: string
required: true
- name: blog-id
in: path
type: string
required: true
- name: post-id
in: path
type: string
required: true
- name: properties
in: body
schema:
$ref: '#/definitions/new_dc_post'
responses:
'200':
description: array containing the updated post's id
schema:
$ref: '#/definitions/Ids'
'404':
description: this post does not exists
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
delete:
summary: Not yet developed Delete the post
parameters:
- name: x_dc_key
in: header
type: string
required: true
- name: blog-id
in: path
type: string
required: true
- name: post-id
in: path
type: string
required: true
responses:
'200':
description: array containing the deleted post's id
schema:
$ref: '#/definitions/Ids'
'404':
description: this post does not exists
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
'/{blog-id}/metas':
post:
summary: Create a new Postr meta
parameters:
- name: x_dc_key
in: header
type: string
required: false
- name: blog-id
in: path
type: string
required: true
- name: properties
in: body
schema:
$ref: '#/definitions/new_meta'
responses:
'200':
description: New meta id
schema:
title: categories
type: array
items:
$ref: '#/definitions/category'
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
'/{blog-id}/{post-id}/metas':
get:
summary: get metas for a post
parameters:
- name: x_dc_key
in: header
type: string
required: false
- name: blog-id
in: path
type: string
required: true
- name: post-id
in: path
type: integer
required: true
responses:
'200':
description: New meta id
schema:
title: categories
type: array
items:
$ref: '#/definitions/metas'
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
'/{blog-id}/categories':
get:
summary: Not yet developed Get list of available categories
parameters:
- name: x_dc_key
in: header
type: string
required: false
- name: blog-id
in: path
type: string
required: true
responses:
'200':
description: array containing the categories properties
schema:
title: categories
type: array
items:
$ref: '#/definitions/category'
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
post:
summary: Create a new category
parameters:
- name: x_dc_key
in: header
type: string
required: true
- name: blog-id
in: path
type: string
required: true
- name: properties
in: body
schema:
$ref: '#/definitions/new_category'
responses:
'200':
description: array containing the created category id
schema:
$ref: '#/definitions/Ids'
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
'/{blog-id}/categories/{cat-id}':
get:
summary: Not yet developed get one category properties
parameters:
- name: x_dc_key
in: header
type: string
required: false
- name: blog-id
in: path
type: string
required: true
- name: cat-id
in: path
type: string
required: true
responses:
'200':
description: array containing the created category properties
schema:
$ref: '#/definitions/category'
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
patch:
summary: Not yet developed Update some attributes
parameters:
- name: blog-id
in: path
type: string
required: true
- name: cat-id
in: path
type: string
required: true
- name: category
in: body
schema:
$ref: '#/definitions/category'
responses:
'200':
description: array containing the modified category id
schema:
$ref: '#/definitions/Ids'
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
definitions:
blog:
type: object
required:
- blog_id
- blog_name
- blog_url
properties:
blog_id:
type: string
blog_name:
type: string
blog_url:
type: string
blog_desc:
type: string
lang:
type: string
blog_timezone:
type: string
url_scan:
type: string
enum:
- query_string
- path_info
OneSetting:
type: object
properties:
ns:
type: string
value:
type: string
type:
type: string
label:
type: string
global:
type: boolean
settings:
type: array
items:
type: object
Ids:
type: object
properties:
id:
type: integer
description: New blog id
blogPropertiesPut:
required:
- blog_id
- blog_name
- blog_url
- blog_desc
type: object
properties:
blog_id:
type: string
blog_name:
type: string
blog_url:
type: string
blog_desc:
type: string
new_meta:
required:
- meta_id
- meta_type
- post_id
type: object
properties:
meta_id:
type: string
meta_type:
type: string
post_id:
type: integer
blogProperties:
type: object
properties:
blog_id:
type: string
blog_name:
type: string
blog_url:
type: string
blog_desc:
type: string
new_dc_post:
type: object
required:
- post_format
- post_status
- post_content
- post_title
properties:
post_title:
type: string
post_format:
type: string
description: generally 'xhtml' or 'wiki'. If you put another value, not managed by Dotclear or a plugin, Fill in the post_content_xhtml field.
post_content:
type: string
description: The content on WhatYouWant format
post_content_xhtml:
type: string
description: If post_format is wiki or xhtml and not set, It will be generated from post_content
post_status:
type: string
enum:
- Pending
- Scheduled
- Unpublished
- Published
cat_id:
type: integer
new_cat_id:
type: string
description: If creating a new category, this is the only required cat_ field. If given cat_id must not be given
new_cat_parent_id:
type: integer
description: Only if new_cat_id is given
new_cat_desc:
type: string
description: the new category description.
new_cat_url:
type: string
description: the new category url
post_dt:
type: string
description: \'YY-MM-dd hh:mm:ss\' If not set, Current dateTime will be used.
post_password:
type: string
description: Don\'t set that value if your new post won\'t be protected
post_url:
type: string
description: If not set, will be created using the date and the post_titlke
post_lang:
type: string
description: If not set, User lang will be used
post_excerpt:
type: string
post_excerpt_xhtml:
type: string
description: If post_format is wiki or xhtml, It will be generated from post_excerpt
post_notes:
type: string
post_selected:
type: boolean
post_open_comment:
type: boolean
post_open_tb:
type: boolean
post_tags:
type: array
description: post tags
dc_post:
type: object
properties:
post_id:
type: string
post_title:
type: string
post_format:
type: string
description: generally 'xhtml' or 'wiki'. If you put another value, not managed by Dotclear or a plugin, Fill in the post_content_xhtml field.
post_content:
type: string
description: The content on WhatYouWant format
post_content_xhtml:
type: string
description: If post_format is wiki or xhtml and not set, It will be generated from post_content
post_status:
type: string
enum:
- Pending
- Scheduled
- Unpublished
- Published
cat_id:
type: integer
new_cat_id:
type: string
description: If creating a new category, this is the only required cat_ field. If given cat_id must not be given
new_cat_parent_id:
type: integer
description: Only if new_cat_id is given
new_cat_desc:
type: string
description: the new category description.
new_cat_url:
type: string
description: the new category url
post_dt:
type: string
description: \'YY-MM-dd hh:mm:ss\' If not set, Current dateTime will be used.
post_password:
type: string
description: Don\'t set that value if your new post won\'t be protected
post_url:
type: string
description: If not set, will be created using the date and the post_titlke
post_lang:
type: string
description: If not set, User lang will be used
post_excerpt:
type: string
post_excerpt_xhtml:
type: string
description: If post_format is wiki or xhtml, It will be generated from post_excerpt
post_notes:
type: string
post_selected:
type: boolean
post_open_comment:
type: boolean
post_open_tb:
type: boolean
post_tags:
type: array
description: post tags
nb_comment:
type: integer
nb_trackback:
type: integer
post_firstpub:
type: string
metas:
type: array
items:
type: object
metas:
type: array
items:
type: object
category:
type: object
properties:
cat_id:
type: integer
cat_title:
type: string
cat_url:
type: string
cat_desc:
type: string
cat_position:
type: integer
cat_parent_id:
type: integer
temporary:
type: boolean
new_category:
type: object
required:
- cat_title
properties:
cat_title:
type: string
cat_url:
type: string
cat_desc:
type: string
cat_parent_id:
type: integer
cat_position:
type: integer
temporary:
type: boolean
Error:
type: object
properties:
code:
type: integer
format: int32
message:
type: string
fields:
type: string

@ -0,0 +1,150 @@
swagger: '2.0'
info:
title: Dotclear API
description: Manage your(s) blogs with this API
version: 0.0.2
host: dotclear.localhost
schemes:
- http
basePath: /dotclear/index.php?rest
produces:
- application/json
paths:
'/{blog_id}/settings':
get:
summary: 'Get the about:config'
description: Get all parameters
parameters:
- name: x_dc_key
in: header
type: string
required: true
- name: blog_id
in: path
type: string
required: true
responses:
'200':
description: OK
'404':
description: this blog id does not exists
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
'/{blog_id}/settings/{name_space}':
get:
summary: Get the settings inside the name-space
description: same
parameters:
- name: x_dc_key
in: header
type: string
required: true
- name: blog_id
in: path
type: string
required: true
- name: name_space
in: path
type: string
required: true
responses:
'200':
description: OK
'404':
description: this blog id does not exists
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
post:
summary: Create or edit a new namespace and or a new setting'
description: 'Let body empty if you just want to create a namespace without setting. Note that if the setting already exists, it will be erased. So, PUT and PATCH methods are useless.'
parameters:
- name: x_dc_key
in: header
type: string
required: true
- name: blog_id
in: path
type: string
required: true
- name: name_space
in: path
type: string
required: true
- name: setting
description: 'Can be empty, Can pass many settings. [{"id":"string","type":"string","value":"string","value_change":"string Optional","global":"bool optional"},{"id2":...}]'
in: body
schema:
$ref: '#/definitions/settings'
responses:
'201':
description: OK
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
'/{blog_id}/settings/{name_space}/{setting_id}':
get:
summary: Get value and type for one setting'
description: ''
parameters:
- name: x_dc_key
in: header
type: string
required: true
- name: blog_id
in: path
type: string
required: true
- name: name_space
in: path
type: string
required: true
- name: setting_id
in: path
type: string
required: true
responses:
'200':
description: OK
schema:
$ref: '#/definitions/OneSetting'
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
definitions:
OneSetting:
type: object
properties:
ns:
type: string
value:
type: string
type:
type: string
label:
type: string
global:
type: boolean
settings:
type: array
items:
type: object
Error:
type: object
properties:
code:
type: integer
format: int32
message:
type: string
fields:
type: string

@ -0,0 +1,55 @@
{
"swagger": "2.0",
"info": {
"title": "Dotclear API",
"description": "Manage your(s) blogs with this API",
"version": "0.0.2"
},
"host": "dotclear.localhost",
"schemes": [
"http"
],
"basePath": "/dotclear/index.php?rest",
"produces": [
"application/json"
],
"paths": {
"/specs": {
"get": {
"summary": "Get this API SWAGGER documentation",
"responses": {
"200": {
"description": "swagger.json",
"schema": {
"title": "doc",
"type": "string"
}
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
}
}
},
"definitions": {
"Error": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
},
"fields": {
"type": "string"
}
}
}
}
}

@ -0,0 +1,350 @@
{
"swagger": "2.0",
"info": {
"title": "Dotclear API",
"description": "Manage your(s) blogs with this API",
"version": "0.0.2"
},
"host": "dotclear.localhost",
"schemes": [
"http"
],
"basePath": "/dotclear/index.php?rest",
"produces": [
"application/json"
],
"paths": {
"/blogs": {
"get": {
"summary": "Get list of availables blogs",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"required": false,
"type": "string"
}
],
"responses": {
"200": {
"description": "array serving blogs properties",
"schema": {
"type": "array",
"items": {
"type": "string"
}
}
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
},
"post": {
"summary": "Create a new blog",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"type": "string",
"required": true
},
{
"name": "blog",
"in": "body",
"description": "The blog you want to create",
"schema": {
"$ref": "#/definitions/blog"
},
"required": true
}
],
"responses": {
"201": {
"description": "Success, array containing the new blog's identifiant",
"schema": {
"type": "object",
"properties": {
"code": {
"type": "integer"
},
"blog_id": {
"type": "integer"
},
"message": {
"type": "string"
}
}
}
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
}
},
"/blogs/{blog-id}": {
"get": {
"summary": "Get a blog poperties",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"type": "string",
"required": false
},
{
"name": "blog-id",
"in": "path",
"type": "string",
"required": true
}
],
"responses": {
"200": {
"description": "Core blog properties. use {blog_id}/settings methods for more settings.",
"schema": {
"$ref": "#/definitions/blogProperties"
}
},
"404": {
"description": "this blog id does not exists"
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
},
"patch": {
"summary": "Update part of blog properties",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"type": "string",
"required": true
},
{
"name": "blog-id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "blog",
"in": "body",
"description": "This list of parameters is not exhaustive",
"required": true,
"schema": {
"$ref": "#/definitions/blogProperties"
}
}
],
"responses": {
"200": {
"description": "array containing the edited blog's identifiant",
"schema": {
"$ref": "#/definitions/Ids"
}
},
"404": {
"description": "this blog id does not exists"
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
},
"put": {
"summary": "Overwrite blog Properties (if an optional parameter is not set, his value will be erased by the default value)",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"type": "string",
"required": true
},
{
"name": "blog-id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "blog",
"in": "body",
"description": "This list of parameters is not exhaustive",
"required": true,
"schema": {
"$ref": "#/definitions/blogPropertiesPut"
}
}
],
"responses": {
"200": {
"description": "array containing the edited blog's identifiant",
"schema": {
"$ref": "#/definitions/Ids"
}
},
"404": {
"description": "this blog id does not exists"
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
},
"delete": {
"summary": "Delete this blog",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"type": "string",
"required": true
},
{
"name": "blog-id",
"in": "path",
"type": "string",
"required": true
}
],
"responses": {
"200": {
"description": "array containing the deleted blog's identifiant",
"schema": {
"$ref": "#/definitions/Ids"
}
},
"404": {
"description": "this blog id does not exists"
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
}
}
},
"definitions": {
"blog": {
"type": "object",
"required": [
"blog_id",
"blog_name",
"blog_url"
],
"properties": {
"blog_id": {
"type": "string"
},
"blog_name": {
"type": "string"
},
"blog_url": {
"type": "string"
},
"blog_desc": {
"type": "string"
},
"lang": {
"type": "string"
},
"blog_timezone": {
"type": "string"
},
"url_scan": {
"type": "string",
"enum": [
"query_string",
"path_info"
]
}
}
},
"Ids": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"description": "New blog id"
}
}
},
"blogPropertiesPut": {
"required": [
"blog_id",
"blog_name",
"blog_url",
"blog_desc"
],
"type": "object",
"properties": {
"blog_id": {
"type": "string"
},
"blog_name": {
"type": "string"
},
"blog_url": {
"type": "string"
},
"blog_desc": {
"type": "string"
}
}
},
"blogProperties": {
"type": "object",
"properties": {
"blog_id": {
"type": "string"
},
"blog_name": {
"type": "string"
},
"blog_url": {
"type": "string"
},
"blog_desc": {
"type": "string"
}
}
},
"Error": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
},
"fields": {
"type": "string"
}
}
}
}
}

@ -0,0 +1,363 @@
{
"swagger": "2.0",
"info": {
"title": "Dotclear API Categories Method",
"description": "Search Create Update Delete Categories",
"version": "0.0.2"
},
"host": "dotclear.localhost",
"schemes": [
"http"
],
"basePath": "/dotclear/index.php?rest",
"produces": [
"application/json"
],
"paths": {
"/{blog-id}/categories": {
"get": {
"summary": "Get list of available categories",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"type": "string",
"required": false
},
{
"name": "blog-id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "filters",
"in": "query",
"type": "string",
"required": false,
"description": "UrlEncoded filters Separate each of them by a space ( \"+\" once urlencoded). Values are between double quotes Sample cat_title%3D%22SearchedTitle%22+cat_url%3D%22searched%2Furl%22 Available keys are \"cat_title\",\"cat_url\",\"cat_desc\", \"cat_level\",\"cat_parent_id\",\"cat_position\""
}
],
"responses": {
"200": {
"description": "array containing the categories properties",
"schema": {
"title": "categories",
"type": "array",
"items": {
"$ref": "#/definitions/category"
}
}
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
},
"post": {
"summary": "Create a new category",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"type": "string",
"required": true
},
{
"name": "blog-id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "properties",
"in": "body",
"description": "cat_position is facultative. If unset, the new category will have the last cat_position. If setted and position_permute false or unsetted; It will shift the following categories.",
"schema": {
"$ref": "#/definitions/new_category"
}
}
],
"responses": {
"200": {
"description": "array containing the created category id",
"schema": {
"$ref": "#/definitions/Ids"
}
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
}
},
"/{blog-id}/categories/{cat-id}": {
"get": {
"summary": "Get one category properties",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"type": "string",
"required": false
},
{
"name": "blog-id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "cat-id",
"in": "path",
"type": "string",
"required": true
}
],
"responses": {
"200": {
"description": "array containing the created category properties",
"schema": {
"$ref": "#/definitions/category"
}
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
},
"patch": {
"summary": "Update some attributes",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"type": "string"
},
{
"name": "blog-id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "cat-id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "category",
"in": "body",
"schema": {
"$ref": "#/definitions/patch_category"
}
}
],
"responses": {
"200": {
"description": "array containing the modified category id",
"schema": {
"$ref": "#/definitions/Ids"
}
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
},
"delete": {
"summary": "Delete a category",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"type": "string"
},
{
"name": "blog-id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "cat-id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "options",
"in": "body",
"description": "By default, all posts and subcategories contained on the deleted s one will be setted on the parent. If the category was a top level one, posts will be setted with no category, and subcategories will become top levels cat. However you can choose to put all of them on another category, or to delete them.",
"schema": {
"$ref": "#/definitions/delete_category"
}
}
],
"responses": {
"200": {
"description": "array containing Sucess message",
"schema": {
"$ref": "#/definitions/success"
}
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
}
}
},
"definitions": {
"Ids": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"description": "New blog id"
}
}
},
"category": {
"type": "object",
"description": "about the cat_position: The first position is 0. It's the relative postions with the same parent's child.",
"properties": {
"cat_id": {
"type": "integer"
},
"level": {
"type": "integer"
},
"cat_title": {
"type": "string"
},
"cat_url": {
"type": "string"
},
"cat_desc": {
"type": "string"
},
"cat_level": {
"type": "integer"
},
"cat_parent_id": {
"type": "integer"
},
"cat_position": {
"type": "integer"
}
}
},
"new_category": {
"type": "object",
"required": [
"cat_title"
],
"properties": {
"cat_title": {
"type": "string"
},
"cat_url": {
"type": "string"
},
"cat_desc": {
"type": "string"
},
"cat_parent_id": {
"type": "integer"
},
"cat_position": {
"type": "integer"
},
"position_permute": {
"type": "boolean"
},
"temporary": {
"type": "boolean"
}
}
},
"patch_category": {
"type": "object",
"properties": {
"cat_title": {
"type": "string"
},
"cat_url": {
"type": "string"
},
"cat_desc": {
"type": "string"
},
"cat_parent_id": {
"type": "integer"
},
"cat_position": {
"type": "integer"
},
"permute": {
"default": false,
"type": "boolean"
},
"temporary": {
"type": "boolean"
}
}
},
"delete_category": {
"type": "object",
"properties": {
"move_childs_on_cat_id": {
"type": "integer"
},
"delete_childs": {
"default": false,
"type": "boolean"
}
}
},
"Error": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
},
"fields": {
"type": "string"
}
}
},
"success": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
}
}
}
}
}

@ -0,0 +1,508 @@
{
"swagger": "2.0",
"info": {
"title": "Dotclear API Comments methods",
"description": "Search Create Update Delete comments",
"version": "0.0.2"
},
"host": "dotclear.localhost",
"schemes": [
"http"
],
"basePath": "/dotclear/index.php?rest",
"produces": [
"application/json"
],
"paths": {
"/{blog-id}/comments": {
"get": {
"summary": "Get list of comments",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"type": "string",
"required": false
},
{
"name": "blog-id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "filters",
"in": "query",
"type": "string",
"required": false
},
{
"name": "limits",
"in": "query",
"type": "string",
"required": false
}
],
"responses": {
"200": {
"description": "array containing the categories properties",
"schema": {
"title": "list of comments",
"type": "array",
"items": {
"$ref": "#/definitions/comments"
}
}
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
},
"delete": {
"summary": "Delete a list of comments",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"type": "string",
"required": false
},
{
"name": "blog-id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "list",
"in": "body",
"schema": {
"$ref": "#/definitions/list"
}
}
],
"responses": {
"200": {
"description": "array containing the categories properties",
"schema": {
"title": "list of comments",
"type": "array",
"items": {
"$ref": "#/definitions/comments"
}
}
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
}
},
"/{blog-id}/{post-id}/comments": {
"get": {
"summary": "Get list of comments for the given post",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"type": "string",
"required": false
},
{
"name": "blog-id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "post-id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "filters",
"in": "query",
"type": "string",
"required": false
},
{
"name": "limits",
"in": "query",
"type": "string",
"required": false
}
],
"responses": {
"200": {
"description": "array containing the categories properties",
"schema": {
"title": "list of comments",
"type": "array",
"items": {
"$ref": "#/definitions/comments"
}
}
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
},
"post": {
"summary": "Create a new comment",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"type": "string",
"required": true
},
{
"name": "blog-id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "post-id",
"in": "path",
"type": "integer",
"required": true
},
{
"name": "properties",
"in": "body",
"schema": {
"$ref": "#/definitions/new_comment"
}
}
],
"responses": {
"200": {
"description": "array containing the created category id",
"schema": {
"$ref": "#/definitions/Ids"
}
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
}
},
"/{blog-id}/comments/{comment-id}": {
"get": {
"summary": "Get one comment properties",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"type": "string",
"required": false
},
{
"name": "blog-id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "comment-id",
"in": "path",
"type": "integer",
"required": true
}
],
"responses": {
"200": {
"description": "array containing the created category properties",
"schema": {
"$ref": "#/definitions/comments"
}
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
},
"patch": {
"summary": "Update some attributes",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"type": "string"
},
{
"name": "blog-id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "comment-id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "cmooent",
"in": "body",
"schema": {
"$ref": "#/definitions/patch_comment"
}
}
],
"responses": {
"200": {
"description": "array containing the modified category id",
"schema": {
"$ref": "#/definitions/Ids"
}
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
},
"delete": {
"summary": "Delete a comment",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"type": "string"
},
{
"name": "blog-id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "comment-id",
"in": "path",
"type": "string",
"required": true
}
],
"responses": {
"200": {
"description": "array containing Sucess message",
"schema": {
"$ref": "#/definitions/success"
}
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
}
}
},
"definitions": {
"Ids": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"description": "New blog id"
}
}
},
"Error": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
},
"fields": {
"type": "string"
}
}
},
"list": {
"type": "array",
"items": {
"type": "string"
}
},
"patch_comment": {
"type": "object",
"properties": {
"comment_dt": {
"type": "string"
},
"comment_tz": {
"type": "string"
},
"comment_upddt": {
"type": "string"
},
"comment_author": {
"type": "string"
},
"comment_email": {
"type": "string"
},
"comment_site": {
"type": "string"
},
"comment_content": {
"type": "string"
},
"comment_words": {
"type": "string"
},
"comment_ip": {
"type": "string"
},
"comment_status": {
"type": "integer"
},
"comment_spam_status": {
"type": "integer"
},
"comment_spam_filter": {
"type": "integer"
},
"comment_trackback": {
"type": "integer"
}
}
},
"new_comment": {
"type": "object",
"properties": {
"comment_dt": {
"type": "string"
},
"comment_tz": {
"type": "string"
},
"comment_upddt": {
"type": "string"
},
"comment_author": {
"type": "string"
},
"comment_email": {
"type": "string"
},
"comment_site": {
"type": "string"
},
"comment_content": {
"type": "string"
},
"comment_words": {
"type": "string"
},
"comment_ip": {
"type": "string"
},
"comment_status": {
"type": "integer"
},
"comment_spam_status": {
"type": "integer"
},
"comment_spam_filter": {
"type": "integer"
},
"comment_trackback": {
"type": "integer"
}
}
},
"comments": {
"type": "object",
"properties": {
"comment_id": {
"type": "integer"
},
"post_id": {
"type": "integer"
},
"comment_dt": {
"type": "string"
},
"comment_tz": {
"type": "string"
},
"comment_upddt": {
"type": "string"
},
"comment_author": {
"type": "string"
},
"comment_email": {
"type": "string"
},
"comment_site": {
"type": "string"
},
"comment_content": {
"type": "string"
},
"comment_words": {
"type": "string"
},
"comment_ip": {
"type": "string"
},
"comment_status": {
"type": "integer"
},
"comment_spam_status": {
"type": "integer"
},
"comment_spam_filter": {
"type": "integer"
},
"comment_trackback": {
"type": "integer"
}
}
},
"success": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
}
}
}
}
}

@ -0,0 +1,360 @@
{
"swagger": "2.0",
"info": {
"title": "Dotclear API",
"description": "Manage your(s) blogs with this API",
"version": "0.0.2"
},
"host": "dotclear.localhost",
"schemes": [
"http"
],
"basePath": "/dotclear/index.php?rest",
"produces": [
"application/json"
],
"paths": {
"/{blog-id}/metas": {
"post": {
"summary": "Create a new Postr meta",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"type": "string",
"required": false
},
{
"name": "blog-id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "properties",
"in": "body",
"schema": {
"$ref": "#/definitions/new_meta"
}
}
],
"responses": {
"200": {
"description": "New meta id",
"schema": {
"title": "categories",
"type": "array",
"items": {
"type": "integer"
}
}
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
},
"get": {
"summary": "get metas",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"type": "string",
"required": false
},
{
"name": "blog-id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "post_id",
"in": "query",
"type": "string",
"required": false
},
{
"name": "meta_type",
"in": "query",
"type": "string",
"required": false
},
{
"name": "meta_id",
"in": "query",
"type": "string",
"required": false
}
],
"responses": {
"200": {
"description": "metas",
"schema": {
"title": "Metas",
"type": "array",
"items": {
"$ref": "#/definitions/meta"
}
}
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
}
},
"/{blog-id}/{post-id}/metas": {
"get": {
"summary": "get metas for a post",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"type": "string",
"required": false
},
{
"name": "blog-id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "post-id",
"in": "path",
"type": "integer",
"required": true
}
],
"responses": {
"200": {
"description": "Metas properties",
"schema": {
"title": "categories",
"type": "array",
"items": {
"$ref": "#/definitions/meta"
}
}
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
},
"delete": {
"summary": "Delete all metas for a given post",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"type": "string",
"required": false
},
{
"name": "blog-id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "post-id",
"in": "path",
"type": "integer",
"required": true
}
],
"responses": {
"200": {
"description": "succes messqge",
"schema": {
"title": "success message",
"type": "array",
"items": {
"$ref": "#/definitions/metas"
}
}
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
}
},
"/{blog-id}/{post-id}/meta/{meta-id}": {
"delete": {
"summary": "Delete a meta for a given POST",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"type": "string",
"required": false
},
{
"name": "blog-id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "post-id",
"in": "path",
"type": "integer",
"required": true
},
{
"name": "meta-id",
"in": "path",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "confirmqtion",
"schema": {
"title": "categories",
"type": "array",
"items": {
"$ref": "#/definitions/metas"
}
}
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
},
"patch": {
"summary": "Delete the meta with the given id and recreate one",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"type": "string",
"required": false
},
{
"name": "blog-id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "post-id",
"in": "path",
"type": "integer",
"required": true
},
{
"name": "meta-id",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "meta",
"in": "body",
"description": "This list of parameters is not exhaustive",
"required": true,
"schema": {
"$ref": "#/definitions/new_meta"
}
}
],
"responses": {
"200": {
"description": "confirmqtion",
"schema": {
"title": "categories",
"type": "array",
"items": {
"$ref": "#/definitions/metas"
}
}
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
}
}
},
"definitions": {
"new_meta": {
"required": [
"meta_id",
"meta_type",
"post_id"
],
"type": "object",
"properties": {
"meta_id": {
"type": "string"
},
"meta_type": {
"type": "string"
},
"post_id": {
"type": "integer"
}
}
},
"metas": {
"type": "array",
"items": {
"type": "object"
}
},
"meta": {
"type": "object",
"properties": {
"count": {
"type": "integer"
},
"meta_id": {
"type": "string"
},
"meta_type": {
"type": "string"
}
}
},
"Error": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
},
"fields": {
"type": "string"
}
}
}
}
}

@ -0,0 +1,586 @@
{
"swagger": "2.0",
"info": {
"title": "Dotclear API - manage posts",
"description": "SCRUD Posts entrys",
"version": "0.0.2"
},
"host": "dotclear.localhost",
"schemes": [
"http"
],
"basePath": "/dotclear/index.php?rest",
"produces": [
"application/json"
],
"paths": {
"/{blog-id}/posts": {
"get": {
"summary": "Get list of posts",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"type": "string",
"required": true
},
{
"name": "blog-id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "limit-start",
"in": "query",
"required": false,
"type": "integer"
},
{
"name": "limit-count",
"in": "query",
"type": "integer",
"required": false
},
{
"name": "cat_id",
"in": "query",
"type": "string",
"required": false
},
{
"name": "post_status",
"type": "string",
"in": "query",
"required": false
},
{
"name": "password",
"type": "string",
"in": "query",
"required": false
},
{
"name": "post_selected",
"type": "boolean",
"in": "query",
"required": false
},
{
"name": "post_open_comment",
"type": "boolean",
"in": "query",
"required": false
},
{
"name": "post_open_tb",
"type": "boolean",
"in": "query",
"required": false
},
{
"name": "post_month",
"type": "string",
"in": "query",
"required": false
},
{
"name": "post_year",
"type": "string",
"in": "query",
"required": false
},
{
"name": "post_lang",
"type": "string",
"in": "query",
"required": false
},
{
"name": "post_format",
"type": "string",
"in": "query",
"required": false
},
{
"name": "sortby",
"type": "string",
"in": "query",
"required": false,
"description": "If many, separate them by a comma"
}
],
"responses": {
"200": {
"description": "list of posts",
"schema": {
"title": "posts",
"type": "array",
"items": {
"$ref": "#/definitions/dc_post"
}
}
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
}
},
"/{blog-id}/post": {
"post": {
"summary": "Create a new post",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"type": "string",
"required": true
},
{
"name": "blog-id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "properties",
"in": "body",
"description": "Some non required fields you don't define will be set (default value) by the API. You can post many posts once by putting them on an array like [{'post_title':'blah',...},{'post_title':'bluh',...}]",
"schema": {
"$ref": "#/definitions/new_dc_post"
}
}
],
"responses": {
"200": {
"description": "Id of newly created post",
"schema": {
"$ref": "#/definitions/Ids"
}
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
}
},
"/{blog-id}/post/{post-id}": {
"get": {
"summary": "Get a post entry",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"type": "string",
"required": false
},
{
"name": "blog-id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "post-id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "fields",
"in": "query",
"type": "array",
"items": {
"type": "string"
},
"required": false,
"description": "Fields you want to get. If unset, all available fields will be get."
}
],
"responses": {
"200": {
"description": "The post values",
"schema": {
"$ref": "#/definitions/dc_post"
}
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
},
"patch": {
"summary": "Not yet developed Update part of a post entry's properties",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"type": "string",
"required": true
},
{
"name": "blog-id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "post-id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "properties",
"in": "body",
"schema": {
"$ref": "#/definitions/dc_post"
}
}
],
"responses": {
"200": {
"description": "array containing the updated post's id",
"schema": {
"$ref": "#/definitions/Ids"
}
},
"404": {
"description": "this post does not exists"
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
},
"put": {
"summary": "Not yet developed Update full blog properties. Unsetted parameters will be erased",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"type": "string",
"required": true
},
{
"name": "blog-id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "post-id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "properties",
"in": "body",
"schema": {
"$ref": "#/definitions/new_dc_post"
}
}
],
"responses": {
"200": {
"description": "array containing the updated post's id",
"schema": {
"$ref": "#/definitions/Ids"
}
},
"404": {
"description": "this post does not exists"
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
},
"delete": {
"summary": "Not yet developed Delete the post",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"type": "string",
"required": true
},
{
"name": "blog-id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "post-id",
"in": "path",
"type": "string",
"required": true
}
],
"responses": {
"200": {
"description": "array containing the deleted post's id",
"schema": {
"$ref": "#/definitions/Ids"
}
},
"404": {
"description": "this post does not exists"
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
}
}
},
"definitions": {
"Ids": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"description": "New blog id"
}
}
},
"new_dc_post": {
"type": "object",
"required": [
"post_format",
"post_status",
"post_content",
"post_title"
],
"properties": {
"post_title": {
"type": "string"
},
"post_format": {
"type": "string",
"description": "generally 'xhtml' or 'wiki'. If you put another value, not managed by Dotclear or a plugin, Fill in the post_content_xhtml field."
},
"post_content": {
"type": "string",
"description": "The content on WhatYouWant format"
},
"post_content_xhtml": {
"type": "string",
"description": "If post_format is wiki or xhtml and not set, It will be generated from post_content"
},
"post_status": {
"type": "string",
"enum": [
"Pending",
"Scheduled",
"Unpublished",
"Published"
]
},
"cat_id": {
"type": "integer"
},
"new_cat_title": {
"type": "string",
"description": "If creating a new category, this is the only required cat_ field. If given cat_id must not be given"
},
"new_cat_parent_id": {
"type": "integer",
"description": "Only if new_cat_id is given"
},
"new_cat_position": {
"type": "integer",
"description": "the new cat position relative to the brothers (same level) categories"
},
"new_cat_desc": {
"type": "string",
"description": "the new category description."
},
"new_cat_url": {
"type": "string",
"description": "the new category url"
},
"post_dt": {
"type": "string",
"description": "\\'YY-MM-dd hh:mm:ss\\' If not set, Current dateTime will be used."
},
"post_password": {
"type": "string",
"description": "Don\\'t set that value if your new post won\\'t be protected"
},
"post_url": {
"type": "string",
"description": "If not set, will be created using the date and the post_titlke"
},
"post_lang": {
"type": "string",
"description": "If not set, User lang will be used"
},
"post_excerpt": {
"type": "string"
},
"post_excerpt_xhtml": {
"type": "string",
"description": "If post_format is wiki or xhtml, It will be generated from post_excerpt"
},
"post_notes": {
"type": "string"
},
"post_selected": {
"type": "boolean"
},
"post_open_comment": {
"type": "boolean"
},
"post_open_tb": {
"type": "boolean"
},
"post_tags": {
"type": "array",
"description": "post tags"
}
}
},
"dc_post": {
"type": "object",
"properties": {
"post_id": {
"type": "string"
},
"post_title": {
"type": "string"
},
"post_format": {
"type": "string",
"description": "generally 'xhtml' or 'wiki'. If you put another value, not managed by Dotclear or a plugin, Fill in the post_content_xhtml field."
},
"post_content": {
"type": "string",
"description": "The content on WhatYouWant format"
},
"post_content_xhtml": {
"type": "string",
"description": "If post_format is wiki or xhtml and not set, It will be generated from post_content"
},
"post_status": {
"type": "string",
"enum": [
"Pending",
"Scheduled",
"Unpublished",
"Published"
]
},
"cat_id": {
"type": "integer"
},
"new_cat_id": {
"type": "string",
"description": "If creating a new category, this is the only required cat_ field. If given cat_id must not be given"
},
"new_cat_parent_id": {
"type": "integer",
"description": "Only if new_cat_id is given"
},
"new_cat_desc": {
"type": "string",
"description": "the new category description."
},
"new_cat_url": {
"type": "string",
"description": "the new category url"
},
"post_dt": {
"type": "string",
"description": "\\'YY-MM-dd hh:mm:ss\\' If not set, Current dateTime will be used."
},
"post_password": {
"type": "string",
"description": "Don\\'t set that value if your new post won\\'t be protected"
},
"post_url": {
"type": "string",
"description": "If not set, will be created using the date and the post_titlke"
},
"post_lang": {
"type": "string",
"description": "If not set, User lang will be used"
},
"post_excerpt": {
"type": "string"
},
"post_excerpt_xhtml": {
"type": "string",
"description": "If post_format is wiki or xhtml, It will be generated from post_excerpt"
},
"post_notes": {
"type": "string"
},
"post_selected": {
"type": "boolean"
},
"post_open_comment": {
"type": "boolean"
},
"post_open_tb": {
"type": "boolean"
},
"post_tags": {
"type": "array",
"description": "post tags"
},
"nb_comment": {
"type": "integer"
},
"nb_trackback": {
"type": "integer"
},
"post_firstpub": {
"type": "string"
},
"metas": {
"type": "array",
"items": {
"type": "object"
}
}
}
},
"Error": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
},
"fields": {
"type": "string"
}
}
}
}
}

@ -0,0 +1,224 @@
{
"swagger": "2.0",
"info": {
"title": "Dotclear API",
"description": "Manage your(s) blogs with this API",
"version": "0.0.2"
},
"host": "dotclear.localhost",
"schemes": [
"http"
],
"basePath": "/dotclear/index.php?rest",
"produces": [
"application/json"
],
"paths": {
"/{blog_id}/settings": {
"get": {
"summary": "Get the about:config",
"description": "Get all parameters",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"type": "string",
"required": true
},
{
"name": "blog_id",
"in": "path",
"type": "string",
"required": true
}
],
"responses": {
"200": {
"description": "OK"
},
"404": {
"description": "this blog id does not exists"
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
}
},
"/{blog_id}/settings/{name_space}": {
"get": {
"summary": "Get the settings inside the name-space",
"description": "same",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"type": "string",
"required": true
},
{
"name": "blog_id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "name_space",
"in": "path",
"type": "string",
"required": true
}
],
"responses": {
"200": {
"description": "OK"
},
"404": {
"description": "this blog id does not exists"
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
},
"post": {
"summary": "Create or edit a new namespace and or a new setting'",
"description": "Let body empty if you just want to create a namespace without setting. Note that if the setting already exists, it will be erased. So, PUT and PATCH methods are useless.",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"type": "string",
"required": true
},
{
"name": "blog_id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "name_space",
"in": "path",
"type": "string",
"required": true
},
{
"name": "setting",
"description": "Can be empty, Can pass many settings. [{\"id\":\"string\",\"type\":\"string\",\"value\":\"string\",\"value_change\":\"string Optional\",\"global\":\"bool optional\"},{\"id2\":...}]",
"in": "body",
"schema": {
"$ref": "#/definitions/settings"
}
}
],
"responses": {
"201": {
"description": "OK"
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
}
},
"/{blog_id}/settings/{name_space}/{setting_id}": {
"get": {
"summary": "Get value and type for one setting'",
"description": "",
"parameters": [
{
"name": "x_dc_key",
"in": "header",
"type": "string",
"required": true
},
{
"name": "blog_id",
"in": "path",
"type": "string",
"required": true
},
{
"name": "name_space",
"in": "path",
"type": "string",
"required": true
},
{
"name": "setting_id",
"in": "path",
"type": "string",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/OneSetting"
}
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
}
}
},
"definitions": {
"OneSetting": {
"type": "object",
"properties": {
"ns": {
"type": "string"
},
"value": {
"type": "string"
},
"type": {
"type": "string"
},
"label": {
"type": "string"
},
"global": {
"type": "boolean"
}
}
},
"settings": {
"type": "array",
"items": {
"type": "object"
}
},
"Error": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
},
"fields": {
"type": "string"
}
}
}
}
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,817 @@
<?php
class RestCategories
{
/*
* Don't expose Nested tree algorithm via the API
* First goal of this class is to convert structure id|left|right
* to - a less optimized but simpliest - way of use id|parent_id|position
*/
/*
* base structure is
mysql> describe dc_category;
+--------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+-------+
| cat_id | bigint(20) | NO | PRI | NULL | |
| blog_id | varchar(32) | NO | MUL | NULL | |
| cat_title | varchar(255) | NO | | NULL | |
| cat_url | varchar(255) | NO | MUL | NULL | |
| cat_desc | longtext | YES | | NULL | |
| cat_position | int(11) | YES | | 0 Unused (by dotclear) field
| cat_lft | int(11) | YES | | NULL | |
| cat_rgt | int(11) | YES | | NULL | |
+--------------+--------------+------+-----+---------+-------+
8 rows in set (0.00 sec)
*/
public $cats; //Array structured like:
/* [
{
"cat_id": 4,
"cat_title": "trololo",
"cat_url": "trololo",
"cat_desc": "",
"cat_level": 0,
"cat_parent_id": null,
"cat_position": 0
},
{
"cat_id": 6,
"cat_title": "child",
"cat_url": "trololo/child",
"cat_desc": "",
"cat_level": 1,
"cat_parent_id": 4,
"cat_position": 0
},
*/
protected $catsLftRgt;
protected $blog_id;
protected $core;
protected $table;
protected $con;
protected function getNextInsertCatId(){
$sql = "SELECT max(cat_id) as nextId FROM ".$this->table." ;";
$rs = $this->con->select($sql);
$rs->fetch();
return (int)($rs->nextId) +1;
}
/*
* build part of url like
* parent/sub/category
*/
protected function generateCatUrl($title,$cat_lft){
//Select all parents
$sql = "SELECT cat_title
FROM " .$this->table . "
WHERE blog_id='". $this->con->escape($this->blog_id) . "'
AND cat_lft < '" . $cat_lft ."'
AND cat_rgt > '" . $cat_lft ."'
ORDER BY cat_lft ASC";
$rs = $this->con->select($sql);
$urlParts =array();
while($rs->fetch()){
$urlParts[] = text::tidyURL($rs->cat_title,false);
}
$urlParts[] = text::tidyURL($title);
return implode("/",$urlParts);
}
/*
* $params keys can be:
* 'cat_title','cat_url','cat_desc',
* 'cat_parent_id','cat_position','temporary'
*/
public function updateCategory($cat_id,$params){
$valuesToChange = array();
if(isset($params['cat_title'])){
$valuesToChange[] = "cat_title = '". $this->con->escape($params['cat_title']) . "'";
}
if(isset($params['cat_url'])){
$valuesToChange[] = "cat_url = '". $this->con->escape($params['cat_url']). "'";
}
if(isset($params['cat_desc'])){
$valuesToChange[] = "cat_desc = '". $this->con->escape($params['cat_desc']). "'";
}
if(count($valuesToChange) > 0){
//do the update
$sql = "UPDATE ".$this->table."
SET ".implode(",",$valuesToChange)."
WHERE blog_id='". $this->con->escape($this->blog_id) . "'
AND cat_id= '". $this->con->escape($cat_id)."';";
$this->con->execute($sql);
}
if(
(isset($params['cat_position']))
OR (isset($params['cat_parent_id']))
){
//changement de position
$cat_position = (isset($params['cat_position']))? $params['cat_position'] : null;
$cat_parent_id = (isset($params['cat_parent_id']))? $params['cat_parent_id'] : null;
$permute=(isset($params['permute']))? $params['permute']:false;
$this->changePosition($cat_id,$cat_parent_id,$cat_position,$permute);
}
}
/*
* return the actual cat_left for a parent and a position given
* If cat is a top level one. set $parent to null
* in position doesn't exists the last position will be returned
* IN $parent_id: integer, $position: integer
* OUT: integer
*/
protected function getCatLeft($parent_id,$position){
if((is_null($parent_id)) && (is_null($position))){
//on met la categorie après la dernière position
$sql = "SELECT max(cat_rgt) AS max FROM ".$this->table."
WHERE blog_id='". $this->con->escape($this->blog_id) . "';";
$rs = $this->con->select($sql);
if($rs->max == null){
return 1; //it's the first category, there's no other
}else{
return $rs->max + 1;
}
}
if(!is_null($position)){
foreach($this->catsLftRgt as $cat){
if(($cat['cat_parent_id'] == $parent_id)
&&($cat['cat_position'] == $position)){
return $cat['cat_lft'];
}
}
}
//position not found return the parent cat_rgt
$sql = "SELECT cat_rgt FROM ".$this->table."
WHERE blog_id='" . $this->con->escape($this->blog_id) . "'
AND cat_id='". $this->con->escape($parent_id)."';";
$rs = $this->con->select($sql);
if(!$rs->cat_rgt){
//ce cas ne devrait jamais se produire
error_log("something wrong on RestCategories::getCatLeft ".$parent_id."|".$position);
return false;
}else{
return $rs->cat_rgt;
}
}
/*
* permute two categories positions
*/
public function permutePosition($cat1_id,$cat2_id){
$twoCats = array();
foreach($this->calsLftRgt as $cat){
if(($cat['cat_id'] == $cat1_id)
||($cat['cat_id'] == $cat2_id))
{
$twoCats[] = $cat;
}
}
if(count($twoCats) <> 2){
//At least one of the two cats was not found
return false;
}
if($twoCats[0]['cat_lft'] > $twoCats[1]['cat_lft']){
//inverser l'ordre
$twoCats[2] = $twoCats[0];
$twoCats[0] = $twoCats[1];
$twoCats[1] = $twoCats[2];
unset($twoCats[2]);
}
try{
$this->con->begin();
//grow or reduce cat1 parents, if not the sames
if($twoCats[0]['cat_parent_id'] <> $twoCats[1]['cat_parent_id']){
$dif = $twoCats[1]['cat_rgt'] - $twoCats[1]['cat_lft']
- $twoCats[0]['cat_rgt'] + $twoCats[0]['cat_lft'];
if($dif > 0){
$sql = "UPDATE ".$this->table."
SET cat_rgt = cat_rgt + ".$dif."
WHERE blog_id='" . $this->con->escape($this->blog_id) . "'
AND cat_lft < ".$twoCats[0]['cat_lft']."
AND cat_rgt > ".$twoCats[0]['cat_lft'].";";
$this->con->execute($sql);
}elseif($dif < 0){
$sql = "UPDATE ".$this->table."
SET cat_rgt = cat_rgt - ".abs($dif)."
WHERE blog_id='" . $this->con->escape($this->blog_id) . "'
AND cat_lft < ".$twoCats[0]['cat_lft']."
AND cat_rgt > ".$twoCats[0]['cat_lft'].";";
$this->con->execute($sql);
}else{
//dif == 0 do nothing
}
}
//shift cat
if($dif > 0){
$sql = "UPDATE ".$this->table."
SET cat_lft = cat_lft + ".$dif.",
cat_rgt = cat_rgt + ".$dif."
WHERE blog_id='" . $this->con->escape($this->blog_id) . "'
AND cat_lft > ".$twoCats[0]['cat_lft'].";";
$this->con->execute($sql);
}elseif($dif < 0){
$sql = "UPDATE ".$this->table."
SET cat_lft = cat_lft + ".$dif.",
cat_rgt = cat_rgt + ".$dif."
WHERE blog_id='" . $this->con->escape($this->blog_id) . "'
AND cat_lft > ".$twoCats[0]['cat_lft'].";";
$this->con->execute($sql);
}else{
//dif == 0 do nothing
}
//mémoriser le nouveau cat_lft de la cat 2
$sql = "SELECT cat_lft,cat_rgt FROM ".$this->table."
WHERE blog_id='" . $this->con->escape($this->blog_id) . "'
AND cat_id='".$this->con->escape($cat2_id)."'";
$rs = $this->con->select($sql);
$rs->fetch();
$cat2_cat_lft = $rs->cat_lft;
$cat2_cat_rgt = $rs->cat_rgt;
//déplacer la cat 2
$sql = "UPDATE ".$this->table."
SET cat_lft=".$twoCats[0]['cat_lft'].",
cat_rgt=". (int)($twoCats[0]['cat_lft'] + $twoCats[1]['cat_rgt'] - $twoCats[1]['cat_lft'])."
WHERE blog_id='" . $this->con->escape($this->blog_id) . "'
AND cat_id='".$this->con->escape($cat2_id)."'";
$this->con->execute($sql);
//faire la place autour
//grow parents
//grow or reduce cat2 parents, if not the sames
if($twoCats[0]['cat_parent_id'] <> $twoCats[1]['cat_parent_id']){
$dif = $twoCats[0]['cat_rgt'] - $twoCats[0]['cat_lft']
- $twoCats[1]['cat_rgt'] + $twoCats[1]['cat_lft'];
if($dif > 0){
$sql = "UPDATE ".$this->table."
SET cat_rgt = cat_rgt + ".$dif."
WHERE blog_id='" . $this->con->escape($this->blog_id) . "'
AND cat_lft < ".$cat2_cat_lft."
AND cat_rgt > ".$cat2_cat_lft.";";
$this->con->execute($sql);
}elseif($dif < 0){
$sql = "UPDATE ".$this->table."
SET cat_rgt = cat_rgt - ".abs($dif)."
WHERE blog_id='" . $this->con->escape($this->blog_id) . "'
AND cat_lft < ".$cat2_cat_lft."
AND cat_rgt > ".$cat2_cat_lft.";";
$this->con->execute($sql);
}else{
//dif == 0 do nothing
}
}
//décaler
if($dif > 0){
$sql = "UPDATE ".$this->table."
SET cat_lft = cat_lft + ".$dif.",
cat_rgt = cat_rgt + ".$dif."
WHERE blog_id='" . $this->con->escape($this->blog_id) . "'
AND cat_lft > ".$cat2_cat_lft.";";
$this->con->execute($sql);
}elseif($dif < 0){
$sql = "UPDATE ".$this->table."
SET cat_lft = cat_lft + ".$dif.",
cat_rgt = cat_rgt + ".$dif."
WHERE blog_id='" . $this->con->escape($this->blog_id) . "'
AND cat_lft > ".$cat2_cat_lft.";";
$this->con->execute($sql);
}else{
//dif == 0 do nothing
}
//move cat 2
$sql = "UPDATE ".$this->table."
SET cat_lft=".$cat2_cat_lft.",
cat_rgt=". (int)($cat2_cat_lft + $twoCats[0]['cat_rgt'] - $twoCats[0]['cat_lft'])."
WHERE blog_id='" . $this->con->escape($this->blog_id) . "'
AND cat_id='".$this->con->escape($cat2_id)."'";
$this->con->execute($sql);
$this->con->commit();
}catch (Exception $e) {
$this->con->rollback();
error_log($e);
return false;
}
//refresh the array after changes
$this->__construct($this->core);
return true;
}
/*
* Change the categorie position
* Facultative: $permute -> will permute position with an existing category
* else shift if needed brother categories
*/
public function changePosition($cat_id, $new_parent_id, $new_cat_position, $permute = false){
if($permute){
//find the cat_id
return $this->permute($cat_id, $new_parent_id, $new_cat_position);
}
try
{
$this->con->begin();
$currentCatKey = array_search($cat_id, array_column($this->catsLftRgt, 'cat_id'));
if(!$currentCatKey){
return false;
}
$currentCat = $this->catsLftRgt[$currentCatKey];
$currentCatWidth = $currentCat['cat_rgt'] - $currentCat['cat_lft'] + 1;
if($new_parent_id == null){
$new_parent_id = $currentCat["cat_parent_id"];
}
if($new_parent_id !== null){
$parentCatKey = array_search($new_parent_id, array_column($this->catsLftRgt, 'cat_id'));
$parentCat = $this->catsLftRgt[$parentCatKey];
}
//find the future cat_lft
$new_cat_left = $this->getCatLeft($new_parent_id,$new_cat_position);
//reduce actuals parents
if(!is_null($currentCat['cat_parent_id'])){
$sql = "UPDATE ".$this->table."
SET cat_rgt = cat_rgt - ".$currentCatWidth."
WHERE blog_id='". $this->con->escape($this->blog_id) . "'
AND cat_lft < ".$currentCat['cat_lft']."
AND cat_rgt > ".$currentCat['cat_lft'].";";
$this->con->execute($sql);
}
//shift all
$sql = "UPDATE ".$this->table."
SET cat_lft = cat_lft - ".$currentCatWidth.",
cat_rgt = cat_rgt - ".$currentCatWidth."
WHERE blog_id='". $this->con->escape($this->blog_id) . "'
AND cat_lft > " . $currentCat['cat_lft'].";";
$this->con->execute($sql);
//augmenter les nouveaux parents
if(!is_null($new_parent_id)){
$sql = "UPDATE ".$this->table."
SET cat_rgt = cat_rgt + ".$currentCatWidth."
WHERE blog_id='". $this->con->escape($this->blog_id) . "'
AND cat_lft < ".$new_cat_left."
AND cat_rgt > ".$new_cat_left.";";
$this->con->execute($sql);
}
//tout décaler again
$sql = "UPDATE ".$this->table."
SET cat_lft = cat_lft + ".$currentCatWidth.",
cat_rgt = cat_rgt + ".$currentCatWidth."
WHERE blog_id='". $this->con->escape($this->blog_id) . "'
AND cat_lft >= ".$new_cat_left.";";
$this->con->execute($sql);
//enregistrer les nouveaux cat_lft et cat_rgt
$sql = "UPDATE ".$this->table."
SET cat_lft ='".$new_cat_left."',
cat_rgt ='". ($new_cat_left + $currentCatWidth -1) . "'
WHERE blog_id='". $this->con->escape($this->blog_id) . "'
AND cat_id='".$currentCat['cat_id']."';";
$this->con->execute($sql);
$this->con->commit();
//refresh the array after changes
$this->__construct($this->core);
return true;
}catch (Exception $e) {
$this->con->rollback();
error_log($e);
return false;
}
}
public function addCategory($params){
// /!\ cat_id is cat_title
if(!isset($params['cat_title'])){ //the only mandatory field
return false;
}
$this->con->writeLock($this->table);
try
{
if(isset($params['cat_position'])){
$cat_position = $params['cat_position'];
}else{
$cat_position = null;
}
if(isset($params['cat_parent_id'])){
$cat_parent_id = $params['cat_parent_id'];
//tester s'il existe
if($this->getCatProperties($cat_parent_id) === false){
return false;
}
}else{
$cat_parent_id = null;
}
$cat_lft = $this->getCatLeft($cat_parent_id,$cat_position);
//add +2 on parents cat-rgt to grown them
$sql = "UPDATE ".$this->table."
SET cat_rgt = cat_rgt + 2
WHERE blog_id='". $this->con->escape($this->blog_id) . "'
AND cat_lft < '" . $cat_lft . "'
AND cat_rgt >= '" . $cat_lft . "';";
$this->con->execute($sql);
//Add +2 on cat_lft and cat_rgt when cat_lft is > in order to shift cats
$sql = "UPDATE ".$this->table."
SET cat_rgt = cat_rgt + 2,
cat_lft = cat_lft + 2
WHERE blog_id='". $this->con->escape($this->blog_id) . "'
AND cat_lft >= '" . $cat_lft . "';";
$this->con->execute($sql);
//Let's insert the new catégorie:
if(empty($params['cat_url'])){
$new_cat_url = $this->generateCatUrl($params['cat_title'], $cat_lft);
}else{
$new_cat_url = $params['cat_url'];
}
$new_cat_id = $this->getNextInsertCatId();
$cur = $this->con->openCursor($this->core->prefix.'category');
$cur->cat_id = $this->getNextInsertCatId();
$cur->blog_id = $this->con->escape($this->blog_id);
$cur->cat_title = $params['cat_title'];
$cur->cat_url = $new_cat_url;
if(isset($params['cat_desc'])){
$cur->cat_desc = $params['cat_desc'];
}else{
$cur->cat_desc = "";
}
$cur->cat_lft = $cat_lft;
$cur->cat_rgt = $cat_lft + 1;
$this->core->callBehavior('coreBeforeCategoryCreate',$this->core,$cur);
if($cur->insert()){
$this->con->unlock();
$this->core->callBehavior('coreAfterCategoryCreate',$this->core,$cur);
return $new_cat_id;
}else{
$this->con->unlock();
//refresh the array after changes
$this->__construct($this->core);
return false;
}
}catch (Exception $e) {
$this->con->unlock();
error_log($e);
return false;
}
}
/*
* Return filtered categories
*/
public function getCats($filters){
$cats = array();
foreach($this->cats as $cat){
$ok = true;
foreach($filters as $key => $value){
if($value !== $cat[$key]){
$ok = false;
break;
}
}
if($ok){
$cats[] = $cat;
}
}
return $cats;
}
public function getCatProperties($cat_id){
foreach($this->cats as $cat){
if($cat['cat_id'] == $cat_id){
return $cat;
}
}
return false;
}
public function moveChilds($cat_from_id,$cat_dest_id,$deleteOriginCat = false)
{
//$cat_from ne doit pas être null
if(is_null($cat_from_id)){
return false;
}
//Si cat_dest_id est null, l'user veut transformer les enfants en categories de premier niveau
if(is_null($cat_dest_id)){
//to do
return;
}
$sql = "SELECT cat_lft,cat_rgt
FROM ".$this->table."
WHERE blog_id='".$this->con->escape($this->blog_id)."'
AND cat_id='".$this->con->escape($this->$cat_from_id)."';";
$rs = $this->con->execute($sql);
$rs->fetch();
$origin_cat_lft = $rs->cat_lft;
$origin_cat_rgt = $rs->cat_rgt;
$sql = "SELECT cat_lft,cat_rgt
FROM ".$this->table."
WHERE blog_id='".$this->con->escape($this->blog_id)."'
AND cat_id='".$this->con->escape($this->$cat_dest_id)."';";
$rs = $this->con->execute($sql);
$rs->fetch();
$dest_cat_lft = $rs->cat_lft;
$dest_cat_rgt = $rs->cat_rgt;
//la categorie de destination ne peut pas être un enfant de celle d'origine
if(($origin_cat_lft < $dest_cat_lft) && ($origin_cat_rgt < $dest_cat_lft)){
return false;
}
$this->con->begin();
try{
//agrandir la categorie de destination
$sql = "UPDATE ".$this->table."
SET cat_rgt = cat_rgt + ".(int)( $origin_cat_rgt - $origin_cat_lft )."
WHERE blog_id='".$this->con->escape($this->blog_id)."'
AND cat_id='".$this->con->escape($this->$cat_dest_id)."';";
$this->con->execute($sql);
//déplacer tout ce qui doit l'être suite à cet aggrandissement
$sql = "UPDATE ".$this->table."
SET cat_lft = cat_lft + ".(int)( $origin_cat_rgt - $origin_cat_lft )."
cat_rgt = cat_rgt + ".(int)( $origin_cat_rgt - $origin_cat_lft )."
WHERE blog_id='".$this->con->escape($this->blog_id)."'
AND cat_lft >".$dest_cat_rgt.";";
$this->con->execute($sql);
//si la categorie d'origine était après, elle vient d'etre déplacée
//mettre à jour sa position
if($origin_cat_lft > $dest_cat_lft){
$of= $origin_cat_lft;
$origin_cat_lft = $origin_cat_rgt;
$origin_cat_rgt = $origin_cat_rgt + $origin_cat_rgt - $of;
}
//déplacer les categories enfants
if($dest_cat_rgt > $origin_cat_lft){
//addition
$sql = "UPDATE ".$this->table."
SET cat_lft = cat_lft + ".(int)($dest_cat_rgt - $origin_cat_lft).",
cat_rgt = cat_rgt + ".(int)($dest_cat_rgt - $origin_cat_lft)."
WHERE blog_id='".$this->con->escape($this->blog_id)."'
AND cat_lft BETWEEN ".$origin_cat_lft." AND ".$origin_cat_rgt.";";
$this->con->execute($sql);
}else{
//soustraction
$sql = "UPDATE ".$this->table."
SET cat_lft = cat_lft - ".(int)($origin_cat_lft - $dest_cat_rgt).",
cat_rgt = cat_rgt + ".(int)($origin_cat_lft - $dest_cat_rgt)."
WHERE blog_id='".$this->con->escape($this->blog_id)."'
AND cat_lft BETWEEN ".$origin_cat_lft." AND ".$origin_cat_rgt.";";
$this->con->execute($sql);
}
$dest_cat_rgt = $dest_cat_rgt + $origin_cat_rgt - $origin_cat_lft;
if($deleteOriginCat){
$sql = "DELETE FROM ".$this->table."
WHERE blog_id='".$this->con->escape($this->blog_id)."'
AND cat_id='".$this->con->escape($this->$cat_from_id)."';";
$this->con->execute($sql);
$unShiftSteps = $origin_cat_rgt - $origin_cat_rgt + 1;
}else{
//reduire la cat d'origine
$sql = "UPDATE ".$this->table."
SET cat_rgt= cat_lft + 1
WHERE blog_id='".$this->con->escape($this->blog_id)."'
AND cat_id='".$this->con->escape($this->$cat_from_id)."';";
$this->con->execute($sql);
$unShiftSteps = $origin_cat_rgt - $origin_cat_rgt - 1;
}
//Décaller
$sql = "UPDATE ".$this->table."
SET cat_lft = cat_lft - ". $unShiftSteps .",
cat_rgt = cat_rgt - ". $unShiftSteps ."
WHERE blog_id='".$this->con->escape($this->blog_id)."'
AND cat_lft > ".$origin_cat_lft.";";
$this->con->execute($sql);
$this->con->commit();
}catch (Exception $e) {
$this->con->rollback();
error_log($e);
return false;
}
}
protected function getCatLftRgt($cat_id){
foreach($this->catsLftRgt as $cat){
if($cat['cat_id'] == $cat_id){
return $cat;
}
}
return false;
}
/*
* Delete the given category
* And reorganize the orders of the categories
* /!\ this function does not care about chields posts
*/
public function deleteCategory($cat_id,$deleteSubs = false)
{
$this->con->begin();
try{
if($deleteSubs){
//delete subs cats
$sql = "DELETE subs.* FROM
".$this->table." AS subs,
".$this->table." AS parent
WHERE subs.blog_id='".$this->con->escape($this->blog_id)."'
AND parent.cat_id='".$this->con->escape($cat_id)."'
AND subs.cat_lft BETWEEN parent.cat_lft AND parent.cat_rgt;";
$this->con->execute($sql);
//unshift followin cats before delete it
$sql = "UPDATE
".$this->table." followings,
".$this->table." parent
SET
followings.cat_lft = followings.cat_lft - parent.cat_lft - 1,
followings.cat_rgt = followings.cat_rgt - parent.cat_lft - 1
WHERE
followings.blog_id='".$this->con->escape($this->blog_id)."'
AND parent.cat_id='".$this->con->escape($cat_id)."'
AND followings.cat_lft > parent.cat_lft;";
$this->con->execute($sql);
}else{
//chields cats will be upped
//unshift cats
$sql = "UPDATE
".$this->table." cats,
".$this->table." parent
SET
cats.cat_lft = CASE WHEN cats.cat_lft BETWEEN parent.cat_lft AND parent.cat_rgt THEN cats.cat_lft - 1
WHEN cats.cat_lft > parent.cat_rgt THEN cats.cat_lft - 2
ELSE cats.cat_lft
END,
cats.cat_rgt = CASE WHEN cats.cat_lft BETWEEN parent.cat_lft AND parent.cat_rgt THEN cats.cat_rgt - 1
WHEN cats.cat_lft > parent.cat_rgt THEN cats.cat_rgt - 2
ELSE cats.cat_rgt
END
WHERE
cats.blog_id='".$this->con->escape($this->blog_id)."'
AND parent.cat_id='".$this->con->escape($cat_id)."'
AND cats.cat_lft > parent.cat_lft;";
$this->con->execute($sql);
}
//simply del the cat
$sql = "
DELETE FROM ".$this->table."
WHERE blog_id='" . $this->con->escape($this->blog_id) . "'
AND cat_id='". $this->con->escape($cat_id)."';";
$this->con->execute($sql);
$this->con->commit();
return true;
}catch (Exception $e) {
$this->con->rollback();
error_log($e);
return false;
}
}
public function cat_titleExists($cat_title){
foreach($this->cats as $cat){
if($cat['cat_title'] == $cat_title){
return true;
}
}
return false;
}
public function __construct($core)
{
/*
* Create all the categories tree on an array
*/
$this->core =& $core;
$this->con =& $core->con;
$this->blog_id = $core->blog->id;
$this->table = $core->prefix.'category';
$this->add_condition = array('blog_id' => "'".$this->con->escape($this->blog_id)."'");
//all categories on an array
$sql = "SELECT
cat_id, cat_title, cat_url, cat_desc, cat_lft, cat_rgt
FROM ".$this->table."
WHERE blog_id='".$this->blog_id."'
ORDER BY cat_lft ASC;";
//The ORDER BY on the left property, make the returned rows are on the good order,
//But we still have to calculate their level and position
$rs = $this->con->select($sql);
$cats = array();
$catsLftRgt = array();
$index = 0;
$nbeCatsLevel0 = 0;
while($rs->fetch()){
$betterParentLevel = -1;
$betterParentId = -1;
$countPrevious = 0;
foreach($catsLftRgt as $potentialParent){
if(
($rs->cat_lft > $potentialParent['cat_lft'])
&& ($rs->cat_lft < $potentialParent['cat_rgt'])
&& ($betterParentLevel < $potentialParent['cat_level'])
)
{
$betterParentLevel = $potentialParent['cat_level'];
$betterParentId = $potentialParent['cat_id'];
$betterParentIndex = $countPrevious;
}
$countPrevious++;
}
//Split data on two arrays
//the goal is to no expose via api cat_lft and cat_rgt
$cats[$index] = array(
'cat_id' => (int)$rs->cat_id,
'cat_title' => $rs->cat_title,
'cat_url' => $rs->cat_url,
'cat_desc' => $rs->cat_desc
);
$catsLftRgt[$index] = array(
'cat_lft' => (int)$rs->cat_lft,
'cat_rgt' => (int)$rs->cat_rgt,
'cat_id' => (int)$rs->cat_id,
'cat_level' => (int)$betterParentLevel + 1,
'count_childs' => 0
);
$cats[$index]['cat_level'] = (int)$betterParentLevel + 1;
if($betterParentId == -1){
$catsLftRgt[$index]['cat_parent_id'] = $cats[$index]['cat_parent_id'] = null;
$catsLftRgt[$index]['cat_position'] = $cats[$index]['cat_position'] = (int)$nbeCatsLevel0;
$nbeCatsLevel0++;
}else{
$catsLftRgt[$index]['cat_parent_id'] = $cats[$index]['cat_parent_id'] = (int)$betterParentId;
$catsLftRgt[$index]['cat_position'] = $cats[$index]['cat_position'] = $catsLftRgt[$betterParentIndex]['count_childs'];
$catsLftRgt[$betterParentIndex]['count_childs']++;
}
$index++;
}
$this->cats = $cats;
$this->catsLftRgt = $catsLftRgt;
}
}

@ -0,0 +1,139 @@
<?php
class RestDocumentation extends RestQuery
/*
* serves the swagger UI page
*/
{
protected $chapter;
protected function chapterExists(){
if($this->chapter == 'all'){
return true;
}
//documentation files must have the pattern /^swagger\-([a-zA-Z]+)\.json$/
$files = scandir(path::real(dirname(__FILE__).'/../documentation/'));
foreach($files as $file){
if($file == 'swagger-'.$this->chapter.'.json'){
return true;
}
}
return false;
}
public function __construct($args){
global $core;
if($args == "documentation"){
//il faut concaténer toutes les docs disponibles
$this->chapter = 'all';
}else{
list($osef,$this->chapter) = explode("/",$args);
}
if(!$this->chapterExists()){
$this->response_code = 404;
$this->response_message = array(
'error' => 'Not found'.$this->chapter,
'code' => 404
);
}
//le documentation demandée par l'user existe.
$this->response_code = 200;
$this->response_message =
'<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Swagger UI</title>
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="index.php?pf=rest/documentation/swagger-ui-dist/swagger-ui.css" >
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
<style>
html
{
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}
*,
*:before,
*:after
{
box-sizing: inherit;
}
body {
margin:0;
background: #fafafa;
}
</style>
</head>
<body>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="position:absolute;width:0;height:0">
<defs>
<symbol viewBox="0 0 20 20" id="unlocked">
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V6h2v-.801C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8z"></path>
</symbol>
<symbol viewBox="0 0 20 20" id="locked">
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8zM12 8H8V5.199C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8z"/>
</symbol>
<symbol viewBox="0 0 20 20" id="close">
<path d="M14.348 14.849c-.469.469-1.229.469-1.697 0L10 11.819l-2.651 3.029c-.469.469-1.229.469-1.697 0-.469-.469-.469-1.229 0-1.697l2.758-3.15-2.759-3.152c-.469-.469-.469-1.228 0-1.697.469-.469 1.228-.469 1.697 0L10 8.183l2.651-3.031c.469-.469 1.228-.469 1.697 0 .469.469.469 1.229 0 1.697l-2.758 3.152 2.758 3.15c.469.469.469 1.229 0 1.698z"/>
</symbol>
<symbol viewBox="0 0 20 20" id="large-arrow">
<path d="M13.25 10L6.109 2.58c-.268-.27-.268-.707 0-.979.268-.27.701-.27.969 0l7.83 7.908c.268.271.268.709 0 .979l-7.83 7.908c-.268.271-.701.27-.969 0-.268-.269-.268-.707 0-.979L13.25 10z"/>
</symbol>
<symbol viewBox="0 0 20 20" id="large-arrow-down">
<path d="M17.418 6.109c.272-.268.709-.268.979 0s.271.701 0 .969l-7.908 7.83c-.27.268-.707.268-.979 0l-7.908-7.83c-.27-.268-.27-.701 0-.969.271-.268.709-.268.979 0L10 13.25l7.418-7.141z"/>
</symbol>
<symbol viewBox="0 0 24 24" id="jump-to">
<path d="M19 7v4H5.83l3.58-3.59L8 6l-6 6 6 6 1.41-1.41L5.83 13H21V7z"/>
</symbol>
<symbol viewBox="0 0 24 24" id="expand">
<path d="M10 18h4v-2h-4v2zM3 6v2h18V6H3zm3 7h12v-2H6v2z"/>
</symbol>
</defs>
</svg>
<div id="swagger-ui"></div>
<script src="index.php?pf=rest/documentation/swagger-ui-dist/swagger-ui-bundle.js"> </script>
<script src="index.php?pf=rest/documentation/swagger-ui-dist/swagger-ui-standalone-preset.js"> </script>
<script>
window.onload = function() {
// Build a system
const ui = SwaggerUIBundle({
url: "'.$core->blog->url.$core->url->getBase('rest').'/specs/'.$this->chapter.'",
dom_id: \'#swagger-ui\',
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
})
window.ui = ui
}
</script>
</body>
</html>';
}
}

@ -0,0 +1,121 @@
<?php
class RestQueryDeleteCategories extends RestQuery
{
public function __construct($args,$body){
global $core;
$explodedArgs = explode("/",$args);
$this->blog_id = $explodedArgs[0];
$this->required_perms = 'none'; //To do
if($core->auth === false){
$core->auth = new restAuth($core);
$unauth = true;
}
if($this->is_allowed() === false){
return;
}
if(!isset($explodedArgs[2])){
$this->is404("no category given");
return;
}else{
$cat_id = $explodedArgs[2];
}
$core->blog = new dcBlog($core, $this->blog_id);
if(!$core->blog->id){
$this->is404('Resource '.$blog_id.' not found');
return;
}
$cats = new RestCategories($core);
if(!$cats->getCatProperties($cat_id)){
$this->is404($cat_id.' category not found');
return;
}
if(empty($body)){
$params = array();
}elseif(empty(json_decode($body,true))){
$params = array();
}else{
$params = $this->body_to_array($body);
if($params === false){
return;
}
if(!$this->check_for_required_fields(
$params,
array(), //required fields
array("move_childs_on_cat_id","delete_childs") //facultatives fields
)){
return;
}
}
if(isset($params["move_childs_on_cat_id"])){
if(!$cats->getCatProperties($params["move_childs_on_cat_id"])){
$this->is404($params["move_childs_on_cat_id"].' category not found');
return;
}
//déplacer les posts
$sql = " UPDATE ".$core->prefix."post
SET cat_id='".$core->con->escape($params["move_childs_on_cat_id"])."'
WHERE blog_id='".$core->con->escape($core->blog->id)."'
AND cat_id='".$core->con->escape($cat_id)."';";
$core->con->execute($sql);
//déplacer les sous catégories
$cats->moveChilds($cat_id,$params["move_childs_on_cat_id"]);
}
if((isset($params["delete_childs"])) && ($params["delete_childs"])){
//delete posts
$sql = "DELETE
post.*
FROM
".$core->prefix."post AS post,
".$core->prefix."category AS category,
".$core->prefix."category AS parentcategory
WHERE
post.cat_id = category.cat_id
AND parentcategory.cat_id ='".$core->con->escape($cat_id)."'
AND category.cat_lft BETWEEN parentcategory.cat_lft AND parentcategory.cat_rgt
AND post.blog_id='".$core->con->escape($core->blog->id)."';";
$core->con->execute($sql);
$deleteSubs = true;
}else{
$deletSubs = false;
}
//OK to delete cat
if($cats->deleteCategory($cat_id,$deleteSubs)) {
$this->response_code = 200;
$this->response_message = array(
"code" => 200,
"message" => "Successfully delete Category"
);
}else{
$this->response_code = 500;
$this->response_message = array(
"code" => 500,
"message" => "Something wrong is happened while trying to delete the category."
);
}
}
}

@ -0,0 +1,62 @@
<?php
class RestQueryDeleteComments extends RestQuery
{
public function __construct($args,$body){
global $core;
$explodedArgs = explode("/",$args);
$this->blog_id = $explodedArgs[0];
$this->required_perms = 'none'; //To do
if($core->auth === false){
$core->auth = new restAuth($core);
$unauth = true;
}
if($this->is_allowed() === false){
return;
}
$core->blog = new dcBlog($core, $this->blog_id);
if(!$core->blog->id){
$this->is404('Resource '.$blog_id.' not found');
return;
}
if(isset($explodedArgs[2])){
$listToDelete = array(intval($explodedArgs[2]));
}else{
//list To Delete is on the body
$list=json_decode($body);
}
error_log(json_encode($listToDelete,true));
foreach($listToDelete as $item){
if(!is_int($item)){
$this->response_code = 400;
$this->response_message = array(
"error"=> 400,
"message"=> "items ids to delete must be integers values"
);
return;
}
}
$sql = "DELETE comments.*
FROM ".$core->prefix."comment AS comments,
".$core->prefix."post AS posts
WHERE comments.post_id=posts.post_id
AND posts.blog_id='".$core->con->escape($core->blog->id)."'
AND comments.comment_id IN (".implode(",",$listToDelete).");";
$core->con->execute($sql);
$this->response_code = 201;
$this->response_message = array(
"code"=> 201,
"message" => "delete made"
);
}
}

@ -0,0 +1,35 @@
<?php
class RestQueryDeletePostMeta extends RestQuery
{
public function __construct($args){
global $core;
$explodedArgs = explode("/",$args);
$this->blog_id = $explodedArgs[0];
//preg_match('/^(.*)\/(.*)\/meta\/(.*)$/', $args ))
$post_id = $explodedArgs[1];
if(isset($explodedArgs[3])) {
$meta_id = $explodedArgs[3];
}else {
$meta_id = null;
}
$core->blog = new dcBlog($core, $this->blog_id);
if(!$core->blog->id){
//Le blog n'existe pas
$this->response_code = 404;
$this->response_message = array('code' => 404, 'error' => 'Resource '.$blog_id.' not found');
return;
}
$core->meta->delPostMeta($post_id,null,$meta_id);
$this->response_code = 200;
$this->response_message = array(
'code' => 200,
'message' => 'successfully remove meta'
);
}
}

@ -0,0 +1,45 @@
<?php
class RestQueryGetCategories extends RestQuery
{
public function __construct($args){
global $core;
$explodedArgs = explode("/",$args);
$this->blog_id = $explodedArgs[0];
$core->blog = new dcBlog($core, $this->blog_id);
if(!$core->blog->id){
//Le blog n'existe pas
$this->response_code = 404;
$this->response_message = array('code' => 404, 'error' => 'Resource '.$blog_id.' not found');
return;
}
if(isset($_GET['filters'])){
$filtersArr = $this->getFilters(
$_GET['filters'],
array('cat_title','cat_url','cat_desc',
'cat_level','cat_parent_id','cat_position')
);
if($filtersArr === false){
return;
}
}else{
$filtersArr = array();
}
$cats = new RestCategories($core);
if(isset($explodedArgs[2])){
//une categorie est fournie
$this->response_message = $cats -> getCatProperties($explodedArgs[2]);
}else{
$this->response_message = $cats -> getCats($filtersArr);
}
$this->response_code = 200;
}
}

@ -0,0 +1,71 @@
<?php
class RestQueryGetComments extends RestQuery
{
public function __construct($args){
global $core;
$explodedArgs = explode("/",$args);
$this->blog_id = $explodedArgs[0];
$this->required_perms = 'none'; //To do
$post_id = ($explodedArgs[1] == 'comments')? null:$explodedArgs[1];
$comment_id = (isset($explodedArgs[2]))? $explodedArgs[2]:null;
//check if blog exists
$core->blog = new dcBlog($core, $this->blog_id);
if(!$core->blog->id){
$this->is404('Resource '.$blog_id.' not found');
return;
}
if(!is_null($post_id)){
//check if post exists
$post = $core->blog->getPosts(array('post_id' => $post_id));
if ($post->isEmpty()) {
$this->is404("No post with id: ".$post_id." found");
return;
}
}
$givenFilters = array();
if(isset($_GET['filters'])){
$availableFilters = array(
'post_type','post_id','cat_id','comment_id','comment_site','comment_status','comment_trackback','comment_ip','post_url','user_id');
$givenFilters = $this->getFilters($_GET['filters'],$availableFilters);
if($givenFilters === false){
return;
}
}
//verifier s'il n'y a pas des incohérences... parceque c'est rigolo
// de shooter l'user avec une erreur 409
if(
((!is_null($post_id)) && (isset($givenFilters["post_id"])))
|| ((!is_null($comment_id) && (isset($givenFilters["comment_id"]))))
){
$this->response_code = 409;
$this->response_message = array(
"error" => 409,
"message" => "Post_id or Comment_id must not be filtered both by URL path AND URL filters var on query string"
);
}
if(!is_null($post_id)){
$givenFilters["post_id"] = $post_id;
}
if(!is_null($comment_id)){
$givenFilters["comment_id"] = $comment_id;
}
//time to execute the query
$commentsRecord = $core->blog->getComments($givenFilters);
$this->response_code = 200;
$this->response_message = $this->rs_to_array($commentsRecord);
}
}

@ -0,0 +1,40 @@
<?php
class RestQueryGetMetas extends RestQuery
{
public function getMetas($params){
global $core;
$rs = $core->meta->getMetadata($params, false);
return $this->rs_to_array($rs);
}
public function __construct($args){
global $core;
$explodedArgs = explode("/",$args);
$this->blog_id = $explodedArgs[0];
//check if user is allowed
$core->blog = new dcBlog($core, $this->blog_id);
if(!$core->blog->id){
//Le blog n'existe pas
$this->response_code = 404;
$this->response_message = array('code' => 404, 'error' => 'Resource '.$blog_id.' not found');
return;
}
$params = array();
if (isset($_GET['post_id']))
$params['post_id'] = $_GET['post_id'];
if (isset($_GET['meta_id']))
$params['meta_id'] = $_GET['meta_id'];
if (isset($_GET['meta_type']))
$params = $_GET['meta_type'];
$this -> response_code = 200;
$this -> response_message = $this -> getMetas($params);
}
}

@ -0,0 +1,27 @@
<?php
class RestQueryGetPostMetas extends RestQuery
{
public function __construct($args){
global $core;
$explodedArgs = explode("/",$args);
$this->blog_id = $explodedArgs[0];
$core->blog = new dcBlog($core, $this->blog_id);
if(!$core->blog->id){
//Le blog n'existe pas
$this->response_code = 404;
$this->response_message = array('code' => 404, 'error' => 'Resource '.$blog_id.' not found');
return;
}
$this->response_message = RestQueryGetMetas::getMetas(array('post_id'=>$explodedArgs[1]));
$this->response_code = 200;
}
}

@ -43,10 +43,7 @@ class RestQueryGetPost extends RestQuery
$this -> response_message = $postArr;
$this -> response_code = 200;
}
}

@ -1,7 +1,7 @@
<?php
class RestQueryGetPosts extends RestQuery
{
//curl -X GET "http://dotclear.localhost/dotclear/index.php?rest/default/posts" -H "accept: application/json" -H "x_dc_key: 1zhoGXv9PA0lvPNG81GUlCNfqT45gVuV"
public function __construct($args)
{
@ -17,6 +17,12 @@ class RestQueryGetPosts extends RestQuery
$unauth = true;
}
$core->blog = new dcBlog($core, $this->blog_id);
if(!$core->blog->id){
//Le blog n'existe pas
$this->response_code = 404;
$this->response_message = array('code' => 404, 'error' => 'Resource '.$blog_id.' not found');
return;
}
$blog_settings = new dcSettings($core,$this->blog_id);
if($this->is_allowed() === false){
@ -98,4 +104,4 @@ class RestQueryGetPosts extends RestQuery
}
}
}

@ -1,7 +1,89 @@
<?php
class RestQueryGetSpecs extends RestQuery
class RestQueryGetSpecs extends RestDocumentation //some common functions betwin this 2 class
{
public function __construct(){
protected function getSwaggerArray(){
/*
* need $this -> chapter initied
* return the swagger doc (as an array)
* with the real basePath and the URL
* if chapter is 'all' it will concat all swagger definitions.
*/
global $core;
if(!ctype_alpha($this->chapter)){
return false;
}
if($this->chapter == 'all'){
//concat all specs array in one
$url = parse_url($core->blog->url.$core->url->getBase('rest'));
preg_match('/https?:\/\/[^\/]*(\/.*)/',$core->blog->url.$core->url->getBase('rest'),$end);
$specs = array(
"swagger" => "2.0",
"info:" => array(
"title" => "Dotclear API",
"description" => "Manage yours blogs with this API",
"version" => "0.1"
),
"host" => $url['host'],
"schemes" => array(
$url['scheme']
),
"basePath" =>$end[1],
"produces" => array(
"application/json"
),
"paths" =>array(),
"definitions" => array(),
);
$files = scandir(path::real(dirname(__FILE__).'/../documentation/'));
foreach($files as $file){
if (preg_match('/^swagger\-(.*)\.json$/',$file)){
$swag = json_decode(
file_get_contents(
path::real(dirname(__FILE__).'/../documentation/').'/'.$file
),true
);
$specs["paths"] = array_merge($specs["paths"], $swag["paths"]);
$specs["definitions"] = array_merge($specs["definitions"], $swag["definitions"]);
}
}
return $specs;
}
$files = scandir(path::real(dirname(__FILE__).'/../documentation/'));
foreach($files as $file){
if($file == 'swagger-'.$this->chapter.'.json'){
//return path::real(dirname(__FILE__).'/../documentation/').'/'.$file;
$specs = json_decode(
file_get_contents(
path::real(dirname(__FILE__).'/../documentation/').'/'.$file
),true
);
//change some parameters
$url = parse_url($core->blog->url.$core->url->getBase('rest'));
$specs['host'] = $url['host'];
$specs['schemes'] = $url['scheme'];
preg_match('/https?:\/\/[^\/]*(\/.*)/',$core->blog->url.$core->url->getBase('rest'),$end);
$specs['basePath'] = $end[1];
return $specs;
}
}
return false;
}
public function __construct($args){
global $core;
$this->response_code = 200;
$this->required_perms = 'unauth';
@ -9,15 +91,23 @@ class RestQueryGetSpecs extends RestQuery
return;
}
$specs = json_decode(file_get_contents(dirname(__FILE__).'/../documentation/swagger.json'),true);
//change some parameters
$url = parse_url($core->blog->url.$core->url->getBase('rest'));
$specs['host'] = $url['host'];
$specs['schemes'] = $url['scheme'];
preg_match('/https?:\/\/[^\/]*(\/.*)/',$core->blog->url.$core->url->getBase('rest'),$end);
$specs['basePath'] = $end[1];
if($args == "specs"){
$this->chapter = 'all';
}else{
list($osef,$this->chapter) = explode("/",$args);
}
$specs = $this->getSwaggerArray();
if($specs === false){
$this->response_code = 404;
$this->response_message = array(
'error' => 'Not found'.$body,
'code' => 404
);
return;
}
$this->response_message = $specs;
return;
}
}
}

@ -0,0 +1,66 @@
<?php
class RestQueryPatchCategories extends RestQuery
{
public function __construct($args,$body){
global $core;
$explodedArgs = explode("/",$args);
$this->blog_id = $explodedArgs[0];
$this->required_perms = 'none'; //To do
if($core->auth === false){
$core->auth = new restAuth($core);
$unauth = true;
}
if($this->is_allowed() === false){
return;
}
if(!isset($explodedArgs[2])){
$this->is404("no category given");
return;
}else{
$cat_id = $explodedArgs[2];
}
$core->blog = new dcBlog($core, $this->blog_id);
if(!$core->blog->id){
$this->is404('Resource '.$blog_id.' not found');
return;
}
$cats = new RestCategories($core);
$cat = $cats->getCatProperties($cat_id);
if($cat === false){
$this->is404($cat_id.' category not found');
return;
}
//les valeurs envoyées par l'user
$queryArr = $this->body_to_array($body);
if($queryArr === false){
return;
}
if(!$this->check_for_required_fields(
$queryArr ,
array(), //required fields
array('cat_title','cat_url','cat_desc','cat_parent_id','cat_position','temporary', 'permute') //facultatives fields
)){
return;
}
$cats->updateCategory($cat_id,$queryArr);
$this->response_code = 201;
$this->response_message = array(
'code' => 201,
'message' => 'Successfully update category',
'id' => $cat_id
);
}
}

@ -0,0 +1,84 @@
<?php
class ResQueryPatchMeta extends RestQuery
{
public function __construct($args,$body){
global $core;
$explodedArgs = explode("/",$args);
$this->blog_id = $explodedArgs[0];
$post_id = $explodedArgs[1];
$meta_id = $explodedArgs[3];
$this->required_perms = 'none'; //To do
if($core->auth === false){
$core->auth = new restAuth($core);
$unauth = true;
}
$core->blog = new dcBlog($core, $this->blog_id);
if(!$core->blog->id){
//Le blog n'existe pas
$this->response_code = 404;
$this->response_message = array('code' => 404, 'error' => 'Resource '.$blog_id.' not found');
return;
}do
$blog_settings = new dcSettings($core,$this->blog_id);
if($this->is_allowed() === false){
return;
}
$clientQueryArr = json_decode($body, true);
//memorise the old one attributes before delete it
$oldMeta = RestQueryGetMetas::getMetas(
array(
'post_id' => $post_id,
'meta_id' => $meta_id
)
);
if(count($oldMeta) == 0){
//error 404
$this -> response_code = 404;
$this -> response_message = array(
'code' => 404,
'message' =>'No existing meta with this post_id and this meta_id'
);
return
}
//delete the old meta
$r = $core->meta->delPostMeta($post_id,null,$meta_id);
//create the new one
if(isset($clientQueryArr['post_id'])){
$new_post_id = $clientQueryArr['post_id'];
}else {
$new_post_id = $oldMeta[0]['post_id'];
}
if(isset($clientQueryArr['meta_id'])){
$new_post_id = $clientQueryArr['meta_id'];
}else {
$new_post_id = $oldMeta[0]['meta_id'];
}
if(isset($clientQueryArr['meta_type'])){
$new_post_id = $clientQueryArr['meta_type'];
}else {
$new_post_id = $oldMeta[0]['meta_type'];
}
}
}

@ -23,13 +23,22 @@ class RestQuery{
public function __construct()
{
$this->response_code = 404;
$this->response_message = array(
"error" => "Method not found",
"code" => 404
);
$this->response_code = 404;
$this->response_message = array(
"error" => "Method not found",
"code" => 404
);
}
protected function is404($customMessage = '')
{
$this->response_code = 404;
if (empty($customMessage))
$this->response_message = array('code' => 404, 'error' => 'Resource not found');
else
$this->response_message = array('code' => 404, 'error' => $customMessage);
}
/**
* Check if required fields are set
* $strict => Go on error if a additionnal field is given
@ -83,6 +92,43 @@ class RestQuery{
}
/*
* IN $RawFilters string urlencoded corresponding to $_GET['filters']
* IN $permittedKeys array listing the keys the filter can Used
* OUT array ('KeyName' => 'expectedValue')
*/
protected function getFilters($rawFilters,$permittedKeys)
{
$subject = urldecode($rawFilters);
$matchExpr = '/(?<=^|\\s)([^=\\s]+)="((?:[^\\\\"]|\\\\.)*)"/';
$replaceExpr = '/\\\\./';
$replaceCallback = function($match) {
switch ($match[0][1]) {
case 'r': return "\r";
case 'n': return "\n";
default: return $match[0][1];
}
};
preg_match_all($matchExpr, $subject, $matches);
$result = array();
foreach ($matches[1] as $i => $key) {
if(!in_array($key,$permittedKeys)){
$this->response_code = 400;
$this->response_message = array("code" => 400,
"message" => "UnAllowed filter ".$key);
return false;
}
$result[$key] = preg_replace_callback($replaceExpr, $replaceCallback, $matches[2][$i]);
}
return $result;
}
protected function body_to_array($body){
if($ret = json_decode($body,true)){
return $ret;
@ -262,4 +308,19 @@ class RestQuery{
return "HTTP/1.0 ".$code." Something wrong happened";
}
}
function rs_to_array($rs){
$arr = array();
while($rs->fetch()){
$r = array();
$columns = $rs->columns();
foreach($columns as $key){
$r[$key] = $rs->$key;
}
$arr[] = $r;
}
return $arr;
}
}

@ -73,6 +73,11 @@ class RestQueryPostBlogSettings extends RestQuery
$unauth = true;
}
$core->blog = new dcBlog($core, $this->blog_id);
if(!$core->blog->id){
//Le blog n'existe pas
$this->is404('Resource '.$blog_id.' not found');
return;
}
$blog_settings = new dcSettings($core,$this->blog_id);

@ -2,50 +2,7 @@
class RestQueryPostCategories extends RestQuery
{
/**
* IN $params array with keys
* OUT integer, the new category id
*/
public function createCategory($params){
global $core;
if(!isset($params['cat_title'])){
return false;
}
try
{
$cur = $core->con->openCursor($core->prefix.'category');
$cur->cat_title = $params['cat_title'];
if (isset($params['cat_desc'])) {
$cur->cat_desc = $params['cat_desc'];
}
if (isset($params['cat_url'])) {
$cur->cat_url = $params['cat_url'];
}else{
$cur->cat_url = '';
}
if(isset($params['cat_parent_id'])){
$cat_parent_id = $params['cat_parent_id'];
}else{
$cat_parent_id = null;
}
# --BEHAVIOR-- adminBeforeCategoryCreate
$core->callBehavior('adminBeforeCategoryCreate',$cur);
$id = $core->blog->addCategory($cur,(integer)$cat_parent_id);
# --BEHAVIOR-- adminAfterCategoryCreate
$core->callBehavior('adminAfterCategoryCreate',$cur,$id);
return $id;
}catch (Exception $e) {
return false;
}
}
public function __construct($args,$body){
global $core;
@ -58,6 +15,12 @@ class RestQueryPostCategories extends RestQuery
$unauth = true;
}
$core->blog = new dcBlog($core, $this->blog_id);
if(!$core->blog->id){
//Le blog n'existe pas
$this->response_code = 404;
$this->response_message = array('code' => 404, 'error' => 'Resource '.$blog_id.' not found');
return;
}
$blog_settings = new dcSettings($core,$this->blog_id);
if($this->is_allowed() === false){
@ -76,14 +39,27 @@ class RestQueryPostCategories extends RestQuery
}
if(!$this->check_for_required_fields(
$clientQueryArr,
array('cat_title'), //required fields
array('cat_url','cat_desc','cat_parent_id','cat_position','temporary') //facultatives fields
$clientQueryArr,
array('cat_title'), //required fields
array('cat_url','cat_desc','cat_parent_id','cat_position','temporary') //facultatives fields
)){
return;
}
$id = $this->createCategory($clientQueryArr);
//$id = $this->createCategory($clientQueryArr);
$cats = new RestCategories($core);
if($cats->cat_titleExists($clientQueryArr['cat_title'])){
$this->response_code = 409;
$this->response_message = array(
'error' => 409,
'message' => 'a cat with the same cat_title allready exists.'
);
return;
}
$id = $cats->addCategory($clientQueryArr);
if($id === false){
$this->response_code = 500;
@ -100,4 +76,4 @@ class RestQueryPostCategories extends RestQuery
}
}
}
}

@ -36,6 +36,12 @@ class RestQueryPostMetas extends RestQuery
$unauth = true;
}
$core->blog = new dcBlog($core, $this->blog_id);
if(!$core->blog->id){
//Le blog n'existe pas
$this->response_code = 404;
$this->response_message = array('code' => 404, 'error' => 'Resource '.$blog_id.' not found');
return;
}
$blog_settings = new dcSettings($core,$this->blog_id);
if($this->is_allowed() === false){

@ -11,6 +11,12 @@ class RestQueryPostPost extends RestQuery{
$unauth = true;
}
$core->blog = new dcBlog($core, $this->blog_id);
if(!$core->blog->id){
//Le blog n'existe pas
$this->response_code = 404;
$this->response_message = array('code' => 404, 'error' => 'Resource '.$blog_id.' not found');
return;
}
$blog_settings = new dcSettings($core,$this->blog_id);
if($this->is_allowed() === false){
@ -38,7 +44,7 @@ class RestQueryPostPost extends RestQuery{
if(!$this->check_for_required_fields(
$p,
array('post_title','post_format','post_content','post_status'), //required fields
array('cat_id','new_cat_id','new_cat_parent','post_dt','post_password',
array('cat_id','new_cat_title','new_cat_parent_id','new_cat_position','post_dt','post_password',
'post_lang','post_excerpt','post_excerpt_xhtml','post_content_xhtml',
'post_notes','post_selected','post_open_comment','post_open_tb','post_url','post_tags') //facultatives fields
)){
@ -51,17 +57,26 @@ class RestQueryPostPost extends RestQuery{
foreach($allPosts as $p){
//gestion de la categorie
if(isset($p['new_cat_id'])){
if(isset($p['new_cat_title'])){
$params = array();
$params['cat_title'] = $p['new_cat_id'];
$params['cat_title'] = $p['new_cat_title'];
if(isset($p['new_cat_parent_id']))
$params['cat_parent_id'] = $p['new_cat_parent_id'];
else
$params['cat_parent_id'] = null;
if(isset($p['new_cat_position']))
$params['cat_position'] = $p['new_cat_position'];
else
$params['cat_position'] = null;
if(isset($p['new_cat_url']))
$params['cat_url'] = $p['new_cat_url'];
if(isset($p['new_cat_desc']))
$params['cat_desc'] = $p['new_cat_desc'];
$cat_id = RestQueryPostCategories::createCategory($params);
$cats = new RestCategories($core);
$cat_id = $cats->addCategory($params);
if($cat_id === false){
$this->response_message = 400;
@ -202,4 +217,4 @@ class RestQueryPostPost extends RestQuery{
"id" => $id);
}
}
}

@ -28,6 +28,12 @@ class ResQueryPutBlogs extends RestQuery
//does the blog exists?
$core->blog = new dcBlog($core, $this->blog_id);
if(!$core->blog->id){
//Le blog n'existe pas
$this->response_code = 404;
$this->response_message = array('code' => 404, 'error' => 'Resource '.$blog_id.' not found');
return;
}
$blog_settings = new dcSettings($core,$this->blog_id);
if(!$core->blog->id){
@ -65,4 +71,4 @@ class ResQueryPutBlogs extends RestQuery
);
return;
}
}
}

@ -59,11 +59,41 @@ if(!empty($_POST['resetApiKey'])){
<title><?php echo __('REST API configuration'); ?></title>
</head>
<body>
<h2>Documentation</h2>
<p><a href="<?php echo $core->blog->url."rest/documentation" . '">' . __('Documentation and test interface Swagger UI') .'</a></p>'; ?>
<h2><?php echo __('Your API key');?></h2>
<?php echo $apiKey-> get_dc_admin_form($core->auth->userID()); ?>
<h2>Documentation</h2>
<ul>
<li><a href="<?php echo $core->blog->url."rest/documentation" . '" target="_blank" >' . __('Full documentation') .'</a></p>'; ?></li>
</ul>
<h3><?php echo __('System methods'); ?> </h3>
<ul>
<li><a href="<?php echo $core->blog->url."rest/documentation/blogs" . '" target="_blank" >' . __('Search Create Read Update Replace').' blogs</a></p>'; ?></li>
<li><a href="<?php echo $core->blog->url."rest/documentation/settings" . '" target="_blank" >' . __('Search Create Read Update Replace').' settings</a></p>'; ?></li>
<li><a href="<?php echo $core->blog->url."rest/documentation/users" . '" target="_blank" >' . __('Search Create Read Update Replace').' users</a></p>'; ?></li> <li><a href="<?php echo $core->blog->url."rest/documentation/plugins" . '" target="_blank" >' . __('Search Create Read Update Replace').' plugins</a></p>'; ?></li>
</ul>
<h3><?php echo __('Content management methods'); ?> </h3>
<ul>
<li><a href="<?php echo $core->blog->url."rest/documentation/posts" . '" target="_blank" >' . __('Search Create Read Update Replace').' Posts</a></p>'; ?></li>
<li><a href="<?php echo $core->blog->url."rest/documentation/metas" . '" target="_blank" >' . __('Search Create Read Update Replace').' Metas</a></p>'; ?></li>
<li><a href="<?php echo $core->blog->url."rest/documentation/categories" . '" target="_blank" >' . __('Search Create Read Update Replace').' Categories </a></p>'; ?></li>
<li><a href="<?php echo $core->blog->url."rest/documentation/comments" . '" target="_blank" >' . __('Search Create Read Update Replace').' '.__('Comments').'</a></p>'; ?></li>
</ul>
<h3><?php echo __('Public files methods'); ?> </h3>
<ul>
<li><a href="<?php echo $core->blog->url."rest/documentation/files" . '" target="_blank" >' . __('Search Create Read Update Replace').' '.__('files').'</a></p>'; ?></li>
</ul>
<h3><?php echo __('This API'); ?></h3>
<ul>
<li><a href="<?php echo $core->blog->url."rest/documentation/api" . '" target="_blank" >' . __('Methods to get documentation and extend this API').'</a></p>'; ?></li>
</ul>
</ul>
<?php
//Seulement si administrateur:
if($core->auth->isSuperAdmin()):
@ -93,4 +123,4 @@ if($core->auth->isSuperAdmin()):
endif;
?>
</body>
</html>
</html>

@ -42,3 +42,24 @@ msgstr "Créer une clef pour"
msgid "Copy and paste it, You will cannot see it again."
msgstr "Copiez collez la. Cette clef ne pourra pas vous être refournie."
msgid "Full documentation"
msgstr "Documentation complète"
msgid "System methods"
msgstr "Méthodes système"
msgid "Content management methods"
msgstr "Méthodes de gestion du contenu"
msgid "Public files methods"
msgstr "Gestion de la médiathèque"
msgid "Search Create Read Update Replace"
msgstr "Chercher Créer Lire Modifier Supprimer"
msgid "This API"
msgstr "Cette API"
msgid "Methods to get documentation and extend this API"
msgstr "Méthodes pour obtenir la documentation et etendre cette API"

@ -1,32 +1,27 @@
<?php
$api_key = 'tn0GHPOxbK3hbJAygRPihJHqPKvhC2vw'; //super admin api_key, change it by your
$api_key = 'G3OenlFITbzR5PWvLNWlId9quqsqibuo'; //super admin api_key, change it by your
$api_url = 'http://dotclear.localhost/rest'; //my local dev platform, change it by your
//testUser key DVsmYPmW6jvfk4kgak1krvbxcl1nGXMJ
function check_json_content($content,$aKeyToCheck){
function check_json_content($content,$aKeyToCheck,$responseIsArrayOfObjects){
$arr=json_decode($content,true);
if($responseIsArrayOfObjects){
$arr = $arr[0];
}
if(($aKeyToCheck == '') && (is_array($arr))){
return true;
}
if($aKeyToCheck === false){
if (is_array($arr)){
return true;
}else{
return false;
}
}
if(isset($arr[$aKeyToCheck])){
if(is_array($arr[$aKeyToCheck])){
return json_encode($arr[$aKeyToCheck],true);
}else{
return $arr[$aKeyToCheck];
}
}else{
return false;
}
}
function test($url, $method, $body, $expectedCode, $expectedKeyOnResponse, $x_dc_key){
function test($url, $method, $body, $expectedCode,$responseIsArrayOfObjects, $expectedKeyOnResponse, $x_dc_key){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
@ -51,9 +46,10 @@ function test($url, $method, $body, $expectedCode, $expectedKeyOnResponse, $x_dc
return;
}
$r = check_json_content($response ,$expectedKeyOnResponse);
$r = check_json_content($response ,$expectedKeyOnResponse,$responseIsArrayOfObjects);
if($r === false){
echo "\nQuery type ".$method." on url ".$url." JSON parse error or missing propertie.\n".
echo "\nQuery type ".$method." on url ".$url." JSON parse error or missing property.\n".
"return code: ".$httpCode."\n".
"Response content:\n".$response;
//on va pas plus loin, ça pourrait mettre la m... dans la suite
@ -72,6 +68,7 @@ $allTests = array(
'method' => 'GET',
'expectedResponseCode' => '404',
'expectedKeyOnResponse' => 'error',
'responseIsArrayOfObjects' => false,
'body' => '',
'x_dc_key' => '',
'saveAs' => ''
@ -82,6 +79,7 @@ $allTests = array(
'url' => $api_url.'/specs',
'method' => 'GET',
'expectedResponseCode' => '200',
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'swagger',
'body' => '',
'x_dc_key' => '',
@ -93,6 +91,7 @@ $allTests = array(
'url' => $api_url.'/blogs',
'method' => 'GET',
'expectedResponseCode' => '403',
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'error',
'body' => '',
'x_dc_key' => '',
@ -104,6 +103,7 @@ $allTests = array(
'url' => $api_url.'/blogs',
'method' => 'GET',
'expectedResponseCode' => '403',
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'error',
'body' => '',
'x_dc_key' => '7777777777777',
@ -115,6 +115,7 @@ $allTests = array(
'url' => $api_url.'/blogs',
'method' => 'GET',
'expectedResponseCode' => '200',
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => false, //is a single list
'body' => '',
'x_dc_key' => $api_key,
@ -127,6 +128,7 @@ $allTests = array(
'url' => $api_url.'/blogs',
'method' => 'POST',
'expectedResponseCode' => '201',
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'id', //is a single list
'body' => json_encode(array(
"blog_id" => "test-api",
@ -145,6 +147,7 @@ $allTests = array(
'url' => $api_url.'/blogs',
'method' => 'POST',
'expectedResponseCode' => '400',
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'error',
'body' => '{"ce n\'est pas du" => "JSON"}',
'x_dc_key' => $api_key,
@ -158,6 +161,7 @@ $allTests = array(
'url' => $api_url.'/blogs/%blog_id%',
'method' => 'GET',
'expectedResponseCode' => '200',
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'blog_url',
'body' => '',
'x_dc_key' => $api_key,
@ -171,6 +175,7 @@ $allTests = array(
'url' => $api_url.'/blogs/%blog_id%',
'method' => 'PATCH',
'expectedResponseCode' => '400',
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'error',
'body' => '{JSON IS FUN}',
'x_dc_key' => $api_key,
@ -183,6 +188,7 @@ $allTests = array(
'url' => $api_url.'/blogs/%blog_id%',
'method' => 'PATCH',
'expectedResponseCode' => '403',
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'error',
'body' => '{"blog_name": "Patched Blog name"}',
'x_dc_key' => 'heyHey!',
@ -195,6 +201,7 @@ $allTests = array(
'url' => $api_url.'/blogs/%blog_id%',
'method' => 'PATCH',
'expectedResponseCode' => '200',
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'message',
'body' => '{"blog_name": "Patched Blog name"}',
'x_dc_key' => $api_key,
@ -205,10 +212,11 @@ $allTests = array(
//PUT
//Patch blog properties with error ON JSON
array(
'title' => 'PUT /blogs/%blog_id% with with error ON JSON',
'title' => 'PUT /blogs/%blog_id% with error ON JSON',
'url' => $api_url.'/blogs/%blog_id%',
'method' => 'PUT',
'expectedResponseCode' => '400',
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'error',
'body' => '{JSON IS FUN}',
'x_dc_key' => $api_key,
@ -220,6 +228,7 @@ $allTests = array(
'url' => $api_url.'/blogs/%blog_id%',
'method' => 'PUT',
'expectedResponseCode' => '403',
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'error',
'body' => '{"blog_id": "%blog_id%","blog_url":"https://plop.local/", "blog_name": "Patched Blog name", "blog_desc": "blahblah"}',
'x_dc_key' => 'heyHey!',
@ -231,6 +240,7 @@ $allTests = array(
'url' => $api_url.'/blogs/%blog_id%',
'method' => 'PUT',
'expectedResponseCode' => '200',
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'message',
'body' => '{"blog_id": "%blog_id%","blog_url":"https://plop.local/", "blog_name": "Patched Blog name", "blog_desc": "blahblah"}',
'x_dc_key' => $api_key,
@ -243,6 +253,7 @@ $allTests = array(
'url' => $api_url.'/%blog_id%/settings',
'method' => 'GET',
'expectedResponseCode' => '200',
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'system',
'body' => '',
'x_dc_key' => $api_key,
@ -254,6 +265,7 @@ $allTests = array(
'url' => $api_url.'/%blog_id%/settings/system',
'method' => 'GET',
'expectedResponseCode' => '200',
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'url_scan',
'body' => '',
'x_dc_key' => $api_key,
@ -264,6 +276,7 @@ $allTests = array(
'url' => $api_url.'/%blog_id%/settings/system/url_scan',
'method' => 'GET',
'expectedResponseCode' => '200',
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'value',
'body' => '',
'x_dc_key' => $api_key,
@ -274,6 +287,7 @@ $allTests = array(
'url' => $api_url.'/%blog_id%/settings/HEYHEY/url_scan',
'method' => 'GET',
'expectedResponseCode' => '404',
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'code',
'body' => '',
'x_dc_key' => $api_key,
@ -285,6 +299,7 @@ $allTests = array(
'url' => $api_url.'/%blog_id%/settings/test',
'method' => 'POST',
'expectedResponseCode' => '201',
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'code',
'body' => '[{"id":"test","value":"hey","type":"string"},{"id":"test2","value":"hey","type":"string"}]',
'x_dc_key' => $api_key,
@ -295,6 +310,7 @@ $allTests = array(
'url' => $api_url.'/%blog_id%/settings/test',
'method' => 'POST',
'expectedResponseCode' => '403',
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'code',
'body' => '[{"id":"test2","value":"hey","type":"string"}]',
'x_dc_key' => '',
@ -305,6 +321,7 @@ $allTests = array(
'url' => $api_url.'/%blog_id%/settings/test',
'method' => 'POST',
'expectedResponseCode' => '400',
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'code',
'body' => '[{"id"=> Hey"test2","value":"hey","type":"string"}]',
'x_dc_key' => $api_key,
@ -317,6 +334,7 @@ $allTests = array(
'url' => $api_url.'/%blog_id%/settings/test/test2',
'method' => 'DELETE',
'expectedResponseCode' => '403',
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'code',
'body' => '',
'x_dc_key' => 'lkjmlhkjb:b:kjb',
@ -327,6 +345,7 @@ $allTests = array(
'url' => $api_url.'/%blog_id%/settings/test/tsdfLJKt2',
'method' => 'DELETE',
'expectedResponseCode' => '404',
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'code',
'body' => '',
'x_dc_key' => $api_key,
@ -338,12 +357,101 @@ $allTests = array(
'url' => $api_url.'/%blog_id%/settings/test/test2',
'method' => 'DELETE',
'expectedResponseCode' => '200',
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'code',
'body' => '',
'x_dc_key' => $api_key,
'saveAs' => ''
),
//Categories
//create an new category
array(
'title' => 'Create an new Category named cat3',
'url' => $api_url.'/%blog_id%/post/categories',
'method' => 'POST',
'expectedResponseCode' => 200,
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'id',
'body' => json_encode(array(
"cat_title" => "Cat 3",
)),
'x_dc_key' => $api_key,
'saveAs' => 'cat3'
),
array(
'title' => 'Create an new Category named 2',
'url' => $api_url.'/%blog_id%/post/categories',
'method' => 'POST',
'expectedResponseCode' => 200,
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'id',
'body' => json_encode(array(
"cat_title" => "Cat 2",
)),
'x_dc_key' => $api_key,
'saveAs' => 'cat2'
),
array(
'title' => 'Create an new Category named 1',
'url' => $api_url.'/%blog_id%/post/categories',
'method' => 'POST',
'expectedResponseCode' => 200,
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'id',
'body' => json_encode(array(
"cat_title" => "Cat 1",
)),
'x_dc_key' => $api_key,
'saveAs' => 'cat1'
),
array(
'title' => 'Create an new sub Category named 2.1',
'url' => $api_url.'/%blog_id%/post/categories',
'method' => 'POST',
'expectedResponseCode' => 200,
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'id',
'body' => json_encode(array(
"cat_title" => "Cat 2.1",
"cat_parent_id" => '%cat2%'
)),
'x_dc_key' => $api_key,
'saveAs' => 'cat21'
),
//another cat
array(
'title' => 'Create an new Category named 3 that allready exists',
'url' => $api_url.'/%blog_id%/post/categories',
'method' => 'POST',
'expectedResponseCode' => 409,
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'error',
'body' => json_encode(array(
"cat_title" => "Cat 3"
)),
'x_dc_key' => $api_key,
'saveAs' => ''
),
//change the parent of cat 2.1
array(
'title' => 'Change cat parent',
'url' => $api_url.'/%blog_id%/categories/%cat21%',
'method' => 'PATCH',
'expectedResponseCode' => 201,
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'id',
'body' => '{"cat_parent_id": %cat3%}',
'x_dc_key' => $api_key,
'saveAs' => ''
),
//create a POST
array(
@ -351,13 +459,14 @@ $allTests = array(
'url' => $api_url.'/%blog_id%/post',
'method' => 'POST',
'expectedResponseCode' => '200',
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'id',
'body' => json_encode(array(
"post_title" => "New Post",
"post_format"=> "wiki",
"post_content"=> "!!!Pouette \n hey",
"post_content_xhtml"=> "string",
"post_status"=> "Pending",
"post_status"=> 0,
"post_tags" => array('plip','plap')
)),
'x_dc_key' => $api_key,
@ -370,6 +479,7 @@ $allTests = array(
'url' => $api_url.'/%blog_id%/post',
'method' => 'POST',
'expectedResponseCode' => '200',
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'message',
'body' => json_encode(array(
array(
@ -377,14 +487,14 @@ $allTests = array(
"post_format"=> "wiki",
"post_content"=> "!!!Pouette \n hey",
"post_content_xhtml"=> "string",
"post_status"=> "Pending",
"post_status"=> 0,
),
array(
"post_title" => "New Post3",
"post_format"=> "wiki",
"post_content"=> "!!!Pouette \n\n!!hey\n heu...",
"post_content_xhtml"=> "string",
"post_status"=> "Pending",
"post_status"=> 0,
)
)),
'x_dc_key' => $api_key,
@ -398,33 +508,35 @@ $allTests = array(
'url' => $api_url.'/%blog_id%/post',
'method' => 'POST',
'expectedResponseCode' => '200',
'expectedKeyOnResponse' => 'message',
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'id',
'body' => json_encode(array(
"post_title" => "New Post4",
"post_format"=> "wiki",
"post_content"=> "!!!Pouette \n hey",
"post_content_xhtml"=> "string",
"post_status"=> "Pending",
"new_cat_id"=> "TestingCat",
"post_status"=> 0,
"new_cat_title"=> "TestingCat",
)),
'x_dc_key' => $api_key,
'saveAs' => ''
),
//create a post with an existing category
//create a post with an existing category
array(
'title' => 'Create a post /%blog_id%/post with an existing cat',
'title' => 'Create a post /%blog_id%/post with an existing cat %cat_id%',
'url' => $api_url.'/%blog_id%/post',
'method' => 'POST',
'expectedResponseCode' => '200',
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'message',
'body' => json_encode(array(
"post_title" => "New Post5",
"post_format"=> "wiki",
"post_content"=> "!!!Pouette \n hey",
"post_content_xhtml"=> "string",
"post_status"=> "Pending",
"cat_id"=> 1,
"post_status"=> 0,
"cat_id"=> '%cat21%',
)),
'x_dc_key' => $api_key,
'saveAs' => ''
@ -436,15 +548,16 @@ $allTests = array(
'url' => $api_url.'/%blog_id%/post',
'method' => 'POST',
'expectedResponseCode' => '200',
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'message',
'body' => json_encode(array(
"post_title" => "New Post6",
"post_format"=> "wiki",
"post_content"=> "!!!Pouette \n hey",
"post_content_xhtml"=> "string",
"post_status"=> "Pending",
"new_cat_parent" => 1,
"new_cat_id"=> "Testing sub Cat",
"post_status"=> 0,
"new_cat_parent_id" => "%cat3%",
"new_cat_title"=> "Testing sub Cat",
)),
'x_dc_key' => $api_key,
'saveAs' => ''
@ -455,25 +568,26 @@ $allTests = array(
'url' => $api_url.'/%blog_id%/post',
'method' => 'POST',
'expectedResponseCode' => '200',
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'message',
'body' => json_encode(array(
"post_title" => "New Post6",
"post_format"=> "wiki",
"post_content"=> "!!!Pouette \n hey",
"post_content_xhtml"=> "string",
"post_status"=> "Pending",
"new_cat_parent" => 1,
"new_cat_id"=> "Testing sub Cat 2",
"post_dt" => '2013-04-19 05:06:07',
"post_password" => 'toto',
"post_url" => "newPost",
"post_lang" => "de",
"post_excerpt" => "blahblah",
"post_notes" => "heu...",
"post_selected" => true,
"post_open_comment" => true,
"post_open_tb" => true,
)),
'body' =>'{
"post_title":"New Post6",
"post_format":"wiki",
"post_content":"!!!Pouette \n hey",
"post_content_xhtml":"string",
"post_status":0,
"new_cat_parent_id":%cat21%,
"new_cat_title":"Testing sub Cat 2",
"post_dt":"2013-04-19 05:06:07",
"post_password":"toto",
"post_url":"newPost",
"post_lang":"de",
"post_excerpt":"blahblah",
"post_notes":"heu...",
"post_selected":true,
"post_open_comment":true,
"post_open_tb":true
}',
'x_dc_key' => $api_key,
'saveAs' => ''
),
@ -485,36 +599,62 @@ $allTests = array(
'url' => $api_url.'/%blog_id%/metas',
'method' => 'POST',
'expectedResponseCode' => '201',
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => 'id',
'body' => '{ "meta_id": "lol", "meta_type": "tag", "post_id": %post_id% }',
'x_dc_key' => $api_key,
'saveAs' => 'meta_id'
),
//Get metas
array(
'title' => 'get all meta /%blog_id%/metas',
'url' => $api_url.'/%blog_id%/metas',
'method' => 'GET',
'expectedResponseCode' => '200',
'responseIsArrayOfObjects' => true,
'expectedKeyOnResponse' => 'meta_id',
'body' => '',
'x_dc_key' => $api_key,
'saveAs' => ''
),
array(
'title' => 'get all meta /%blog_id%/metas?meta_type=tag',
'url' => $api_url.'/%blog_id%/metas',
'method' => 'GET',
'expectedResponseCode' => '200',
'responseIsArrayOfObjects' => true,
'expectedKeyOnResponse' => 'meta_id',
'body' => '',
'x_dc_key' => $api_key,
'saveAs' => ''
),
// delete a meta
array(
'title' => 'delete q meta /%blog_id%/%post_id%/meta/%meta_id%',
'url' => $api_url.'/%blog_id%/%post_id%/meta/%meta_id%',
'method' => 'DELETE',
'expectedResponseCode' => '200',
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => false,
'body' => '',
'x_dc_key' => $api_key,
'saveAs' => ''
),
// delete all metas for a blog
array(
'title' => 'delete q meta /%blog_id%/%post_id%/metas',
'url' => $api_url.'/%blog_id%/%post_id%/metas',
'method' => 'DELETE',
'expectedResponseCode' => '200',
'responseIsArrayOfObjects' => false,
'expectedKeyOnResponse' => false,
'body' => '',
'x_dc_key' => $api_key,
'saveAs' => ''
),
/*
"post_title": "string",
"post_format": "string",
"post_content": "string",
"post_content_xhtml": "string",
"post_status": "Pending",
"cat_id": 0,
"new_cat_id": "string",
"new_cat_parent_id": 0,
"new_cat_desc": "string",
"new_cat_url": "string",
"post_dt": "string",
"post_password": "string",
"post_url": "string",
"post_lang": "string",
"post_excerpt": "string",
"post_excerpt_xhtml": "string",
"post_notes": "string",
"post_selected": true,
"post_open_comment": true,
"post_open_tb": true,
"post_words": [
null
]
*/
/*
@ -540,18 +680,22 @@ foreach($allTests as $oneTest){
//replaces
foreach($oneTest as $key => $value){
foreach($saveIds as $find => $replace){
$value = $oneTest[$key] = str_replace('%'.$find.'%', $replace, (string)$value);
if(is_string($value)){
$value = $oneTest[$key] = str_replace('%'.$find.'%', $replace, (string)$value);
}
}
}
echo "\nTesting ".$oneTest['title']." ".$oneTest['url']." method ". $oneTest['method'];
$t = test(
$oneTest['url'],
$oneTest['method'],
$oneTest['body'],
$oneTest['expectedResponseCode'],
$oneTest['responseIsArrayOfObjects'],
$oneTest['expectedKeyOnResponse'],
$oneTest['x_dc_key']
);

Loading…
Cancel
Save