FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » FUDforum » How To » post_proc.inc.t (preg_replace and strpos question)
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
post_proc.inc.t [message #40495] Mon, 10 March 2008 21:16 Go to next message
Ernesto is currently offline  Ernesto   Sweden
Messages: 413
Registered: August 2005
Karma: 0
Senior Member
So I added an image resize script, which gives an image with larger than X pixels width a reduced size.

The resize part works fine and the images render perfectly and my click to resize script works fine as well.

My problem occurs when I want to edit a post where I have previously posted an image where the resize was tirggered.

This is the old original Ilya code for reference:
	while (preg_match('!<img src="(.*?)" border=0 alt="\\1">!is', $fudml)) {
		$fudml = preg_replace('!<img src="(.*?)" border=0 alt="\\1">!is', '[img]\1[/img]', $fudml);
	}
	while (preg_match('!<img class="(r|l)" src="(.*?)" border=0 alt="\\2">!is', $fudml)) {
		$fudml = preg_replace('!<img class="(r|l)" src="(.*?)" border=0 alt="\\2">!is', '[img\1]\2[/img\1]', $fudml);
	}
	while (preg_match('!<a href="mailto:(.+?)" target="_blank">\\1</a>!is', $fudml)) {
		$fudml = preg_replace('!<a href="mailto:(.+?)" target="_blank">\\1</a>!is', '[email]\1[/email]', $fudml);
	}
	while (preg_match('!<a href="(.+?)" target="_blank">\\1</a>!is', $fudml)) {
		$fudml = preg_replace('!<a href="(.+?)" target="_blank">\\1</a>!is', '[url]\1[/url]', $fudml);
	}

	if (strpos($fudml, '<img src="') !== false) {
		$fudml = preg_replace('!<img src="(.*?)" border=0 alt="(.*?)">!is', '[img=\1]\2[/img]', $fudml);
	}
	if (strpos($fudml, '<img class="') !== false) {
		$fudml = preg_replace('!<img class="(r|l)" src="(.*?)" border=0 alt="(.*?)">!is', '[img\1=\2]\3[/img\1]', $fudml);
	}
	if (strpos($fudml, '<a href="mailto:') !== false) {
		$fudml = preg_replace('!<a href="mailto:(.+?)" target="_blank">(.+?)</a>!is', '[email=\1]\2[/email]', $fudml);
	}
	if (strpos($fudml, '<a href="') !== false) {
		$fudml = preg_replace('!<a href="(.+?)" target="_blank">(.+?)</a>!is', '[url=\1]\2[/url]', $fudml);
	}

	if (isset($php)) {
		$fudml = str_replace(array_keys($php), array_values($php), $fudml);
	}




This is my altered, not working code. I must have done something wrong, if anyone could point out where my error is, I will kiss you on the mouth and make babies with you!

while (preg_match('!<a onclick="return hs.expand(this, {allowSizeReduction: false})" href="(.*?)" class="highslide" target="_new"><img border="0" src="(.*?)" style="width:(.*?)px; height:(.*?)px;" alt="(.*?)"></a>!is', $fudml)) {
		$fudml = preg_replace('!<a onclick="return hs.expand(this, {allowSizeReduction: false})" href="(.*?)" class="highslide" target="_new"><img border="0" src="(.*?)" style="width:(.*?)px; height:(.*?)px;" alt="(.*?)"></a>!is', '[img]\5[/img]', $fudml);
	}
	while (preg_match('!<img src="(.*?)" style="width:(.*?)px; height:(.*?)px" border="0" alt="\\4">!is', $fudml)) {
		$fudml = preg_replace('!<img src="(.*?)" style="width:(.*?)px; height:(.*?)px;" border="0" alt="\\4">!is', '[img]\4[/img]', $fudml);
	}
	while (preg_match('!<img class="(r|l)" src="(.*?)" style="width:(.*?)px; height:(.*?)px;" border="0" alt="\\5">!is', $fudml)) {
		$fudml = preg_replace('!<img class="(r|l)" src="(.*?)" style="width:(.*?)px; height:(.*?)px;" border="0" alt="\\5">!is', '[img\1]\5[/img\1]', $fudml);
	}
	while (preg_match('!<a href="mailto:(.+?)" target="_blank">\\1</a>!is', $fudml)) {
		$fudml = preg_replace('!<a href="mailto:(.+?)" target="_blank">\\1</a>!is', '[email]\1[/email]', $fudml);
	}
	while (preg_match('!<a href="(.+?)" target="_blank">\\1</a>!is', $fudml)) {
		$fudml = preg_replace('!<a href="(.+?)" target="_blank">\\1</a>!is', '[url]\1[/url]', $fudml);
	}

	if (strpos($fudml, '<img src="') !== false) {
		$fudml = preg_replace('!<img src="(.*?)" style="width:(.*?)px; height:(.*?)px;" border="0" alt="(.*?)">!is', '[img]\4[/img]', $fudml);
	}
	if (strpos($fudml, '<img class="') !== false) {
		$fudml = preg_replace('!<img class="(r|l)" src="(.*?)" style="width:(.*?)px height:(.*?)px;" border="0" alt="(.*?)">!is', '[img\1=\2]\5[/img\1]', $fudml);
	}
	if (strpos($fudml, '<a onclick') !== false) {
		$fudml = preg_replace('!<a onclick="return hs.expand(this, {allowSizeReduction: false})" href="(.*?)" class="highslide" target="_new"><img border="0" src="(.*?)" style="width:(.*?)px; height:(.*?)px;" alt="(.*?)"></a>!is', '[img]\1[/img]', $fudml);
	}
	if (strpos($fudml, '<a href="mailto:') !== false) {
		$fudml = preg_replace('!<a href="mailto:(.+?)" target="_blank">(.+?)</a>!is', '[email=\1]\2[/email]', $fudml);
	}
	if (strpos($fudml, '<a href="') !== false) {
		$fudml = preg_replace('!<a href="(.+?)" target="_blank">(.+?)</a>!is', '[url=\1]\2[/url]', $fudml);
	}

	if (isset($php)) {
		$fudml = str_replace(array_keys($php), array_values($php), $fudml);
	}



Just as a reference, this is the code that the script creates:
<a onclick="return hs.expand(this, {allowSizeReduction: false})" href="'.$parms.'" class="highslide" target="_new"><img border="0" src="'.$parms.'" style="width:'.$imgw.'px; height:'.$imgh.'px;" alt="Click to view full-size"></a>


[Updated on: Mon, 10 March 2008 21:17]

Report message to a moderator

Re: post_proc.inc.t [message #40498 is a reply to message #40495] Mon, 10 March 2008 23:27 Go to previous message
Ilia is currently offline  Ilia   Canada
Messages: 13241
Registered: January 2002
Karma: 0
Senior Member
Administrator
Core Developer
I think your \\5 should be \\4, since there are only 4 capture blocks.

FUDforum Core Developer
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: a forum is hiding..
Next Topic: Invisible forums?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Dec 11 21:20:20 GMT 2024

Total time taken to generate the page: 0.02028 seconds