";
echo $_SERVER['PHP_SELF'].'//'.preg_match("/install/i",$_SERVER['PHP_SELF']);
exit;
}
// MySQL 데이타 베이스에 접근
function dbconn($table = "") {
//TODO:dbconn 사용하는 모든 녀석들을 없애야한다.
global $connect, $HTTP_COOKIE_VARS;
$f = @file("d_setting/set.php") or Error("set.php파일이 없습니다. DB설정을 먼저 하십시요!");
for($i=1; $i<= 4; $i++) $f[$i] = trim(str_replace("\n","",$f[$i]));
if(!$connect) $connect = @MYDB_connect($f[1],$f[2],$f[3]) or Error("DB 접속시 에러가 발생했습니다");
if($table != "") { $f[4] = $table; }
@MYDB_select_db($f[4], $connect) or Error("DB Select 에러가 발생했습니다","");
return $connect;
}
// 에러 메세지 출력
function Error($message, $url="") {
global $setup, $connect, $dir, $config_dir;
include "error.php";
if($connect) @MYDB_close($connect);
exit;
}
function returnJson($value, $noCache = true, $pretty = false, $die = true){
header('Content-Type: application/json');
if($noCache){
header('Expires: Sun, 01 Jan 2014 00:00:00 GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', FALSE);
header('Pragma: no-cache');
}
if($pretty){
$flag = JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT;
}
else{
$flag = JSON_UNESCAPED_UNICODE;
}
echo json_encode($value, $flag);
if($die){
die();
}
}
// 게시판의 생성유무 검사
function isTable($connect, $str, $dbname='') {
if(!$dbname) {
$f=@file("d_setting/set.php") or Error("set.php파일이 없습니다. DB설정을 먼저 하십시요");
for($i=1;$i<=4;$i++) $f[$i]=str_replace("\n","",$f[$i]);
$dbname=$f[4];
}
$result = MYDB_list_tables($dbname, $connect) or Error(__LINE__." : list_table error : ".MYDB_error($connect),"");
$cnt = MYDB_num_rows($result);
for($i=0; $i < $cnt; $i++) {
$tablename = MYDB_fetch_row($result);
if($str == $tablename[0]) return 1;
}
return 0;
}
// 빈문자열 경우 1을 리턴
function isblank($str) {
//FIXME: 리턴 값은 boolean이 더 적절하다.
$temp=str_replace(" ","",$str);
$temp=str_replace("\n","",$temp);
$temp=strip_tags($temp);
$temp=str_replace(" ","",$temp);
$temp=str_replace(" ","",$temp);
if(preg_match("/[^[:space:]]/i",$temp)) return 0;
return 1;
}
function Debug($str) {
echo "";
}
function MessageBox($str) {
echo "";
}
function getmicrotime() {
$microtimestmp = explode(' ', microtime());
return $microtimestmp[0] + $microtimestmp[1];
}
function PrintElapsedTime() {
global $_startTime;
$_endTime = round(getMicroTime() - $_startTime, 3);
echo "
";
}
/**
* '비교적' 안전한 int 변환
* null -> null
* int -> int
* float -> int
* numeric(int, float) 포함 -> int
* 기타 -> 예외처리
*
* @return int|null
*/
function toInt($val){
if($val === null){
return null;
}
if(is_int($val)){
return $val;
}
if(is_numeric($val)){
return intval($val);//
}
throw new InvalidArgumentException('올바르지 않은 타입형 :'.$val);
}
function LogText($prefix, $variable){
$fp = fopen('logs/dbg_logs.txt', 'a+');
if($fp == false){
$directory_name = dirname('logs/dbg_logs.txt');
if(!is_dir($directory_name)){
mkdir($directory_name);
$fp = fopen('logs/dbg_logs.txt', 'a+');
}
}
fwrite($fp, sprintf('%s : %s'."\n", $prefix, var_export($_POST, true)));
fclose($fp);
}
function dictToArray($dict, $keys){
$result = [];
foreach($keys as $key){
$result[] = util::array_get($dict[$key], null);
}
return $result;
}
function parseJsonPost(){
// http://thisinterestsme.com/receiving-json-post-data-via-php/
// http://thisinterestsme.com/php-json-error-handling/
if(strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') != 0){
throw new Exception('Request method must be POST!');
}
//Make sure that the content type of the POST request has been set to application/json
$contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : '';
if(strcasecmp($contentType, 'application/json') != 0){
throw new Exception('Content type must be: application/json');
}
//Receive the RAW post data.
$content = trim(file_get_contents("php://input"));
//Attempt to decode the incoming RAW post data from JSON.
$decoded = json_decode($content, true);
$jsonError = json_last_error();
//In some cases, this will happen.
if(is_null($decoded) && $jsonError == JSON_ERROR_NONE){
throw new Exception('Could not decode JSON!');
}
//If an error exists.
if($jsonError != JSON_ERROR_NONE){
$error = 'Could not decode JSON! ';
//Use a switch statement to figure out the exact error.
switch($jsonError){
case JSON_ERROR_DEPTH:
$error .= 'Maximum depth exceeded!';
break;
case JSON_ERROR_STATE_MISMATCH:
$error .= 'Underflow or the modes mismatch!';
break;
case JSON_ERROR_CTRL_CHAR:
$error .= 'Unexpected control character found';
break;
case JSON_ERROR_SYNTAX:
$error .= 'Malformed JSON';
break;
case JSON_ERROR_UTF8:
$error .= 'Malformed UTF-8 characters found!';
break;
default:
$error .= 'Unknown error!';
break;
}
throw new Exception($error);
}
return $decoded;
}
if(isset($_POST) && count($_POST) > 0){
LogText($_SERVER['REQUEST_URI'], $_POST);
}
extract($_POST, EXTR_SKIP);
//XXX: $_POST를 추출 없이 그냥 쓰는 경우가 많아서 일단 디버깅을 위해 씀!!!! 절대 production 서버에서 사용 금지!
//todo: $_POST로 제공되는 데이터를 각 페이지마다 분석할것.