Jump to content

BBCODE making the <img> tag inactive


php_begins

Recommended Posts

My BBCODE makes the <img> tag inactive. For example, when I have an <img>tag such as:

<br><img width='400' src='http://www.petergrand.com/deck.jpg'><br>

It should display that image but it doesn't when I call with my BBCodeToHTML function.

Here is my bbcode ..can it be modified without affecting other pages?

 

<style type="text/css">
/* Syntax Highlight Code Box */
.linenum{
    text-align:right;
    background:#FDECE1;
    border:1px solid #cc6666;
    padding:18px 1px 18px 1px;
    font-family:Courier New, Courier;
    float:left;
    width:17px;
    margin:3px 0px 30px 0px;
    }

code    {/* safari/konq hack */
    font-family:Courier New, Courier;
    margin:0;
    padding:0;
}

.linetext{
    width:700px;
    text-align:left;
    background:white;
    border:1px solid #cc6666;
    border-left:0px;
    padding:0px 1px 0px 8px;
    font-family:Courier New, Courier;
    float:left;
    margin:3px 0px 30px 0px;
    }

br.clear    {
    clear:both;
}
</style>
<?php
function printCode($code, $lines_number = 0,$title='Code: ')
{
    $break = '
';
    if (!is_array($code)) $codeE = explode($break, $code);
    $count_lines = count($codeE);

    $r = '<div style="margin-bottom: 2px;font-size:10px;font-family:sans-serif">'
        .$title
        .'</div>';

    if ($lines_number)
    {
        $r .= '<div class="linenum">';
        for($i=1;$i<=$count_lines;$i++)
        {
            $r .= $i.'<br />';
        }
        $r .= '</div>';
    }

    $r .= '<div class="linetext">';
    $r .= highlight_string($code,1);
    $r .= (strpos($code,'<?php')===false?$break:'');
    $r .= '</div>';

    return '<div class="code">'.$r.'</div>';
}

function BBCodeToHTML($text) {
    $text = trim(htmlentities($text));


    if(!function_exists('php_box'))
    {
        function php_box($s)
        {
            $code = stripslashes($s[1]);
            $break = '
';
            if(strpos($code,'<?php')===false) $code = '<?php '.$break.$code.$break.'?>';
            return printCode( html_entity_decode($code), true, 'PHP: ');
        }
    }
    $text = preg_replace_callback('/\[php\](.*?)\[\/php\]/Usi','php_box',$text);

    // BBCode [ code ]
    if (!function_exists('escape')) {
        function escape($s) {
            return printCode( html_entity_decode($s[1]), true);
        }
    }
    $text = preg_replace_callback('/\[code\](.*?)\[\/code\]/msi', "escape", $text);

    // BBCode [ quote ] / [ quote="name" ]
    if(!function_exists(parseQuotesRecursive))
    {
        function parseQuotesRecursive($input)
        {
            $regex = '#\[quote\=?"?(.*?)"?\]((?:[^[]|\[(?!/?quote\=?"?(.*?)"?\])|(?R))+)\[/quote\]#i';
            if (is_array($input))
            {
                $input = '<blockquote style="margin: 5px 20px 20px;">'
                    .'<div style="margin-bottom: 2px;font-size:10px;font-family:sans-serif">'
                    .'Quote'.( (strlen($input[1])>0) ? ' From <strong>'.$input[1].'</strong>' : '' ).','
                    .'</div>'
                    .'<div style="padding:4px;padding-top:0;border:#000 1px inset">'
                    .$input[2]
                    .'</div>'
                    .'</blockquote>';
            }
            return preg_replace_callback($regex, 'parseQuotesRecursive', $input);
        }
    }
    $text = parseQuotesRecursive($text);

    //BBcode to Find..
        $in = array(
                     '/\[b\](.*?)\[\/b\]/si',
                     '/\[i\](.*?)\[\/i\]/si',
                     '/\[u\](.*?)\[\/u\]/si',
                     '#\[img\](https?://[-A-Z0-9+&@\#/%?=~_|!:,.;]*[-A-Z0-9+&@\#/%=~_|]\.(?:jpg|jpeg|gif|png|bmp))\[\/img\]#si',
                     '#\[email\]([-A-Z0-9+&@\#/%?=~_|!:,.;]*[-A-Z0-9+&@\#/%=~_|])\[\/email\]#si',
                     '#\[url\=((?:ftp|http?)://[-A-Z0-9+&@\#/%?=~_|!:,.;]*[-A-Z0-9+&@\#/%=~_|])\](.*?)\[\/url\]#si',
                     '/\[size\="?(.*?)"?\](.*?)\[\/size\]/si',
                     '/\[color\="?(.*?)"?\](.*?)\[\/color\]/si',
                     '#\[url\]((??!/?\[(?:url|b|img|i)\]).)*?)\|(.*?)\[/url\]#si',
                     '#\[url\]((??!/?\[(?:url|b|img|i)\]).)*?)\[/url\]#si',
                     '/\[list\=(.*?)\](.*?)\[\/list\]/si',
                     '/\[list\](.*?)\[\/list\]/si',
                     '/\[\*\]\s?(.*?)\n/si'
    );
    // And replace them by...
    $out = array(
                     '<strong>\1</strong>',
                     '<em>\1</em>',
                     '<u>\1</u>',
                     '<img src="\1" alt="\1" />',
                     '<a href="mailto:\1">\1</a>',
                     '<a href="\1">\2</a>',
                     '<span style="font-size:\1%">\2</span>',
                     '<span style="color:\1">\2</span>',
                     "<a href='$1'>$2</a>",
                     "<a href='$1'>$1</a>",
                     '<ol start="\1">\2</ol>',
                     '<ul>\1</ul>',
                     '<li>\1</li>'
    );
    $text = preg_replace($in, $out, $text);

    // paragraphs
    $text = str_replace("\r", "", $text);
    $text = "<p>".ereg_replace("(\n){2,}", "</p><p>", $text)."</p>";
    $text = nl2br($text);

    // clean some tags to remain strict
    // not very elegant, but it works.
    if (!function_exists('removeBr')) {
        function removeBr($s) {
            return str_replace("<br />", "", $s[0]);
        }
    }
    $text = preg_replace_callback('/<pre>(.*?)<\/pre>/ms', "removeBr", $text);
    $text = preg_replace('/<p><pre>(.*?)<\/pre><\/p>/ms', "<pre>\\1</pre>", $text);

    $text = preg_replace_callback('/<ul>(.*?)<\/ul>/ms', "removeBr", $text);
    $text = preg_replace('/<p><ul>(.*?)<\/ul><\/p>/ms', "<ul>\\1</ul>", $text);

    return $text;
}

?>

Link to comment
Share on other sites

function BBCodeToHTML($text) {
    $text = trim(htmlentities($text));

 

The first line of your BBCode function is converting all HTML to HTML Entities; which is proper. So the <IMG > tag is changed to be displayed rather than interpreted. You should probably be using the BBCode tag for an image ( ....

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.