Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
6 kaklik 1
<?php
2
 
3
/************************************************************************/
4
/* G-Shout : Gravitasi Shoutbox                                         */
5
/* ============================================                         */
6
/*                                                                      */
7
/* Copyright (c) 2005 by Yohanes Pradono                                */
8
/* http://gravitasi.com                                                 */
9
/*                                                                      */
10
/* This program is free software. You can redistribute it and/or modify */
11
/* it under the terms of the GNU General Public License as published by */
12
/* the Free Software Foundation; either version 2 of the License.       */
13
/*                                                                      */
14
/************************************************************************/
15
 
16
// to prevent direct access
17
if (eregi("functions.inc.php",$_SERVER['PHP_SELF'])) {           
18
	die("<b>Access Denied!</b><br /><i>You can't access this file directly...</i><br /><br />- G-Shout -");
19
}
20
 
21
// functions to count the page generation time (from phpBB2)
22
// ( or just any time between timer_start() and timer_stop() )
23
 
24
function timer_start() {
25
    global $timestart;
26
    $mtime = microtime();
27
    $mtime = explode(" ",$mtime);
28
    $mtime = $mtime[1] + $mtime[0];
29
    $timestart = $mtime;
30
    return true;
31
}
32
 
33
function timer_stop($display=0,$precision=3) { //if called like timer_stop(1), will echo $timetotal
34
    global $timestart,$timeend;
35
    $mtime = microtime();
36
    $mtime = explode(" ",$mtime);
37
    $mtime = $mtime[1] + $mtime[0];
38
    $timeend = $mtime;
39
    $timetotal = $timeend-$timestart;
40
    if ($display)
41
        echo number_format($timetotal,$precision);
42
    return $timetotal;
43
}
44
 
45
//starting to count the page generation time
46
timer_start();
47
 
48
include("./includes/globals.inc.php");
49
include("config.php");
50
include("./languages/lang-".$language.".php");
51
 
52
// format date with GMT different
53
function formattanggal($tgl) {
54
	global $gmt,$dateformat;
55
	$timeadjust = ($gmt * 60 * 60);
56
	$waktu = gmdate($dateformat,$tgl + $timeadjust);
57
 
58
	//days
59
	$waktu = str_replace("Sunday", _SUNDAY, $waktu);
60
	$waktu = str_replace("Monday", _MONDAY, $waktu);
61
	$waktu = str_replace("Tuesday", _TUESDAY, $waktu);
62
	$waktu = str_replace("Wednesday", _WEDNESDAY, $waktu);
63
	$waktu = str_replace("Thursday", _THURSDAY, $waktu);
64
	$waktu = str_replace("Friday", _FRIDAY, $waktu);
65
	$waktu = str_replace("Saturday", _SATURDAY, $waktu);
66
 
67
	//months
68
	$waktu = str_replace("January", _JANUARY, $waktu);
69
	$waktu = str_replace("February", _FEBRUARY, $waktu);
70
	$waktu = str_replace("March", _MARCH, $waktu);
71
	$waktu = str_replace("April", _APRIL, $waktu);
72
	$waktu = str_replace("May", _MAY, $waktu);
73
	$waktu = str_replace("June", _JUNE, $waktu);
74
	$waktu = str_replace("July", _JULY, $waktu);
75
	$waktu = str_replace("August", _AUGUST, $waktu);
76
	$waktu = str_replace("September", _SEPTEMBER, $waktu);
77
	$waktu = str_replace("October", _OCTOBER, $waktu);
78
	$waktu = str_replace("November", _NOVEMBER, $waktu);
79
	$waktu = str_replace("December", _DECEMBER,$waktu);
80
 
81
    return $waktu;
82
}
83
 
84
 
85
/* function to display random images,
86
 * borrowed from rid.php script by Nenad Motika [nmotika@bezveze.com]
87
 * URL : http://www.bezveze.com/skripte/rid/
88
 */
89
function displayRandomImage($dirname) {
90
	$folder=opendir($dirname);
91
	while ($file = readdir($folder)) $names[count($names)] = $file;
92
	closedir($folder);//sort file names in array
93
	sort($names);
94
	//remove any non-images from array
95
	$tempvar=0;
96
	for ($i=0;$names[$i];$i++){
97
		$ext=strtolower(substr($names[$i],-4));
98
		if ($ext==".jpg"||$ext==".gif"||$ext=="jpeg"||$ext==".png"){
99
			$names1[$tempvar]=$names[$i];$tempvar++;
100
			}
101
		}
102
//random
103
srand ((double) microtime() * 10000000);
104
$rand_keys = array_rand ($names1, 2);
105
//random image from array
106
$slika=$names1[$rand_keys[0]]; 
107
//image dimensions
108
$dimensions = GetImageSize($dirname.$slika);
109
//if (isset($pic)){header ("Location: $slika");}      //original, commented out
110
//else {echo "<img src=\"$slika\" $dimensions[3]>";}  //original, commented out
111
$imageurl = $dirname.$slika;                          //added this
112
  return $imageurl;                                   //added this
113
 
114
}
115
#####################
116
 
