XtGem Forum catalog

GUESTBOOK You have been logged out.

'; setcookie ('password', ''); unset($_COOKIE['password'], $password); } if (isset($_POST['password'])) { $password = md5($_POST['password']); if ($password == md5(ADMIN_PASS)) { setcookie('password', $password); } } else { $password = isset($_COOKIE['password']) ? $_COOKIE['password'] : NULL; } ob_end_flush(); echo '

View - Sign'; echo '

'; echo ''; switch (FUNC) { /*================================*\ -- default -- \*================================*/ default: if (!$fp = @fopen(GB_FILE, 'r')) { echo '

failed to open: '.GB_FILE.'

'; break; } $i = 0; $data = NULL; $to_show = (P * MAX_PER_PAGE) - MAX_PER_PAGE; if (P > 1) echo '

Page '.P.'

'; while (!feof($fp)) { $i++; if ($i > ($to_show + MAX_PER_PAGE)) break; $data = fgets($fp, 4096); if (empty($data)) break; if ($i > $to_show) { list ($date, $name, $mesg, $ip) = str_replace('\|', '|', preg_split('/(?Name: $name
Date: ".date(DATE_FORMAT, $date)."
Message: $mesg


"); } } if ($i > MAX_PER_PAGE) { $line_count = substr_count(fread($fp, filesize(GB_FILE)), "\n") + $i; $line_count = ceil($line_count / MAX_PER_PAGE); $s = 1; $f = $line_count + 1; echo "\n".'

Page: # '; if ($line_count > MAX_PER_PAGE) { if (P < 6) { $s = 1; $f = 10; } elseif (($line_count-P) < 6) { $s = $line_count - 8; $f = $line_count; } else { $s = P -3; $f = $s + 8; } echo (P > 5) ? ' 1-' : NULL; } for ($k=$s; $k<$f; $k++) { echo ($k == P) ? "$k " : "$k "; } echo ($k <= $line_count) ? "of $line_count

" : '

'; } fclose($fp); break; /*================================*\ -- sign -- \*================================*/ case 'sign': $name = (isset($_POST['name'])) ? strip_chars($_POST['name']) : NULL; $mesg = (isset($_POST['mesg'])) ? strip_chars($_POST['mesg']) : NULL; if (isset($_POST['submit'])) { $errors = NULL; $now = time(); $name_len = strlen($name); $mesg_len = strlen($mesg); if ($name) { if ($name_len > MAX_NAME_LEN) { $errors = '- Name is too long, '.$name_len.' (Max: '.MAX_NAME_LEN.')
'; } } else { $errors = '- Name field is empty
'; } if ($mesg) { if ($mesg_len > MAX_MESG_LEN) { $errors.= '- Message is too long, '.$mesg_len.' (Max: '.MAX_MESG_LEN.')
'; } elseif ($mesg_len < MIN_MESG_LEN) { $errors.= '- Message is too short (Min: '.MIN_MESG_LEN.')
'; } } else { $errors.= '- Message field is empty
'; } if (!$fp = @fopen(GB_FILE, 'r')) { echo 'Unable to open guestbook file for reading, check location and file permissions.'; break; } list($date, , , $ip) = fgetcsv($fp, 4096, '|'); fclose($fp); if ($_SERVER['REMOTE_ADDR'] == $ip && $now < $date+POST_TIME) { $errors.= '- You are posting too soon after your last post'; } if ($errors) { echo '

'.$errors.'

'; } else { if ($name == ADMIN_USER) { if (@$_POST['pass'] != ADMIN_PASS && $password != md5(ADMIN_PASS)) { echo '

This username requires a password

'; echo '

'; break; } } $filesize = filesize(GB_FILE); $filesize = (empty($filesize)) ? 1024 : $filesize; if (!$fp = @fopen(GB_FILE, 'r+')) { echo 'Unable to open guestbook file for reading and writing, check location and file permissions.'; break; } $data = fread($fp, $filesize); rewind($fp); fwrite($fp, "$now|".str_replace("\n", NULL, str_replace('|', '\|', $name)).' |'.str_replace("\n", '
', bbcode($mesg)).' |'.$_SERVER['REMOTE_ADDR'].'|'); if (! empty($data)) fwrite($fp, "\n". $data); fclose($fp); echo '

Your message has been added
Go to the main page to view it

'; break; } } echo "\n".'



BBCode

'; break; /*================================*\ -- admin -- \*================================*/ case 'admin': if ($password == md5(ADMIN_PASS)) { if (isset($_GET['d'])) { /*================================*\ -- admin delete -- \*================================*/ if (isset($_GET['c'])) { if (!$fp = @fopen(GB_FILE, 'r')) { echo 'Unable to open guestbook file for reading , check location and file permissions.'; break; } $output = ''; while (!feof($fp)) { $line = fgets($fp, 4096); if (substr($line, 0, 10) == $_GET['d']) { $output .= fread($fp, filesize(GB_FILE)); fclose($fp); if (!$fp = @fopen(GB_FILE, 'w')) { echo 'Unable to open guestbook file for writing, check location and file permissions.'; break; } fwrite($fp, $output); fclose($fp); echo '

Message has been deleted.
Go back to the admin page

'; break 2; } else { $output .= $line; } } fclose($fp); echo '

There was an error deleting this post, it doesn\'t seem to exist
Go back to the admin page and try again

'; } if (!$fp = @fopen(GB_FILE, 'r')) { echo 'Unable to open guestbook file for reading, check location and file permissions.'; break; } while (!feof($fp)) { $line = fgets($fp, 4906); if (substr($line, 0, 10) == $_GET['d']) { list($date, $name, $mesg) = explode ('|', $line); echo '

Are you sure you want to delete this entry?

'; echo '

'.$name.' - on '.date(DATE_FORMAT, $date).'
'.$mesg.'

'; echo '

Yes - No

'; break 2; } } fclose($fp); echo '

There was an error finding this post, it doesn\'t seem to exist
Go back to the admin page and try again

'; } elseif (isset($_GET['e'])) { /*================================*\ -- admin edit -- \*================================*/ if (isset($_GET['c'])) { $name = (isset($_POST['name'])) ? strip_chars($_POST['name']) : NULL; $mesg = (isset($_POST['mesg'])) ? strip_chars($_POST['mesg']) : NULL; $errors = NULL; $name_len = strlen($name); $mesg_len = strlen($mesg); if ($name) { if ($name_len > MAX_NAME_LEN) { $errors = '- Name is too long, '.$name_len.' (Max: '.MAX_NAME_LEN.')
'; } } else { $errors = '- Name field is empty
'; } if ($mesg) { if ($mesg_len > MAX_MESG_LEN) { $errors.= '- Message is too long, '.$mesg_len.' (Max: '.MAX_MESG_LEN.')
'; } elseif ($mesg_len < MIN_MESG_LEN) { $errors.= '- Message is too short (Min: '.MIN_MESG_LEN.')
'; } } else { $errors.= '- Message field is empty
'; } if ($errors) { echo '

'.$errors.'

'; } else { if (!$fp = @fopen(GB_FILE, 'r')) { echo 'Unable to open guestbook file for reading, check location and file permissions.'; break; } $output = ''; while (!feof($fp)) { $line = fgets($fp, 4096); if (substr($line, 0, 10) == $_GET['e']) { list($date, , , $ip) = str_replace('\|', '|', preg_split("/(?', bbcode($mesg)).' |'.$ip."|\n".fread($fp, filesize(GB_FILE)); fclose($fp); $fp = @fopen(GB_FILE, 'w'); fwrite($fp, $output); fclose($fp); echo '

