Latest Publications

Alarms in Ubuntu

I’ve been looking for a while for a good, easy to use, easy to install, no fuss alarm clock. Just something I can set to go off in 10 minutes. Or at 2 o’clock. Or tomorrow. I haven’t found any apps that did that in a nice and easy fashion. I have found several that would do lots of things, but none of them were easy to use and handle – almost all of them were bloated, with bad UI. So, once more, I googled, but this time I came across another solution. ‘Look ye to the command line!’ I read. ‘Use the at command, Luke!’ And so I issued a ‘man at’ and quickly came upon good stuff.

From the man page of at:

DESCRIPTION
at and batch read commands from standard input or a specified
file which are to be executed at a later time, using /bin/sh.

Which, in my ears, sound awesome! You see, what you get here is close to the power of crontab, but single-use, i.e. you setup a command to run once, at a given time, and that’s it. In other words, a command that will let you set up alarms easily.

The next step was turning at into an actual alarm. I prefer the sound method: play something that sounds like an actual alarm, and you’ll be sure you don’t overlook the thing. You can combine with something visual too, of course, like a dialog box. For the sound, I found AUTHENTIC NAVY ALARM SOUNDS PAGE which hosts a few different wave files. In particular, the general alarm (old style) works well for me. To play it, all you need to do is

aplay -q sound.file

Combined with at, this then becomes

echo "aplay -q sound.file" | at [time]

One of the beauties of at is that it will accept lots of different time inputs. So, you can do ‘at 7:40′, ‘at 3pm’, ‘at now + 5 minutes’, ‘at today + 5 days’, etc.

With things put together into a script, it might look like

#!/bin/bash
if [ "$1" = '' ]
then
    echo "No argument for for alarm! Supply with time
example:
    alarm 7:45
    alarm 19:59
    alarm 3pm + 3 day
    alarm 2010-09-18
    "
    exit 1
else
    if `echo aplay -q /home/fake51/Downloads/gqold.wav | at $1 2>\&1 > /dev/null`
    then
        exit 0
    else
        echo "Setting alarm failed"
        exit 1
    fi
fi

Save the above script as alarm in ~/bin/, chmod to 0755 and you can then set alarms like

alarm 11:40
alarm "2010-01-06 12:00"
alarm "now + 5 minutes"

Should you want to remove the alarms before they run, you can see commands set to run with atq and remove them with atrm [number]

  • Google Reader
  • Delicious
  • Digg
  • Blogger Post
  • LinkedIn
  • Slashdot
  • StumbleUpon
  • Twitter
  • WordPress
  • Share/Bookmark

Comparing CMS/blog systems, part 3.2: CMS Made Simple day to day

Having gone through the setup of my new site for PL PHP in Comparing CMS/blog systems, part 3.1: Typo3 day to day I next wanted to try going through the same with CMS Made Simple. As noted in Comparing CMS/blog systems, part 2 I didn’t get CMS Made Simple installed the first time round, but as I lowered my expectations PHP version I got it working without problems. So after a few minutes, it was time for my second try at creating PL PHP

Hands dirty

Part of installing CMS Made Simple is typically installing default templates and content. So, unlike Typo3 where the first thing you see of your site is an error, with CMSMS you see a working site with content. This is good and bad: it gives you a good idea of what CMSMS can do, but it also means you have to figure out how to change what’s already there – sometimes a clean slate is easier to work with.

It’s not a big problem in any way, though. Diving into the work without checking any docs quickly led me to the templates point under the layout menu. From here, you can easily create a new template as well as have a look at existing ones to learn from. However, when you create a new template, CMSMS prefills it with various goodies that you’ll typically need – so, I didn’t have any need for looking at other templates to get me going. Looking at the syntax of the prefilled template (as well as looking under the hood) CMSMS uses Smarty for its templates. I haven’t worked with Smarty before, so that put me in pretty much the same position as when trying to create a template in Typo3. Only, Smarty apparently uses a mixture of HTML and pseudo-PHP, so the learning curve is a lot less steep. It took me all of 20 minutes to copy in the HTML I already had for PL PHP and put the replacement markers in the proper spots. That gave me basic template structure:

{process_pagedata}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
 <title>{sitename} - {title}</title>
 {metadata}
 {stylesheet}
