Not logged in. · Lost password · Register
Forum: Customising UNB Modifications and plug-ins RSS
Plugin development.
writing a plugin.
Reply
Reply · Quote TwystNeko #1
Member since Mar 2008 · 3 posts
Group memberships: Members
Show profile · Link to this post
Subject: Plugin development.
Alrighty, so I'm helping my friend out by writing a "post as anonymous" plugin, as per this thread. So, what I've got so far, is the config page, saving the settings, and adding the required fields and tables. Here's how I have it planned to work..

'anon' field added to posts, to flag a post as anonymous.
'anonypost' table added: id, threadid, userid, anonymous name
Two setting added: basename for the anonymous name, and the avatar to use for them

1. User opens the Post Options below the post, and checks off "Post Anonymously".
2. Plugin sees this, and sets the added "anon" field in the posts table to 1, for this post.
3. When the post is being parsed, in the post.preparse phase, it checks for the anon flag. If it's found..
4. Look in the "anonypost" table for this thread to see if this user has posted in this thread already. example: select name from anonypost where ((threadid = thisthread) and (userid = thisuser)). if a name's returned, use it. Otherwise, pull all the anonymous names (select name from anonypost where threadid=thisthread), trim them to just the number, get the max, and increment it.
5. Use the "anonymous name" instead of their real one. Use an anonymous-specific avatar. Remove the signature and other information.
6. If an admin is looking at the post, show the post normally, but add "this was posted anonymously" to the end of the message.



Now, I've got some of this done, but the API and Hooks are kicking my butt.
I'm stalled at step 2 - I can add the option to the Post Options section, but there seems to be no way to read that! post.preparse doesn't do it. post.postthreadcreate doesn't do it.

edit: okay, got it. Have to check $_POST array in post.verifyaccept.

Also, one potential issue I see is with quoting - is there a "prequote" hook?

I'm trying to write this as an actual plugin, rather than just hack the code into shape. :)
Avatar
Reply · Quote Yves (Administrator) #2
User title: UNB developer & webmaster
Member since Jan 2004 · 3740 posts · Location: Erlangen, Germany
Group memberships: Administrators, Members
Show profile · Link to this post
There's usually no more hooks than in the online documentation on this site. What would be the objective of that "prequote" hook?
♪ ...nanananah, all in all we’re just brilliant thieves, nanananah... ♪♬
Reply · Quote TwystNeko #3
Member since Mar 2008 · 3 posts
Group memberships: Members
Show profile · Link to this post
The idea is that when someone hits 'quote', it doesn't show the original name. Pressing quote fills in with
[quote='TwystNeko']

for example, thereby defeating the anonymity.

Also, from testing - If I use post.verifyaccept, it does pass on the anonypost variable that I'm setting, in the $_POST array.

But I can't get the post ID in that hook. Or even the thread ID - since this is prior to the post being added to the database.

If I use post.postthreadcreate - that only triggers when a THREAD is created - and doesn't give me an easy way to get the post ID. (I can do it via the DB calls, but that's a bit of a pain).

So what do I call when a POST is added?
This post was edited on 2008-03-28, 00:35 by TwystNeko.
Reply · Quote TwystNeko #4
Member since Mar 2008 · 3 posts
Group memberships: Members
Show profile · Link to this post
Okay. I've added a new hook - line 627 of post.inc.php, I added:
UnbCallHook('post.postcreated',array('post' => $post));

this passes the completed post object to the hooked function - I can now set the anonymous flag in the database. Yay!

Now, next roadblock: When I hook into post.preparse, I can look at the post, see that it's anonymous, which is great. However.. I can't seem to change the displayed user name or avatar. I'm currently trying to modify the $tpitem variable, that I see in common_post.lib.php, as overriding that would allow me to do what I need to.
This post was edited on 2008-03-28, 01:42 by TwystNeko.
Avatar
Reply · Quote NFG #5
Member since Sep 2006 · 105 posts
Group memberships: Members
Show profile · Link to this post
Just a quick <bump> for this one...

Any thoughts on this, Yves?
Avatar
Reply · Quote Yves (Administrator) #6
User title: UNB developer & webmaster
Member since Jan 2004 · 3740 posts · Location: Erlangen, Germany
Group memberships: Administrators, Members
Show profile · Link to this post
In reply to post #4
Reading the code, it seems like you shouldn't change the contents of the $user variable from a hook handler in that region (near post.preparse). This may lead to inconsistencies in the code which can have unpredictable results. You may need to alter the code to get the feature you need...
♪ ...nanananah, all in all we’re just brilliant thieves, nanananah... ♪♬
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please note the verification code from the picture into the text field next to it.
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Reply
Go to forum
This board is powered by the Unclassified NewsBoard software, 20100516-dev, © 2003-10 by Yves Goergen
Page created in 216 ms (172 ms) · 70 database queries in 132 ms
Current time: 2010-07-30, 10:57:55 (UTC +02:00)