About IT and Sports

My Web development experiences and sports encounters


Handling settings.php in Drupal

When working with Drupal there is a moment where you have to think about the way you want to manage settings.php. This file contains important configuration settings like the database credentials. It is most often also used to add custom configuration settings. Drupal comes with a default version of this file and during installation Drupal will write the database settings to this file.

The problem
Many projects run in a DTAP (Development, Testing, Acceptance and Production) development process, using a SCM tool like git or svn in a multi developer and multi location environment. The following problems/requirement should have your attention:
1. Each DTAP environment have their own specific settings as does every developer. For instance the database settings. Changes to settings.php will probably lead to SCM conflicts.
2. From a security point of view you don’t want database passwords in version control. Especially when you are using an online service like github.com.
3. You want to be able to make environment specific settings (develop, test, acceptance, production). For instance when you have a Varnish instance which only runs on acceptance and production.
4. General configuration settings for all environments should be possible
5. You want to prevent working with local changes or unversioned files on any environments

The solution
To handle the requirement above, we have worked out way to achieve this:
- Database settings are taken out of settings.php and moved to a separate file env.settings.inc. This file is included from settings.php
- The file env.settings.inc is not added to version control. In git you can use .gitignore to keep it out of version control.
- In env.settings.inc a variable is included to define the environment:
$environment = “develop”; // Possible values: develop, acceptance, production

- Per environment a settings file is created: develop.settings.inc, etc. These files are included in settings.php and added to version control.
- General configuration settings which are needed for all environments are added to settings.php. Settings.php is also added to version control.

In settings.php we add the following:

