Web Programming

Eight web developer warning signs

Most of us have been there. You talk to someone who has had a bad experience with a site built on a popular web framework and then once you look at the code you suddenly understand why. So I decided it could be useful to create a little cheat sheet. If you find yourself thinking I've done that as you read along, it might be time to get back to bagging groceries, building beautiful houses, practicing law or whatever else you're good at so you don't harm more folks out there who are just trying to make a living.

So here's the list:

Making outbound links generic

I'm looking for a good way to make outbound links from a Drupal site not show the full path of the referring page when the user reaches an external server. There are some posts in the Drupal forum about doing this sort of thing. In short, instead of wanting to track clicks I'm more interested in not making the internal URL evident to the external server. For example if I have an internal page at the following URL:

http://example.com/top-job-applicants

One easy way is of course not to use path aliases and that would be the quick work-around. However, in some cases I want users to be able to remember a URL and most don't recall 'node/1234' as well as they do 'job-applicants'. The challenge is that for privacy reasons I don't want to make evident to the operators of a server linked from the internal page that the user is an applicant (and maybe they aren't but are a prospect I want to encourage to apply).

A cursory look at the modules list didn't reveal the answer. Likely a module for this with a filter that can be applied to redirect all links through it will be the solution.

Sure I know Dreamweaver, Front Page and more

As a hiring manager I'm always skeptical when I get a resume filled with "technical" classes from one of the myriad of technical schools around the country. When I've worked with graduates of these programs it seems they have a marginal, but usually satisfactory, understanding of how technology is supposed to work. The problem is I rarely need people who can work with technology that is working. If technology is working and things are simple there is little that end-users need. Even relatively simple tasks like deploying computers depends upon a specific understanding of the complex situation that is most business networks. Few organizations do a "out of the box" installation of a Microsoft Active Directory and run 100% machines that work in that environment. These complexities mean a technical manager is quickly looking for skills that don't come from these technical schools. Ironically because they do tend to come in people who are self-motivated to learn the technology any way they can often the requisite skills are stronger in those who haven't been through this sort of program.

Sharing Space

First a minor clarification. While this serise has been titled a redesign, we're really talking here about first doing a re-implementation in order to enable a re-design.

.htaccess

Once a site is in produciton it's best to do away with .htaccess for performance. This is simple enough as the directives in .htaccess can be put in the Apache configuration file. For these early stages, though, it is great to have a .htaccess file so you can make changes without having to restart. Drupal ships with a .htaccess file that works for re-writing URLs so one can do "clean" URLs.

The problem with the site at hand, however, is it needs to still access the old site while the new Drupal site is going up around it. Drupal's .htaccess file contains the following directives that we are concerned with:

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

This tells the webserver that if a client requests a file and there is no file by that name and no directory by that name to send /index.php instead and to take the requested "page" and send it as an argument. Thus /node/3 becomes index.php?q=node/3. This works fine if the user requests a regular file. However it breaks down if they request a directory. If a user requests /oldsite/ Apache doesn't know that the "if the file doesn't exist" part applies to /oldsite/index.html until it is too late. Apache merrily serves up index.php.

To solve this problem (and a couple of variations) we add the following three lines before the three above in the .htaccess file:

Category: 

Let's Get Together

The best is the enemy of the good. - Voltaire

One of the challenges facing the migration of a website from a collection of loosely gathered HTML and PDF files into a content management system is finding the balance between keeping the current site running and implementing the new site. In dreamland where information systems staffs and communications staffs are sitting about waiting for things to do there are plenty of helpers. In the real world it's not that simple.

This website started as a collection of pages in a single directory. Something like this:

/www/dept1.html
/www/dept1_hours.html
/www/dept1_additional_info.html
/www/dept1_special.html
/www/dept2.html
/www/hello.html
/www/home.html
/www/otherdepartment.html
/www/staff/staff_bio1.html
/www/staff/staff_bio2.html

As organizations are dynamic additional people come along and have some additional needs. In addition some departments have staff allocated who can do some HTML work and want to improve their sites. With time the directory grows to look more like:

/www/dept1/dept1.html
/www/dept1/dept1_hours.html
/www/dept1/dept1_additional_info.html
/www/dept1/dept1_special.html
/www/dept2.html
/www/hello.html
/www/home.html
/www/otherdepartment.html
/www/staff/staff_bio1.html
/www/staff/staff1/mypage.html
/www/staff/staff_bio2.html

Basically there are tons of files at the first level and a handful of second, third and fourth level directories. A little good fortune made this project easier. The existing site included a "include" directory. This is fortunate because Drupal has an include directory but it is called "includes".

Category: 

Journal of a redesign

With today's post I'm going to start profiling some hints and tricks for migrating an existing static website to a new site managed by a content management system. As it has been for the last few dozen projects I've worked on Drupal is the content management system of choice.

Background

The website in question started as a small collection of web pages. Early on (sometime before I got involved) the choice was made to use server-side includes to provide a semblance of control on the design. Over and over files were created and pages added. According to Google there are now roughly 2,600 entries for this site in their index.

In the early days of the site there was a dilemma. Since there was no content management system where people with information could make it available to users they had to send it to the webmasters. This quickly becomes a resource drag and the information suppliers are then told to put their information in PDF documents. With this history, the one-page PDF is more common than it should be. Much feared, the one-sentence PDF also makes frequent appearances.

The need for some automation drove the connection of several Microsoft Access databases and a small number of PHP scripts. With several processes left half-baked what should have been a help offered little assistance. Instead of posting a single-sentence PDF directly, the process grew into a series of e-mail the PDF, a webmaster posts the file and copies and pastes several entries into an Access database. Since that didn't cause enough problems there is then a step of FTPing the Access database to the server. The server uses ODBC connections to other data sources, but for this particular process they were never setup.

Category: 

How to create really annoying databases

Microsoft Access is at once great and the scourge of my existence. It has great power to create databases quickly and for small organizations it can be very handy. However, it also makes it easy to create databases even if it's something you really have no business doing.

I'm working on a couple of inherited projects now and there are two very annoying things. One of the annoying things is to create quasi-relational tables with no normalization. Put as many columns in as possible and repeat them in as many databases as possible. If that doesn't do enough for you copy the database a hundred times and create separate versions of it.

The other, almost more annoying practice, is to create one of these monster tables. Then instead of having your PHP script run queries on the table you create a query in Microsoft Access and run the PHP queries against the MS Access query. For annoying bonus points, rename three of the 40 fields so you have "Username" instead of "User". Repeat.

Oy.

Subscribe to Web Programming