<?
/***************************************************************************
* Copyright 2003 Ian Meyer, Ian Pitcher
*
* 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; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
require("functions.color.php");
// Output the html header, takes $title as an argument.
function bco_html_header($title)
{
global $user_data, $userinfo;
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
echo "\n<html>";
echo "\n<head>";
echo "\n<title>$title</title>";
echo "\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />";
// Stylesheet function here
if ($user_data['show_stylesheet']) {
if (isset($userinfo['colors'])) {
$colors = urldecode($userinfo['colors']);
} else {
// Get the default colors from the config table.
$get_default_color_query = "select config_value from bco_config where config_name='default_colors'";
if (!$colors = pg_fetch_result(pg_query($get_default_color_query), 0)) {
bco_error("MySQL said: " . pg_last_error());
}
}
print "<style type=\"text/css\">";
print bco_generate_stylesheet($colors);
print "</style>";
//print "<link rel=\"stylesheet\" href=\"style.php\" />"; // I don't recall why this was here.
}
echo "\n</head>";
echo "\n<body>";
}
// The html footer
function bco_html_footer()
{
echo "\n</body>";
echo "\n</html>";
}
// Displays an html page with the error message as an argument
function bco_error($err_msg)
{
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
echo "\n<html>";
echo "\n<head>";
echo "\n<title>ERROR</title>";
echo "\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />";
// Stylesheet function here
bco_generate_stylesheet();
echo "\n</head>";
echo "\n<body>";
bco_index_menu("Oops!");
echo "\n<br />";
echo "\n<table width=\"100%\" cellpadding=\"2\" cellspacing=\"0\" class=\"replytbl\">";
echo "\n <tr>";
echo "\n <td class=\"tr1\" colspan=\"5\"><div align=\"center\"><h3>ERROR: $err_msg</h3></div></td>";
echo "\n </tr>";
echo "\n</table>";
echo "\n</body>";
echo "\n</html>";
exit;
}
//
// Spits out a simple page with links to other pages or whatever the user defines.
//
function bco_display_info($info, $title)
{
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
echo "\n<html>";
echo "\n<head>";
echo "\n<title>$title</title>";
echo "\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />";
// Stylesheet function here
bco_generate_stylesheet();
echo "\n</head>";
echo "\n<body>";
bco_index_menu($title);
echo "\n<br />";
echo "\n<table width=\"100%\" cellpadding=\"2\" cellspacing=\"0\" class=\"replytbl\">";
echo "\n <tr>";
echo "\n <td class=\"tr1\" colspan=\"5\"><div align=\"center\">$info</div></td>";
echo "\n </tr>";
echo "\n</table>";
echo "\n</body>";
echo "\n</html>";
exit;
}
function bco_clean_html($string)
{
// Convert everything to entities here.
$tmp_string = stripslashes(htmlentities($string));
// The regular expression to match ip numbers.
$ip_pattern = "(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])";
// Matches the url, along with the ip pattern in there, so http://178.56.23.59/ matches as does http://crewcial.org
$url_pattern = "(http|https|ftp)\:\/\/($ip_pattern|[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3})(:[a-zA-Z0-9]*)?\/?([a-zA-Z0-9\-\._\?\,\'\/\\\+&%\$#\=~])*[^\.\,\)\(\s]";
// All the follow follow the pattern of
// tag_pattern
// and then following is where it gets "cleaned" up.
// $a_pattern = "/<a *href *= *"(((http|https|ftp):\/\/|mailto:)(.*))">(.*)< *\/ *a *>/Umsi";
// $tmp_string = preg_replace($a_pattern, "<a href=\"\$1\" class=\"tr1link\">\$5</a>", $tmp_string);
$a_pattern = "/<a *href *= *"(((http|https|ftp):\/\/|mailto:)(.*))(\/.*)?">(.*)< *\/ *a *>/Umsi";
$tmp_string = preg_replace($a_pattern, "<a href=\"\$2$4$5\" class=\"tr1link\">\$6</a> [$4]", $tmp_string);
$img_pattern = "/<img *src *= *"((http|https|ftp):\/\/(.*))" *>/Umsi";
$tmp_string = preg_replace($img_pattern, "<img src=\"\$1\" alt=\"\$1\" />", $tmp_string);
$font_pattern = "/<font *size *= *"([1-7])" *>(.*)< *\/ *font *>/Umsi";
$tmp_string = preg_replace($font_pattern, "<font size=\"\$1\">\$2</font>", $tmp_string);
$br_pattern = "/<br *( *\/)? *>/i";
$tmp_string = preg_replace($br_pattern, "<br />", $tmp_string);
$strong_pattern = "/<strong *>(.*)<\/ *strong *>/Umsi";
$tmp_string = preg_replace($strong_pattern, "<strong>\$1</strong>", $tmp_string);
$i_pattern = "/<i *>(.*)<\/ *i *>/Umsi";
$tmp_string = preg_replace($i_pattern, "<i>\$1</i>", $tmp_string);
$b_pattern = "/<b *>(.*)<\/ *b *>/Umsi";
$tmp_string = preg_replace($b_pattern, "<b>\$1</b>", $tmp_string);
$u_pattern = "/<u *>(.*)<\/ *u *>/Umsi";
$tmp_string = preg_replace($u_pattern, "<u>\$1</u>", $tmp_string);
// Okay this is kind of tricky.. we want to take everything that is contained inside the pre tag and make our own output.
// So we need to use a callback function...
// For more info see http://php.net/preg_replace_callback
// The function the callback uses is right after this one.. called "fake_pre"
// Should work correctly.
$pre_pattern = "/<pre>(.*)<\/pre>/Umsi";
$tmp_string = preg_replace_callback($pre_pattern, "bco_fake_pre", $tmp_string);
$em_pattern = "/<em *>(.*)<\/ *em *>/Umsi";
$tmp_string = preg_replace($em_pattern, "<em>\$1</em>", $tmp_string);
// Convert & to &
//$tmp_string = preg_replace("/&/", "&", $tmp_string);
// Return the clean string.
return $tmp_string;
}
// Function to check magic quotes runtime and add slashes accordingly
function bco_addslashes($string)
{
if (get_magic_quotes_gpc()) {
return $string;
} else {
return addslashes($string);
}
}
// This is the callback function for making <pre> tags look nice
function bco_fake_pre($text)
{
$text = str_replace(" ", " ", $text);
$text = str_replace("\\n", "<br />", $text);
$text = str_replace("<pre>", "<br />", $text);
$text = str_replace("</pre>", "<br />", $text);
return "<span class=\"mono\">$text[0]</span>";
}
// This function "removes" images by replaced the image tag wtih an anchor linking to the image with specified text.
function bco_remove_images($string)
{
$img_replace_pattern = "/<img src=\"(.*)\" alt=\"(.*)\" \/>/Umsi";
$string = preg_replace($img_replace_pattern, "<a href=\"\$1\" class=\"tr1\">IMAGE REMOVED - CLICK TO VIEW</a>", $string);
return($string);
}
// Taken from phpbb and altered for my own use.. a big thanks to them!
// http://phpbb.com - nice forum!!!
// Takes 5 arguments,
// if you want to remove the previous and next being displayed, change $add_prevnext_text = TRUE to $add_prevnext_text = FALSE
function bco_makepagenumbers($base_url, $num_items, $per_page, $start_item, $order, $add_prevnext_text = TRUE)
{
$total_pages = ceil($num_items/$per_page);
if ( $total_pages == 1 ) {
return '';
}
$on_page = floor($start_item / $per_page) + 1;
$page_string = '';
if ( $total_pages > 10 ) {
$init_page_max = ( $total_pages > 3 ) ? 3 : $total_pages;
for($i = 1; $i < $init_page_max + 1; $i++) {
$page_string .= ( $i == $on_page ) ? '<strong>' . $i . '</strong>' : '<a href="' . $base_url . "&start=" . ( ( $i - 1 ) * $per_page ) . "&order=$order" . '">' . $i . '</a>';
if ( $i < $init_page_max ) {
$page_string .= ", ";
}
}
if ( $total_pages > 3 ) {
if ( $on_page > 1 && $on_page < $total_pages ) {
$page_string .= ( $on_page > 5 ) ? ' ... ' : ', ';
$init_page_min = ( $on_page > 4 ) ? $on_page : 5;
$init_page_max = ( $on_page < $total_pages - 4 ) ? $on_page : $total_pages - 4;
for($i = $init_page_min - 1; $i < $init_page_max + 2; $i++) {
$page_string .= ($i == $on_page) ? '<strong>' . $i . '</strong>' : '<a href="' . $base_url . "&start=" . ( ( $i - 1 ) * $per_page ) . "&order=$order" . '">' . $i . '</a>';
if ( $i < $init_page_max + 1 ) {
$page_string .= ', ';
}
}
$page_string .= ( $on_page < $total_pages - 4 ) ? ' ... ' : ', ';
}
else {
$page_string .= ' ... ';
}
for($i = $total_pages - 2; $i < $total_pages + 1; $i++) {
$page_string .= ( $i == $on_page ) ? '<strong>' . $i . '</strong>' : '<a href="' . $base_url . "&start=" . ( ( $i - 1 ) * $per_page ) . "&order=$order" . '">' . $i . '</a>';
if( $i < $total_pages ) {
$page_string .= ", ";
}
}
}
} else {
for($i = 1; $i < $total_pages + 1; $i++) {
$page_string .= ( $i == $on_page ) ? '<strong>' . $i . '</strong>' : '<a href="' . $base_url . "&start=" . ( ( $i - 1 ) * $per_page ) . "&order=$order" . '">' . $i . '</a>';
if ( $i < $total_pages ) {
$page_string .= ', ';
}
}
}
if ( $add_prevnext_text ) {
if ( $on_page > 1 ) {
$page_string = ' <a href="' . $base_url . "&start=" . ( ( $on_page - 2 ) * $per_page ) . "&order=$order" . '"><<</a> ' . $page_string;
}
if ( $on_page < $total_pages ) {
$page_string .= ' <a href="' . $base_url . "&start=" . ( $on_page * $per_page ) . "&order=$order" . '">>></a> ';
}
}
$page_string = "<strong>go to page: </strong>" . " " . $page_string;
switch ($order) {
case "asc":
$page_string .= ' - <a href="' . $base_url . '&start=' . $start_item . "&order=desc" . '">descending</a>';
break;
case "desc":
$page_string .= ' - <a href="' . $base_url . '&start=' . $start_item . "&order=asc" . '">ascending</a>';
break;
default:
$page_string .= ' - <a href="' . $base_url . '&start=' . $start_item . "&order=asc" . '">ascending</a>';
break;
}
return $page_string;
}
?>