corrade-http-templates – Diff between revs 4 and 25
?pathlinks?
Rev 4 | Rev 25 | |||
---|---|---|---|---|
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 | ########################################################################### |
13 | ########################################################################### |
|
14 | ## CONFIGURATION ## |
14 | ## CONFIGURATION ## |
|
15 | ########################################################################### |
15 | ########################################################################### |
|
16 | |
16 | |
|
17 | require_once('config.php'); |
17 | require_once('config.php'); |
|
18 | require_once('functions.php'); |
18 | require_once('functions.php'); |
|
19 | |
19 | |
|
20 | ########################################################################### |
20 | ########################################################################### |
|
21 | ## INTERNALS ## |
21 | ## INTERNALS ## |
|
22 | ########################################################################### |
22 | ########################################################################### |
|
23 | |
23 | |
|
24 | # Check if this is the group chat notification. |
24 | # Check if this is the group chat notification. |
|
25 | if(!isset($_POST['type']) || $_POST['type'] != "group") return; |
25 | if(!isset($_POST['type']) || $_POST['type'] != "group") return; |
|
26 | # Check that the notification is for the configured group. |
26 | # Check that the notification is for the configured group. |
|
27 | if(!isset($_POST['group']) || $_POST['group'] != $GROUP) return; |
27 | if(!isset($_POST['group']) || $_POST['group'] != $GROUP) return; |
|
28 | # Bail if "firstname", "lastname" or the "message" variables are blank. |
28 | # Bail if "firstname", "lastname" or the "message" variables are blank. |
|
29 | if(!isset($_POST['firstname']) || |
29 | if(!isset($_POST['firstname']) || |
|
30 | empty($_POST['firstname']) || |
30 | empty($_POST['firstname']) || |
|
31 | !isset($_POST['lastname']) || |
31 | !isset($_POST['lastname']) || |
|
32 | empty($_POST['lastname']) || |
32 | empty($_POST['lastname']) || |
|
33 | !isset($_POST['message']) || |
33 | !isset($_POST['message']) || |
|
34 | empty($_POST['message'])) return; |
34 | empty($_POST['message'])) return; |
|
35 | |
35 | |
|
36 | #### |
36 | #### |
|
37 | # I. Initialize a new blank array. |
37 | # I. Initialize a new blank array. |
|
38 | $data = array(); |
38 | $data = array(); |
|
39 | |
39 | |
|
40 | #### |
40 | #### |
|
41 | # II. If the file exists, trim it to the number of chat lines. |
41 | # II. If the file exists, trim it to the number of chat lines. |
|
42 | switch(file_exists("chat.log")) { |
42 | switch(file_exists("chat.log")) { |
|
43 | case TRUE: |
43 | case TRUE: |
|
44 | # Open the chat log and trim the lines to the configured line size. |
44 | # Open the chat log and trim the lines to the configured line size. |
|
45 | $data = explode( |
45 | $data = explode( |
|
46 | PHP_EOL, |
46 | PHP_EOL, |
|
47 | atomized_get_contents( |
47 | atomized_get_contents( |
|
48 | "chat.log" |
48 | "chat.log" |
|
49 | ) |
49 | ) |
|
50 | ); |
50 | ); |
|
51 | while(sizeof($data) > $CHAT_LINES) |
51 | while(sizeof($data) > $CHAT_LINES) |
|
52 | array_shift($data); |
52 | array_shift($data); |
|
53 | break; |
53 | break; |
|
54 | } |
54 | } |
|
55 | |
55 | |
|
56 | #### |
56 | #### |
|
57 | # III. Add the line at the end including the date. |
57 | # III. Add the line at the end including the date. |
|
58 | array_push( |
58 | array_push( |
|
59 | $data, |
59 | $data, |
|
60 | sprintf( |
60 | sprintf( |
|
61 | "[%s:%s] %s %s : %s", |
61 | "[%s:%s] %s %s : %s", |
|
62 | date("H"), |
62 | gmdate("H"), |
|
63 | date("i"), |
63 | gmdate("i"), |
|
64 | $_POST['firstname'], |
64 | $_POST['firstname'], |
|
65 | $_POST['lastname'], |
65 | $_POST['lastname'], |
|
66 | $_POST['message'] |
66 | $_POST['message'] |
|
67 | ) |
67 | ) |
|
68 | ); |
68 | ); |
|
69 | |
69 | |
|
70 | #### |
70 | #### |
|
71 | # IV. Now dump the array to the file. |
71 | # IV. Now dump the array to the file. |
|
72 | atomized_put_contents( |
72 | atomized_put_contents( |
|
73 | "chat.log", |
73 | "chat.log", |
|
74 | implode( |
74 | implode( |
|
75 | PHP_EOL, |
75 | PHP_EOL, |
|
76 | $data |
76 | $data |
|
77 | ) |
77 | ) |
|
78 | ); |
78 | ); |
|
79 | |
79 | |
|
80 | ?> |
80 | ?> |
|
81 | |
81 | |