@ -17,13 +17,13 @@ Class Controller {
@@ -17,13 +17,13 @@ Class Controller {
}
//redirect url
protected function redirect($url, $code = 302) { //--{{{
protected function redirect($url, $code = 302) {
header("Location: {$url}", true, $code);
exit;
} //--}}}
}
//render view
protected function render($viewName, $viewData = array(), $pageTitle = '') { //--{{{
protected function render($viewName, $viewData = array(), $pageTitle = '') {
$layoutFile = __DIR__ . '/../views/layout/' . $this->layout . '.php';
if (!empty(FSC::$app['config']['theme'])) {
$layoutFile = __DIR__ . '/../themes/' . FSC::$app['config']['theme'] . '/views/layout/' . $this->layout . '.php';
@ -48,40 +48,40 @@ Class Controller {
@@ -48,40 +48,40 @@ Class Controller {
}else {
throw Exception("Layout file not exist: {$layoutFile}", 500);
}
} //--}}}
}
//render json data
protected function renderJson($data) { //--{{{
protected function renderJson($data) {
header("Content-Type: application/json; charset=utf-8");
echo json_encode($data);
exit;
} //--}}}
}
//render m3u8 file
protected function renderM3u8($content) { //--{{{
protected function renderM3u8($content) {
header("Content-Type: application/x-mpegURL; charset=utf-8");
echo $content;
exit;
} //--}}}
}
//get params by key
protected function get($key = '', $defaultValue = '') { //--{{{
protected function get($key = '', $defaultValue = '') {
if (empty($key)) {
return $_GET;
}
return !empty($_GET[$key]) ? $_GET[$key] : $defaultValue;
} //--}}}
}
//post params by key
protected function post($key = '', $defaultValue = '') { //--{{{
protected function post($key = '', $defaultValue = '') {
if (empty($key)) {
return $_POST;
}
return !empty($_POST[$key]) ? $_POST[$key] : $defaultValue;
} //--}}}
}
//debug log
protected function logTimeCost() { //--{{{
protected function logTimeCost() {
if (!empty(FSC::$app['config']['debug'])) {
$end_time = microtime(true);
$timeCost = ceil( ($end_time - FSC::$app['start_time']) * 1000 ); //ms
@ -94,10 +94,10 @@ Class Controller {
@@ -94,10 +94,10 @@ Class Controller {
@error_log("{$logTime}\t{$thisUrl}\ttime cost: {$timeCost} ms\n", 3, "{$logDir}debug.log");
}
}
} //--}}}
}
//get user real ip
protected function getUserIp() { //--{{{
protected function getUserIp() {
$ip = false;
if (!empty($_SERVER["HTTP_CLIENT_IP"])) {
@ -122,10 +122,10 @@ Class Controller {
@@ -122,10 +122,10 @@ Class Controller {
}
return !empty($ip) ? $ip : $_SERVER['REMOTE_ADDR'];
} //--}}}
}
//request url via curl
protected function request($url, $postFields = array(), $timeout = 10, $pc = false) { //--{{{
protected function request($url, $postFields = array(), $timeout = 10, $pc = false) {
$s = curl_init();
curl_setopt($s, CURLOPT_URL, $url);
@ -154,11 +154,11 @@ Class Controller {
@@ -154,11 +154,11 @@ Class Controller {
'status' => $curlStatus,
'result' => $curlResult,
);
} //--}}}
}
//set cookie for message show
//type: info, warning, danger, success
protected function sendMsgToClient($msg, $type = 'info') { //--{{{
protected function sendMsgToClient($msg, $type = 'info') {
$cookieKey = "alert_msg_{$type}";
$expires = time() + 15;
$path = '/';
@ -169,6 +169,6 @@ Class Controller {
@@ -169,6 +169,6 @@ Class Controller {
$val = base64_encode( $noempty );
setcookie($cookieKey, $val, $expires, $path);
} //--}}}
}
}