MyBB Community Forums

Full Version: Delete [img] tags from quoted posts
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Pretty simple I think; I'd like to make it so that when someone selects to quote a post, any img tags in the post are stripped out.
css:

blockquote img a,blockquote img{display:none}
I'd rather strip it from the input when the post is quoted -- so that an img can be manually inserted into a quote if necessary -- but this is helpful if it can't happen, thanks.
<?php

if(!defined("IN_MYBB"))
{
	die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

/**
 * Plugin info
 *
 */
function dont_quote_images_info()
{
	return array(
				"name" => "Dont Quote Images",
				"description" => "",
				"website" => "",
				"author" => "Santiago Dimattia",
				"authorsite" => "http://www.teleportz.com.ar",
				"version" => "0.1",
				"guid" => "",
				"compatibility" => "16*"
			);
}

/**
 * Hook functions
 *
 */
$plugins->add_hook('newreply_end', 'dont_quote_images_do');

/**
 * Delete :)
 *
 */
function dont_quote_images_do()
{
	global $mybb, $message;

	if(isset($mybb->input['pid']))
	{
		$message = preg_replace("#\[img\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#ise", "", $message);
	}
}

As far as I can tell, it works OK.
where do you place this?
(2011-02-08, 08:35 PM)Uncontrol Wrote: [ -> ]where do you place this?

It's a plugin. Save the code as dont_quote_images.php and upload it to the plugins folder.
no ending parameters. correct code

<?php

if(!defined("IN_MYBB"))
{
    die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

/**
 * Plugin info
 *
 */
function dont_quote_images_info()
{
    return array(
                "name" => "Dont Quote Images",
                "description" => "",
                "website" => "",
                "author" => "Santiago Dimattia",
                "authorsite" => "http://www.teleportz.com.ar",
                "version" => "0.1",
                "guid" => "",
                "compatibility" => "16*"
            );
}

/**
 * Hook functions
 *
 */
$plugins->add_hook('newreply_end', 'dont_quote_images_do');

/**
 * Delete :)
 *
 */
function dont_quote_images_do()
{
    global $mybb, $message;

    if(isset($mybb->input['pid']))
    {
        $message = preg_replace("#\[img\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#ise", "", $message);
    }
}
?> 
(2011-02-08, 10:15 PM)TheGodFather Wrote: [ -> ]no ending parameters. correct code

<?php

if(!defined("IN_MYBB"))
{
    die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

/**
 * Plugin info
 *
 */
function dont_quote_images_info()
{
    return array(
                "name" => "Dont Quote Images",
                "description" => "",
                "website" => "",
                "author" => "Santiago Dimattia",
                "authorsite" => "http://www.teleportz.com.ar",
                "version" => "0.1",
                "guid" => "",
                "compatibility" => "16*"
            );
}

/**
 * Hook functions
 *
 */
$plugins->add_hook('newreply_end', 'dont_quote_images_do');

/**
 * Delete :)
 *
 */
function dont_quote_images_do()
{
    global $mybb, $message;

    if(isset($mybb->input['pid']))
    {
        $message = preg_replace("#\[img\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#ise", "", $message);
    }
}
?> 

It's not required to close the PHP tags.
In fact, it's recommended not to close them, as it prevents whitespaces at the end of the file (causing headers not being sent to the browser).

---

If you do close the tag, double-check if there is a whitespace or a linebreak at the end of the file before saving.
I suggest not delete img tags, but replace with image links.
How to do that? Wink
This should work:

$message = preg_replace("#\[img\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#ise", "\(Image: $2)\n", $message);
Pages: 1 2