'xFacility/Codes'에 해당되는 글 4건

  1. 2010.06.08 container()
  2. 2010.06.08 xFacility^PHP > Internal API 3.0
  3. 2010.05.17 xFacility^PHP > Internal API 2.0
  4. 2010.05.17 xFacility^PHP > Internal API 1.0
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 마이클