Making a Blog Engine

Sat, November 25 2017

Making a Blog Engine

The latest Modern Pascal web site required that we introduce a blog to make a well rounded experience for our clients. So, instead of inventing the wheel, I decided - why not buy an existing inexpensive PHP script; and port it to Modern Pascal so I could update my notes on porting PHP to Celerity. The challenge of porting PHP to Modern Pascal Celerity is digging through all of the bloat caused by an open (too open) Object architect. Once you dig through all of the file, some files only contain a small routine which is being used from the file, as the new author used code from another projects author.
WARNING! The opinions expressed in this article are the author's own and do not reflect the view of MP Solutions, LLC.

Now, I have no problem with sharing code, reusing code, etc. This is how many developers learn, same for me over the last 35 years - however, learn the routine(s) you need and make your own library. I understand some people reuse the whole library to keep the copyright intact, etc. that is fine in your copy - copyright the routines. You have to remember, you are running in a script language, all the code parsing is consuming time - time delays = potential server burden = loss of visitors due to slow connections.

So what are the challenges?

Your first challenge is PHP is a script markup language, whereas, Modern Pascal's Celerity is a script programming language. So you cannot simply migrate HTML into script logic, instead you have to copy HTML into dynamic output. For serious business programmers this makes more sense, however, the arguement could be "you are writing for the web not for business". That way of thinking is one reason I think so many professional programmers stay out of the web development market.

So you will want to skim through each php script, and copy the html out to static files Celerity can add to the buffer by calling
Response.SendFile(Request.getDomainRoot+"filename.inc");
What if I need to manipulate something that is in the buffer? Celerity gives you complete access and control over the buffer before it is actually digested by apache. You can gain access by working with the response object,
buffer:=Response.getContent();
and to update the buffer (var type string) you when you are finished:
Response.setContent(buffer);
 
I document the Response and Request objects in an article under the category Celerity.

Another challenge that I personally thought was crazy, is the way PHP pre-parses the post data and query string into array elements. Yes, it is convenient, however, it is also another memory hog feature that the developer does not actually get to control. In Celerity, if you need to work with either or both, and enjoy the convenience of working with the data like a dictionary array - use the TStringList class, and setDelimiter to "&".
var
   strlist:TStringlist;
{...}
   strlist.init();
   strlist.setDelimiter("&");
   strlist.setDelimitedText(request.getPostData());
{...}
   if (strlist.getValues["username"]!="") then ...
{...}
   strlist.free;