Exemplo n.º 1
0
 static function is_cid($cid)
 {
     //长度
     if (!regexp::match($cid, 'cid')) {
         return false;
     }
     //城市
     $city_id = array(11, 12, 13, 14, 15, 21, 22, 23, 31, 32, 33, 34, 35, 36, 37, 41, 42, 43, 44, 45, 46, 50, 51, 52, 53, 54, 61, 62, 63, 64, 65, 71, 81, 82, 91);
     $cid_city = intval(substr($cid, 0, 2));
     if (!in_array($cid_city, $city_id)) {
         return false;
     }
     if (strlen($cid) === 18) {
         //ISO-加权因子
         if (strtolower(substr($cid, 17, 1)) !== self::get_right_no($cid)) {
             return false;
         }
         list($year, $lie) = array(substr($cid, 6, 4), 10);
     } else {
         list($year, $lie) = array('19' . substr($cid, 6, 2), 8);
     }
     //年(1912-2020)月(1-12)日(1-31)
     list($month, $day) = array(substr($cid, $lie, 2), substr($cid, $lie + 2, 2));
     if (intval($year) < 1912 || intval($year) > 2020) {
         return false;
     }
     if (intval($month) < 1 || intval($month) > 12) {
         return false;
     }
     if (intval($day) < 1 || intval($day) > 31) {
         return false;
     }
     return true;
 }
Exemplo n.º 2
0
 static function check($value, $rule, $type = 'regexp')
 {
     $type = strtolower(trim($type));
     switch ($type) {
         case 'in':
             //是否在指定范围值之内,逗号分隔字符串或者数组
         //是否在指定范围值之内,逗号分隔字符串或者数组
         case 'not_in':
             $range = is_array($rule) ? $rule : explode(',', $rule);
             return $type == 'in' ? in_array($value, $range) : !in_array($value, $range);
         case 'between':
             //在某个区间内
         //在某个区间内
         case 'not_between':
             //在某个区间外
             list($min, $max) = is_array($rule) ? $rule : explode(',', $rule);
             return $type == 'between' ? $value >= $min && $value <= $max : $value < $min || $value > $max;
         case 'equal':
             //是否相等
         //是否相等
         case 'not_equal':
             //是否不等
             return $type === 'equal' ? $value === $rule : $value !== $rule;
         case 'length':
             //长度
             $length = mb_strlen($value, 'utf-8');
             if (strpos($rule, ',')) {
                 //指定长度区间内
                 list($min, $max) = explode(',', $rule);
                 return $length >= $min && $length <= $max;
             } else {
                 //长度相等
                 return $length == $rule;
             }
         case 'expire':
             //有效期
             $now_time = time();
             list($start, $end) = explode(',', $rule);
             $start = is_numeric($start) ? $start : strtotime($start);
             $end = is_numeric($end) ? $end : strtotime($end);
             return $now_time >= $start && $now_time <= $end;
         case 'regexp':
         default:
             //默认使用正则验证
             return regexp::match($value, $rule);
     }
 }
Exemplo n.º 3
0
 static function family_name($real_name)
 {
     if (strlen($real_name) >= 6 && strlen($real_name) <= 15) {
         if (regexp::match($real_name, 'chinese')) {
             $first_name = substr($real_name, 0, 3);
             $odd_family_name = file::read('family_name', 1);
             $odd_data = str_split($odd_family_name[0], 3);
             if (in_array($first_name, $odd_data)) {
                 return true;
             }
             $first_name = substr($real_name, 0, 6);
             $even_family_name = file::read('family_name', 2);
             $even_data = explode(',', $even_family_name);
             if (in_array($first_name, $even_data)) {
                 return true;
             }
         }
     }
     return false;
 }