117
// function to check website / email address
118
function check_uri($address) {
119
	return eregi('^([:/~@a-zA-Z0-9_\-\.]+)\.([:/~a-zA-Z0-9]+)$',$address);
120
}
121
 
122
//funtion to encode email address
123
function hex_encode($email_address) {
124
	for ($x=0; $x < strlen($email_address); $x++) {
125
		$encoded .= '%' . bin2hex($email_address[$x]);
126
		}
127
return $encoded; 
128
} 
129
function hexentity_encode($email_address) {
130
	for ($x=0; $x < strlen($email_address); $x++) {
131
		$encoded .= '&#x' . bin2hex($email_address[$x]);
132
		}
133
	return $encoded;
134
}
135
 
136
function remQuote($theQ) {
137
	$trans = array ("\'" => "'", "\\\"" => "\"");
138
	return strtr(chop($theQ), $trans);
139
}
140
 
141
/****************************************************************
142
these 2 functions are used to view shoutbox in frontpage side
143
*****************************************************************/
144
// to format the table layout
145
function content($id,$com,$nam,$sex,$uri,$timestamp,$ip,$reply,$redate) {
146
	global $hr, $namaadmin, $deletetime, $adminweb, $entry, $require_uri, $gmt;
147
	$com = remQuote($com);
148
	if($hr == "yes") {
149
		$hrbar = "<hr align=\"center\" />";
150
	} else {
151
		$hrbar = "";
152
	}
153
 
154
	if ($sex == "m") {
155
		$urlsexm = displayRandomImage("images/male/");
156
		$sex = "<img alt=\""._MALE."\" title=\""._MALE."\" src=\"$urlsexm\" width=\"24\" height=\"24\" />";
157
	} else if ($sex == "f") {
158
		$urlsexf = displayRandomImage("images/female/");
159
		$sex = "<img alt=\""._FEMALE."\" title=\""._FEMALE."\" src=\"$urlsexf\" width=\"24\" height=\"24\" />";
160
	} else {
161
		$sex = "<img alt=\"unknown\" title=\"unknown\" src=\"images/unknown.gif\" width=\"24\" height=\"24\" />";
162
	}
163
 
164
	// older shouts before version 1.0 won't be processed by formattanggal()
165
	if (is_numeric($timestamp)) {
166
		$tgltime = $timestamp;
167
		$tgl = formattanggal($timestamp);
168
		} else {
169
			$tgl = $timestamp;
170
	}
171
 
172
	// check the $gmt value
173
	if(substr($gmt,0,1)=="-"){
174
	$tz_info = "(GMT".$gmt.")";
175
	}else if($gmt == "0") {
176
	$tz_info = "(GMT)";
177
	} else {
178
	$tz_info = "(GMT+".$gmt.")";
179
	}
180
 
181
		$style = ($entry % 2) ? 'tableCellOne' : 'tableCellTwo';
182
		echo "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" class=\"$style\"><tr><td title=\""._SHOUTED_ON." ".$tgl." ";
183
		echo $tz_info;
184
		echo "\"><p align=\"justify\">$sex&nbsp;";
185
 
186
		if(empty($uri)){
187
			echo ("<b>$nam</b>");
188
		} else {
189
				$uri = strip_tags(checkUri(chop($uri)));
190
				echo ("<a href=\"$uri\" target=\"_blank\">$nam</a>");
191
		}
192
 
193
			echo ": $com </p></td><tr><td>";
194
 
195
		if (($ip == $_SERVER["REMOTE_ADDR"]) && ($timestamp > time()-ceil($deletetime*60))){
196
			echo "<a class=\"delete\" href=\"shoutbox.php?action=deleteshout&amp;id=$id\" onclick=\"return confirm('You are about to delete this shout \\n  \'OK\' to delete, \'Cancel\' to stop.')\">delete</a>";
197
			}
198
 
199
		echo "</td></tr>";
200
		if ($reply!=""){
201
			echo "<tr><td title=\""._REPLIED_ON." ".formattanggal($redate)." ";
202
			echo $tz_info;
203
			echo "\"><i><a href=\"#\">$namaadmin</a> : $reply</i></tr></td>";
204
			}
205
		echo "</table>$hrbar";
206
 
207
} //end of showTag
208
 
