Firefox PHP

Tagger Hack: Retrieving threads from db

Posted by Ambush Commander 
Tagger Hack: Retrieving threads from db
September 13, 2007 01:38AM
I am currently working on a "tagger" mod/hack for Phorum that will enable users/admins to "tag" posts, search for posts with certain tags, and generate "tag clouds", ala del.icio.us. It's a project primarily for my own needs, but if someone else finds it useful, good for them.

I have managed to bang out a working (albeit private) prototype, but I'm not happy with some of the hacks/patches I've needed to make to the source code. The biggest problem involves alterations to the DB handling functions.

In order to allow users to filter threads by tags, I'd like to overload behavior on the List page. However, the list hook gets to the threads too late: I need to modify the SQL itself that is being used to retrieve the threads (I'm doing some fancy table joins and other things in order to retrieve the tags I want). As of right now, I've added in code that injects this extra SQL into the statement generated at phorum_db_get_thread_list(), detecting a "tag" get parameter.

It is, consequently, extremely messy, and not very forwards compatible. Is there a better way of doing this, or should I just bite my lip and press forward? Also, why do functions defined by modules not seem to be callable from the DB processor?

HTML Purifier, standards-compliant HTML filtering
Re: Tagger Hack: Retrieving threads from db
September 13, 2007 02:45AM
It is best not to hack the code, but that is no news to you. What I normally do when the standard db layer misses functionality for a feature that I am building, is create the extra required db code as part of my module. For example the Spam Hurdles module creates an extra table and has some functions for interfacing with that table.

The thing that you are trying to pull off here is much more complicated than the Spam Hurdles db handling though. I think you have two options here: either hack the core code or fully override the full list page. Overriding would mean that you implement the list functionality in full (front end script + db interfacing). That last one solves the problem of having to hack core code, but it does not meet any requirement for being forward compatible.

Isn't it an option to use the search interface for listing messages by tag(s)? You can override the search functionality more easy than the list functionality and to me, tagging sounds more like a search feature than something to do through the list page.

Functions defined from a mod should be accessible from anywhere in PHP. We did not do anything special to disallow this. It might be that at the time that your db code runs, the module has not yet been loaded. Modules only get loaded as their first hook is called.


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: Tagger Hack: Retrieving threads from db
September 13, 2007 03:31AM
Search overloading would work quite well. What I'm concerned about are the little "extras" that are in phorum_db_get_thread_list(). For example, the SQL statement for selecting threads contains a few extra gems: it checks for approval status, it checks the sort column, and it uses an index. Presumably, this could expand in the future, so it's slightly non-forwards compatible, but tolerable.

As for the module loading problem, makes sense. I should make a dummy hook function for those pages, then?

HTML Purifier, standards-compliant HTML filtering
Re: Tagger Hack: Retrieving threads from db
September 13, 2007 09:41AM
You could indeed add a common_pre hook, with an empty function as its implementation. That would make Phorum load the mod at an early stage.

I will try to think about a way to handle the list madness. At this moment I have no really brilliant ideas on how to handle it in a fun way. Dynamically extending the db layer functionality is the problem here. We do not allow hooks in the db layer and really want to keep it that way. I did do some dynamic query building for the "prune messages" functionality, but I don't think that such type of system would be sufficient for the needs of the tagging mod.


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: Tagger Hack: Retrieving threads from db
September 13, 2007 01:41PM
This sounds like a problem similar to creating extra user info. Maurice, would it make sense to create a "Custom Message Fields" section much like the custom profile fields that you have already added?

I know that this is more of a feature request for a future phorum version, but I think it makes sense to have custom message fields and they would really add some power to phorum. Just a few uses would be the tags mentioned above, a ratings system (which could even be used a la slashdot.org), or adding set of available icons which a poster could use to highlight or categorize a post.

So I guess this is me officially asking that "Custom Message Fields" be considered for a future phorum release and darn the expense and the hassle :p


