Bookmark Manager
As a way to learn some ColdFusion basics, in 2003 I decided to implement a project I had been meaning to do for a long time in PHP: A central Bookmark manager. I never envisioned some of the social possibilities that del.icio.us has implemented since, but I was thinking along those lines.
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 made use of some of the following tags:
- “ - Bookmarks are stored in a MySQL database, which I set up as a ColdFusion datasource via the administration panel.
,- If/Else branching is probably the first thing everyone looks up once they learn the basic syntax of a language; it’s indispensible.,- 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.
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.
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.
Adding a new Category
If the user selects 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.
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.
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 to send the user to the correct URL.
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 expired years ago, nothing ever came of them:
- 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 ‘parentcategoryid’ 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.
