hi Green Ali3n,
weiss nicht genau was du meinst, aber ich versuch mich mal:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>BBCode</title>
<script language="JavaScript" type="text/javascript">
<!--
function checkform(){
if(document.getElementById('form1').message.value == ""){
window.alert('Bitte füllen Sie das Formular aus!');
document.getElementById('form1').message.focus();
return false;
} else {
return true;
}
}
var imageTag = false;
var theSelection = false;
var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var clientVer = parseInt(navigator.appVersion); // Get browser version
var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
var is_nav = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1)
&& (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1)
&& (clientPC.indexOf('webtv')==-1) && (clientPC.indexOf('hotjava')==-1));
var is_moz = 0;
var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
var is_mac = (clientPC.indexOf("mac")!=-1);
// Hilfebox Nachrichten
var b_help = "Text in fett: [b]Text[/b]";
var i_help = "Text in kursiv: [i]Text[/i]";
var u_help = "Unterstrichener Text: [u]Text[/u]";
var s_help = "Durchgestrichener Text: [s]Text[/s]";
var q_help = "Zitat: [quote]Text[/quote] oder [quote=\"Name\"]Text[/quote]";
var p_help = "Bild einfügen: [img]http://Bild-URL[/img]";
var w_help = "URL einfügen: [url]http://URL[/url] oder [url=http://URL]Beschreibung[/url]";
var a_help = "Alle offenen BBCode Tags schließen";
var y_help = "Zentriert: [center]Text[/center]";
// Infotext fuer die Helpbox
function helpline(help) {
document.post.helpbox.value = eval(help + "_help");
}
// BBCode Tags, entscheidend für die bbstyle(); Funktion!
bbcode = new Array();
bbtags = new Array('[b]','[/b]','[i]','[/i]','[u]','[/u]','[s]','[/s]','[quote]','[/quote]','[img]','[/img]','[url]','[/url]','[center]','[/center]');
imageTag = false;
function getarraysize(thearray) {
for (i = 0; i < thearray.length; i++) {
if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null))
return i;
}
return thearray.length;
}
function arraypush(thearray,value) {
thearray[ getarraysize(thearray) ] = value;
}
function arraypop(thearray) {
thearraysize = getarraysize(thearray);
retval = thearray[thearraysize - 1];
delete thearray[thearraysize - 1];
return retval;
}
function bbstyle(bbnumber) {
var txtarea = document.post.message;
txtarea.focus();
donotinsert = false;
theSelection = false;
bblast = 0;
if (bbnumber == -1) {
while (bbcode[0]) {
butnumber = arraypop(bbcode) - 1;
txtarea.value += bbtags[butnumber + 1];
buttext = eval('document.post.addbbcode' + butnumber + '.value');
eval('document.post.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
}
imageTag = false;
txtarea.focus();
return;
}
if ((clientVer >= 4) && is_ie && is_win)
{
theSelection = document.selection.createRange().text;
if (theSelection) {
document.selection.createRange().text = bbtags[bbnumber] + theSelection + bbtags[bbnumber+1];
txtarea.focus();
theSelection = '';
return;
}
}
else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
{
mozWrap(txtarea, bbtags[bbnumber], bbtags[bbnumber+1]);
return;
}
for (i = 0; i < bbcode.length; i++) {
if (bbcode[i] == bbnumber+1) {
bblast = i;
donotinsert = true;
}
}
if (donotinsert) {
while (bbcode[bblast]) {
butnumber = arraypop(bbcode) - 1;
txtarea.value += bbtags[butnumber + 1];
buttext = eval('document.post.addbbcode' + butnumber + '.value');
eval('document.post.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
imageTag = false;
}
txtarea.focus();
return;
} else {
if (imageTag && (bbnumber != 14)) {
txtarea.value += bbtags[15];
lastValue = arraypop(bbcode) - 1;
document.post.addbbcode14.value = "Img";
imageTag = false;
}
txtarea.value += bbtags[bbnumber];
if ((bbnumber == 14) && (imageTag == false)) imageTag = 1;
arraypush(bbcode,bbnumber+1);
eval('document.post.addbbcode'+bbnumber+'.value += "•"');
txtarea.focus();
return;
}
storeCaret(txtarea);
}
function mozWrap(txtarea, open, close)
{
var selLength = txtarea.textLength;
var selStart = txtarea.selectionStart;
var selEnd = txtarea.selectionEnd;
if (selEnd == 1 || selEnd == 2)
selEnd = selLength;
var s1 = (txtarea.value).substring(0,selStart);
var s2 = (txtarea.value).substring(selStart, selEnd)
var s3 = (txtarea.value).substring(selEnd, selLength);
txtarea.value = s1 + open + s2 + close + s3;
return;
}
function storeCaret(textEl) {
if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}
//-->
</script>
</head>
<body>
<?php
function bbcode($message){
$string = nl2br(htmlspecialchars($string)); // Sonderzeichen und Umbrueche in HTML Code umwandeln
$bb_code = array('&\[b\](.+?)\[/b\]&',
'&\[i\](.+?)\[/i\]&',
'&\[u\](.+?)\[/u\]&',
'&\[s\](.+?)\[/s\]&',
'&\[center\](.+?)\[/center\]&',
'&\[email\](.+?)\[/email\]&',
'&\[img\](.+?)\[/img\]&',
'&\[url=([a-z0-9]+://)([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*?)?)\](.*?)\[/url\]&',
'&\[url\]([a-z0-9]+?://){1}([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*)?)\[/url\]&',
'&\[url\]((www|ftp)\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*?)?)\[/url\]&',
'&\[quote\](.+?)\[/quote\]&');
$bb_replaces = array('[b]\\1[/b]',
'[i]\\1[/i]',
'<u>\\1</u>',
'<strike>\\1</strike>',
'<center>\\1</center>',
'[url='mailto:\\1']\\1[/url]',
'[img]\\1[/img]',
'[url='\1\2']\6[/url]',
'[url='\1\2']\1\2[/url]',
'[url='http://\1']\1[/url]',
'
[b]Quote:[/b]<div style="margin:0px 10px;padding:5px;background-color:#F7F7F7;border:1px dotted #CCCCCC;width:80%; font-size:10px;">\1</div>
');
$message = preg_replace($bb_code, $bb_replaces, $message);
return $message;
}
if( $button ) {
// TRUE ...
} else {
// FORMULAR MIT $row->inhalt
?>
<center>
<form action="<?=$_SERVER["PHP_SELF"]?>" method="post" name="post" id="form1" onSubmit="checkform(this)">
<table width="400" border="0" cellspacing="0" cellpadding="2">
<tr align="center" valign="middle">
<td>
<input type="button" name="addbbcode0" value=" B " style="font-weight:bold; width: 45px" onClick="bbstyle(0)" onMouseOver="helpline('b')" />
</td>
<td>
<input type="button" name="addbbcode2" value=" i " style="font-style:italic; width: 40px" onClick="bbstyle(2)" onMouseOver="helpline('i')" />
</td>
<td>
<input type="button" name="addbbcode4" value=" u " style="text-decoration: underline; width: 40px" onClick="bbstyle(4)" onMouseOver="helpline('u')" />
</td>
<td>
<input type="button" name="addbbcode6" value="S" style="text-decoration: line-through; width: 40px" onClick="bbstyle(6)" onMouseOver="helpline('s')" />
</td>
<td>
<input type="button" name="addbbcode8" value="Quote" style="width: 65px" onClick="bbstyle(8)" onMouseOver="helpline('q')" />
</td>
<td>
<input type="button" name="addbbcode10" value="Img" style="width: 55px" onClick="bbstyle(10)" onMouseOver="helpline('p')" />
</td>
<td>
<input type="button" name="addbbcode12" value="URL" style="text-decoration: underline; width: 55px" onClick="bbstyle(12)" onMouseOver="helpline('w')" />
</td>
<td>
<input type="button" name="addbbcode14" value=" Center " style="width: 75px" onClick="bbstyle(14)" onMouseOver="helpline('y')" />
</td>
</tr>
<tr>
<td colspan="10">
<p align="center">
[url='javascript:bbstyle(-1)'][ Offene Tags schließen ][/url]
<input type="text" name="helpbox" size="45" maxlength="100" style="width:450px; font-size:10px" border="0px" value="Styles können schnell durch markieren des Text hinzugefügt werden" />
<textarea name="message" rows="15" cols="35" wrap="virtual" style="width:450px" onselect="storeCaret(this);" onclick="storeCaret(this);" onkeyup="storeCaret(this);"><?=$row->inhalt;?></textarea>
<input type="reset" value="Zurücksetzen" /><input type="submit" value="Absenden" />
</p>
</td>
</tr>
</table>
</form>
</center>
<?php
}
?>
</body>
</html>
Alles anzeigen
Das alles benötigt nur eine Datei und ist unabhängig. Wenn der Text abgesandt wurde, wird es dann ausgewertet und das Formular verschwindet.
Gruss Schky