JENS MALMGREN I create, that is my hobby.

Porting my blog for the second time, render posts part 8

This is post #30 of my series about how I port this blog from Blogengine.NET 2.5 ASPX on a Windows Server 2003 to a Linux Ubuntu server, Apache2, MySQL and PHP. A so called LAMP. The introduction to this project can be found in this blog post

I have grand goals for this project. Now I am scrutinizing the progress of the project and here and there little things are not quite right. This is annoying, the grandness is taking some punches from the fist of reality. Perhaps many thinks that developing software is an activity free of emotions but that is not true. On the contrary, there are plentiful of emotions going on during the development of software. So far there has been much hope that perhaps I am doing things right and excitement of doing new things. Now there are other emotions coming up in me. I feel irritated that it is not working and dissolution that I could not spot an URL got somewhere in the middle. The reason was that this link had /image and that the URL detection would not check if it was at the beginning of the URL. So that is solved by adding a ^ binding it to the beginning of the URL, like so:

# Added '^' to prevent any link with '/image' to be listed as a local URL.		
$bIsLocalURL = $tag =~ /(malmgren\.nl|blogspot\.com|googleusercontent\.com|^\/image)/i;

Likewise I should not replace /image if it was not at the beginning of the URL. Added ^ like so:

$strTarget =~ s/^\/([iI])mage/http:\/\/\/$1mage/;

Now that URL would not break.

Then I found a construction like this:


'$strTarget = uri_decode($strParsedURL);'

With this line of code here above the result would be


But that is not enough. "%20" had to be converted again. So I had to decode twice!

$strTarget = uri_decode($strParsedURL);≺br /≻$strTarget = uri_decode($strTarget);

And now that worked!

Almost. Then I found an example of an images named %252520. For this to resolve properly the routine need to run until there is no parenthesis over.

$strTarget = $strParsedURL;
while ($strTarget =~ /%/)
	$strTarget = uri_decode($strTarget);

That worked, but it is actually really "dangerous". If the URL contains a percentage character that do not resolve then the loop would go on for ever. So I solved that.

$strTarget = $strParsedURL;
my $changed = 1;
while ($strTarget =~ /%/ && $changed)
	$changed = $strTarget ne uri_decode($strTarget);
	$strTarget = uri_decode($strTarget);

I got all images work now. Next I will work on the aspx links.

I was born 1967 in Stockholm, Sweden. I grew up in the small village Vågdalen in north Sweden. 1989 I moved to Umeå to study Computer Science at University of Umeå. 1995 I moved to the Netherlands where I live in Almere not far from Amsterdam.

Here on this site I let you see my creations.

I create, that is my hobby.