'xFacility'에 해당되는 글 11건

  1. 2010.12.02 어플리케이션 메뉴
  2. 2010.10.20 xFacility Data Form데이터 형식
  3. 2010.08.23 xf_language 변수
  4. 2010.08.07 xFacility 변수 규칙
  5. 2010.06.29 문장 구조
  6. 2010.06.08 container()
  7. 2010.06.08 xFacility^PHP > Internal API 3.0
  8. 2010.05.17 xFacility^PHP > Internal API 2.0
  9. 2010.05.17 xFacility^PHP > Internal API 1.0
  10. 2010.05.17 데이터 형식
xFacility/Documents2010. 12. 2. 23:56
그간 xFacility 어플리케이션을 한 메뉴에 모으기 위한 고민을 하였다.
만약 사이트 내에 Viewer와 Blog라는 어플리케이션이 있다면 다음과 같이 보이도록 하는 것이다.

Viewer
- Pictures
- Video
- eBooks
- Settings
Blog
- Notice
- Column
- Scrapbook
- Settings

이와 같은 메뉴 보여주기를 위해서는 우선 메뉴 형식의 통일화가 필요하다.
둘째로는 조금 복잡한 문제로써, 권한에 대한 것을 신경 쓸 필요가 있다. 위에 보이는 것처럼 Settings메뉴가 그냥 노출되어 있다고 하자. 그렇다고 Settings 메뉴를 아무나 들어갈 수는 없지 않은가! 하지만 어플리케이션 자체에는 사용자에 대한 정보가 전혀 없으므로, 결국 이 권한에 대한 부분은 xFacility가 중간에서 조율할 필요성이 있다는 것이다.

'xFacility > Documents' 카테고리의 다른 글

xFacility Data Form데이터 형식  (0) 2010.10.20
xf_language 변수  (0) 2010.08.23
xFacility 변수 규칙  (0) 2010.08.07
문장 구조  (0) 2010.06.29
데이터 형식  (0) 2010.05.17
Posted by 마이클
xFacility/Documents2010. 10. 20. 14:45
xFacility는 육하원칙에 의거하여 데이터를 보관하기 위해 일정한 데이터 형식을 갖고 있다.
C에서 데이터 형식을 혼동하여 사용하면 프로그램이 예기치 못한 오류를 발생하는 것처럼,
xFacility에서도 형식에 맞게 데이터를 입력하지 않으면 오류를 발생한다.

