2018-01-24 01:36:47 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2018-01-24 04:44:45 +09:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2018-01-24 01:36:47 +09:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
2018-02-07 16:21:15 +09:00
|
|
|
class StoreController extends Controller {
|
2018-03-06 21:34:53 +09:00
|
|
|
private $objUser;
|
|
|
|
private $objPermission;
|
2018-03-09 16:34:16 +09:00
|
|
|
private $storePath;
|
2018-03-06 21:34:53 +09:00
|
|
|
|
|
|
|
public function __construct() {
|
2018-03-09 16:34:16 +09:00
|
|
|
$this->storePath = storage_path('app/public/store');
|
2018-03-06 21:34:53 +09:00
|
|
|
$this->objUser = new UserController();
|
|
|
|
$this->objPermission = new PermissionController();
|
|
|
|
}
|
|
|
|
|
2018-03-05 17:34:47 +09:00
|
|
|
// Game
|
|
|
|
public function getGames() { // /api/rpc/store/game/getgames
|
2018-03-12 19:59:41 +09:00
|
|
|
return DB::table('str_games_loc')
|
|
|
|
->join('str_games', 'str_games.id', '=', 'str_games_loc.ref_id')
|
|
|
|
->get(array(
|
|
|
|
'str_games.id',
|
|
|
|
'str_games.name',
|
|
|
|
'str_games_loc.name as altname'
|
|
|
|
));
|
2018-03-05 17:34:47 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getGame($id) { // /api/rpc/store/game/getgame/id
|
2018-03-12 19:59:41 +09:00
|
|
|
return DB::table('str_games_loc')
|
|
|
|
->join('str_games', 'str_games.id', '=', 'str_games_loc.ref_id')
|
|
|
|
->where('str_games.id', $id)
|
|
|
|
->get(array(
|
|
|
|
'str_games.id',
|
|
|
|
'str_games.name',
|
|
|
|
'str_games_loc.name as altname'
|
|
|
|
));
|
2018-03-05 17:34:47 +09:00
|
|
|
}
|
2018-02-07 16:21:15 +09:00
|
|
|
|
2018-03-05 18:59:58 +09:00
|
|
|
public function newGame(Request $request) { // /api/rpc/store/games/newgame
|
2018-03-05 19:34:01 +09:00
|
|
|
$add = DB::table('str_games')
|
2018-03-05 18:59:58 +09:00
|
|
|
->insert([
|
|
|
|
'name' => $request->name
|
|
|
|
]);
|
|
|
|
|
|
|
|
return \Response::json($add);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function editGame(Request $request) { // /api/rpc/store/games/editgame
|
2018-03-05 19:34:01 +09:00
|
|
|
return DB::table('str_games')
|
2018-03-05 18:59:58 +09:00
|
|
|
->where('id', $request->id)
|
|
|
|
->update([
|
|
|
|
'name' => $request->name
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2018-03-05 17:34:47 +09:00
|
|
|
// Category
|
2018-02-07 16:21:15 +09:00
|
|
|
public function getCategories() { // /api/rpc/store/category/getcategories
|
2018-03-12 19:59:41 +09:00
|
|
|
return DB::table('str_category_loc')
|
|
|
|
->join('str_category', 'str_category.id', '=', 'str_category_loc.ref_id')
|
|
|
|
->get(array(
|
|
|
|
'str_category.id',
|
|
|
|
'str_category.name',
|
|
|
|
'str_category_loc.name as altname',
|
|
|
|
'str_category.game_id',
|
|
|
|
'str_category.min_screenshots'
|
|
|
|
));
|
2018-02-07 16:21:15 +09:00
|
|
|
}
|
|
|
|
|
2018-03-05 17:34:47 +09:00
|
|
|
public function getCategory($id) { // /api/rpc/store/category/getcategory/id
|
2018-03-12 19:59:41 +09:00
|
|
|
return DB::table('str_category_loc')
|
|
|
|
->join('str_category', 'str_category.id', '=', 'str_category_loc.ref_id')
|
|
|
|
->where('str_category.id', $id)
|
|
|
|
->get(array(
|
|
|
|
'str_category.id',
|
|
|
|
'str_category.name',
|
|
|
|
'str_category_loc.name as altname',
|
|
|
|
'str_category.game_id',
|
|
|
|
'str_category.min_screenshots'
|
|
|
|
));
|
2018-02-07 16:21:15 +09:00
|
|
|
}
|
|
|
|
|
2018-03-05 17:57:23 +09:00
|
|
|
public function getCategoriesOfGame($id) { // /api/rpc/store/category/getcategoriesofgame/id
|
2018-03-12 19:59:41 +09:00
|
|
|
return DB::table('str_category_loc')
|
|
|
|
->join('str_category', 'str_category.id', '=', 'str_category_loc.ref_id')
|
2018-03-05 17:57:23 +09:00
|
|
|
->join('str_games', 'str_category.game_id', '=', 'str_games.id')
|
|
|
|
->where('str_games.id', $id)
|
|
|
|
->get(array(
|
|
|
|
'str_category.id',
|
2018-03-12 19:59:41 +09:00
|
|
|
'str_category.name',
|
|
|
|
'str_category_loc.name as altname'
|
2018-03-05 17:57:23 +09:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2018-03-05 18:33:48 +09:00
|
|
|
public function getGameOfCategory($id) { // /api/rpc/store/category/getgameofcategory/id
|
2018-03-13 18:52:49 +09:00
|
|
|
return DB::table('str_games_loc')
|
|
|
|
->join('str_games', 'str_games.id', '=', 'str_games_loc.ref_id')
|
|
|
|
->join('str_category', 'str_category.game_id', '=', 'str_games.id')
|
2018-03-05 18:33:48 +09:00
|
|
|
->where('str_category.id', $id)
|
|
|
|
->get(array(
|
|
|
|
'str_games.id',
|
2018-03-13 18:52:49 +09:00
|
|
|
'str_games.name',
|
|
|
|
'str_games_loc.name as altname'
|
2018-03-05 18:33:48 +09:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2018-03-05 17:34:47 +09:00
|
|
|
public function getCategoryGame($id) { // /api/rpc/store/category/getcategorygame/id
|
2018-02-07 16:21:15 +09:00
|
|
|
return DB::table('str_category')
|
2018-03-05 17:13:20 +09:00
|
|
|
->select('game_id')
|
2018-02-07 16:21:15 +09:00
|
|
|
->where('id', $id)
|
|
|
|
->get();
|
|
|
|
}
|
|
|
|
|
2018-03-05 17:34:47 +09:00
|
|
|
public function getCategoryMinScreenshots($id) { // /api/rpc/store/category/getcategoryminscrot/id
|
2018-02-07 16:21:15 +09:00
|
|
|
return DB::table('str_category')
|
|
|
|
->select('min_screenshots')
|
|
|
|
->where('id', $id)
|
|
|
|
->get();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCategoryName($id) { // /api/rpc/store/category/getcategoryname/id
|
2018-03-13 18:52:49 +09:00
|
|
|
return DB::table('str_category_loc')
|
|
|
|
->join('str_category', 'str_category.id', '=', 'str_category_loc.ref_id')
|
|
|
|
->where('str_category.id', $id)
|
|
|
|
->get(array(
|
|
|
|
'str_category.name',
|
|
|
|
'str_category_loc.name as altname'
|
|
|
|
));
|
2018-02-07 16:21:15 +09:00
|
|
|
}
|
|
|
|
|
2018-03-12 22:43:54 +09:00
|
|
|
public function getCategoryNameOfEntry($id) { // /api/rpc/store/category/getcategorynameofentry/id
|
|
|
|
return DB::table('str_file')
|
|
|
|
->join('str_category', 'str_category.id', '=', 'str_file.cat_id')
|
2018-03-13 18:52:49 +09:00
|
|
|
->join('str_category_loc', 'str_category.id', '=', 'str_category_loc.ref_id')
|
2018-03-12 22:43:54 +09:00
|
|
|
->where('str_file.id', $id)
|
2018-03-13 18:52:49 +09:00
|
|
|
->get(array(
|
|
|
|
'str_category.name',
|
|
|
|
'str_category_loc.name as altname'
|
|
|
|
));
|
2018-03-12 22:43:54 +09:00
|
|
|
}
|
|
|
|
|
2018-03-05 18:59:58 +09:00
|
|
|
public function newCategory(Request $request) { // /api/rpc/store/category/newcategory
|
|
|
|
$add = DB::table('str_category')
|
|
|
|
->insert([
|
|
|
|
'name' => $request->name,
|
2018-03-05 20:06:15 +09:00
|
|
|
'game_id' => $request->game_id,
|
2018-03-05 18:59:58 +09:00
|
|
|
'min_screenshots' => $request->min_screenshots
|
|
|
|
]);
|
|
|
|
|
|
|
|
return \Response::json($add);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function editCategory(Request $request) { // /api/rpc/store/category/editcategory
|
|
|
|
return DB::table('str_category')
|
|
|
|
->where('id', $request->id)
|
|
|
|
->update([
|
|
|
|
'name' => $request->name,
|
|
|
|
'min_screenshots' => $request->min_screenshots
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2018-02-07 16:21:15 +09:00
|
|
|
// Entries
|
|
|
|
public function getAllEntries() { // /api/rpc/store/entry/getallentries
|
2018-01-24 23:58:21 +09:00
|
|
|
return DB::table('str_file')
|
|
|
|
->select('*')
|
|
|
|
->get();
|
2018-01-24 01:36:47 +09:00
|
|
|
}
|
|
|
|
|
2018-02-07 16:21:15 +09:00
|
|
|
public function getAllApprovedEntries() { // /api/rpc/store/entry/getallapprovedentries
|
2018-01-24 23:58:21 +09:00
|
|
|
return DB::table('str_file')
|
|
|
|
->select('*')
|
|
|
|
->where('isApproved', 1)
|
|
|
|
->get();
|
2018-01-24 01:36:47 +09:00
|
|
|
}
|
|
|
|
|
2018-02-07 16:21:15 +09:00
|
|
|
public function getAllBrokenEntries() { // /api/rpc/store/entry/getallbrokenentries
|
2018-01-24 23:58:21 +09:00
|
|
|
return DB::table('str_file')
|
|
|
|
->select('*')
|
|
|
|
->where('isBroken', 1)
|
|
|
|
->get();
|
2018-01-24 01:36:47 +09:00
|
|
|
}
|
|
|
|
|
2018-02-07 16:21:15 +09:00
|
|
|
public function getAllPendingEntries() { // /api/rpc/store/entry/getallpendingentries
|
2018-01-24 23:58:21 +09:00
|
|
|
return DB::table('str_file')
|
|
|
|
->select('*')
|
|
|
|
->where('isApproved', 0)
|
|
|
|
->get();
|
2018-01-24 01:36:47 +09:00
|
|
|
}
|
|
|
|
|
2018-02-07 16:21:15 +09:00
|
|
|
public function getNewEntries() { // /api/rpc/store/entry/getnewentries
|
2018-01-31 20:05:52 +09:00
|
|
|
return DB::table('str_file')
|
2018-02-01 18:29:19 +09:00
|
|
|
->select(
|
|
|
|
'id',
|
|
|
|
'title',
|
|
|
|
'version',
|
|
|
|
'submit_date'
|
|
|
|
)
|
2018-01-31 20:05:52 +09:00
|
|
|
->where('isApproved', 1)
|
|
|
|
->orderBy('submit_date', 'desc')
|
|
|
|
->limit(5)
|
|
|
|
->get();
|
2018-01-24 01:36:47 +09:00
|
|
|
}
|
|
|
|
|
2018-02-07 16:21:15 +09:00
|
|
|
public function getHotEntries() { // /api/rpc/store/entry/gethotentries
|
2018-01-31 20:05:52 +09:00
|
|
|
return DB::table('str_file')
|
2018-02-01 18:29:19 +09:00
|
|
|
->select(
|
|
|
|
'id',
|
|
|
|
'title',
|
|
|
|
'version',
|
|
|
|
'downloads'
|
|
|
|
)
|
2018-01-31 20:05:52 +09:00
|
|
|
->where('isApproved', 1)
|
|
|
|
->orderBy('downloads', 'desc')
|
|
|
|
->limit(5)
|
|
|
|
->get();
|
2018-01-24 01:36:47 +09:00
|
|
|
}
|
|
|
|
|
2018-02-07 16:21:15 +09:00
|
|
|
public function getEntriesPageAll($cat, $from, $to) { // /api/rpc/store/entry/getentriespageall/cat/from/to
|
2018-01-31 17:33:47 +09:00
|
|
|
return DB::table('str_file')
|
|
|
|
->select(
|
|
|
|
'id',
|
|
|
|
'title',
|
|
|
|
'version',
|
|
|
|
'description',
|
|
|
|
'submit_date',
|
|
|
|
'last_date',
|
|
|
|
'views',
|
|
|
|
'downloads'
|
|
|
|
)
|
|
|
|
->where('cat_id', $cat)
|
|
|
|
->offset($from)
|
|
|
|
->limit($to)
|
|
|
|
->get();
|
|
|
|
}
|
|
|
|
|
2018-02-07 16:21:15 +09:00
|
|
|
public function getEntriesPageApproved($cat, $from, $to) { // /api/rpc/store/entry/getentriespageapproved/cat/from/to
|
2018-01-31 17:33:47 +09:00
|
|
|
return DB::table('str_file')
|
|
|
|
->select(
|
|
|
|
'id',
|
|
|
|
'title',
|
|
|
|
'version',
|
|
|
|
'description',
|
|
|
|
'submit_date',
|
|
|
|
'last_date',
|
|
|
|
'views',
|
|
|
|
'downloads'
|
|
|
|
)
|
|
|
|
->where('cat_id', $cat)
|
|
|
|
->where('isApproved', 1)
|
|
|
|
->offset($from)
|
|
|
|
->limit($to)
|
|
|
|
->get();
|
|
|
|
}
|
|
|
|
|
2018-02-07 16:21:15 +09:00
|
|
|
public function getEntriesPagePopularView($cat, $from, $to) { // /api/rpc/store/entry/getentriespagepopularview/cat/from/to
|
2018-01-31 17:33:47 +09:00
|
|
|
return DB::table('str_file')
|
|
|
|
->select(
|
|
|
|
'id',
|
|
|
|
'title',
|
|
|
|
'version',
|
|
|
|
'description',
|
|
|
|
'submit_date',
|
|
|
|
'last_date',
|
|
|
|
'views',
|
|
|
|
'downloads'
|
|
|
|
)
|
|
|
|
->where('cat_id', $cat)
|
|
|
|
->where('views', '>', 1000)
|
|
|
|
->offset($from)
|
|
|
|
->limit($to)
|
|
|
|
->get();
|
|
|
|
}
|
|
|
|
|
2018-02-07 16:21:15 +09:00
|
|
|
public function getEntriesPagePopularDownload($cat, $from, $to) { // /api/rpc/store/entry/getentriespagepopulardownload/cat/from/to
|
2018-01-31 17:33:47 +09:00
|
|
|
return DB::table('str_file')
|
|
|
|
->select(
|
|
|
|
'id',
|
|
|
|
'title',
|
|
|
|
'version',
|
|
|
|
'description',
|
|
|
|
'submit_date',
|
|
|
|
'last_date',
|
|
|
|
'views',
|
|
|
|
'downloads'
|
|
|
|
)
|
|
|
|
->where('cat_id', $cat)
|
|
|
|
->where('downloads', '>', 1000)
|
|
|
|
->offset($from)
|
|
|
|
->limit($to)
|
|
|
|
->get();
|
|
|
|
}
|
|
|
|
|
2018-03-02 23:44:25 +09:00
|
|
|
public function getChangelog($id) { // /api/rpc/store/entry/getchangelog/id
|
|
|
|
return DB::table('str_file')
|
|
|
|
->select('version', 'changelog')
|
|
|
|
->where('id', $id)
|
|
|
|
->get();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getNotice($id) { // /api/rpc/store/entry/getnotice/id
|
|
|
|
return DB::table('str_file')
|
|
|
|
->select('title', 'version', 'warningnote')
|
|
|
|
->where('id', $id)
|
|
|
|
->get();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDownloadCount($id) { // /api/rpc/store/entry/getdownloadcount/id
|
|
|
|
return DB::table('str_file')
|
|
|
|
->select('downloads')
|
|
|
|
->where('id', $id)
|
|
|
|
->get();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function updateDownloadCount(Request $request) { // /api/rpc/store/entry/updatedownloadcount
|
|
|
|
return DB::table('str_file')
|
|
|
|
->where('id', $request->id)
|
|
|
|
->update(['downloads', $request->downloads]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function FileSizeConvert($bytes) {
|
|
|
|
$bytes = floatval($bytes);
|
|
|
|
$arBytes = array(
|
|
|
|
0 => array(
|
|
|
|
// "UNIT" => "TiB",
|
|
|
|
// "VALUE" => pow(1024, 4)
|
|
|
|
"UNIT" => "TQ",
|
|
|
|
"VALUE" => pow(4096, 4)
|
|
|
|
),
|
|
|
|
1 => array(
|
|
|
|
// "UNIT" => "GiB",
|
|
|
|
// "VALUE" => pow(1024, 3)
|
|
|
|
"UNIT" => "GQ",
|
|
|
|
"VALUE" => pow(4096, 3)
|
|
|
|
),
|
|
|
|
2 => array(
|
|
|
|
// "UNIT" => "MiB",
|
|
|
|
// "VALUE" => pow(1024, 2)
|
|
|
|
"UNIT" => "MQ",
|
|
|
|
"VALUE" => pow(4096, 2)
|
|
|
|
),
|
|
|
|
3 => array(
|
|
|
|
// "UNIT" => "KiB",
|
|
|
|
// "VALUE" => 1024
|
|
|
|
"UNIT" => "KQ",
|
|
|
|
"VALUE" => 4096
|
|
|
|
),
|
|
|
|
4 => array(
|
|
|
|
// "UNIT" => "B",
|
|
|
|
"UNIT" => "Q",
|
|
|
|
"VALUE" => 1
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach($arBytes as $arItem) {
|
|
|
|
if($bytes >= $arItem["VALUE"]) {
|
|
|
|
$result = $bytes / $arItem["VALUE"];
|
|
|
|
$result = strval(round($result, 2))." ".$arItem["UNIT"];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFilesOfEntry($id) { // /api/rpc/store/entry/getfilesofentry/id
|
|
|
|
$files = array_map("htmlspecialchars", scandir("assets/store/$id"));
|
|
|
|
$files = array_diff($files, array('..', '.', 'screens'));
|
|
|
|
|
|
|
|
$result = array();
|
|
|
|
|
|
|
|
foreach ($files as $file) {
|
|
|
|
array_push($result, [
|
|
|
|
'id' => $id,
|
|
|
|
'file' => $file,
|
|
|
|
'size' => $this->FileSizeConvert(filesize('assets/store/'.$id.'/'.$file))
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2018-03-05 23:08:44 +09:00
|
|
|
public function getNextEntryId() { // /api/rpc/store/entry/getnextentryid
|
|
|
|
$get = DB::table('str_file')->max('id');
|
|
|
|
$get++;
|
|
|
|
|
|
|
|
return $get;
|
|
|
|
}
|
|
|
|
|
2018-03-02 00:59:26 +09:00
|
|
|
public function getEntry($id, $mode) { // /api/rpc/store/entry/getentry/id/mode
|
|
|
|
if ($mode == 'user') {
|
|
|
|
return DB::table('str_owners')
|
|
|
|
->join('str_file', 'str_owners.file_id', '=', 'str_file.id')
|
|
|
|
->join('users', 'str_owners.user_id', '=', 'users.id')
|
|
|
|
->join('usr_details', 'usr_details.user_id', '=', 'str_owners.user_id')
|
|
|
|
->join('usr_profile', 'usr_profile.user_id', '=', 'str_owners.user_id')
|
|
|
|
->join('usr_perm_id', 'usr_perm_id.user_id', '=', 'str_owners.user_id')
|
|
|
|
->where('str_owners.user_id', $id)
|
|
|
|
->get(array(
|
|
|
|
'file_id',
|
|
|
|
'str_owners.user_id',
|
|
|
|
'cat_id',
|
|
|
|
'title',
|
|
|
|
'version',
|
|
|
|
'description',
|
|
|
|
'changelog',
|
|
|
|
'views',
|
|
|
|
'downloads',
|
2018-03-05 20:06:15 +09:00
|
|
|
'isApproved',
|
2018-03-02 00:59:26 +09:00
|
|
|
'submit_date',
|
|
|
|
'last_date',
|
|
|
|
'username',
|
|
|
|
'avatar',
|
|
|
|
'perm_id',
|
|
|
|
'gender',
|
|
|
|
'display_name',
|
|
|
|
'name_style',
|
|
|
|
));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return DB::table('str_owners')
|
|
|
|
->join('str_file', 'str_owners.file_id', '=', 'str_file.id')
|
|
|
|
->join('users', 'str_owners.user_id', '=', 'users.id')
|
|
|
|
->join('usr_details', 'usr_details.user_id', '=', 'str_owners.user_id')
|
|
|
|
->join('usr_profile', 'usr_profile.user_id', '=', 'str_owners.user_id')
|
|
|
|
->join('usr_perm_id', 'usr_perm_id.user_id', '=', 'str_owners.user_id')
|
|
|
|
->where('file_id', $id)
|
|
|
|
->take(1)
|
|
|
|
->get(array(
|
|
|
|
'file_id',
|
|
|
|
'str_owners.user_id',
|
|
|
|
'cat_id',
|
|
|
|
'title',
|
|
|
|
'version',
|
|
|
|
'description',
|
|
|
|
'changelog',
|
|
|
|
'views',
|
|
|
|
'downloads',
|
2018-03-05 20:06:15 +09:00
|
|
|
'isApproved',
|
2018-03-02 00:59:26 +09:00
|
|
|
'submit_date',
|
|
|
|
'last_date',
|
|
|
|
'username',
|
|
|
|
'avatar',
|
|
|
|
'perm_id',
|
|
|
|
'gender',
|
|
|
|
'display_name',
|
|
|
|
'name_style',
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2018-01-24 01:36:47 +09:00
|
|
|
}
|
|
|
|
|
2018-03-02 23:44:25 +09:00
|
|
|
public function getEntryName($id) { // /api/rpc/store/entry/getentryname/id
|
2018-01-25 00:35:17 +09:00
|
|
|
return DB::table('str_file')
|
2018-03-02 23:44:25 +09:00
|
|
|
->select('title', 'version')
|
2018-01-25 00:35:17 +09:00
|
|
|
->where('id', $id)
|
|
|
|
->get();
|
|
|
|
}
|
|
|
|
|
2018-02-07 16:21:15 +09:00
|
|
|
public function getEntriesInCategory($cat_id) { // /api/rpc/store/entry/getentriesincategory/cat_id
|
2018-01-25 00:35:17 +09:00
|
|
|
return DB::table('str_file')
|
2018-02-05 19:23:18 +09:00
|
|
|
->select('*')
|
|
|
|
->where('cat_id', $cat_id)
|
2018-01-25 00:35:17 +09:00
|
|
|
->get();
|
|
|
|
}
|
|
|
|
|
2018-02-07 16:21:15 +09:00
|
|
|
public function countEntriesInCategory($cat_id) { // /api/rpc/store/entry/countentriesincategory/cat_id
|
2018-03-09 16:34:16 +09:00
|
|
|
// return $this->storePath.'/screens';
|
2018-01-24 23:58:21 +09:00
|
|
|
return DB::table('str_file')
|
|
|
|
->where('cat_id', $cat_id)
|
2018-02-05 19:23:18 +09:00
|
|
|
->where('isApproved', 1)
|
|
|
|
->count();
|
|
|
|
}
|
|
|
|
|
2018-02-07 16:21:15 +09:00
|
|
|
public function countEntriesInCategoryFull($cat_id) { // /api/rpc/store/entry/countentriesincategoryfull/cat_id
|
2018-02-05 19:23:18 +09:00
|
|
|
return DB::table('str_file')
|
|
|
|
->where('cat_id', $cat_id)
|
|
|
|
->count();
|
2018-01-24 01:36:47 +09:00
|
|
|
}
|
2018-01-25 00:30:18 +09:00
|
|
|
|
2018-03-09 23:57:07 +09:00
|
|
|
public function makedir(Request $request) {
|
|
|
|
$id = $request->id;
|
2018-03-09 16:34:16 +09:00
|
|
|
|
2018-03-09 23:57:07 +09:00
|
|
|
if (!mkdir($this->storePath.'/'.$id, 0755, true)) {
|
2018-03-09 16:34:16 +09:00
|
|
|
Log::error('File MKDIR failed: ');
|
2018-03-06 23:41:17 +09:00
|
|
|
exit();
|
2018-03-09 23:57:07 +09:00
|
|
|
}
|
2018-03-09 16:34:16 +09:00
|
|
|
|
2018-03-09 23:57:07 +09:00
|
|
|
if (!mkdir($this->storePath.'/'.$id.'/screens', 0755, true)) {
|
2018-03-09 16:34:16 +09:00
|
|
|
Log::error('Asset MKDIR failed: ');
|
2018-03-06 23:41:17 +09:00
|
|
|
exit();
|
2018-03-09 19:53:33 +09:00
|
|
|
}
|
2018-03-09 23:57:07 +09:00
|
|
|
}
|
2018-03-09 16:34:16 +09:00
|
|
|
|
2018-03-09 23:57:07 +09:00
|
|
|
public function uploadEntry(Request $request) { // /api/rpc/store/entry/upload
|
|
|
|
header('Access-Control-Allow-Origin: *');
|
|
|
|
$id = $request->id;
|
2018-03-09 16:34:16 +09:00
|
|
|
|
2018-03-09 23:57:07 +09:00
|
|
|
Log::info('Name: '.$request->file('imgfile')); //TMP
|
|
|
|
Log::info('Type: '.gettype($request->file('imgfile'))); // TMP
|
2018-03-09 16:34:16 +09:00
|
|
|
|
2018-03-09 23:57:07 +09:00
|
|
|
$request->file('upfile')->move(public_path('storage/store'.$id), $request->file('imgfile')->getClientOriginalName);
|
|
|
|
$request->file('imgfile')->move(public_path('storage/store'.$id.'/screens'), $request->file('imgfile')->getClientOriginalName);
|
2018-03-09 16:34:16 +09:00
|
|
|
|
2018-03-09 23:57:07 +09:00
|
|
|
exit(); // TMP
|
2018-03-09 16:34:16 +09:00
|
|
|
|
2018-03-06 23:41:17 +09:00
|
|
|
$add = DB::table('str_file')
|
2018-03-05 23:08:44 +09:00
|
|
|
->insert([
|
2018-03-06 23:41:17 +09:00
|
|
|
'game_id' => intval($request->game_id),
|
|
|
|
'cat_id' => intval($request->cat_id),
|
2018-03-05 23:08:44 +09:00
|
|
|
'title' => $request->title,
|
|
|
|
'version' => $request->version,
|
2018-03-06 23:41:17 +09:00
|
|
|
'video' => (!empty($request->video) ? $request->video : ''),
|
2018-03-05 23:08:44 +09:00
|
|
|
'description' => $request->description,
|
|
|
|
'changelog' => '',
|
2018-03-06 23:41:17 +09:00
|
|
|
'warningnote' => (!empty($request->warningnote) ? $request->warningnote : ''),
|
|
|
|
'submit_date' => intval($request->submit_date),
|
|
|
|
'last_date' => intval(0),
|
|
|
|
'views' => intval(0),
|
|
|
|
'downloads' => intval(0),
|
|
|
|
'isApproved' => intval(1),
|
|
|
|
'isBroken' => intval(0),
|
2018-03-05 23:08:44 +09:00
|
|
|
'failreason' => '',
|
|
|
|
'breakreason' => '',
|
2018-03-06 23:41:17 +09:00
|
|
|
'approveignore' => intval(0),
|
|
|
|
'brokenignore' => intval(0)
|
2018-03-05 23:08:44 +09:00
|
|
|
]);
|
2018-03-06 23:41:17 +09:00
|
|
|
|
|
|
|
return \Response::json($add);
|
2018-02-01 04:47:29 +09:00
|
|
|
}
|
|
|
|
|
2018-02-07 16:21:15 +09:00
|
|
|
public function updateEntry(Request $request) { // /api/rpc/store/entry/update
|
2018-02-01 04:47:29 +09:00
|
|
|
return DB::table('str_file')
|
|
|
|
->where('id', $request->id)
|
|
|
|
->update([
|
|
|
|
'cat_id' => $request->cat_id,
|
|
|
|
'title' => $request->title,
|
|
|
|
'version' => $request->version,
|
|
|
|
'description' => $request->description,
|
|
|
|
'changelog' => $request->changelog,
|
|
|
|
'warningnote' => $request->warningnote,
|
|
|
|
'last_date' => $request->last_date
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2018-02-07 16:21:15 +09:00
|
|
|
public function restoreEntry(Request $request) { // /api/rpc/store/entry/restore
|
2018-02-01 04:47:29 +09:00
|
|
|
return DB::table('str_file')
|
|
|
|
->where('id', $request->id)
|
2018-03-05 20:20:44 +09:00
|
|
|
->update(['isApproved' => 1]);
|
2018-02-01 04:47:29 +09:00
|
|
|
}
|
|
|
|
|
2018-02-07 16:21:15 +09:00
|
|
|
public function removeEntry(Request $request) { // /api/rpc/store/entry/remove
|
2018-02-01 04:47:29 +09:00
|
|
|
return DB::table('str_file')
|
|
|
|
->where('id', $request->id)
|
2018-03-05 20:20:44 +09:00
|
|
|
->update(['isApproved' => 0]);
|
2018-02-01 04:47:29 +09:00
|
|
|
}
|
2018-03-06 21:34:53 +09:00
|
|
|
|
|
|
|
public function browsePermissions($uid) {
|
|
|
|
// Get user ID.
|
|
|
|
$perm = $this->objUser->getUser($uid);
|
|
|
|
|
|
|
|
// Does the user ID exist? Grand the appropriate rights. Otherwise, use guest.
|
|
|
|
if ($uid != 0) {
|
|
|
|
// Store permissions.
|
|
|
|
$grouppermstr = $this->objPermission->getPermissionGroup('str', $perm[0]->perm_id);
|
|
|
|
$userpermstr = $this->objPermission->getPermissionUser('str', $uid);
|
|
|
|
|
|
|
|
// User permissions.
|
|
|
|
$grouppermusr = $this->objPermission->getPermissionGroup('usr', $perm[0]->perm_id);
|
|
|
|
$userpermusr = $this->objPermission->getPermissionUser('usr', $uid);
|
|
|
|
|
|
|
|
// Now provide an array of user overwritten permissions if it exists. Otherwise, give its group permissions.
|
|
|
|
$strarr = array();
|
|
|
|
$usrarr = array();
|
|
|
|
|
|
|
|
if (!empty($userpermstr[0])) {
|
|
|
|
$strarr = (array)$userpermstr[0];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$strarr = (array)$grouppermstr[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($userpermusr[0])) {
|
|
|
|
$usrarr = (array)$userpermusr[0];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$usrarr = (array)$grouppermusr[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
$merge = array();
|
|
|
|
$merge = array_merge($strarr, $usrarr);
|
|
|
|
|
|
|
|
return $merge;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Store permissions.
|
|
|
|
$grouppermstr = $this->objPermission->getPermissionGroup('str', 6);
|
|
|
|
|
|
|
|
// User permissions.
|
|
|
|
$grouppermusr = $this->objPermission->getPermissionGroup('usr', 6);
|
|
|
|
|
|
|
|
// Since guests don't have user overwritten permissions, simply return the group permissions.
|
|
|
|
$merge = array();
|
|
|
|
$merge = array_merge((array)$grouppermstr[0], (array)$grouppermusr[0]);
|
|
|
|
|
|
|
|
return $merge;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-24 01:36:47 +09:00
|
|
|
}
|