fix system/database
This commit is contained in:
parent
82a932b3f7
commit
95086080fb
|
@ -15,7 +15,7 @@ if(!function_exists("exec_db_alt_callback")) {
|
|||
if(loadHelper(sprintf("database.%s", $rule['driver']))) {
|
||||
if(function_exists($rule['callback'])) {
|
||||
if(is_array($params) && count($params) > 0) {
|
||||
$result = call_user_func_array($rule['callback'], $params);
|
||||
$result = call_user_func_array($rule['callback'], $params);
|
||||
} else {
|
||||
$result = call_user_func($rule['callback']);
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ if(!function_exists("exec_db_alt_callback")) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
@ -53,9 +53,13 @@ if(!function_exists("get_db_alt_connect")) {
|
|||
array(
|
||||
"driver" => "oracle",
|
||||
"callback" => "get_db_oracle_connect"
|
||||
),
|
||||
array(
|
||||
"driver" => "pgsql",
|
||||
"callback" => "get_db_pgsql_connect"
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
$conn = exec_db_alt_callback($rules);
|
||||
|
||||
return $conn;
|
||||
|
@ -82,9 +86,13 @@ if(!function_exists("exec_db_alt_query")) {
|
|||
array(
|
||||
"driver" => "oracle",
|
||||
"callback" => "exec_db_oracle_query"
|
||||
),
|
||||
array(
|
||||
"driver" => "pgsql",
|
||||
"callback" => "exec_db_pgsql_query"
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
$result = exec_db_alt_callback($rules, array($sql, $bind));
|
||||
|
||||
return $result;
|
||||
|
@ -111,9 +119,13 @@ if(!function_exists("exec_db_alt_fetch_all")) {
|
|||
array(
|
||||
"driver" => "oracle",
|
||||
"callback" => "exec_db_oracle_fetch_all"
|
||||
)
|
||||
),
|
||||
array(
|
||||
"driver" => "pgsql",
|
||||
"callback" => "exec_db_pgsql_fetch_all"
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
$rows = exec_db_alt_callback($rules, array($sql, $bind));
|
||||
|
||||
return $rows;
|
||||
|
@ -133,3 +145,17 @@ if(!function_exists("exec_db_alt_fetch")) {
|
|||
return $fetched;
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists("get_db_alt_last_id")) {
|
||||
function get_db_alt_last_id($driver) {
|
||||
$last_id = false;
|
||||
|
||||
if($driver == "mysql.imp") {
|
||||
$last_id = @mysqli_insert_id();
|
||||
} elseif($driver == "mysql.old") {
|
||||
$last_id = @mysql_insert_id();
|
||||
}
|
||||
|
||||
return $last_id;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,10 +38,8 @@ if(!function_exists("get_db_connect")) {
|
|||
$conn = get_db_connect($a, $b);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(loadHelper("database.alt")) {
|
||||
$conn = call_user_func("get_db_alt_connect", $db_driver);
|
||||
}
|
||||
} elseif(loadHelper("database.alt")) {
|
||||
$conn = call_user_func("get_db_alt_connect", $db_driver);
|
||||
}
|
||||
|
||||
return $conn;
|
||||
|
@ -88,7 +86,7 @@ if(!function_exists("get_db_binded_sql")) {
|
|||
$sql = str_replace(":" . $k, "'" . addslashes($bind[$k]) . "'", $sql);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $sql;
|
||||
}
|
||||
}
|
||||
|
@ -118,7 +116,19 @@ if(!function_exists("get_db_stmt")) {
|
|||
|
||||
if(!function_exists("get_db_last_id")) {
|
||||
function get_db_last_id() {
|
||||
return get_dbc_object()->lastInsertId();
|
||||
$last_id = false;
|
||||
|
||||
$dbc = get_dbc_object();
|
||||
$config = get_config();
|
||||
$db_driver = get_value_in_array("db_driver", $config, "");
|
||||
|
||||
if(in_array($db_driver, array("mysql", "mysql.pdo"))) {
|
||||
$last_id = $dbc->lastInsertId();
|
||||
} elseif(loadHelper("database.dbt")) {
|
||||
$last_id = call_user_func("get_db_alt_last_id", $db_driver);
|
||||
}
|
||||
|
||||
return $last_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -461,7 +471,7 @@ if(!function_exists("get_timediff_on_query")) {
|
|||
if(!function_exists("json_decode_to_assoc")) {
|
||||
function json_decode_to_assoc($data) {
|
||||
$result = array();
|
||||
|
||||
|
||||
$func_rules = array(
|
||||
"json_decode" => "Dose not exists json_decode function",
|
||||
"json_last_error" => "Dose not exists json_last_error function",
|
||||
|
|
269
system/uri.php.save
Normal file
269
system/uri.php.save
Normal file
|
@ -0,0 +1,269 @@
|
|||
<?php
|
||||
/**
|
||||
* @file uri.php
|
||||
* @date 2018-04-13
|
||||
* @author Go Namhyeon <gnh1201@gmail.com>
|
||||
* @brief URI module
|
||||
*/
|
||||
|
||||
if(!function_exists("base_url")) {
|
||||
function base_url() {
|
||||
return get_config_value("base_url");
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists("base_api_url")) {
|
||||
function base_api_url() {
|
||||
return get_config_value("base_api_url");
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists("get_uri")) {
|
||||
function get_uri() {
|
||||
$requests = get_requests();
|
||||
|
||||
$request_uri = "";
|
||||
if(!array_key_empty("REQUEST_URI", $_SERVER)) {
|
||||
$request_uri = $requests["_URI"];
|
||||
}
|
||||
|
||||
return $request_uri;
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists("read_requests")) {
|
||||
function read_requests() {
|
||||
// process http encryption
|
||||
$config = get_config();
|
||||
$httpencrypt = strtolower(get_value_in_array("httpencrypt", $config, ""));
|
||||
if($httpencrypt == "jcryption") {
|
||||
if(loadHelper("jcryption.lnk")) {
|
||||
jcryption_load();
|
||||
eval(jcryption_get_code());
|
||||
}
|
||||
}
|
||||
|
||||
// process requests
|
||||
$requests = array(
|
||||
"_ALL" => $_REQUEST,
|
||||
"_POST" => $_POST,
|
||||
"_GET" => $_GET,
|
||||
"_URI" => !array_key_empty("REQUEST_URI", $_SERVER) ? $_SERVER["REQUEST_URI"] : '',
|
||||
"_FILES" => is_array($_FILES) ? $_FILES : array(),
|
||||
);
|
||||
|
||||
// with security module
|
||||
if(function_exists("get_clean_xss")) {
|
||||
foreach($requests['_GET'] as $k=>$v) {
|
||||
if(is_string($v)) {
|
||||
$requests['_GET'][$k] = get_clean_xss($v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set alias
|
||||
$aliases = array(
|
||||
"all" => "_ALL",
|
||||
"post" => "_POST",
|
||||
"get" => "_GET",
|
||||
"uri" => "_URI",
|
||||
"files" => "_FILES"
|
||||
);
|
||||
foreach($aliases as $k=>$v) {
|
||||
$requests[$k] = $requests[$v];
|
||||
}
|
||||
|
||||
return $requests;
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists("get_requests")) {
|
||||
function get_requests() {
|
||||
$requests = get_scope("requests");
|
||||
|
||||
if(!is_array($requests)) {
|
||||
set_scope("requests", read_requests());
|
||||
}
|
||||
|
||||
return get_scope("requests");
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists("get_final_link")) {
|
||||
function get_final_link($url, $data=array(), $entity=true) {
|
||||
$link = "";
|
||||
$url = urldecode($url);
|
||||
|
||||
$params = array();
|
||||
$base_url = "";
|
||||
$query_str = "";
|
||||
|
||||
$strings = explode("?", $url);
|
||||
$pos = (count($strings) > 1) ? strlen($strings[0]) : -1;
|
||||
|
||||
if($pos < 0) {
|
||||
$base_url = $url;
|
||||
} else {
|
||||
$base_url = substr($url, 0, $pos);
|
||||
$query_str = substr($url, ($pos + 1));
|
||||
parse_str($query_str, $params);
|
||||
}
|
||||
|
||||
foreach($data as $k=>$v) {
|
||||
$params[$k] = $v;
|
||||
}
|
||||
|
||||
if(count($params) > 0) {
|
||||
$link = $base_url . "?" . http_build_query($params);
|
||||
} else {
|
||||
$link = $base_url;
|
||||
}
|
||||
|
||||
if($entity == true) {
|
||||
$link = str_replace("&", "&", $link);
|
||||
}
|
||||
|
||||
return $link;
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists("get_route_link")) {
|
||||
function get_route_link($route, $data=array(), $entity=true, $base_url="") {
|
||||
$_data = array(
|
||||
"route" => $route
|
||||
);
|
||||
|
||||
foreach($data as $k=>$v) {
|
||||
$_data[$k] = $v;
|
||||
}
|
||||
|
||||
if(empty($base_url)) {
|
||||
$base_url = base_url();
|
||||
}
|
||||
|
||||
return get_final_link($base_url, $_data, $entity);
|
||||
}
|
||||
}
|
||||
|
||||
// URI: Uniform Resource Identifier
|
||||
// URL: Uniform Resource Locator
|
||||
if(!function_exists("redirect_uri")) {
|
||||
function redirect_uri($uri, $permanent=false, $options=array()) {
|
||||
if(array_key_equals("check_origin", $options, true)) {
|
||||
if(!check_redirect_origin($uri)) {
|
||||
set_error("Invalid redirect URL");
|
||||
show_errors();
|
||||
}
|
||||
}
|
||||
|
||||
header("Location: " . $uri, true, $permanent ? 301 : 302);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists("redirect_with_params")) {
|
||||
function redirect_with_params($uri, $data=array(), $permanent=false, $entity=false) {
|
||||
redirect_uri(get_final_link($uri, $data, $entity), $permanent);
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists("redirect_route")) {
|
||||
function redirect_route($route, $data=array()) {
|
||||
redirect_uri(get_route_link($route, $data, false));
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists("get_requested_value")) {
|
||||
function get_requested_value($name, $method="_ALL", $escape_quotes=true, $escape_tags=false) {
|
||||
$value = "";
|
||||
$requests = get_requests();
|
||||
|
||||
// set validated value
|
||||
if(array_key_exists($method, $requests)) {
|
||||
$value = array_key_empty($name, $requests[$method]) ? $value : $requests[$method][$name];
|
||||
|
||||
if(is_string($value)) {
|
||||
// security: set escape quotes
|
||||
if($escape_quotes == true) {
|
||||
$value = addslashes($value);
|
||||
}
|
||||
|
||||
// security: set escape tags
|
||||
if($escape_tags == true) {
|
||||
$value = htmlspecialchars($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists("get_requested_values")) {
|
||||
function get_requested_values($names, $method="_ALL", $escape_quotes=true, $escape_tags=false) {
|
||||
$values = array();
|
||||
|
||||
if(is_array($names)) {
|
||||
foreach($names as $name) {
|
||||
$values[$name] = get_requested_value($name);
|
||||
}
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists("empty_requested_value")) {
|
||||
function empty_requested_value($name, $method="_ALL") {
|
||||
$value = get_requested_value($name, $method);
|
||||
return empty($value);
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists("get_binded_requests")) {
|
||||
function get_binded_requests($rules, $method="_ALL") {
|
||||
$data = array();
|
||||
|
||||
foreach($rules as $k=>$v) {
|
||||
if(!empty($v)) {
|
||||
$data[$v] = get_requested_value($k);
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists("get_array")) {
|
||||
function get_array($arr) {
|
||||
return is_array($arr) ? $arr : array();
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists("check_is_string_not_array")) {
|
||||
function check_is_string_not_array($str) {
|
||||
return (is_string($str) && !(is_array($str) || $str == "Array"));
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists("set_header_content_type")) {
|
||||
function set_header_content_type($type) {
|
||||
$type = strtolower($type);
|
||||
$rules = array(
|
||||
"json" => "application/json",
|
||||
"xml" => "text/xml",
|
||||
"text" => "text/plain",
|
||||
"html" => "text/html",
|
||||
"xhtml" => "application/xhtml+xml"
|
||||
);
|
||||
|
||||
if(array_key_exists($type, $rules)) {
|
||||
header(sprintf("Content-type: %s", $rules[$type]));
|
||||
} else {
|
||||
header(sprintf("Content-type: %s", $type));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set scope
|
||||
set_scope("requests", read_requests());
|
Loading…
Reference in New Issue
Block a user