데이터명[who][#][항목명]
데이터명[how][#][항목명]
데이터명[what][#][항목명]
데이터명[where][#][항목명]
데이터명[when][#][항목명]
데이터명[why][#][항목명]

'xFacility > Documents' 카테고리의 다른 글

어플리케이션 메뉴  (0) 2010.12.02
xf_language 변수  (0) 2010.08.23
xFacility 변수 규칙  (0) 2010.08.07
문장 구조  (0) 2010.06.29
데이터 형식  (0) 2010.05.17
Posted by 마이클
xFacility/Documents2010. 8. 23. 14:46
xFacility의 변수인 xf_language는 사용자의 언어 정보를 담는다. 사용자가 가장 편한 언어를 최상위인 0번으로 하여, 익숙치 않은 언어일 수록 후번에 등록이 된다. 예를 들어, 한국어를 모국어로 하고 제1외국어를 영어로 제2외국어를 일본어로 한다면, 그 사용자의 언어정보는 다음과 같이 구성될 것이다.
$xf_language['0'] = "ko-kr";
$xf_language['1'] = "en-us";
$xf_language['2'] = "ja-jp";

xf_language 변수는 사용자의 정보이기 때문에 어플리케이션에 상관 없이 유지, 보존되어야 한다. 그래서 사용자 로그인 후 세션 정보로 이를 등록할 필요가 있는데 xFacility변수의 기본 규칙을 따라 php의 경우 $_SESSION['xf_language']에 그 내용을 입력한다.

'xFacility > Documents' 카테고리의 다른 글

어플리케이션 메뉴  (0) 2010.12.02
xFacility Data Form데이터 형식  (0) 2010.10.20
xFacility 변수 규칙  (0) 2010.08.07
문장 구조  (0) 2010.06.29
데이터 형식  (0) 2010.05.17
Posted by 마이클
xFacility/Documents2010. 8. 7. 13:55
xFacility 프로그램에서 지정하는 변수명에는 규칙이 있다.

1. 접두어로 xf_를 사용한다.
데이터베이스 정보와 관련한 변수인 경우 접두어 xf_에 데이터베이스의 약어인 db를 붙여서 xf_db를 변수명으로 사용한다.
사용자와 관련한 변수인 경우 접두어 xf_에 사용자의 약어인 user를 붙여서 xf_user를 변수명으로 사용한다.

2. 하위정보 는 배열로 저장한다.
xFacility의 데이터베이스 정보 중, 데이터베이스 서버인 경우는 데이터베이스 변수인 xf_db에 배열명 server를 이용하여 xf_db[server]와 같은 식으로 지정한다.
사용자의 아이디는 사용자 변수인 xf_user에 배열명 id를 이용하여 xf_user[id]와 같이 지정한다.

3. 세션 또는 쿠키에는 포장을 해서 변수를 등록한다.
세션 또는 쿠키에 저장하려면 $_SESSION[xf_user], $_COOKIE[xf_user]와 같은 식으로 포장을 해서 등록한다.

'xFacility > Documents' 카테고리의 다른 글

xFacility Data Form데이터 형식  (0) 2010.10.20
xf_language 변수  (0) 2010.08.23
문장 구조  (0) 2010.06.29
데이터 형식  (0) 2010.05.17
처리Process  (0) 2010.05.16
Posted by 마이클
xFacility/Documents2010. 6. 29. 01:40
문장이란 xFacility에서 데이터를 전송/수신할 때, 효과적으로 하기 위한 하나의 규칙이다.
문장은 육하원칙의 요소로 구성되며, 그 구성 형태는 영문법의 문장 구조를 따르고 있다.
(물론, 프로그램은 문장 구성 요소를 각각 처리하므로 문장 구조를 벗어나도 이해할 수 있다.)
그렇기 때문에 문장을 해석하는 주체(컴퓨터 또는 사람)에 상관 없이 모두 문장을 쉽게 이해할 수 있다는 장점이 있다.

1. Who
문장의 주체이다.

2. How
주체가 행하는 행동이다.

3. Whom
문장의 수신자, 행동에 영향을 받는 사람이다. 보통 xFacility를 여기에 기입한다.

4. What
행동에 대한 목적어이다. 행동을 행하는데 있어서 중심이 되는 데이터들을 여기에 기입한다.

5. Where
이 문장이 효력을 발휘하는 지점이다.

6. When
이 문장이 효력을 발휘하는 시점이다.

7. Why
이 문장이 작성된 까닭이다.

'xFacility > Documents' 카테고리의 다른 글

xFacility Data Form데이터 형식  (0) 2010.10.20
xf_language 변수  (0) 2010.08.23
xFacility 변수 규칙  (0) 2010.08.07
데이터 형식  (0) 2010.05.17
처리Process  (0) 2010.05.16
Posted by 마이클
xFacility/Codes2010. 6. 8. 19:57
API 4.0에 쓰이는 그릇Container처리 함수입니다.
고민을 나누면 코드를 더 효율적으로 변경할 수 있을 것 같아서 올립니다.

function container($container) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
08.Jun.2010.
DESCRIPTION:
Parse Container to Array
CALL:
container("{a{c{e{10;1;}e=6;}d{g=7;}c{e{5}}}b{e=5;}}");
RETURN:
$result[a][c][e][0] = 10;
$result[a][c][e][1] = 1;
$result[a][c][e][2] = 6;
$result[a][c][e][3] = 5;
$result[a][c][b][e] = 5;
$result[a][d][g] = 7;
*/
if(is_container($container)) {
$container = trim($container);
$leng = strlen($container);
$opens = substr_count($container, "{");
$equals = substr_count($container, "=");
$divides = substr_count($container, ";");
$closes = substr_count($container, "}");
$loop = $opens+$equals+$divides+$closes;
if($loop == 0) {
$return = $container;
} else if(substr_count($container, "{")==substr_count($container, "}")) {
$last_char = substr($container, $leng-1, 1);
if($last_char=="{"||$last_char=="=") {
$container .= substr($container, 0, strlen($container)-1);
} else if($last_char!=";"&&$last_char!="}") {
$container = "{".$container."}";
}
$open = find_chars($container, "{");
$equal = find_chars($container, "=");
$divide = find_chars($container, ";");
$close = find_chars($container, "}");
$j=0;$k=0;$l=0;$m=0;$counter=0;
for($i=0; $i<$loop; $i++) {
if($open[$j]==NULL&&$open[$j]!="0")
$open[$j]=$leng-1;
if($equal[$k]==NULL&&$equal[$j]!="0")
$equal[$k]=$leng-1;
if($divide[$l]==NULL&&$divide[$j]!="0")
$divide[$l]=$leng-1;
if($close[$m]==NULL&&$close[$j]!="0")
$close[$m]=$leng-1;
$breaker[$i] = min($open[$j], $equal[$k], $divide[$l], $close[$m]);
$last_char = substr($container, $breaker[$i-1], 1);
$now_char = substr($container, $breaker[$i], 1); 
$length = $breaker[$i];
if($i!=0)
$length -= $breaker[$i-1]+1;
switch ($now_char) {
case "{":
if($last_char!="="&&$length>0) {
$address_now .= "{".trim(substr($container, $breaker[$i-1]+1, $length));
if($auto[$address_now]==NULL&&$auto[$address_now]!="0") {
$auto[$address_now] = 0;
}
}
$j++;
break;
case "=":
if($last_char!="="&&$length>0) {
$address_now .= "{".trim(substr($container, $breaker[$i-1]+1, $length));
}
$k++;
break;
case ";":
if($length>0) {
$value[$counter] = trim(substr($container, $breaker[$i-1]+1, $length));
if($last_char!="=")
$address_now .= "{".$auto[$address_now];
$address[$counter] = $address_now;
$address_now = drop_atlastchar($address_now, "{");
if($last_char!="=")
$auto[$address_now]++;
$counter++;
}
$l++;
break;
case "}":
if($i!=0&&$length>0) {
$value[$counter] = trim(substr($container, $breaker[$i-1]+1, $length));
if($last_char!="=")
$address_now .= "{".$auto[$address_now];
$address[$counter] = $address_now;
$address_now = drop_atlastchar($address_now, "{");
$address_now = drop_atlastchar($address_now, "{");
if($last_char!="=")
$auto[$address_now]++;
$counter++;
} else if($length==0&&$last_char==";") {
$address_now = drop_atlastchar($address_now, "{");
}
$m++;
break;
}
}
}
}
//upsidedown
for($i=0; $i<$counter; $i++) {
$value_tmp[$counter-$i-1] = $value[$i];
$address_tmp[$counter-$i-1] = $address[$i];
}
unset($value, $address);
$value = $value_tmp;
$address = $address_tmp;
for($i=0; $i<=$counter; $i++) {
$loop = substr_count($address[$i], "{");
for($j=0; $j<$loop; $j++) {
$name = drop_atlastchar($address[$i], "{", false);
$temp[$name] = $value[$i];
unset($value[$i]);
$value[$i] = $temp;
unset($temp);
$address[$i] = drop_atlastchar($address[$i], "{");
}
$return = array_merge_recursive($value[$i], $return);
}
return $return;
}

'xFacility > Codes' 카테고리의 다른 글

xFacility^PHP > Internal API 3.0  (0) 2010.06.08
xFacility^PHP > Internal API 2.0  (0) 2010.05.17
xFacility^PHP > Internal API 1.0  (0) 2010.05.17
Posted by 마이클
xFacility/Codes2010. 6. 8. 11:11
API 2.0에서 함수명만을 변경해서 가져온 것도 있고, 처리 알고리즘이 변화한 함수들도 있습니다.

<?php
//Common
//String
//Get extension of url or path
function get_extension($path) {
$return = substr($path,strrpos($path,".")+1);
return $return;
}
//Trim the strings at end
function trim_string($string, $character = ",;") {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
22.Apr.2010.
DESCRIPTION:
Trim a special character(comma and semicolon) at end of string
CALL:
trim_string("lang=en,ko,jp,ch;hobby=reading books,programming,bowling;");
RETURN:
$string = "lang=en,ko,jp,ch;hobby=reading books,programming,bowling";
*/
//Define times for a Loop
$length = strlen($character);
//Check each character by a loop
for ($i=0; $i<$length; $i++) {
//If the end of string is a appointed character,
if(substr($string,-1) == substr($character, $i, 1)) {
//Delete the last character of string
$string = substr($string, 0, -1);
}
}
//Return a trimmed string
return $string;
}
//Drop string at first needle
function drop_atfirsttext($haystack, $needle, $from = false) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
07.Jun.2010.
DESCRIPTION:
Drop a text from(or to) a first needle.
CALL:
drop_atfirsttext("http://www.nate.com:8080/", ":");
RETURN:
if($from = true) {
$return = "//www.nate.com:8080/";
} else if($from = false) {
$return = "http";
}
*/
if($from == true || $from == 1) {
$start = strpos($haystack, $needle) + strlen($needle);
$string = substr($haystack, $start);
$string = ltrim($string);
} else {
$length = strpos($haystack, $needle);
$string = substr($haystack, 0, $length);
$string = rtrim($string);
}
return $string;
}
//Drop string at first needle
function drop_atlasttext($haystack, $needle, $from = false) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
07.Jun.2010.
DESCRIPTION:
Drop a text from(or to) a last needle.
CALL:
drop_atlasttext("http://www.nate.com:8080/", ":");
RETURN:
if($from = true) {
$return = "http://www.nate.com";
} else if($to = false) {
$return = "8080/";
}
*/
if($from == true || $from == 1) {
$start = strrpos($haystack, $needle);
$length = strlen($haystack)-$start;
$string = substr($haystack, $start+strlen($needle), $length);
$string = rtrim($string);
} else {
$length = strrpos($haystack, $needle);
$string = substr($haystack, 0, $length);
$string = rtrim($string);
}
return $string;
}
//Drop a text to a needle
function drop_fronttext($haystack, $needle, $position) {
for($i=0; $i<$position; $i++) {
$start = strpos($haystack, $needle) + strlen($needle);
$haystack = substr($haystack, $start);
}
$string = ltrim($haystack);
return $string;
}
//Position of a needle
function whereis_string($haystack, $needle) {
if(substr_count($haystack, $needle) == 0) {
$return[0] = "xfacility";
$return[1] = "return";
$return[2] = 1;
$return[5] = "Nothing to Find.";
} else {
for($i=0; substr_count($haystack, $needle)!=0; $i++) {
if($i == 0){
$array[$i] = strpos($haystack, $needle);
} else {
$array[$i] = $array[$i-1] + strlen($needle) + strpos($haystack, $needle);
}
$haystack = substr($haystack, strlen($needle) + strpos($haystack, $needle));
}
$return = $array;
}
return $return;
}
//File
//Scandir for PHP4
function scandir_php4($path) {
$handle = dir($path);
while (false !== ($entry = $handle->read())) {
$result[$i] = $entry; 
$i++;
}
$handle->close();
return $result;
}
//Count numbers of directories and files
function count_dir($path) {
$handle = dir($path);
while (false !== ($entry = $handle->read())) {
$result++;
}
$handle->close();
return $result;
}
//Upload a file
function upload_file($file=NULL, $counter=1) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
07.Jun.2010.
DESCRIPTION:
Upload each files to shelf.
CALL:
upload_file($_FILES);
RETURN:
$return['path'] = "/home/hosting_users/username/www/shelf/123901233.bmp";
$return['url'] = "/shelf/123901233.bmp";
$return['size'] = "1255320";
$return['name'] = "123901233.bmp":
$return['mime'] = "image/bmp";
$return['ext'] = "bmp";
*/
$return[0] = "xFacility";
$return[1] = "return";
$return[2] = 0;
$return[3] = "API";
$return[4] = have_thetime();
if($file == NULL) {
if($_FILES == NULL) {
$return[2] = 1;
$return[5] = "There is nothing to process.";
return $return;
} else {
$file = $_FILES;
}
}
for($i=0; $i<$counter; $i++) {
if ($file[$i]['size'] > 0) {
$timestamp = time();
$extension = get_extension($file[$i]['name']);
$filename = $timestamp.".".$extension;
$directory = $_SERVER['DOCUMENT_ROOT']."/shelf/";
$path = $directory.$filename;
$url = "/shelf/".$filename;
if(file_exists($url)) {
$return[2] = 1;
$return[5] = "There is a file having the name.<br />Please retry.<br />Filename: $filename";
return $return;
} else {
move_uploaded_file($file[$i]['tmp_name'], $path);
$result['path'][$i] = $path;
$result['url'][$i] = $url;
$result['size'][$i] = $file[$i]['size'];
$result['name'][$i] = $file[$i]['name'];
$result['mime'][$i] = $file[$i]['type'];
$result['ext'][$i] = $extension;
}
} else {
$return[2] = 1;
$return[5] = "There is nothing to upload.";
return $return;
}
}
$return = $result;
return $return;
}
//find icon
function find_icon($type="file", $mime="text/plain", $extension="txt", $size="32") {
switch($type) {
case "file":
switch($mime) {
case "application/x-msdownload":
$return = "exe";
break;
case "application/unknown":
$return = "hwp";
break;
case "image/jpeg":
case "image/bmp" :
case "text/plain":
default:
$return = "txt";
break;
}
break;
case "text":
$return ="txt";
break;
case "link":
default:
$return = "htm";
}
$return .= $size.".png";
return $return;
}
//HTML
function redirect($url) {
echo "<meta http-equiv='Refresh' content='0; url=$url' />"; 
return 0;
}
//JavaScript
function alert($message) {
echo "<script type='text/javascript'>\n";
echo "<!--\n";
   echo "alert('$message');\n";
   echo "// -->\n";
echo "</script>\n";
return 0;
}
//XML
//Bring a value of an element
function get_valueofelement($codes, $element) {
//Check Codes
//Numbers of open tags match numbers of close tags
if($return == NULL) {
$open = substr_count($codes, "<$element>");
$close = substr_count($codes, "</$element>");
if($open != $close) {
$return = "1";
}
}
//Overlapping of open or close code
if($return == NULL) {
$open = whereis_string($codes, "<$element>");
if($open[0]=="xfacility"&&$open[1]=="return"&&$open[2]==1) {
$open = whereis_string($codes, "<$element ");
if($open[0]=="xfacility"&&$open[1]=="return"&&$open[2]==1) {
$return = $open;
}
}
$close = whereis_string($codes, "</$element>");
for($i=0; 1; $i++){
if($open[$i]==NULL) {
break;
} else if($open[$i]>=$close[$i]) {
$return = "1";
}
}
}
//Parse
if($return == NULL) {
for($i=0; 1; $i++) {
if($close[$i]==NULL) {
break;
}
$return[$i] = substr($codes, $open[$i]);
$return[$i] = drop_atfirsttext($return[$i], ">");
$return[$i] = drop_atfirsttext($return[$i], "</$element>", 0);
$return[$i] = trim($return[$i]);
$return[$i] = str_replace("\t", "", $return[$i]);
}
}
return $return;
}
//Convert what to condition
function cvt_what2condition() {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
28.Apr.2010.
DESCRIPTION:
Parse Range to Array
CALL:
parse_range("<item>
<no>1</no>
<subject>hello world!</subject>
</item>
<item>
<no>2</no>
<subject>play</subject>
</item>
<item>
<no>3</no>
</item>");
RETURN:
$condition = (`no`='1' AND `subject`='hello world!') OR (`no`='2' AND `subject1='play') OR (`no`='3');
*/
}
//Convert where to Table
function cvt_where2table() {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
28.Apr.2010.
DESCRIPTION:
Parse Range to Array
CALL:
parse_range("1-3,7,10-11");
RETURN:
$array[0] = "1";
$array[1] = "2";
$array[2] = "3";
$array[3] = "7";
$array[4] = "10";
$array[5] = "11";
*/
}
//Range
//Is range
function is_range($range) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
17.May.2010.
DESCRIPTION:
Check this out as a range.
CALL:
is_range("1-3,7,10-11");
RETURN:
$is = true;
*/
return $is;
}
//Parse Range
function parse_range($range) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
28.Apr.2010.
DESCRIPTION:
Parse Range to Array
CALL:
parse_range("1-3,7,10-11");
RETURN:
$array[0] = "1";
$array[1] = "2";
$array[2] = "3";
$array[3] = "7";
$array[4] = "10";
$array[5] = "11";
*/
//Trim a string
$range = trim_string($range);
$range = trim($range);
//Parse a string by comma
$temp = split(",", $range);
//Move values to array
$now = 0;
for ($i=0; $i<=substr_count($range,","); $i++) {
//Check a hyphen
if (substr_count($temp[$i],"-") == 1) {
list($start, $end) = split("-", $temp[$i]);
$difference = $end - $start;
for ($j=0; $j<=$difference; $j++) {
$array[$now] = $start + $j;
$now += 1;
}
} else {
$array[$now] = $temp[$i];
$now += 1;
}
}
//Delete overlapping values 
$array = array_unique($array);
//Sort the array
sort($array);
reset($array);
//Return Array
return $array;
}
//Convert range to condition
function cvt_range2condition($range) {
if($range == 0) {
$return = 1;
} else {
$array = parse_range($range);
$i = 0;
foreach ($array as $value) {
if($i != 0) {
$return .= " OR ";
}
$return .= "`no`=".$value;
$i++; 
}
$return = trim_string($return);
}
return $return;
}
//Container
function parse_container($container) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
22.Apr.2010.
DESCRIPTION:
Parse a string including values to Array
CALL:
parse_container("lang=en,ko,jp,ch;hobby=reading books,programming,bowling;");
RETURN:
$array['lang'][0] = "en";
$array['lang'][1] = "ko";
$array['lang'][2] = "jp";
$array['lang'][3] = "ch";
$array['hobby'][0] = "reading books";
$array['hobby'][1] = "programming";
$array['hobby'][2] = "bowling";
*/
//Trim a string of values
$container = trim_string($container);
//Parse a string by semicolon
$temp = split(";", $container);
//Define times for a loop
$counter = substr_count($container, ";");
for ($i = 0; $i<=$counter; $i++) {
//Parse a string into name and values
list($name, $values) = split("=", $temp[$i]);
//Trim a left of name
$name = ltrim($name);
//Parse values into each value
$array[$name] = split(",", $values);
//Define times for a internal loop
$counter2 = substr_count($values, ",");
for ($j = 0; $j<=$counter2; $j++) {
//Trim a left of value
$array[$name][$j] = ltrim($array[$name][$j]);
}
}
//Return Array
return $array;
}
//Time
function have_thetime($timestamp = NULL) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
16.May.2010.
DESCRIPTION:
Have the time
CALL:
have_thetime("0");
RETURN:
$result = "1970Jan01090000";
*/
if($timestamp == NULL) {
$timestamp = time();
}
return date('YMdHis', $timestamp);
}
//Checker
function check_sentence($sentence) {
//Parse
$who = get_valueofelement($sentence, "who");
$how = get_valueofelement($sentence, "how");
$what = get_valueofelement($sentence, "what");
$where = get_valueofelement($sentence, "where");
$when = get_valueofelement($sentence, "when");
$why = get_valueofelement($sentence, "why");
//Authority
if($return==NULL) {
//If the sentence of xFXML was written by xfacility, 
if($who[0]=="xfacility") {
$return[2] = 1;
$return[5] = "We cannot support to send a message from xfacility to xfacility.";
//Is there a user having the number?
} else {
$query = "SELECT * FROM `xf_user` WHERE `no`='$who[0]'";
$result = execute_query($query);
$number = count_result($result);
if($number==0) {
$return[2] = 1;
$return[5] = "There is no user who have the number.";
}
}
//Find settings in xF_Authority
}
//Form
if($return==NULL) {
}
//Rule
if($return==NULL) {
}
//Return
return $return;
}
//Database
//Execute
function execute_query($query) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
28.Apr.2010.
DESCRIPTION:
Execute an query
CALL:
execute_query("DROP TABLE `xf_authority`;");
RETURN:
$result = <<RESULT OF QUERY>>;
$result = 1; // Error
*/
//Load information about DB 
include $_SERVER['DOCUMENT_ROOT']."/shelf/database.php";
//Connect to DB, Select DB and run a query
//If the database program is MySQL,
if($xf_db['kind'] == "mysql") {
//Connect to database Program
$link = @mysql_connect($xf_db['server'], $xf_db['username'], $xf_db['password']);
//Select database
mysql_select_db($xf_db['database'], $link);
$result = mysql_query($query, $link);
//Close the connection
mysql_close();
} else {
$result = false;
}
//Return result of database
if($result == false) {
$return[0] = "xFacility";
$return[1] = "return";
$return[2] = "1";
$return[3] = "API";
$return[4] = have_thetime();
$return[5] = "There is an error while executing a query.<br />Query:<br />".$query;
} else {
$return = $result;
}
return $return;
}
//Count a number of results
function count_result($result) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
28.Apr.2010.
DESCRIPTION:
Count the rows of a result 
CALL:
count_result(<<RESULT OF QUERY>>);
RETURN:
$number = 3;
$number = NULL; // Error
*/
//Load information about DB 
include $_SERVER['DOCUMENT_ROOT']."/shelf/database.php";
//If the database program is MySQL,
if($xf_db['kind'] == "mysql") {
$number = mysql_num_rows($result);
} else {
$number = NULL;
}
//Return a number
return $number;
}
function parse_result($result, $fields = NULL) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
30.May.2010.
DESCRIPTION:
Parse a result of query
CALL:
xfx_prs_res(<<RESULT OF QUERY>>);
RETURN:
$array['no'][0] = 3;
$array['indicator'][0] = 1349851283;
$array['status'][0] = 1;
$array['id'][0] = "root";
$array['pw'][0] = "*68F9CD57023F17CBE06EE6365D9B4FEBF3EB3EE4";
$array['etc'][0] = "lang=en,ko,jp,ch";
$array['no'][1] = 4;
$array['indicator'][1] = 1352878344;
$array['status'][1] = 1;
$array['id'][1] = "administrator";
$array['pw'][1] = "*1F7E399139C29C99909A2C7E8C56247043C4FEE1";
$array['etc'][1] = "lang=ko,en";
$array = NULL //Error
*/
//Load information about DB
include $_SERVER['DOCUMENT_ROOT']."/shelf/database.php";
//If the list of fields are missed,
if($fields == NULL) {
$counter = 0;
} else {
//Parse fields by comma
$temp = split(",", $fields);
//Estimate times for a loop
$counter = substr_count($fields, ",");
}
for ($i=0; $i<=$counter; $i++) {
//If the list of fields are missed,
if($fields == NULL) {
//If the database program is MySQL,
if($xf_db['kind'] == "mysql") {
//Get field Name
$field = @mysql_field_name($result, $i);
} else {
//Stop the processing of this function
return $array = NULL;
}
//If there is no field name,
if ($field == NULL) {
//Stop this Loop
break;
} else {
//One more time
$counter++;
}
} else {
$field = $temp[$i];
}
//Estimate times for a subloop
$counter2 = count_result($result);
for($j=0; $j<$counter2; $j++) {
//If the database program is MySQL,
if($xf_db['kind'] == "mysql") {
$array[$field][$j] = mysql_result($result, $j, $field);
} else {
//Stop the processing of this function
return $array = NULL;
}
}
}
//Return Array
return $array;
}
//Database I/O
//Write
function write_db($what, $where) {
//Infinity loop
for($i=0; 1; $i++) {
//If there is nothing to input in DB,
if($item[$i][0] == NULL) {
break;
}
//If there is not designated number,
if($no[$i] == NULL) {
//Insert
$query = "INSERT INTO `$table[$i]`($fields[$i]) VALUES($values[$i])";
} else {
//Update
$query = "UPDATE `$table[$i]` SET $settings[$i] WHERE $conditions[$i]";
}
$result = execute_query($query);
if($result == 1) {
$return[0] = "xFacility";
$return[1] = "return";
$return[2] = "1";
$return[3] = $where[3];
$return[5] = "There is an error during writing into db.";
return $return;
}
}
//Return
if($return == NULL) {
$return = 0;
}
return $return;
}
//Read
function read_db($what, $where) {
if (is_array($what[$i])==true) {
} else if (is_range($what[$i])==true) {
} else {
$return[2] = "1";
$return[5] = "There is nothing to read.";
}
return $return;
}

//Delete
function delete_db($what, $where) {
$condition = cvt_what2condition($what);
$table = cvt_where2table($where);
$query = "DELETE FROM `$table` WHERE $condition";
$return = execute_query($query);
return $return;
}
//XML I/O
//Read
function read_xfxml($xfxml) {
//Parse
//Trim a xFXML
$sentence = get_valueofelement($xfxml, "sentence");
if($sentence == 1) {
$return = 1;
}
//Check
if($return == NULL) {
foreach($sentence as $key => $value) {
$result = check_sentence($value);
if($result[2]==1) {
$return = $result;
break;
}
}
}
//Execute
if($return == NULL) {
foreach($sentence as $key => $value) {
$how = get_valueofelement($value, "how");
$what = get_valueofelement($value, "what");
$where = get_valueofelement($value, "where");
switch($how[0]) {
case "write":
case "edit":
echo "write_db($what[0], $where[0])";
break;
case "read":
echo "read_db($what[0], $where[0])";
break;
case "delete":
echo "delete_db($what[0], $where[0])";
break;
case "return":
$return[2] = 1;
$return[5] = "There is nothing to run.";
}
}
}
//Return
echo write_xfxml($return);
}
//Write
function write_xfxml($return) {
if($return[0] == NULL) {
$return[0] = "xfacility";
}
if ($return[1] == NULL) {
$return[1] = "return";
}
if ($return[2] == NULL) {
$return[2] = "0";
}
if ($return[4] == NULL) {
$return[4] = have_thetime();
}
//Declare
$xfxml = "<?xml version='1.0' encoding='utf-8' ?>\n\n";
//Open sentences
$xfxml .= "<sentences>\n";
//Open sentence
$xfxml .= "\t<sentence>\n";
//Who
$xfxml .= "\t\t<who>$return[0]</who>\n";
//How
$xfxml .= "\t\t<how>$return[1]</how>\n";
//What
$xfxml .= "\t\t<what>$return[2]</what>\n";
//Where
$xfxml .= "\t\t<where>$return[3]</where>\n";
//When
$xfxml .= "\t\t<when>$return[4]</when>\n";
//Why
$xfxml .= "\t\t<why>$return[5]</why>\n";
//Close sentence
$xfxml .= "\t</sentence>\n";
//Close sentences
$xfxml .= "</sentences>\n";
return $xfxml;
}
//[xF]User
function xfu_signin($id, $pw, $url=NULL) {
if($id == NULL) {
alert("아이디가 입력되지 않았습니다.");
} else {
if ($pw == NULL) {
alert("비밀번호가 입력되지 않았습니다.");
} else {
$query = "SELECT * FROM `xf_user` WHERE `id`='$id'";
$result = execute_query($query);
if($result == 1) {
alert("쿼리 실행중 오류가 발생하였습니다.");
} else {
$counter = count_result($result);
if($counter > 1) {
alert("DB에 문제가 있습니다. 동일 아이디가 $counter개 있습니다.");
} else if($counter < 1) {
alert("There is no ID in system.");
} else {
$query = "SELECT * FROM `xf_user` WHERE `id`='$id' AND `pw`=password('$pw')";
$result = execute_query($query);
if($result == 1) {
alert("Error on executing a query.");
} else {
$counter = count_result($result);
if($counter == 0) {
alert("The password is wrong.");
} else {
alert("You have signed in.");
$array = parse_result($result);
$return['xf_id'] = $array['no'][0];
$return['xf_etc'] = parse_container($array['etc'][0]);
}
}
}
}
if($url != NULL) {
redirect($url);
}
}
}
return $return;
}
//[xF]Appbox
function get_nameofapps() {
$path = $_SERVER['DOCUMENT_ROOT']."/appbox/";
$array = scandir_php4($path); 
$counter = count_dir($path);
for($i=0; $i<$counter; $i++) {
if($array[$i]=="." || $array[$i]=="..") {
unset($array[$i]);
} else if(!is_dir($path.$array[$i])) {
unset($array[$i]);
}
}
sort($array);
reset($array);
$return = $array;
return $return;
}
?>

'xFacility > Codes' 카테고리의 다른 글

container()  (0) 2010.06.08
xFacility^PHP > Internal API 2.0  (0) 2010.05.17
xFacility^PHP > Internal API 1.0  (0) 2010.05.17
Posted by 마이클
xFacility/Codes2010. 5. 17. 23:27
1.0 버전에서 코드 효율성을 위하여 새로 작성한 2.0 버전입니다.
Database 입출력처리는 기존 버전의 코드를 계승했습니다.

//Part1. Common API
//1. [xF]Interaction
//1.1. Text
//1.1.1. Trim
function xfi_trm_str($string, $character = ",;") {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
28.Apr.2010.
DESCRIPTION:
Trim a special character(comma and semicolon) at end of string
CALL:
xfi_trm_str("lang=en,ko,jp,ch;hobby=reading books,programming,bowling;");
RETURN:
$string = "lang=en,ko,jp,ch;hobby=reading books,programming,bowling";
*/
//Define times for a Loop
$length = strlen($character);
//Check each character by a loop
for ($i=0; $i<$length; $i++) {
//If the end of string is a appointed character,
if(substr($string,-1) == substr($character, $i, 1)) {
//Delete the last character of string
$string = substr($string, 0, -1);
}
}
//Return a trimmed string
return $string;
}

//1.1.2. Range
//1.1.2.1. Parse a range
function xfi_prs_ran ($range) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
28.Apr.2010.
DESCRIPTION:
Parse Range to Array
CALL:
xfi_prs_ran("1-3,7,10-11");
RETURN:
$array[0] = "1";
$array[1] = "2";
$array[2] = "3";
$array[3] = "7";
$array[4] = "10";
$array[5] = "11";
*/
//Trim a string
$range = xfi_trm_str($range);
$range = trim($range);
//Parse a string by comma
$temp = split(",", $range);
//Move values to array
$now = 0;
for ($i=0; $i<=substr_count($range,","); $i++) {
//Check a hyphen
if (substr_count($temp[$i],"-") == 1) {
list($start, $end) = split("-", $temp[$i]);
$difference = $end - $start;
for ($j=0; $j<=$difference; $j++) {
$array[$now] = $start + $j;
$now += 1;
}
} else {
$array[$now] = $temp[$i];
$now += 1;
}
}
//Delete overlapping values 
$array = array_unique($array);
//Sort the array
sort($array);
reset($array);
//Return Array
return $array;
}

//1.1.2.2. Convert a range to a condition
function xfi_cvt_ran ($range) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
28.Apr.2010.
DESCRIPTION:
Convert a range to a condition of a SQL query
CALL:
xfi_cvt_ran("1-3,7,10-11");
RETURN:
$string = "`no` = '1' OR `no` = '2' OR `no` = '3', `no` = 7, `no` = '10', `no` = '11'";
*/
$array = xfi_prs_ran($range);
for($i=0; 1; $i++) {
//If the value is NULL,
if ($array[$i] == NULL) {
break;
} else {
//If this is the first time of loop,
if ($i == 0) {
$condition = "`no`='$array[$i]'";
} else {
$condition .= " OR `no`='$array[$i]'";
}
}
}
//Return condition
return $condition;
}

//1.1.3. Container
//1.1.3.1. Parse a container
function xfi_prs_con($container) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
28.Apr.2010.
DESCRIPTION:
Parse a string including values to Array
CALL:
xfi_prs_con("lang=en,ko,jp,ch;hobby=reading books,programming,bowling;");
RETURN:
$array['lang'][0] = "en";
$array['lang'][1] = "ko";
$array['lang'][2] = "jp";
$array['lang'][3] = "ch";
$array['hobby'][0] = "reading books";
$array['hobby'][1] = "programming";
$array['hobby'][2] = "bowling";
*/

//Trim a string of values
$container = xfi_trm_str($container);
//Parse a string by semicolon
$temp = split(";", $container);
//Define times for a loop
$counter = substr_count($container, ";");
for ($i = 0; $i<=$counter; $i++) {
//Parse a string into name and values
list($name, $values) = split("=", $temp[$i]);
//Trim a left of name
$name = ltrim($name);
//Parse values into each value
$array[$name] = split(",", $values);
//Define times for a internal loop
$counter2 = substr_count($values, ",");
for ($j = 0; $j<=$counter2; $j++) {
//Trim a left of value
$array[$name][$j] = ltrim($array[$name][$j]);
}
}
//Return Array
return $array;
}

//1.1.3.2. Convert a container to a condition
function xfi_cvt_con($container) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
28.Apr.2010.
DESCRIPTION:
Convert a string including values to a condition of a SQL query
CALL:
xfi_cvt_con("lang=en,ko,jp,ch;hobby=reading books,programming,bowling;");
RETURN:
$condition = "`lang` = 'en' OR `lang` = 'en' OR `lang` = 'en' OR `lang` = 'OR' `hobby` = 'reading books' OR `hobby` = 'programming' OR `hobby` = 'bowling'"; 
*/
//Trim a string of values
$container = xfi_trm_str($container);
//Parse a string by semicolon
$temp = split(";", $container);
//Define times for a loop
$counter = substr_count($container, ";");
for ($i = 0; $i<=$counter; $i++) {
//Parse a string into name and values
list($name, $values) = split("=", $temp[$i]);
//Trim a left of name
$name = ltrim($name);
//Parse values into each value
$value = split(",", $values);
//Define times for a internal loop
$counter2 = substr_count($values, ",");
for ($j = 0; $j<=$counter2; $j++) {
//If this is the first time of loop,
if ($i ==0 && $j == 0) {
$condition = "`$name`= '$value[$j]'";
} else {
$condition .= " OR `$name`= '$value[$j]'";
}
}
}
return $condition;
}

//1.2. Database
//1.2.1. Excute a query
function xfi_exe_que($query) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
28.Apr.2010.
DESCRIPTION:
Execute an query
CALL:
xfi_exe_que("DROP TABLE `xf_authority`;");
RETURN:
$result = <<RESULT OF QUERY>>;
$result = NULL; // Error
*/
//Load information about DB 
include $_SERVER['DOCUMENT_ROOT']."/shelf/database.php";
//Connect to DB, Select DB and run a query
//If the database program is MySQL,
if($xf_db['kind'] == "mysql") {
//Connect to database Program
$link = @mysql_connect($xf_db['server'], $xf_db['username'], $xf_db['password']);
//Select database
mysql_select_db($xf_db['database'], $link);
$result = mysql_query($query, $link) or die("Query Error!\n");
//Close the connection
mysql_close();
} else {
$result = NULL;
}
//Return result of database
return $result;
}

//1.2.2. Count a number of rows of a result
function xfi_cnt_res($result) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
28.Apr.2010.
DESCRIPTION:
Count the rows of a result 
CALL:
xfi_cnt_res(<<RESULT OF QUERY>>);
RETURN:
$number = 3;
$number = NULL; // Error
*/
//Load information about DB 
include $_SERVER['DOCUMENT_ROOT']."/shelf/database.php";
//If the database program is MySQL,
if($xf_db['kind'] == "mysql") {
$number = mysql_num_rows($result);
} else {
$number = NULL;
}
//Return a number
return $number;
}

//1.2.4. Parse a Result
function xfi_prs_res($result, $fields = NULL) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
28.Apr.2010.
DESCRIPTION:
Parse a result of query
CALL:
xfi_prs_res(<<RESULT OF QUERY>>);
RETURN:
$array['no'][0] = 3;
$array['indicator'][0] = 1349851283;
$array['status'][0] = 1;
$array['id'][0] = "root";
$array['pw'][0] = "*68F9CD57023F17CBE06EE6365D9B4FEBF3EB3EE4";
$array['etc'][0] = "lang=en,ko,jp,ch";
$array['no'][1] = 4;
$array['indicator'][1] = 1352878344;
$array['status'][1] = 1;
$array['id'][1] = "administrator";
$array['pw'][1] = "*1F7E399139C29C99909A2C7E8C56247043C4FEE1";
$array['etc'][1] = "lang=ko,en";
$array = NULL //Error
*/
//Load information about DB
include $_SERVER['DOCUMENT_ROOT']."/shelf/database.php";
//If the list of fields are missed,
if($fields == NULL) {
$counter = 0;
} else {
//Parse fields by comma
$temp = split(",", $fields);
//Estimate times for a loop
$counter = substr_count($fields, ",");
}
for ($i=0; $i<=$counter; $i++) {
//If the list of fields are missed,
if($fields == NULL) {
//If the database program is MySQL,
if($xf_db['kind'] == "mysql") {
//Get field Name
$field = @mysql_field_name($result, $i);
} else {
//Stop the processing of this function
return $array = NULL;
}
//If there is no field name,
if ($field == NULL) {
//Stop this Loop
break;
} else {
//One more time
$counter++;
}
} else {
$field = $temp[$i];
}
//Estimate times for a subloop
$counter2 = xfi_cnt_res($result);
for($j=0; $j<$counter2; $j++) {
//If the database program is MySQL,
if($xf_db['kind'] == "mysql") {
$array[$field][$j] = mysql_result($result, $j, $field);
} else {
//Stop the processing of this function
return $array = NULL;
}
}
}
//Return Array
return $array;
}
function xfi_prs_fie($table) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
28.Apr.2010.
DESCRIPTION:
Parse field names of a table
CALL:
xfi_prs_fie("xf_user");
RETURN:
$array[0] = "no";
$array[1] = "indicator";
$array[2] = "status";
$array[3] = "id";
$array[4] = "pw";
$array[5] = "etc";
 */
//Load information about DB
include $_SERVER['DOCUMENT_ROOT']."/shelf/database.php";
//Run a query
$query = "SELECT * FROM `$table`";
$result = xfi_exe_que($query);
//Start a loop for making array 
for($i=0; 1; $i++) {
//If a kind of database is mysql,
if($xf_db['kind'] == "mysql") {
$array[$i] = @mysql_field_name($result, $i);
} else {
return false;
}
//If a name of field is null,
if ($array[$i] == NULL) {
unset($array[$i]);
break;
}
}
//Return an array;
return $array;
}
//1.3. XML

//1.4. xFacility
//1.4.1. Basic I/O
//1.4.1.1. Write
function xfi_wrt_ite($table, $container) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
28.Apr.2010.
DESCRIPTION:
Write an item in xFacility
CALL:
xfi_wrt_ite("xf_user","status=1;id=root;pw=password;lang=en,jp;");
RETURN:
$item['no'][0] = 1;
$item['indicator'][0] = 1238944426;
$item['status'][0] = 1;
$item['id'][0] = "root";
$item['pw'][0] = "*1F7E399139C29C99909A2C7E8C56247043C4FEE1";
$item['etc'][0] = "lang=en,ko";
*/
//Trim a string of values
$container = xfi_trm_str($container);
//Parse a string by semicolon
$temp = split(";", $container);
//Define times for a loop
$counter = substr_count($container, ";");
for ($i = 0; $i<=$counter; $i++) {
//Parse a string into name and values
list($name[$i], $contents[$i]) = split("=", $temp[$i]);
//Trim the left of name and values
$name[$i] = ltrim($name[$i]);
$contents[$i] = ltrim($contents[$i]);
}
//Get names of fields
$field = xfi_prs_fie($table);
//Compare a fieldname with a name of variables
for($i=0; 1; $i++) {
if($name[$i] == NULL) {
break;
}
for($j=0; 1; $j++) {
if($field[$j] == "etc") {
if($value[$j] == NULL) {
$value[$j] = $name[$i]."=".$contents[$i];
} else {
$value[$j] .= ";".$name[$i]."=".$contents[$i];
}
break;
} else if($field[$j] == $name[$i]) {
$value[$j] = $contents[$i];
break;
}
}
}
//Fields & Values
for($i=0; 1; $i++) {
if($field[$i] == NULL) {
break;
} else if($field[$i] == "no") {
$field[$i] = NULL;
$value[$i] = NULL;
} else if($field[$i] == "indicator") {
$indicator = time();
$value[$i] = "'$indicator'";
} else if($field[$i]=="pw" || $field[$i]=="password") {
$value[$i] = "password('$value[$i]')";
} else {
$value[$i] = "'$value[$i]'";
}
if($fields == NULL) {
$fields = $field[$i];
$values = $value[$i];
} else {
$fields .= ", $field[$i]";
$values .= ", $value[$i]";
}
}
//Make a query
$query = "INSERT INTO `$table`($fields) VALUES($values);";
$result = xfi_exe_que($query);
//Find information
$result = xfi_fnd_ite($table, "`indicator`='$indicator'");
$item = xfi_prs_res($result);
//Return information
return $item;
}
//1.4.1.2. Find
function xfi_fnd_ite($table, $condition) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
28.Apr.2010.
DESCRIPTION:
Find items in xFacility
CALL:
xfi_fnd_ite("xf_user", "no='1'");
RETURN:
<<RESULT OF QUERY>>
*/
$query = "SELECT * FROM `$table` WHERE $condition;";
$result = xfi_exe_que($query);
//Return result of query
return $result;
}
//1.4.1.3. Read
function xfi_red_ite($table, $range) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
DESCRIPTION:
Read items in xFacility
CALL:
xfi_red_ite("xf_user", "1-3,7");
RETURN:
$item['no'][0] = 1;
$item['indicator'][0] = 1238944426;
$item['status'][0] = 1;
$item['id'][0] = "root";
$item['pw'][0] = "*1F7E399139C29C99909A2C7E8C56247043C4FEE1";
$item['etc'][0] = "lang=en,ko";
$item['no'][0] = 2;
$item['indicator'][0] = 1283849349;
$item['status'][0] = 1;
$item['id'][0] = "administrator";
$item['pw'][0] = "*68F9CD57023F17CBE06EE6365D9B4FEBF3EB3EE4";
$item['etc'][0] = "lang=en,jp";
$item['no'][0] = 3;
$item['indicator'][0] = 1349851283;
$item['status'][0] = 1;
$item['id'][0] = "admin";
$item['pw'][0] = "*B94651992BD5A5D8316CEE083B6D7E9E3AEAC137";
$item['etc'][0] = "lang=en,ch";
$item['no'][0] = 7;
$item['indicator'][0] = 1739234725;
$item['status'][0] = 1;
$item['id'][0] = "michaelson";
$item['pw'][0] = "*68F9CD57023F17CBE06EE6365D9B4FEBF3EB3EE4";
$item['etc'][0] = "lang=ko,en";
*/
//Convert a range to a condition
$condition = xfi_cvt_ran($range);
//Run a query
$result = xfi_fnd_ite($table, $condition);
//Parse a result
$item = xfi_prs_res($result);
//Return items
return $item;
}
//1.4.1.4. Edit
function xfi_edi_ite($table, $container) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
28.Apr.2010.
DESCRIPTION:
Edit an item in xFacility
CALL:
xfi_edi_ite("xf_user","status=1;id=root;pw=password;lang=en,jp;");
RETURN:
$item['no'][0] = 1;
$item['indicator'][0] = 1238944426;
$item['status'][0] = 1;
$item['id'][0] = "root";
$item['pw'][0] = "*1F7E399139C29C99909A2C7E8C56247043C4FEE1";
$item['etc'][0] = "lang=en,ko";
*/
//Trim a string of values
$container = xfi_trm_str($container);
//Parse a string by semicolon
$temp = split(";", $container);
//Define times for a loop
$counter = substr_count($container, ";");
for ($i = 0; $i<=$counter; $i++) {
//Parse a string into name and values
list($name[$i], $contents[$i]) = split("=", $temp[$i]);
//Trim the left of name and values
$name[$i] = ltrim($name[$i]);
$contents[$i] = ltrim($contents[$i]);
}
//Get names of fields
$field = xfi_prs_fie($table);
//Compare a fieldname with a name of variables
for($i=0; 1; $i++) {
if($name[$i] == NULL) {
break;
}
for($j=0; 1; $j++) {
if($field[$j] == "etc") {
if($value[$j] == NULL) {
$value[$j] = $name[$i]."=".$contents[$i];
} else {
$value[$j] .= ";".$name[$i]."=".$contents[$i];
}
break;
} else if($field[$j] == $name[$i]) {
$value[$j] = $contents[$i];
break;
}
}
}
//Fields & Values
for($i=0; 1; $i++) {
if($field[$i] == NULL) {
break;
} else if($field[$i] == "no") {
$field[$i] = NULL;
$no = $value[$i];
$value[$i] = NULL;
} else if($field[$i] == "indicator") {
$field[$i] = NULL;
$value[$i] = NULL;
} else if($field[$i]=="pw" || $field[$i]=="password") {
$value[$i] = "password('$value[$i]')";
} else {
$value[$i] = "'$value[$i]'";
}
if($field[$i] != NULL) {
if($setting == NULL) {
$setting = "`$field[$i]`=$value[$i]";
} else {
$setting .= ", `$field[$i]`=$value[$i]";
}
}
}
//Make a query
$query = "UPDATE `$table` SET $setting WHERE `no`='$no';";
$result = xfi_exe_que($query);
//Find information
$result = xfi_fnd_ite($table, "`no`='$no'");
$item = xfi_prs_res($result);
//Return information
return $item;
}
//1.4.1.5. Delete
function xfi_del_ite($table, $range) {
/*
DEVELOPER:
Michael Son(michaelson@nate.com)
28.Apr.2010.
DESCRIPTION:
Delete items in xFacility
CALL:
xfi_del_ite("xf_user", "1-3,7");
RESULT:
<<RESULT OF QUERY>>
*/
//Convert a range to a condition
$condition = xfi_cvt_ran($range);
//Write a query
$query = "DELETE FROM `$table` WHERE $condition";
//Run a query
$result = xfi_exe_res($query);
//Return result of query
return $result;
}
//Relationship
//1.4.2. Relationship
function xfi_mke_rel($table, $no, $event) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
28.Apr.2010.
DESCRIPTION:
Make relationships with other library
CALL:
xfi_mke_rel("xf_party", 1, "write");
RETURN:
TRUE;
FALSE;
*/
//If the prefix is xf_party
if ($table == "xf_party") {

//If the prefix is xf_shelf
} else if ($table == "xf_shelf") {

//If the prefix is xf_compass,
} else if ($table == "xf_compass") {

//If the prefix is xf_timeline,
} else if ($table == "xf_timeline") {
//If the prefix is xf_mission,
} else if ($table == "xf_mission") {
}
}
//1.4.3. Checking
//1.4.3.1. Data
//1.4.3.1. Data
function xfi_chk_dat() {
/*
DEVELOPER:
Michael Son(michaelson@nate.com)
28.Apr.2010.
DESCRIPTION:
Check a form of data
CALL:
xfi_chk_dat();
RESULT:
TRUE;
FALSE;
*/
}
//1.4.3.2. Authority
//1.4.3.2. Authority
function xfi_chk_ath() {
/*
DEVELOPER:
Michael Son(michaelson@nate.com)
28.Apr.2010.
DESCRIPTION:
Check a authority of access
CALL:
xfi_chk_ath();
RESULT:
TRUE;
FALSE;
*/
}

//Part2. System API
//2. [xF]User
//3. [xF]Owner
//4. [xF]Authority
//5. [xF]Referer
//Part3. Data API
//6. [xF]Party
//7. [xF]Shelf
//8. [xF]Compass
//9. [xF]Timeline

'xFacility > Codes' 카테고리의 다른 글

container()  (0) 2010.06.08
xFacility^PHP > Internal API 3.0  (0) 2010.06.08
xFacility^PHP > Internal API 1.0  (0) 2010.05.17
Posted by 마이클
xFacility/Codes2010. 5. 17. 23:27
개발하다가 효율성이 떨어져 중도 포기한 Internal API 1.0입니다.

//Part1. Common API
//1. [xF]Secretary(xfx)
//1.1. Text
function xfx_trm_str($string, $character = ",;") {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
22.Apr.2010.
DESCRIPTION:
Trim a special character(comma and semicolon) at end of string
CALL:
xfx_trm_str("lang=en,ko,jp,ch;hobby=reading books,programming,bowling;");
RETURN:
$string = "lang=en,ko,jp,ch;hobby=reading books,programming,bowling";
*/
//Define times for a Loop
$length = strlen($character);
//Check each character by a loop
for ($i=0; $i<$length; $i++) {
//If the end of string is a appointed character,
if(substr($string,-1) == substr($character, $i, 1)) {
//Delete the last character of string
$string = substr($string, 0, -1);
}
}
//Return a trimmed string
return $string;
}
function xfx_prs_ran ($range) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
22.Apr.2010.
DESCRIPTION:
Parse Range to Array
CALL:
xfx_prs_ran("1-3,7,10-11");
RETURN:
$array[0] = "1";
$array[1] = "2";
$array[2] = "3";
$array[3] = "7";
$array[4] = "10";
$array[5] = "11";
*/
//Trim a string
$range = xfx_trm_str($range);
$range = trim($range);
//Parse a string by comma
$temp = split(",", $range);
//Move values to array
$now = 0;
for ($i=0; $i<=substr_count($range,","); $i++) {
//Check a hyphen
if (substr_count($temp[$i],"-") == 1) {
list($start, $end) = split("-", $temp[$i]);
$difference = $end - $start;
for ($j=0; $j<=$difference; $j++) {
$array[$now] = $start + $j;
$now += 1;
}
} else {
$array[$now] = $temp[$i];
$now += 1;
}
}
//Delete overlapping values 
$array = array_unique($array);
//Sort the array
sort($array);
reset($array);
//Return Array
return $array;
}
function xfx_cvt_ran ($range) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
22.Apr.2010.
DESCRIPTION:
Convert a range to a condition of a SQL query
CALL:
xfx_cvt_ran("1-3,7,10-11");
RETURN:
$string = "`no` = '1' OR `no` = '2' OR `no` = '3', `no` = 7, `no` = '10', `no` = '11'";
*/
$array = xfx_prs_ran($range);
for($i=0; 1; $i++) {
//If the value is NULL,
if ($array[$i] == NULL) {
break;
} else {
//If this is the first time of loop,
if ($i == 0) {
$condition = "`no`='$array[$i]'";
} else {
$condition .= " OR `no`='$array[$i]'";
}
}
}
//Return condition
return $condition;
}
function xfx_prs_con ($container) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
22.Apr.2010.
DESCRIPTION:
Parse a string including values to Array
CALL:
xfx_prs_con("lang=en,ko,jp,ch;hobby=reading books,programming,bowling;");
RETURN:
$array['lang'][0] = "en";
$array['lang'][1] = "ko";
$array['lang'][2] = "jp";
$array['lang'][3] = "ch";
$array['hobby'][0] = "reading books";
$array['hobby'][1] = "programming";
$array['hobby'][2] = "bowling";
*/

  //Trim a string of values
$container = xfx_trm_str($container);
//Parse a string by semicolon
$temp = split(";", $container);
//Define times for a loop
$counter = substr_count($container, ";");
for ($i = 0; $i<=$counter; $i++) {
//Parse a string into name and values
list($name, $values) = split("=", $temp[$i]);
//Trim a left of name
$name = ltrim($name);
//Parse values into each value
$array[$name] = split(",", $values);
//Define times for a internal loop
$counter2 = substr_count($values, ",");
for ($j = 0; $j<=$counter2; $j++) {
//Trim a left of value
$array[$name][$j] = ltrim($array[$name][$j]);
}
}
//Return Array
return $array;
}
function xfx_cvt_con($container) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
22.Apr.2010.
DESCRIPTION:
Convert a string including values to a condition of a SQL query
CALL:
xfx_cvt_con("lang=en,ko,jp,ch;hobby=reading books,programming,bowling;");
RETURN:
$condition = "`lang` = 'en' OR `lang` = 'en' OR `lang` = 'en' OR `lang` = 'OR' `hobby` = 'reading books' OR `hobby` = 'programming' OR `hobby` = 'bowling'"; 
*/
//Trim a string of values
$container = xfx_trm_str($container);
//Parse a string by semicolon
$temp = split(";", $container);
//Define times for a loop
$counter = substr_count($container, ";");
for ($i = 0; $i<=$counter; $i++) {
//Parse a string into name and values
list($name, $values) = split("=", $temp[$i]);
//Trim a left of name
$name = ltrim($name);
//Parse values into each value
$value = split(",", $values);
//Define times for a internal loop
$counter2 = substr_count($values, ",");
for ($j = 0; $j<=$counter2; $j++) {
//If this is the first time of loop,
if ($i ==0 && $j == 0) {
$condition = "`$name`= '$value[$j]'";
} else {
$condition .= " OR `$name`= '$value[$j]'";
}
}
}
return $condition;
}
//1.2. Database
function xfx_exe_que($query) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
22.Apr.2010.
DESCRIPTION:
Parse Range to Array
CALL:
xfx_exe_que("DROP TABLE `xf_authority`;");
RETURN:
$result = <<RESULT OF QUERY>>;
$result = NULL; // Error
*/
//Load information about DB 
include $_SERVER['DOCUMENT_ROOT']."/shelf/database.php";
//Connect to DB, Select DB and run a query
//If the database program is MySQL,
if($xf_db['kind'] == "mysql") {
//Connect to database Program
$link = @mysql_connect($xf_db['server'], $xf_db['username'], $xf_db['password']);
//Select database
mysql_select_db($xf_db['database'], $link);
$result = mysql_query($query, $link) or die("Query Error!\n");
//Close the connection
mysql_close();
} else {
$result = NULL;
}
//Return result of database
return $result;
}
function xfx_cnt_res($result) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
22.Apr.2010.
DESCRIPTION:
Count the rows of a result 
CALL:
xfx_cnt_res(<<RESULT OF QUERY>>);
RETURN:
$number = 3;
$number = NULL; // Error
*/
//Load information about DB 
include $_SERVER['DOCUMENT_ROOT']."/shelf/database.php";
//If the database program is MySQL,
if($xf_db['kind'] == "mysql") {
$number = mysql_num_rows($result);
} else {
$number = NULL;
}
//Return a number
return $number;
}
function xfx_prs_res($result, $fields = NULL) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
22.Apr.2010.
DESCRIPTION:
Count the rows of a result 
CALL:
xfx_prs_res(<<RESULT OF QUERY>>);
RETURN:
$array['no'][0] = 3;
$array['indicator'][0] = 1349851283;
$array['status'][0] = 1;
$array['id'][0] = "root";
$array['pw'][0] = "*68F9CD57023F17CBE06EE6365D9B4FEBF3EB3EE4";
$array['etc'][0] = "lang=en,ko,jp,ch";
$array['no'][1] = 4;
$array['indicator'][1] = 1352878344;
$array['status'][1] = 1;
$array['id'][1] = "administrator";
$array['pw'][1] = "*1F7E399139C29C99909A2C7E8C56247043C4FEE1";
$array['etc'][1] = "lang=ko,en";
$array = NULL //Error
*/
//Load information about DB
include $_SERVER['DOCUMENT_ROOT']."/shelf/database.php";
//If the list of fields are missed,
if($fields == NULL) {
$counter = 0;
} else {
//Parse fields by comma
$temp = split(",", $fields);
//Estimate times for a loop
$counter = substr_count($fields, ",");
}
for ($i=0; $i<=$counter; $i++) {
//If the list of fields are missed,
if($fields == NULL) {
//If the database program is MySQL,
if($xf_db['kind'] == "mysql") {
//Get field Name
$field = @mysql_field_name($result, $i);
} else {
//Stop the processing of this function
return $array = NULL;
}
//If there is no field name,
if ($field == NULL) {
//Stop this Loop
break;
} else {
//One more time
$counter++;
}
} else {
$field = $temp[$i];
}
//Estimate times for a subloop
$counter2 = xfx_cnt_res($result);
for($j=0; $j<$counter2; $j++) {
//If the database program is MySQL,
if($xf_db['kind'] == "mysql") {
$array[$field][$j] = mysql_result($result, $j, $field);
} else {
//Stop the processing of this function
return $array = NULL;
}
}
}
//Return Array
return $array;
}
//1.3. XML

//1.4. xFaciltiy
function xfx_fnd_ite($table, $condition) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
23.Apr.2010.
DESCRIPTION:
Find a item in xFacility
CALL:
xfx_fnd_ite("xf_user", "no='1'");
RETURN:
<<RESULT OF QUERY>>
*/
$query = "SELECT * FROM `$table` WHERE $condition;";
$result = xfx_exe_que($query);
return $result;
}
function xfx_mke_rel($table, $no, $event) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
23.Apr.2010.
DESCRIPTION:
Make relationships with other library
CALL:
xfx_mke_rel("xf_party", 1, "write");
RETURN:
??
*/
//If the prefix is xf_party
if ($prefix == "xf_party") {

  //If the prefix is xf_shelf
} else if ($prefix == "xf_shelf") {

  //If the prefix is xf_compass,
} else if ($prefix == "xfc") {

  //If the prefix is xf_timeline,
} else if ($prefix == "xft") {
//If the prefix is xf_mission,
} else if ($prefix == "xfm") {
}
}

//Part2. System API
//2. xfu
//2.1. Write
function xfu_write_item($id, $pw, $etc = 'lang=en') {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
23.Apr.2010.
DESCRIPTION:
Make a item in [xF]User
CALL:
xfu_write_item("root", "password");
RETURN:
$xf_user['no'][0] = 3;
$xf_user['indicator'][0] = 1349851283;
$xf_user['status'][0] = 1;
$xf_user['id'][0] = "root";
$xf_user['pw'][0] = "*68F9CD57023F17CBE06EE6365D9B4FEBF3EB3EE4";
$xf_user['etc'][0] = "lang=en";
$xf_user = NULL; //Error
*/
//Check same ID in [xF]User
$result = xfx_fnd_ite("xf_user", "`id`='$id'"); 
if (xfx_cnt_res($result) == 1) {
$xf_user = NULL;
return $xf_user;
}
//Make a indicator
$indicator = time();
$query = "INSERT INTO `xf_user`(indicator, status, id, pw, etc) VALUES('$indicator', '1', '$id', password('$pw'), '$etc')";
$result = xfx_exe_que($query);
//Get information for the registration
unset($result);
$result = xfx_fnd_ite("xf_user", "`id`='$id' AND `indicator`='$indicator'");
$xf_user = xfx_prs_res($result);
//Return registered information of user 
return $xf_user;
}
//2.2. Find
function xfu_find_items($container) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
23.Apr.2010.
DESCRIPTION:
Find items in [xF]User
CALL:
xfu_find_item("id=root,admin,administrator;no=1;");
RETURN:
<<RESULT OF QUERY>>
*/
//Write a condition by values
$condition = xfx_cvt_con($container);
$result = xfx_fnd_ite("xf_user", $condition);
//Return information of user 
return $result;
}
//2.3. Read
function xfu_read_item($no) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
23.Apr.2010.
DESCRIPTION:
Read a item in [xF]User
CALL:
xfu_read_items("1-3,7");
RETURN:
$xf_user['no'][0] = 3;
$xf_user['indicator'][0] = 1238944426;
$xf_user['status'][0] = 1;
$xf_user['id'][0] = "root";
$xf_user['pw'][0] = "*1F7E399139C29C99909A2C7E8C56247043C4FEE1";
$xf_user['etc'][0] = "lang=en,ko";
*/

  //Convert a range to condition
$condition = "`no`='$no'";
$result = xfx_fnd_ite("xf_user", $condition);
$xf_user = xfx_prs_res($result);
//Return user information
return $xf_user; 
}
function xfu_read_items($range) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
23.Apr.2010.
DESCRIPTION:
Read items in [xF]User
CALL:
xfu_read_items("1-3,7");
RETURN:
$xf_user['no'][0] = 3;
$xf_user['indicator'][0] = 1238944426;
$xf_user['status'][0] = 1;
$xf_user['id'][0] = "root";
$xf_user['pw'][0] = "*1F7E399139C29C99909A2C7E8C56247043C4FEE1";
$xf_user['etc'][0] = "lang=en,ko";
$xf_user['no'][0] = 2;
$xf_user['indicator'][0] = 1283849349;
$xf_user['status'][0] = 1;
$xf_user['id'][0] = "administrator";
$xf_user['pw'][0] = "*68F9CD57023F17CBE06EE6365D9B4FEBF3EB3EE4";
$xf_user['etc'][0] = "lang=en,jp";
$xf_user['no'][0] = 3;
$xf_user['indicator'][0] = 1349851283;
$xf_user['status'][0] = 1;
$xf_user['id'][0] = "admin";
$xf_user['pw'][0] = "*B94651992BD5A5D8316CEE083B6D7E9E3AEAC137";
$xf_user['etc'][0] = "lang=en,ch";
$xf_user['no'][0] = 7;
$xf_user['indicator'][0] = 1739234725;
$xf_user['status'][0] = 1;
$xf_user['id'][0] = "michaelson";
$xf_user['pw'][0] = "*68F9CD57023F17CBE06EE6365D9B4FEBF3EB3EE4";
$xf_user['etc'][0] = "lang=ko,en";
*/

  //Convert a range to condition
$condition = xfx_cvt_ran($range);
$result = xfx_fnd_ite("xf_user", $condition);
$xf_user = xfx_prs_res($result);
//Return user information
return $xf_user; 
}
//2.4. Edit
function xfu_edit_item($no, $id, $pw, $etc = 'lang=en') {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
23.Apr.2010.
DESCRIPTION:
Edit a item in [xF]User
CALL:
xfu_edit_item(3, "root", "password", "lang=en");
RETURN:
$xf_user['no'][0] = 3;
$xf_user['indicator'][0] = 1349851283;
$xf_user['status'][0] = 1;
$xf_user['id'][0] = "root";
$xf_user['pw'][0] = "*68F9CD57023F17CBE06EE6365D9B4FEBF3EB3EE4";
$xf_user['etc'][0] = "lang=en";
$xf_user = NULL; //Error
*/
//Is there information
$result = xfx_fnd_ite("xf_user", "`no`='$no'"); 
if (xfx_cnt_res($result) == 0) {
$xf_user = NULL;
return $xf_user;
}
//Check by rule
//Not register same id
$result = xfx_fnd_ite("xf_user", "`no`!='$no' AND `id`='$id'"); 
if (xfx_cnt_res($result) == 1) {
$xf_user = NULL;
return $xf_user;
}
$query = "UPDATE `xf_user` SET `id`='$id', `pw`=PASSWORD('$pw'), `etc`='$etc' WHERE `no`='$no';";
$result = xfx_exe_que($query);
//Get information about a user
$result = xfx_fnd_ite("xf_user", "`no`='$no'");
$xf_user = xfx_prs_res($result);
//Return registered information of user 
return $xf_user;
}
//2.5. Delete
function xfu_delete_item($no) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
23.Apr.2010.
DESCRIPTION:
Delete a item in [xF]User
CALL:
xfu_delete_items(3);
RETURN:
<<RESULT OF QUERY>>
*/
$query = "DELETE FROM `xf_user` WHERE `no`='$no'";
$result = xfx_exe_que($query);
return $result;
}
function xfu_delete_items($range) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
23.Apr.2010.
DESCRIPTION:
Delete items in [xF]User
CALL:
xfu_delete_items("1-3,7");
RETURN:
<<RESULT OF QUERY>>
*/
$condition = xfx_cvt_ran($range);
$query = "DELETE FROM `xf_user` WHERE $condition";
$result = xfx_exe_que($query);
//Return result
return $result;
}
//3. xfo
//3.1. Write
function xfo_write_item($status, $owner_type, $owner_no, $own_type, $own_no) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
23.Apr.2010.
DESCRIPTION:
Make a item in [xF]Owner
CALL:
xfo_write_item(1, "xf_party", 1, "xf_shelf", 34);
RETURN:
$xf_owner['no'][0] = 3;
$xf_owner['indicator'][0] = 1349851283;
$xf_owner['status'][0] = 1;
$xf_owner['owner_type'][0] = "xf_party";
$xf_owner['owner_no'][0] = "1";
$xf_owner['own_type'][0] = "xf_shelf";
$xf_owner['own_no'][0] = "34";
$xf_owner = NULL; //Error
*/
//Check by the rule
//Not own itself
if ($owner_type == $own_type && $owner_no == $own_no) {
$xf_owner = NULL;
return $xf_owner;
}
//Not own each other
$result = xfx_fnd_ite("xf_owner", "`owner_type`='$own_type' AND `owner_no`='$own_no'");
if(xfx_cnt_res($result) >= 1) {
$xf_owner = NULL;
return $xf_owner;
}
$result = xfx_fnd_ite("xf_owner", "`own_type`='$owner_type' AND `own_no`='$owner_no'");
if(xfx_cnt_res($result) >= 1) {
$xf_owner = NULL;
return $xf_owner;
}
//Not register same thing
$result = xfx_fnd_ite("xf_owner", "`owner_type`='$owner_type' AND `owner_no`='$owner_no' AND `own_type`='$own_type' AND `own_no`='$own_no'");
if(xfx_cnt_res($result) >= 1) {
$xf_owner = NULL;
return $xf_owner;
}
//Reset a value of status
$status = 1;
//Set indicator
$indicator = time();
//Write a item in DB
$query = "INSERT INTO `xf_owner`(indicator, status, owner_type, owner_no, own_type, own_no) VALUES('$indicator', '$status', '$owner_type', '$owner_no', '$own_type', '$own_no')";
$result = xfx_exe_que($query);
//Receive information from DB
$result = xfx_fnd_ite("xf_owner", "`indicator`='$indicator' AND `owner_type`='$owner_type' AND `owner_no`='$owner_no'");
$xf_owner = xfx_prs_res($result);
//Return information about Owner
return $xf_owner;
}
//3.2. Find
function xfo_find_items($container) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
25.Apr.2010.
DESCRIPTION:
Find items in [xF]Owner
CALL:
xfo_find_items("");
RETURN:
<<RESULT OF QUERY>>
*/
$condtion = xfx_cvt_con($container); 
$result = xfx_fnd_ite("xf_owner", $condition);
return $result;
}
//3.3. Read
function xfo_read_item($no) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
23.Apr.2010.
DESCRIPTION:
Read a item in [xF]User
CALL:
xfo_read_item(3);
RETURN:
$xf_owner['no'][0] = 3;
$xf_owner['indicator'][0] = 1349851283;
$xf_owner['status'][0] = 1;
$xf_owner['owner_type'][0] = "xf_party";
$xf_owner['owner_no'][0] = "1";
$xf_owner['own_type'][0] = "xf_shelf";
$xf_owner['own_no'][0] = "34";
*/
//Make a condtion using a no
$condition = "`no` = '$no'";
$result = xfx_fnd_ite("xf_owner", $condition);
$xf_owner = xfx_prs_res($result);
//Return user information
return $xf_owner;
}
function xfo_read_items($range) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
25.Apr.2010.
DESCRIPTION:
Read items in [xF]Owner
CALL:
xfo_read_items("1-3,7");
RETURN:
$xf_owner['no'][0] = 1;
$xf_owner['indicator'][0] = 1349851283;
$xf_owner['status'][0] = 1;
$xf_owner['owner_type'][0] = "xf_party";
$xf_owner['owner_no'][0] = "1";
$xf_owner['own_type'][0] = "xf_shelf";
$xf_owner['own_no'][0] = "12";
$xf_owner['no'][0] = 2;
$xf_owner['indicator'][0] = 1397421283;
$xf_owner['status'][0] = 1;
$xf_owner['owner_type'][0] = "xf_party";
$xf_owner['owner_no'][0] = "1";
$xf_owner['own_type'][0] = "xf_party";
$xf_owner['own_no'][0] = "7";
$xf_owner['no'][0] = 3;
$xf_owner['indicator'][0] = 1489211283;
$xf_owner['status'][0] = 1;
$xf_owner['owner_type'][0] = "xf_party";
$xf_owner['owner_no'][0] = "1";
$xf_owner['own_type'][0] = "xf_shelf";
$xf_owner['own_no'][0] = "34";
$xf_owner['no'][0] = 7;
$xf_owner['indicator'][0] = 1541851283;
$xf_owner['status'][0] = 1;
$xf_owner['owner_type'][0] = "xf_party";
$xf_owner['owner_no'][0] = "7";
$xf_owner['own_type'][0] = "xf_compass";
$xf_owner['own_no'][0] = "4";
*/
//Convert a range to condition
$condition = xfx_cvt_ran($range);
$result = xfx_fnd_ite("xf_owner", $condition);
$xf_owner = xfx_prs_res($result);
//Return user information
return $xf_owner;
}
//3.4. Edit
function xfo_edit_item($no, $status, $owner_type, $owner_no, $own_type, $own_no) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
25.Apr.2010.
DESCRIPTION:
Edit a item in [xF]Owner
CALL:
xfo_edit_item(3, 1, "xf_party", 1, "xf_shelf", 34);
RETURN:
$xf_owner['no'][0] = 3;
$xf_owner['indicator'][0] = 1489211283;
$xf_owner['status'][0] = 1;
$xf_owner['owner_type'][0] = "xf_party";
$xf_owner['owner_no'][0] = "1";
$xf_owner['own_type'][0] = "xf_shelf";
$xf_owner['own_no'][0] = "34";
*/
//Check by the rule

  //Edit
$query = "UPDATE `xf_owner` SET `status`='$status', `owner_type`='$owner_type', `owner_no`='$owner_no', `own_type`='$own_type', `own_no`='$own_no' WHERE `no`='$no';";
$result = xfx_exe_que($query);
$xf_owner = xfa_read_item($no);
return $xf_owner;
}
//3.5. Delete
function xfo_delete_item($no) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
23.Apr.2010.
DESCRIPTION:
Delete a item in [xF]Owner
CALL:
xfo_delete_items(3);
RETURN:
<<RESULT OF QUERY>>
*/
$query = "DELETE FROM `xf_owner` WHERE `no`='$no'";
$result = xfx_exe_que($query);
//Return result
return $result;
}
function xfo_delete_items($range) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
23.Apr.2010.
DESCRIPTION:
Delete items in [xF]Owner
CALL:
xfo_delete_items("1-3,7");
RETURN:
<<RESULT OF QUERY>>
*/
$condition = xfx_cvt_ran($range);
$query = "DELETE FROM `xf_owner` WHERE $condition";
$result = xfx_exe_que($query);
//Return result
return $result;
}
//4. xfa
//4.1. Write
function xfa_write_item($status, $subject_type, $subject_no, $verb, $object_type, $object_no) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
26.Apr.2010.
DESCRIPTION:
Write a item in [xF]Authority
CALL:
xfa_write_item(1, "xf_user", 1, xfa_find_item, "xf_authority", 1);
RESULT:
$xf_authority['no'][0] = 1;
$xf_authority['indicator'][0] = 1398594750;
$xf_authority['status'][0] = 1;
$xf_authority['subject_type'][0] = 1;
$xf_authority['subject_no'][0] = 1;
$xf_authority['verb'][0] = 1;
$xf_authority['object_type'][0] = 1;
$xf_authority['object_no'][0] = 1;
*/
$indicator = time();
$query = "INSERT INTO `xf_authority`(indicator, status, subject_type, subject_no, verb, object_type, object_no) VALUES('$indicator', $status', '$subject_type', '$subject_no', '$verb', '$object_type', '$object_no')";
$result = xfx_exe_que($query);
$result = xfx_fnd_ite("xf_authority", "`indicator`='$indicator' AND subject_no`='$subject_no' AND `object_no`='$object_no'");
$xf_authority = xfx_prs_res($result);
return $xf_authority;
}
//4.2. Find
function xfa_find_items($container) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
25.Apr.2010.
DESCRIPTION:
Find items in [xF]Authority
CALL:
xfa_find_items("status=1;verb=xfa_find_item");
RETURN:
<<RESULT OF QUERY>>
*/
$condition = xfx_cvt_con($container);
$result = xfx_fnd_ite("xf_authority", $condition);
return $result;
}
//4.3. Read
function xfa_read_item($no) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
25.Apr.2010.
DESCRIPTION:
Read a item in [xF]Authority
CALL:
xfa_read_item(5);
RETURN:
$xf_authority['no'] = 5;
$xf_authority['indicator'] = 1436879648;
$xf_authority['status'] = 3
$xf_authority['subject_type'] = "xf_party"; 
$xf_authority['subject_no'] = 3;
$xf_authority['verb'] = "xfs_write_item";
$xf_authority['object_type'] = "xf_shelf";
$xf_authority['object_no'] = 0;
*/
$result = xfx_fnd_ite("xf_authority", "`no`='$no'");
$xf_authority = xfx_prs_res($result);
return $xf_authority;
}
function xfa_read_items($range) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
25.Apr.2010.
DESCRIPTION:
Read items in [xF]Authority
CALL:
xfa_read_items("1-3,5");
RETURN:
$xf_authority['no'] = 1;
$xf_authority['indicator'] = 1339429529;
$xf_authority['status'] = 1
$xf_authority['subject_type'] = "xf_party"; 
$xf_authority['subject_no'] = 3;
$xf_authority['verb'] = "xfs_write_item";
$xf_authority['object_type'] = "xf_shelf";
$xf_authority['object_no'] = 0;
$xf_authority['no'] = 2;
$xf_authority['indicator'] = 1358829841;
$xf_authority['status'] = 0
$xf_authority['subject_type'] = "xf_party"; 
$xf_authority['subject_no'] = 3;
$xf_authority['verb'] = "xfs_write_item";
$xf_authority['object_type'] = "xf_shelf";
$xf_authority['object_no'] = 0;
$xf_authority['no'] = 3;
$xf_authority['indicator'] = 1397172184;
$xf_authority['status'] = 2
$xf_authority['subject_type'] = "xf_party"; 
$xf_authority['subject_no'] = 3;
$xf_authority['verb'] = "xfs_write_item";
$xf_authority['object_type'] = "xf_shelf";
$xf_authority['object_no'] = 0;
$xf_authority['no'] = 5;
$xf_authority['indicator'] = 1436879648;
$xf_authority['status'] = 3
$xf_authority['subject_type'] = "xf_party"; 
$xf_authority['subject_no'] = 3;
$xf_authority['verb'] = "xfs_write_item";
$xf_authority['object_type'] = "xf_shelf";
$xf_authority['object_no'] = 0;
*/
$condition = xfx_cvt_ran($range);
$result = xfx_fnd_ite("xf_authority", $condition);
$xf_authority = xfx_prs_res($result);
return $xf_authority;
}
//4.4. Edit
function xfa_edit_item($no, $status, $subject_type, $subject_no, $verb, $object_type, $object_no) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
25.Apr.2010.
DESCRIPTION:
Edit a item in [xF]Authority
CALL:
xfa_edit_item(5, 3, "xf_party", 3, "xfs_write_item", "xf_shelf", 0);
RETURN:
$xf_authority['no'] = 5;
$xf_authority['indicator'] = 1436879648;
$xf_authority['status'] = 3
$xf_authority['subject_type'] = "xf_party"; 
$xf_authority['subject_no'] = 3;
$xf_authority['verb'] = "xfs_write_item";
$xf_authority['object_type'] = "xf_shelf";
$xf_authority['object_no'] = 0;
*/
$query = "UPDATE `xf_authority` SET `status`='$status', `subject_type`='$subject_type', `subject_no`='$subject_no', `verb`='$verb', `object_type`='$object_type', `object_no`='$object_no' WHERE `no`='$no';";
$result = xfx_exe_que($query);
$xf_authority = xfa_read_item($no);
return $xf_authority;
}
//4.5. Delete
function xfa_delete_item($no) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
25.Apr.2010.
DESCRIPTION:
Delete a item in [xF]Authority
CALL:
xfa_delete_items(3);
RETURN:
<<RESULT OF QUERY>>
*/
$query = "DELETE FROM `xf_authority` WHERE `no`='$no'";
$result = xfx_exe_que($query);
//Return result
return $result;
}
function xfa_delete_items($range) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
25.Apr.2010.
DESCRIPTION:
Delete items in [xF]Authority
CALL:
xfa_delete_items("1-3,7");
RETURN:
<<RESULT OF QUERY>>
*/
$condition = xfx_cvt_ran($range);
$query = "DELETE FROM `xf_authority` WHERE $condition";
$result = xfx_exe_que($query);
//Return result
return $result;
}
//5. xfr
//5.1. Write
function xfr_write_item($status, $referer_type, $referer_no, $reference_type, $reference_no) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
28.Apr.2010.
DESCRIPTION:
Write an item in [xF]Referer
CALL:
xfr_write_item(1, "xf_party", 5, "xf_timeline", 7);
RETURN:
$xf_referer['no'][0] = 3;
$xf_referer['indicator'][0] = 1239559924;
$xf_referer['status'][0] = 1;
$xf_referer['referer_type'][0] = "xf_party";
$xf_referer['referer_no'][0] = 5;
$xf_referer['reference_type'][0] = "xf_timeline";
$xf_referer['reference_no'][0] = 7;
*/

  //Write a new item
