Skip to:
Content
Pages
Categories
Search
Top
Bottom

Adding Images to a Topic.

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

  • chandersbs
    Member

    @chandersbs

    Copy and paste this code and save it as allow-images.php

    <?php

    /*

    Plugin Name: Allow Images

    Plugin URI: https://bbpress.org/#

    Description: Allows <img /> tags to be posted in your forums. The image must be a png, gif or jpeg.

    Author: Michael D Adams

    Author URI: http://blogwaffe.com/

    Version: 0.7.1

    */

    // You can add more tags here

    function allow_images_allowed_tags( $tags ) {

    $tags = array(‘src’ => array(), ‘title’ => array(), ‘alt’ => array());

    return $tags;

    }

    function allow_images_encode_bad( $text ) {

    $text = wp_specialchars( $text );

    $text = preg_replace(‘|
    |’, ‘
    ‘, $text);

    foreach ( bb_allowed_tags() as $tag => $args ) {

    if ( ‘br’ == $tag )

    continue;

    if ( $args )

    $text = preg_replace(“|<(/?$tag.*?)>|”, ‘<$1>’, $text);

    else

    $text = preg_replace(“|<(/?$tag)>|”, ‘<$1>’, $text);

    }

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

    return $text;

    }

    function allow_images( $text ) {

    if ( preg_match_all(‘/<img(.+?)src=(“|’)(.+?)\2(.+?)>/i’, $text, $matches, PREG_SET_ORDER ) )

    foreach( $matches as $match )

    if (

    preg_match(‘/src=/i’, $match[4]) // multiple src = someone’s trying to cheat

    ||

    !in_array(substr($match[3], -4), array(‘.png’, ‘.jpg’, ‘.gif’)) // only match .jpg, .gif, .png

    &&

    ‘.jpeg’ != substr($match[3], -5) // and .jpeg

    )

    $text = str_replace($match[0], ”, $text);

    return $text;

    }

    remove_filter( ‘pre_post’, ‘encode_bad’ );

    add_filter( ‘pre_post’, ‘allow_images_encode_bad’, 9 );

    add_filter( ‘pre_post’, ‘allow_images’, 52 );

    add_filter( ‘bb_allowed_tags’, ‘allow_images_allowed_tags’ );

    ?>

    Upload it to your my-plugins folder, create if it doesn’t exist. And activate it.


    chandersbs
    Member

    @chandersbs

    I couldn’t find the plugin, but you can’t download it from this website, just search for a plugin called “Allow images”


    chrishajer
    Participant

    @chrishajer

    https://bbpress.org/plugins/topic/allow-images/page/4/

    There was a problem with it working with 1.0 though. I thought someone posted a fix in the comments.

    Thanks. Will the above code posted by chandersbs work in 1.0?

    Thanks.

    That code above did not work for me chandersbs. The one below did. Is it safe to use the one below?

    <?php

    /*

    Plugin Name: Allow Images

    Plugin URI: https://bbpress.org/#

    Description: Allows <img /> tags to be posted in your forums. The image must be a png, gif or jpeg.

    Author: Michael D Adams

    Author URI: http://blogwaffe.com/

    Version: 0.7.1

    */

    // You can add more tags here

    function allow_images_allowed_tags( $tags ) {

    $tags = array(‘src’ => array(), ‘title’ => array(), ‘alt’ => array());

    return $tags;

    }

    function allow_images( $text ) {

    if ( preg_match_all(‘/<img(.+?)src=(“|’)(.+?)\2(.*?)>/i’, $text, $matches, PREG_SET_ORDER ) ){

    foreach( $matches as $match ){

    if (preg_match(‘/src=/i’, $match[4]) /* multiple src = someone’s trying to cheat */ || !in_array(substr($match[3], -4), array(‘.png’, ‘.jpg’, ‘.gif’)) /*only match .jpg, .gif, .png*/ && ‘.jpeg’ != substr($match[3], -5) /*and .jpeg*/){

    $text = str_replace($match[0], ”, $text);

    }

    }

    }

    return $text;

    }

    add_filter( ‘pre_post’, ‘allow_images’, 52 );

    add_filter( ‘bb_allowed_tags’, ‘allow_images_allowed_tags’ );

    ?>

    Also is it possible for a user to upload an image that resides on their computer rather than on a server? If so, how?

    Thanks.

    That code is probably fine, the version number is okay anyway but it’s slightly different to the one above.

    There’s an upload plugin for PostImage: https://bbpress.org/forums/topic/request-image-upload-with-free-image-hosting#post-56890

    That’s the only one I know of

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