Site controller and routes.
このコミットが含まれているのは:
コミット
6bd26f26a5
|
@ -0,0 +1,167 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Contracts\Routing\ResponseFactory;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
use App\Http\Controllers\AuthController;
|
||||
use App\Http\Controllers\UserController;
|
||||
use App\Http\Controllers\PermissionController;
|
||||
|
||||
class SiteController extends Controller {
|
||||
private $objAuth;
|
||||
private $objUser;
|
||||
private $objPermission;
|
||||
|
||||
public function __contruct() {
|
||||
$this->objAuth = new AuthController();
|
||||
$this->objUser = new UserController();
|
||||
$this->objPermission = new PermissionController();
|
||||
}
|
||||
|
||||
public function getPosts() { // /api/rpc/site/post/getposts
|
||||
$get = DB::table('blg_content')
|
||||
->select('id', 'user_id', 'title', 'slug', 'post_date', 'publish_date', 'message')
|
||||
->where('public_status', 1)
|
||||
->where('isPost', 1)
|
||||
->orderBy('publish_date', 'desc')
|
||||
->get();
|
||||
|
||||
$res = array();
|
||||
$key = 0;
|
||||
|
||||
setlocale(LC_ALL, 'ja_JP.utf8');
|
||||
|
||||
foreach ($get as $i) {
|
||||
array_push($res, [
|
||||
'key' => $key,
|
||||
'id' => $i->id,
|
||||
'user_id' => $i->user_id,
|
||||
'title' => $i->title,
|
||||
'slug' => $i->slug,
|
||||
'post_date' => strftime('%Y/%m/%d(%a) %H:%M:%S %Z', $i->post_date),
|
||||
'publish_date' => strftime('%Y/%m/%d(%a) %H:%M:%S %Z', $i->publish_date),
|
||||
'message' => $i->message
|
||||
]);
|
||||
$key++;
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function getPost($slug) { // /api/rpc/site/post/getpost/slug
|
||||
$get = DB::table('blg_content')
|
||||
->select('id', 'user_id', 'title', 'slug', 'post_date', 'publish_date', 'message')
|
||||
->where('public_status', 1)
|
||||
->where('isPost', 1)
|
||||
->where('slug', $slug)
|
||||
->orderBy('publish_date', 'desc')
|
||||
->get();
|
||||
|
||||
$res = array();
|
||||
|
||||
setlocale(LC_ALL, 'ja_JP.utf8');
|
||||
|
||||
foreach ($get as $i) {
|
||||
array_push($res, [
|
||||
'id' => $i->id,
|
||||
'user_id' => $i->user_id,
|
||||
'title' => $i->title,
|
||||
'slug' => $i->slug,
|
||||
'post_date' => strftime('%Y/%m/%d(%a) %H:%M:%S %Z', $i->post_date),
|
||||
'publish_date' => strftime('%Y/%m/%d(%a) %H:%M:%S %Z', $i->publish_date),
|
||||
'message' => $i->message
|
||||
]);
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function getPages() { // /api/rpc/site/page/getpages
|
||||
$get = DB::table('blg_content')
|
||||
->select('id', 'user_id', 'title', 'slug', 'message')
|
||||
->where('public_status', 1)
|
||||
->where('isPost', 0)
|
||||
->orderBy('sortorder', 'asc')
|
||||
->get();
|
||||
|
||||
$res = array();
|
||||
$key = 0;
|
||||
|
||||
foreach ($get as $i) {
|
||||
array_push($res, [
|
||||
'key' => $key,
|
||||
'id' => $i->id,
|
||||
'user_id' => $i->user_id,
|
||||
'title' => $i->title,
|
||||
'slug' => $i->slug,
|
||||
'message' => $i->message
|
||||
]);
|
||||
$key++;
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function getPage($slug) { // /api/rpc/site/page/getpage/slug
|
||||
$get = DB::table('blg_content')
|
||||
->select('id', 'user_id', 'title', 'slug', 'message')
|
||||
->where('public_status', 1)
|
||||
->where('isPost', 0)
|
||||
->where('slug', $slug)
|
||||
->orderBy('sortorder', 'asc')
|
||||
->get();
|
||||
|
||||
$res = array();
|
||||
|
||||
foreach ($get as $i) {
|
||||
array_push($res, [
|
||||
'id' => $i->id,
|
||||
'user_id' => $i->user_id,
|
||||
'title' => $i->title,
|
||||
'slug' => $i->slug,
|
||||
'message' => $i->message
|
||||
]);
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function getComments($id) { // /api/rpc/site/post/getcomments/id
|
||||
$get = DB::table('blg_comments')
|
||||
->select('id', 'user_id', 'content_id', 'votes', 'post_date', 'last_date', 'isDeleted', 'message', 'ip_address')
|
||||
->where('content_id', $id)
|
||||
->orderBy('post_date', 'asc')
|
||||
->get();
|
||||
|
||||
$res = array();
|
||||
$key = 0;
|
||||
|
||||
foreach ($get as $i) {
|
||||
array_push($res, [
|
||||
'key' => $key,
|
||||
'id' => $i->id,
|
||||
'user_id' => $i->user_id,
|
||||
'content_id' => $i->content_id,
|
||||
'votes' => $i->votes,
|
||||
'post_date' => strftime('%Y/%m/%d(%a) %H:%M:%S %Z', $i->post_date),
|
||||
'last_date' => strftime('%Y/%m/%d(%a) %H:%M:%S %Z', $i->last_date),
|
||||
'isDeleted' => $i->isDeleted,
|
||||
'message' => $i->message,
|
||||
'ip_address' => $i->ip_address
|
||||
]);
|
||||
$key++;
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function getSettings() { // /api/rpc/site/admin/getsettings
|
||||
return DB::table('blg_settings')
|
||||
->select('sitename', 'description', 'tags', 'blog_status', 'announcement', 'theme', 'locale')
|
||||
->get();
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Page class
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| These are the API routes corresponding to page.
|
||||
|
|
||||
*/
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Site class
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| These are the API routes corresponding to site.
|
||||
|
|
||||
*/
|
||||
|
||||
// Posts
|
||||
Route::get('/api/rpc/site/post/getposts', 'SiteController@getPosts');
|
||||
Route::get('/api/rpc/site/post/getpost/{slug}', 'SiteController@getPost');
|
||||
Route::get('/api/rpc/site/post/getcomments/{id}', 'SiteController@getComments');
|
||||
|
||||
// Pages
|
||||
Route::get('/api/rpc/site/page/getpages', 'SiteController@getPages');
|
||||
Route::get('/api/rpc/site/page/getpage/{slug}', 'SiteController@getPage');
|
||||
|
||||
// Admin
|
||||
Route::get('/api/rpc/site/admin/getsettings', 'SiteController@getSettings');
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
require(__DIR__.'/class/board.php');
|
||||
// require(__DIR__.'/class/image.php');
|
||||
// require(__DIR__.'/class/page.php');
|
||||
require(__DIR__.'/class/site.php');
|
||||
require(__DIR__.'/class/store.php');
|
||||
require(__DIR__.'/class/user.php');
|
||||
|
||||
|
|
新しいイシューから参照