Joe Curia (aka Azumandias)
Modules: l0Admin Mass Email00000000l000000Automatic Time Zones000ll.l00000Enhanced Custom Profiles0.00Google Calendar0000l.l000000Post Previews
000000000Admin Security Suite000000000000Check Modules for Upgrades0000External Authentication000000Group Auto-Email00000.00000Private Message Alerts
000000000Attachment Download Counter0000Custom Attachment Icons000ll.ll00Favorite Forums000000.00000Highlighted Search Terms0000Self-Delete Posts Option
000000000Attachment Watermarks0l00000000Custom Language Database00l.l.0Forum Lockdown00000.00000Ignore Forums0000000000000Threaded Tree View
000000000Automatic Message Pruning00.llll.00Easy Color Scheme Manager0l.l00Forum Subscriptions0000lll000Moderated User Group
Templates:lGeneric Integration000000000 0000Simple Rounded000000 00000000Tabbed Emerald
Re: Tagger Hack: Retrieving threads from db
September 13, 2007 02:33PM
they are there, its just called meta without needing extra-definition ;).


Thomas Seifert
Phorum Development Team / Mysnip-Solutions.de
Custom Phorum and general software development
worry-free Phorum Hosting
Re: Tagger Hack: Retrieving threads from db
September 13, 2007 03:10PM
So it should be possible to save the tags to the meta field without disturbing the other meta data? I'm assuming the meta field holds an array which could hold other arrays? This would then be readable without doing anything else to the db layer?


Joe Curia (aka Azumandias)
Modules: l0Admin Mass Email00000000l000000Automatic Time Zones000ll.l00000Enhanced Custom Profiles0.00Google Calendar0000l.l000000Post Previews
000000000Admin Security Suite000000000000Check Modules for Upgrades0000External Authentication000000Group Auto-Email00000.00000Private Message Alerts
000000000Attachment Download Counter0000Custom Attachment Icons000ll.ll00Favorite Forums000000.00000Highlighted Search Terms0000Self-Delete Posts Option
000000000Attachment Watermarks0l00000000Custom Language Database00l.l.0Forum Lockdown00000.00000Ignore Forums0000000000000Threaded Tree View
000000000Automatic Message Pruning00.llll.00Easy Color Scheme Manager0l.l00Forum Subscriptions0000lll000Moderated User Group
Templates:lGeneric Integration000000000 0000Simple Rounded000000 00000000Tabbed Emerald
Re: Tagger Hack: Retrieving threads from db
September 13, 2007 04:43PM
I considered using the meta field, but decided against it. If I had implemented it that way, I would need to do a table scan in order to find the rows that had what I wanted.

HTML Purifier, standards-compliant HTML filtering
Re: Tagger Hack: Retrieving threads from db
September 13, 2007 04:54PM
Meta data can do that, but the big problem with meta data in this respect, is that you cannot run SQL queries on the meta data. So it is pretty useless when used for tagging.


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: Tagger Hack: Retrieving threads from db
September 13, 2007 05:08PM
So would this put us back to implementing a "Custom Message Fields" concept? It would allow each custom field to be queried, correct? What would it take to implement this idea?


Joe Curia (aka Azumandias)
Modules: l0Admin Mass Email00000000l000000Automatic Time Zones000ll.l00000Enhanced Custom Profiles0.00Google Calendar0000l.l000000Post Previews
000000000Admin Security Suite000000000000Check Modules for Upgrades0000External Authentication000000Group Auto-Email00000.00000Private Message Alerts
000000000Attachment Download Counter0000Custom Attachment Icons000ll.ll00Favorite Forums000000.00000Highlighted Search Terms0000Self-Delete Posts Option
000000000Attachment Watermarks0l00000000Custom Language Database00l.l.0Forum Lockdown00000.00000Ignore Forums0000000000000Threaded Tree View
000000000Automatic Message Pruning00.llll.00Easy Color Scheme Manager0l.l00Forum Subscriptions0000lll000Moderated User Group
Templates:lGeneric Integration000000000 0000Simple Rounded000000 00000000Tabbed Emerald
Sorry, only registered users may post in this forum.

Click here to login