$indicator = time();
$query = "INSERT INTO `xf_referer`(indicator, status, referer_type, referer_no, reference_type, reference_no) VALUES('$indicator', '$status', '$referer_type', '$referer_no', $reference_type', '$reference_no')"; 
$result = xfx_exe_que($query);
//Bring information about a item which has just written
$result = xfx_fnd_ite("xf_referer", "`indicator`='$indicator' AND `reference_type`='$reference_type' AND `reference_no`='$reference_no'");
$xf_referer = xfx_prs_res($result);
//Return information
return $xf_referer;
}
//5.2. Find
function xfr_find_items($container) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
28.Apr.2010.
DESCRIPTION:
Find items in [xF]Referer
CALL:
xfr_find_items("referer_type=xf_party;reference_type=xf_timeline");
RETURN:
<<RESULT OF QUERY>>
*/
//Convert a container to a condition
$condition = xfx_cvt_con($container);
$result = xfx_fnd_ite("xf_referer", $container);
return $result;
}
//5.3. Read
function xfr_read_item($no) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
28.Apr.2010.
DESCRIPTION:
Read a item in [xF]Referer
CALL:
xfr_read_item(3);
RETURN:
$xf_referer['no'][0] = 3;
$xf_referer['indicator'][0] = 1239559924;
$xf_referer['status'][0] = 1;
$xf_referer['referer_type'][0] = "xf_party";
$xf_referer['referer_no'][0] = 5;
$xf_referer['reference_type'][0] = "xf_timeline";
$xf_referer['reference_no'][0] = 7;
*/
$result = xfx_fnd_ite("xf_referer", "`no`='$no'");
$xf_referer = xfx_prs_res($result);
return $xf_referer;
}
function xfr_read_items($range) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
DESCRIPTION:
Read items in [xF]Referer
CALL:
xfr_read_item("1-3,7");
RETURN:
$xf_referer['no'][0] = 1;
$xf_referer['indicator'][0] = 1239559924;
$xf_referer['status'][0] = 1;
$xf_referer['referer_type'][0] = "xf_party";
$xf_referer['referer_no'][0] = 5;
$xf_referer['reference_type'][0] = "xf_timeline";
$xf_referer['reference_no'][0] = 7;
$xf_referer['no'][0] = 2;
$xf_referer['indicator'][0] = 1310293983;
$xf_referer['status'][0] = 1;
$xf_referer['referer_type'][0] = "xf_timeline";
$xf_referer['referer_no'][0] = 10;
$xf_referer['reference_type'][0] = "xf_shelf";
$xf_referer['reference_no'][0] = 7;
$xf_referer['no'][0] = 3;
$xf_referer['indicator'][0] = 1372039747;
$xf_referer['status'][0] = 1;
$xf_referer['referer_type'][0] = "xf_shelf";
$xf_referer['referer_no'][0] = 7;
$xf_referer['reference_type'][0] = "xf_timeline";
$xf_referer['reference_no'][0] = 10;
$xf_referer['no'][0] = 7;
$xf_referer['indicator'][0] = 1482938748;
$xf_referer['status'][0] = 1;
$xf_referer['referer_type'][0] = "xf_party";
$xf_referer['referer_no'][0] = 8;
$xf_referer['reference_type'][0] = "xf_timeline";
$xf_referer['reference_no'][0] = 14;
*/
//Convert a range to a condition
$condition = xfx_cvt_ran($range) ;
$result = xfx_fnd_ite("xf_referer", $condition);
$xf_referer = xfx_prs_res($result);
//Return Information
return $xf_referer;
}
//5.4. Edit
function xfr_edit_item($no, $status, $referer_type, $referer_no, $reference_type, $reference_no) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
28.Apr.2010.
DESCRIPTION:
Edit an item in [xF]Referer
CALL:
xfr_edit_item(3, 1, "xf_party", 5, "xf_timeline", 7);
RETURN:
$xf_referer['no'][0] = 3;
$xf_referer['indicator'][0] = 1239559924;
$xf_referer['status'][0] = 1;
$xf_referer['referer_type'][0] = "xf_party";
$xf_referer['referer_no'][0] = 5;
$xf_referer['reference_type'][0] = "xf_timeline";
$xf_referer['reference_no'][0] = 7;
*/
$query = "UPDATE SET `status`='$status, `referer_type`='$referer_type', `referer_no`='$referer_no', `reference_type`='$reference_type', `refererence_no`='$reference_no' WHERE `no`='$no';";
$result = xfx_exe_que($result);
$xf_referer = xfr_read_item($no);
return $xf_referer;
}
//5.5. Delete
function xfr_delete_item($no) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
28.Apr.2010.
DESCRIPTION:
Delete an item from [xF]Referer
CALL:
xfr_delete_item(3);
RETURN:
<<RESULT OF QUERY>>
*/
$condition = "`no`='$no'";
$query = "DELETE FROM `xf_referer` WHERE ".$condition;
$result = xfx_exe_que($query);
//Return a result
return $result;
}
function xfr_delete_items($range) {
/*
DEVELOPMENT:
Michael Son(michaelson@nate.com)
28.Apr.2010.
DESCRIPTION:
Delete items from [xF]Referer
CALL:
xfr_delete_items("1-3,7");
RETURN:
<<RESULT OF QUERY>>
*/
$condition = xfx_cvt_ran($range);
$query = "DELETE FROM `xf_referer` WHERE ".$condition;
$result = xfx_exe_que($query);
//Return a result
return $result;
}
//Part3. Data API
//6. xfp
//6.1. Write
function xfp_write_item($status) {
/*
DEVELOPMENT:
DESCRIPTION:
CALL:
RETURN:
*/
}
//6.2. Find
function xfp_find_items($container) {
/*
DEVELOPMENT:
DESCRIPTION:
CALL:
RETURN:
*/
}
//6.3. Read
function xfp_read_item($no) {
/*
DEVELOPMENT:
DESCRIPTION:
CALL:
RETURN:
*/
}
function xfp_read_items($range) {
/*
DEVELOPMENT:
DESCRIPTION:
CALL:
RETURN:
*/
}
//6.4. Edit
function xfp_edit_item($no) {
/*
DEVELOPMENT:
DESCRIPTION:
CALL:
RETURN:
*/
}
//6.5. Delete
function xfp_delete_item($no) {
/*
DEVELOPMENT:
DESCRIPTION:
CALL:
RETURN:
*/
}
function xfp_delete_items($range) {
/*
DEVELOPMENT:
DESCRIPTION:
CALL:
RETURN:
*/
}
//7. xfs
//7.1. Write
function xfs_write_item($status) {
/*
DEVELOPMENT:
DESCRIPTION:
CALL:
RETURN:
*/
}
//7.2. Find
function xfs_find_items($container) {
/*
DEVELOPMENT:
DESCRIPTION:
CALL:
RETURN:
*/
}
//7.3. Read
function xfs_read_item($no) {
/*
DEVELOPMENT:
DESCRIPTION:
CALL:
RETURN:
*/
}
function xfs_read_items($range) {
/*
DEVELOPMENT:
DESCRIPTION:
CALL:
RETURN:
*/
}
//7.4. Edit
function xfs_edit_item($no, $status) {
/*
DEVELOPMENT:
DESCRIPTION:
CALL:
RETURN:
*/
}
//7.5. Delete
function xfs_delete_item($no) {
/*
DEVELOPMENT:
DESCRIPTION:
CALL:
RETURN:
*/
}
function xfs_delete_items($range) {
/*
DEVELOPMENT:
DESCRIPTION:
CALL:
RETURN:
*/
}
//8. xfc
//8.1. Write
function xfc_write_item($status) {
/*
DEVELOPMENT:
DESCRIPTION:
CALL:
RETURN:
*/
}
//8.2. Find
function xfc_find_items($container) {
/*
DEVELOPMENT:
DESCRIPTION:
CALL:
RETURN:
*/
}
//8.3. Read
function xfc_read_item($no) {
/*
DEVELOPMENT:
DESCRIPTION:
CALL:
RETURN:
*/
}
function xfc_read_items($range) {
/*
DEVELOPMENT:
DESCRIPTION:
CALL:
RETURN:
*/
}
//8.4. Edit
function xfc_edit_item($no, $status) {
/*
DEVELOPMENT:
DESCRIPTION:
CALL:
RETURN:
*/
}
//8.5. Delete
function xfc_delete_item($no) {
/*
DEVELOPMENT:
DESCRIPTION:
CALL:
RETURN:
*/
}
function xfc_delete_items($range) {
/*
DEVELOPMENT:
DESCRIPTION:
CALL:
RETURN:
*/
}
//9. xft
//9.1. Write
function xft_write_item($status) {
/*
DEVELOPMENT:
DESCRIPTION:
CALL:
RETURN:
*/
}
//9.2. Find
function xft_find_items($container) {
/*
DEVELOPMENT:
DESCRIPTION:
CALL:
RETURN:
*/
}
//9.3. Read
function xft_read_item($no) {
/*
DEVELOPMENT:
DESCRIPTION:
CALL:
RETURN:
*/
}
function xft_read_items($range) {
/*
DEVELOPMENT:
DESCRIPTION:
CALL:
RETURN:
*/
}
//9.4. Edit
function xft_edit_item($no, $status) {
/*
DEVELOPMENT:
DESCRIPTION:
CALL:
RETURN:
*/
}
//9.5. Delete
function xft_delete_item($no) {
/*
DEVELOPMENT:
DESCRIPTION:
CALL:
RETURN:
*/
}
function xft_delete_items($range){
/*
DEVELOPMENT:
DESCRIPTION:
CALL:
RETURN:
*/
}

