Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Coding in Vbulletin 3.x Tips
deathemperor's Avatar
deathemperor
Join Date: Jul 2003
Posts: 1,270

 

HOL
Show Printable Version Email this Page Subscription
deathemperor deathemperor is offline 02-13-2005, 10:00 PM

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.
Reply With Quote
  #2  
Old 02-14-2005, 09:56 PM
Guy G Guy G is offline
 
Join Date: Nov 2004
Posts: 250
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Nice... would be cool if you could extend it a little bit.
Reply With Quote
  #3  
Old 02-15-2005, 04:30 AM
deathemperor's Avatar
deathemperor deathemperor is offline
 
Join Date: Jul 2003
Location: HOL
Posts: 1,270
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for the kind word, Usergroup permission tips added.
Reply With Quote
  #4  
Old 02-15-2005, 08:57 AM
Guy G Guy G is offline
 
Join Date: Nov 2004
Posts: 250
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by deathemperor
Thanks for the kind word, Usergroup permission tips added.
Even better.... cool guide.
Reply With Quote
  #5  
Old 03-23-2005, 05:04 PM
husain's Avatar
husain husain is offline
 
Join Date: Feb 2005
Posts: 43
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Just what I was looking for. Thank you!
Reply With Quote
  #6  
Old 03-23-2005, 05:40 PM
Revan's Avatar
Revan Revan is offline
 
Join Date: Jan 2004
Location: Norway
Posts: 1,671
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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', 
Reply With Quote
  #7  
Old 03-23-2005, 06:04 PM
deathemperor's Avatar
deathemperor deathemperor is offline
 
Join Date: Jul 2003
Location: HOL
Posts: 1,270
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

fixed

thanks Revan
Reply With Quote
Reply


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 01:18 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.06107 seconds
  • Memory Usage 2,301KB
  • Queries Executed 20 (?)
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
  • (13)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (6)postbit
  • (7)postbit_onlinestatus
  • (7)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