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