JENS MALMGREN I create.

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 https://www.malmgren.nl/post/Porting-my-blog-for-the-second-time-Project-can-start.aspx.

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 www.jens.malmgren.nl 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:

# http://www.jens.malmgren.nl/post/Porting-my-blog-for-the-second-time-render-posts-part-8.aspx 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:

# http://www.jens.malmgren.nl/post/Porting-my-blog-for-the-second-time-render-posts-part-8.aspx
$strTarget =~ s/^\/([iI])mage/http:\/\/www.jens.malmgren.nl\/$1mage/;

Now that URL would not break.

Then I found a construction like this:

DSC_1929%2520skarpare.jpg

'$strTarget = uri_decode($strParsedURL);'

With this line of code here above the result would be

DSC_1929%20skarpare.jpg

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.

# http://www.jens.malmgren.nl/post/Porting-my-blog-for-the-second-time-render-posts-part-8.aspx
$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.

# http://www.jens.malmgren.nl/post/Porting-my-blog-for-the-second-time-render-posts-part-8.aspx
$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 moved from Sweden to The Netherlands in 1995.

Here on this site, you find my creations because that is what I do. I create.