2017-12-17 20:40:04 +00:00
|
|
|
<?php
|
2017-12-31 18:34:33 +00:00
|
|
|
/**
|
2018-04-13 05:37:28 +00:00
|
|
|
* @file base.php
|
2018-04-13 05:27:39 +00:00
|
|
|
* @date 2018-04-13
|
2017-12-31 18:34:33 +00:00
|
|
|
* @author Go Namhyeon <gnh1201@gmail.com>
|
2018-04-13 05:37:28 +00:00
|
|
|
* @brief Base module
|
2017-12-17 20:40:04 +00:00
|
|
|
*/
|
|
|
|
|
2018-04-13 05:37:28 +00:00
|
|
|
// set scope
|
|
|
|
if(!function_exists("set_scope")) {
|
|
|
|
function set_scope($k, $v) {
|
|
|
|
global $scope;
|
|
|
|
$scope[$k] = $v;
|
|
|
|
}
|
|
|
|
}
|
2017-12-31 18:31:24 +00:00
|
|
|
|
2018-04-13 05:37:28 +00:00
|
|
|
// get scope
|
|
|
|
if(!function_exists("get_scope")) {
|
|
|
|
function get_scope($k) {
|
|
|
|
global $scope;
|
|
|
|
return array_key_exists($k, $scope) ? $scope[$k] : null;
|
|
|
|
}
|
|
|
|
}
|
2018-02-26 04:20:46 +00:00
|
|
|
|
2018-04-13 05:37:28 +00:00
|
|
|
// register loaded resources
|
|
|
|
if(!function_exists("register_loaded")) {
|
|
|
|
function register_loaded($k, $v) {
|
|
|
|
global $scope;
|
|
|
|
if(array_key_exists($k, $scope['loaded'])) {
|
|
|
|
array_push($scope['loaded'][$k], $v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// sandbox for include function
|
|
|
|
if(!function_exists("include_isolate")) {
|
|
|
|
function include_isolate($file, $data=array()) {
|
|
|
|
if(count($data) > 0) {
|
|
|
|
extract($data);
|
2018-04-13 05:27:39 +00:00
|
|
|
}
|
2018-04-13 05:37:28 +00:00
|
|
|
return include($file);
|
2017-12-22 18:34:40 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-17 20:40:04 +00:00
|
|
|
|
2018-04-13 05:37:28 +00:00
|
|
|
// load view file
|
|
|
|
if(!function_exists("renderView")) {
|
|
|
|
function renderView($name, $data=array()) {
|
|
|
|
if(count($data) > 0) {
|
|
|
|
extract($data);
|
|
|
|
}
|
2018-04-13 05:27:39 +00:00
|
|
|
|
2018-04-13 05:37:28 +00:00
|
|
|
$flag = true;
|
|
|
|
$views = explode(';', $name);
|
|
|
|
foreach($views as $name2) {
|
|
|
|
$viewfile = './view/' . $name2 . '.php';
|
|
|
|
if(file_exists($viewfile)) {
|
|
|
|
$flag = $flag && include_isolate($viewfile, $data);
|
|
|
|
register_loaded("view", $viewfile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $flag;
|
|
|
|
}
|
|
|
|
}
|
2018-03-23 09:23:03 +00:00
|
|
|
|
2018-04-13 05:37:28 +00:00
|
|
|
// load system module
|
|
|
|
if(!function_exists("loadModule")) {
|
|
|
|
function loadModule($name) {
|
|
|
|
$flag = true;
|
|
|
|
$modules = explode(';', $name);
|
|
|
|
foreach($modules as $name2) {
|
|
|
|
$systemfile = './system/' . $name2 . '.php';
|
|
|
|
if(file_exists($systemfile)) {
|
|
|
|
$flag = $flag && include_isolate($systemfile);
|
|
|
|
register_loaded("view", $systemfile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $flag;
|
|
|
|
}
|
2018-02-26 04:20:46 +00:00
|
|
|
}
|
|
|
|
|
2018-04-13 05:37:28 +00:00
|
|
|
// load helper file
|
|
|
|
if(!function_exists("loadHelper")) {
|
|
|
|
function loadHelper($name) {
|
|
|
|
$flag = true;
|
|
|
|
$helpers = explode(';', $name);
|
|
|
|
foreach($helpers as $name2) {
|
|
|
|
$helperfile = './helper/' . $name2 . '.php';
|
|
|
|
if(file_exists($helperfile)) {
|
|
|
|
$flag = $flag && include_isolate($helperfile);
|
|
|
|
register_loaded("helper", $helperfile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-02-09 11:14:17 +00:00
|
|
|
|
2018-04-13 05:37:28 +00:00
|
|
|
// load route file
|
|
|
|
if(!function_exists("loadRoute")) {
|
|
|
|
function loadRoute($name, $data=array()) {
|
|
|
|
$flag = true;
|
|
|
|
$routes = explode(";", $name);
|
|
|
|
foreach($routes as $name2) {
|
|
|
|
$routefile = './route/' . $name . '.php';
|
|
|
|
if(file_exists($routefile)) {
|
|
|
|
$flag = $flag && include_isolate($routefile, $data);
|
|
|
|
register_loaded("route", $routefile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $flag;
|
|
|
|
}
|
|
|
|
}
|
2017-12-17 20:40:04 +00:00
|
|
|
|
2018-04-13 05:37:28 +00:00
|
|
|
if(!function_exists("array_key_empty")) {
|
|
|
|
function array_key_empty($key, $array) {
|
|
|
|
$empty = true;
|
|
|
|
|
|
|
|
if(is_array($array)) {
|
|
|
|
if(array_key_exists($key, $array)) {
|
|
|
|
if(!empty($array[$key])) {
|
|
|
|
$empty = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $empty;
|
2017-12-17 20:40:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-13 05:37:28 +00:00
|
|
|
if(!function_exists("array_multikey_empty")) {
|
|
|
|
function array_multikey_empty($keys, $array) {
|
|
|
|
$flag = true;
|
|
|
|
foreach($keys as $key) {
|
|
|
|
$flag = $flag && array_key_empty($key, $array);
|
|
|
|
}
|
|
|
|
return $flag;
|
|
|
|
}
|
2017-12-25 10:19:42 +00:00
|
|
|
}
|
2018-04-13 05:37:28 +00:00
|
|
|
|
|
|
|
if(!function_exists("get_value_in_array")) {
|
|
|
|
function get_value_in_array($name, $arr=array(), $default=0) {
|
|
|
|
$output = 0;
|
|
|
|
|
|
|
|
if(is_array($arr)) {
|
|
|
|
$output = array_key_empty($name, $arr) ? $default : $arr[$name];
|
|
|
|
} else {
|
|
|
|
$output = $default;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!function_exists("cut_str")) {
|
|
|
|
function cut_str($str, $start, $len=0) {
|
|
|
|
$cutted_str = "";
|
|
|
|
if(function_exists("iconv_substr")) {
|
|
|
|
$cutted_str = iconv_substr($str, $start, $len, "utf-8");
|
|
|
|
} elseif(function_exists("mb_substr")) {
|
|
|
|
$cutted_str = mb_substr($str, $start, $len);
|
|
|
|
} else {
|
|
|
|
$cutted_str = substr($start, $len);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $cutted_str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!function_exists("read_file_by_line")) {
|
|
|
|
function read_file_by_line($filename) {
|
|
|
|
$lines = array();
|
|
|
|
$handle = fopen($filename, "r");
|
|
|
|
if ($handle) {
|
|
|
|
while (($line = fgets($handle)) !== false) {
|
|
|
|
$lines[] .= $line;
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose($handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $lines;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!function_exists("nl2p")) {
|
|
|
|
function nl2p($string) {
|
|
|
|
$paragraphs = '';
|
|
|
|
foreach (explode("\n", $string) as $line) {
|
|
|
|
if (trim($line)) {
|
|
|
|
$paragraphs .= '<p>' . $line . '</p>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $paragraphs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope = array();
|
|
|
|
|
|
|
|
set_scope("loaded", array(
|
|
|
|
"module" => array(),
|
|
|
|
"helper" => array(),
|
|
|
|
"view" => array(),
|
|
|
|
"route" => array(),
|
|
|
|
));
|