Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2007-10-25 15:08:51
- Chalito
- Plugin Author
- Registered: 2007-08-22
- Posts: 26
Obtaining saved comment ID and replacing functions
Hi folks!
I’m trying to get my very first (hopefully not the last) txp plugin working. I’m trying to add threaded comments (by way of setting a different class to comments depending on wether they’re replying to the article or to another comment). I’ve posted about it in the thread that suggested the idea here .
For this I’m creating a new table to relate comments with their parents.
So, my problem is that I need to insert the relationship data into that table right after the comment is saved. I would get the comment’s discussid, and the reply_to value sent with the form data, and insert the appropiate data into the proper table.
Using the callback for comment.save doesn’t seem to be of any use, since it’s called before the comment is actually saved (and I need to know the comments auto-incremented id.. I guess I’ll be using mysql_insert_id somewhere). I thought of modifying the commentSave() function, but how can I do that without modifying the source outside the plugin? If I copy the function over to my plugin and change the behaviour, I’ll have to rename it so I dont get an error for redefining an existing function.. but if I rename it, publish.php won’t call it.
I bet this has happened to someone before, I just couldn’t find anything concise in the forum about it. Maybe someone can throw an idea or two this way? :)
thanks
[[edit: fixed typo]]
Last edited by Chalito (2007-10-25 23:53:47)
Offline
Re: Obtaining saved comment ID and replacing functions
You might find a possible hook for your code by building a comment spam evaluator.
Offline
#3 2007-10-25 23:52:03
- Chalito
- Plugin Author
- Registered: 2007-08-22
- Posts: 26
Re: Obtaining saved comment ID and replacing functions
Well, the problem is that I’m trying to insert the relationship after the comment insertion, so hooking to commant.save won’t do. But you just gave me an idea.. maybe I can insert the relationship before I save the comment after all. I was thinking about mysql_insert_id because that’s all I can do with a direct php function, but instead I could ask mysql about SHOW TABLE STATUS, and get the value for the next auto_increment id.
I’ll try that, although I guess I’ll have to deal with some other stuff later (like making sure the comment gets saved, etc).
Thanks! I’ll post later to tell how it went. Meanwhile, if someone knows how to either alter an existing function from a plugin without modifying txp’s sourcecode, or how to work on a comment right after it’s been saved, I’m sure the info will be precious, and it’ d be useful to implement a more elegant solution.
Offline