Exemplo n.º 1
0
// Funktion zum Einbinden von Bildern
function do_bbcode_img($action, $attributes, $content, $params, $node_object)
{
    if ($action == 'validate') {
        return true;
    }
    return '<img src="' . htmlspecialchars($content) . '" alt="">';
}
$bbcode = new StringParser_BBCode();
$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('code', 'simple_replace', null, array('start_tag' => '<code>', 'end_tag' => '</code>'), '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' => '</ul>'), 'list', array('block', 'listitem'), array());
$bbcode->addCode('*', 'simple_replace', null, array('start_tag' => '<li>', 'end_tag' => '</li>'), '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);
Exemplo n.º 2
0
 function parseBBcode($input)
 {
     //load our BBcode parser - Dan: This probably shouldn't be in the controller but I can't think of a better place for it
     if (!class_exists('StringParser_BBCode')) {
         include_once JPATH_BASE . "/administrator/components/com_ninja/helpers/bbcode/stringparser_bbcode.class.php";
     }
     $bbcode = new StringParser_BBCode();
     //this is a temporary fix, so the module can appear on pages that have Ninjamonials or Ninjaboard installed
     //in which case these functions will already have been created. So we don't want to cause an error by creatign thema again
     if (!function_exists('convertlinebreaks')) {
         //Initialise the settings
         // Unify line breaks of different operating systems
         function convertlinebreaks($text)
         {
             $text = preg_replace("/\r\n|\r|\n/", "\n", $text);
             $text = str_replace("\r\n", "\n", $text);
             $text = str_replace('\\r\\n', "\n", $text);
             $text = str_replace("<br/>", "\n", $text);
             $text = str_replace("<br />", "\n", $text);
             return str_replace("<br>", "\n", $text);
         }
         // Remove everything but the newline charachter
         function bbcode_stripcontents($text)
         {
             return preg_replace("/[^\n]/", '', $text);
         }
         function do_bbcode_url($action, $attributes, $content, $params, $node_object)
         {
             if (!isset($attributes['default'])) {
                 $url = $content;
                 $text = htmlspecialchars($content);
             } else {
                 $url = $attributes['default'];
                 $text = $content;
             }
             if ($action == 'validate') {
                 if (substr($url, 0, 5) == 'data:' || substr($url, 0, 5) == 'file:' || substr($url, 0, 11) == 'javascript:' || substr($url, 0, 4) == 'jar:') {
                     return false;
                 }
                 return true;
             }
             return '<a href="' . htmlspecialchars($url) . '">' . $text . '</a>';
         }
         // Function to include images
         function do_bbcode_img($action, $attributes, $content, $params, $node_object)
         {
             if ($action == 'validate') {
                 if (substr($content, 0, 5) == 'data:' || substr($content, 0, 5) == 'file:' || substr($content, 0, 11) == 'javascript:' || substr($content, 0, 4) == 'jar:' || substr($content, -4) == '.php') {
                     return false;
                 }
                 return true;
             }
             return '<img src="' . htmlspecialchars($content) . '" alt="">';
         }
         function do_bbcode_color($action, $attributes, $content, $params, $node_object)
         {
             //the default attribute is one after the bbtag itself [color=blah]text[/color]
             if (isset($attributes['default'])) {
                 return '<span style="color:' . $attributes['default'] . '">' . $content . '</span>';
             }
             return $content;
         }
         function do_bbcode_quote($action, $attributes, $content, $params, $node_object)
         {
             if (!isset($attributes['default'])) {
                 $whoSaid = '';
             } else {
                 $whoSaid = '<span class="nmWhoSaid">' . JText::sprintf('NM_WHOSAID', $attributes['default']) . '</span>';
             }
             return '<blockquote class="nmQuote"><span>' . $whoSaid . $content . '</span></blockquote>';
         }
         function do_bbcode_size($action, $attributes, $content, $params, $node_object)
         {
             if (isset($attributes['default'])) {
                 return '<span style="font-size:' . $attributes['default'] . '%">' . $content . '</span>';
             }
             return $content;
         }
     }
     $bbcode->addFilter(1, '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' => '<strong>', 'end_tag' => '</strong>'), 'inline', array('listitem', 'block', 'inline', 'link'), array());
     $bbcode->addCode('i', 'simple_replace', null, array('start_tag' => '<em>', 'end_tag' => '</em>'), 'inline', array('listitem', 'block', 'inline', 'link'), array());
     $bbcode->addCode('u', 'simple_replace', null, array('start_tag' => '<u>', 'end_tag' => '</u>'), 'inline', array('listitem', 'block', 'inline', 'link'), array());
     $bbcode->addCode('color', 'callback_replace', 'do_bbcode_color', array('usecontent_param' => 'default'), '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('quote', 'callback_replace', 'do_bbcode_quote', array('usecontent_param' => 'default'), 'block', array('block'), array('link', 'listitem', 'inline'));
     $bbcode->addCode('size', 'callback_replace', 'do_bbcode_size', array('usecontent_param' => 'default'), 'inline', array('listitem', 'block', 'inline', 'link'), array());
     $bbcode->addCode('img', 'usecontent', 'do_bbcode_img', array(), 'image', array('listitem', 'block', 'inline', 'link'), array());
     $bbcode->setOccurrenceType('img', 'image');
     $bbcode->setMaxOccurrences('image', 4);
     $bbcode->addCode('ul', 'simple_replace', null, array('start_tag' => '<ul>', 'end_tag' => '</ul>'), 'list', array('block', 'listitem'), array());
     $bbcode->addCode('ol', 'simple_replace', null, array('start_tag' => '<ol>', 'end_tag' => '</ol>'), 'list', array('block', 'listitem'), array());
     $bbcode->addCode('*', 'simple_replace', null, array('start_tag' => '<li>', 'end_tag' => '</li>'), '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(false);
     /*
      * End setup bbcode
      */
     $parsed_input = $bbcode->parse(trim($input));
     /*
      * TODO - This is a very quick and dirty emoticon emoticon handler.
      * This MUST be replaced asap
      */
     // Smileys to find...
     $emoticonsIn = array(':)', ':(', ':o', ':s', '8)', ':D');
     // And replace them with...
     $emoticonsOut = array('<img border="0" src="' . JRoute::_('media/com_ninjamonials/images/emoticons/smiley_smile.png') . '" alt=":)"/>', '<img border="0" src="' . JRoute::_('media/com_ninjamonials/images/emoticons/smiley_sad.png') . '" alt=":("/>', '<img border="0" src="' . JRoute::_('media/com_ninjamonials/images/emoticons/smiley_surprised.png') . '" alt=":o"/>', '<img border="0" src="' . JRoute::_('media/com_ninjamonials/images/emoticons/smiley_confused.png') . '" alt=":s"/>', '<img border="0" src="' . JRoute::_('media/com_ninjamonials/images/emoticons/smiley_cool.png') . '" alt="8)"/>', '<img border="0" src="' . JRoute::_('media/com_ninjamonials/images/emoticons/smiley_biggrin.png') . '" alt=":D"/>');
     $output = str_replace($emoticonsIn, $emoticonsOut, $parsed_input);
     return $output;
 }
Exemplo n.º 3
0
 private function addReply()
 {
     if (isset($_POST['addReply'])) {
         if (!isset($_POST['reply']) or empty($_POST['reply'])) {
             $msg = 'You need to fillout a reply!';
             header('Location: index.php?mod=Forum&act=read&id=' . (int) $_GET['id'] . '&msg=' . urlencode($msg));
             exit;
         } else {
             $message = nl2br(htmlentities($_POST['reply'], ENT_COMPAT, 'UTF-8'));
             // Smiley
             //$message = str_replace(":-)","<img src=\"/images/smiley/smile.png\">",$message);
             $message = str_replace(":-)", "<img src=images/smiley/smile.png>", $message);
             //$message = str_replace(":-(","<img src=\"/images/smiley/sad.png\">",$message);
             $message = str_replace(":-(", "<img src=images/smiley/sad.png>", $message);
             //Smiley  ende
             //BBCodes test
             require_once 'stringparser_bbcode.class.php';
             $bbcode = new StringParser_BBCode();
             $bbcode->addCode('b', 'simple_replace', null, array('start_tag' => '<b>', 'end_tag' => '</b>'), 'inline', array('block', 'inline'), array());
             // Fett
             $bbcode->addCode('i', 'simple_replace', null, array('start_tag' => '<i>', 'end_tag' => '</i>'), 'inline', array('block', 'inline'), array());
             // Kursiv
             $bbcode->addCode('u', 'simple_replace', null, array('start_tag' => '<u>', 'end_tag' => '</u>'), 'inline', array('block', 'inline'), array());
             // Unterstrichen
             $bbcode->addCode('list', 'simple_replace', null, array('start_tag' => '<ul>', 'end_tag' => '</ul>'), 'list', array('block', 'listitem'), array());
             // Liste
             $bbcode->addCode('*', 'simple_replace', null, array('start_tag' => '<li>', 'end_tag' => '</li>'), 'listitem', array('list'), array());
             // Punkt in der Liste
             $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->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);
             $message = $bbcode->parse($message);
             //BBCodes ende test
             $top = $this->db->fetchRow('SELECT * FROM `<ezrpg>forum_top` WHERE `id`=?', array($_GET['id']));
             $insert = array();
             $insert['id_cat'] = $top->id_cat;
             $insert['id_top'] = $top->id;
             $insert['poster'] = $this->player->username;
             $insert['message'] = $message;
             $insert['date'] = time();
             $this->db->insert('<ezrpg>forum_mes', $insert);
             $msg = 'The reply is succesfull added!';
             header('Location: index.php?mod=Forum&act=read&id=' . (int) $_GET['id'] . '&msg=' . urlencode($msg));
             exit;
         }
     }
 }
 function BBCodeToHTML($content)
 {
     global $_ARRAYLANG;
     $objBBCode = new \StringParser_BBCode();
     $objBBCode->addFilter(STRINGPARSER_FILTER_PRE, array(&$this, 'convertlinebreaks'));
     //unify all linebreak variants from different systems
     $objBBCode->addFilter(STRINGPARSER_FILTER_PRE, array(&$this, 'convertlinks'));
     //      $objBBCode->addFilter(STRINGPARSER_FILTER_POST, array(&$this, 'stripBBtags'));
     $objBBCode->addFilter(STRINGPARSER_FILTER_POST, array(&$this, 'removeDoubleEscapes'));
     $objBBCode->addParser(array('block', 'inline', 'link', 'listitem'), 'htmlspecialchars');
     $objBBCode->addParser(array('block', 'inline', 'link', 'listitem'), 'nl2br');
     $objBBCode->addParser('list', array(&$this, 'bbcode_stripcontents'));
     $objBBCode->addCode('b', 'simple_replace', null, array('start_tag' => '<b>', 'end_tag' => '</b>'), 'inline', array('block', 'inline'), array());
     $objBBCode->addCode('i', 'simple_replace', null, array('start_tag' => '<i>', 'end_tag' => '</i>'), 'inline', array('block', 'inline'), array());
     $objBBCode->addCode('u', 'simple_replace', null, array('start_tag' => '<u>', 'end_tag' => '</u>'), 'inline', array('block', 'inline'), array());
     $objBBCode->addCode('s', 'simple_replace', null, array('start_tag' => '<strike>', 'end_tag' => '</strike>'), 'inline', array('block', 'inline'), array());
     $objBBCode->addCode('url', 'usecontent?', array(&$this, 'do_bbcode_url'), array('usecontent_param' => 'default'), 'inline', array('listitem', 'block', 'inline'), array('link'));
     $objBBCode->addCode('img', 'usecontent', array(&$this, 'do_bbcode_img'), array('usecontent_param' => array('w', 'h')), 'image', array('listitem', 'block', 'inline', 'link'), array());
     $objBBCode->addCode('quote', 'callback_replace', array(&$this, 'do_bbcode_quote'), array('usecontent_param' => 'default'), 'block', array('block', 'inline'), array('list', 'listitem'));
     $objBBCode->addCode('code', 'usecontent', array(&$this, 'do_bbcode_code'), array('usecontent_param' => 'default'), 'block', array('block', 'inline'), array('list', 'listitem'));
     $objBBCode->addCode('list', 'simple_replace', null, array('start_tag' => '<ul>', 'end_tag' => '</ul>'), 'list', array('block', 'listitem'), array());
     $objBBCode->addCode('*', 'simple_replace', null, array('start_tag' => '<li>', 'end_tag' => '</li>'), 'listitem', array('list'), array());
     $objBBCode->setCodeFlag('*', 'closetag', BBCODE_CLOSETAG_OPTIONAL);
     $objBBCode->setCodeFlag('*', 'paragraphs', true);
     $objBBCode->setCodeFlag('list', 'paragraph_type', BBCODE_PARAGRAPH_BLOCK_ELEMENT);
     $objBBCode->setCodeFlag('list', 'opentag.before.newline', BBCODE_NEWLINE_DROP);
     $objBBCode->setCodeFlag('list', 'closetag.before.newline', BBCODE_NEWLINE_DROP);
     $objBBCode->setOccurrenceType('img', 'image');
     $objBBCode->setMaxOccurrences('image', 5);
     $objBBCode->setRootParagraphHandling(false);
     //do not convert new lines to paragraphs, see stringparser_bbcode::setParagraphHandlingParameters();
     $content = $objBBCode->parse($content);
     return $content;
 }
Exemplo n.º 5
0
    {
        if ($action == "validate") {
            return true;
        }
        return "<img src=\"" . html_encode($content) . "\" alt=\"\" title=\"\" />";
    }
}
$bbcode = new StringParser_BBCode();
$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("quote", "simple_replace", null, array("start_tag" => "<span class=\"quoteStyle\">", "end_tag" => "</span>"), "inline", array("block", "inline"), array());
$bbcode->addCode("code", "simple_replace", null, array("start_tag" => "<span class=\"codeStyle\">", "end_tag" => "</span>"), "inline", array("block", "inline"), array());
$bbcode->addCode("u", "simple_replace", null, array("start_tag" => "<span style=\"text-decoration: underline\">", "end_tag" => "</span>"), "inline", array("listitem", "block", "inline", "link"), array());
$bbcode->addCode("b", "simple_replace", null, array("start_tag" => "<span style=\"font-weight: bold\">", "end_tag" => "</span>"), "inline", array("listitem", "block", "inline", "link"), array());
$bbcode->addCode("i", "simple_replace", null, array("start_tag" => "<span style=\"font-style: oblique\">", "end_tag" => "</span>"), "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("color", "usecontent?", "do_bbcode_color", array("usecontent_param" => "default"), "link", array("listitem", "block", "inline"), array());
$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->setOccurrenceType("img", "image");
$bbcode->setMaxOccurrences("image", 10);
$bbcode->addCode("list", "simple_replace", null, array("start_tag" => "<ul>", "end_tag" => "</ul>"), "list", array("block", "listitem"), array());
$bbcode->addCode("*", "simple_replace", null, array("start_tag" => "<li>", "end_tag" => "</li>"), "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(false);