<?php

function redirect($url,$tps) {
echo "<html><head><META HTTP-EQUIV=Refresh CONTENT=\"$tps; URL=$url\">";
}

function stdate($time) {
    setlocale (LC_TIME, "fr");
    ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $time, $datetime);
    $datetime = strftime("%d/%m/%y à %H:%M:%S", mktime($datetime[4],$datetime[5],$datetime[6],$datetime[2],$datetime[3],$datetime[1]));
    $datetime = ucfirst($datetime);
return($datetime);
}

function select_topic($topic){
        $handle = opendir('Images/Topics');
        while ($f = readdir($handle))
        {
            if ($f != '.' && $f != '..' && $f != 'CVS')
            {
		$f = substr($f, 0, $f-4);
                if ($topic == $f) $checked="selected";
				else $checked="";

		echo "<OPTION VALUE=\"$f\" $checked>$f</OPTION>";
	     }
        }
        closedir($handle);
  }

function select_theme($theme){
        $handle = opendir('Theme');
	$content = "";
        while ($f = readdir($handle))
        {
            if ($f != '.' && $f != '..' && $f != 'CVS' && !ereg("[.]",$f))
            {
                if ($theme == $f) $checked="selected";
				else $checked="";
				$content.="<option value=\"$f\" $checked>$f</option>";
	     }
        }
        closedir($handle);
	return($content);
}

function ladate() {
	$nday=date("l");
	$day=date("d");
	$month=date("m");
	$year=date("Y"); 

	switch ($nday) {
		case "Monday":
		$nday="Lundi";
		break;

		case "Tuesday":
		$nday="Mardi";
		break;

		case "Wednesday":
		$nday="Mercredi";
		break;

		case "Thursday":
		$nday="Jeudi";
		break;

		case "Friday":
		$nday="Vendredi";
		break;

		case "Saturday":
		$nday="Samedi";
		break;

		case "Sunday":
		$nday="Dimanche";
		break;
	} 

	switch ($month) {
		case 1:
		$month="Janvier";
		break;

		case 2:
		$month="Février";
		break;

		case 3:
		$month="Mars";
		break;

		case 4:
		$month="Avril";
		break;

		case 5:
		$month="Mai";
		break;

		case 6:
		$month="Juin";
		break;

		case 7:
		$month="Juillet";
		break;

		case 8:
		$month="Août";
		break;

		case 9:
		$month="Septembre";
		break;

		case 10:
		$month="Octobre";
		break;

		case 11:
		$month="Novembre";
		break;

		case 12:
		$month="Décembre";
		break;
	}
	$thedate = "$nday $day $month $year";

return($thedate);
}

