reasonableframework/route/api.gnuboard.php

64 lines
1.6 KiB
PHP
Raw Normal View History

2018-05-30 15:54:47 +00:00
<?php
/**
* @file api.gnuboard.php
2018-05-30 15:54:47 +00:00
* @date 2018-05-31
* @author Go Namhyeon <gnh1201@gmail.com>
2018-08-19 13:57:37 +00:00
* @brief Integration controller for Gnuboard CMS 4.x, 5.x
2018-05-30 15:54:47 +00:00
*/
2018-05-30 15:57:36 +00:00
/**** how to test ***/
/* read: GET/POST [base_url]/?route=gnbapi&action=read&bo_table=[bo_table]&wr_id=[wr_id] */
/* write: GET/POST [base_url]/?route=gnbapi&action=write&bo_table=[bo_table]&wr_subject=mysubject&wr_content=mycontent&version=[4 or 5] */
2018-08-24 15:00:20 +00:00
if(!defined("_DEF_RSF_")) set_error_exit("do not allow access");
2018-05-30 15:54:47 +00:00
loadHelper("gnuboard.dbt");
$action = get_requested_value("action");
$bo_table = get_requested_value("bo_table");
$data = array();
$result = array(
2019-05-20 08:19:05 +00:00
"success" => false
2018-05-30 15:54:47 +00:00
);
switch($action) {
2019-05-20 08:19:05 +00:00
case "write":
$version = get_requested_value("version");
$data = array(
"wr_subject" => get_requested_value("wr_subject"),
"wr_content" => get_requested_value("wr_content"),
);
for($i = 0; $i < 10; $i++) {
$data["wr_" . $i] = get_requested_value("wr_" . $i);
}
if($wr_id = gnb_write_post($bo_table, $data, $version)) {
$result = array(
"success" => true,
"data" => array(
"wr_id" => $wr_id,
),
);
}
break;
case "read":
$wr_id = get_requested_value("wr_id");
$row = gnb_get_post_by_id($bo_table, $wr_id);
if(!array_key_empty("wr_id", $row)) {
$result = array(
"success" => true,
"data" => $row
);
}
2018-05-30 15:54:47 +00:00
}
2018-08-24 15:18:19 +00:00
set_header_content_type("json");
2018-05-30 15:54:47 +00:00
echo json_encode($result);