Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 07-30-2009, 03:42 PM
Charlie2009 Charlie2009 is offline
 
Join Date: Oct 2008
Posts: 8
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Code Review

Hi, I have been working on an internal project for my forum for a little while now, and have just about finished up. However, before I put all of it live I was hoping to have a few pros take a look and let me know if I borked anything up. It all works like it is supposed to work, but that doesn't mean it will work effciently on a high volume server.

The Project Goals:
  1. Create a usergroup that will allow non-moderators to move spam into the moderation queue
  2. Modify the Report system to show that a message has been moved to the moderation queue

What has been done:
I have completed the first task. I used group memberships and the built-in promotion routine to assign users to a new group based on time, posts and rep. If the members are present in the group I display a check box below the standard Report screen.

I modified report.php with the following block of code
PHP Code:
//========== SPAM SQUAD ==========
$bSpamReport false;
$bError false;
$strAddReason '';
if(
$_POST['chkSpam'] == '1')
{
    require_once(
DIR '/includes/functions_databuild.php');
    require_once(
DIR '/includes/functions.php');
    
    
//Get Post Info
    
if (!$postinfo AND !$postinfo fetch_postinfo($postid))
    {
        
$bError true;
    }
    
    
//Get Thread Info
    
if (!$threadinfo AND !$threadinfo fetch_threadinfo($postinfo['threadid']))
    {
        
$bError true;
    }
    
    if(!
$bError)
    {
        
//Set a Spam Reported Flag and Modify the Message
        
$bSpamReport true;
        
$strAddReason '
        
        [b]This post has been sent to the moderation queue because it was flagged as SPAM[/b]'
;
        
        
//Unapprove the post and Rebuilt the Forum Information
        
unapprove_post($postid);    
        
build_forum_counters($threadinfo[forumid]);
    }
}
//========== SPAM SQUAD ========== 
It checks for the existence of the checkbox, and then automatically appends some text to the "reason". Assuming that appropriate information can be found about the post, thread and forum; I unapprove the post (which may be the entire thread) and rebuild the forum counters.

Now for part two.

Part two required that I make one more change to report.php. I added a boolean parameter to let the reportitem class know that a spam report was made.
PHP Code:
$reportobj->do_report($vbulletin->GPC['reason'] . $strAddReason$postinfo$bSpamReport); 
I had to make a few modifications to the class_reportitem.php

I first change the function structure. I set a default value as to not upset any other calls that wouldn't know about the new boolean parameter.
PHP Code:
function do_report($reason, &$iteminfo$bSpamReport false
Here is where I get a little fuzzy about things.

I replaced:
PHP Code:
$threadman->set('title'$subject); 
with:
PHP Code:
if($bSpamReport)
{
$threadman->set('title'$subject ' SPAM REPORTED!!!!!');
$threadman->set('iconid'4);
}
else
{
$threadman->set('title'$subject);

That will take care of changing the thread title and icon if the first report of the spam post was made by someone with the ability to flag it as spam. Since the majority of our members cannot do this, the first report may not be from one of those members.

Here are the changes that deal with a post in an existing report:

replaced:
PHP Code:
$postman->set('title'$subject); 
with:
PHP Code:
//SPAM SQUAD ++++++++
if($bSpamReport)
{
//Get Datamanager for existing thread
$dataman =& datamanager_init('Thread'$this->registryERRTYPE_SILENT'threadpost'); 

//Set exiting data
$dataman->set_existing(&$rpthreadinfo);
$dataman->set('title'$subject ' SPAM REPORTED!!!!!');
$dataman->set('iconid'4);

$dataman->pre_save(); 
if (
count($dataman->errors) == 0

$dataman->save();  
}  

unset(
$dataman);

//Alter information for THIS post
$postman->set('title'$subject ' SPAM REPORTED!!!!!');
$postman->set('iconid'4);
}
else
{
$postman->set('title'$subject);
}
//++++++++ SPAM SQUAD 
This will make the appropriate changes to the post as well as the existing thread. This is the first time I created a datamanager instead of just altering one that was prexisting.

I apologize if this isn't the proper way to go about this, but I am still learning. Any tips or suggestions (or critisims) would be appreciated. There is some front end security measures put in place that only allow members to to "flag as spam" when the author has 5 posts or less. However, I fear this could easily be defeated with anything that intercepts the http stream. All you would have to do is know the variable name and value. I suppose the user doing it would get caught soon thereafter, but still a concern. Would the standard procedure be to just do a second check of credentials on the server side?
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:22 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04709 seconds
  • Memory Usage 2,338KB
  • Queries Executed 12 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (7)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)showthread_list
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_threadedmode.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids_threaded
  • showthread_threaded_construct_link
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete