-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.php
121 lines (94 loc) · 3.46 KB
/
lib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
require_once 'classes.php';
// Reads the first line in a file and tries to figure out what kind of grade
// file it is. A new object of the appropriate grade file type is returned.
function smart_autodiscover_filetype($file) {
$lines = smart_split_file($file);
$line = $lines[0];
if (SmartFileKeypadidCSV::validate_line($line)) {
return new SmartFileKeypadidCSV($file);
}
if (SmartFileKeypadidTabbed::validate_line($line)) {
return new SmartFileKeypadidTabbed($file);
}
if (SmartFileFixed::validate_line($line)) {
return new SmartFileFixed($file);
}
if (SmartFileInsane::validate_line($line)) {
return new SmartFileInsane($file);
}
if (SmartFileCommaLongLsuid::validate_line($line)) {
return new SmartFileCommaLongLsuid($file);
}
if (SmartFileCommaLongPawsid::validate_line($line)) {
return new SmartFileCommaLongPawsid($file);
}
if (SmartFileTabLongLsuid::validate_line($line)) {
return new SmartFileTabLongLsuid($file);
}
if (SmartFileTabLongPawsid::validate_line($line)) {
return new SmartFileTabLongPawsid($file);
}
if (SmartFileTabShortLsuid::validate_line($line)) {
return new SmartFileTabShortLsuid($file);
}
if (SmartFileCSVLsuid::validate_line($line)) {
return new SmartFileCSVLsuid($file);
}
if (SmartFileMEC::validate_line($line)) {
return new SmartFileMEC($file);
}
if (SmartFileTabShortPawsid::validate_line($line)) {
return new SmartFileTabShortPawsid($file);
}
if (SmartFileAnonymous::validate_line($line)) {
return new SmartFileAnonymous($file);
}
if (SmartFileCSVPawsid::validate_line($line)) {
return new SmartFileCSVPawsid($file);
}
if (count($lines) >= 3 && SmartFileMaple::validate_line($lines[2])) {
return new SmartFileMaple($file);
}
return false;
}
// Splits a file into an array of lines and normalize newlines
function smart_split_file($file) {
// Replace \r\n with \n, replace any leftover \r with \n, explode on \n
$lines = explode("\n", preg_replace("/\r/", "\n", preg_replace("/\r\n/", "\n", $file)));
if (end($lines) == '') {
return array_slice($lines, 0, count($lines) - 1, True);
} else {
return $lines;
}
}
// Checks whether or not a string is a valid LSUID. It must be a nine digit
// digit number that starts with 89 to pass.
function smart_is_lsuid2($s) {
return preg_match('/^89\d{7}$/', $s);
}
// Checks whether or not a string is a valid MEC LSUID. It must be a twelve digit
// digit number that starts with three digits and has 89.* afterward.
function smart_is_mec_lsuid($s) {
return preg_match('/^...89\d{7}$/', $s);
}
// Checks whether or not a string is a valid grade. It must be of the form
// NNN.NN, NN.NN, or N.NN to pass.
function smart_is_grade($s) {
//return preg_match('/^\d{1,3}(.\d{2})?$/', trim($s));
return preg_match('/^\d{1,3}|[(.\d{1})]|[(.\d{2})]?$/', trim($s));
}
// Checks whether or not a string is a valid anonymous number. It must be of
// the form XXXX to pass.
function smart_is_anon_num($s) {
return preg_match('/^\d{4}$/', $s);
}
// Checks whether or not a string is a valid pawsid. It must be 1-16 and contain
// only alphanumeric characters including hyphens.
function smart_is_pawsid($s) {
return preg_match('/^[a-zA-Z0-9\-]{1,16}$/', $s);
}
function smart_is_keypadid($s) {
return preg_match('/^[A-Z0-9]{6}$/', $s);
}
?>