Greyledge.net
ColdFusion

ColdFusion Bookmark Manager

In an attempt to learn some ColdFusion basics, I decided to implement a project I've been meaning to do for a long time in PHP: A central Bookmark manager.

While any web browser worth its salt has a feature for saving favorite URLs, users of more than one computer or browser (Mozilla, MSIE, Lynx, Opera, Home, work, laptop, etc) often find themselves with several different bookmark lists, each one out of sync.

By centralizing those bookmarks in a web-based application, the user can easily maintain a single bookmark list from anywhere on the web. By using JavaScript "Bookmarklet" links in the browser's personal links toolbar, adding a bookmark to the ColdFusion application is as easy as adding it to the browser's native favorites page.

This project was my first foray into the world of ColdFusion, and makes use of some of the following tags:

<cfquery>
Bookmarks are stored in a MySQL database, which I set up as a ColdFusion datasource via the administration panel.
<cfif>,<cfelse>
If/Else branching is probably the first thing everyone looks up once they learn the basic syntax of a language; it's indispensible.
<cfswitch>,<cfcase>
I was happy to learn that ColdFusion supports switching, which usually makes for much cleaner code than a series of if/elseif/elseif/elseif/else statements.
Custom tags
Custom tags are the rough equivalent of user-defined functions in other programming languages, although that comparison is not entirely correct because there is also such a thing as a user-defined function in ColdFusion. Nevertheless, the idea is the same; taking a frequently used chunk of code and breaking it into its own tag that can be called with different parameters, if needed.

Source Code

This is my first ColdFusion programming effort and as such it's not much for careful planning, consistent variable and file naming, heavy security, or portability, but as long as I've got the code lying around you're welcome to use it under the terms of the GNU General Public License:

Installation Notes (also included in the download)

How it Works

Security

The first task was to implement some very basic password protection. Each page of the application checks for the presence of a cookie indicating logged-in status. If the cookie is not present, the user is automatically redirected to a login form. The referring URL is saved as a hidden form variable from the URL variable scope, and once logged in the user is sent back to the page they were trying to access.

The username/password for this simple application are hard-coded into the login script; hardly robust, but adequate for learning purposes.

[Screenshot]

The "Add Bookmark" Link

To make adding bookmarks convenient, a JavaScript bookmark is added to the browser's link toolbar. This is the link URL: javascript:void window.open("http://localhost/cf/bookmark/add.cfm?pageurl=" + escape(document.location) + "&pagetitle=" + document.title, "cfbookmark", "width=300,height=150")

The link pops open a small window and tells it to load the "add" page, sending it the URL and Title of the document the user is currently viewing.

Adding a Bookmark

Taking the URL and Title information from the URL variable scope and retrieving a list of categories from the bookmark database, add.cfm presents the user with a form where they can select a category for the link and indicate whether or not they want the link to be "public". By giving links a public or private designation, it becomes simple to automagically generate a links web page for the user's own web site, featuring only those links marked "public".

If the user selects an existing category, the new bookmark is inserted into the database and the popup window closes itself.

[Screenshot]

Adding a new Category

If the user selects <New Category> when adding a link, they are directed to an "Add Category" form. The bookmark information is preserved as hidden form fields, and upon submission the new Category is inserted into the database, and then the new bookmark. The popup window then closes itself.

[Screenshot]

Viewing Bookmarks

In addition to bookmark URLs and page titles, the database also stores the date upon which the bookmark was last visited; in this way the bookmarks.cfm page can display a convenient "Recently Visited" section at the top of the page, and organize bookmarks in order of recent visitation.

[Screenshot]

Following Links

In order to keep "Last Visited" information about each bookmark up to date, each link on the Bookmarks page actually passes the Bookmark's database ID number to a local script called exodus.cfm, which updates the bookmark's last_visited timestamp and then uses <cflocation> to send the user to the correct URL.

Screen Shots

The Login screen
If the user is not logged in, they are redirected to this screen.
Adding a bookmark to an existing category
The smaller window pops up when the user clicks the "Add Bookmark" link in their browser favorites. The user can edit the bookmark title, but the existing page title is used by default. The category menu is pulled down in this shot. (Categories are displayed in the order in which they have been added to the database.)
Creating a new category (The bookmark is automatically saved in the new category.)
When the user selects <New Category> from the menu on the "Add Bookmark" screen, they are directed to this form where they can enter the new category name.
The bookmark page.
The bookmark page itself, which displays links in the order of most recent visitation.

Room for Improvement

I can think of all kinds of enhancements for this project, but since my hosting provider doesn't support ColdFusion and my own evaluation copy is going to expire in about 25 days, they will probably have to wait until I put together a PHP implementation. Nevertheless, here are some possible improvements:

  • A password-protected page for editing bookmarks; changing their title, url, public status, category, or deleting them altogether.
  • Support for nested categories. This would be as easy as adding a 'parent_category_id' field to the category table, and tweaking the code which generates the category pulldown menu and the bookmarks.cfm page.
  • A script for generating Netscape-compatible bookmark.htm files; combined with a cron job or scheduled task, this would be a great way to keep the convenience of the browser's own Bookmarks menu while maintaing bookmarks in a central location on the web.
  • Implementation as a web service, or at the very least implementation of multi-user support.
  • Et cetera.
Valid XHTML 1.0! Valid CSS!