]> git.mxchange.org Git - friendica-addons.git/blob - jappixmini/jappix/php/generate-chat.php
default features - actually handle the security token in the addon code
[friendica-addons.git] / jappixmini / jappix / php / generate-chat.php
1 <?php
2
3 /*
4
5 Jappix - An open social platform
6 This is the PHP script used to generate a chat log
7
8 -------------------------------------------------
9
10 License: AGPL
11 Author: Vanaryon
12 Last revision: 26/08/11
13
14 */
15
16 // PHP base
17 define('JAPPIX_BASE', '..');
18
19 // Get the needed files
20 require_once('./functions.php');
21 require_once('./read-main.php');
22 require_once('./read-hosts.php');
23
24 // Optimize the page rendering
25 hideErrors();
26 compressThis();
27
28 // Not allowed for a special node
29 if(isStatic() || isUpload())
30         exit;
31
32 // Create the HTML file to be downloaded
33 if(isset($_POST['content']) && isset($_POST['xid']) && !empty($_POST['xid']) && isset($_POST['nick']) && !empty($_POST['nick']) && isset($_POST['avatar']) && !empty($_POST['avatar']) && isset($_POST['date']) && !empty($_POST['date']) && isset($_POST['type']) && !empty($_POST['type'])) {
34         // Get the POST vars
35         $original = $_POST['content'];
36         $xid = $_POST['xid'];
37         $nick = $_POST['nick'];
38         $avatar = $_POST['avatar'];
39         $date = $_POST['date'];
40         $type = $_POST['type'];
41         
42         // Generate the XID link
43         $xid_link = 'xmpp:'.$xid;
44         
45         if($type == 'groupchat')
46                 $xid_link .= '?join';
47         
48         // Generates the avatar code
49         if($avatar != 'none')
50                 $avatar = '<div class="avatar-container">'.$avatar.'</div>';
51         else
52                 $avatar = '';
53         
54         // Generates an human-readable date
55         $date = explode('T', $date);
56         $date = explode('-', $date[0]);
57         $date = $date[2].'/'.$date[1].'/'.$date[0];
58         
59         // Generate some values
60         $content_dir = '../store/logs/';
61         $filename = 'chat_log-'.md5($xid.time());
62         $filepath = $content_dir.$filename.'.html';
63         
64         // Generate Jappix logo Base64 code
65         $logo = base64_encode(file_get_contents(JAPPIX_BASE.'/img/sprites/logs.png'));
66         
67         // Create the HTML code
68         $new_text_inter = 
69 '<!DOCTYPE html>
70 <html>  
71
72 <head>
73         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
74         <title>'.$nick.' ('.$xid.')</title>
75         <style type="text/css">
76                 * {
77                         margin: 0;
78                         padding: 0;
79                 }
80                 
81                 body {
82                         background-color: #424242;
83                         font-family : Verdana, Arial, Helvetica, sans-serif;
84                         font-size: 0.8em;
85                         text-shadow: 0 0 5px white;
86                         color: white;
87                         margin: 8px;
88                         padding: 8px 12px;
89                 }
90                 
91                 a {
92                         color: white;
93                 }
94                 
95                 #head {
96                 
97                 }
98                 
99                 #head .avatar-container {
100                         text-align: center;
101                         float: left;
102                         height: 70px;
103                         width: 70px;
104                         margin-right: 18px;
105                 }
106                 
107                 #head .avatar {
108                         max-height: 70px;
109                         max-width: 70px;
110                 }
111                 
112                 #head h1 {
113                         font-size: 2.2em;
114                         margin: 0;
115                         text-shadow: 1px 1px 1px black;
116                 }
117                 
118                 #head h3 {
119                         font-size: 0.95em;
120                         margin: 0;
121                 }
122                 
123                 #head h5 {
124                         font-size: 0.9em;
125                         margin: 8px 0 16px 0;
126                 }
127                 
128                 #head h3,
129                 #head h5 {
130                         text-shadow: 0 0 1px black;
131                 }
132                 
133                 #head a.logo {
134                         position: absolute;
135                         top: 16px;
136                         right: 20px;
137                 }
138                 
139                 #content {
140                         background-color: #e8f1f3;
141                         color: black;
142                         padding: 14px 18px;
143                         border-radius: 4px;
144                         clear: both;
145                         -moz-border-radius: 4px;
146                         -webkit-border-radius: 4px;
147                         box-shadow: 0 0 20px #202020;
148                         -moz-box-shadow: 0 0 20px #202020;
149                         -webkit-box-shadow: 0 0 20px #202020;
150                 }
151                 
152                 #content a {
153                         color: black;
154                 }
155                 
156                 #content .one-group {
157                         border-bottom: 1px dotted #d0d0d0;
158                         padding-bottom: 8px;
159                         margin-bottom: 10px;
160                 }
161                 
162                 #content .one-group b.name {
163                         display: block;
164                         margin-bottom: 4px;
165                 }
166                 
167                 #content .one-group b.name.me {
168                         color: #123a5c;
169                 }
170                 
171                 #content .one-group b.name.him {
172                         color: #801e1e;
173                 }
174                 
175                 #content .one-group span.date {
176                         float: right;
177                         font-size: 0.9em;
178                 }
179                 
180                 #content .user-message {
181                         margin-bottom: 3px;
182                 }
183                 
184                 #content .system-message {
185                         color: #053805;
186                         margin-bottom: 3px;
187                         padding-left: 0 !important;
188                 }
189                 
190                 #content .system-message a {
191                         color: #053805;
192                 }
193                 
194                 .hidden {
195                         display: none !important;
196                 }
197         </style>
198 </head>
199
200 <body>
201         <div id="head">
202                 '.$avatar.'
203                 
204                 <h1>'.$nick.'</h1>
205                 <h3><a href="'.$xid_link.'">'.$xid.'</a></h3>
206                 <h5>'.$date.'</h5>
207                 
208                 <a class="logo" href="https://project.jappix.com/" target="_blank">
209                         <img src="data:image/png;base64,'.$logo.'" alt="" />
210                 </a>
211         </div>
212         
213         <div id="content">
214                 '.$original.'
215         </div>
216 </body>
217 </html>'
218 ;
219         
220         $new_text = stripslashes($new_text_inter);
221         
222         // Write the code into a file
223         file_put_contents($filepath, $new_text);
224         
225         // Security: remove the file and stop the script if too bit (+6MiB)
226         if(filesize($filepath) > 6000000) {
227                 unlink($filepath);
228                 exit;
229         }
230         
231         // Return to the user the generated file ID
232         exit($filename);
233 }
234
235 ?>