if (file_exists (‘./’ .conf_path(). ‘/env.settings.inc’)) {
include_once(‘./’. conf_path(). ‘/env.settings.inc’);

if (file_exists (‘./’. conf_path(). ‘/’. $environment . ‘.settings.inc’)) {
include_once(‘./’. conf_path(). ‘/’. $environment . ‘.settings.inc’);

This solution meets all the requirements. It’s clean and and well-ordered. And most importantly it prevents a lot of irritations, because you don’t have conflicts on settings.php anymore. If you found any flaws in this configuration or if you have another strategy on settings.php, please share them.

This article was originaly posted on the Colours blog.

Building webapplications on top of Drupal

Drupal is best known as one of the most popular CMS products used on the web. But the Drupal community likes to call Drupal a Content Management Framework; a tool which gives you the ability to quickly and efficiently tailor a webapplication to your needs. Drupal is not just a content publishing tool but can be used on a broad range of applications.

Web applications often contain functionalities which CMS tools also have. Users need to register and login. Autorisation is needed to distribute permissions. A template engine separates data from layout. You want to have tools for consistent interfacing. These are a few important functions you will probably need  in every web application. But there are many more which might be useful in the more specific requirements of your project.

An important part of the Drupal framework is the module system. It gives you the ability to separate custom code from the Drupal core and  modules. This makes updating Drupal to newer versions much easier and packages functionality in a orderly fashion. Drupal furthermore gives modules the ability to hook into core functionality. For instance to create new url’s or to change forms.

A good example of a webapplication we have build at Colours is the web application for the anual World Press Photo contest. This application contains 3 parts:

  1. A frontend in which photographers can register, upload and manage their photos
  2. A backend for administration of photographers and uploaded photos
  3. A tool for judging photos

A custom tailored web application was needed to accomodate for a high performance website and complex functionality. Good performance is need to smoothly upload 100.000 large photo files in a short timeframe. Most of the images are uploaded in just a few days before the deadline. During the upload proces some cpu and memory consuming operations are needed to convert images to a custom size. A separate imageserver was responsible for image conversions. The webservers communicated with the imageserver through SOAP webservices. We used the YUI Uploader to facilitate a user friendly(multi file select, progress tracking) and high performance (faster upload, asynchronous events) method of uploading files.

The backend functionality for administration and judging implement the Contest rules. These screens make good use of the Drupal Form api to efficiently create forms and permissions to implement autorisation.

A more specific functionality is the link to Salesforce CRM. A contributed module was used to make the connection to Salesforce. Custom code was writen to map the custom user profile to the specific user account fields in the CRM database.

Drupal offers an excellent environment if you want to mix a CMS with specific application functionality. You can easily use what the Drupal core has to offer. Use contributed modules to incorporate more specific functions. All this gives you great power and flexibility.

Dutch version posted on drupal.nl:

This article was originaly posted on the Colours blog which has recently been taken offline.

Git deployment over ftp

Most shared hosting services don’t offer git deployment options. Normally you just use ftp to upload your changes to your website. It’s easy to make errors on such deployments, especially when you do updates where you only want to change a number of files. Because I didn’t want this anymore for my blog, I looked for a better solution.

I found git-deploy. It’s a binary executable which you run from your Linux development environment. It’s able to deploy only the changes since your last deployment. It requires ruby and can be installed using gem. I followed the installation instructions on the project homepage on github: https://github.com/aizatto/git-deploy.

The only thing I was missing in this installation description was the installation of ruby. I used this command:

sudo apt-get install ruby libruby rdoc libgtk2-ruby libglade2-ruby libyaml-ruby libzlib-ruby libopenssl-ruby libdl-ruby libreadline-ruby libiconv-ruby sqlite3 libsqlite3-ruby irb libssl-dev

Copy the git-deploy binary to your binaries path. Create a deploy.yml and REVISION file. The REVISION file is used to save the commit-id of the last deployment.

When you committed changes to git, just run git-deploy. The REVISION file on your ftp site is updated by git-deploy.

Google gadget app for Simplenote

I am that kind of person who likes to keep lists. Mostly because if I don’t, I forget. I the old days I used paper notes, but when iGoogle was launched I quickly started using gadgets to collect my notes. Because I have a PC or laptop arround most of the day, keeping notes with iGoogle was quite efficient. When I bought an iPhone I wanted to have my notes with me everywhere. Because iGoogle did not have a good user experience on the iPhone I started looking for a better solution. I found Simplenote. This service supports serveral devices, browsers and more. It also hase a public Restfull API which you can use to connect.

Unfortunately Simplenote did not have a Google gadget app. Because I got quite attached to my iGoogle page, I decided to create a Simplenote gadget. The gadget I created has basic Simplenote support. It can create, edit, sync and delete notes. I had a lot of fun building the gadget with javascript and JQuery.

You can find the app in the Google Gadget Directory and install it from there. Any comments on this app are greatly appreciated.

IPhone Hello world – Getting started

Today I made my first IPhone app. It was only a Hello World app, but it always feels nice when you try something different. In this case Objective-C for the ios platform. I got my app to open a new view from a button click and change a label to display the current date and time also after a button click.

Some getting started tips.

To get going you need to download the IDE apple provides for ios and osx development: Xcode. Go to the iOS Dev Center, create an apple account. Download and install Xcode and iOS SDK. This website has tons of documentation and also a good Getting started section.

The Hello World app I made was completely programmatic. I used the following guidance:

You can also use the Interface Builder (which comes with Xcode) to create buttons, label and other interface components. To handle the IDE, you need to read to following user guide to understand how this works.

If you want to create your own Hello World, you will want to play arround with buttons and labels. It is wise to understand how views work. Check out the View Programming Guide.

Remove photo’s from camera with iPhoto

Ever since Image capture is not available anymore for Mac OSX, I don’t have an easy way of cleaning up photo’s on my Canon Ixus camera. It’s simply not possible in iPhoto to delete selected photo by pressing backspace or draging them to the dustbin.

You do have the option to delete photo’s after you’ve imported them, but I usually don’t use it because I like to keep recent photo’s on my camera for a little while. But once in while you need to clean up your memory card.

The only way to delete a selection of photo’s I discovered so far is to import already imported photo’s again. At the end of the import, iPhoto will ask you to delete the photo’s on the camera.I wonder if there is a better way.

Upgrade to WordPress 3.0 and iPhone access

For some time now I wanted be able to make posts on my blog through my iPhone. No particular reason, I just seemed cool to me. I decided to make my blog accessible for mobile devices and found some plugins which make this possible. I noticed that WordPress 3.0 was out so I decided to upgrade WordPress as well. I made some backups and downloaded the zip file. Diasabled my plugins and copied the extracted zip to my hosting server. Keep the wp-content folder in tact, only overwrite the files and subfolders which came with the zip file. Next login to the backend and let wordpress patch your database. Activate you plugins again and you’re done.

Looking into iPhone accessibility I found out that there is a Worpress app in the app store. I quickly installed and started writing this post from my iPhone. Although type is a lot slower, it is just fun.

I also wanted to make the frontend more accessible for mobile browsers. I installed the plugin WordPress PDA & iPhone. I gives a simple but effective interface to your blog. I am all happy now :)

Een zwevende bal

Soms gebeuren er onwaarschijnlijke dingen tijdens een golfwedstrijd. Ik sloeg samen met mijn partner Peter Cloodt af in een foursome wedstrijd voor de NGF competitie. De wedstrijd werd gespeeld op Golfbaan Capelle aan de IJssel. We konden de baan niet en hadden ook niet voor gespeeld. De afslag op de eerste tee was meteen een dilemma. Het was een dogleg naar rechts, dus een goede positionering in de bocht was belangrijk. Welke club slaan we af; de houten 3 of toch maar de driver. Het werd de laatste.

De drive was exact zoals opgelijnt. Helaas bleek er toch minder ruimte te zijn als gedacht en stuiterde de bal door de bocht de struiken in. Aangekomen bij de bal stonden Peter en ik perplex. Ik speel al 20 jaar golf maar dit had ik nog nooit meegemaakt.

zwevende balDe bal hing in de struik ongeveer 1 meter boven de grond. Geklemd tussen een paar takjes. Normaal gesproken als een bal zweeft in de lucht neem je een tennisracket of honkbalknuppel maar beide zaten helaas niet in onze tas. Nadat de verwondering voorbij was en we terug keerden in de realiteit van de situatie, besloten we een strafslag te nemen en te droppen. Jammergenoeg ging de hole verloren. Uiteindelijk konden we de partij wel winnen.

Understanding Zend Framework form decorators

I just watched a very good screen cast on zendcast.com about form decorators. It points out the essences of the zend form decorators which you might not grab right away when reading the reference guide or copying away from examples on the net.

There are 3 important aspects which you need to keep in mind when working with decorators. First of all form decorators change a piece of content, for instance a form element, which is of course what you might expect from the decorator design pattern. Try to picture this piece of content in its simplest form. For instance a <input> element. Your goal is to place this element somewhere in your html content, say a table.

The imput element can be created by instantiating a Zend_Form_Element_Text class. By adding decorators to this object you can influence how the input element is shown. Decorators can change content in 3 ways: prepending the content, replacing the content or appending the content. If you want to render the input element in table cell, you should use a decorator which replaces the content punting <td> tags around it:

<? $content = “<td>” . $content . ” </td>”; ?>

The second important thing to understand is that decorators are rendered in the order they are added to the Zend_Form_Element. This way you are able to render the content in a hierarchical way. Which is also the case in building up html content. You start which a leaf element and wrap around, prepend or append content until the last decorator is reached.Let’s look at the an example:

array(array(‘data’ => ‘HtmlTag’),  array(‘tag’ =>’td’, ‘class’=> ‘element’)),
array(‘Label’, array(‘tag’ => ‘td’)),
array(array(‘row’ => ‘HtmlTag’), array(‘tag’ => ‘tr’))

The example above creates a 2 column table structure. The first decorator (ViewHelper) renders the <input> element, the second puts it in a table cell, the third prepends a label which is also put in a separate table cell, the fourth wraps around a <tr> tag and the last decorator puts the rendered content within <table> tags.

The third important thing to keep in mind is that you can do most of the html rendering with the decorators Zend Framework already offers in its library. You don’t need to make many of your own decorators. The decorator you are going to use frequently is the HtmlTag decorator. Use this decorator to change the html tags you want to use. For instance if you want your content to be inside <div>’s. The example uses the HtmlTag decorator 2 times. For this reason you need to use an alias to identify the decorator. In the example the aliases are ‘ row’ and ‘ data’.

Understanding decorators will save you a lot of trial and error programming. So put some time in learning what decorators do. The webcast on zendcast is a good starting point: Zend_Form Decorators explained.

Team 1 op weg naar de competitie (Deel 2)

Onlangs beschreef ik in deel 1 van dit artikel hoe team 1 zich voorbereid op de competitie middels trainingen, oefenwedstrijden en speciale indoor trainingen bij Jumbo Golfwereld.

De vast trainingsdag is de zondag ochtend. Onze jongens moeten vroeg uit de veren. Om 8.30 uur dient acte de presence gegeven te worden op de driving range. In november is er gestart met groepslessen  onder leiding van Kars Gresel. Een frisse en vernieuwende aanpak zorgt voor veel enthousiasme binnen het team. De swing wordt verder verbeterd door gebruik te maken van video analyses en theorie van ondermeer Dave Peltz. Een belangrijke conclusie in het bestuderen van de theorie van Peltz is dat er meer nadruk gelegd moet worden op het korte spel. De helft van het totaal aantal slagen in een rondje golf wordt op of rond de green gemaakt. Dat betekend dat je ook minstens de helf van de trainingstijd moet besteden aan putten en chippen.

De voorbereiding van op de competitie zal in maart worden afgesloten met een trainingsstage in Spanje. Het Empora Golf resort biedt goede oefenfaciliteiten, 2 top banen, een hotel en de lokatie ligt slechts op een uurtje rijden van Ryanair vliegveld Girona. Vanwege het zachte Spaanse klimaat kan er ook in maart onder perfecte baan omstandigheden geoefend worden.

Dit oefenprogramma moet het eerste heren team klaar stomen voor de competitie. Hierin zal de eerste match op de Dommel meteen een belangrijke worden wil de doelstelling om kampioen te worden in de poule gehaald worden. Tegenstander is Capelle aan de IJssel. Zij zijn afgelopen jaar gedegradeerd uit de hoofdklasse en kunnen daarom gezien worden als een sterke opponent. Er mag ook veel tegenstand verwacht worden van Princenbosch. Zij werden vorig jaar kampioen in hun poule maar konden niet promoveren. Overige tegenstanders zijn De Wouwse Plantage en De Dommel.