Beste leden,
Vandaag ben ik bezig geweest met de ubb codes techniek in te bouwen in het admin paneel. Zodat de beheerders simpel teksten een bepaalde ompaak kunnen geven. Met succes werkt het allemaal wel maar, betreft het nog een aantal schoonheids foutjes.
1. Als je veel tekst hebt komt de ubb code altijd helemaal onderaan het script te staan. Waar je muis ook staat hij komt onderaan. [offtopic](dit geld natuurlijk ook bij wijnig tekst, is best wel irritant)[/offtopic]
2. Als je een tekst selecteerd zal het mooi zijn dat als je dan op B[offtopic](bold)[/offtopic] knop klikt dat de desbetreffende tekst omringt word met lalala [offtopic](net als bij CP zelf)[/offtopic]
Ik hoop dat iemand van jullie me zou willen helpen aangezien mijn javascript kennen me hier te kort voor zal doen.
Config script waar de betekenis van de ubb word uitgeroepen:
<?php
function ubb($bericht) {
$bericht = nl2br($bericht);
$bericht = preg_replace("/\[B\](?U)((.|\n|\r)*)\[\/B\]/", "<B>\\1</B>",$bericht);
$bericht = preg_replace("/\[U\](?U)((.|\n|\r)*)\[\/U\]/", "<U>\\1</U>", $bericht);
$bericht = preg_replace("/\[I\](?U)((.|\n|\r)*)\[\/I\]/", "<I>\\1</I>", $bericht);
$bericht = preg_replace("/\[S\](?U)((.|\n|\r)*)\[\/S\]/", "<S>\\1</S>", $bericht);
$bericht = preg_replace("/\[MARQUEE\](?U)((.|\n|\r)*)\[\/MARQUEE\]/", "<MARQUEE>\\1</MARQUEE>", $bericht);
$bericht = preg_replace("/\[CENTER\](?U)((.|\n|\r)*)\[\/CENTER\]/", "<CENTER>\\1</CENTER>", $bericht);
$bericht = eregi_replace("\\[COLOR=([^\\[]*)\\]([^\\[]*)\\[/COLOR\\]","<font color=\"\\1\">\\2</font>",$bericht);
$bericht = eregi_replace("\\[URL=([^\\[]*)\\]([^\\[]*)\\[/URL\\]","<a href=\\1 target=_blank>\\2</a>",$bericht);
$bericht = eregi_replace("\\[IMG\\]([^\\[]*)\\[/IMG\\]","<img src=\\1>",$bericht);
return $bericht;
}
?>
Toon Meer
Admin script waar ubb gebruikt word (samengevat):
<html>
<head>
<script language="JavaScript">
function Invoegen(ubb) {
var edit;
var HuidigeTekst = document.form1.message.value;
edit = HuidigeTekst+ubb+" ";
document.form1.message.value=edit;
document.form1.message.focus();
return;
}
function ubb() {
return;
}
</script>
</head>
<body>
<form name=\"form1\" method=\"POST\" onSubmit=\"return submitForm(this.SEND);\">
<table width=\"100%\">
<tr>
<td colspan=\"2\"><h2><u>Aanbod pagina toevoegen</u></h2><br></td>
</tr>
<tr>
<td width=\"20\">Titel:</td>
<td><input type=\"text\" name=\"subject\" value=\"{$help->titel}\"></td>
</tr>
<tr>
<td width=\"20%\">Codes:</td>
<td>
<input type=\"button\" name=\"b\" value=\"B\" style=\"font-weight: bold; width: 30px;\" onClick=\"javascript:Invoegen('[B]tekst hier[/B]');\" />
<input type=\"button\" name=\"u\" value=\"U\" style=\"text-decoration: underline; width: 30px;\" onClick=\"javascript:Invoegen('[U]tekst hier[/U]');\" />
<input type=\"button\" name=\"i\" value=\"I\" style=\"font-style: italic; width: 30px;\" onClick=\"javascript:Invoegen('[I]tekst hier[/I]');\" />
<input type=\"button\" name=\"s\" value=\"S\" style=\"text-decoration: line-through; width: 30px;\" onClick=\"javascript:Invoegen('[S]tekst hier[/S]');\" />
<input type=\"button\" name=\"center\" value=\"center\" onClick=\"javascript:Invoegen('[CENTER]tekst hier[/CENTER]');\" />
<input type=\"button\" name=\"marquee\" value=\"marquee\" onClick=\"javascript:Invoegen('[MARQUEE]tekst hier[/MARQUEE]');\" />
<input type=\"button\" name=\"url\" value=\"http://\" onClick=\"javascript:Invoegen('[URL=http://www.linkhier.nl]Klik hier tekst[/URL]');\" />
<input type=\"button\" name=\"img\" value=\"image\" onClick=\"javascript:Invoegen('[IMG]http://www.linkhier.nl/imagenaam.jpg[/IMG]');\" />
<SELECT name=\"kleurlinks\" onChange=\"window.location=document.form1.kleurlinks.options[document.form1.kleurlinks.selectedIndex].value\">
<OPTION SELECTED value=\"javascript:void(0)\">Tekst kleur
<OPTION input type=\"button\" name=\"color\" value=\"javascript:Invoegen('[COLOR=black]tekst hier[/COLOR]');\"\" /> <font color=\"black\"> Zwart </font>
<OPTION input type=\"button\" name=\"color\" value=\"javascript:Invoegen('[COLOR=white]tekst hier[/COLOR]');\"\" /> <font color=\"white\"> Wit </font>
<OPTION input type=\"button\" name=\"color\" value=\"javascript:Invoegen('[COLOR=red]tekst hier[/COLOR]');\"\" /> <font color=\"red\"> Rood </font>
<OPTION input type=\"button\" name=\"color\" value=\"javascript:Invoegen('[COLOR=blue]tekst hier[/COLOR]');\"\" /> <font color=\"blue\"> Blauw </font>
<OPTION input type=\"button\" name=\"color\" value=\"javascript:Invoegen('[COLOR=green]tekst hier[/COLOR]');\"\" /> <font color=\"green\"> Groen </font>
<OPTION input type=\"button\" name=\"color\" value=\"javascript:Invoegen('[COLOR=yellow]tekst hier[/COLOR]');\"\" /> <font color=\"yellow\"> Geel </font>
<OPTION input type=\"button\" name=\"color\" value=\"javascript:Invoegen('[COLOR=pink]tekst hier[/COLOR]');\"\" /> <font color=\"pink\"> Roze </font>
<OPTION input type=\"button\" name=\"color\" value=\"javascript:Invoegen('[COLOR=orange]tekst hier[/COLOR]');\"\" /> <font color=\"orange\"> Oranje </font>
<OPTION input type=\"button\" name=\"color\" value=\"javascript:Invoegen('[COLOR=pirple]tekst hier[/COLOR]');\"\" /> <font color=\"pirle\"> Paars </font>
</SELECT>
</td>
</tr>
<tr>
<td width=\"20%\"> bericht: </td>
<td><textarea name=\"message\" cols=65 rows=10>{$help->bericht}</textarea></td>
</tr>
<tr>
<td width=\"20%\"></td>
<td width=\"100%\" colspan=\"2\"><input type=\"submit\" name=\"submit\" value=\"Submit\" style=\"width: 200;\"></td>
</tr>
</table>
</form>
</body>
</html>
Toon Meer
Alvast heel erg bedankt voor de gene die de oplossing voor me heeft:).
Groetjes,
Rick