Message has been edited.
Go back to the admin page

'; break 2; } else { $output .= $line; } } fclose($fp); echo '

There was an error finding this post, it doesn\'t seem to exist
Go back to the admin page and try again

'; } } if (isset($_POST['submit'])) { echo "\n".'



BBCode

'; break; } if (!$fp = @fopen(GB_FILE, 'r')) { echo 'Unable to open guestbook file for reading, check location and file permissions.'; break; } while (!feof($fp)) { $line = fgets($fp, 4906); if (substr($line, 0, 10) == $_GET['e']) { list(, $name, $mesg) = str_replace('\|', '|', preg_split("/(?(.+?)\<\/b>)is", "[b]$1[/b]", $mesg); $mesg = preg_replace("(\(.+?)\<\/i\>)is", "[i]$1[/i]", $mesg); $mesg = preg_replace("(\(.+?)\<\/u\>)is", "[u]$1[/u]", $mesg); $mesg = preg_replace("(\(.+?)\<\/del\>)is", "[s]$1[/s]", $mesg); $mesg = str_replace('
', "\n", $mesg); $mesg = strip_tags($mesg); echo "\n".'



BBCode

'; break 2; } } fclose($fp); echo '

There was an error finding this post, it doesn\'t seem to exist
Go back to the admin page and try again

