summaryrefslogtreecommitdiff
path: root/index.php
blob: 6b88a379898b2454696cc95a1bf54653db00f2e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
<?php

/**
 * index.php - Part of the dri-devel IRC logging facilities 
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * Copyright (C) 2009-2012 Christoph Brill <egore911@egore911.de>
 */

require_once('common.inc.php');

if (isset($date)) {
	$title = 'IRC Logs of #'.$channel.' on irc.freenode.net for '.$date;
	$oneday = new DateInterval("P1D");
	$prevday = date_sub(date_create_from_format("Y-m-d", $date), $oneday)->format("Y-m-d");
	$nextday = date_add(date_create_from_format("Y-m-d", $date), $oneday)->format("Y-m-d");

	// Set a cookie to store the reference to the last time we showed the log
	if (isset($_COOKIE[$channel . '_last_visit'])) {
		$last_visit = $_COOKIE[$channel . '_last_visit'];
		if ($date == date('Y-m-d', $last_visit)) {
			$last_visit = date('H:i', $last_visit);
			setcookie($channel . '_last_visit', time(), time()+2592000);
		} else {
			unset($last_visit);
		}
	} else {
		setcookie($channel . '_last_visit', time(), time()+2592000);
	}

} else {
	$title = 'DRI IRC log overview';
}
$show_html = !isset($_GET['channel']) || (isset($_GET['show_html']) && $_GET['show_html'] == 'true');
$show_joins = isset($_GET['show_joins']) && $_GET['show_joins'] == 'true';
$show_irssi = isset($_GET['show_irssi']) && $_GET['show_irssi'] == 'true';
$highlight_names = isset($_GET['highlight_names']) ? $_GET['highlight_names'] : (isset($_COOKIE['stored_users']) ? $_COOKIE['stored_users'] : '');
if ($highlight_names == '') {
	$users = array();
} else {
	$users = explode(';', $highlight_names);
}
if (isset($_GET['highlight_names'])) {
	setcookie('stored_users', $highlight_names, time()+2592000);
}

$colors = array('#009900', '#CC3300', '#330099', '#FF6600', '#CC33CC', '#66CCCC', '#FF0066', '#9900FF', '#00FFCC', '#6600FF');

echo '<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <title>'.$title.'</title>
  <link rel="shortcut icon" href="favicon.ico" />
  <style type="text/css">
body { font-family:monospace; }
h1 { text-align: center; }
#setupdiv {position: absolute; top: 8.6em; right: 2em; width: 18em; background-color:white; border:solid 1px gray; padding: 10px;}
html>body #setupdiv { position: fixed; }
  </style>
  <script src="js/date-functions.js" type="text/javascript"></script>
  <script src="js/datechooser.js" type="text/javascript"></script>
  <link rel="stylesheet" type="text/css" href="css/datechooser.css"/>
  <!--[if lte IE 6.5]>
  <link rel="stylesheet" type="text/css" href="css/select-free.css"/>
  <![endif]-->'.PHP_EOL;

include_once("analyticstracking.php");

