Convert quoted images to url

All new MODs released in our MOD Database will be announced in here. All support for released MODs needs to take place in the Customisations Database.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTICE: This forum is only for the announcement of new releases and/or updates of MODs. Any MOD support should be obtained through the Customisations Database in the support area designated for each MOD.

A direct link to support for each MOD is in the first post of the respective topic.
Miata.SharK
Registered User
Posts: 5
Joined: Fri May 08, 2009 10:37 am

Re: Convert quoted images to url

Post by Miata.SharK »

Php version: 3.0.4
Other Mod Installed: http://www.phpbb.it/forum/viewtopic.php?f=63&t=12314

This is my message_parse.php

Code: Select all

	/**
	* Parse BBCode
	*/
	function parse_bbcode()
	{
	
		if (!$this->bbcodes)
		{
			$this->bbcode_init();
		}
		
		global $user;
		
//Start MOD Convert quoted images to url    
      preg_match_all('#\[quote(.*?)\](.*?)\[/quote\]#si', $this->message, $qmatch );
      foreach ($qmatch[2]as $qmatchin){
         $qres = preg_replace('#\[url=(.*(jpg|jpeg|gif|png|bmp))\]\[img\].*\[/img\]\[/url\]#iU', '[ [url=\1]'. $user->lang['IMAGE'] .'[/url] ]', $qmatchin);
         $qres = preg_replace('#\[url=.*\]\[img\](.*)\[/img\]\[/url\]#iU', '[ [url=\1]'. $user->lang['IMAGE'] .'[/url] ]', $qmatchin);
         $qres = preg_replace('#\[img\](.*)\[/img\]#iU', '[ [url=\1]'. $user->lang['IMAGE'] .'[/url] ]', $qmatchin);
         $qres = preg_replace('#\[youtube\]\n*(.*)\n*\[/youtube\]#iU', '[url=$1]Video di YouTube postato precedentemente[/url]', $qmatchin);
         $this->message = str_replace($qmatchin, $qres, $this->message);
      }
      //End MOD Convert quoted images to url

		$this->bbcode_bitfield = '';
		$bitfield = new bitfield();

		foreach ($this->bbcodes as $bbcode_name => $bbcode_data)
		{
			if (isset($bbcode_data['disabled']) && $bbcode_data['disabled'])
			{
				foreach ($bbcode_data['regexp'] as $regexp => $replacement)
				{
					if (preg_match($regexp, $this->message))
					{
						$this->warn_msg[] = sprintf($user->lang['UNAUTHORISED_BBCODE'] , '[' . $bbcode_name . ']');
						continue;
					}
				}
			}
			else
			{
				foreach ($bbcode_data['regexp'] as $regexp => $replacement)
				{
					// The pattern gets compiled and cached by the PCRE extension,
					// it should not demand recompilation
					if (preg_match($regexp, $this->message))
					{
						$this->message = preg_replace($regexp, $replacement, $this->message);
						$bitfield->set($bbcode_data['bbcode_id']);
					}
				}
			}
		}

		$this->bbcode_bitfield = $bitfield->get_base64();
	}

	/**
	* Prepare some bbcodes for better parsing
	*/
	function prepare_bbcodes()
	{
		// Ok, seems like users instead want the no-parsing of urls, smilies, etc. after and before and within quote tags being tagged as "not a bug".
		// Fine by me ;) Will ease our live... but do not come back and cry at us, we won't hear you.

		/* Add newline at the end and in front of each quote block to prevent parsing errors (urls, smilies, etc.)
		if (strpos($this->message, '[quote') !== false && strpos($this->message, '[/quote]') !== false)
		{
			$this->message = str_replace("\r\n", "\n", $this->message);

			// We strip newlines and spaces after and before quotes in quotes (trimming) and then add exactly one newline
			$this->message = preg_replace('#\[quote(=".*?")?\]\s*(.*?)\s*\[/quote\]#siu', '[quote\1]' . "\n" . '\2' ."\n[/quote]", $this->message);
		}
		*/

		// Add other checks which needs to be placed before actually parsing anything (be it bbcodes, smilies, urls...)
	}

	/**
	* Init bbcode data for later parsing
	*/
	function bbcode_init()
	{
		static $rowset;

		// This array holds all bbcode data. BBCodes will be processed in this
		// order, so it is important to keep [code] in first position and
		// [quote] in second position.
		$this->bbcodes = array(
			'code'			=> array('bbcode_id' => 8,	'regexp' => array('#\[code(?:=([a-z]+))?\](.+\[/code\])#ise' => "\$this->bbcode_code('\$1', '\$2')")),
			'quote'			=> array('bbcode_id' => 0,	'regexp' => array('#\[quote(?:="(.*?)")?\](.+)\[/quote\]#ise' => "\$this->bbcode_quote('\$0')")),
			'attachment'	=> array('bbcode_id' => 12,	'regexp' => array('#\[attachment=([0-9]+)\](.*?)\[/attachment\]#ise' => "\$this->bbcode_attachment('\$1', '\$2')")),
			'b'				=> array('bbcode_id' => 1,	'regexp' => array('#\[b\](.*?)\[/b\]#ise' => "\$this->bbcode_strong('\$1')")),
			'i'				=> array('bbcode_id' => 2,	'regexp' => array('#\[i\](.*?)\[/i\]#ise' => "\$this->bbcode_italic('\$1')")),
			'url'			=> array('bbcode_id' => 3,	'regexp' => array('#\[url(=(.*))?\](.*)\[/url\]#iUe' => "\$this->validate_url('\$2', '\$3')")),
			'img'			=> array('bbcode_id' => 4,	'regexp' => array('#\[img\](.*)\[/img\]#iUe' => "\$this->bbcode_img('\$1')")),
			'size'			=> array('bbcode_id' => 5,	'regexp' => array('#\[size=([\-\+]?\d+)\](.*?)\[/size\]#ise' => "\$this->bbcode_size('\$1', '\$2')")),
			'color'			=> array('bbcode_id' => 6,	'regexp' => array('!\[color=(#[0-9a-f]{6}|[a-z\-]+)\](.*?)\[/color\]!ise' => "\$this->bbcode_color('\$1', '\$2')")),
			'u'				=> array('bbcode_id' => 7,	'regexp' => array('#\[u\](.*?)\[/u\]#ise' => "\$this->bbcode_underline('\$1')")),
			'list'			=> array('bbcode_id' => 9,	'regexp' => array('#\[list(?:=(?:[a-z0-9]|disc|circle|square))?].*\[/list]#ise' => "\$this->bbcode_parse_list('\$0')")),
			'email'			=> array('bbcode_id' => 10,	'regexp' => array('#\[email=?(.*?)?\](.*?)\[/email\]#ise' => "\$this->validate_email('\$1', '\$2')")),
			'flash'			=> array('bbcode_id' => 11,	'regexp' => array('#\[flash=([0-9]+),([0-9]+)\](.*?)\[/flash\]#ie' => "\$this->bbcode_flash('\$1', '\$2', '\$3')"))
		);

		// Zero the parsed items array
		$this->parsed_items = array();

		foreach ($this->bbcodes as $tag => $bbcode_data)
		{
			$this->parsed_items[$tag] = 0;
		}

		if (!is_array($rowset))
		{
			global $db;
			$rowset = array();

			$sql = 'SELECT *
				FROM ' . BBCODES_TABLE;
			$result = $db->sql_query($sql);

			while ($row = $db->sql_fetchrow($result))
			{
				$rowset[] = $row;
			}
			$db->sql_freeresult($result);
		}

		foreach ($rowset as $row)
		{
			$this->bbcodes[$row['bbcode_tag']] = array(
				'bbcode_id'	=> (int) $row['bbcode_id'],
				'regexp'	=> array($row['first_pass_match'] => str_replace('$uid', $this->bbcode_uid, $row['first_pass_replace']))
			);
		}
	}