209
/********************************************
210
FUNCTION TO SHOW THE SHOUTS FROM FRONT PAGE
211
*********************************************/
212
function viewShoutBox() {
213
	global $datafile, $page, $commentshown, $smileys, $smileydir, $maxchars, $allowedtags, $usesmiley, $useHTMLencode, $textwrappingwidth, $namaadmin, $help;
214
 
215
// pagination system
216
if (!isset($page)||$page==0) {
217
	$page=1;
218
}
219
$entry = ($commentshown * $page)-$commentshown;
220
$selesai = $commentshown*$page;
221
 
222
$d = array();
223
require_once($datafile);
224
 
225
 
226
	array_walk ($smileys, 'alter_smiley', $smileydir);
227
	reset ($smileys);
228
	while (chop($d[$entry]) != "" && $help != true && $entry < $selesai) {
229
		$temporary = explode("#%", $d[$entry]);
230
		$id = $temporary[0];
231
		$com = $temporary[1];
232
 
233
		if($maxchars != "" && $maxchars > 0) {
234
			$com = substr ($com, 0, $maxchars);
235
		} else {
236
 
237
		}
238
 
239
		if($allowedtags == "") {
240
			$com = htmlspecialchars($com);
241
		}
242
 
243
//		$transi = array ("< " => "&lt; ", " >" => " &gt;");
244
//		$com = strtr(chop($com), $transi);
245
 
246
		$com = strip_tags(chop($com), $allowedtags);
247
		if($usesmiley == "yes") {
248
			$com = strtr($com, $smileys);
249
		}
250
		if($useHTMLencode == "yes") {
251
			$com = HTMLEncode($com);
252
		}
253
		if($textwrappingwidth != "0"){
254
			$com = ww1($com);
255
		}
256
 
257
if($temporary[1] != $namaadmin){
258
$nam = ucfirst(chop($temporary[2]));//nama hurup gede untuk tamu
259
}else{
260
$nam = chop($temporary[2]);
261
}
262
		//if($usetextwrapping) {
263
		if($textwrappingwidth != "0"){
264
			$nam = ww2($nam);
265
		}
266
		$nam = stripslashes(strip_tags($nam));//added this
267
		$nam = htmlspecialchars($nam);
268
		$sex = $temporary[3];
269
		$uri = $temporary[4];
270
		$tgl = $temporary[5];
271
		$ip = $temporary[6];
272
		$reply = $temporary[7];
273
		if($usesmiley == "yes") {
274
			$reply = strtr($reply, $smileys);
275
			}
276
		if($textwrappingwidth != "0"){
277
			$reply = ww1($reply);
278
			//$reply = ww2($reply);
279
		}
280
		$redate = $temporary[8];
281
 
282
		content($id,$com,$nam,$sex,$uri,$tgl,$ip,$reply,$redate);
283
		$entry++;
284
	} // end while
285
 
286
}// end of viewShoutBox()
287
 
288
//function to show Shout Entry from Control Panel
289
function showEntryfromCPanel($id,$com,$nam,$sex,$uri,$timestamp,$ip,$reply,$redate) {
290
	global $entry, $status, $page, $usesmiley, $smileys, $smileydir ;
291
	$style = ($entry % 2) ? 'tableCellOne' : 'tableCellTwo';
292
 
293
	if ($sex == "m"){
294
		$esex = _M;
295
	}else if($sex == "f"){
296
		$esex = _F;
297
	} else {}
298
 
299
	if ($redate != ""){
300
		$formatted_redate = formattanggal($redate);
301
		} else {
302
			$formatted_redate = "";
303
	}
304
 
305
if ($id != ""){
306
echo "
307
<tr>
308
 
309
<td class=\"$style\">
310
$id
311
</td>
312
 
313
<td class=\"$style\">
314
".formattanggal($timestamp)."
315
</td>
316
 
317
<td class=\"$style\">
318
".wordwrap_cpanel(htmlentities($com))."
319
</td>
320
 
321
<td class=\"$style\">
322
$nam
323
</td>
324
 
325
<td class=\"$style\">
326
$esex
327
</td>
328
 
329
<td class=\"$style\">
330
$ip
331
</td>
332
 
333
<td class=\"$style\">
334
<a href=\"".checkUri($uri)."\" target=\"_blank\">$uri</a>
335
</td>
336
 
337
<td class=\"$style\">
338
$formatted_redate
339
</td>
340
 
341
<td class=\"$style\">
342
<div style=\"color: rgb(0, 153, 51);\">".wordwrap_cpanel($reply)."</div>
343
</td>
344
 
345
<td class=\"$style\">
346
<!--
347
<a href=\"editshout.php?id=$id&amp;page=$page\">"._EDIT."</a>
348
-->
349
<a href=\"javascript:void(0)\" onclick=\"window.open('pop_editshout.php?id=$id&amp;page=$page','editshout','width=400,height=500,location=0,menubar=0,toolbar=0,scrollbars=yes,resizable=0,status=1,screenx=245,screeny=102')\" >"._EDIT."</a>
350
</td>
351
 
352
<td class=\"$style\">
353
<input class=\"checkbox\" name=\"toggle[]\" value=\"$id\" type=\"checkbox\">
354
</td>
355
 
356
</tr>
357
";
358
}
359
 
360
}
361
 
