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

Reply
 
Thread Tools
Adding user options in usercp for mod's [Not in the manual]
almannai
Join Date: Oct 2007
Posts: 889

 

Show Printable Version Email this Page Subscription
almannai almannai is offline 01-17-2010, 10:00 PM

Hi,

This article is a part of "Not in the manual" series of articles that I hope will wrtie from time to time.

Ok .. So if you have been programing in Vb3.x you are used to adding changes in the user cp by adding more options to one of the Login, Messaging, Thread View, Date/Time or the "Other" Section of the $customfields array.

For example adding a textbox option to the "other" section in the usercp was as simple as adding the following plugin to the "profile_complete" hook


PHP Code:
//build our customfield
    
$profilefieldname 'my_profilefieldname';
    
$profilefield['description'] = 'This is a description of my_profilefieldname';
    
$profilefield['size'] = 5;
    
$profilefield['maxlength'] = 5;
    eval(
'$tempcustom = "' fetch_template('userfield_textbox') . '";');
 
//add our customfield
    
$customfields['other'] .= $tempcustom


To explain the above code: First we are setting our profilefield variable like name, textbox size, description etc. We write the system 'userfield_textbox' in our variable tempcustom. Then we add that variable to the other section of the customfields array.

Well that is a straightforward coding and maybe that is because we are used to it. In vb4 it is little bit more extra coding. First off all the customfields array is not there, so we have to insert our changes by replacing the "other" section of the "modifyoptions" template with the "other"section plus our custom code. Plus some other minor changes and here is same code but for vb4


PHP Code:
//build our customfield
    
$profilefieldname 'my_profilefieldname';
    
$profilefield['description'] = 'This is a description of my_profilefieldname';
    
$profilefield['profilefieldid']=$profilefieldname;
    
$profilefield['currentvalue'] = $vbulletin->userinfo['my_profilefieldname'];
    
$profilefield['maxlength'] = 5;
    
$templater vB_Template::create('userfield_textbox'); 
    
$templater->register('profilefieldname'$profilefieldname);  
    
$templater->register('profilefield'$profilefield);  
    
$tempcustom=$templater->render();
 
//add our customfield
    
$tempcustom "\n" .'  '.$tempcustom.'  ';        
    
$other_search  '\' ' '. $customfields['.'\''.'other'.'\''.'] . \''
    
$other_replace '\' ' '. $customfields['.'\''.'other'.'\''.'] . \''.$tempcustom;               
    
$vbulletin->templatecache['modifyoptions'] = str_replace($other_search$other_replace$vbulletin->templatecache['modifyoptions']); 

The first part of the code is setting our profilefield variables then saving the 'userfield_textbox' template to our $tempcustom using vb4 way. That is by using
vB_Template class and registering 'profilefieldname' and 'profilefield' then rendering it.

The second part we search for $customfields['other'] and replace by $customfields['other'] itself plus the $tempcustom. Don't get confused by the too many commas in the code I made it like this to make it easier [I think] to read. Actualy here how the other section part looks in the 'modifyoptions' template ' . $customfields['other'] . '

In case you want to add Dropdownlist see the following example

PHP Code:
    $profilefieldname 'my_profilefieldname';
    
$profilefield['title'] = $vbphrase['my_profilefield_title'];
    
$profilefield['description'] = $vbphrase['my_profilefield_description'];
    
$profilefield['profilefieldid']=$profilefieldname;
    
$profilefield['currentvalue'] = $vbulletin->userinfo['my_profilefieldname'];

    
$selectbits '';
    
$options = array(
        
'option1'    => $vbphrase['option_1'],
        
'option2'    => $vbphrase['option_2'],
    );
    
    
$templater vB_Template::create('userfield_select_option'); 
    foreach(
$options AS $key=>$val) {
        
$selected $vbulletin->userinfo['my_profilefieldname'] == $key 'selected="selected"' '';
        
$templater->register('selected'$selected);  
        
$templater->register('key'$key);  
        
$templater->register('val'$val);  
        
$selectbits.=$templater->render();
    }
    
    
$templater vB_Template::create('userfield_select'); 
    
$templater->register('profilefieldname'$profilefieldname);  
    
$templater->register('profilefield'$profilefield);  
    
$templater->register('selectbits'$selectbits);  
    
$tempcustom.=$templater->render(); 


I will not go farther to explain this code cause I'm sure you will figure it out. Just small hint though; in this code we used $vbphrase to save our title and description as this is the proper way of doing it if you want to make more professional way of building mod's.

Happy coding
Reply With Quote
  #2  
Old 01-18-2010, 10:34 PM
MARCO1's Avatar
MARCO1 MARCO1 is offline
 
Join Date: Jun 2008
Posts: 872
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Very Nice, Thanks.
Reply With Quote
  #3  
Old 01-19-2010, 08:31 AM
almannai almannai is offline
 
Join Date: Oct 2007
Posts: 889
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by MARCO1 View Post
Very Nice, Thanks.


Nice seeing you here MARCO1
Reply With Quote
  #4  
Old 01-20-2010, 05:34 PM
MARCO1's Avatar
MARCO1 MARCO1 is offline
 
Join Date: Jun 2008
Posts: 872
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by almannai View Post
Nice seeing you here MARCO1
That's my home my friend
Reply With Quote
  #5  
Old 01-22-2010, 04:50 PM
almannai almannai is offline
 
Join Date: Oct 2007
Posts: 889
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by MARCO1 View Post
That's my home my friend
I know...

What do you think about my new mod that is the everywhere sidebar?
Reply With Quote
  #6  
Old 01-22-2010, 05:26 PM
MARCO1's Avatar
MARCO1 MARCO1 is offline
 
Join Date: Jun 2008
Posts: 872
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by almannai View Post
I know...

What do you think about my new mod that is the everywhere sidebar?
Check this : https://vborg.vbsupport.ru/showpost....17&postcount=4
Reply With Quote
  #7  
Old 01-23-2010, 06:14 AM
almannai almannai is offline
 
Join Date: Oct 2007
Posts: 889
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by MARCO1 View Post
Thank you for your continuous support
Reply With Quote
  #8  
Old 04-14-2010, 08:15 PM
ARP ARP is offline
 
Join Date: Mar 2009
Posts: 64
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hello, Can you make a simple Mod of this plugins to add the options ? I can't get this working
Maybe I doing something wrong
Reply With Quote
  #9  
Old 04-15-2010, 06:55 AM
almannai almannai is offline
 
Join Date: Oct 2007
Posts: 889
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by ARP View Post
Hello, Can you make a simple Mod of this plugins to add the options ? I can't get this working
Maybe I doing something wrong
I've used same techniques in one of my mods

check it out here
https://vborg.vbsupport.ru/showthread.php?t=232639
Reply With Quote
  #10  
Old 04-16-2010, 11:25 PM
ARP ARP is offline
 
Join Date: Mar 2009
Posts: 64
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Check your PM's
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 10:00 AM.


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.05227 seconds
  • Memory Usage 2,322KB
  • Queries Executed 23 (?)
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
  • (3)bbcode_php
  • (6)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (10)post_thanks_box
  • (1)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (10)post_thanks_postbit_info
  • (9)postbit
  • (10)postbit_onlinestatus
  • (10)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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • 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