'xFacility > Codes' 카테고리의 다른 글

container()  (0) 2010.06.08
xFacility^PHP > Internal API 3.0  (0) 2010.06.08
xFacility^PHP > Internal API 2.0  (0) 2010.05.17
Posted by 마이클
xFacility/Documents2010. 5. 17. 14:32
1. xFXML

xFXML이란 xFacility의 원활한 데이터 처리를 위해서 사용하는 XML형식입니다.

그 최소 형식은 다음과 같습니다.
<?xml version="1.0" encoding="utf-8" ?>

<sentences>
<sentence>
<who></who>
<how></how>
<what></what>
<where></where>
<when></when>
<why></why>
</sentence>
</sentences>

who는 사용자 고유번호 또는 xfacility를 입력합니다.
how는 읽기, 쓰기, 수정 등의 해야 할(또는 완료한) 행동을 기술합니다. 명령 결과 전송시 반환return이라 표시합니다.
what은행동의 대상을 나타냅니다. 실제적 데이터가 여기에 기술됩니다.
where는 어떠한 라이브러리에서 이러한 행동을 취할 것인지(취했는지) 나타냅니다. 데이터 내용과 관련 있습니다.
when은 언제 이러한 행동이 이뤄질 것인지(또는 이루어졌는지) 나타냅니다.
why는 이러한 행동이 취해진 까닭을 기술합니다. 오류가 발생한 경우 오류가 발생한 이유가 여기에 기술됩니다.

