corrade-http-templates – Diff between revs 24 and 78
?pathlinks?
Rev 24 | Rev 78 | |||
---|---|---|---|---|
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 stores group messages to a local file that can ## |
6 | ## This is a script that stores group messages to a local file that can ## |
|
7 | ## then be read-in by other scripts and displayed. The script will only ## |
7 | ## then be read-in by other scripts and displayed. The script will only ## |
|
8 | ## write to a file "chat.log" in the current directory and the name of ## |
8 | ## write to a file "chat.log" in the current directory and the name of ## |
|
9 | ## the chat log ("chat.log") is hard-coded because it depends on this ## |
9 | ## the chat log ("chat.log") is hard-coded because it depends on this ## |
|
10 | ## script's HTML counter-part that has the name hard-coded too. ## |
10 | ## script's HTML counter-part that has the name hard-coded too. ## |
|
11 | ########################################################################### |
11 | ########################################################################### |
|
12 | |
12 | |
|
13 | # Send the response. |
13 | # Send the response. |
|
14 | http_response_code(200); |
14 | http_response_code(200); |
|
15 | |
15 | |
|
16 | ########################################################################### |
16 | ########################################################################### |
|
17 | ## CONFIGURATION ## |
17 | ## CONFIGURATION ## |
|
18 | ########################################################################### |
18 | ########################################################################### |
|
19 | |
19 | |
|
20 | require_once('config.php'); |
20 | require_once('config.php'); |
|
21 | require_once('functions.php'); |
21 | require_once('vendor/was/utilities/src/IO/IO.php'); |
|
22 | |
22 | |
|
23 | ########################################################################### |
23 | ########################################################################### |
|
24 | ## INTERNALS ## |
24 | ## INTERNALS ## |
|
25 | ########################################################################### |
25 | ########################################################################### |
|
26 | |
26 | |
|
27 | # Check if this is the membership notification. |
27 | # Check if this is the membership notification. |
|
28 | if(!isset($_POST['type']) || $_POST['type'] != "membership") return; |
28 | if(!isset($_POST['type']) || $_POST['type'] != "membership") return; |
|
29 | # Check that the notification is for the configured group. |
29 | # Check that the notification is for the configured group. |
|
30 | if(!isset($_POST['group']) || $_POST['group'] != $GROUP) return; |
30 | if(!isset($_POST['group']) || $_POST['group'] != $GROUP) return; |
|
31 | # Bail if "firstname", "lastname" or the "message" variables are blank. |
31 | # Bail if "firstname", "lastname" or the "message" variables are blank. |
|
32 | if($_POST['firstname'] == '' |
32 | if($_POST['firstname'] == '' |
|
33 | || $_POST['lastname'] == '' |
33 | || $_POST['lastname'] == '' |
|
34 | || ( |
34 | || ( |
|
35 | $_POST['action'] != 'joined' && |
35 | $_POST['action'] != 'joined' && |
|
36 | $_POST['action'] != 'parted' |
36 | $_POST['action'] != 'parted' |
|
37 | )) return; |
37 | )) return; |
|
38 | |
38 | |
|
39 | #### |
39 | #### |
|
40 | # I. Initialize a new blank array. |
40 | # I. Initialize a new blank array. |
|
41 | $data = array(); |
41 | $data = array(); |
|
42 | |
42 | |
|
43 | #### |
43 | #### |
|
44 | # II. If the file exists, trim it to the number of chat lines. |
44 | # II. If the file exists, trim it to the number of chat lines. |
|
45 | switch(file_exists("membership.log")) { |
45 | switch(file_exists("membership.log")) { |
|
46 | case TRUE: |
46 | case TRUE: |
|
47 | # Open the membership.log and trim the lines. |
47 | # Open the membership.log and trim the lines. |
|
48 | $data = explode( |
48 | $data = explode( |
|
49 | PHP_EOL, |
49 | PHP_EOL, |
|
50 | atomized_get_contents( |
50 | atomized_get_contents( |
|
51 | "membership.log" |
51 | "membership.log" |
|
52 | ) |
52 | ) |
|
53 | ); |
53 | ); |
|
54 | while(sizeof($data) > $MEMBERSHIP_LINES) |
54 | while(sizeof($data) > $MEMBERSHIP_LINES) |
|
55 | array_shift($data); |
55 | array_shift($data); |
|
56 | break; |
56 | break; |
|
57 | } |
57 | } |
|
58 | |
58 | |
|
59 | #### |
59 | #### |
|
60 | # II. Add the line at the end. |
60 | # II. Add the line at the end. |
|
61 | array_push( |
61 | array_push( |
|
62 | $data, |
62 | $data, |
|
63 | sprintf( |
63 | sprintf( |
|
64 | "[%s:%s] %s %s : %s", |
64 | "[%s:%s] %s %s : %s", |
|
65 | date("H"), |
65 | date("H"), |
|
66 | date("i"), |
66 | date("i"), |
|
67 | $_POST['firstname'], |
67 | $_POST['firstname'], |
|
68 | $_POST['lastname'], |
68 | $_POST['lastname'], |
|
69 | $_POST['action']." the group." |
69 | $_POST['action']." the group." |
|
70 | ) |
70 | ) |
|
71 | ); |
71 | ); |
|
72 | |
72 | |
|
73 | #### |
73 | #### |
|
74 | # II. Now dump the array to the file. |
74 | # II. Now dump the array to the file. |
|
75 | atomized_put_contents( |
75 | atomized_put_contents( |
|
76 | "membership.log", |
76 | "membership.log", |
|
77 | implode( |
77 | implode( |
|
78 | PHP_EOL, |
78 | PHP_EOL, |
|
79 | $data |
79 | $data |
|
80 | ) |
80 | ) |
|
81 | ); |
81 | ); |
|
82 | |
82 | |
|
83 | ?> |
83 | ?> |
|
84 | |
84 | |