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