So habe da jetzt ein BBCODE Script für meine editnews function.
Aber irgendwie funktioniert die nicht richtig obwohl ich kein fehler sehe.
Also mein genaues Problem ist das wenn ich ein Text eingeb der an die Funktion übergeben wird und da z.b. [b]Test steht das sich nix ändert sondern das einfach so wieder ausgeben wird ohne das es durch ein HTMl Tag ersetzt wird!
PHP-Code:
<?php
function editnews($titel, $inhalt, $inhalt_long, $id, $cat)
{
require_once 'stringparser_bbcode.class.php';
$bbcode = new StringParser_BBCode ();
// Zeilenumbrüche verschiedener Betriebsysteme vereinheitlichen
function convertlinebreaks ($text) {
return preg_replace ("/\015\012|\015|\012/", "\n", $text);
}
// Alles bis auf Neuezeile-Zeichen entfernen
function bbcode_stripcontents ($text) {
return preg_replace ("/[^\n]/", '', $text);
}
function do_bbcode_url ($action, $attributes, $content, $params, $node_object) {
if ($action == 'validate') {
return true;
}
if (!isset ($attributes['default'])) {
return '[url="'.htmlspecialchars ($content).'"]'.htmlspecialchars ($content).'[/url]';
}
return '[url="'.htmlspecialchars ($attributes['default']).'"]'.$content.'[/url]';
}
// Funktion zum Einbinden von Bildern
function do_bbcode_img ($action, $attributes, $content, $params, $node_object) {
if ($action == 'validate') {
return true;
}
return '[img]'.htmlspecialchars($content).'[/img]';
}
$bbcode->addFilter (STRINGPARSER_FILTER_PRE, 'convertlinebreaks');
$bbcode->addParser (array ('block', 'inline', 'link', 'listitem'), 'htmlspecialchars');
$bbcode->addParser (array ('block', 'inline', 'link', 'listitem'), 'nl2br');
$bbcode->addParser ('list', 'bbcode_stripcontents');
$bbcode->addCode ('b', 'simple_replace', null, array ('start_tag' => '[b]', 'end_tag' => '[/b]'),
'inline', array ('listitem', 'block', 'inline', 'link'), array ());
$bbcode->addCode ('i', 'simple_replace', null, array ('start_tag' => '[i]', 'end_tag' => '[/i]'),
'inline', array ('listitem', 'block', 'inline', 'link'), array ());
$bbcode->addCode ('url', 'usecontent?', 'do_bbcode_url', array ('usecontent_param' => 'default'),
'link', array ('listitem', 'block', 'inline'), array ('link'));
$bbcode->addCode ('link', 'callback_replace_single', 'do_bbcode_url', array (),
'link', array ('listitem', 'block', 'inline'), array ('link'));
$bbcode->addCode ('img', 'usecontent', 'do_bbcode_img', array (),
'image', array ('listitem', 'block', 'inline', 'link'), array ());
$bbcode->addCode ('bild', 'usecontent', 'do_bbcode_img', array (),
'image', array ('listitem', 'block', 'inline', 'link'), array ());
$bbcode->setOccurrenceType ('img', 'image');
$bbcode->setOccurrenceType ('bild', 'image');
$bbcode->setMaxOccurrences ('image', 2);
$bbcode->addCode ('list', 'simple_replace', null, array ('start_tag' => '<ul>', 'end_tag' => '[/list]'),
'list', array ('block', 'listitem'), array ());
$bbcode->addCode ('*', 'simple_replace', null, array ('start_tag' => '[*]', 'end_tag' => ''),
'listitem', array ('list'), array ());
$bbcode->setCodeFlag ('*', 'closetag', BBCODE_CLOSETAG_OPTIONAL);
$bbcode->setCodeFlag ('*', 'paragraphs', true);
$bbcode->setCodeFlag ('list', 'paragraph_type', BBCODE_PARAGRAPH_BLOCK_ELEMENT);
$bbcode->setCodeFlag ('list', 'opentag.before.newline', BBCODE_NEWLINE_DROP);
$bbcode->setCodeFlag ('list', 'closetag.before.newline', BBCODE_NEWLINE_DROP);
$bbcode->setRootParagraphHandling (true);
$inhalt2 = $bbcode->parse ($inhalt);
$con = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS) or die(mysql_error());
if($con)
{
mysql_select_db(MYSQL_DB);
$sql = "UPDATE news
SET
Titel = '$titel',
Inhalt = '$inhalt2',
Inhalt_long = '$inhalt_long',
Cat = '$cat'
WHERE
ID = $id";
$result = mysql_query($sql) OR die(mysql_error());
}
else
{
$error = "Fehler in der Datenbank:
\n".$con."
\n";
return $error;
}
$message .= "News wurde geändert!";
return $message;
}
?>