Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
  #1  
Old 08-08-2009, 02:54 AM
neverstop neverstop is offline
 
Join Date: Jan 2007
Posts: 170
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default infraction.php plugin

Hi,

I am looking to add a plugin in infraction.php. What I want to do is when an infraction is given to alter the 'credits' column (it is a custom column) in the user table of the user that is receiving the infraction. For example: user foo receives an infraction, and when he receives this infraction the plugin with do something like:
PHP Code:
SET credits credits-
Now I have scoured the infraction.php file and I cannot find a where I could add this. I am not a programmer so please bear with me. Is there an appropriate hook where this would work?

Thanks in advance,
Ian

EDIT: tried to post infraction.php in [php] tags but it made my msg too long to post.
Reply With Quote
  #2  
Old 08-08-2009, 04:33 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm not real familiar with the infraction system, but I think you would add it using the datamanager somewhere in the do=update area of that page. If you aren't a programmer, it may be a bit more involved than you though. The best way to do this is with the datamanager. But, first you need to add the field you added to the database to the validfields for the user datamanager - in class_dm_user.php. Then you would set the info for that field using the datamanager (maybe using the hookinfraction_update_start ?). There are articles on the datamanager that you may want to check out.
Reply With Quote
  #3  
Old 08-08-2009, 05:15 AM
neverstop neverstop is offline
 
Join Date: Jan 2007
Posts: 170
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi Lynne, thanks for your reply.

Unfortunately serialized data is indeed over my head. Is there anyway i could just add a query in do=update at infraction_verify_permissions maybe? Like: UPDATE user SET credits = credits-1 WHERE userid = *the poster* Sorry if this is a stupid question, I can plug my way around VB sometimes but I am def not a programmer.

If not I will prob have to just post in the paid services forum

--------------- Added [DATE]1249744761[/DATE] at [TIME]1249744761[/TIME] ---------------

Ok so I have this kind of working. I added this plugin at infraction_update_complete:

PHP Code:
$db->query_write("UPDATE " TABLE_PREFIX "user SET credits = credits-1 WHERE userid = $userinfo[userid]"); 
And it works like I want it to, it takes away one "credit" from the poster receiving the infraction.

Now to expland on it a bit I wanted to wrap the query in an if condition: if the post is in forumid x, y or z then take away the point, if in any other forum do nothing.

Can someone point me in the right direction to make this happen?
Reply With Quote
  #4  