The website link is http://mx5italia.netsons.org/phpbb/
Test user id: provolo
test user password: provolo
There is a testing area in the lower category

I hope you can make it work :)

thanks a lot!
User avatar
Ger
Registered User
Posts: 2117
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100

Re: Convert quoted images to url

Post by Ger »

Try to replace this:

Code: Select all

//Start MOD Convert quoted images to url    
      preg_match_all('#\[quote(.*?)\](.*?)\[/quote\]#si', $this->message, $qmatch );
      foreach ($qmatch[2]as $qmatchin){
         $qres = preg_replace('#\[url=(.*(jpg|jpeg|gif|png|bmp))\]\[img\].*\[/img\]\[/url\]#iU', '[ [url=\1]'. $user->lang['IMAGE'] .'[/url] ]', $qmatchin);
         $qres = preg_replace('#\[url=.*\]\[img\](.*)\[/img\]\[/url\]#iU', '[ [url=\1]'. $user->lang['IMAGE'] .'[/url] ]', $qmatchin);
         $qres = preg_replace('#\[img\](.*)\[/img\]#iU', '[ [url=\1]'. $user->lang['IMAGE'] .'[/url] ]', $qmatchin);
         $qres = preg_replace('#\[youtube\]\n*(.*)\n*\[/youtube\]#iU', '[url=$1]Video di YouTube postato precedentemente[/url]', $qmatchin);
         $this->message = str_replace($qmatchin, $qres, $this->message);
      }
      //End MOD Convert quoted images to url
 
