Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MyCode, links, mentions (and smilies) parsed in code tags
#1
So basically:

[ code=php]// @MangaD test :) http://lf-empire.de[/code]

results in this mess:

    PHP-Code:
// <DVZ_ME#0> <span style="font-weight: bold;" class="mycode_b">test</span> :) <a href="http://lf-empire.de" target="_blank" rel="noopener" class="mycode_url">http://lf-empire.de</a>

I know that smilies have been semi-fixed, but I have fixed this entirely:

Actually this was more complicated than I thought, my solution was only working if html is enabled, which isn't the case. So now I've fixed this with a dirty hack...


1. Go to file /forum/inc/class_parser.php

2. Search for:

Code:
// If MyCode needs to be replaced, first filter out [code] and [php] tags.
if(!empty($this->options['allow_mycode']) && $mybb->settings['allowcodemycode'] == 1)
{
preg_match_all("#\[(code|php)\](.*?)\[/\\1\](\r\n?|\n?)#si", $message, $code_matches, PREG_SET_ORDER);
$message = preg_replace("#\[(code|php)\](.*?)\[/\\1\](\r\n?|\n?)#si", "<mybb-code>\n", $message);
}

3. Add after:

Code:
$message = $plugins->run_hooks("parse_message_mangad", $message);

4. Go to file /forum/inc/plugins/BBGeSHi.php

5. Search for:

Code:
$plugins->add_hook("parse_message_end", "BBGeSHi_run");

6. Replace with:

Code:
$plugins->add_hook("parse_message_mangad", "BBGeSHi_run");

What this does is make the parser run first for codes before anything else before other mycode, smilies, etc are parsed, but after html symbols are parsed. Without this, the other tags are parsed first and result in html that is then parsed by BBGeSHi. So now we should be getting the correct result of the parsed tags instead of their html. This is still not what we want though, we don't want the tags to be parsed at all.

4. Search for:

Code:
$_geshied = str_replace("\r", "", $_geshied);

5. Add after:

Code:
$_geshied = str_replace(array('[',']'),array('&#91;','&#93;'),$_geshied);
$_geshied = str_replace("@","&#64;",$_geshied);
$_geshied = str_replace(".", "&#46;", $_geshied);
$_geshied = str_replace("(", "&#40;", $_geshied);
$_geshied = str_replace(")", "&#41;", $_geshied);
$_geshied = str_replace(":", "&#58;", $_geshied);
$_geshied = str_replace("^", "&#94;", $_geshied);
$_geshied = str_replace("$", "&#36;", $_geshied);
$_geshied = str_replace("_", "&#95;", $_geshied);

What this does is replace these special characters with their html codes (before they are parsed, thanks to step 3), so they won't be parsed.

This solution is not clean but fixes the bug. Though some smilies like =P probably will be parsed because '=' cannot be escaped. If there are better solutions please let me know! :)
[Image: random.php?pic=random]
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
The meaning of life is to give life a meaning.
Stop existing. Start living.
Reply
Thanks given by: Som1Lse , A-Man , Rhino.Freak , Silverthorn
#2
Implemented.

(12-07-2015, 03:47 AM)MangaD Wrote:  because '=' cannot be escaped

&#61; ?
Silverthorn / Blue Phoenix
~ Breaking LFE since 2008 ~

"Freeze, you're under vrest!" - Mark, probably.

» Gallery | » Sprites | » DeviantArt
Reply
Thanks given by: MangaD
#3
(12-07-2015, 07:22 PM)Blue Phoenix Wrote:  Implemented.

(12-07-2015, 03:47 AM)MangaD Wrote:  because '=' cannot be escaped

&#61; ?

It breaks the syntax highlighting. :'(
Because of the span tags, their attributes have things like style="...
and the = must be interpreted as html here. Same reason why we cannot escape < and >.

In the meantime I will try to find a solution for not parsing smilies completely...
    PHP-Code:
=P =P =P


Nevermind, seems to work with this particular smilie...
[Image: random.php?pic=random]
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
The meaning of life is to give life a meaning.
Stop existing. Start living.
Reply
Thanks given by:
#4
But mine still displayed '='! How did BP write do it? WTF!
Reply
Thanks given by:
#5
Fair enough.

    PHP-Code:
$wat = $that['this']->$aaa;
=p
Silverthorn / Blue Phoenix
~ Breaking LFE since 2008 ~

"Freeze, you're under vrest!" - Mark, probably.

» Gallery | » Sprites | » DeviantArt
Reply
Thanks given by:
#6
(12-07-2015, 07:32 PM)Hellblazer Wrote:  But mine still displayed '='! How did BP write do it? WTF!

You can escape characters manually yourself, using their respective HTML codes. So if you don't want MyCode to be parsed, you can replace [ with &#91;

If you are wondering how I managed to make the HTML code to show up as code and not [ , it's because I escaped the & of the code, making it &#38;#91;
[Image: random.php?pic=random]
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
The meaning of life is to give life a meaning.
Stop existing. Start living.
Reply
Thanks given by: Hellblazer
#7
I see what you did there.
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)