mirror of
https://github.com/SophiaAtkinson/steamwidgets-web.git
synced 2025-06-27 01:57:40 -07:00
Initial commit
This commit is contained in:
38
app/controller/_base.php
Normal file
38
app/controller/_base.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Base controller class
|
||||
*
|
||||
* Extend or modify to fit your project needs
|
||||
*/
|
||||
class BaseController extends Asatru\Controller\Controller {
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $layout = 'layout';
|
||||
|
||||
/**
|
||||
* Perform base initialization
|
||||
*
|
||||
* @param $layout
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($layout = '')
|
||||
{
|
||||
if ($layout !== '') {
|
||||
$this->layout = $layout;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A more convenient view helper
|
||||
*
|
||||
* @param array $yields
|
||||
* @param array $attr
|
||||
* @return Asatru\View\ViewHandler
|
||||
*/
|
||||
public function view($yields, $attr = array())
|
||||
{
|
||||
return view($this->layout, $yields, $attr);
|
||||
}
|
||||
}
|
103
app/controller/api.php
Normal file
103
app/controller/api.php
Normal file
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* API controller
|
||||
*/
|
||||
class ApiController extends BaseController {
|
||||
/**
|
||||
* Construct object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
}
|
||||
|
||||
/**
|
||||
* Query Steam game/app data
|
||||
*
|
||||
* @param Asatru\Controller\ControllerArg $request
|
||||
* @return Asatru\View\JsonHandler
|
||||
*/
|
||||
public function queryAppInfo($request)
|
||||
{
|
||||
try {
|
||||
$appid = $request->params()->query('appid', null);
|
||||
$language = $request->params()->query('lang', 'english');
|
||||
|
||||
$data = SteamApp::querySteamData($appid, $language);
|
||||
|
||||
return json(array('code' => 200, 'appid' => $appid, 'lang' => $language, 'data' => $data));
|
||||
} catch (\Exception $e) {
|
||||
return json(array('code' => 500, 'msg' => $e->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Query Steam server data
|
||||
*
|
||||
* @param Asatru\Controller\ControllerArg $request
|
||||
* @return Asatru\View\JsonHandler
|
||||
*/
|
||||
public function queryServerInfo($request)
|
||||
{
|
||||
try {
|
||||
$addr = $request->params()->query('addr', null);
|
||||
|
||||
$data = SteamServer::querySteamData(env('STEAM_API_KEY'), $addr);
|
||||
|
||||
return json(array('code' => 200, 'addr' => $addr, 'data' => $data));
|
||||
} catch (\Exception $e) {
|
||||
return json(array('code' => 500, 'msg' => $e->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Query Steam user data
|
||||
*
|
||||
* @param Asatru\Controller\ControllerArg $request
|
||||
* @return Asatru\View\JsonHandler
|
||||
*/
|
||||
public function queryUserInfo($request)
|
||||
{
|
||||
try {
|
||||
$steamid = $request->params()->query('steamid', null);
|
||||
|
||||
$data = SteamUser::querySteamData(env('STEAM_API_KEY'), $steamid);
|
||||
|
||||
return json(array('code' => 200, 'steamid' => $steamid, 'data' => $data));
|
||||
} catch (\Exception $e) {
|
||||
return json(array('code' => 500, 'msg' => $e->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Query JavaScript or CSS resource for component
|
||||
*
|
||||
* @param Asatru\Controller\ControllerArg $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function queryResource($request)
|
||||
{
|
||||
$res = $request->params()->query('type');
|
||||
$module = $request->params()->query('module');
|
||||
$ver = $request->params()->query('version', 'v1');
|
||||
|
||||
if ($res === 'js') {
|
||||
if (file_exists(public_path('/js/steamcards/' . $ver . '/steam_' . $module . '.js'))) {
|
||||
return redirect(asset('js/steamcards/' . $ver . '/steam_' . $module . '.js'));
|
||||
} else {
|
||||
http_response_code(404);
|
||||
exit();
|
||||
}
|
||||
} else if ($res === 'css') {
|
||||
if (file_exists(public_path('/css/steamcards/' . $ver . '/steam_' . $module . '.css'))) {
|
||||
return redirect(asset('css/steamcards/' . $ver . '/steam_' . $module . '.css'));
|
||||
} else {
|
||||
http_response_code(404);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
25
app/controller/error404.php
Normal file
25
app/controller/error404.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Example error 404 controller
|
||||
*/
|
||||
class Error404Controller extends BaseController {
|
||||
/**
|
||||
* Handles special case: $404
|
||||
*
|
||||
* @param Asatru\Controller\ControllerArg $request
|
||||
* @return Asatru\View\ViewHandler
|
||||
*/
|
||||
public function index($request)
|
||||
{
|
||||
//Add a log line
|
||||
addLog(ASATRU_LOG_INFO, "Error 404");
|
||||
|
||||
//Generate the 404 view
|
||||
$v = new Asatru\View\ViewHandler();
|
||||
$v->setLayout('layout') //The layout file. Will be \app\views\layout.php
|
||||
->setYield('yield', 'error/404'); //The index yield. Will be \app\views\error\404.php
|
||||
|
||||
return $v; //Pass the object to the engine
|
||||
}
|
||||
}
|
42
app/controller/index.php
Normal file
42
app/controller/index.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Index controller
|
||||
*/
|
||||
class IndexController extends BaseController {
|
||||
const INDEX_LAYOUT = 'layout';
|
||||
|
||||
/**
|
||||
* Perform base initialization
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(self::INDEX_LAYOUT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles URL: /
|
||||
*
|
||||
* @param Asatru\Controller\ControllerArg $request
|
||||
* @return Asatru\View\ViewHandler
|
||||
*/
|
||||
public function index($request)
|
||||
{
|
||||
//Generate and return a view by using the helper
|
||||
return parent::view(['content', 'index']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles URL: /generator
|
||||
*
|
||||
* @param Asatru\Controller\ControllerArg $request
|
||||
* @return Asatru\View\ViewHandler
|
||||
*/
|
||||
public function generator($request)
|
||||
{
|
||||
//Generate and return a view by using the helper
|
||||
return view('generator', []);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user