다음은 예제 코드입니다.
<?xml version="1.0" encoding="utf-8" ?>

<sentences>
<sentence>
<who>xfacility</who>
<how>return</how>
<what>1</what>
<where>party</where>
<when>2010May05162118</when>
<why>An error occured. xFacility cannot EDIT the item. Nothing has the NUMBER(2).</why>
</sentence>
<sentence>
<who>xfacility</who>
<how>return</how>
<what>0</what>
<where>shelf</where>
<when>2010May05162118</when>
<why></why>
</sentence>
</sentences>


2. 범위Range

특정한 대상을 숫자로 지정하기 위해 사용하는 형식입니다.
숫자(1234567890)와 콤마(,), 하이픈(-), 느낌표(!)을 통해서 나타냅니다.
인쇄 옵션에서 페이지를 지정할 때의 문법과 같습니다.

숫자는 지정할 숫자를 그대로 사용합니다.
콤마(,)는 "또는"의 의미입니다.
하이픈(-)은 "에서"의 의미입니다. 2-4인 경우 2에서 4라고 읽으며 2,3,4를 지정합니다.
'-'는 처음부터 끝까지(모든 번호를) 지정합니다.
'x-'는 x이후 모든 번호를 지정합니다.(모든 번호에서 x-1을 제외합니다.)
'-y'는 1부터 y까지의 번호를 지정합니다.
'x-y'는 x부터 y까지 지정합니다.
느낌표(!)는 "부정(NOT)"을 의미합니다. !2-4라고 쓰인경우 2,3,4를 제외하여 지정합니다.
0은 아무것도 지정하지 않습니다. NULL값으로 규정합니다.

