You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
2.9 KiB
110 lines
2.9 KiB
<?php
|
|
// SPDX-License-Identifier: EUPL-1.2
|
|
// Authors: see README.md
|
|
|
|
use SeaCMS\Api\LateApiAware;
|
|
use SeaCMS\Api\JsonResponse;
|
|
use SeaCMS\App\MdResponse;
|
|
|
|
/**
|
|
* A plugin for SeaCMS-app.
|
|
*/
|
|
class SeacmsAppPlugin extends AbstractPicoPlugin implements LateApiAware
|
|
{
|
|
/**
|
|
* Pico API version.
|
|
* @var int
|
|
*/
|
|
const API_VERSION = 3;
|
|
|
|
/**
|
|
* return api routes
|
|
* @return array
|
|
*/
|
|
public function registerApiRoutes():array
|
|
{
|
|
return [
|
|
];
|
|
}
|
|
|
|
/**
|
|
* return api routes
|
|
* @return array
|
|
*/
|
|
public function registerLateApiRoutes():array
|
|
{
|
|
return [
|
|
'POST pages/(.*)/create' => 'createPage', // TODO only define for POST
|
|
'GET pages' => 'apiPagesBase',
|
|
'GET pages/(.*)' => 'apiPageBase',
|
|
'GET pages/(.*)/md' => 'apiPageAsMd'
|
|
];
|
|
}
|
|
|
|
/**
|
|
* method to create a page
|
|
* @return JsonResponse
|
|
*/
|
|
public function createPage(string $pageName): JsonResponse
|
|
{
|
|
return new JsonResponse(501,['code'=>501,'reason'=>"work in progress for '$pageName'"]);
|
|
}
|
|
|
|
/**
|
|
* method to see base of pages api
|
|
* @return JsonResponse
|
|
*/
|
|
public function apiPagesBase(): JsonResponse
|
|
{
|
|
return new JsonResponse(200,[
|
|
'title' => 'Base api route to see pages',
|
|
'routes' => [
|
|
'Base for one page' => urldecode($this->getPico()->getPageUrl('index',[
|
|
'api' => 'pages/<NameOfPage>'
|
|
])),
|
|
'page as Markdown' => urldecode($this->getPico()->getPageUrl('index',[
|
|
'api' => 'pages/<NameOfPage>/md'
|
|
])),
|
|
'page as Markdown Extra' => urldecode($this->getPico()->getPageUrl('index',[
|
|
'api' => 'pages/<NameOfPage>/mdx'
|
|
]))
|
|
]
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* method to see base of page api
|
|
* @return JsonResponse
|
|
*/
|
|
public function apiPageBase(string $pageName): JsonResponse
|
|
{
|
|
return new JsonResponse(200,[
|
|
'title' => 'Base api route to see page',
|
|
'routes' => [
|
|
'page as Markdown' => $this->getPico()->getPageUrl('index',[
|
|
'api' => "pages/$pageName/md"
|
|
]),
|
|
'page as Markdown Extra' => $this->getPico()->getPageUrl('index',[
|
|
'api' => "pages/$pageName/mdx"
|
|
])
|
|
]
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* method to see page as md
|
|
* @return JsonResponse
|
|
*/
|
|
public function apiPageAsMd(string $pageName): JsonResponse
|
|
{
|
|
$pages = $this->getPico()->getPages();
|
|
if (array_key_exists($pageName,$pages)){
|
|
|
|
return new MdResponse(200,$pages[$pageName]['raw_content']);
|
|
} else {
|
|
return new JsonResponse(404,['code'=>404,'reason'=>"Page '$pageName' has not been found !"]);
|
|
}
|
|
|
|
}
|
|
|
|
} |