2019-05-25 17:02:45 +00:00
|
|
|
<?php
|
2019-05-25 17:16:24 +00:00
|
|
|
/**
|
2019-05-27 08:15:28 +00:00
|
|
|
* @file catsplit.format.php
|
2019-05-25 17:16:24 +00:00
|
|
|
* @date 2019-05-28
|
|
|
|
* @author Go Namhyeon <gnh1201@gmail.com>
|
2019-05-27 08:15:28 +00:00
|
|
|
* @brief Catsplit format encoder
|
|
|
|
* @documentation https://github.com/gnh1201/catsplit-format
|
2019-05-25 17:16:24 +00:00
|
|
|
*/
|
2019-05-25 17:02:45 +00:00
|
|
|
|
2019-06-06 03:57:40 +00:00
|
|
|
if(!check_function_exists("catsplit_unescape")) {
|
|
|
|
function catsplit_unescape($data) {
|
|
|
|
return trim($data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!check_function_exists("casplit_escape")) {
|
|
|
|
function casplit_escape($data) {
|
|
|
|
return htmlspecialchars($data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-27 08:15:28 +00:00
|
|
|
if(!check_function_exists("catsplit_encode")) {
|
|
|
|
function catsplit_encode($data) {
|
2019-05-25 17:04:29 +00:00
|
|
|
$_ks = array();
|
|
|
|
$_vs = array();
|
|
|
|
foreach($data as $k=>$v) {
|
|
|
|
$_ks[] = $k;
|
|
|
|
$_vs[] = make_safe_argument($v);
|
|
|
|
}
|
2019-06-06 03:57:40 +00:00
|
|
|
$_ks = array_map("casplit_escape", $_ks);
|
|
|
|
$_vs = array_map("casplit_escape", $_vs);
|
2019-05-25 17:24:10 +00:00
|
|
|
return sprintf("('%s')<=(%s)", implode("','", $_vs), implode(",", $_ks));
|
2019-05-25 17:02:45 +00:00
|
|
|
}
|
|
|
|
}
|
2019-06-01 05:35:34 +00:00
|
|
|
|
|
|
|
if(!check_function_exists("catsplit_decode")) {
|
2019-06-01 10:51:47 +00:00
|
|
|
function catsplit_decode($data) {
|
2019-06-01 05:35:34 +00:00
|
|
|
$s_final = array();
|
|
|
|
|
|
|
|
// step 1
|
|
|
|
$s1 = explode(")<=(", substr($data, 1, -1));
|
|
|
|
|
|
|
|
// step 2
|
2019-06-06 03:57:40 +00:00
|
|
|
$s2a = array_map("catsplit_unescape", explode(",", $s1[0]));
|
|
|
|
$s2b = array_map("catsplit_unescape", explode(",", $s1[1]));
|
2019-06-01 05:35:34 +00:00
|
|
|
|
|
|
|
// step 3
|
|
|
|
$s3 = array_combine($s2b, $s2a);
|
|
|
|
|
|
|
|
// step 4
|
|
|
|
foreach($s3 as $k=>$v) {
|
|
|
|
$s_final[$k] = substr(stripslashes($v), 1, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $s_final;
|
|
|
|
}
|
|
|
|
}
|