① 처음은 반드시 숫자이어야 합니다.
② 음수는 사용 불가능합니다.
③ 제외할 번호가 있을 때에는 제외할 숫자 앞에 !를 붙입니다.

다음은 예제입니다.
1,2,3,4,5,6,7,8,9,10  //
1-10 //위와 동일합니다.
-10 //위와 동일합니다.
1,4-7,10 //1번, 4번, 5번, 6번, 7번 그리고 10번을 지정합니다.
10,7-4,1 //위와 동일합니다.
1-10,!2,!3,!8-9 //위와 동일합니다.
10- //10번 이후의 모든 번호를 지정합니다.
0 //모든 번호를 지정합니다.

범위는 아이템 번호를 지정할 때 주로 사용됩니다. 만약 2에서 5번까지의 게시물을 읽고 싶은 경우, <no>2-5</no>로 지정하면 원하는 게시물을 불러 올 수 있습니다. 또한 범위는 기존 웹보드와 달리 비연속적, 비연관적 게시물을 무제한으로 불러 올 수 있는 장점이 있습니다.

3. 그릇Container

그릇은 XML은 데이터의 부피가 크기 때문의 효과적인 데이터 공간 활용을 위해서 새로 개발한 형식입니다.
개발자들이 이 형식을 익히기 위해 노력할 필요가 없도록 최대한 C의 형식을 빌어왔으며
xFacility API를 통해서 그릇은 XML 또는 배열 변수로도 변환이 가능합니다.
배열을 위해 만들어진 형식이기 때문에 배열 데이터를 플랫폼이나 언어에 상관없이 손쉽게 작성할 수 있으며,
배열을 시각화할 수 있다는 장점이 있습니다.

