JENS MALMGREN I create, that is my hobby.

Porting my blog for the second time, static pages

This is post #44 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

Now it is time to finish the two remaining tabs of the main menu of my blog: About and Jens Art. I could put the content of these pages in the database but why would I? It is two pages and they will always be "hand made". It is much easier to put these two pages on disk and load them as they are. But that said how should I use that reusing the new template functionality?

Well, there is a hybrid solution possible of course! Suppose I make a static page with a specific structure. Then when the pages are served the parts I need are extracted from the static page and injected into the template functionality so that when I change layout also my static pages will get the new layout. So this is the solution I created. I think this is really compact source code for rendering a static page. I called this program here below static.php:

$domain = "";
$strSlug = "";
$strID = "";

include "dbconnection.php";
include "generic.php";

$strTitle = "About";
$strDescription = "About Jens Malmgren";

$strLeftSideBar = "";
$strRightSideBar = "";
$strCategorySlug = "";
$iSelectedTab = 1;

$strPathToCurrentPage = "/art";
$strStaticPage = "";
$strContent = "";
$strPage = "";

if (array_key_exists("page", $arrayArgs) && $arrayArgs["page"] != "")
	$strPage = $arrayArgs["page"];

if ($strPage == "about" || $strPage == "art")
	$strPathToCurrentPage = "/" . $strPage;
	$strStaticPage = file_get_contents($strPage . ".htm");
	preg_match("/≺title≻(.*?)≺\/title≻/", $strStaticPage, $matches);
	$strTitle = $matches[1];
	preg_match("/≺description≻(.*?)≺\/description≻/", $strStaticPage, $matches);
	$strDescription = $matches[1];
	preg_match("/≺selectedtab≻([0-9])≺\/selectedtab≻/", $strStaticPage, $matches);
	$iSelectedTab = intval($matches[1]);
	preg_match("/≺body≻(.*?)≺\/body≻/s", $strStaticPage, $matches);
	$strContent = $matches[1];
	preg_match("/≺leftsidebar≻(.*?)≺\/leftsidebar≻/s", $strStaticPage, $matches);
	$strLeftSideBar = $matches[1];
	preg_match("/≺rightsidebar≻(.*?)≺\/rightsidebar≻/s", $strStaticPage, $matches);
	$strRightSideBar = $matches[1];


But wait a moment. We start from the beginning! In the beginning a request arrives at the web server and it is resolved by the URL rewriting routine. The rules for these I store in my .htaccess file. To direct /art to my page about art I need to add a rule rewriting the URL into something opening my page static.php with as argument art. The same for /about. Here is my latest .htaccess page:

RewriteEngine on
RewriteRule ^about$ /static.php?page=about [NC]
RewriteRule ^art$ /static.php?page=art [NC]
RewriteRule ^post$ /post.php [NC]
RewriteRule ^post/(.*)$ /post.php/?post=$1 [NC]
RewriteRule ^category$ /category.php [NC]
RewriteRule ^category/(.*)$ /category.php/?category=$1 [NC]

There is a little security in this here because static.php will only be accessed with proper arguments. On line 30 I open a file with the same name as the page argument plus '.htm' and then I search for each of the snippets in the file and serve these into my PreparePage routine in generic.php. It can look like this:

Here Is 'art.htm' of the page in the image here above:

	≺title≻Jens Art≺/title≻
	≺description≻On this page you can read more about Jens Art≺/description≻
≺p≻Here above you can enter a search term. When you click on the '≻≻' button the search result will be displayed in the main area.≺/p≻
≺p≻If you would like to take contact with me please do so on the following address: jens at malmgren dot nl.≺/p≻
≺p≻To find out more about my production please click on the other tabs of this website:≺p≻
	≺li≻About: About me.≺/li≻
	≺li≻Jens Art: This is my online gallery. Here you see the pieces I am proud of.≺/li≻
	≺li≻Posts: This is my blog with the most recent post first.≺/li≻
	≺li≻Categories: This is a page of all categories in this website.≺/li≻
≺h1≻Jens Art≺/h1≻
≺a href = "/media/2017-01-17_Francesca.jpg" target = "_blank"≻≺img style = "width:200px;float:left;margin:5px;" src = "/media/2016-01-17-Francesca-1.jpg"/≻≺/a≻On 17 of January 2016 I painted Francesca. This is the second painting I made of her.

As you can see I used special tag names I invented myself such as: descriptions, selectedtab, leftsidebar, rightsidebar etc.

Now I am finished with the tabs of the main menu. It is about time to go back to the import routine and try importing all the pages I created since after 5 of September 2015. When that is done and working then technically the blog presentation is done. From that moment a new phase of the project will start and that is the deployment. But I talk about that another time.

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.