function BBcode($texte){

	$texte = str_replace(">", "&gt;", $texte);
	$texte = str_replace("<", "&lt;", $texte);
	// [CODE] and [/CODE] for posting code (HTML, PHP, C etc etc) in your posts.
	$matchCount = preg_match_all("#\[code\](.*?)\[/code\]#si", $texte, $matches);
	for ($i = 0; $i < $matchCount; $i++)
	{
		$currMatchTextBefore = preg_quote($matches[1][$i]);
		$currMatchTextAfter = htmlspecialchars($matches[1][$i]);
		$texte = preg_replace("#\[code\]$currMatchTextBefore\[/code\]#si", "<TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD>Code:<HR></TD></TR><TR><TD><PRE>$currMatchTextAfter</PRE></TD></TR><TR><TD><HR></TD></TR></TABLE>", $texte);
	}


$texte = preg_replace("#\&lt;FONT (.*?)\&gt;(.*?)#si", "<font \\"."1>\\"."2", $texte);
$texte = preg_replace("#\&lt;/font\&gt;#si", "</font>", $texte);

$texte = preg_replace("#\&lt;BLOCKQUOTE (.*?)\&gt;(.*?)\&lt;/BLOCKQUOTE\&gt;#si", "<BLOCKQUOTE \\"."1>\\"."2</BLOCKQUOTE>", $texte);
$texte = preg_replace("#\&lt;div (.*?)\&gt;(.*?)\&lt;/div\&gt;#si", "<div \\"."1>\\"."2</div>", $texte);
$texte = preg_replace("#\&lt;em\&gt;(.*?)\&lt;/em\&gt;#si", "<em>\\"."1</em>", $texte);
$texte = preg_replace("#\&lt;strong\&gt;(.*?)\&lt;/strong\&gt;#si", "<strong>\\"."1</strong>", $texte);
$texte = preg_replace("#\&lt;u\&gt;(.*?)\&lt;/u\&gt;#si", "<u>\\"."1</u>", $texte);
$texte = preg_replace("#\&lt;p\&gt;(.*?)\&lt;/p\&gt;#si", "<p>\\"."1</p>", $texte);
$texte = preg_replace("#\&lt;BLOCKQUOTE\&gt;(.*?)\&lt;/BLOCKQUOTE\&gt;#si", "<BLOCKQUOTE>\\"."1</BLOCKQUOTE>", $texte);
$texte = preg_replace("#\&lt;li\&gt;#si", "<li>", $texte);
$texte = preg_replace("#\&lt;/li\&gt;#si", "</li>", $texte);
$texte = preg_replace("#\&lt;ul\&gt;#si", "<ul>", $texte);
$texte = preg_replace("#\&lt;/ul\&gt;#si", "</ul>", $texte);
$texte = preg_replace("#\&lt;br\&gt;#si", "<br>", $texte);
$texte = preg_replace("#\&lt;ol (.*?)\&gt#si", "<ol \\"."1>", $texte);
$texte = preg_replace("#\&lt;ol\&gt;#si", "<ol>", $texte);
$texte = preg_replace("#\&lt;/ol\&gt;#si", "</ol>", $texte);
$texte = preg_replace("#\&lt;hr\&gt;#si", "<hr>", $texte);
$texte = preg_replace("#\&lt;a href=(http://)?(.*?)\&gt;(.*?)\&lt;/a\&gt;#si", "<A HREF=\\"."2 TARGET=_blank>\\"."3</A>", $texte);
$texte = preg_replace("#\&lt;img (.*?)\&gt;#si", "<img \\"."1>", $texte);
$texte = preg_replace("#\&lt;p (.*?)\&gt;#si", "<p \\"."1>", $texte);
$texte = preg_replace("#\&lt;p\&gt;#si", "<p>", $texte);
$texte = preg_replace("#\&lt;/p\&gt;#si", "</p>", $texte);

		// [s]smiley[/s] code..
	$texte = preg_replace("#\[s\](http://)?(.*?)\[/s\]#si", "<img src=modules/Forum/images/icones/\\"."2 border=0>", $texte);

	// [QUOTE] and [/QUOTE] for posting replies with quote, or just for quoting stuff.
	$texte = preg_replace("#\[quote\](.*?)\[/quote]#si", "<!-- BBCode Quote Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD>Quote:<HR></TD></TR><TR><TD><BLOCKQUOTE>\\"."1</BLOCKQUOTE></FONT></TD></TR><TR><TD><HR></TD></TR></TABLE><!-- BBCode Quote End -->", $texte);
	// [b] and [/b] for bolding text.
	$texte = preg_replace("#\[b\](.*?)\[/b\]#si", "<B>\\"."1</B>", $texte);
	// [u] and [/u] for underligning text.
	$texte = preg_replace("#\[u\](.*?)\[/u\]#si", "<U>\\"."1</U>", $texte);
	// [i] and [/i] for italicizing text.
	$texte = preg_replace("#\[i\](.*?)\[/i\]#si", "<I>\\"."1</I>", $texte);
	// [url]www.phpbb.com[/url] code..
	$texte = preg_replace("#\[url\](http://)?(.*?)\[/url\]#si", "<A HREF=http://\\"."2 TARGET=_blank>\\"."2</A>", $texte);
	// [url=www.phpbb.com]phpBB[/url] code..
	$texte = preg_replace("#\[url=(http://)?(.*?)\](.*?)\[/url\]#si", "<A HREF=http://\\"."2 TARGET=_blank>\\"."3</A>", $texte);
	// [EDK=www.phpbb.com]phpBB[/EDK] code..
	$texte = preg_replace("#\[edk=(ed2k://)?(.*?)\](.*?)\[/edk\]#si", "<A HREF=ed2k://\\"."2 TARGET=_blank>\\"."3</A>", $texte);
	// [INT=/modules/fichiers]phpBB[/INT] code..
	$texte = preg_replace("#\[int=(.*?)\](.*?)\[/int\]#si", "<A HREF=\\"."1>\\"."2</A>", $texte);
	// [irc]channel[/irc] code..
	$texte = preg_replace("#\[irc\](irc://quakenet.org/)?(.*?)\[/irc\]#si", "<A HREF=irc://quakenet.org/\\"."2 TARGET=_blank>\\"."2</A>", $texte);
	// [email]user@domain.tld[/email] code..
	$texte = preg_replace("#\[email\](.*?)\[/email\]#si", "<A HREF=mailto:\\"."1>\\"."1</A>", $texte);
	// [img]image_url_here[/img] code..
	$texte = preg_replace("#\[img\](.*?)\[/img\]#si", "<IMG SRC=\\"."1>", $texte);
	// unordered list code..
	$matchCount = preg_match_all("#\[list\](.*?)\[/list\]#si", $texte, $matches);
	for ($i = 0; $i < $matchCount; $i++)
	{
		$currMatchTextBefore = preg_quote($matches[1][$i]);
		$currMatchTextAfter = preg_replace("#\[\*\]#si", "<LI>", $matches[1][$i]);

		$texte = preg_replace("#\[list\]$currMatchTextBefore\[/list\]#si", "<!-- BBCode ulist Start --><UL>$currMatchTextAfter</UL><!-- BBCode ulist End -->", $texte);
	}
	// ordered list code..
	$matchCount = preg_match_all("#\[list=([a1])\](.*?)\[/list\]#si", $texte, $matches);
	for ($i = 0; $i < $matchCount; $i++)
	{
		$currMatchTextBefore = preg_quote($matches[2][$i]);
		$currMatchTextAfter = preg_replace("#\[\*\]#si", "<LI>", $matches[2][$i]);

		$texte = preg_replace("#\[list=([a1])\]$currMatchTextBefore\[/list\]#si", "<!-- BBCode olist Start --><OL TYPE=\\"."1>$currMatchTextAfter</OL><!-- BBCode olist End -->", $texte);
	}
	$texte = nl2br($texte);

	return($texte);
}

?>