앞서 xFXML의 설명을 위해 나왔던 코드를 그릇으로 옮기면 다음과 같습니다.
sentence{who=xfacility;how=return;what=1;where=xfxmlio;when=2010May05162118;why=An error occured. xFacility cannot EDIT the item. Nothing has the NUMBER(2).;}, sentence{who=xfacility;how=return;what=0;where=shelf;when=2010May05162118;why=;}

다음과 같은 것도 가능합니다.
{a{b{c{d{e{f{g{h{i:5}}}}}}}}}

//PHP
$string = "{a{b{c{d{e{f{g{h{i:5}}}}}}}}}";
$array = container($string);
//RESULT:  $array[a][b][c][d][e][f][g][h][i] = 5;

배열을 시각화할 수 있습니다.
{
a{
c{
e{
h:10;
i:1;
}
f:6;
}
d{
g:7;
}
}
b{
e:5;
}
}

= {a{c{e{h:10;i:1;}f:6;}d{g:7;}}b{e:5;}}

문법요소 사이에 있는 문자는 다음으로 인식됩니다. (배열명이 없는 경우 자동으로 배열명을 배정합니다.)
 끝         /      시작  {  =  ;  }  공백
 { 배열명   배열명 배열명 배열명
 = 배열명   배열명 배열명  배열명
 ; 값(자동배열) 값(자동배열) 값(자동배열) 값(자동배열) 
 } 값(자동배열) 값(자동배열) 값(자동배열)
 공백
