FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » FUDforum Development » Plugins and Code Hacks » API hooks into post moderation?
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
API hooks into post moderation? [message #160671] Mon, 12 October 2009 01:00 Go to next message
LADave is currently offline  LADave   United States
Messages: 19
Registered: July 2009
Location: Los Angeles
Karma: 0
Junior Member
Would it be possible to get some API hooks that allow the moderation of posts? Currently the 'fud_fetch_msg' function only returns approved posts. It's easy to edit that function to return unapproved posts but going through all the proper steps to 'approve' a post isn't available through the API.

I'm trying to get some automated moderation of posts using the Defensio API but I'm running into some troubles since I can't find the proper way to 'approve' a post so that FUD is happy.

Thanks,
Dave
Re: API hooks into post moderation? [message #160674 is a reply to message #160671] Mon, 12 October 2009 15:48 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3771
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
You are welcome to prepare a patch. Alternatively, you may want to try something like this:

<?php
include_once 'GLOBALS.php';
fud_use('db.inc');
fud_use('imsg_edt.inc');
fud_use('rev_fmt.inc');
fud_use('cookies.inc');
fud_use('users.inc');
fud_use('th.inc');
fud_use('th_adm.inc');
fud_use('fileio.inc');
fud_use('isearch.inc');
fud_use('iemail.inc');

$i = 0;
$c = q("SELECT id FROM ".$GLOBALS['DBHOST_TBL_PREFIX']."msg WHERE apr=0");
while ($r = db_rowobj($c)) {
      echo "Approve message ID# ". $r->id ."\n";
      fud_msg_edit::approve($r->id);
      $i++;
}
echo $i." messages approved.\n";
?>
Re: API hooks into post moderation? [message #160675 is a reply to message #160674] Mon, 12 October 2009 16:50 Go to previous messageGo to next message
LADave is currently offline  LADave   United States
Messages: 19
Registered: July 2009
Location: Los Angeles
Karma: 0
Junior Member
Thanks for the code to get me going in the right direction. I was trying something similar this weekend but was getting some PHP errors that I couldn't track down.

I think I'm leaning towards making an auto-moderation script with some simple rules. Basically auto-approve imported NNTP messages in which the user has more than X number of posts already. Should be pretty simple to implement, I'll post here when I get it figured out or when I run into problems I can't solve Razz

-Dave
Re: API hooks into post moderation? [message #160685 is a reply to message #160675] Tue, 13 October 2009 01:26 Go to previous messageGo to next message
LADave is currently offline  LADave   United States
Messages: 19
Registered: July 2009
Location: Los Angeles
Karma: 0
Junior Member
Here's my first shot at auto-moderation based on previous post count. This should work great in my forum since I trust NNTP posts from people who have a proven track record but I want to moderate newly created users or users with less than a certain amount of posts (trying 6 posts to start with).

Comments/improvements appreciated.

-Dave

#!/usr/local/bin/php -q
<?php
include_once 'GLOBALS.php';
include_once 'fudapi.inc.php';
fud_use('db.inc');
fud_use('imsg_edt.inc');
fud_use('rev_fmt.inc');
fud_use('cookies.inc');
fud_use('users.inc');
fud_use('th.inc');
fud_use('th_adm.inc');
fud_use('fileio.inc');
fud_use('isearch.inc');
fud_use('iemail.inc');

$i = 0;
$postsToAutoApprove = 6;
$maxToApprove = 100;
$c = q("SELECT id FROM ".$GLOBALS['DBHOST_TBL_PREFIX']."msg WHERE apr=0");
while ($r = db_rowobj($c)) {
      $msg = fud_fetch_msg($r->id);
      $user = fud_fetch_user($msg->poster_id);
      if ($user->posted_msg_count >= $postsToAutoApprove) 
      {
		echo "Approved message ID# ". $r->id ." (" . $user->login . "): " . $msg->subject . "\n";
		fud_msg_edit::approve($r->id);
		$i++;
		if ($i>$maxToApprove)
			break;
	  }
}
if ($i>0)
	echo $i." messages approved.\n";
?>
Re: API hooks into post moderation? [message #160687 is a reply to message #160685] Tue, 13 October 2009 06:14 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3771
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
Excellent strategy. It would be great if you can document it on the wiki.
Re: API hooks into post moderation? [message #160689 is a reply to message #160687] Tue, 13 October 2009 20:27 Go to previous messageGo to next message
LADave is currently offline  LADave   United States
Messages: 19
Registered: July 2009
Location: Los Angeles
Karma: 0
Junior Member
Added a wiki page here: http://cvs.prohost.org/index.php/Auto_Post_Moderation

In order for this script to work it does require a small edit to the FUDAPI which isn't ideal. Not sure the best way to handle this requirement, I'll look into it over the next couple days and post here/on the wiki with the changes.
Re: API hooks into post moderation? [message #160692 is a reply to message #160689] Wed, 14 October 2009 05:43 Go to previous message
naudefj is currently offline  naudefj   South Africa
Messages: 3771
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
Looks good - thanks!
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: "News"
Next Topic: NNTP improvements
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 21 16:30:39 GMT 2024

Total time taken to generate the page: 0.02604 seconds