Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Does not work when Advance Editor is set to BBcode

This plugin does not work when Editor post format is set to BBcode.
Plugin only shows default image on discussion list but does not show uploaded discussion image.
Please could you help fix this?

Comments

  • This plugin was not made to work with BBcode it never did there is nothing to fix.

    If you want it to work with BBcode you will have to modify it yourself.

    You will need to modify the preg_match bellow to reflect BBcode. The way it is now, only works with markup and html.

    preg_match('#\<img.+?src="([^"]*).+?\>#s', $Sender->EventArguments['Discussion']->Body, $images);
            if ($images[1]) {
                $ImageSrc = $images[1];
    
  • @vrijvlinder - can you please modify the preg_match to reflect BBCode?

  • If you can give me a couple months to learn how… I am traveling and can't do it at the moment sorry :(

  • You could also match the rendered output:

    preg_match('#\<img.+?src="([^"]*).+?\>#s', Gdn_Format::to($Sender->EventArguments['Discussion']->Body, $Sender->EventArguments['Discussion']->Format), $images);
    

    Could be a problem with Emoji though.

  • RiverRiver MVP
    edited August 2016

    @Bleistivt said:
    You could also match the rendered output:

    preg_match('#\<img.+?src="([^"]*).+?\>#s', Gdn_Format::to($Sender->EventArguments['Discussion']->Body, $Sender->EventArguments['Discussion']->Format), $images);
    

    Could be a problem with Emoji though.

    very clean if you don't use emojis as you said, <3 <3 which will lead to 404 for image.

    @Prosper said:
    This plugin does not work when Editor post format is set to BBcode.
    Plugin only shows default image on discussion list but does not show uploaded discussion image.
    Please could you help fix this?

    alternatively a big kludge here..

    assumptions the bbcode and markdown are the ones that automatically occur when using the advanced editor

    meaning [img] and [/img] BBCode tags or the !{}(image url) Markdown info

    change in both places in the plugin.

     preg_match('#\<img.+?src="([^"]*).+?\>#s', $Sender->EventArguments['Discussion']->Body, $images);
            if ($images[1]) {
                $ImageSrc = $images[1];
            }
    

    to

            $Discuss = $Sender->EventArguments['Discussion'];
            $formatter = $Discuss->Format;
           // check formatter - choose bbcode or markdown inserted image 
           switch($formatter) {
            case "BBCode":
             preg_match('#\[img\](.*?)\[/img\]#si', $Discuss->Body, $images);
            break;
            case "Markdown":
             preg_match('#\!\[\]\((.*?)\"\"\)#si', $Discuss->Body, $images);
            break;
            }
            // if no bbcode or markdown image found default to standard html.
            if ($images[1]) {
             $ImageSrc = $images[1];
             } else {
             preg_match('#\<img.+?src="([^"]*).+?\>#si', $Discuss->Body, $images);
              if ($images[1]) {
                 $ImageSrc = $images[1];
                 } 
            }
    

    Pragmatism is all I have to offer. Avoiding the sidelines and providing centerline pro-tips.

Sign In or Register to comment.