If you want to have a quick fix which should be fairly easy to port, check the categories system of ACS 3.5, namely:
/www/categories
/www/doc/sql/categories.sql
/www/tcl/categories.tcl
All in all not more than 1000 lines of code
Example how this works:
http://acs35.theservice.de/news/item?news_item_id=100003&group_id=23&scope=group