Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-12-03 00:16:32

Walker
Plugin Author
From: Boston, MA
Registered: 2004-02-24
Posts: 592
Website

Adding field to save with comment.

Howdy,

Does anyone have an idea of how I might add some data to be saved with a comment?

Specifically, I’m working on a Defensio plugin and I’d like to be able to store, at the very least, the “signature” alphanumeral that Defensio uses to uniquely identify a comment within it’s system.

I just can’t figure out where to store that data (and how to make a DB insert to save the Defensio signature while also knowing the txp_discuss table’s id for the comment itself).

Offline

#2 2007-12-03 06:21:19

net-carver
Archived Plugin Author
Registered: 2006-03-08
Posts: 1,648

Re: Adding field to save with comment.

Walker

Like you say, doesn’t look like it will be easy to get txp to store the data returned by the defensio api, even if you were to add a field to the table to store it. How about approaching it from a slightly different angle…

You don’t strictly need the id for the comment itself. There’s a clue for you if you look at publish/comment.php. On about line 336 the code checks if there is already a matching comment based on name, message and ip — no comment id in sight.

$isdup = safe_row("message,name", "txp_discuss", "name='$name' and message='$message2db' and ip='".doSlash($ip)."'");

Now, I think you can do what you want if you combine that thought with…

  1. a comment.save callback (which you’ll already have in place)
  2. a custom comments tag

Have your comment.save routine do the defensio api call as normal but now cache the result (in your own cache table) using the name/message/ip as the key, not the comment id.

Then make your custom comments tag resolve the final comment id and cached data just before the comments are displayed (ie for non spam this will be immediate as the page is reloaded with the new comment in it.) How you resolve the defensio data (signatures) to the comment id is up to you. You could copy the signature to a new field in the txp_discuss table and delete it from your cache or simply use your cache table to hold it by just adding the comment id to it.

Try leaving some comments on this page (for my comment pack) to see what effects you can achieve with a replacement for the <txp:comments /> tag. No hacks to core were needed, and the tag manipulates the existing comments (updates their status or deletes them.) Which is soooo close to what you need to do.

Do get in contact if you want some example code.

Last edited by net-carver (2007-12-03 06:23:10)


Steve

Offline

#3 2007-12-03 08:08:04

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Adding field to save with comment.

There should be an easier way to get the ID. When storing images, articles and such, we provide the new ID in a global variable. I’ll look into this later today. Perhaps we can do the same for comments.

Offline

#4 2007-12-03 08:39:24

net-carver
Archived Plugin Author
Registered: 2006-03-08
Posts: 1,648

Re: Adding field to save with comment.

If we are talking about core file changes then things will be easier :)

Something like the following at line 366 perhaps…

global $comment_id;
$comment_id =$rs;
callback_event('comment.assignid');

In the longer term (crockery?) would it be possible to allow plugins to manipulate other data that txp can store in the txp_discuss table along with the comments — custom fields for comments? I think this could facilitate other comment plugins a lot.


Steve

Offline

#5 2007-12-03 14:41:44

Walker
Plugin Author
From: Boston, MA
Registered: 2004-02-24
Posts: 592
Website

Re: Adding field to save with comment.

Like Whoa.
Thanks guys.

Ruud, if you do find a way in version 4.0.5 to find the comment id, that would be awesome.
I will look at this stuff as soon as I can, but I don’t think I’m going to be able to get back to this plugin until later this week.

p.s.
I’m already using defensio to moderate the comments on my site

The reasons I need to be able to attach the ID to the Defensio Signature is so that I can finish off my Extensions->Defensio tab so that the admin of a textpattern site can report false positives and false negatives back to the Defensio system (it’s a learning system) and view reports generated by the Defensio system.

Offline

#6 2007-12-03 14:43:13

Walker
Plugin Author
From: Boston, MA
Registered: 2004-02-24
Posts: 592
Website

Re: Adding field to save with comment.

Oh, p.s. I don’t need to manipulate the comments data, per se. I would just be happy if a comment id had been exposed as a global by the time comment.save is called. (Hopefully the system reserves it at that time….or something?)

Offline

#7 2007-12-03 14:51:11

net-carver
Archived Plugin Author
Registered: 2006-03-08
Posts: 1,648

Re: Adding field to save with comment.

Could be wrong but I don’t think it works like that.

I think that callback is for spam-prevention plugins to evaluate a comment during its client-side lifespan — before it gets inserted into the DB and therefore before any ID is assigned to it.

Edited to add: something like a ‘comment.saved’ callback would be able to notify interested parties of the latest comment’s id.

Last edited by net-carver (2007-12-03 14:53:29)


Steve

Offline

#8 2007-12-03 14:53:11

Walker
Plugin Author
From: Boston, MA
Registered: 2004-02-24
Posts: 592
Website

Re: Adding field to save with comment.

net-carver. you are absolutely correct. I know.

But, if comments happened to be implemented with reserved IDs (they could still be rolled back), then it would be accessible in comment.save. What is this called? ….transactions, kinda….?

Offline

#9 2007-12-03 14:57:08

net-carver
Archived Plugin Author
Registered: 2006-03-08
Posts: 1,648

Re: Adding field to save with comment.

Right, then you need to add code to handle deleting of placeholder rows for abandoned comment entries too. Still possible.


Steve

Offline

#10 2007-12-03 15:03:10

net-carver
Archived Plugin Author
Registered: 2006-03-08
Posts: 1,648

Re: Adding field to save with comment.

Walker, did you check out this thread? Looks like there may be an answer down that route.


Steve

Offline

#11 2007-12-03 15:12:04

Walker
Plugin Author
From: Boston, MA
Registered: 2004-02-24
Posts: 592
Website

Re: Adding field to save with comment.

Yeah, that is a thought. I could SHOW STATUS in SQL and then later (admin side) make sure the two tables are in synch….seems like a weak point in my plugin, though. As I would have to compare the comments, make sure they match up, and then delete the ones that don’t…..and mark them as checked so the plugin doesn’t end up checking them again later…

I’ll give that one a shot if Ruud comes back with a “negative”.

Offline

#12 2007-12-03 15:41:15

net-carver
Archived Plugin Author
Registered: 2006-03-08
Posts: 1,648

Re: Adding field to save with comment.

That’s possible, and I imaging will work some (most) of the time. However, you may get problems with two people posting comments simultaneously if your server supports parallel php worker threads in any way.

Imagine there are two threads (one per poster submitting their comment) and that each does its ‘SHOW STATUS’ before any comment actually gets inserted to the table. So each gets back id 100 as the next value. But only one of those comments is actually going to really be stored as id 100, the other may get 101 or some higher number.

The possibility of incorrect id assumptions like this will increase with the frequency of attempted comment submission.

AFAIK, using the name / message / id ip triplet will work out better as a key for your returned defensio data — and it will be no worse than what textpattern itself achieves.

Last edited by net-carver (2007-12-03 15:42:26)


Steve

Offline

Board footer

Powered by FluxBB