corrade-http-templates – Diff between revs 2 and 80
?pathlinks?
Rev 2 | Rev 80 | |||
---|---|---|---|---|
1 | <?php |
1 | <?php |
|
2 | |
2 | |
|
3 | ########################################################################### |
3 | ########################################################################### |
|
4 | ## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ## |
4 | ## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ## |
|
5 | ########################################################################### |
5 | ########################################################################### |
|
6 | ## This is a script that reads a visitors log and generates a json ## |
6 | ## This is a script that reads a visitors log and generates a json ## |
|
7 | ## object from the number of males and females that Corrade detected. ## |
7 | ## object from the number of males and females that Corrade detected. ## |
|
8 | ########################################################################### |
8 | ########################################################################### |
|
9 | |
9 | |
|
10 | ########################################################################### |
10 | ########################################################################### |
|
11 | ## CONFIGURATION ## |
11 | ## CONFIGURATION ## |
|
12 | ########################################################################### |
12 | ########################################################################### |
|
13 | |
13 | |
|
14 | # Visitors file. |
14 | # Visitors file. |
|
15 | $VISITOR_FILE = "visitors.log"; |
15 | $VISITOR_FILE = "visitors.log"; |
|
16 | |
16 | |
|
17 | ########################################################################### |
17 | ########################################################################### |
|
18 | ## INTERNALS ## |
18 | ## INTERNALS ## |
|
19 | ########################################################################### |
19 | ########################################################################### |
|
20 | |
- | ||
21 | ########################################################################### |
- | ||
22 | ## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ## |
- | ||
23 | ########################################################################### |
- | ||
24 | function atomized_get_contents($file) { |
- | ||
25 | $fp = fopen($file, "r+"); |
- | ||
26 | $ct = ''; |
- | ||
27 | if (flock($fp, LOCK_SH)) { |
- | ||
28 | if (filesize($file)) { |
- | ||
29 | $ct = fread($fp, filesize($file)); |
- | ||
30 | } |
- | ||
31 | flock($fp, LOCK_UN); |
- | ||
32 | } |
- | ||
33 | fclose($fp); |
- | ||
34 | return $ct; |
- | ||
35 | } |
- | ||
36 | |
- | ||
37 | /////////////////////////////////////////////////////////////////////////// |
- | ||
38 | // Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 // |
- | ||
39 | /////////////////////////////////////////////////////////////////////////// |
- | ||
40 | function wasCSVToArray($csv) { |
- | ||
41 | $l = array(); |
- | ||
42 | $s = array(); |
- | ||
43 | $m = ""; |
- | ||
44 | for ($i = 0; $i < strlen($csv); ++$i) { |
- | ||
45 | switch ($csv{$i}) { |
- | ||
46 | case ',': |
- | ||
47 | if (sizeof($s) == 0 || !current($s) == '"') { |
- | ||
48 | array_push($l, $m); |
- | ||
49 | $m = ""; |
- | ||
50 | break; |
- | ||
51 | } |
- | ||
52 | $m .= $csv{$i}; |
- | ||
53 | continue; |
- | ||
54 | case '"': |
- | ||
55 | if ($i + 1 < strlen($csv) && $csv{$i} == $csv{$i + 1}) { |
- | ||
56 | $m .= $csv{$i}; |
- | ||
57 | ++$i; |
- | ||
58 | break; |
- | ||
59 | } |
20 | |
|
60 | if (sizeof($s) == 0|| !current($s) == $csv[$i]) { |
21 | require_once('vendor/was/utilities/src/formats/csv/csv.php'); |
|
61 | array_push($s, $csv{$i}); |
- | ||
62 | continue; |
- | ||
63 | } |
- | ||
64 | array_pop($s); |
- | ||
65 | break; |
- | ||
66 | default: |
- | ||
67 | $m .= $csv{$i}; |
- | ||
68 | break; |
- | ||
69 | } |
- | ||
70 | } |
- | ||
71 | array_push($l, $m); |
- | ||
72 | return $l; |
- | ||
73 | } |
22 | require_once('vendor/was/utilities/src/IO/IO.php'); |
|
74 | |
23 | |
|
75 | $f = 0; |
24 | $f = 0; |
|
76 | $m = 0; |
25 | $m = 0; |
|
77 | |
26 | |
|
78 | array_walk( |
27 | array_walk( |
|
79 | explode( |
28 | explode( |
|
80 | PHP_EOL, |
29 | PHP_EOL, |
|
81 | atomized_get_contents( |
30 | atomized_get_contents( |
|
82 | $VISITOR_FILE |
31 | $VISITOR_FILE |
|
83 | ) |
32 | ) |
|
84 | ), |
33 | ), |
|
85 | function($e, $k) use(&$f, &$m) { |
34 | function($e, $k) use(&$f, &$m) { |
|
86 | switch(wasCSVToArray($e)[1]) { |
35 | switch(wasCSVToArray($e)[1]) { |
|
87 | case 'female': |
36 | case 'female': |
|
88 | ++$f; |
37 | ++$f; |
|
89 | break; |
38 | break; |
|
90 | default: |
39 | default: |
|
91 | ++$m; |
40 | ++$m; |
|
92 | break; |
41 | break; |
|
93 | } |
42 | } |
|
94 | } |
43 | } |
|
95 | ); |
44 | ); |
|
96 | |
45 | |
|
97 | header('content-type: application/json; charset=utf-8'); |
46 | header('content-type: application/json; charset=utf-8'); |
|
98 | echo json_encode( |
47 | echo json_encode( |
|
99 | array( |
48 | array( |
|
100 | "Male" => $m, |
49 | "Male" => $m, |
|
101 | "Female" => $f |
50 | "Female" => $f |
|
102 | ) |
51 | ) |
|
103 | ); |
52 | ); |
|
104 | |
- | ||
105 | ?> |
- | ||
106 | |
53 | |
|
107 |
|
- | ||
108 | |
- | ||
109 | |
- | ||
110 | |
- |