값(자동배열) 값(자동배열) 값(무배열)

4. 치환자Replacer

치환자는 치환될 내용을 보관하는 XML형식입니다.
<?xml version="1.0" encoding="utf-8" ?>

<replacer>
<imageaddress>http://www.example.com/image.jpg</imageaddress>
<content>
<p>Hello World</p>
</content>
</replacer>

이와 같은 내용을 xFacility API를 통해 제공하는 replacer()함수를 이용하면 %치환변수명% 자리에 해당 내용이 바뀌어 들어갑니다.

만약 치환변수가 있는 원본 파일의 내용이 다음과 같다면,
<html>
<head>
<title>Test</title>
</head>
<body>
<img src="%imageaddress%" />
%content%
</body>
</html>

replacer()함수의 처리를 거친 뒤에는 다음과 같이 변환됩니다.
<html>
<head>
<title>Test</title>
</head>
<body>
<img src="http://www.example.com/image.jpg" />
<p>Hello World</p>
</body>
</html>

'xFacility > Documents' 카테고리의 다른 글

xFacility Data Form데이터 형식  (0) 2010.10.20
xf_language 변수  (0) 2010.08.23
xFacility 변수 규칙  (0) 2010.08.07
문장 구조  (0) 2010.06.29
처리Process  (0) 2010.05.16
Posted by 마이클