Tuesday 26 June 2007

Drupal Modules

Drupal requires a few modules before it can be truly functioning to one's expectation. The three sites listed below are more than enough for the beginner. As it is, some of the modules are only relevant if the website to be built is of a particular type - community, commercial, blog, etc. That said, the one module that must be installed would be the WYSIWYG editor. The default Drupal content creation way is to type in the page wholesale with all the markup which is a pain!

Modules:
Top 10 Drupal modules
10 Drupal Modules You Can't Live Without
Drupal Podcast No. 40: Top 40 Projects

WYSIWYG Editor:
TinyMCE WYSIWYG Editor
widgEditor - A WYSIWYG editor
FCKeditor

Friday 22 June 2007

PHP HTTP Authentication using database with PEAR

With Ubuntu 7.04 (Feisty Fawn) and a Synaptic-installation of php5, you'll have to install the Auth_HTTP package as in the book and then the DB package.

To obtain data read from the database, must use the getAuthData("column_name") method on the Auth_HTTP object.

Thursday 21 June 2007

PHP HTTP Authentication

The HTTP Authentication for PHP comes in two versions, “Basic” and “Digest”.
  • Basic sends the username and password across the net in plain text.
  • Digest uses some clever one-way encryption techniques (eg. MD5 or SHA1) to prove that both client and server are exactly who they say they are without actually sending the password at all (in fact the server doesn't even need to store the password itself).

A problem with HTTP Authentication is that there is no way to easily logout, in fact there is no support for logging out. The browser can access the restricted material until such time that the cached credentials are flushed. This usually happens when the browser is closed.

Friday 15 June 2007

Beginning PHP and MySQL 5 - Chapters 1-7

Ch 1 - An Introduction to PHP
Basically the history of PHP and why you should use it.

Ch 2 - Installing and Configuring Apache and PHP
Useful in getting started up. There are a lot of configuration options listed out. Using default values so skipped over it for now.

Ch 3 - PHP Basics
Learned the syntax that are available, quite a few including a short form version. Went through comments, outputting to html, datatypes, variables and constants, expessions and control structures like if, if-else and switch.

Ch 4 - Functions
All about functions, the prototype for a function is similar to a method:
function function_name(parameters)
{
function-body
}
There is no return type required. If needed, it can be added to the body.

Variable functions are functions which are evaluated at execution time to retrieve their names:
$function()
Given a URL parameter, this allows one to bypass the tedious if statement in order to know which function to call:
if($trigger == "retrieveUser")
{
retrieveUser($rowid);
}
else if($trigger == "retrieveNews")
{
retrieveNews($rowid);
}
else if($trigger == "retrieveWeather")
{
retrieveWeather($rowid);
}
to the much more compact:
$trigger($rowid);
There are security risks in using this so care must be taken.

Reuseable functions can be stored in a function library and called up by:
include("function.library.php");

Ch 5 - Arrays

Of note is the natural sorting function, natsort(), which sorts (10, 1, 20, 2) to (1, 2, 10, 20) instead of (1, 10, 2, 20).

Ch 6 - Object-Oriented PHP
Normal OO stuff that can be found in C or Java. The Properties feature in PHP can be used to extend the class by adding in new properties. A potential gotcha for constructors is that they do not call the parent constructor automatically.

Ch 7 - Advanced OOP Features
Again more of the same. However there are OOP features that are not supported such constructor, method and operator overloading. There is a section on reflection, showing how to obtain the class type, methods and parameters.

Wednesday 13 June 2007

Initial thoughts on PHP

Learning PHP through a book entitled Beginning PHP and MySQL 5: From Novice to Professional, Second Edition by W. Jason Gilmore.

PHP is a loosely-typed language due to its origin as a web counter script. This is inherent in the quick and dirty way it does things, one can put in a variable and assign and reassign it to various data types like strings, integers and floats. There is no need for declarations and type-casting, though it is available. Coming from a Java background, that is very off-putting. Acclimation would be easy but care must be taken to prevent any bad programming habits from creeping in.

The OOP aspect of PHP is a mix of C and Java coding styles. In that respect, it is pretty conventional and a Java programmer can take easily to it. Relatively simple websites should be easy to prototype quickly.

Thursday 7 June 2007

Installing CruiseControl - a continuous integration framework

The first step in installing CruiseControl (CC) is going to the SourceForge site and downloading the distribution. There are two flavors, a binary and a source distribution. You should choose the binary distribution as it is a trimmed version of the source distribution and is much simpler to use. After the download, extract the file to where you want to place it.

From here, you will want to follow the getting started guides for the binary and source distributions in order to set up CruiseControl. The binary distribution lets you run it 'out of the box' and you can see how a functional CC is supposed to work. Once you have the hang of it, you can try out putting your own project under CC. Using the guide for the source distribution, under the "Running the Build Loop" section, you can specify a place to store all your work.

Now the binary distribution sets the root of the CC directory to where the sh/bat executive file is called from. The requirement is that CC's lib and dist directories must be there. So the default is to call cruisecontrol.sh from the extraction place, that will also bind the project storage to be there. If you call the sh file from the specified place in the previous paragraph, CC will complain about not finding the lib and dist directories. The solution is to edit cruisecontrol.sh and hardcode the CCDIR to the extraction place, then call it from the project storage. Note that the binary distribution uses a projects directory instead of a checkout directory.

After that, follow the guide in creating config.xml and build-.xml, making changes as necessary. CC makes use of the Ant build tool so all the project compiling, testing and archiving are done using that. This site tells you how to make use of SVN in Ant instead of CVS.

Links:

Wednesday 6 June 2007

Continuous Integration

Continuous Integration (CI) is a software development practice of having team members integrate their work into the project frequently. Every integration is automatically built and tested so integration errors can be flushed out.

From Martin Fowler's article on CI, the practices to follow are:

  1. Maintain a Single Source Repository
  2. Automate the Build
  3. Make Your Build Self-Testing
  4. Everyone Commits Every Day
  5. Every Commit Should Build the Mainline on an Integration Machine
  6. Keep the Build Fast
  7. Test in a Clone of the Production Environment
  8. Make it Easy for Anyone to Get the Latest Executable
  9. Everyone can see what's happening
  10. Automate Deployment

Current practice at the moment only make use of steps 1 and 2. With step 2, though an Ant build script is present, the Eclipse IDE's automatic build is favored.

Step 3 - Tests are coded but currently they are run by hand, not in conjunction with the build. Step 4 - This is not adhered to, usually committing is done when a large task has been completed.

Steps 5, 6 and 7 are not relevant with the current practice.

Step 8 - Current practice is to ask developer for the latest code, use the source repository to transfer the code then build it. If the code is transferred to a new machine, custom settings have to be supplied before it can be built. Generally a lot of hassle and potential pitfalls.

Step 9 - Only the developer knows what's happening, anyone else has to be informed by that person.

Step 10 - The Ant build script has a deployment task. However that task only deals with production deployment which is set to a particular server and is not suitable for testing.

CI is supposed to lessen integration impact and allow for better communication between team members who are working on a project. Being a development team of one, there are no major issues. Anything that occurs is the result of that single developer and must subsequently be resolved by that person. However that will change as the team grows.