with

Code: Select all

 //Start MOD Convert quoted images to url
      preg_match_all('#\[quote(.*?)\](.*?)\[/quote\]#si', $this->message, $qmatch );
      foreach ($qmatch[2]as $qmatchin){
         preg_match_all('#\[code\](.*?)\[/code\]#is', $qmatchin, $qcode);
         $crepl = str_replace('[img]', '[img]', $qcode[1]);
         $replacement = str_replace($qcode[1], $crepl, $qmatchin);
         $replacement = preg_replace('#\[url=\n*(.*(jpg|jpeg|gif|png|bmp))\n*\]\n*\[img\]\n*(.*)\n*\[/img\]\n*\[/url\]#iU', '[ [url=$1]'. $user->lang['IMAGE'] .'[/url] ]', $replacement);
         $replacement = preg_replace('#\[url=\n*(.*)\n*\]\n*\[img\]\n*(.*)\n*\[/img\]\n*\[/url\]#iU', '[ [url=$1]'. $user->lang['IMAGE'] .'[/url] ]', $replacement);
         $replacement = preg_replace('#\[img\]\n*(.*)\n*\[/img\]#iU', '[ [url=$1]'. $user->lang['IMAGE'] .'[/url] ]', $replacement);
         $replacement = preg_replace('#\[youtube\]\n*(.*)\n*\[/youtube\]#iU', '[url=$1]Video di YouTube postato precedentemente[/url]', $replacement);
         $this->message = str_replace($qmatchin, $replacement, $this->message);
         $this->message = str_replace($crepl, $qcode[1], $this->message);
      }
      //End MOD Convert quoted images to url   
My extensions:
Simple CMS, Feed post bot, Avatar Resize, Modbreak, Magic OGP, Live topic update, Modern Quote, Quoted Where (GDPR) and Autoresponder.
Newest: FAQ manager for 3.2

Like my work? Buy me a coffee to keep it coming. :ugeek:

Kinderpraktijk SensIQ

-Don't PM me for support-
Miata.SharK
Registered User
Posts: 5
Joined: Fri May 08, 2009 10:37 am

Re: Convert quoted images to url

Post by Miata.SharK »

YESSSSSS :D

It works perfeclty!!!!!!!


Thank you so much!!!! :D
User avatar
Ger
Registered User
Posts: 2117
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100

Re: Convert quoted images to url

Post by Ger »

You're welcome. :)
My extensions:
Simple CMS, Feed post bot, Avatar Resize, Modbreak, Magic OGP, Live topic update, Modern Quote, Quoted Where (GDPR) and Autoresponder.
Newest: FAQ manager for 3.2

Like my work? Buy me a coffee to keep it coming. :ugeek:

Kinderpraktijk SensIQ

-Don't PM me for support-
ducloi
Registered User
Posts: 28
Joined: Tue Jul 06, 2004 10:41 am

Re: Convert quoted images to url

Post by ducloi »

:cry:
I want to quote, keep and comment 1 of 3 images in a post. How can I do that?
User avatar
Ger
Registered User
Posts: 2117
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100