</head>
<body>

 <div id='main_frame'>
 <!-- start header -->
  <div id='header'>
   <div id='logo'>
    <div id='logo_text'><a href='/'>{sitename}</a></div>
   </div>
   <!-- start menu -->
   <div id='menu'><span class='splitter'>&nbsp;</span>
    {menu}
   </div>
   <!-- end menu -->
  <div class='float-clear'></div>
 </div>  
  <!-- end header -->
  <!-- start content -->
  <div id="content">
   <h1>{title}</h1>
  {content}
  </div>
  <!-- end content -->

  <!-- start footer -->
  <div id='footer'>
 &copy; 2009 Peter Lind<span class='splitter'>&nbsp;</span>PL PHP<span class='splitter'>&nbsp;</span>
  </div>
 <!-- end footer -->
 </div>
</body>
</html>

As should be visible, most of the template is just straightforward HTML. The rest is fairly self-explanatory as well, given the names used for the placeholders: menu, content, metadata, stylesheet, etc. What actually goes into those placeholders? A quick test shows it’s pretty much what you’d expect – which means, the next steps are reduced to making sure the right content is output.

Next is taking care of the stylesheet. This is more or less the same procedure as with the template: create a new stylesheet, copy the contents from the already created version, then set the media type and submit. Before you can actually see the changes made by the new template and stylesheet, you’ll need to set both as default for the pages. This is done through the Templates and Stylesheets menupoints, point and click. One thing to remember is you need to set the template as default and set the pages you already have created to your new template. Otherwise you’ll either not see current pages using the new template or not see new pages using it.

At this point, the site has working template and stylesheet. The menu is still all out of whack and the content needs to be fixed, so next up is looking at generating a menu. This is handled under Layout -> Menu Manager and once again, you click the button to create new, then start filling in details. Here though, you’ll be working from nothing so copying an existing menu structure and modifying can make it easier.

This was probably the part that took the longest, as it makes the most use of Smartys pseudo-php. The menu structure I use for PL PHP is fairly simple though, so it was mainly a question of analyzing the existing setup and then taking the parts I needed. It came out like this:

{if $count > 0}
 {foreach from=$nodelist item=node}
  {if $node->current}
  <a href='{$node->url}' class='active-menupoint' title='{$node->menutext}'>{$node->menutext}</a>
  {else}
  <a href='{$node->url}' title='{$node->menutext}'>{$node->menutext}</a>
  {/if}
 <span class='splitter'>&nbsp;</span>
 {/foreach}
{/if}

If you know PHP you can guess what’s going on here. If you don’t, it might be somewhat confusing but probably not too much: node->url and node->menutext should give it away. It’s just a basic loop over the pages, creating a link for each it finds.

After saving this part, you should once again remember to set it as default, as otherwise the menus won’t be rendered using it. Having done that, my site now looks like it’s supposed to – apart from actual content. This is handled from the Pages point in the Content menu. First part is to delete the existing pages, then create new ones with proper names and placing. Two minutes later, my site now has the proper content structure and I can get busy writing copy – using the ubiquitous TinyMCE editor.

One thing missing is the pretty urls. The setup for that is not as easy to find as the other things, so I turn to Google for some help, which instantly brings up some ok looking hits. The CMSMS wiki has the info needed, and it turns out that you just need to edit your config.php (specifically, setting $config['url_rewriting'] to ‘mod_rewrite’) and add a .htaccess file that routes all requests to index.php. After that’s done, CMSMS happily accepts pretty urls. And like with Typo3, you can change which urls are used for your pages – that’s handled for each page individually when editing it (under the options tab).

Done

So, about three hours after I started implementing PL PHP in CMS Made Simple I have a working site looking the way I want it to, with pretty urls and what not. Although I am a PHP developer, I’m not sure if it would have been much harder for non-tech people – the interface is fairly intuitive. Especially if you’re happy to go with the design provided by the default templates of CMSMS you’ll be up and running with a site in very little time.

Comparing the experience to that of Typo3 this was easy on a level Typo3 can only dream of – but probably don’t.

  • Google Reader
  • Delicious
  • Digg
  • Blogger Post
  • LinkedIn
  • Slashdot
  • StumbleUpon
  • Twitter
  • WordPress
  • Share/Bookmark

Comparing CMS/blog systems, part 3.1: TYPO3 day to day

Series: CMS and Blog systems

  1. Comparing CMS/blog systems, part 1: blog installation
  2. Comparing CMS/blog systems, part 2: CMS installation
  3. Comparing CMS/blog systems, part 3.1: TYPO3 day to day