362
/**************************************************** 
363
 
364
main function writeTag() to write into Database File
365
 
366
*****************************************************/
367
function writeTag($nama, $kelamin, $uri, $comment) {
368
	global $datafile, $commentshown, $keep, $namaadmin, $errors, $gnama, $gsex, $guri, $gcomment, $ccmail, $bccmail, $emailaddress, $body, $extra_hdr_str, $require_uri;
369
 
370
	$trans = array ( "\n" => "<br />", "\r" => " ", "#%" => "");
371
 
372
	if (!is_writeable($datafile)) {
373
//		echo("<b>Unable to inisiate command.</b><br />It is either the file \"$datafile\" doesn't exist or the file is not set to writeable. Please refer to config file on how.<br /><br />");
374
//		chmod($datafile, 0666 );  
375
//		$file = fopen($datafile, "w+");
376
//		fwrite($file, $comment."#%");
377
//		fwrite($file, "$nama#%$uri#%".gettanggal()."#%\n");
378
//		fclose($file);
379
 
380
	} else if (chop($nama) == '' || chop($uri) == '' || chop($comment) == '') {
381
		echo("<div class=\"alert\"><b>Error!</b><br /><i>"._ERROR_EMPTY."</i></div><br /><br />");
382
	}
383
	else if ($_POST['gname'] == _DEFAULT_NAME || $nama == "") {// if the name field = default value 
384
		echo("<div class=\"alert\"><b>Error!</b><br /><i>"._ERROR_NAME."</i></div><br /><br />");
385
	}
386
	else if ($kelamin == '' && $nama != $namaadmin) {// kalau nama bukan nama admin dan jenis kelamin kosong
387
		echo("<div class=\"alert\"><b>Error!</b><br /><i>"._ERROR_SEX."</i></div><br /><br />");
388
	}
389
	//pikiren dewe, males njelaske
390
	else if(($uri == _DEFAULT_URI || !check_uri($_POST['guri'])) && $require_uri == "yes") {
391
		  echo("<div class=\"alert\"><b>Error!</b><br /><i>"._ERROR_URI."</i></div><br /><br />");
392
	}
393
	else if ($comment == _DEFAULT_MESSAGE || $comment == "") {      
394
		echo("<div class=\"alert\"><b>Error!</b><br /><i>"._ERROR_MESSAGE."</i></div><br /><br />");
395
	} 
396
 
397
	else {
398
		// if user's name same with admin name
399
		if ($nama == $namaadmin) {
400
		$nama = $nama."-";
401
		}
402
		//sampek sini
403
		$comment = strtr(chop($comment), $trans);
404
		$comment = stripslashes($comment);
405
		$uri = strtr(chop($uri), $trans);
406
		if(($uri == _DEFAULT_URI || empty($_POST['guri'])) && $require_uri == "no"){
407
		$uri = "";
408
		}
409
		$nama = strtr(chop($nama), $trans);
410
        $nama = stripslashes($nama);
411
		$kelamin = strip_tags($kelamin);
412
 
413
		$fp = fopen($datafile, "r");
414
 
415
		//to give the unique ID number
416
		include_once($datafile);
417
        $ex = explode("#%",$d[0]);
418
		$id = $ex[0]+1;
419
 
420
	while (!feof($fp)){
421
		$data = fgets($fp, filesize($datafile));
422
            if (substr($data,0,2) == "<?") {
423
                $output[] = "<?php\n\$d[] = \"$id#%$nama#%$kelamin#%$uri#%".time()."#%".$_SERVER["REMOTE_ADDR"]."#%#%#%\";\n";
424
			} else if (substr($data,0,2) == '?>'){
425
				$output[] = "";
426
			} else {//nothing happened
427
				$output[] = $data;
428
			}
429
	}//end while
430
        fclose($fp);
431
        $fp = fopen($datafile,"w");
432
		if($fp){
433
        //foreach ($output as $data){
434
        //    fwrite ($fp, $data);
435
        //}
436
 
437
		for ($i=0;$i<$keep;$i++){
438
			fwrite ($fp, $output[$i]);
439
		}
440
		fwrite($fp, "?>");
441
		fclose($fp);
442
		}
443
 
444
############### to send email
445
	if ($sendcomments == "yes") {
446
	$extra_hdr_str = "From: G-Shout ".$version." <g-shout@".$_SERVER['HTTP_HOST']."> \r\nCc: $ccmail \r\nBcc: $bccmail \r\nContent-type: text/html\r\nX-Mailer: PHP/" .phpversion();
447
 
448
	$body = "<p align=\"center\">Name: $gname <br /><br /> Sex: $gsex <br /><br /> Web/Email: $guri <br /><br /> Message: $gcomment <br /><br /> IP address: ".$_SERVER["SERVER_NAME"]." <br /><br /><br /> powered by <a href=\"http://g-shout.sourceforge.net\"> target=\"_blank\">G-Shout ".$version."</a></p>";
449
 
450
    $name = $nama;
451
	$nick = $nama;
452
	$subject = _EMAIL_SUBJECT;
453
 
454
	mail($emailaddress,$subject,$body,$extra_hdr_str);
455
	}
456
############### 
457
	}
458
}
459
 
