vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=187)
-   -   Coding in Vbulletin 3.x Tips (https://vborg.vbsupport.ru/showthread.php?t=76297)

deathemperor 02-13-2005 10:00 PM

Coding in Vbulletin 3.x Tips
 
Quick 1st Tip:

Inserting new Vbulletin Settings by running a php script.

sample code:

PHP Code:

function setting_add($title$description$varname$value$defaultvalue$optioncode$displayorder,$grouptitle)
{
    global 
$DB_site;
    
$DB_site->query("INSERT INTO " TABLE_PREFIX "phrase (phraseid, languageid, varname, text, phrasetypeid) VALUES (NULL, '0', 'setting_" $varname "_title', '" addslashes($title) ."', '5000')");
    
$DB_site->query("INSERT INTO " TABLE_PREFIX "phrase (phraseid, languageid, varname, text, phrasetypeid) VALUES (NULL, '0',  'setting_" $varname "_desc', '" addslashes($description) ."', '5000')");
    
$DB_site->query("INSERT INTO " TABLE_PREFIX "setting (varname, grouptitle, value, defaultvalue, optioncode, displayorder, advanced, volatile) VALUES ('$varname', '$grouptitle', '$value', '$defaultvalue', '$optioncode', '$displayorder', '0', '0')");



To run this function use:

PHP Code:

setting_add('Setting title''Setting Descritption''varname''value''defaultvalue''typeofHTMLcode''displayorder','grouptitle'); 

Setting title: The tile of the setting.
Setting Descritption: The discription of the setting.
varname: varname is cancloseboard => $vboptions['cancloseboard'].
value: the default value.
defaultvalue: MySQL default value.
displayorder: the displayorder of the setting.
grouptitle: if you want to have a brand new setting, then use a different value with vbulletin default grouptitle, it will be a child setting if you use a existed value.

This is the most simple way to add a new setting AFAIK. just a 1st quick tips, there will be more, soon.


2nd Tip: Adding Usergroup Permission.


This is simple, you need to edit 2 file: init.php and admincp/usergroup.php

in init.php find:

PHP Code:

// ----------------------------------------------------------
// ###  END PLUGIN USERGROUP PERMISSIONS BITFIELDS HERE   ### 

ABOVE THIS, ADD:

PHP Code:

$_BITFIELD['usergroup']['permissionname'] = array(
    
'candothis'   => 1,
    
'candothat'   => 2,
    
'canviewthis'    => 4,
    
'canviewthat'        => 8,
    
'candownloadthis'   => 16,
    
'candownloadthat'  => 32
); 

This is for a absolute new permission, if you need a new permission for "permissionname" just add a new value like 'onemore' => 64, you can notice that the number get double.

in admincp/Usergroup.php find:

PHP Code:

print_table_header($vbphrase['forum_viewing_permissions']); 

Add above:

PHP Code:

    print_table_header('Permission Name');
    
print_yes_no_row('Can do This''usergroup[candothis]'$ug_bitfield['canviewsong']);
    
print_yes_no_row('Can do that''usergroup[candothat]'$ug_bitfield['candownload']);
    
print_yes_no_row('Can view this''usergroup[canviewthis]'$ug_bitfield['canviewthis']);
    
print_yes_no_row('Can view that''usergroup[canviewthat]'$ug_bitfield['canviewthat']);
    
print_yes_no_row('Can download this''usergroup[candownloadthis]'$ug_bitfield['candownloadthis']);
    
print_yes_no_row('Can download that''usergroup[candownloadthat]'$ug_bitfield['candownloadthat']);
    
print_table_break(); 

of course this can be change for the place of the permission if you know what to do.


to check for permission in php vb files, use:

PHP Code:

    if (!($permissions['permissionname'] & candothis))
    {
        
print_no_permission();
    } 

OR


PHP Code:

    if (!($permissions['permissionname'] & 1))
    {
        
print_no_permission();
    } 

Either of the way will check the usergroup permission that if you candothis or not, if not show the no permission page. Same for other, with candownloadthat you can use either candownloadthat or 32.


Some notes: If you use a totally new usergroup permission like the example above you will then need to run some queries:

this must be run:

[sql]ALTER TABLE `usergroup` ADD COLUMN `permissionname` int(10) unsigned NOT NULL DEFAULT 0[/sql]


This is optional to add default permission for some usergroup:

[sql]UPDATE usergroup SET jukeboxpermissions=63 WHERE usergroupid IN (5,6,7)[/sql]

this query set the admin, mod, smod usergroup to have full permission, the number 63 = 1 + 2 + 4 + 6 + 8 + 16 + 32, so if you want a usergroup to have full permission, just total all the number in that permission, and to disable any permission you extract that number. Admin will have candothis and candothat set to no if they're 60.


For a exist permission you need to run no queries
Simple place a new value with the correct number below the vb based permission.

Example:

PHP Code:

$_BITFIELD['usergroup']['calendarpermissions'] = array(
    
'canviewcalendar'    => 1,
    
'canpostevent'       => 2,
    
'caneditevent'       => 4,
    
'candeleteevent'     => 8,
    
'canviewothersevent' => 16,
        
'candoeverything' => 32
); 

in usergroup permission find

PHP Code:

        print_yes_no_row($vbphrase['can_view_others_events'], 'usergroup[canviewothersevent]'$ug_bitfield['canviewothersevent']); 


ADD BELOW

PHP Code:

    print_yes_no_row('Can Do anything''usergroup[cansearchevent]'$ug_bitfield['cansearchevent']); 

The above example add a new permission: candoeverything in calendarpermissions

I hope I am not just trying to be complex.

Next: Forum permission.

Guy G 02-14-2005 09:56 PM

Nice... would be cool if you could extend it a little bit.

deathemperor 02-15-2005 04:30 AM

Thanks for the kind word, Usergroup permission tips added.

Guy G 02-15-2005 08:57 AM

Quote:

Originally Posted by deathemperor
Thanks for the kind word, Usergroup permission tips added.

Even better.... cool guide.

husain 03-23-2005 05:04 PM

Just what I was looking for. Thank you!

Revan 03-23-2005 05:40 PM

Quote:

Originally Posted by deathemperor
PHP Code:

    print_table_header('Permission Name');
    
print_yes_no_row('Can do This''usergroup[candothis]'$ug_bitfield['canviewsong']);
    
print_yes_no_row('Can do that''usergroup[candothat]'$ug_bitfield['candownload']);
    
print_yes_no_row('Can view this''usergroup[canviewthis]'$ug_bitfield['canviewthis']);
    
print_yes_no_row('Can view that''usergroup[canviewthat]'$ug_bitfield['canviewthat']);
    
print_yes_no_row('Can download this, 'usergroup[candownloadthis]', $ug_bitfield['candownloadthis']);
    print_yes_no_row('
Can download that', 'usergroup[candownloadthat]', $ug_bitfield['candownloadthat']);
    print_table_break(); 


Syntax error :)
PHP Code:

'Can download this,
// should be
'
Can download this', 


deathemperor 03-23-2005 06:04 PM

fixed

thanks Revan


All times are GMT. The time now is 06:51 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.04041 seconds
  • Memory Usage 1,778KB
  • 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
  • (13)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)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