vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   infraction.php plugin (https://vborg.vbsupport.ru/showthread.php?t=220435)

neverstop 08-08-2009 01:54 AM

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.

Lynne 08-08-2009 03:33 AM

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.

neverstop 08-08-2009 04:15 AM

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?

Lynne 08-08-2009 02:30 PM

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']


neverstop 08-08-2009 06:41 PM

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!

neverstop 08-10-2009 02:24 AM

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?

Lynne 08-10-2009 02:28 AM

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.

neverstop 08-10-2009 02:53 AM

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 


Lynne 08-10-2009 03:02 AM

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.


All times are GMT. The time now is 04:15 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02531 seconds
  • Memory Usage 1,940KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (6)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete