corrade-http-templates – Blame information for rev 71

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