if (isset($date)) {
	echo '	<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.5.3-crypto-sha1.js"></script>
	<script type="text/javascript">
<!--

function showHideMenu() {
	var setupdiv = document.getElementById("setupdiv");
	showhidebutton = document.getElementById("showhidebutton");
	showhidebuttonimage = document.getElementById("showhidebuttonimage");

	if (setupdiv.style.visibility == "hidden") {
		setupdiv.style.visibility = "";
		showhidebutton.title = "Hide menu";
		showhidebuttonimage.src = "images/application_form_delete.png";
	} else {
		setupdiv.style.visibility = "hidden";
		showhidebutton.title = "Show menu";
		showhidebuttonimage.src = "images/application_form.png";
	}
}

function prevDay() {
	$s = document.getElementById("date");
	$s.value="' . $prevday . '";
	document.getElementById("datepick").submit();
}
function nextDay() {
	$s = document.getElementById("date");
	$s.value="' . $nextday . '";
	document.getElementById("datepick").submit();
}

function addUser(username) {

	// The user was already in the list
	if (document.setup.highlight_names.value.indexOf(username) >= 0) {

		// Remove the username from the list
		var myvalue = document.setup.highlight_names.value;
		myvalue = myvalue.replace(username, "");
		myvalue = myvalue.replace(/;;/g,";");
		myvalue = myvalue.replace(/^;/, "");
		myvalue = myvalue.replace(/;$/, "");
		document.setup.highlight_names.value = myvalue;

		// Unmark the lines of the user
		for (var k = 0; k < document.styleSheets.length; k++) {
			var rules = document.styleSheets[k].cssRules || document.styleSheets[k].rules;
			for (var x = 0; x < rules.length; x++) {
				if (rules[x].selectorText == (\'span.user_\' + username)) {
					rules[x].style.color = \'\';
				}
			}
		}

		// Now drop the username from the colorlist
		var colorlist = document.getElementById(\'usernames\');
		var colorlistelement = document.getElementById(\'user_\' + username);
		colorlist.removeChild(colorlistelement);

	} else {

		// Add the username to the list
		if (document.setup.highlight_names.value != \'\') {
			document.setup.highlight_names.value += \';\';
		}
		document.setup.highlight_names.value += username;

		// Mark all the lines of the newly selected user
		var color = Crypto.SHA1(username).substr(0, 6);
		var styleSheet = document.styleSheets[0];
		if (styleSheet.addRule) {
			styleSheet.addRule(\'span.user_\' + username , \'color: #\' + color, 0);
		} else if (styleSheet.insertRule) {
			styleSheet.insertRule(\'span.user_\' + username + \' { color: #\' + color + \'; }\', 0);
		} else {
			document.getElementById("datepick").submit();
		}

		// Now add the username to the colorlist
		var colorlist = document.getElementById(\'usernames\');
		var colorlistelement = document.createElement(\'span\');
		colorlistelement.setAttribute(\'id\', \'user_\' + username);
		colorlistelement.setAttribute(\'class\', \'user_\' + username);
		colorlistelement.style.display = \'block\';
		colorlistelement.innerHTML = \'<a href="javascript:addUser(\\\'\' + username + \'\\\');" style="color: inherit;">\' + username + \'</a>\';
		colorlist.appendChild(colorlistelement);
	}
}

// Stuff for drag and drop copied from http://aktuell.de.selfhtml.org/artikel/dhtml/draganddrop/

//Das Objekt, das gerade bewegt wird.
var dragobjekt = null;

// Position, an der das Objekt angeklickt wurde.
var dragx = 0;
var dragy = 0;

// Mausposition
var posx = 0;
var posy = 0;


function draginit() {
 // Initialisierung der  berwachung der Events

  document.onmousemove = drag;
  document.onmouseup = dragstop;
}


function dragstart(element) {
   //Wird aufgerufen, wenn ein Objekt bewegt werden soll.
  dragobjekt = element;
  dragx = posx - dragobjekt.offsetLeft;
  dragy = posy - dragobjekt.offsetTop;
}


function dragstop() {
  //Wird aufgerufen, wenn ein Objekt nicht mehr bewegt werden soll.
  dragobjekt=null;
}


function drag(ereignis) {
  //Wird aufgerufen, wenn die Maus bewegt wird und bewegt bei Bedarf das Objekt.

  posx = document.all ? window.event.clientX : ereignis.pageX;
  posy = document.all ? window.event.clientY : ereignis.pageY;
  if(dragobjekt != null) {
    dragobjekt.style.left = (posx - dragx) + "px";
    dragobjekt.style.top = (posy - dragy) + "px";
  }
}


//-->
  </script>'.PHP_EOL;

	if (count($users) > 0) {
		echo '	<style type="text/css">'.PHP_EOL;
		foreach ($users as $user) {
			echo '		span.user_'.$user.' { '.get_color($user).'; }'.PHP_EOL;
		}
		echo '	</style>'.PHP_EOL;
	}
}

echo ' </head>
 <body onload="draginit()">'.PHP_EOL;

function get_month($filename) {
	return substr($filename, 10, 7);
}

function finish_month() {
	global $last_month, $month_counter;
	if ($last_month != '') {
		while ($month_counter++ < 32) {
			echo '    <br/>'.PHP_EOL;
		}
		$month_counter = 0;
		echo '   </div>'.PHP_EOL;
	}
}

function get_color($user) {
	global $users;
	$isUser = array_search($user, $users);
	if ($isUser !== false) {
		return 'color: #'.substr(sha1($user), 0, 6);
	}
}

if (!isset($date)) {
	echo '  <h1>'.$title.'</h1>
  <hr/>
  <form name="open_for" method="get" action="">
   <input name="channel" type="text" value="' . $channel . '" style="display: none; visibility: hidden;"/>
   <label for="date">Enter date of the log to open:</label>
   <input id="date" size="10" maxlength="10" name="date" value="'.date('Y-m-d').'" onkeyup="javascript:makeValid(\'date\')" onblur="javascript:makeValidFinal(this, \'date\', \'date_chooser\', 1950, 2049, Date.patterns.ISO8601ShortPattern, false)" type="text"/><img src="images/calendar.png" alt="Choose date" onclick="showChooser(this, \'date\', \'date_chooser\', 1950, 2049, Date.patterns.ISO8601ShortPattern, false);"/><div id="date_chooser" class="dateChooser select-free" style="display: none; visibility: hidden; width: 160px;"></div>
   <input value="OK" type="submit"/>
  </form>
  <hr/>'.PHP_EOL;

	if ($handle = opendir(LOG_DIR)) {
		// Get the files sorted by name
		$files = array();
		while (false !== ($file = readdir($handle))) {
			if (substr($file, -4) == '.log' && !is_dir($file))
				$files[] = $file;
		}
		closedir($handle);
		rsort($files);

		$last_month = '';
		$month_counter = 0;
		// Border for all month blocks, floating so it will put them right
		echo '  <div style="float: right; width: 100%;">'.PHP_EOL;
		foreach ($files as $file) {
			$month = get_month($file);
			if ($last_month != $month) {
				finish_month();
				$last_month = $month;
				echo '   <div style="border: 1px solid gray; margin: 10px; padding: 20px; float: left;">'.$month.'<hr/>'.PHP_EOL;
			}
			echo '    <a href="?channel='.$channel.'&date='.get_date($file).'">'.get_date($file).'</a> <a href="'.LOG_DIR.'/'.$file.'">(raw)</a><br/>'.PHP_EOL;
			$month_counter++;
		}
		finish_month();
		echo '  </div>'.PHP_EOL;
	}
} else {
	echo '  <h1>'.$title.'</h1>
  <hr/>
  <form id="datepick" name="setup" action="" method="get">
   <div style="right: 5px; top: 5px; visibility: hidden" id="setupdiv" onmousedown="dragstart(this)">'.PHP_EOL;
	$even = false;
	foreach ($channels as $c) {
		echo '    <label><input name="channel" value="'.$c.'"'.($c == $channel ? ' checked="checked"' : '').' type="radio"/>'.$c.'</label>'.($even ? '<br/>' : '').PHP_EOL;
		$even = !$even;		
	}
	echo '    <hr/>
    <input name="show_joins" value="true" type="checkbox"'.($show_joins ? ' checked="checked"' : '').'/>Show Joins/Disconnects<br/>
    <input name="show_irssi" value="true" type="checkbox"'.($show_irssi ? ' checked="checked"' : '').'/>Show IRSSI<br/>
    <input name="show_html" value="true"'.($show_html ? ' checked="checked"' : '').' type="checkbox"/>Linkify HTML<br/>
    <label for="highlight_names">Highlight names:</label><input id="highlight_names" name="highlight_names" type="text" value="'.$highlight_names.'"/>
    <input value="Update" type="submit"/>
    <div id="usernames">'.PHP_EOL;
	foreach ($users as $user) {
		echo '<span class="user_'.$user.'" id="user_'.$user.'" style="display: block;"><a style="color: inherit;" href="javascript:addUser(\''.$user.'\');">'.$user.'</a></span>'.PHP_EOL;
	}
	echo '    </div>
  </div>
   <label for="date">Enter date of the log to open:</label>'.PHP_EOL;
	if (file_exists(LOG_DIR.'dri-devel-' . $prevday . '.log')) {
		echo '<a href="#" title="Previous day" onclick="prevDay(); return false;"><img src="images/play_blue_rev.png" /></a>';
	} else {
		echo '<img src="images/play_gray_rev.png" title="Previous day" />';
	}
	echo '<input id="date" size="10" maxlength="10" name="date" value="'.$date.'" onkeyup="javascript:makeValid(\'date\')" onblur="javascript:makeValidFinal(this, \'date\', \'date_chooser\', 1950, 2049, Date.patterns.ISO8601ShortPattern, false)" type="text"/><img src="images/calendar.png" alt="Choose date" onclick="showChooser(this, \'date\', \'date_chooser\', 1950, 2049, Date.patterns.ISO8601ShortPattern, false);"/><div id="date_chooser" class="dateChooser select-free" style="display: none; visibility: hidden; width: 160px;"></div>';
	if (file_exists(LOG_DIR.'dri-devel-' . $nextday . '.log')) {
		echo '<a href="#" title="Next day" onclick="nextDay(); return false;" ><img src="images/play_blue.png" /></a>'.PHP_EOL;
	} else {
		echo '<img src="images/play_gray.png" title="Next day" />'.PHP_EOL;
	}
	echo '   <input value="OK" type="submit"/>
   <a href="#" onclick="showHideMenu(); return false;" title="Show menu" id="showhidebutton"><img id="showhidebuttonimage" src="images/application_form.png" /></a>'.PHP_EOL;
	echo '  </form>
 <hr/>'.PHP_EOL;
	$filename = 'dri-devel-'.$date.'.log';

	$pattern = '#(^|[^\"=]{1})(http://|ftp://|mailto:|news:)([^\s<>]+)([\s\n<>]|$)#sm';

	$timehashes = array();
	$lines = file(LOG_DIR.$filename);
	foreach ($lines as $line_num => $line) {
		if (is_from_selected_channel($line, $channel)) {
			if (!filter_join($line)) {
				$user = get_user($line);
				$user_clean = substr($user, 2, -1);
				if (in_array($user_clean, $ignore)) {
					continue;
				}
				$user = htmlentities($user, ENT_QUOTES);
				$time = get_time($line);
				if (isset($last_visit) && $last_visit < $time) {
					echo '<hr/>';
					unset($last_visit);
				}
				echo '<span class="user_'.$user_clean.'">';
				$line = htmlentities($line, ENT_QUOTES);
				if ($show_html == 'true') {
					$line = preg_replace($pattern, "\\1<a href=\"\\2\\3\">\\2\\3</a>\\4", $line);
				}
				$user_link = '<a style="color: inherit;" href="javascript:addUser(\''.$user_clean.'\');"';
				if (isset($realname[$user_clean])) {
					$user_link .= ' title="'.$realname[$user_clean].'"';
				}
				$user_link .= '>'.str_replace('<', '&lt;', str_replace('>', '&gt;', $user)).'</a>';
				if (!in_array($time, $timehashes)) {
					$time_link = '<a name="t-'.str_replace(':', '', $time).'">'.$time.'</a>';
					$line = str_replace($time, $time_link, $line);
					array_push($timehashes, $time);
				}
				echo str_replace($user, $user_link, $line),'<br/>';
				echo '</span>';
			}
		}
	}
}

/*
$lines = file('index.txt');
error_reporting(E_ALL);
foreach ($lines as $line_num => $filename) {
	$filename = str_replace(array("\n", "\r"), '', $filename);

	if (file_exists(LOG_DIR.$filename) == TRUE) {
		$color = 'green';
	} else {
		$color = 'red';
	}
	echo '<span style="color: '.$color.'">'.$filename.'</span><br/>';
}*/

echo '  &nbsp;<br/>
  <hr/>
  <span>Written by <a href="mailto:egore911%20-%20at%20%21%20egore911%20/%20de">Christoph Brill</a> © 2007-'.date('Y').'</span>
  <p style="text-align: center;">
   <a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10"  style="border: none;" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a><br/><br/>
   <a href="https://play.google.com/store/apps/details?id=de.egore911.drilog"><img src="http://www.android.com/images/brand/android_app_on_play_logo_small.png" style="border: none;" alt="Available in Android Market" height="45" width="129" /></a>
  </p>
 </body>
</html>'.PHP_EOL;

?>