代码拉取完成,页面将自动刷新
import CBOpenSSL.code
import lib/consoleprocess
import lib/http
import lib/os
var INPUT_POST_ = 0;
var INPUT_GET_ = 1;
var INPUT_COOKIE = 2;
var INPUT_ENV = 4;
var INPUT_SERVER = 5;
var INPUT_SESSION = 6;
var INPUT_REQUEST = 99;
var FILTER_FLAG_NONE = 0;
var FILTER_REQUIRE_SCALAR = 33554432;
var FILTER_REQUIRE_ARRAY = 16777216;
var FILTER_FORCE_ARRAY = 67108864;
var FILTER_NULL_ON_FAILURE = 134217728;
var FILTER_VALIDATE_INT = 257;
var FILTER_VALIDATE_BOOLEAN = 258;
var FILTER_VALIDATE_FLOAT = 259;
var FILTER_VALIDATE_REGEXP = 272;
var FILTER_VALIDATE_URL = 273;
var FILTER_VALIDATE_DOMAIN = 277;
var FILTER_VALIDATE_EMAIL = 274;
var FILTER_VALIDATE_IP = 275;
var FILTER_VALIDATE_MAC = 276;
var FILTER_DEFAULT = 516;
var FILTER_UNSAFE_RAW = 516;
var FILTER_SANITIZE_STRING = 513;
var FILTER_SANITIZE_STRIPPED = 513;
var FILTER_SANITIZE_ENCODED = 514;
var FILTER_SANITIZE_SPECIAL_CHARS = 515;
var FILTER_SANITIZE_FULL_SPECIAL_CHARS = 522;
var FILTER_SANITIZE_EMAIL = 517;
var FILTER_SANITIZE_URL = 518;
var FILTER_SANITIZE_NUMBER_INT = 519;
var FILTER_SANITIZE_NUMBER_FLOAT = 520;
var FILTER_SANITIZE_MAGIC_QUOTES = 521;
var FILTER_SANITIZE_ADD_SLASHES = 523;
var FILTER_CALLBACK = 1024;
var FILTER_FLAG_ALLOW_OCTAL = 1;
var FILTER_FLAG_ALLOW_HEX = 2;
var FILTER_FLAG_STRIP_LOW = 4;
var FILTER_FLAG_STRIP_HIGH = 8;
var FILTER_FLAG_STRIP_BACKTICK = 512;
var FILTER_FLAG_ENCODE_LOW = 16;
var FILTER_FLAG_ENCODE_HIGH = 32;
var FILTER_FLAG_ENCODE_AMP = 64;
var FILTER_FLAG_NO_ENCODE_QUOTES = 128;
var FILTER_FLAG_EMPTY_STRING_NULL = 256;
var FILTER_FLAG_ALLOW_FRACTION = 4096;
var FILTER_FLAG_ALLOW_THOUSAND = 8192;
var FILTER_FLAG_ALLOW_SCIENTIFIC = 16384;
var FILTER_FLAG_PATH_REQUIRED = 262144;
var FILTER_FLAG_QUERY_REQUIRED = 524288;
var FILTER_FLAG_SCHEME_REQUIRED = 65536;
var FILTER_FLAG_HOST_REQUIRED = 131072;
var FILTER_FLAG_HOSTNAME = 1048576;
var FILTER_FLAG_IPV4 = 1048576;
var FILTER_FLAG_IPV6 = 2097152;
var FILTER_FLAG_NO_RES_RANGE = 4194304;
var FILTER_FLAG_NO_PRIV_RANGE = 8388608;
var FILTER_FLAG_EMAIL_UNICODE = 1048576;
var FILE_APPEND = 8;
var PHP_INT_MAX = 9223372036854775807;
var DIRECTORY_SEPARATOR = php::chose(php::isWin(), "\\", "/" );
module php{
/**
* 打乱数组
* @author CBrother's community
*/
function shuffle(array) {
// 判断是否为数组
var type = CBType(array);
if (type == "Array") {
var size = array.size();
for (var i = 0; i < size; i++) {
// 从 i 到最后随机选一个元素
var rand = Rand(i, size - 1);
// 没有swap()交换变量函数,这里用变量代替
// 当前值
var currentVal = array[i];
// 随机位置值
var randVal = array[rand];
// 交换变量
array[i] = randVal;
array[rand] = currentVal;
}
return array;
}
return false;
}
/**
* 截取数组
* @author CBrother's community
*/
function array_slice(array, offset, length) {
if (offset == null) {
offset = 0;
}
if (length == null) {
length = array.size();
if(offset == 0){
var tmpArray = new Array();
if(array && array.size()){
foreach (k,v : array) {
tmpArray.add(v);
}
}
return tmpArray;
}
}
if (offset == 0 && length == 0){
return [];
}
// 判断是否为数组
var type = CBType(array);
if (type == "Array") {
var size = array.size();
offset = chose(offset < 0, size + offset, offset);
length = chose(length == 0, 0, length);
length = chose(length < 0, size + length - offset, length);
var newArray = [];
var start = false;
var thisIndex = -1;
var arraylength = 0;
foreach(key, value: array) {
++thisIndex;
if (arraylength >= length) {
break;
}
if (thisIndex == offset) {
start = true;
}
if (!start) {
continue;
}
++arraylength;
newArray.add(array[key]);
}
return newArray;
}
return false;
}
/**
* 翻转数组,以相反的元素顺序返回数组。
* @author CBrother's community
*/
function array_reverse(array) {
var type = CBType(array);
var list = new List();
if (type == "Array") {
foreach(k, v: array) {
list.addFirst(v);
}
var result = new Array();
foreach(k, v: list) {
result.add(v);
}
return result;
}
return false;
}
/**
* 在数组中搜索某个键值,并返回对应的键名。
* @author CBrother's community
*/
function array_search(value, array) {
foreach(k, v: array) {
if (v == value) {
return k;
}
}
return false;
}
/**
* 计算数组的和
* @author CBrother's community
*/
function array_sum(array) {
var result = 0;
foreach(k, v: array) {
result += FLOAT(v);
}
return result;
}
/**
* 对map中的每个元素应用用户自定义函数
* @author CBrother's community
*/
function array_walk(array, func) {
var type = CBType(array);
if (func == null || type != "Map") {
return false;
}
foreach(k, v: array) {
func.invoke(v, k);
}
}
/**
* 把2个数组合并为一个数组。
* @author CBrother's community
*/
function array_merge(array1, array2) {
var array1Type = CBType(array1);
var array2Type = CBType(array2);
if (array1Type == "Map" || array2Type == "Map") {
var result = {};
foreach(k, v: array1) {
result[k] = v;
}
foreach(k, v: array2) {
result[k] = v;
}
return result;
}
var result = [];
foreach(k, v: array1) {
result.add(v);
}
foreach(k, v: array2) {
result.add(v);
}
return result;
}
/**
* 递归地合并一个或多个数组
* 该函数与 array_merge() 函数的区别在于处理两个数组元素有相同的键名时。不会进行键名覆盖,而是将多个相同键名的值递归组成一个数组。
* @author CBrother's community
*/
function array_merge_recursive(array1, array2) {
var array1Type = CBType(array1);
var array2Type = CBType(array2);
if (array1Type == "Map" || array2Type == "Map") {
var result = {};
foreach(k, v: array1) {
result[k] = v;
}
foreach(k, v: array2) {
if (result[k] != null) {
result[k] = [result[k], v];
} else {
result[k] = v;
}
}
return result;
}
var result = [];
foreach(k, v: array1) {
result.add(v);
}
foreach(k, v: array2) {
result.add(v);
}
return result;
}
/**
* 使用用户自定义函数来改变数组的值
* @author CBrother's community
*/
function array_map(func, array) {
foreach(k, v: array) {
array[k] = func.invoke(v);
}
return array;
}
/**
* 取array,map 所有键值
* value可选,您可以指定键值,然后只有该键值对应的键名会被返回
* @author CBrother's community
*/
function array_keys(array, value) {
var result = [];
foreach(k, v: array) {
if (value != null) {
if (value == v) {
result.add(k);
}
} else {
result.add(k);
}
}
return result;
}
/**
* 交换map的键和值
* @author CBrother's community
*/
function array_flip(array) {
var arrayType = CBType(array);
if (arrayType != "Map") {
return false;
}
var result = {};
foreach(k, v: array) {
result[v] = k;
}
return result;
}
/**
* 返回输入数组中某个单一列的值
* @author CBrother's community
*/
function array_column(array, column_key) {
var arrayType = CBType(array);
if (arrayType != "Array" || empty(column_key)) {
return false;
}
var result = [];
for (var i = 0; i < array.size(); i++) {
result.add(array[i][column_key]);
}
return result;
}
/**
* 用于统计数组中所有值出现的次数
* @author CBrother's community
*/
function array_count_values(array) {
if (empty(array)) {
return false;
}
var map = new Map();
for (var i = 0; i < array.size(); i++) {
if (map[array[i]] == null) {
map[array[i]] = 1;
} else {
map[array[i]]++;
}
}
return map;
}
/**
* 通过合并两个数组来创建一个map,其中的一个数组是键名,另一个数组的值为键值。
* @author CBrother's community
*/
function array_combine(keys, values) {
if (empty(keys) || empty(values) || keys.size() != values.size()) {
return false;
}
var result = new Map();
for (var i = 0; i < keys.size(); i++) {
result.add(keys[i], values[i]);
}
return result;
}
/**
* 把数组进行平均分割
* @author CBrother's community
*/
function array_chunk(array, size) {
var arrayType = CBType(array);
if (arrayType != "Array") {
return null;
}
var lenght = array.size();
if (size < 1) {
return null;
}
var i = 0;
var j = -1;
var result = [];
while (i < lenght) {
var remain = i % size;
if (remain) {
result[j].insert(remain, array[i]);
} else {
++j;
result.insert(j, [array[i]]);
}
i++;
}
return result;
}
//
/**
* 将数组的所有的键都转换为大写字母或小写字母
* @author CBrother's community
*/
function array_change_key_case(array, caseType) {
var arrayType = CBType(array);
if (arrayType == "Array") {
return array;
}
caseType = chose(caseType != 0 && caseType != null, 1, 0);
var result = {};
foreach(k, v: array) {
result[chose(caseType == 0, strlower(k), strupper(k))] = v;
}
return result;
}
/**
* 默认过滤函数,判断值是否为空
* @author CBrother's community
*/
function _func(v) {
return chose(empty(v), false, v);
}
/**
* 用回调函数过滤数组中的元素。
* @author CBrother's community
*/
function array_filter(arr, func) {
// 判断使用用户函数,还是内置函数
var funcFilter = chose(func == null, _func, func);
foreach(k, v: arr) {
if (!funcFilter.invoke(v)) {
foreach_del;
}
}
return arr;
}
/**
* 数组去重复
* @author CBrother's community
*/
function array_unique(array) {
var myMap = new Map();
var result = [];
for (var i = 0; i < array.size(); i++) {
if (myMap.get(array[i]) != true) {
myMap.set(array[i], true);
result.add(array[i]);
}
}
return result;
}
function array_values(var1){
if(!is_array(var1) && !is_map(var1) ) throw("MyException","array_values():Parameter \"var1\" must to be an array or a map type");
if(is_array(var1)) return var1;
else {
var newArr = [];
foreach (k,v : var1)
{
newArr.add(v);
}
return newArr;
}
}
function array_fill(index, number, value){
if(is_numeric(index)) index = INT(index);
if(is_numeric(number)) number = INT(number);
if(!is_int(index)) throw ("MyException", "array_fill() parameter \"index\" must to be a intger type");
if(!is_int(number)) throw ("MyException", "array_fill() parameter \"number\" must to be a intger type");
if(index < 0) throw ("MyException", "array_fill() parameter \"index\" can't be less than 0");
if(number < 0) throw ("MyException", "array_fill() parameter \"number\" can't be less than 0");
var arr = [];
for(var i =0;i<(index + number); i++){
if(i < index) arr.add(null);
else {
if(is_array(value)){
var tmpValue = [];
foreach (k,v : value) {
tmpValue.add(v);
}
arr.add(tmpValue);
}else if( is_map(value)){
var tmpValue = {};
foreach (k,v : value) {
tmpValue.set(k,v);
}
arr.add(tmpValue);
}else{
arr.add(value);
}
}
}
if(index>0)
for(var i =index-1; i>=0; i--){
arr.remove(i);
}
return arr;
}
/**
* 判断变量是否为空
* @author CBrother's community
*/
function empty(mixedVar) {
var type = CBType(mixedVar);
var arrayMap = {
"Array": 1,
"Map": 1,
"List": 1
};
if(!mixedVar || (mixedVar && mixedVar == "")) return true;
if (arrayMap[type] == 1 && mixedVar.size() == 0) {
return true;
}
var emptyValues = [null, false, 0, "", '0'];
for (var i = 0; i < emptyValues.size(); i++) {
if (mixedVar == emptyValues[i]) {
return true;
}
}
return false;
}
/**
* 日期格式化函数
* 没有支持全部format关键字
* @author CBrother's community
*/
function date(format, timestamp) {
if (format == null) {
format = "Y-m-d H:i:s";
}
if (timestamp == null) {
var time = new Time(); //不传参数表示获取当前时间初始化Time类
} else {
var time = new Time(INT(timestamp)); //传入时间戳(秒),则用时间戳初始化Time类
}
var map = {
"Y": "%Y", // 年,四位数字
"y": "%y", // 年,两位数字
"m": "%m", // 月份,两位数字,从"01"至"12"
"d": "%d", // 几日,两位数字,若不足则补零;从"01"至"31"
"H": "%H", // 24小时制的小时,从"00"至"23"
"h": "%I", // 12小时制的小时,从"01"至"12"
"i": "%M", // 分钟数(00-59)
"s": "%S", // 秒(00-59)
"D": "%a", // 星期几,3个英文字母,如:"Fri"
"l": "%A" // 星期几,本地完整星期名称
};
foreach(k, v: map) {
format = strreplace(format, k, v);
}
return time.strftime(format);
}
/**
* 模拟三元表达式
* @author CBrother's community
* @param mixed var1
* @param mixed var2
* @return bool
*/
function chose(condition, var1, var2) {
if (condition) {
return var1;
}
return var2;
}
/**
* 打印变量,跟dump功能一样
* @author CBrother's community
*/
function print_r(mixedExpression) {
dump.invoke(mixedExpression);
}
/**
* 打印变量,跟dump功能一样
* @author CBrother's community
*/
function var_dump(mixedExpression) {
dump.invoke(mixedExpression);
}
/**
* 打印变量
* @author CBrother's community
*/
function dump(mixedExpression, tips) {
if (tips != null) {
print "------" + tips + "------";
}
var result = varExport(mixedExpression);
print result;
}
/**
* 将变量转换为结构信息
* @author CBrother's community
*/
function varExport(mixedExpression, idtLevel) {
var idtLevel = chose(idtLevel == null, 2, idtLevel);
var cnt = 0;
var retstr = "";
var iret = "";
var value;
var innerIndent = "";
var outerIndent = "";
var x = [];
var type = CBType(mixedExpression);
switch (type) {
case "null": {
retstr = "null";
break;
}
case "string": {
retstr = "\"" + mixedExpression + "\"";
break;
}
case "bool": {
// 模拟三元表达式
retstr = chose(mixedExpression, "true", "false");
break;
}
case "Array": {
outerIndent = _makeIndent(idtLevel - 2);
innerIndent = _makeIndent(idtLevel);
for (var i = 0; i < mixedExpression.size(); i++) {
value = " ";
value += varExport(mixedExpression[i], idtLevel + 2);
x.add(innerIndent + "[" + i + "] =>" + value);
}
if (x.size() > 0) {
iret = strjoin(x, ",\n") + "\n";
}
retstr = outerIndent + "Array(" + x.size() + ") [\n" + iret + outerIndent + "]";
break;
}
case "Map": {
outerIndent = _makeIndent(idtLevel - 2);
innerIndent = _makeIndent(idtLevel);
foreach(k, v: mixedExpression) {
value = " ";
value += varExport(v, idtLevel + 2);
x.add(innerIndent + "\"" + k + "\" :" + value);
}
if (x.size() > 0) {
iret = strjoin(x, ",\n") + "\n";
}
retstr = outerIndent + "Map {\n" + iret + outerIndent + "}";
break;
}
default: {
//retstr = "不支持查看:" + type + "类型";
retstr = STRING(mixedExpression);
break;
}
}
return retstr;
}
/**
* 生成缩进字符
* @author CBrother's community
*/
function _makeIndent(idtLevel) {
var arr = new Array();
for (var i = 0; i < idtLevel; i++) {
arr.add("");
}
return strjoin(arr, " ");
}
/**
* @param string str
* @return string str
*/
function trim(str, charlist){
if(!str || (str && str == "")) return "";
var regex = new RegEx("(^\s+)|(\s+$)","gi");
if(!empty(charlist)) str = strreplace(str,charlist,"");
return regex.replace(str,"");
}
function isset(var1){
if(var1 != null ) return true;
return false;
}
function explode(delims, str, limit = null){
if(!is_string(str)) throw ("MyExcetion", "Parameter \"str\" must to be a string!");
if(!is_string(delims)) throw ("MyExcetion", "Parameter \"delims\" must to be a string!");
if(!(is_null(limit) || is_int(limit))) throw ("MyExcetion", "Parameter \"limit\" must to be a numeric or null!");
if(str == "") return [];
var returnData = new Array();
if(is_int(limit) && (limit == 0 || limit == 1)){
returnData = [str];
} else if(delims == ""){
var len = strlen(str);
var byteArray = new ByteArray();
byteArray.writeString(str);
for(var i = 0; i < len; i++){
returnData.add(chr(byteArray.getByte(i)));
}
byteArray.clear();
}else {
returnData = strsplit(str,delims);
}
if(is_int(limit) && limit != 0 && limit != 1 && returnData && returnData.size()){
var realLimit = limit;
var returnDataLen = returnData.size();
if(math::abs(limit) > returnDataLen ) {
realLimit = returnDataLen;
if(limit < 0) realLimit = 0 - realLimit;
}
if(limit < 0){
for(var i =0; i < math::abs(limit); i++){
array_pop(returnData);
}
}else{
var newReturnData = [];
for(var i=0; i < realLimit; i++){
if(i == realLimit - 1){
var tmpLastItem = "";
var tmpDelims;
for(var j = i; j < returnDataLen; j++){
tmpDelims = chose(j == i,"", delims);
tmpLastItem += tmpDelims + returnData[j];
}
newReturnData.add(tmpLastItem);
}else{
newReturnData.add(returnData[i]);
}
}
return newReturnData;
}
}
return returnData;
}
function iconv($in_charset, $out_charset, $str){
return str_convert($str, $in_charset, $out_charset);
}
function is_numeric(var1) {
var regEx = new RegEx("^[0-9.]+$");
if(is_int(var1) || is_uint(var1) || is_long(var1) || is_float(var1) || regEx.match(var1)) return true;
return false;
}
function is_int(var1) {
if(CBType(var1) == "int") return true;
return false;
}
function is_uint(var1) {
if(CBType(var1) == "uint") return true;
return false;
}
function is_long(var1) {
if(CBType(var1) == "long") return true;
return false;
}
function is_float(var1) {
if(CBType(var1) == "float") return true;
return false;
}
function is_integer(var1) {
return is_int(var1);
}
function is_string(str){
if(str == null) return false;
if(strlower(CBType(str)) != "string") return false;
return true;
}
function substr(str, start ,length){
start = INT(start);
length = INT(length);
if(is_numeric(str)) str = STRING(str);
if(!is_string(str)) throw ("MyException", "substr() parameter \"str\" must to be a string type");
var getStrLen = strlen(str);
if(!getStrLen) return "";
if(length) {
if(start < 0){
var startAbs = math::abs(start);
if(getStrLen > startAbs){
start = getStrLen - startAbs;
}else {
start = 0;
}
}
var end = start + length;
if(end > getStrLen) end = getStrLen;
return strget(str,start,end);
}else{
return strget(str,start);
}
}
function strpos(str, findStr, idx =0){
return strfind(str, findStr, idx);
}
function stripos(str, findStr, idx =0){
return strifind(str, findStr, idx);
}
function strrpos(str, findStr, idx =0){
return strrfind(str, findStr, idx);
}
function strripos(str, findStr, idx =0){
return strirfind(str, findStr, idx);
}
/**
* 搜索字符串在另一字符串中是否存在
* @param string 被搜索的字符串。
* @param string 要搜索的字符串。
* @param string 一个默认值为 "false" 的布尔值。如果设置为 "true",它将返回 search 参数第一次出现之前的字符串部分。
*/
function strstr(str, findStr, before_search = false){
var index = strpos(str, findStr);
if(before_search){
return substr(str, index, strlen(findStr));
}else{
return substr(str, index);
}
}
function lcfirst(str){
if(!is_string(str)) throw ("MyException", "lcfirst() parameter \"str\" must to be a string type");
if(str =="") return str;
var byteArray = new ByteArray();
byteArray.writeString(str);
var ascll = byteArray.getByte(0);
if(ascll >=65 && ascll <=90){
ascll = ascll + 32;
byteArray.setByte(0, ascll);
var str = byteArray.readString();
return str;
}
return str;
}
function ucfirst(str){
if(!is_string(str)) throw ("MyException", "ucfirst() parameter \"str\" must to be a string type");
if(str =="") return str;
var byteArray = new ByteArray();
byteArray.writeString(str);
var ascll = byteArray.getByte(0);
if(ascll >=97 && ascll <=122){
ascll = ascll - 32;
byteArray.setByte(0, ascll);
var str = byteArray.readString();
return str;
}
return str;
}
function str_split(str, length = 1){
if(!is_string(str)) throw ("MyException", "str_split() parameter \"str\" must to be a string type");
if(!is_int(length)) throw ("MyException", "str_split() parameter \"length\" must to be a intger type");
length = INT(length);
if(length < 1) length = 1;
if(str == "") return [""];
var len = strlen(str);
var byteArray = new ByteArray();
var returnData = [];
byteArray.writeString(str);
for(var i = 0; i < len; i=i-0){
var tmpItem = "";
for (var j = 0; j<length; j++){
tmpItem += chr(byteArray.getByte(i++));
if(i >= len) break;
}
returnData.add(tmpItem);
}
byteArray.clear();
return returnData;
}
function hash_hmac($type, $string_to_sign, $accessKeySecret, output){
// output = true;
if($type == "sha1"){
return openssl_hmac_sha1($accessKeySecret,$string_to_sign);
}
throw ("MyException", "hash_hmac not support " + $type);
}
function is_array(arr){
if(arr == null) return false;
if(strlower(CBType(arr)) != "array") return false;
return true;
}
function is_map(map){
if(map == null) return false;
if(strlower(CBType(map)) != "map") return false;
return true;
}
function is_null(var1){
if(var1 == null) return true;
return false;
}
function is_resource(fileOpen){
if(CBType(fileOpen) == "File") return true;
return false;
}
function isWin(){
return os::systemName() == "windows";
}
function file_exists(filePath){
if(empty(filePath)) throw ("MyException", "file_exists function parameter \"filePath\" is not allow empty!");
return os::access(filePath);
// var myFile = new File("C:/aaa.txt","r");
// return myFile.exists();
}
function fileInfo(filePath){
var fileExists = file_exists(trim(filePath));
if(!fileExists) throw ("MyException", filePath + " not exists!");
return os::stat(filePath);
}
function filesize(filePath){
var info = fileInfo(filePath);
return info.size;
}
function mime_content_type(path){
path = trim(path);
if(empty(path)) throw ("MyException", "mime_content_type function parameter \"Path\" is not allow empty!");
if(!file_exists(path)) throw ("MyException", path + " not exists!");
var console = new ConsoleProcess();
console.start();
console.write("file -i -b " + path);
console.write("\n");
var str = console.read();
console.closeProcess();
str = chose(str, trim(str), "");
if(str){
str = explode(";",str);
if(empty(str)) return null;
if(str.size()) return str[0];
return "";
}
return str;
}
function file_get_contents(path){
path = trim(path);
if(empty(path)) throw ("MyException", "file_get_contents function parameter \"Path\" is not allow empty!");
var path_ = strget(path,0,8);
var isUrl = false;
if(path_){
var regex = new RegEx("^(http://.*){1}|(https://){1}","ib");
isUrl = regex.match(path_);
}
if(isUrl){
var myReq = new HttpClientRequest();
myReq.setMethod("GET");
myReq.setUrl(path);
var myRes = myReq.flush();
// print myRes.getStatus();
return myRes.getData();
} else if(file_exists(path)){
var myfileR = new File(path,"rb");
var size = myfileR.size();
var data = myfileR.read(size);
myfileR.close();
return data;
}else{
throw ("MyException", path + " not exists!");
}
}
function file_put_contents(path, content, flags = 0){
path = trim(path);
if(empty(path)) throw ("MyException", "file_get_contents function parameter \"Path\" is not allow empty!");
// if(!file_exists(path)) throw ("MyException", path + " not exists!");
var mode = "wb";
if(flags == FILE_APPEND) mode = "ab+";
var myFileW = new File(path, mode);
if(CBType(content) == "ByteArray"){
var tmpSize = content.getSize();
if(tmpSize){
var enter = php::ord("\n");
content.setByte(tmpSize, enter);
}
myFileW.writeBytes(content);
}else{
myFileW.write(content + "\n");
}
myFileW.flush();
myFileW.close();
return true;
// var myFileW = new File("D:\\Downloads\\zte_bbs_copy.sql","wb");
}
function end(arr){
if(!arr) return null;
if(arr && !arr.size()) return null;
return arr[(arr.size()-1)];
}
function current(arr){
if(!arr) return null;
if(arr && !arr.size()) return null;
return arr[0];
}
function ord(char){
if(!is_string(char)) return 0;
else if(strascii(char,0) == '\\' && strascii(char,1) == 'x')
{
return INT("0x"+strget(char,2));
}
else if(strascii(char,0) == '0' && strascii(char,1) == 'x')
{
return INT(char);
}
return strascii(char,0);
}
function chr(var1){
if(!is_int(var1)) return null;
var1 = INT(var1);
var byteArray = new ByteArray();
byteArray.setByte(0, var1);
var str = byteArray.readString();
byteArray.clear();
return str;
}
/**
* 判断某个值是否在数组内
* @author CBrother's community
*/
function in_array(value, array) {
foreach(k, v: array) {
if (v == value) {
return true;
}
}
return false;
}
function count(array){
if(is_array(array)) return array.size();
}
function copyMap(map){
var mapNew = {};
if(map.size()){
foreach (k,v : map)
{
mapNew.set(k,v);
}
}
return mapNew;
}
function getMapKeys(map){
var keys = [];
foreach (k,v : map) {
keys.add(k);
}
return keys;
}
function getMapValues(map){
var values = [];
foreach (k,v : map) {
values.add(v);
}
return values;
}
function map_keys(map){
return getMapKeys(map);
}
function map_values(map){
return getMapValues(map);
}
function bateArrayCmp(arr1, arr2){
var arr1Len = arr1.size();
var arr2Len = arr2.size();
if(arr1Len && !arr2Len) return 1;
if(!arr1Len && arr2Len) return -1;
// print arr1Len + " "+arr2Len;
for(var i =0; i < arr1Len; i++){
if(arr1Len >= arr2Len ){
var tmpRes = arr1[i] - arr2[i];
if (tmpRes == 0 && i != arr2Len-1) continue;
else if(tmpRes == 0) return 1;
else if(tmpRes <0 && arr1Len > arr2Len && i+1 == arr2Len && arr1[i+1]>=48 && arr1[i+1]<=57 && arr2[i]>=48 && arr2[i]<=57 ){
if(arr1[i] != 48) tmpRes = 1;
}
return tmpRes;
}else{
if(i < arr2Len){
var tmpRes = arr1[i] - arr2[i];
if(tmpRes == 0 && i != arr1Len-1) continue;
else if(tmpRes == 0) return -1;
// else if(tmpRes >0 && arr1[i]>=48 && arr1[i]<=57 && arr2[i+1]>=48 && arr2[i+1]<=57 ){
// tmpRes = -1;
// }
return tmpRes;
}
}
}
}
/**
* @param Map map
* @param string|null sortType
* @param bool|null sortNature
*/
function sortPosReset(map, sortType, sortNature){
if(!map || ( map && !map.size())) return [];
if(empty(sortType)) sortType = "asc";
var keysArr = getMapKeys(map);
var keysLen = keysArr.size();
var keyMapOfBateArray = {};
if(keysLen == 1) return keysArr;
if(sortNature){
for(var i =0; i<keysLen; i++){
var tmpArr = [];
var tmpLen = strlen(keysArr[i]);
var byteArray = new ByteArray();
byteArray.writeString(keysArr[i]);
for(var j = 0; j < tmpLen; j++){
tmpArr.add( byteArray.getByte(j) );
}
keyMapOfBateArray.add(keysArr[i], tmpArr);
}
// dump(keyMapOfBateArray);
}
for(var i =0; i<keysLen; i++){
for(var j =i; j<keysLen; j++){
if(j == i) continue;
var changePos = false;
switch (sortType) {
case "asc": {
if(sortNature){
var BateArray_i = keyMapOfBateArray[ keysArr[i] ];
var BateArray_j = keyMapOfBateArray[ keysArr[j] ];
var cmpRes = bateArrayCmp(BateArray_i, BateArray_j);
if(cmpRes > 0) changePos = true;
} else if(stricmp(keysArr[j], keysArr[i]) < 0 ) {
changePos = true;
}
break;
}
case "desc": {
if(sortNature){
} else if(stricmp(keysArr[i], keysArr[j]) < 0 ) {
changePos = true;
}
break;
}
default: {
throw ("MyException", "sort function not support “" + sortType + "”");
break;
}
}
if(changePos){
var tmp = keysArr[i];
keysArr[i] = keysArr[j];
keysArr[j] = tmp;
}
}
}
map.clear();
keyMapOfBateArray.clear();
return keysArr;
}
function ksort(map){
return sortPosReset(map);
}
function krsort(map){
return sortPosReset(map, "desc");
}
function uksort_nature(map){
var map1 = copyMap(map);
return sortPosReset(map1, "asc", true);
}
function rawurlencode(encodeStr){
if(empty(encodeStr)) return "";
return strreplace(url_encode(encodeStr), "%7E", "~");
}
function rawurldecode(str){
if(empty(str)) return "";
return url_decode(str);
}
function str_replace(searchMix, replaceMix, var1){
if(is_string(searchMix) && is_string(replaceMix)){
return strreplace(var1, searchMix, replaceMix);
}else if(is_array(searchMix) && is_array(replaceMix) ) {
foreach(k , v : searchMix){
var1 = strreplace(var1, searchMix[k], replaceMix[k]);
}
return var1;
}else if(is_array(searchMix) && is_string(replaceMix) ) {
foreach(k , v : searchMix){
var1 = strreplace(var1, searchMix[k], replaceMix);
}
return var1;
}else if(is_array(replaceMix) && is_string(searchMix) ) {
foreach(k , v : replaceMix){
var1 = strreplace(var1, searchMix, replaceMix[k]);
}
return var1;
}else{
thorw ("MyExcetion", "Parameter 1 and Parameter 2 support string or array!");
}
}
/**
examples:
var $str = "123456789";
print (php::substr_replace($str, "___", 2,13) ) ;
print (php::substr_replace($str, "___", 2,2) ) ;
print (php::substr_replace($str, "___", 2,1) ) ;
print (php::substr_replace($str, "___", 2,0) ) ;
print (php::substr_replace($str, "___", 2,-1) ) ; //12___9
print (php::substr_replace($str, "___", 2,-2) ) ; //12___89
print (php::substr_replace($str, "___", 2,-3) ) ; //12___789
print (php::substr_replace($str, "___", 2,-4) ) ; //12___6789
print (php::substr_replace($str, "___", 2,-5) ) ; //12___56789
print (php::substr_replace($str, "___", 2,-6) ) ; //12___456789
print (php::substr_replace($str, "___", 2,-7) ) ; //12___3456789
print (php::substr_replace($str, "___", 2,-8) ) ; //12___9
print (php::substr_replace($str, "___", 2,-9) ) ; //12___9
print (php::substr_replace($str, "___", 2,-10) ) ; //12___9
print (php::substr_replace($str, "___", 2,-11) ) ; //12___9
print "----------------------------------";
print (php::substr_replace($str, "___", -2,3) + " =>3" ) ;
print (php::substr_replace($str, "___", -2,2) + " =>2" ) ;
print (php::substr_replace($str, "___", -2,1) + " =>1" ) ;
print (php::substr_replace($str, "___", -2,0) + " =>0" ) ;
print (php::substr_replace($str, "___", -2,-1) + " =>-1" ) ;
print (php::substr_replace($str, "___", -2,-2) + " =>-2" ) ;
print (php::substr_replace($str, "___", -2,-3) + " =>-3" ) ;
print (php::substr_replace($str, "___", -2,-4) + " =>-4" ) ;
print (php::substr_replace($str, "___", -2,-5) + " =>-5" ) ;
print (php::substr_replace($str, "___", -2,-6) + " =>-6" ) ;
print (php::substr_replace($str, "___", -2,-7) + " =>-7" ) ;
print (php::substr_replace($str, "___", -2,-8) + " =>-8" ) ;
print (php::substr_replace($str, "___", -2,-9) + " =>-9" ) ;
print (php::substr_replace($str, "___", -2,-10) + " =>-10" ) ;
print (php::substr_replace($str, "___", -2,-11) + " =>-11" ) ;
print "__________________replace array___________________";
print (php::substr_replace($str, ["___"], 2,13) ) ;
print (php::substr_replace($str, ["___"], 2,2) ) ;
print (php::substr_replace($str, ["___"], 2,1) ) ;
print (php::substr_replace($str, ["___"], 2,0) ) ;
print (php::substr_replace($str, ["___"], 2,-1) ) ; //12___9
print (php::substr_replace($str, ["___"], 2,-2) ) ; //12___89
print (php::substr_replace($str, ["___"], 2,-3) ) ; //12___789
print (php::substr_replace($str, ["___"], 2,-4) ) ; //12___6789
print (php::substr_replace($str, ["___"], 2,-5) ) ; //12___56789
print (php::substr_replace($str, ["___"], 2,-6) ) ; //12___456789
print (php::substr_replace($str, ["___"], 2,-7) ) ; //12___3456789
print (php::substr_replace($str, ["___"], 2,-8) ) ; //12___9
print (php::substr_replace($str, ["___"], 2,-9) ) ; //12___9
print (php::substr_replace($str, ["___"], 2,-10) ) ; //12___9
print (php::substr_replace($str, ["___"], 2,-11) ) ; //12___9
print "----------------------------------";
print (php::substr_replace($str, ["___"], -2,3) + " =>3" ) ;
print (php::substr_replace($str, ["___"], -2,2) + " =>2" ) ;
print (php::substr_replace($str, ["___"], -2,1) + " =>1" ) ;
print (php::substr_replace($str, ["___"], -2,0) + " =>0" ) ;
print (php::substr_replace($str, ["___"], -2,-1) + " =>-1" ) ;
print (php::substr_replace($str, ["___"], -2,-2) + " =>-2" ) ;
print (php::substr_replace($str, ["___"], -2,-3) + " =>-3" ) ;
print (php::substr_replace($str, ["___"], -2,-4) + " =>-4" ) ;
print (php::substr_replace($str, ["___"], -2,-5) + " =>-5" ) ;
print (php::substr_replace($str, ["___"], -2,-6) + " =>-6" ) ;
print (php::substr_replace($str, ["___"], -2,-7) + " =>-7" ) ;
print (php::substr_replace($str, ["___"], -2,-8) + " =>-8" ) ;
print (php::substr_replace($str, ["___"], -2,-9) + " =>-9" ) ;
print (php::substr_replace($str, ["___"], -2,-10) + " =>-10" ) ;
print (php::substr_replace($str, ["___"], -2,-11) + " =>-11" ) ;
print "__________________replace array___________________";
var $arr = ["12345","12345","12345"];
dump (php::substr_replace($arr, "___", 1,3) ) ;
dump (php::substr_replace($arr, ["___"], 1,3) ) ;
dump (php::substr_replace($arr, ["___","="], 1, 3) ) ;
dump (php::substr_replace($arr, ["___","="], 1,-3) ) ;
print "_____________________________________";
dump (php::substr_replace($arr, "___", -4,3) ) ;
dump (php::substr_replace($arr, ["___"], -4,3) ) ;
dump (php::substr_replace($arr, ["___","="], -4, 3) ) ;
dump (php::substr_replace($arr, ["___","="], -4,-3) ) ;
print "_____________________________________";
dump (php::substr_replace("12345789", "___", 1,-3) ) ;
dump (php::substr_replace("12345789", ["___","="], 1,-3) ) ;
*/
function substr_replace(searchVar, replacVar, start , length = null){
if(is_numeric(searchVar)) searchVar = STRING(searchVar);
if(!(is_string(searchVar) || is_array(searchVar))) throw ("MyException", "substr_replace() parameter \"searchVar\" must to be a string or array type");
if(!(is_string(replacVar) || is_array(replacVar))) throw ("MyException", "substr_replace() parameter \"replacVar\" must to be a string or array type");
if(!is_int(start)) throw ("MyException", "substr_replace() parameter \"start\" must to be a intger type");
if(length && !is_int(length)) throw ("MyException", "substr_replace() parameter \"length\" must to be a intger type");
if(is_string(searchVar) && searchVar == "" && is_string(replacVar) && replacVar == "") return searchVar;
else if(is_array(searchVar) && searchVar.size() == 0 && is_array(replacVar) && replacVar.size() == 0) return searchVar;
var tmpSearchVar = [];
var tmpReplacVar = [];
var returnSearchVal = [];
if(is_string(searchVar)){
tmpSearchVar = explode("", searchVar);
}else{
var replacArrSize = null;
if(is_array(replacVar)){
replacArrSize = replacVar.size();
}
for(var i=0; i<searchVar.size(); i++) {
// tmpSearchVar.add(searchVar.get(i));
var tmpReplacVar2 = null;
if(replacArrSize > 0 ){
tmpReplacVar2 = "";
if(i < replacArrSize) tmpReplacVar2 = replacVar.get(i);
}else{
tmpReplacVar2 = replacVar;
}
var tmpItem = substr_replace(searchVar.get(i), tmpReplacVar2, start , length);
returnSearchVal.add(tmpItem);
}
return returnSearchVal;
}
if(is_string(replacVar)){
if(is_string(searchVar)) tmpReplacVar = explode("", replacVar);
else tmpReplacVar = new Array(replacVar);
}else{
for(var i=0; i<replacVar.size(); i++) {
tmpReplacVar.add( replacVar.get(i) );
}
}
if(is_string(searchVar) && is_array(replacVar) ) tmpReplacVar = new Array(tmpReplacVar.get(0));
var sSize = tmpSearchVar.size();
var rSize = tmpReplacVar.size();
var endPos = sSize;
var startPos = start;
var getStart = start;
var getLength = length;
if(length == null) {
length = sSize;
getLength = length;
}
// start 小于0,统一转为start>0的情况处理
if(start < 0) {
start = sSize + start;
startPos = start;
}
if(start > sSize){
startPos = sSize;
endPos = sSize + rSize;
returnSearchVal = tmpSearchVar;
var tmpIndex = 0;
for(var i = startPos; i< endPos; i++ ){
returnSearchVal.add(tmpReplacVar.get(tmpIndex));
tmpIndex++;
}
}else if(start >= 0 && start <= sSize){
if(getLength < 0) {
endPos = sSize + getLength;
if( endPos < startPos ) endPos = startPos;
}else{
endPos = startPos + getLength;
}
var looped = false;
for(var i = 0; i< sSize; i++){
if( looped == false && i >= startPos ) {
i = endPos;
looped = true;
foreach (k,v : tmpReplacVar) {
returnSearchVal.add(tmpReplacVar.get(k));
}
if(getLength>0 && endPos > sSize -1 ) break;
}
returnSearchVal.add(tmpSearchVar.get(i));
}
}
tmpSearchVar = null;
tmpReplacVar = null;
if(is_string(searchVar)){
return strjoin(returnSearchVal,"");
}
return returnSearchVal;
}
function str_repeat(str, times){
if(str && is_numeric(str)) str = STRING(str);
if(!is_string(str)) throw ("MyException", "str_repeat() parameter \"str\" must to be a string type");
if(!is_int(times)) throw ("MyException", "str_repeat() parameter \"times\" must to be a intger type");
if(times < 1) throw ("MyException", "str_repeat() parameter \"times\" can't be less than 1");
if(str == "") return "";
var newStr = "";
for(var i=0; i<times; i++){
newStr += str;
}
return newStr;
}
function getRandString(){
var letters = "abcdefghijklmnopqrstuvwxyz";
letters = explode("", letters);
var lettersLen = letters.size();
for(var i=0; i<lettersLen; i++){
var rand = Rand(i, lettersLen - 1);
// 当前值
var currentVal = letters[i];
// 随机位置值
var randVal = letters[rand];
// 交换变量
letters[i] = randVal;
letters[rand] = currentVal;
}
return strjoin(letters,"");
}
/**
* 输出一组系统信息
* @param string|null type -a/-s/-n/-r/-v/-m/-p/-i/-o
*
*/
function php_uname(type){
if(!type) type = "a";
if(!in_array(type, ["a", "s", "n", "r", "v", "m", "p", "i", "o"])){
throw ("MyExcetion", "type not in [\"a\", \"s\", \"n\", \"r\", \"v\", \"m\", \"p\", \"i\", \"o\"]");
}
var randStr = mtime() + math::rand(1000,2000) + getRandString();
var resLogFile = "/tmp/cb_system_out_" + randStr + ".txt";
if(isWin()) resLogFile = "C:\\Windows\\Temp\\" + randStr + ".txt";
os::system("uname -" + type +" >> " + resLogFile);
var readResLogFile = new File(resLogFile, "r");
var res = readResLogFile.read();
res = trim(res);
// print resLogFile;
return res;
}
function strtotime(dateString){
var checkDateRes = _checkDate(dateString);
if(!checkDateRes.get("result")) return false;//throw ("MyExcetion","strtotime(dateString): parameter \"dateString\" is illegal");
return checkDateRes.get("datestamp");
}
function _checkDate ($dateStr){
$dateStr = trim($dateStr);
if(!$dateStr || $dateStr == "") return false;
else if(strlower(CBType($dateStr)) != "string") return false;
var splitArr = strsplit($dateStr," ");
if(splitArr.size() == 1) $dateStr += " 00:00:00";
else if(splitArr.size() != 2) return false;
var regYear = "[0-9]{1,4}";
var regMonth = "(([0]?[1-9]{1})|([1]{1}[1-2]{1}))";
var regDate = "(([0-2]?[1-9]{1})|([3]{1}[0-1]{1}))";
var regHour = "(([0-1]?[0-9]{1})|([2]?[0-3]{1}))";
var regMinute = "[0-5]?[0-9]{1}";
var regex = new RegEx(""+regYear+"\S{1}"+regMonth+"\S{1}"+regDate+" "+regHour+":{1}"+regMinute+":{1}"+regMinute, "igc");
var check = regex.search($dateStr);
if(check ==null) return false;
var myTime = new Time();
myTime.strptime($dateStr, "%Y-%m-%d %H:%M:%S");
var $value2 = myTime.strftime("%Y-%m-%d %H:%M:%S");
var regex = new RegEx("[0-9]{1,4}","igc");
var res = regex.search($dateStr);
var res2 = regex.search($value2);
var $result = true;
foreach (k,v : res) {
if( !(v && res2 && res2[k] && INT(v[0]) == INT(res2[k][0])) ) {
$result = false;
break;
}
}
return {
"result":$result,
"dateFormat":$dateStr,
"datestamp":myTime.time()
};
}
function checkdnsrr($host, $DNSRecordType){
if(empty($host)) throw ("MyExcetion", "Parameter \"$host\" must to be empty!");
if(!is_string($host)) throw ("MyExcetion", "Parameter \"$host\" must to be a string!");
if(isWin()) throw("MyException","checkdnsrr() is not support windows platform");
$DNSRecordType = strupper($DNSRecordType);
if (!php::in_array($DNSRecordType, ["A", "MX", "NS", "SOA", "PTR", "CNAME", "AAAA", "A6", "SRV", "NAPTR", "TXT", "ANY"])) {
$DNSRecordType = "MX";
throw("MyException","checkdnsrr() Parameter \"$host\" must be in [\"A\", \"MX\", \"NS\", \"SOA\", \"PTR\", \"CNAME\", \"AAAA\", \"A6\", \"SRV\", \"NAPTR\", \"TXT\", \"ANY\"]");
}
if($DNSRecordType == "MX"){
var $tmpHostArr = explode("@",$host);
if($tmpHostArr && $tmpHostArr.size() >=2)
$host = $tmpHostArr[1];
}
var console = new ConsoleProcess();
console.start();
console.write("dig "+ $DNSRecordType +" "+ $host +"\n");
var NonAuthoritativeAnswer = false;
while(1) {
var l = console.readLine(); //逐行读取内容,这里也可以用read一次读取,只是为了演示readLine用法
if(l == null) break;
if( trim(";; ANSWER SECTION:") == l ){
// var tmpAnswer = console.readLine();
NonAuthoritativeAnswer = true;
break;
}
}
console.closeProcess();
return NonAuthoritativeAnswer;
}
function date_parse_from_format(format, $dateStr){
}
function preg_match(pattern, str){
var patternMode = "";
if(strget(pattern,0,1) == "/") {
var lastIndex = strrfind(pattern,"/");
var tmpPatternMode = strget(pattern, lastIndex);
pattern = strget(pattern,1,lastIndex);
if(tmpPatternMode && strlen(tmpPatternMode)) patternMode = trim(tmpPatternMode,"/");
}
var regex = new RegEx(pattern, patternMode);
return chose(regex.match(str), true, false);
}
function is_scalar(var1){
var flag =false;
if(in_array(CBType(var1), ["string", "float", "int", "bool" ])){
flag =true;
}
return flag;
}
function array_pad(array,size,value){
var sizeAbs = math::abs(size);
var needSize = sizeAbs - array.size();
if(needSize <= 0) return array;
for (var index = 0; index < math::abs(needSize) ; index++) {
if(size >= 0) array.add(value);
else {
}
}
return array;
}
function array_push(array,newItem){
array.add(newItem);
}
function array_pop(array){
if(array.size())
array.remove(array.size()-1);
}
function array_shift(array){
if(array.size())
array.remove(0);
}
function array_unshift(array,newItem){
array.insert(0,newItem);
}
function quotemeta( $str, $replaceOtherString = ""){
var search = [".","\\","+","(",")","*","?","^","$","[","]"];
if(!empty( $replaceOtherString )) search.add($replaceOtherString);
foreach (k,v : search)
{
$str = php::str_replace(v, "\\"+v,$str);
}
return $str;
}
function preg_quote($keywords, $replaceOtherString = ""){
return quotemeta( $str, $replaceOtherString);
}
function ereg( pattern, originalstring , getRegs = false){
var regex = new RegEx(pattern, php::chose(getRegs, "gc", ""));
originalstring = regex.search(originalstring);
if(getRegs)
return originalstring;
else
return php::chose(originalstring && originalstring != "",true, false);
}
/**
* mixed object ,
* string method_name
*/
function method_exists(object , method_name){
if(is_string(object)){
throw("MyException","method_exists(): Parameter \"object\" not support a string type");
}
if(strlower(CBType( object )) == "func"){
return true;
}else if(strfind(STRING(object),"]Object ")){
if(!(is_string(method_name) && method_name != "")) throw("MyException","method_exists(): Parameter \"method_name\" must to be a string type");
return FindCBObjFunc(object, method_name);
}else{
return false;
}
}
function _call_user_func(funcName,parmArray){
if(strlower(CBType(funcName)) == "string" )
return CallCBFunc(funcName,parmArray);
else if(strlower(CBType(funcName)) == "array" ){
return CallCBObjFunc (funcName.get(0),funcName.get(1),parmArray);
}else{
throw("MyException","_call_user_func Excteption!");
}
}
function call_user_func(funcName, parmString){
if(!is_string(funcName)) throw("MyException","call_user_func():Parameter \"funcName\" must to be a string type");
if(!is_string(parmString)) throw("MyException","call_user_func():Parameter \"parmString\" must to be a string type");
funcName = trim(funcName);
if(funcName == "") throw("MyException","call_user_func():Parameter \"funcName\" can't to be a empty string");
return _call_user_func(funcName, [parmString]);
}
function call_user_func_array(funcName, parmArray){
if(empty(funcName)) throw("MyException","call_user_func():Parameter \"funcName\" can't to be an empty array");
if(!is_array(parmArray)) throw("MyException","call_user_func():Parameter \"funcName\" must to be an array type");
if(is_array(funcName)) {
if(funcName.size() != 2) throw("MyException","call_user_func():Parameter \"funcName\" must to be an array and this array size to be two");
if(strfind(STRING(funcName.get(0)),"]Object ") == -1) throw("MyException","call_user_func():Parameter \"funcName\" the first element must to be an Object");
if(!is_string(funcName.get(1))) throw("MyException","call_user_func():Parameter \"funcName\" the second element must to be a string type");
}else{
if(!is_string(funcName)) throw("MyException","call_user_func():Parameter \"funcName\" must to be a string type");
}
return _call_user_func(funcName,parmArray);
}
function filter_map_(){
return {
"int": FILTER_VALIDATE_INT,
"boolean":FILTER_VALIDATE_BOOLEAN,
"float":FILTER_VALIDATE_FLOAT,
"validate_regexp":FILTER_VALIDATE_REGEXP,
"validate_domain":FILTER_VALIDATE_DOMAIN,
"validate_url":FILTER_VALIDATE_URL,
"validate_email":FILTER_VALIDATE_EMAIL,
"validate_ip":FILTER_VALIDATE_IP,
"validate_mac":FILTER_VALIDATE_MAC,
"string":FILTER_SANITIZE_STRING,
"stripped":FILTER_SANITIZE_STRIPPED,
"encoded":FILTER_SANITIZE_ENCODED,
"special_chars":FILTER_SANITIZE_SPECIAL_CHARS,
"full_special_chars":FILTER_SANITIZE_FULL_SPECIAL_CHARS,
"unsafe_raw":FILTER_UNSAFE_RAW,
"email":FILTER_SANITIZE_EMAIL,
"url":FILTER_SANITIZE_URL,
"number_int":FILTER_SANITIZE_NUMBER_INT,
"number_float":FILTER_SANITIZE_NUMBER_FLOAT,
"magic_quotes":FILTER_SANITIZE_MAGIC_QUOTES,
"add_slashes":FILTER_SANITIZE_ADD_SLASHES,
"callback":FILTER_CALLBACK
};
}
function filter_list(){
var filter_map = filter_map_();
var array = [];
foreach (k,v : filter_map)
{
array.add(k);
}
return array;
}
function filter_id(key){
var filter_map = filter_map_();
return filter_map.get(key);
}
function filter_var(value, filter_id, param){
switch (INT(filter_id))
{
case 259 : //FILTER_VALIDATE_FLOAT
{
if(is_int(value) || is_float(value) )
return true;
return false;
break;
}
default:
{
throw ("MyException", "filter_var(): please define you code of \"" + filter_id + "\"");
break;
}
}
}
function basename(path, suffix=""){
if(!is_string(path)) throw ("MyExcetion", "Parameter \"path\" must to be a string!");
if(!path || path == "") throw ("MyExcetion", "Parameter \"path\" must to be required!");
if(isWin()){
path = str_replace("\\", "/", path);
}
var idx = strirfind(path, "/");
if(idx == -1 ) idx = 0;
else idx = idx + 1;
var basename = strget(path, idx);
if(is_string(suffix) && suffix != "") basename = str_replace(suffix, "", basename);
return basename;
}
function min(value1, value2){
if(value1 > value2) return value2;
return value1;
}
function max(value1, value2){
if(value1 > value2) return value1;
return value2;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。