Re: Convert quoted images to url

Post by Ger »

Not with this MOD, since this is intended to remove the quoted images when posting.
What you could do is remove this MOD and change posting.php as described here. That removes the images when hitting the quote-button and allows the user to manually put it back in. The removal of this MOD is needed because this original MOD strips the images when submitting.

Bare in mind that the changes in the linked topic aren't extensively tested so make sure you have a backup.
My extensions:
Simple CMS, Feed post bot, Avatar Resize, Modbreak, Magic OGP, Live topic update, Modern Quote, Quoted Where (GDPR) and Autoresponder.
Newest: FAQ manager for 3.2

Like my work? Buy me a coffee to keep it coming. :ugeek:

Kinderpraktijk SensIQ

-Don't PM me for support-
User avatar
Leinad4Mind
Translator
Posts: 865
Joined: Sun Jun 01, 2008 11:08 pm

Re: Convert quoted images to url

Post by Leinad4Mind »

This works on 3.0.5?

Best regards
Want to access all my Premium MODs and Extensions? Check out my store
phpBB Portugal Translator and Moderator
User avatar
Ger
Registered User
Posts: 2117
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100

Re: Convert quoted images to url

Post by Ger »

Dunno, haven't tested that yet. Try it on your test board I'd say, and let us know! :)
My extensions:
Simple CMS, Feed post bot, Avatar Resize, Modbreak, Magic OGP, Live topic update, Modern Quote, Quoted Where (GDPR) and Autoresponder.
Newest: FAQ manager for 3.2

Like my work? Buy me a coffee to keep it coming. :ugeek:

Kinderpraktijk SensIQ

-Don't PM me for support-
User avatar
Neuropass
Registered User
Posts: 1163
Joined: Fri Apr 17, 2009 2:02 pm
Location: SciTE4AutoIt3

Re: Convert quoted images to url

Post by Neuropass »

doeas it work on 3.05??
NTH08
Registered User
Posts: 50
Joined: Sat Dec 13, 2008 11:31 am
Location: Vietnam

Re: Convert quoted images to url

Post by NTH08 »

Yes, it does :D
User avatar
Neuropass
Registered User
Posts: 1163
Joined: Fri Apr 17, 2009 2:02 pm
Location: SciTE4AutoIt3

Re: Convert quoted images to url

Post by Neuropass »

ok thanks but now i'm kind of lost with 8 pages of" yes it works" and "no it doesn't work for me"

what step should i follow to install this mod??? Download and intall from the first page, then what are the extra edits that you haver to do?? it would be easier to add the right steps in the first post, you can't go through 8 pages of errors and solution. Or maybe an updated version would be nice...
User avatar
Ger
Registered User
Posts: 2117
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100

Re: Convert quoted images to url

Post by Ger »

Jus read this.

There won't be an update of the MOD soon.
My extensions:
Simple CMS, Feed post bot, Avatar Resize, Modbreak, Magic OGP, Live topic update, Modern Quote, Quoted Where (GDPR) and Autoresponder.
Newest: FAQ manager for 3.2

Like my work? Buy me a coffee to keep it coming. :ugeek:

Kinderpraktijk SensIQ

-Don't PM me for support-
User avatar
DoYouSpeakWak
Registered User
Posts: 2311
Joined: Fri Jul 25, 2008 1:32 pm
Location: Island of Wak-Wak

Re: Convert quoted images to url

Post by DoYouSpeakWak »

Hey Ger.

I have a simple confilict problem i hope you can help with. I have the mod Reimg installed. Keep in mind your mod still works fine, images still dont get shown in quotes :) But the debug error dont look nice.

Got this error

Code: Select all

[phpBB Debug] PHP Notice: in file /includes/message_parser.php on line 43: Undefined variable: user
[phpBB Debug] PHP Notice: in file /includes/message_parser.php on line 43: Trying to get property of non-object
[phpBB Debug] PHP Notice: in file /includes/message_parser.php on line 44: Undefined variable: user
[phpBB Debug] PHP Notice: in file /includes/message_parser.php on line 44: Trying to get property of non-object
[phpBB Debug] PHP Notice: in file /includes/message_parser.php on line 45: Undefined variable: user
[phpBB Debug] PHP Notice: in file /includes/message_parser.php on line 45: Trying to get property of non-object
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 2182: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3272)
Im 99% sure its due to the changes in bbcode.php made by reimg. See for yourself. Im sure its just a matter of adding a few lines to your code.

