This repository has been archived on 2022-02-10. You can view files and clone it, but cannot push or open issues or pull requests.
rangitaki/rcc/api/list/index.php

60 lines
1.7 KiB
PHP
Raw Normal View History

2016-04-18 09:53:47 +02:00
<?php
// Marcel Kapfer (mmk2410)
// License: MIT License
// api for fetching various lists
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require '../../../vendor/autoload.php';
require '../../../res/php/Config.php';
use \mmk2410\rbe\config\Config as Config;
$config = new Config("../../../config.yaml", '../../../vendor/autoload.php');
$settings = $config->getConfig();
include '../auth/auth.php';
2016-04-18 09:53:47 +02:00
if ($settings["rcc"]["api"] == "on" && $settings["rcc"]["rcc"] == "on") {
$app = new \Slim\App();
/**
2016-04-18 09:57:11 +02:00
* api for get the list of blogs and if $_GET["blog"] is set the list of
* blogs posts in that blog
2016-04-18 09:53:47 +02:00
*
* @param string $_GET["blog"] optional name of the blog
*
* @return JSON json string containing the blogs / blog posts
*/
$app->get('/', function (Request $request, Response $response) {
$blog = $_GET["blog"];
if (!isset($blog)) {
$files = scandir('../../../blogs/', SCANDIR_SORT_DESCENDING);
unset($files[sizeof($files) - 1]);
unset($files[sizeof($files) - 1]);
$response = $response->withHeader('Content-type', 'application/json');
$response = $response->withJson($files, 201);
return $response;
}
$path = "../../../articles/" . $blog . "/";
$files = scandir($path, SCANDIR_SORT_DESCENDING);
unset($files[sizeof($files) - 1]);
unset($files[sizeof($files) - 1]);
$response = $response->withHeader('Content-type', 'application/json');
$response = $response->withJson($files, 201);
return $response;
});
$app->run();
}