corrade-http-templates – Diff between revs 1 and 73

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 1 Rev 73
1 <?php 1 <?php
2   -  
3 ########################################################################### -  
4 ## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ## -  
5 ########################################################################### 2  
6 function atomized_put_contents($file, $data) { -  
7 $fp = fopen($file, "w+"); -  
8 if (flock($fp, LOCK_EX)) { -  
9 fwrite($fp, $data); -  
10 fflush($fp); -  
11 flock($fp, LOCK_UN); -  
12 } -  
13 fclose($fp); -  
14 } -  
15   -  
16 ########################################################################### -  
17 ## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ## -  
18 ########################################################################### -  
19 function atomized_get_contents($file) { -  
20 $fp = fopen($file, "r+"); -  
21 $ct = ''; -  
22 if (flock($fp, LOCK_SH)) { -  
23 if (filesize($file)) { -  
24 $ct = fread($fp, filesize($file)); -  
25 } -  
26 flock($fp, LOCK_UN); -  
27 } -  
28 fclose($fp); -  
29 return $ct; -  
30 } -  
31   -  
32 ########################################################################### -  
33 ## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ## -  
34 ########################################################################### -  
35 function wasKeyValueGet($key, $data) { -  
36 return array_reduce( -  
37 explode( -  
38 "&", -  
39 $data -  
40 ), -  
41 function($o, $p) { -  
42 $x = explode("=", $p); -  
43 return array_shift($x) != $o ? $o : array_shift($x); -  
44 }, -  
45 $key -  
46 ); -  
47 } 3 require_once('vendor/was/utilities/src/IO/IO.php');
48   4  
49 ########################################################################### 5 ###########################################################################
50 ## Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 ## 6 ## Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 ##
51 ########################################################################### 7 ###########################################################################
52 function storeAvatarConversation($firstname, $lastname, $message, $chatFile, $lines) { 8 function storeAvatarConversation($firstname, $lastname, $message, $chatFile, $lines) {
53 #### 9 ####
54 # I. Initialize an array to store the chat lines. 10 # I. Initialize an array to store the chat lines.
55 $data = array(); 11 $data = array();
56   12  
57 #### 13 ####
58 # II. If the file exists, trim it to the number of chat lines. 14 # II. If the file exists, trim it to the number of chat lines.
59 switch(file_exists($chatFile)) { 15 switch(file_exists($chatFile)) {
60 case TRUE: 16 case TRUE:
61 # Open the chat log and trim the lines to the configured line size. 17 # Open the chat log and trim the lines to the configured line size.
62 $data = explode( 18 $data = explode(
63 PHP_EOL, 19 PHP_EOL,
64 atomized_get_contents( 20 atomized_get_contents(
65 $chatFile 21 $chatFile
66 ) 22 )
67 ); 23 );
68 while(sizeof($data) > $lines) 24 while(sizeof($data) > $lines)
69 array_shift($data); 25 array_shift($data);
70 break; 26 break;
71 } 27 }
72   28  
73 #### 29 ####
74 # III. Add the line at the end. 30 # III. Add the line at the end.
75 array_push( 31 array_push(
76 $data, 32 $data,
77 empty($lastname) ? 33 empty($lastname) ?
78 sprintf( 34 sprintf(
79 "[%s:%s] %s : %s", 35 "[%s:%s] %s : %s",
80 date("H"), 36 date("H"),
81 date("i"), 37 date("i"),
82 $firstname, # Don't normalize the name. 38 $firstname, # Don't normalize the name.
83 $message 39 $message
84 ) : 40 ) :
85 sprintf( 41 sprintf(
86 "[%s:%s] %s %s : %s", 42 "[%s:%s] %s %s : %s",
87 date("H"), 43 date("H"),
88 date("i"), 44 date("i"),
89 ucfirst( 45 ucfirst(
90 strtolower( 46 strtolower(
91 $firstname 47 $firstname
92 ) 48 )
93 ), 49 ),
94 ucfirst( 50 ucfirst(
95 strtolower( 51 strtolower(
96 $lastname 52 $lastname
97 ) 53 )
98 ), 54 ),
99 $message 55 $message
100 ) 56 )
101 ); 57 );
102   58  
103 #### 59 ####
104 # IV. Now dump the array to the file. 60 # IV. Now dump the array to the file.
105 atomized_put_contents( 61 atomized_put_contents(
106 $chatFile, 62 $chatFile,
107 implode( 63 implode(
108 PHP_EOL, 64 PHP_EOL,
109 $data 65 $data
110 ) 66 )
111 ); 67 );
112 } 68 }
113   69  
114
Generated by GNU Enscript 1.6.5.90.
70
Generated by GNU Enscript 1.6.5.90.
115   71  
116   72  
117   73