http://psyhosting.info/pre/ger/install. ... bbcode.php

Any help would be greatly appriciated.
Whatever you share comes back. Support the phpBB Communities
Offering paid services. 15+ years of experience with phpBB3 and server management.
User avatar
Ger
Registered User
Posts: 2117
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100

Re: Convert quoted images to url

Post by Ger »

Could you please post ~ line 30-70 from message_parser.php?
My extensions:
Simple CMS, Feed post bot, Avatar Resize, Modbreak, Magic OGP, Live topic update, Modern Quote, Quoted Where (GDPR) and Autoresponder.
Newest: FAQ manager for 3.2

Like my work? Buy me a coffee to keep it coming. :ugeek:

Kinderpraktijk SensIQ

-Don't PM me for support-
User avatar
DoYouSpeakWak
Registered User
Posts: 2311
Joined: Fri Jul 25, 2008 1:32 pm
Location: Island of Wak-Wak

Re: Convert quoted images to url

Post by DoYouSpeakWak »

Ger wrote:Could you please post ~ line 30-70 from message_parser.php?
Thanks for looking into it. Here you go

24-89

Code: Select all

/**
* BBCODE FIRSTPASS
* BBCODE first pass class (functions for parsing messages for db storage)
* @package phpBB3
*/
class bbcode_firstpass extends bbcode
{
	var $message = '';
	var $warn_msg = array();
	var $parsed_items = array();

	/**
	* Parse BBCode
	*/
	function parse_bbcode()
	{
		//Start MOD Convert quoted images to url 	
		preg_match_all('#\[quote(.*?)\](.*?)\[/quote\]#si', $this->message, $qmatch );
		foreach ($qmatch[2]as $qmatchin){
			$qres = preg_replace('#\[url=(.*(jpg|jpeg|gif|png|bmp))\]\[img\].*\[/img\]\[/url\]#iU', '[ [url=\1]'. $user->lang['IMAGE'] .'[/url] ]', $qmatchin);
			$qres = preg_replace('#\[url=.*\]\[img\](.*)\[/img\]\[/url\]#iU', '[ [url=\1]'. $user->lang['IMAGE'] .'[/url] ]', $qmatchin);
			$qres = preg_replace('#\[img\](.*)\[/img\]#iU', '[ [url=\1]'. $user->lang['IMAGE'] .'[/url] ]', $qmatchin);
			$this->message = str_replace($qmatchin, $qres, $this->message);
		}
		//End MOD Convert quoted images to url
	
		if (!$this->bbcodes)
		{
			$this->bbcode_init();
		}

		global $user;

		$this->bbcode_bitfield = '';
		$bitfield = new bitfield();

		foreach ($this->bbcodes as $bbcode_name => $bbcode_data)
		{
			if (isset($bbcode_data['disabled']) && $bbcode_data['disabled'])
			{
				foreach ($bbcode_data['regexp'] as $regexp => $replacement)
				{
					if (preg_match($regexp, $this->message))
					{
						$this->warn_msg[] = sprintf($user->lang['UNAUTHORISED_BBCODE'] , '[' . $bbcode_name . ']');
						continue;
					}
				}
			}
			else
			{
				foreach ($bbcode_data['regexp'] as $regexp => $replacement)
				{
					// The pattern gets compiled and cached by the PCRE extension,
					// it should not demand recompilation
					if (preg_match($regexp, $this->message))
					{
						$this->message = preg_replace($regexp, $replacement, $this->message);
						$bitfield->set($bbcode_data['bbcode_id']);
					}
				}
			}
		}

		$this->bbcode_bitfield = $bitfield->get_base64();
	}
Whatever you share comes back. Support the phpBB Communities
Offering paid services. 15+ years of experience with phpBB3 and server management.

Return to “[3.0.x] MOD Database Releases”