Skip to:
Content
Pages
Categories
Search
Top
Bottom

img tags


  • AphelionZ
    Participant

    @aphelionz

    i’d like for my users to be able to use <img> tags to post pictures. Is there a plugin available that will allow for this? I want to do everything ‘by the book’ as much as possible because i have such a fresh clean install here… please let me know?

Viewing 21 replies - 1 through 21 (of 21 total)

  • meeciteewurkor
    Member

    @meeciteewurkor

    This didn’t work:

    'img' => array(

    'src' => array(),

    'alt' => array(),

    'title' => array()),

    added that to formatting-function.php in the bb_allowed_tags() function.

    Seems like it would have, though?


    AphelionZ
    Participant

    @aphelionz

    indeed…


    AphelionZ
    Participant

    @aphelionz

    I just tried plugin-izing that but it didn’t work either… what are we missing?

    <?php

    /*

    Plugin Name: Allow <img> tags in posts

    Plugin URI: https://bbpress.org/forums/topic/149

    */

    function outlet_bb_allowed_tags() {

    $tags = array(

    'a' => array(

    'href' => array(),

    'title' => array(),

    'rel' => array()),

    'img' => array(

    'src' => array(),

    'alt' => array(),

    'title' => array()),

    'blockquote' => array('cite' => array()),

    'br' => array(),

    'code' => array(),

    'em' => array(),

    'strong' => array(),

    'ul' => array(),

    'ol' => array(),

    'li' => array()

    );

    return apply_filters( 'bb_allowed_tags', $tags );

    }

    add_filter( 'bb_allowed_tags', 'outlet_bb_allowed_tags', -1, 3);

    ?>


    meeciteewurkor
    Member

    @meeciteewurkor

    hmm.. I noticed on the post page, where it says “allowed markup” the img tag isn’t listed. Don’t know if that would have anything to do with it?


    meeciteewurkor
    Member

    @meeciteewurkor

    nevermind, that list is hard-coded into post-form.php. That would have to be changed, too, just to let people know the tag is allowable. If we can get it to work, of course. :)


    AphelionZ
    Participant

    @aphelionz

    hmm.. thats essentially just a print statement in edit-form.php in the templates folder… I added it but it did not help.


    meeciteewurkor
    Member

    @meeciteewurkor

    what about the encode_bad function in the same formatting-functions.php file?

    It has the same list of default allowed html tags. I don’t know enough php yet to understand what it does, though?

    Maybe the img tag needs to be placed here as well?

    function encode_bad( $text ) {

    $text = wp_specialchars($text);

    $text = preg_replace('|<(/?strong)>|', '<$1>', $text);

    $text = preg_replace('|<(/?em)>|', '<$1>', $text);

    $text = preg_replace('|<(/?a.*?)>|', '<$1>', $text);

    $text = preg_replace('|<(/?ol)>|', '<$1>', $text);

    $text = preg_replace('|<(/?p)>|', '<$1>', $text);

    $text = preg_replace('|
    |', '
    ', $text);

    $text = preg_replace('|<(/?ul)>|', '<$1>', $text);

    $text = preg_replace('|<(/?li)>|', '<$1>', $text);

    $text = preg_replace('|<(/?blockquote.*?)>|', '<$1>', $text);

    $text = preg_replace('|<(/?code)>|', '<$1>', $text);

    $text = preg_replace(“|(.*?)|se”, “‘' . encodeit('$1') . '‘”, $text);

    return $text;


    AphelionZ
    Participant

    @aphelionz

    Added this to the above function… still nothing

    function outlet_encode_bad( $text ) {

    $text = wp_specialchars($text);

    $text = preg_replace('|<(/?strong)>|', '<$1>', $text);

    $text = preg_replace('|<(/?em)>|', '<$1>', $text);

    $text = preg_replace('|<(/?a.*?)>|', '<$1>', $text);

    $text = preg_replace('|<(/?ol)>|', '<$1>', $text);

    $text = preg_replace('|<(/?p)>|', '<$1>', $text);

    $text = preg_replace('|<(/?img)>|', '<$1>', $text);

    $text = preg_replace('|
    |', '
    ', $text);

    $text = preg_replace('|<(/?ul)>|', '<$1>', $text);

    $text = preg_replace('|<(/?li)>|', '<$1>', $text);

    $text = preg_replace('|<(/?blockquote.*?)>|', '<$1>', $text);

    $text = preg_replace('|<(/?code)>|', '<$1>', $text);

    $text = preg_replace(“|(.*?)|se”, “‘' . encodeit('$1') . '‘”, $text);

    return $text;

    }

    add_filter( ‘encode_bad’, ‘outlet_encode_bad’, -1, 3);

    There’s also the bb_autop function but that unfortunately is beyond me… I can barely understand regex as it is.

    Anyone?


    peiqinglong
    Member

    @peiqinglong

    I would also like to know if there is an img plugin/rewrite for bbpress.


    AphelionZ
    Participant

    @aphelionz

    function outlet_encode_bad( $text ) {

    $text = wp_specialchars($text);

    $text = preg_replace('|<(/?strong)>|', '<$1>', $text);

    $text = preg_replace('|<(/?em)>|', '<$1>', $text);

    $text = preg_replace('|<(/?a.*?)>|', '<$1>', $text);

    $text = preg_replace('|<(/?ol)>|', '<$1>', $text);

    $text = preg_replace('|<(/?p)>|', '<$1>', $text);

    $text = preg_replace('|<(/?img.*?)>|', '<$1>', $text);

    $text = preg_replace('|
    |', '
    ', $text);

    $text = preg_replace('|<(/?ul)>|', '<$1>', $text);

    $text = preg_replace('|<(/?li)>|', '<$1>', $text);

    $text = preg_replace('|<(/?blockquote.*?)>|', '<$1>', $text);

    $text = preg_replace('|<(/?code)>|', '<$1>', $text);

    $text = preg_replace(“|(.*?)|se”, “‘' . encodeit('$1') . '‘”, $text);

    return $text;

    }

    ..should work, but doesn’t.

    Ok, how bbPress does it is that it takes every < and > and replaces them with the &lt; and &gt; characters.

    Then, it goes through the above list (the exceptions) and turns the lt’s and the gt’s back to actual <‘s and >’s. I can’t get it to recognize the img tag though, because regular expressions confuse the hell out of me. If anybody can get it to recognize the img tags, you’d be making a lot of people happy. For now I am going to take a break…


    meeciteewurkor
    Member

    @meeciteewurkor

    yeah, regex is confusing sometimes. I just bought a book on them off of Amazon. I’ll get back with you in a week or so. :) jk. I’ll keep fiddling and see what I can turn up, if anything.


    meeciteewurkor
    Member

    @meeciteewurkor

    I would be willing to bet that if you duplicated the “a” tag and used “img” where every “a” is, it would work. because “img” uses attributes like “a” uses attributes. just a thought. I’ll give it a shot…


    meeciteewurkor
    Member

    @meeciteewurkor

    ha! I got it to work… hold on and I’ll post what I did…


    meeciteewurkor
    Member

    @meeciteewurkor

    in formatting-functions.php I added this under the function encode_bad:

    $text = preg_replace('|<(/?img.*?)>|', '<$1>', $text);

    under function bb_allowed_tags() I added this:

    'img' => array(

    'src' => array(),

    'alt' => array(),

    'title' => array()),

    for an example see this post I made where it succeeded.

    http://meeciteewurkor.com/bbpress/topic/7?replies=2#post-21

    I added the /bb-images/bbpress.png image in a post. yay!


    AphelionZ
    Participant

    @aphelionz

    but that’s exactly what I did but I plugin-ified it instead of just hacking the code…

    I just tried what you did and it works! Excellent. There must be something wrong with my plugin approach (aka i don’t fully understand filters).

    Great work – my users will be excited.


    meeciteewurkor
    Member

    @meeciteewurkor

    heh.. didn’t notice that. It is exactly the same.

    oh well, at least one can place images now. Glad we got this one figured out. If I ever implement bbpress on a wide scale, that will be the first thing users ask me. :)


    meeciteewurkor
    Member

    @meeciteewurkor

    I’m not sure how the plugins work, but this would be a good candidate, so the core code doesn’t have to be hacked.


    talkaboutdesign
    Member

    @talkaboutdesign

    tried the code you provided, doesnt work.

    http://www.talkaboutdesign.com/forum/topic.php?id=2&replies=2

    I am happy to find many good details here in the post, writing is just fantastic.Wonderful post!


    Erlend
    Participant

    @sadr

    mrtonny8 is a spambot. Please ban.

Viewing 21 replies - 1 through 21 (of 21 total)
  • You must be logged in to reply to this topic.
Skip to toolbar