Exemplo n.º 4
0
 static function condition($data)
 {
     if (is_array($data)) {
         //处理逻辑连接符
         $logic = ' and ';
         if (isset($data['logic'])) {
             $logic = ' ' . $data['logic'] . ' ';
             unset($data['logic']);
         }
         //处理字符串(本生sql)
         $condition = array();
         foreach (array('query', 'native', 'processed') as $name) {
             if (isset($data[$name])) {
                 $condition[] = '(' . $data[$name] . ')';
                 unset($data[$name]);
             }
         }
         //处理条件数据
         foreach ($data as $key => $value) {
             $condition[] = '(' . self::parse_expression($key, $value) . ')';
         }
         return implode($logic, $condition);
     }
     if (regexp::match($data, 'id')) {
         return 'id=' . $data;
     }
     if (regexp::match($data, 'uuid')) {
         return 'uuid="' . $data . '"';
     }
     return $data;
 }
Exemplo n.º 5
0
 static function qrcode($info, $w_h = '120', $level = 'L', $margin = '0')
 {
     $info = trim($info);
     $info = regexp::match($info, 'url') ? urlencode($info) : $info;
     $url = 'http://chart.apis.google.com/chart?';
     $param = 'chs=' . $w_h . 'x' . $w_h . '&cht=qr&chld=' . $level . '|' . $margin . '&chl=' . $info;
     return '<img src=' . $url . $param . '>';
 }
Exemplo n.º 6
0
function url($lie = 0, $type = 0)
{
    // $lie=$lie+n; //n为相对根目录的深度
    $param = explode('/', URL_REQUEST);
    if ($lie < count($param)) {
        $value = get_magic_quotes_gpc() ? $param[$lie] : addslashes($param[$lie]);
        if (is_int($type)) {
            return $type ? abs((int) $value) : strval(trim($value));
        }
        return regexp::match($value, $type) ? $value : null;
    }
}
Exemplo n.º 7
0
 function move()
 {
     if ($this->save_directory) {
         $this->save_path .= $this->save_directory;
         $this->check_directory();
     }
     if (!regexp::match($this->save_name, 'file_name')) {
         throw new sException('file name format error', 512, 13);
     }
     $file_name = $this->save_path . $this->save_name . '.' . $this->file['extension_name'];
     if (move_uploaded_file($this->file['tmp_name'], $file_name)) {
         $this->file['file_name'] = $file_name;
         chmod($file_name, 0644);
         return $file_name;
     }
     throw new sException('move file fail', 513, 14);
 }
Exemplo n.º 8
0
 public static function cleanSeparators($sPath)
 {
     return regexp::replace('#[\\\\/]+#', '/', $sPath);
 }
Exemplo n.º 9
0
 private static function process($value, $mode)
 {
     //原味输出
     $input_type = array('get', 'post', 'request', 'server');
     if (in_array($mode, $input_type, true)) {
         return $value;
     }
     //trim过滤、魔术引号转义
     if (is_string($value)) {
         $value = get_magic_quotes_gpc() ? trim($value) : trim(addslashes($value));
     }
     switch ($mode) {
         case 'title':
             //标题、关键词(去空、特殊字符、html标签)
             return trim(htmlspecialchars(strip_tags($value)));
         case 'int':
             //ID,自然数、POST的整型(0-N,ID、number)
             return abs((int) $value);
         case 'text':
             //介绍、详细内容(就留允许的html标签)
             $allow_tags = '<ul><ol><li><p><h1><h2><h3><h4><h5><h6><table><tr><th><td>';
             $allow_tags .= '<a><img><span><b><i><em><cite><strong><br><hr>';
             return trim(htmlspecialchars(strip_tags($value, $allow_tags)));
         case 'number':
             //数字
             return regexp::match($value, 'number') ? $value : 0;
         case 'float':
             //小数、浮点数(货币、概率)
             return (double) $value;
         case 'account':
             //邮箱、用户名(注册账号时不区分大小写)
             return trim(secure::symbol(strip_tags(strtolower($value))));
         case 'date':
             //日期
         //日期
         case 'time':
             //时间
         //时间
         case 'date_time':
             //日期时间
             $option = array('date' => 'Y-m-d', 'time' => 'H:i:s', 'date_time' => 'Y-m-d H:i:s');
             $format_time = date($option[$mode], strtotime($value));
             return $format_time === $value ? $value : null;
         case 'many':
             //联合复选框(checkbox)
             return implode(',', $value);
         default:
             //正则匹配输出
             return regexp::match($value, $mode) ? $value : null;
     }
 }