Old 08-08-2009, 03:30 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Have you tried $foruminfo['forumid']?
PHP Code:
if (in_array($foruminfo['forumid'],array(x,y)))
{
do 
stuff

If that doesn't work, try one of these:
Code:
$forumid
$forum['forumid']
$foruminfo['forumid']
$thread['forumid']
$threadinfo['forumid']
$GLOBALS['forumid']
Reply With Quote
  #5  
Old 08-08-2009, 07:41 PM
neverstop neverstop is offline
 
Join Date: Jan 2007
Posts: 170
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I saw $threadinfo['forumid'] first in infraction.php first so tried it and low and behold it worked!

Thanks Lynne! You're always so helpful!
Reply With Quote
  #6  
Old 08-10-2009, 03:24 AM
neverstop neverstop is offline
 
Join Date: Jan 2007
Posts: 170
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

OK how about this one... I want to disable the PM users receive if they get an infraction in forums x, y and z

Here is the chunk of code I think that handles the PM:

PHP Code:
    if ($show['pm'])
    {
        if (empty(
$vbulletin->GPC['message']) AND $vbulletin->options['uimessage'] AND !$nocontact)
        {
            
$errors[] = 'nomessagetouser';
        }

        
$pm['message'] =& $vbulletin->GPC['message'];
        
$pm['parseurl'] =& $vbulletin->GPC['parseurl'];
        
$pm['savecopy'] =& $vbulletin->GPC['savecopy'];
        
$pm['signature'] =& $vbulletin->GPC['signature'];
        
$pm['disablesmilies'] =& $vbulletin->GPC['disablesmilies'];
        
$pm['receipt'] =& $vbulletin->GPC['receipt'];
        
$pm['iconid'] =& $vbulletin->GPC['iconid'];

        
// *************************************************************
        // PROCESS THE MESSAGE AND INSERT IT INTO THE DATABASE

        
if ($vbulletin->userinfo['pmtotal'] >= $permissions['pmquota'])
        {
            
$pm['savecopy'] = false;
        }

        
$infraction = array(
            
'username' => unhtmlspecialchars($userinfo['username']),
            
'reason'   => ($infractionlevel['infractionlevelid']) ? fetch_phrase('infractionlevel' $infractionlevel['infractionlevelid'] . '_title''infractionlevel'''truetrue$userinfo['languageid']) : $vbulletin->GPC['customreason'],
            
'message'  => fetch_censored_text($pm['message']),
            
'points'   => $infdata->fetch_field('points')
        );

        
$emailsubphrase = ($infraction['points'] > 0) ? 'infraction_received' 'warning_received';

        
// if we have a specific post we can link to, link to it in the PM
        
if (!empty($postinfo))
        {
            if (
$vbulletin->options['privallowbbcode'])
            {
                
$infraction['post'] = '[post]' $postinfo['postid'] . '[/post]';
            }
            else
            {
                
$infraction['post'] = $vbulletin->options['bburl'] . "/showthread.php?p=$postinfo[postid]#post$postinfo[postid]";
            }
            
$emailphrase $emailsubphrase '_post';
            
$infraction['pagetext'] =& $postinfo['pagetext'];
        }
        else
        {
            
$infraction['post'] = '';
            
$emailphrase $emailsubphrase '_profile';
        }

        eval(
fetch_email_phrases($emailphrase$userinfo['languageid'], $emailsubphrase));

        if (empty(
$message) OR empty($subject))
        {
            
$errors[] = array('problem_with_x_phrase'$emailphrase);
        }

        
// create the DM to do error checking and insert the new PM
        
$pmdm =& datamanager_init('PM'$vbulletinERRTYPE_ARRAY);

        if (!empty(
$errors))
        {
            foreach (
$errors AS $error)
            {
                
$pmdm->error($error);
            }
        }

        
$pmdm->set_info('savecopy',   $pm['savecopy']);
        
$pmdm->set_info('receipt',    $pm['receipt']);
        
$pmdm->set_info('cantrackpm'$cantrackpm);
        
$pmdm->set_info('is_automated'true); // implies overridequota
        
$pmdm->set('fromuserid'$vbulletin->userinfo['userid']);
        
$pmdm->set('fromusername'$vbulletin->userinfo['username']);
        
$pmdm->setr('title'$subject);
        
$pmdm->set_recipients(unhtmlspecialchars($userinfo['username']), $permissions);
        
$pmdm->setr('message'$message);
        
$pmdm->setr('iconid'$pm['iconid']);
        
$pmdm->set('dateline'TIMENOW);
        
$pmdm->setr('showsignature'$pm['signature']);
        
$pmdm->set('allowsmilie'$pm['disablesmilies'] ? 1);

        (
$hook vBulletinHook::fetch_hook('private_insertpm_process')) ? eval($hook) : false;

        
$pmdm->pre_save();

        if (!empty(
$pmdm->errors))
        {
            
define('PMPREVIEW'1);
            
$preview construct_errors($pmdm->errors); // this will take the preview's place
        
}
        else if (
$vbulletin->GPC['preview'] != '')
        {
            
define('PMPREVIEW'1);
            
$old_finfo $foruminfo;
            
$foruminfo = array('forumid' => 'privatemessage');
            
$preview process_post_preview($pm);
            
$foruminfo $old_finfo;
        }
        else
        {
            
// everything's good!
            
$pmdm->save();
            (
$hook vBulletinHook::fetch_hook('private_insertpm_complete')) ? eval($hook) : false;

            
$postmessage =& $vbulletin->GPC['message'];
        }
        unset(
$pmdm);
    } 

Now isn't there a way I can add a plugin at private_insertpm_complete to just completely disable the PM for those three forums?
Reply With Quote
  #7  
Old 08-10-2009, 03:28 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think you would want to try to use a hook before that part of the code and just set $show['pm'] to false (so it skips that section) if it is in those forums. At least, that is what I would try to do first.
Reply With Quote
  #8  
Old 08-10-2009, 03:53 AM
neverstop neverstop is offline
 
Join Date: Jan 2007
Posts: 170
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
if (in_array($threadinfo['forumid'],array(33,29,34,37)))
{
$show['pm'] = false;

So I added that plugin to infraction_update_start which is near the start of if ($_POST['do'] == 'update') and it didnt work. I'm sure I am doing something wrong though. This is the chunk of code above the $show['pm'] chunk.

PHP Code:
if ($_POST['do'] == 'update')
{
    
$vbulletin->input->clean_array_gpc('p', array(
        
'infractionlevelid' => TYPE_UINT,
        
'warning'           => TYPE_ARRAY_BOOL,
        
'note'              => TYPE_STR,
        
'message'           => TYPE_STR,
        
'iconid'            => TYPE_UINT,
        
'wysiwyg'           => TYPE_BOOL,
        
'parseurl'          => TYPE_BOOL,
        
'signature'         => TYPE_BOOL,
        
'disablesmilies'    => TYPE_BOOL,
        
'receipt'           => TYPE_BOOL,
        
'preview'           => TYPE_STR,
        
'savecopy'          => TYPE_BOOL,
        
'expires'           => TYPE_UINT,
        
'points'            => TYPE_STR// leave as STR
        
'period'            => TYPE_NOHTML,
        
'customreason'      => TYPE_STR,
        
'banreason'         => TYPE_NOHTML,
    ));

    (
$hook vBulletinHook::fetch_hook('infraction_update_start')) ? eval($hook) : false;

    
$errors = array();
    
$infdata =& datamanager_init('Infraction'$vbulletinERRTYPE_STANDARD);
    
$infdata->setr_info('warning'$vbulletin->GPC['warning']["{$vbulletin->GPC[infractionlevelid]}"]);
    
$infdata->setr_info('postinfo'$postinfo);
    
$infdata->setr_info('userinfo'$userinfo);
    
$infdata->setr_info('threadinfo'$threadinfo);
    
$infdata->set_info('banreason'$vbulletin->GPC['banreason']);

    if (
$vbulletin->GPC['points'] !== '')
    {
        
$vbulletin->GPC['points'] = intval($vbulletin->GPC['points']);
    }

    if (!
$vbulletin->GPC['infractionlevelid'] AND $vbulletin->userinfo['permissions']['genericpermissions'] & $vbulletin->bf_ugp_genericpermissions['cangivearbinfraction'])
    {    
// custom infraction
        
if (empty($vbulletin->GPC['customreason']) OR (!$vbulletin->GPC['expires'] AND $vbulletin->GPC['period'] != 'N'))
        {
            if (empty(
$vbulletin->GPC['customreason']))
            {
                
$errors[] = 'invalid_custom_infraction_description';
            }
            if (!
$vbulletin->GPC['expires'] AND $vbulletin->GPC['period'] != 'N')
            {
                
$errors[] = 'invalid_timeframe';
            }
        }
        else
        {
            switch(
$vbulletin->GPC['period'])
            {
                case 
'D'$expires mktime(date('H'), date('i'), date('s'), date('m'), date('d') + $vbulletin->GPC['expires'], date('y')); break;
                case 
'M'$expires mktime(date('H'), date('i'), date('s'), date('m') + $vbulletin->GPC['expires'], date('d'), date('y')); break;
                case 
'N'$expires 0; break;
                case 
'H':
                default:
                    
$expires mktime(date('H') + $vbulletin->GPC['expires'], date('i'), date('s'), date('m'), date('d'), date('y')); break;
            }
            
$infdata->set('expires'$expires);
            
$infdata->set('points'$vbulletin->GPC['points']);
            
$infdata->set('customreason'$vbulletin->GPC['customreason']);
        }

        if (
$vbulletin->GPC['points'] AND empty($vbulletin->GPC['banreason']) AND ($infractionban OR ($minimumpointsban AND $vbulletin->GPC['points'] + $userinfo['ipoints'] >= $minimumpointsban)))
        {
            
$errors[] = 'invalid_banreason';
        }
    }
    else
    {
        
$infractionlevel verify_id('infractionlevel'$vbulletin->GPC['infractionlevelid'], 11);
        if (
$infractionlevel['extend'])
        {
            if (isset(
$infcache["$infractionlevel[infractionlevelid]"]['expires']))
            {
                if (
$infcache["$infractionlevel[infractionlevelid]"]['expires'] == 0)
                {
                    
$infdata->set('expires'0);
                }
                else if ((
$expiretime $infcache["$infractionlevel[infractionlevelid]"]['expires'] - TIMENOW) > 0)
                {
                    switch(
$infractionlevel['period'])
                    {
                        case 
'D'$expires $expiretime mktime(date('H'), date('i'), date('s'), date('m'), date('d') + $infractionlevel['expires'], date('y')); break;
                        case 
'M'$expires $expiretime mktime(date('H'), date('i'), date('s'), date('m') + $infractionlevel['expires'], date('d'), date('y')); break;
                        case 
'N'$expires 0; break;
                        case 
'H':
                        default:
                            
$expires $expiretime mktime(date('H') + $infractionlevel['expires'], date('i'), date('s'), date('m'), date('d'), date('y')); break;
                    }

                    
$infdata->set('expires'$expires);
                }
            }
        }

        if (!
$vbulletin->GPC['warning']["{$vbulletin->GPC[infractionlevelid]}"] AND empty($vbulletin->GPC['banreason']) AND ($infractionban OR ($minimumpointsban AND $infractionlevel['points'] + $userinfo['ipoints'] >= $minimumpointsban)))
        {
            
$errors[] = 'invalid_banreason';
        }

        
$infdata->setr_info('infractionlevel'$infractionlevel);
        
$infdata->set('infractionlevelid'$vbulletin->GPC['infractionlevelid']);
    }

    
$banusergroupid 0;
    
$liftdate 0;
    if (!empty(
$banlist) AND $points $infdata->fetch_field('points'))
    {
        
// Look for the longest ban that applies
        
foreach ($banlist AS $ban)
        {
            if ((
$ban['method'] == 'infractions' AND $ban['amount'] == $totalinfractions 1) OR ($ban['method'] == 'points' AND $ban['amount'] <= $userinfo['ipoints'] + $points))
            {
                if (
$ban['liftdate'] == 0)
                {
                    
$liftdate 0;
                    
$banusergroupid $ban['banusergroupid'];
                    break;
                }
                else if (
$liftdate <= $ban['liftdate'])
                {
                    
$liftdate $ban['liftdate'];
                    
$banusergroupid $ban['banusergroupid'];
                }
            }
        }
        if (
$banusergroupid AND !$liftdate)
        {
            
$nocontact true;
        }
    }

    
$infdata->set('whoadded'$vbulletin->userinfo['userid']);
    
$infdata->set('postid'$postinfo['postid']);
    
$infdata->set('note'fetch_censored_text($vbulletin->GPC['note']));

    
// include useful functions
    
require_once(DIR '/includes/functions_newpost.php');
    require_once(
DIR '/includes/functions_misc.php');

    
// unwysiwygify the incoming data
    
if ($vbulletin->GPC['wysiwyg'])
    {
        require_once(
DIR '/includes/functions_wysiwyg.php');
        
$vbulletin->GPC['message'] = convert_wysiwyg_html_to_bbcode($vbulletin->GPC['message'], $vbulletin->options['privallowhtml']);
    }

    
// parse URLs in message text
    
if ($vbulletin->options['privallowbbcode'] AND $vbulletin->GPC['parseurl'])
    {
        
$vbulletin->GPC['message'] = convert_url_to_bbcode($vbulletin->GPC['message']);
    }

    if (
$show['pm'])
    {
        if (empty(
$vbulletin->GPC['message']) AND $vbulletin->options['uimessage'] AND !$nocontact)
        {
            
$errors[] = 'nomessagetouser';
        }

        
$pm['message'] =& $vbulletin->GPC['message'];
        
$pm['parseurl'] =& $vbulletin->GPC['parseurl'];
        
$pm['savecopy'] =& $vbulletin->GPC['savecopy'];
        
$pm['signature'] =& $vbulletin->GPC['signature'];
        
$pm['disablesmilies'] =& $vbulletin->GPC['disablesmilies'];
        
$pm['receipt'] =& $vbulletin->GPC['receipt'];
        
$pm['iconid'] =& $vbulletin->GPC['iconid'];

        
// *************************************************************
        // PROCESS THE MESSAGE AND INSERT IT INTO THE DATABASE 
Reply With Quote
  #9  
Old 08-10-2009, 04:02 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Did you try simply putting $show['pm'] = false; as the plugin to see if changing that variable would even work there? It could be that it is set farther down in the code and gets overwritten prior to it being used in which case you either need to manually modify the code or come up with another way of doing it.
Reply With Quote
Reply

Thread Tools
Display Modes

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:50 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.04580 seconds
  • Memory Usage 2,421KB
  • Queries Executed 11 (?)
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
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (6)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (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_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • 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
  • 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