460
function sheep_wordwrap($str,$cols,$non_prop,$cut,$exclude1,$exclude2){
461
  $count=0;
462
  $tagcount=0;
463
  $str_len=strlen($str);
464
  //$cut=" $cut ";
465
  $calcwidth=0;
466
 
467
  for ($i=0; $i<=$str_len;$i++){
468
    $str_len=strlen($str);
469
    if ($str[$i]==$exclude1)
470
      $tagcount++;
471
    elseif ($str[$i]==$exclude2){
472
      if ($tagcount>0)
473
        $tagcount--;
474
    }
475
    else{
476
      if (($tagcount==0)){
477
        if (($str[$i]==' ') || ($str[$i]=="\n"))
478
          $calcwidth=0;
479
        else{
480
          if ($non_prop){
481
            if (ereg("([QWOSDGCM#@m%w]+)",$str[$i],$matches))
482
              $calcwidth=$calcwidth+7;
483
            elseif (ereg("([I?\|()\"]+)",$str[$i],$matches))
484
              $calcwidth=$calcwidth+4;
485
            elseif (ereg("([i']+)",$str[$i],$matches))
486
              $calcwidth=$calcwidth+2;
487
            elseif (ereg("([!]+)",$str[$i],$matches))
488
              $calcwidth=$calcwidth+3;
489
            elseif (ereg("([&#x]+)",$str[$i],$matches))// hexentity
490
              $calcwidth=$calcwidth+2;
491
            else{
492
              $calcwidth=$calcwidth+5;
493
            }
494
          }
495
          else{
496
            $calcwidth++;
497
          }
498
          if ($calcwidth>$cols){
499
            $str=substr($str,0,$i).$cut.substr($str,$i,$str_len-1);
500
            $calcwidth=0;
501
          }
502
        }
503
      }
504
    }
505
  }
506
  return $str;
507
}
508
 
509
function ww1($stri) {
510
	global $textwrappingwidth, $wrappingseparator;
511
	$tempe = sheep_wordwrap($stri, $textwrappingwidth, true, $wrappingseparator,"<",">");
512
	return $tempe;
513
}
514
 
515
function ww2($stri) {
516
	global $textwrappingwidth, $wrappingseparator;
517
	$tempe = sheep_wordwrap($stri, round($textwrappingwidth*2/3), true, $wrappingseparator,"<",">");
518
	return $tempe;
519
}
520
 
521
$wordwrap_width = "130";// you can change this value for text wordwrap width inside Control Panel
522
function wordwrap_cpanel($stri) {
523
	global $wordwrap_width;
524
	$tempe = sheep_wordwrap($stri, $wordwrap_width, true, "- ","<",">");
525
	return $tempe;
526
}
527
 
528
function alter_smiley (&$item1, $key, $prefix) {
529
	$item1 = "<img alt=\"\" src=\"$prefix$item1\" align=\"middle\" border=\"0\" />";
530
}
531
 
532
function checkUri ($theUri) {
533
	if(!stristr($theUri, "@")) {
534
		$theUri = strtolower($theUri);
535
		if ( substr ($theUri, 0, 7) != "http://") {
536
			$theUri = "http://" . $theUri;
537
		}
538
	} else {
539
		$theUri = hex_encode($theUri); //buat mengencode email ke hex
540
		$theUri = "mailto:" . $theUri;
541
			}
542
	return $theUri;
543
}
544
 
545
function maximumCharacters() {
546
	global $maxchars;
547
	$tempe;
548
	if ($maxchars > 0) {
549
		$tempe = " maxlength=" . $maxchars . " ";
550
	}
551
	return $tempe;
552
}
553
 
554
function HTMLEncode($text) {
555
	global $urltextreplacement;
556
  $searcharray =  array(
557
   "'([-_\w\d.]+@[-_\w\d.]+)'",
558
   "'((?:(?!://).{3}|^.{0,2}))(www\.[-\d\w\.\/]+)'", 
559
   "'(http[s]?:\/\/[-_~\w\d\.\/]+)'");
560
  preg_match("([-_\w\d.]+@[-_\w\d.]+)", $text, $emailaddr);
561
  $hexmail = hex_encode($emailaddr[0]);
562
  $hexentemail = hexentity_encode($emailaddr[0]);
563
	if($urltextreplacement != '') {
564
		$replacearray = array(
565
		"<a href=\"mailto:$hexmail\">[MAIL]</a>",
566
		"\\1http://\\2",
567
		"<a target=_blank href=\"\\1\">$urltextreplacement</a>");
568
	} else {
569
		$replacearray = array(
570
		"<a href=\"mailto:$hexmail\">$hexentemail</a>",
571
		"\\1http://\\2",
572
		"<a target=_blank href=\"\\1\">\\1</a>");
573
	}
574
 
575
  return preg_replace($searcharray, $replacearray, stripslashes($text) );
576
}
577
 