The individual posting on the blogs and cms’ will be bigger, given that there’s simply more to do than for installing. Hence, I’ve decided to split the posts into smaller chunks, dealing with one product at a time. On top of that, the ordering has changed a tad – I wanted to start with the blogs again but as I’m working on a site for PL PHP and thought that I would do that in Typo3, it was a nobrainer to do this blog post alongside the new site. So, I’m reversing the order, taking the CMS systems first, then the blogs – one by one. Oh, and, just to completely change the idea, I’ve reverted to using PHP 5.2 instead of 5.3 – typo3 cannot handle 5.3 and some of the other systems weren’t too happy with it either, so to keep the list systems I’m using 5.2.

Designing

Before I started implementing the site in Typo3 I made a design for the site. I had a browse at OSWD (sadly inactive – it’s a great resource) and found a design that would work well for what I had in mind. I didn’t feel like just grabbing the design (a perfectly valid option) but wanted some minute changes – so I started out with GIMP, got some graphics together, then quickly mocked up an HTML template frame. Here’s a screenshot of what the site will look like:

PL PHP site design

In terms of HTML and CSS it’s a pretty easy layout, everything is wrapped in a div for easy styling and separation.

Hands dirty

So, with the HTML template in hand, I started with Typo3. Unfortunately, I didn’t have any proper docs on how to go about things, so I started off thinking that it would be easy to get a site working, that Typo3 must be setup to easily do what it’s meant to do, and that I would be able to google what I couldn’t figure out on my own. Quite a bit of time later I had learned that Typo3 necessitates fairly detailed docs, is not created with any defaults in mind, and generally makes tasks much more complex than they need be. There are many interesting and cool parts to the system, but they are hard to find for the uninitiated, it seems.

Instead of just ranting, time to show how I went about things. The first step, I thought, was that of making a template. Typo3 is a CMS: content management system. You manage content, displaying it within templates. So, of course, you make a template, then make some content, then display your content in templates, right? No. You cannot make templates in the system before you’ve created pages. So, step 1 is to create your first page in the system, then you can go on and make a template for that page.

So, having gotten this far, I then dived into creating my site template from scratch. Now, more seasoned Typo3 users/developers would probably stop here and ask: why didn’t you just install the TemplaVoila! extension? Or import your HTML template using the tools for that? Well, I wanted to learn how Typo3 actually works. Also, a system that only works if you add plugins/extensions is simply not a working system – it’s a skeleton with no functionality. That aside, getting started with TypoScript wasn’t hard in any way. The idea of the script is pretty straight forward, the syntax the same and if you look at some examples you should be able to pick up fundamentals fairly easy.

When starting with templates, you first create the template, give it a name and set options. You really only need to set the name to be able to edit it – but there is one other very important part to do, which unfortunately is not a default or even pointed out in the template creator. This important part is to include a static template that gives you access to content from pages and/or other places. Without this static template there’s a fair chance you’ll get nothing back when trying to insert content in your template. Now, there’s probably a good reason why one of the static templates giving you access to content isn’t by default included – it’s most likely because there are several templates that do so and the creators of Typo3 don’t want to make choices on behalf of users. Nonetheless, it seems to me that if you need one of these static templates in more than 66% of cases, then you at the very least make a big, fat, red arrow that points to this option. Normally, I’d think it best to include something by default if it’s used a lot, and then let people deselect it if it’s not used – unfortunately, that’s not really an option for Typo3, as some templates exclude others.

Cutting this short: if you’re making a site like me, styling it with CSS (i.e. no tables to position things) you most likely want to include the ‘css_styled_content’ template. This then gives you access to content in pages through a simple TypoScript copy: element < styles.content.get.

After setting up the basic stuff, you can go on to creating the template structure. This is done through mainly two parts of the template editor: constants and setup. Constants are, as the name implies, constants. These can be included in the setup, which is where the template is actually made. The upshot of this is that you can change a constant in one place and see changes in many, i.e. doing away with code duplication. Where this comes in handy is mainly when you’re using one template in many places – no need to change template code, you just set slightly different constants for each page.

My first try at creating my site template in Typo3 was fairly crude. It looked something like this:

page = PAGE
page.bodyTag = <body>
page.stylesheet = fileadmin/styles/main.css

page {
  10 = HTML
  10.value = <div id='main_frame'>
  11 = HTML
  11.value = <div id='header'>
  12 = HTML
  12.value = <div id='logo'>
  13 = TEXT
  13.value = PL PHP
  13.wrap = <div id='logo_text'>|</div>
  14 = HTML
  14.value = </div>
... etc
}

Yes, at first I only knew about three elements in TypoScript: PAGE, TEXT and HTML. I was pretty sure there was a better way to do what I wanted but I find it’s a better way to learn to first give things a try, then improve your first idea. So, using the above method I got most of the template working. I then took some time out to study TypoScript a bit more, learned about a few more elements and rewrote the template to:

page = PAGE
page.bodyTag = <body>
page.stylesheet = fileadmin/styles/main.css

page {
 10 = COA
 10.wrap = <div id="main_frame">|</div>
 10 {
  10 = COA
  10.wrap = <div id='header'>|</div>
  10 {
   10 = COA
   10.wrap = <div id='logo'>|</div>
   10 {
    10 = TEXT
    10.value = <a href='/'>PL PHP</a>
    10.wrap = <div id='logo_text'>|</div>
   }
   20 = TEXT
   20.value =
   20.wrap = <div id='menu'>|</div>
   30 = TEXT
   30.wrap = <div class='float-clear'>|</div>
  }
  20 < styles.content.get
  20.wrap = <div id='content'>|</div>
  30 = TEXT
  30.value (
   &copy; 2009 Peter Lind<span class='splitter'>&nbsp;</span>PL
   PHP<span class='splitter'>&nbsp;</span>
  )
  30.wrap = <div id='footer'>|</div>
 }
}

The advantage in the above should be clear: elements are no longer split – instead, elements are contained within each other as in the actual HTML.

TypoScript is basically a collection of objects that are typically modeled on HTML or PHP counterparts. The TEXT and HTML elements, for instance, resolve to text outputs – the difference between the two is that the properties you set on the TEXT element will be set on it’s stdWrap property (a TEXT element is close to being a stdWrap element) while the same doesn’t go for the HTML element. Will this affect you when starting out with Typo3? Not very likely …

Anyway, a quick run through: first, a PAGE element is declared. This represents the entire page (don’t confuse this with the page you created for the template. The only elements of the page created that will be inserted automatically into the template are those that affect the <head> – so, the PAGE element doesn’t import any content automatically) and you can set various properties such as stylesheet and bodyTag to make basic layout decisions. To get further structure to the template, you then need to add elements to the PAGE element. This is done in the above code with the HTML, TEXT and COA elements. The COA element is an array of cObjects – content objects. Better still, it allows you to wrap the contents as you wish – hence, you can see it as an HTML element that allows for a hierarchy (the HTML element cannot contain other elements).