'; } else { /*================================*\ -- admin default -- \*================================*/ $gb_size = filesize(GB_FILE); echo '

======================
'; echo 'File Size: '.round($gb_size / 1024, 1).'KB'; echo '
======================

'; if (!$fp = @fopen(GB_FILE, 'r')) { echo 'Unable to open guestbook file for reading and writing, check location and file permissions.'; break; } $i = 0; $data = NULL; $to_show = (P * MAX_PER_PAGE) - MAX_PER_PAGE; if (P > 1) echo '

Page '.P.'

'; while (!feof($fp)) { $i++; if ($i > ($to_show + MAX_PER_PAGE)) break; $data = fgets($fp, 4096); if (empty($data)) break; if ($i > $to_show) { list ($date, $name, $mesg, $ip) = str_replace('\|', '|', preg_split("/(?[edit] [delete] [whois]
$name on ".date(DATE_FORMAT, $date)."
$mesg

"); } } if ($i > MAX_PER_PAGE) { $line_count = substr_count(fread($fp, $gb_size), "\n") + $i; $line_count = ceil($line_count / MAX_PER_PAGE); $s = 1; $f = $line_count + 1; echo "\n".'

Page: # '; if ($line_count > MAX_PER_PAGE) { if (P < 6) { $s = 1; $f = 10; } elseif (($line_count-P) < 6) { $s = $line_count - 8; $f = $line_count; } else { $s = P -3; $f = $s + 8; } echo (P > 5) ? ' 1-' : NULL; } for ($k=$s; $k<=$f; $k++) { echo ($k == P) ? "$k " : "$k "; } echo ($k <= $line_count) ? "of $line_count

" : '

'; } fclose($fp); } } else { if (isset($_POST['submit'])) echo '

Sorry wrong password

'; echo "\n".'

'; } break; /*================================*\ -- BBCode -- \*================================*/ case 'bbcode': echo '

BBCode is a way of putting special effects into your text. The allowed BBCode is:

  • [b]bold[/b]
  • [i]italic[/i]
  • [u]underline[/u]
  • [s]strikethrough[/s]

For example: to make this bold. when posting a message add the tags [b] and [/b] around the text (as seen above).

'; break; } /*================================*\ -- functions -- \*================================*/ function strip_chars($var) { return trim(str_replace("\r", NULL, htmlspecialchars(stripslashes(strip_tags($var)), ENT_QUOTES))); } function bbcode($var) { if (ALLOW_URLS == true) $var = preg_replace('/http:\/\/[\w]+(.[\w]+)([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?/i', '$0', $var); $var = preg_replace('(\[b\](.+?)\[\/b\])is', '$1', $var); $var = preg_replace('(\[i\](.+?)\[\/i\])is', '$1', $var); $var = preg_replace('(\[u\](.+?)\[\/u\])is', '$1', $var); $var = preg_replace('(\[s\](.+?)\[\/s\])is', '$1', $var); return trim(str_replace('|', '\|', $var)); } /*================================*\ -- end functions -- \*================================*/ echo "\n"; echo '

Admin'; if (!empty($password)) echo ' - Logout'; echo '

'; ?> PHP Guestbook from gbook