578
function showHelp() {
579
	global $allowedtags, $usesmiley, $useHTMLencode, $urltextreplacement, $emailtextreplacement;
580
	echo("<center><b>Tags allowed</b>:<br />\n");
581
	if($allowedtags == "") {
582
		echo("All tags will be turned into HTML special tags");
583
	} else {
584
		echo(htmlspecialchars($allowedtags));	 
585
	}
586
	echo("</center><br /><br />\n\n");
587
	if($usesmiley) {
588
		echo("<center><b>Emoticons</b>:\n<table cellspacing=\"0\" cellpadding=\"2\" border=\"1\">\n");
589
		echo list_smileys2();
590
		echo "</table>\n";
591
		echo "<div id=\"yahoo\">Emoticons by <a href=\"htttp://www.yahoo.com\" target=\"_blank\">Yahoo!</a></div></center><br /><br />\n\n";
592
	}
593
	if($useHTMLencode) {
594
		echo("<center><b>HTML Encoding</b>:<p align=\"justify\">
595
You can type www.yoursite.com or email email@yoursite.com on shoutbox form and will be automatically changed to ");
596
		if($urltextreplacement == '') {
597
			echo("<a href=\"http://www.yoursite.com\" target=\"_blank\">http://www.yoursite.com</a> or <a href=\"mailto:".hex_encode('email@yoursite.com')."\">email@yoursite.com</a>.");
598
		}
599
		else {
600
			echo("<a href=\"http://www.yoursite.com\" target=\"_blank\">$urltextreplacement</a> or <a href=\"mailto:".hex_encode('email@yoursite.com')."\">[MAIL]</a>.");
601
		}
602
		echo("<br /> All email addresses will be encoded to prevent spamming.");
603
		echo("</p></center><hr />\n");
604
	}
605
}
606
 
607
function showEmoticons() {
608
	global $usesmiley, $smileys;
609
	if($usesmiley) {
610
		echo("<br /><center><b>Emoticons</b>:\n<table cellspacing=\"0\" cellpadding=\"2\" border=\"1\"><br /><br />\n");
611
		$i = 1;
612
		while (list ($key, $value) = each ($smileys)) {
613
			if($i==1){
614
				$str .= "<tr>\n";
615
			}
616
		$key = htmlentities($key);
617
		$str .= "<td align=\"center\" valign=\"middle\"><a class=\"icon\" href=\"#\" onclick=\"add_smiley_cp('$key')\">$value</a> &nbsp; </td>\n";
618
 
619
		if($i==4){
620
			$str .= "</tr>\n";
621
			$i = 1;
622
		} else {
623
			$i++;
624
		}
625
 
626
		}//end while
627
 
628
		echo $str;
629
		echo "</table><br /><br />\n";
630
	}
631
}
632
 
633
function list_smileys () {
634
	global $smileys;
635
	while (list ($key, $value) = each ($smileys)) {
636
		$str .= "<tr><td align=\"center\" valign=\"middle\" width=\"50%\"> &nbsp; $key &nbsp; </td><td align=\"center\" valign=\"middle\" width=\"50%\"> &nbsp; $value &nbsp; </td></tr>\n";
637
	}
638
	return $str;
639
}
640
function list_smileys2() {
641
	global $smileys;
642
	while (list ($key, $value) = each ($smileys)) {
643
		$key = htmlentities($key);
644
		$str .= "<tr><td align=\"center\" valign=\"middle\" width=\"50%\"> &nbsp; $key &nbsp; </td><td align=\"center\" valign=\"middle\" width=\"50%\"> &nbsp; <a class=\"icon\" href=\"#\" onclick=\"add_smiley('$key')\">$value</a> &nbsp; </td></tr>\n";
645
	}
646
	return $str;
647
} 
648
 
649
# these functions below borrowed from Shoutbox by Brett Taylor - http://www.addict.net.nz/~glutnix
650
 
651
function getIP($id) {
652
    global $datafile;
653
    $shouts = file($datafile); // read in shouts for count
654
    //for ($count=$start;$count<=$finish;$count++) { // original
655
	for ($count=0;$count<=count($shout);$count++) { // modified by donie
656
        $csvdata = explode("#%",$shouts[$count]);
657
        if ($csvdata[0] == $id) {
658
            break;
659
        }
660
    }
661
    return $csvdata[6];
662
}
663
 
664
// for making Cookie
665
function makeCookie($password) {
666
	global $admin_password, $autologout;
667
	if($password == $admin_password){
668
		$value = sha1($password);
669
		if(trim($autologout) == "" || $autologout == "0"){
670
		setcookie("gshout_auth", $value);
671
		} else {
672
		setcookie("gshout_auth", $value, time() + ceil($autologout*60), "/");
673
		}
674
    }
675
}
676
function delCookie() {
677
	global $autologout;
678
		if(trim($autologout) == "" || $autologout == "0"){
679
			setcookie("gshout_auth", "");
680
		} else {
681
			setcookie("gshout_auth", "", time() - ceil($autologout*60), "/");
682
		}
683
}
684
 
685
function validCookie($cookiedata) { // for authentication
686
	global $admin_password;
687
	if ($cookiedata == sha1($admin_password)) {
688
		return TRUE;
689
	} else {
690
		return FALSE;
691
	}
692
}
693
 
694
function updateShout($id,$shout,$nick,$sex,$url,$timestamp,$ip,$reply) {
695
    global $datafile, $message;
696
	$newfile = array();
697
    $shouts = fopen ($datafile, "r");
698
    $nick = str_replace("#%","",$nick);
699
    $shout = str_replace("#%","",$shout);
700
	$shout = str_replace("\n"," ",$shout);
701
    $url = str_replace("#%","",$url);
702
 
703
    $nick = stripslashes(trim($nick));
704
    $shout = stripslashes(trim($shout));
705
    $url = stripslashes(trim($url));
706
 
707
	$reply = str_replace("#%","",$reply);
708
	$reply = stripslashes(trim($reply));
709
	$reply = str_replace("\n"," ",$reply);
710
 
711
    while (!feof($shouts)) {
712
	    //$data = fgets($shouts, 8000);
713
		$data = fgets($shouts, filesize($datafile));
714
        $csvdata = explode("#%",$data);
715
 
716
		if ($csvdata[8] != "" || $reply == ""){//if reply time is not empty OR reply is empty
717
		$redate = $csvdata[8];
718
		} else {
719
			$redate = time();
720
		}
721
 
722
		if ($csvdata[0] == $id) {
723
			// found the ID, so re-write it
724
			$newfile[] = $id."#%".$shout."#%".$nick."#%".$sex."#%".$url."#%".$timestamp."#%".$ip."#%".$reply."#%".$redate."#%\n";
725
		} else {
726
            $newfile[] = $data;
727
		}
728
    }
729
    fclose ($shouts);
730
 	$o_shouts = fopen($datafile, "w");
731
	if($o_shouts){
732
	foreach ($newfile as $data){
733
		fwrite ($o_shouts, $data);
734
	}
735
	} else {
736
		return false;
737
		}
738
	fclose ($o_shouts);
739
	return true;
740
}
741
function deleteShout($id) {
742
    global $datafile;
743
	$newfile = array();
744
    $shouts = fopen ($datafile, "r");
745
 
746
$d = array();
747
require_once($datafile);
748
 
749
    while (!feof ($shouts) AND $d[$i] != '') {
750
	    //$data = fgets($shouts, 8000);
751
		$data = fgets($shouts, filesize($datafile));
752
        $csvdata = explode("#%",$d[$i]);
753
		//if ($csvdata[4] == $timestamp) {
754
 
755
		if (is_array($id) && in_array($csvdata[0],$id)){
756
			// found the ID, so don't write it
757
		} else if($csvdata[0] == $id){
758
			// found the ID, so don't write it
759
		} else {
760
			$newfile[] = $data;
761
		}
762
		$i++;
763
 
764
    }//end while
765
    fclose ($shouts);
766
 	$o_shouts = fopen($datafile, "w");
767
	foreach ($newfile as $data){
768
		fwrite ($o_shouts, $data);
769
	}
770
	fclose ($o_shouts);
771
}
772
 
773
//  Gets range of shouts from datafile
774
function getShouts ($start,$number,$dir) {
775
    global $datafile;
776
	//echo "getShouts:".$start.", ".$number.", ".$dir."<BR>";
777
    $shouts = file($datafile); // read in shouts for count
778
    for ($count=$start;$count<=$start+$number;$count++) {
779
        $csvdata = explode("#%",$shouts[$count]);
780
        $output[$count-$start]= array( 'id' => $csvdata[0],
781
			                           'com' => $csvdata[1],
782
                                       'nam' => $csvdata[2],
783
                                       'sex' => $csvdata[3],
784
                                       'uri'  => $csvdata[4],
785
                                       'timestamp' => $csvdata[5],
786
									   'ip' => $csvdata[6],
787
			                           'reply' => $csvdata[7],
788
                                     );
789
    }
790
    if ($dir == -1) {
791
        $output= array_reverse($output);
792
    }
793
    return $output;
794
}
795
function countShouts() {
796
    global $datafile;
797
	$shouts = file($datafile); // read in shouts for count
798
	$shouts = array_filter($shouts, "trim"); // remove arrays with empty value
799
	//echo "countShouts=".count($shouts)."<BR>";
800
    return count($shouts);
801
}
802
 
803
//function to update config file, not used
804
function updateConfig($variable,$value) {
805
	$baris = array();
806
    $fp = fopen ("config.php", "r");
807
    while (!feof ($fp)) {
808
		$data = fgets($fp, filesize("config.php"));
809
        $configdata = explode("=",$data);
810
		if ($configdata[0] == "$".$variable) {
811
			// found the variable, so re-write it
812
			$baris[] = $variable.' = "'.$value.'";\n';
813
			} else {
814
            $baris[] = $data;
815
			}
816
    }
817
    fclose ($fp);
818
 	$o_config = fopen("config.php", "w");
819
	if($o_config){
820
	foreach ($baris as $data){
821
		fwrite ($o_config, $data);
822
	}}
823
	fclose ($o_config);
824
}
825
 
826
function optionLanguages(){
827
	global $language;
828
	$handle=opendir("languages");
829
    while ($file = readdir($handle)) {
830
	if (ereg("^lang\-(.+)\.php$", $file, $matches)) {
831
            $langFound = $matches[1];
832
            $languageslist .= "$langFound ";
833
        }
834
    }
835
    closedir($handle);
836
    $languageslist = explode(" ", $languageslist);
837
    sort($languageslist);
838
    for ($i=0; $i < sizeof($languageslist); $i++) {
839
	if($languageslist[$i]!="") {
840
	    echo "<option value=\"$languageslist[$i]\" ";
841
		if($languageslist[$i]==$language) echo "selected=\"selected\"";
842
		echo ">".ucfirst($languageslist[$i])."</option>\n";
843
	}
844
	}
845
}
846
 
847
function optionSkins(){
848
	global $skin;
849
	$handle=opendir("skins");
850
    while ($file = readdir($handle)) {
851
	if (ereg("^(.+)\.css$", $file, $matches)) {
852
            $skinFound = $matches[1];
853
            $skinslist .= "$skinFound ";
854
        }
855
    }
856
    closedir($handle);
857
    $skinslist = explode(" ", $skinslist);
858
    sort($skinslist);
859
    for ($i=0; $i < sizeof($skinslist); $i++) {
860
	if($skinslist[$i]!="") {
861
	    echo "<option value=\"$skinslist[$i]\" ";
862
		if($skinslist[$i]==$skin) echo "selected=\"selected\"";
863
		echo ">".ucwords(str_replace("_"," ",$skinslist[$i]))."</option>\n";
864
	}
865
	}
866
}
867
 
868
 
869
# functions below is Log system
870
function writeLogs_php($ip, $action, $value) {
871
	global $secret_dir, $lastlogs;
872
	$fp = fopen($secret_dir."/logs.php","r");
873
	$value = base64_encode($value);
874
	while (!feof($fp)){
875
		$data = fgets($fp, filesize($secret_dir."/logs.php"));
876
            if (substr($data,0,2) == '<?') {
877
                $output[] = "<?php\n\$log[] = \"".time()."#%$ip#%$action#%$value#%\";\n";
878
            } else if (substr($data,0,2) == '?>') {
879
                $output[] = "";
880
			} else {//nothing happened
881
				$output[] = $data;
882
			}
883
	}//end while
884
        fclose($fp);
885
        $fp = fopen($secret_dir."/logs.php","w");
886
		if($fp){
887
        //foreach ($output as $data){
888
        //    fwrite ($fp, $data);
889
        //}
890
		for ($i=0;$i<$lastlogs;$i++){
891
			fwrite ($fp, $output[$i]);
892
			if ($i == $lastlogs-1){
893
				fwrite($fp, "?>");
894
			}
895
		}
896
		fclose($fp);
897
}
898
}
899
 
900
function viewLogs($timestamp,$ip,$action,$value){
901
	global $i;
902
	$value = base64_decode($value);
903
	$value = str_replace(">","&gt;",$value);
904
	$style = ($i % 2) ? 'tableCellOne' : 'tableCellTwo';
905
 
906
if ($timestamp != ""){
907
echo "
908
<tr>
909
<td  class='$style' >
910
".formattanggal($timestamp)."
911
</td>
912
<td  class='$style' >
913
$ip
914
</td>
915
<td  class='$style' >
916
$action
917
</td>
918
<td  class='$style' >
919
$value
920
</td>
921
</tr>
922
";
923
}
924
 
925
}
926
 
927
function countLogs() {
928
    global $logfile;
929
	$logs = file($logfile);
930
	$logs = array_filter($logs, "trim"); // remove arrays with empty value
931
    return count($logs);
932
}
933
 
934
// function for new antiflood system, started from v1.1
935
function getTimestampByIP($ip){
936
    global $datafile;
937
	$newfile = array();
938
    $shouts = fopen ($datafile, "r");
939
    while (!feof ($shouts)) {
940
		$fs = filesize($datafile);
941
		if(filesize($datafile) == "0"){
942
			$fs = "4096";
943
		}else{
944
			$fs = filesize($datafile);
945
		}
946
		$data = fgets($shouts, $fs);
947
        $csvdata = explode("#%",$data);
948
		if ($csvdata[6] == $ip) {
949
			$timestamp = $csvdata[5];
950
			break;
951
		}
952
    }//end while
953
	return $timestamp;
954
}
955
 
956
// give 1 line shout using $id
957
function getShoutByID($id){
958
    global $datafile, $com, $nam, $sex, $uri, $timestamp, $ip, $reply, $redate;
959
	$newfile = array();
960
    $shouts = fopen ($datafile, "r");
961
    while (!feof ($shouts)) {
962
		$fs = filesize($datafile);
963
		if(filesize($datafile) == "0"){
964
			$fs = "4096";
965
		}else{
966
			$fs = filesize($datafile);
967
		}
968
		$data = fgets($shouts, $fs);
969
        $temporary = explode("#%",$data);
970
		if ($temporary[0] == $id) {
971
			$com = htmlentities($temporary[1]);
972
			$nam = $temporary[2];
973
			$sex = $temporary[3];
974
			$uri = $temporary[4];
975
			$timestamp = $temporary[5];
976
			$ip = $temporary[6];
977
			$reply = $temporary[7];
978
			$redate = $temporary[8];
979
			break;
980
		}
981
    }//end while
982
}
983
 
984
?>