Three other elements worth mentioning in the code are: first, the notation:

  • = is simple assignment
  • < means copy
  • =< means reference (not used above)
  • > means empty the element (not used above. Basic usage is if you’re using an element already declared)
  • {} serves to reduce typing. Left hand elements inside the block are treated as properties of the element to the left of the {
  • () serves to contain multiple lines. You cannot have anything to the right of the ( and you cannot have anything to the left or right of the )

Secondly, the styles.content.get part. This refers, as one might guess from my rant above, to the included static template. If one was to use the template analyzer, one would see that css_styled_content appears as a template extension to the main template. In this extension styles.content.get is declared and it’s properties filled. In your own template you can then copy the contents of styles.content.get with < – and the content defined in the page of the template will appear inside the template when rendered.

Lastly, as can be guessed from the numbering in the template, elements are rendered according to numerical position. That is, 10 is rendered before 20, which in turn is rendered before 30. Elements are resolved in full before later elements are resolved: 10.10 is resolved before 10.20, regardless of where 10.20 is declared.

Finally, to get the template working properly for the site, a menu is needed. This bit can cause a bit of confusion, mainly because the elements are more complex than other TypoScript elements. What’s needed is an HMENU element and then either TMENU or GMENU element – the first would be Text Menu, the second Graphical Menu. As I’m opting for a css based menu and handling most things myself, I opted for the TMENU. The menu ended up looking like this:

10 = HMENU
10.entryLevel = 0
10 {
 1 = TMENU
 1 {
  NO {
   after = <span class='splitter'>&nbsp;</span>
  }
  ACT < .NO
  ACT {
   ATagParams = class='active-menupoint'
  }
  ACT = 1
 }
}

The HMENU gets things started. The entryLevel bit sets the start level of the menu to just root level (which, strangely, means that root level pages should NOT be included – entryLevel seems to mean ‘include things below this level’). The next part determines the layout of the following menus – which means that the numerical order here takes on a different sense than in the other rendering parts, as here each successive level describes a menu sublevel. Hence, HMENU.1 is menu level 1, HMENU.2 is menu level 2. For each menu level described, a number of properties must be set for them to render. For instance, the NO property of the TMENU element must be set for the menuitems to render.

Luckily, that’s about all it takes to get a menu going, no need to include templates or extensions – just have to use the proper elements, declare them properly and then have a proper page hierarchy (the reason I use ‘proper’ so many times in a row is that I didn’t … chose to learn the hard way, I did).

Now, the templating part is done. It’s time to skip to content creating, which is much easier (or harder, depending upon how creative you are) in Typo3. The backend site includes an ok JavaScript rich text editor that will do all the typical formatting tricks of the day, so there’s not really much to say regarding that: it works and it works quite easy.

Then, to stick some icing on the cake, nice urls would be good. To achieve this, it’s necessary to install an extension and mess about with the .htaccess file in the main site folder. Going by the instructions for the Realurl extension it’s not too bad though – compared to getting content displaying on the page in the first place it was actually a breeze. There is one pitfall to be aware of – you need to download the extension, then upload it to your site. The ‘discover’ feature of Typo3 doesn’t work, it imports an old version of the extension instead of the newest one. Apart from that, the extension works pretty well soon as you have edited your template (the setup part needs three lines) and your .htaccess file – you can even specify custom names for pretty urls.

Done

Getting a basic site up and running to a point where I can look at it and say “that’s alright” took a lot longer than expected. Some parts of Typo3 are overly complex for no apparent reason. Others seem to work fine and don’t need any tweaking. The moral of the story seems to be that you shouldn’t go into Typo3 land without a map and a guide – you probably won’t find your way around.

Here’s the list of things I used to get by:

  • Documentation at Typo3 – You can find tutorials, videos and more here. It could be a great wealth of info but unfortunately it’s not. A lot of the data is outdated, a lot of it is not detailed enough and a lot of it simply assumes to much of the reader. Still, you’ll find answers to some questions here.
  • The TSref – documentation of TypoScript elements and other stuff. Beware of the examples: they seem to make points but generally don’t.
  • Typo3 Enterprise Management – probably the best guide you can find, although it’s a couple of years old.

One thing I’m rather undecided about is the whole idea of TypoScript. I came across the idea that PHP frameworks are not just a bonus – they can be problematic as well. Rasmus Lerdorf voiced that idea and similar ones one his blog a while ago: his point being that PHP in itself actually works as a framework and that if you stick a framework on top that, you’re distancing yourself from what you actually need. TypoScript gives you the same feeling: why has HTML been recreated in this way? Why not just allow actual HTML as templates and mix in some PHP? What are the problems solved with TypoScript? What do we gain from representing templates as TypoScripts? This concern is amplified by the fact that extensions/plugins have been developed to take your HTMLand turn it into a Typo3 template: if TypoScript solves my problems why was TemplaVoila! created?

Some positive sides to it should be visible: templates won’t be the typical mash of HTML and PHP – they’ll be a unique type that encompasses both. This might make it easier to do some PHP without knowing the language fully. It can also simply writing HTML as some things will be done for you. Still, I wonder: do we need another set of building blocks on top of HTML and PHP?

  • Google Reader
  • Delicious
  • Digg
  • Blogger Post
  • LinkedIn
  • Slashdot
  • StumbleUpon
  • Twitter
  • WordPress
  • Share/Bookmark

Input validation fail

I just couldn’t help it, I had to post this little nugget of failure.

On the website of a Danish newspaper – Politiken – they do blogs as well as newsbits (and I mean bits, most of the stuff is just Reuters/AP). On their blogs, comments are of course allowed. So far, so good. Now the problems start when Politiken accept the comments. What they should be doing is check the various fields for meaningful and/or default input. What they are doing is allowing anything that looks remotely meaningful. This leads to beautiful bits of html like the following:

<a class="url" rel="external nofollow" href="http://Website">[name removed]</a>

Failing to check for the default value your own website put into the field is simply pathetic. More pathetic than not checking whether the referenced site is actually a valid domain but not by much.

  • Google Reader
  • Delicious
  • Digg
  • Blogger Post
  • LinkedIn
  • Slashdot
  • StumbleUpon
  • Twitter
  • WordPress
  • Share/Bookmark

Changes

I’ve decided to try moving my career more in the direction of freelancing consulting. It’s party based on necessity (haven’t found a full-time job yet) and partly on want (consulting/freelancing is very interesting). First step has been to make some info available about it – currently only in Danish but I’ll get it up in English soon as well.

The information about me as a consultant is available from the Freelance Webudvikling page. There’s some stuff about what I do, what I have worked on and what I charge. Hopefully, there should also soon be my Danish CVR number. That’s right: I’ve started my own company as well, PL PHP!

  • Google Reader
  • Delicious
  • Digg
  • Blogger Post
  • LinkedIn
  • Slashdot
  • StumbleUpon
  • Twitter
  • WordPress
  • Share/Bookmark