'2010/05'에 해당되는 글 8건

  1. 2010.05.30 파일 읽기 함수
  2. 2010.05.30 CSS 초기화 1
  3. 2010.05.30 PHP 자바스크립트 경고 함수
  4. 2010.05.29 가운데 정렬
  5. 2010.05.17 xFacility^PHP > Internal API 2.0
  6. 2010.05.17 xFacility^PHP > Internal API 1.0
  7. 2010.05.17 데이터 형식
  8. 2010.05.16 처리Process
WebApp/PHP2010. 5. 30. 13:29
function load_file ($filepath) {
$data = implode("", file($filepath));

return $data;
}

파일의 내용을 리턴합니다.

Implode와 file함수를 엮어쓰기 귀찮은 분들을 위한 최적의 함수

'WebApp > PHP' 카테고리의 다른 글

다차원배열의 구성  (0) 2010.06.26
array_merge()  (0) 2010.06.25
Form과 Input 태그로 배열 넘기기  (0) 2010.06.24
파일 경로 숨긴 채로 전송 및 다운로드하기  (0) 2010.06.07
PHP 자바스크립트 경고 함수  (0) 2010.05.30
Posted by 마이클
WebApp/CSS2010. 5. 30. 13:19
body, div, dl, dt, dd, ul, ol, li, hq, h2, h3, h4, h5, h6, pre, form, fieldset, input, p, blockquote, th, td {
margin: 0;
padding: 0;
}
h1, h2, h3, h4, h5, h6 {
font-size: 100%;
}
ol, ul {
list-style: none;
}
address, caption, cite, code, dfn, em, strong, th, var {
font-style: normal;
font-weight: normal;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
fieldset, img {
border: 0;
}
caption, th {
text-align: left;
}
q:before, q:after {
content: '';
}

CSS의 브라우저 기본 값을 초기화하는 코드입니다.

CSS 파일로 하나 만들어서, 가져오기Import해서 사용하시면 편리합니다.

'WebApp > CSS' 카테고리의 다른 글

PNG FIX  (0) 2010.09.27
가운데 정렬  (0) 2010.05.29
Posted by 마이클
WebApp/PHP2010. 5. 30. 12:58
function alert($message) {
echo "<script type='text/javascript'>\n";
echo "<!--\n";
    echo "alert('$message');\n";
    echo "// -->\n";
echo "</script>\n";
return 0;
}

자바스크립트 경고 창으로 메시지를 띄우는 함수입니다.

'WebApp > PHP' 카테고리의 다른 글

다차원배열의 구성  (0) 2010.06.26
array_merge()  (0) 2010.06.25
Form과 Input 태그로 배열 넘기기  (0) 2010.06.24
파일 경로 숨긴 채로 전송 및 다운로드하기  (0) 2010.06.07
파일 읽기 함수  (0) 2010.05.30
Posted by 마이클
WebApp/CSS2010. 5. 29. 12:34
body {
position: relative;
width: 1000px;
left: 50%;
margin: 0 0 0 -500px;
}

또는

body {
position: relative;
width: 1000px;
margin: 0 auto;
}
눈으로도 보이시겠지만 아래 소스가 더 간단합니다. ^-^


작동여부
IE6 IE7 IE8 Firefox3.6 Google Chrome5 Safari4 
미실험 미실험 O O O O

실제 화면

'WebApp > CSS' 카테고리의 다른 글

PNG FIX  (0) 2010.09.27
CSS 초기화  (1) 2010.05.30
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 마이클
xFacility/Documents2010. 5. 16. 21:20
1. 처리 구조



2. 처리 단계

① 최종 사용자가 xFacility Application을 실행
② xFacility Application은 최종 사용자의 컴퓨터에게 xFacility 서버 정보와 xFXML 처리 프로그램(JavaScript 등) 제공
③ 최종 사용자의 컴퓨터는 xFacility 서버로 xFXML을 통해 자료 요청
④ xFacility 서버는 xFXML을 실행하고 그 결과를 다시 xFXML로 최종 사용자에게 전송
⑤ 최종 사용자의 컴퓨터는 그 결과 값을 App 화면에 뿌림

'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 마이클