Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > vBulletin 3.0 > vBulletin 3.0 Full Releases

Reply
 
Thread Tools
User setable default BB code formatting for each post Details »»
User setable default BB code formatting for each post
Version: 1.00, by Darth Cow Darth Cow is offline
Developer Last Online: Feb 2008 Show Printable Version Email this Page

Version: 3.0.5 Rating:
Released: 01-10-2005 Last Update: Never Installs: 9
 
No support by the author.

Allow your users to set default formatting for each of their newpostswith the familiar BB code via the options page in their controlpanel.

This requires one file edit and adding a custom profile field.

There is also the option to allow users to choose not to seeautomaticbb code. This requires another file edit and custom profilefield. (Theaddition of this option is the only change between versions1.0 and1.1.)

First, open up your admincp and find the "User Profile Fields" section in the sidebar and click "Add New User Profile Field".

Click "Continue" with the default Single-Line Text Field option selected. Set the following options:

Title: Automatic BB Code
Description: Enter the opening portion of BB code tags that youwouldlike format all of your posts (e.g. [color=red]). Multiple tagsarefine, but no text outside of the tags. Only single quotation marks(nodouble quotation marks) can be used in this field.
Private Field: Yes
Field Searchable on Members List: No
Show on Members List: No
Regular Expression:
Code:
^(\[(b|i|u|color|font|size|left|center|right)(\=\'?(\#\w+\s*)+\'?)?\])*$
Display Page: Options: Other

You can change the BB codes in the regular expression to any othersyouhave added on your forum or customize them in any way you choose.Justkeep the same formatting with the | character dividing each tag.

Once you've customized this page to your satisfaction (every other option can be left as the default), click Add.

Now, note the "Name" field for your new field in the User Profile Field Manager. It should be of the format "field123".

You'll need to edit includes/functions_newpost.php. Find the following line:

PHP Code:
          // ### PREPARE OPTIONS AND CHECK VALID INPUT ###
          
$post['parseurl'] = intval($post['parseurl']);
          
$post['email'] = intval($post['email']);
          
$post['signature'] = intval($post['signature']);
          
$post['preview'] = iif($post['preview'], 10);
          
$post['disablesmilies'] = intval($post['disablesmilies']);
          
$post['enablesmilies'] = iif($post['disablesmilies'], 01);
          
$post['rating'] = intval($post['rating']);
          
$post['iconid'] = intval($post['iconid']);
          
$post['message'] = trim($post['message']);
          
$post['title'] = trim(preg_replace('/&#0*32;/'' '$post['title']));
          
$post['emailupdate'] = intval($post['emailupdate']);
          
$post['folderid'] = intval($post['folderid']);
          
$post['username'] = trim($post['username']);
          
$post['posthash'] = trim($post['posthash']);
          
$post['poststarttime'] = trim($post['poststarttime']); 
AFTER it add,

PHP Code:
      // Darth Cow's auto BB code hack
          
$auto_bb_opentag $bbuserinfo['field123'];
      
    
preg_match_all("/\[(\w+)(\=\"?\'?(\w+\s*)+\"?\'?)?\]/",$auto_bb_opentag$auto_bb_tagsPREG_SET_ORDER);
          
$auto_bb_closetags array_reverse($auto_bb_tags);
          
$auto_bb_closetag "";
          foreach (
$auto_bb_closetags as $auto_bb_tag)
          {
              
$auto_bb_closetag .= "[/" $auto_bb_tag[1] . "]";
          }
      
          
$post['message'] = $auto_bb_opentag $post['message'] . $auto_bb_closetag;
      
// End hack 
Be sure to edit field123 in the first line to the name of the field you noted above.

Save and upload the file. That's it!

-------------------------------

You can also choice to allow users the option of seeing no automatic bb code. Keep in mind this part will not work if you have enabled caching of posts(vBulletinOptions > Server Settings and Optimization Options >Cached PostsLifespan should equal 0). If you need to cache posts forperformancereasons, then you're out of luck. (There's no technical wayaround this,without saving this information elsewhere in the database,since cachedposts saved parsed BB code for all users--it can't bechanged on anindividual basis as this hack does.)

To do so, add a "Single-Selection Menu" custom profile field with the following options:

Title: Show Automatic BB Code
Description: Set this to "No" to view the forums without anyone else's automatic BB code.
Options:
Quote:
Yes
No
Private Field: Yes
Field Searchable on Members List: No
Show on Members List: No
Display Page: Options: Thread Viewing

Do not change the options from Yes and No (exactly) or the removalofautomatic BB code will not work. You can customize the rest oftheoptions as you choice. Once you're done, hit add it and again notethename of the profile field (it's in the form field123).

Open up /includes/functions_bbcodeparse.php. Find the following line:

PHP Code:
    // ********************* PARSE BBCODE TAGS *************************** 
ABOVE it add:

PHP Code:
// Darth Cow's auto BB code hack
        
$show_auto_bbcode $bbuserinfo['field123'];
    
        global 
$stopsaveparsed$parsed_postcache;
    
        if ((
$stopsaveparsed OR $parsed_postcache['skip'] == true) AND $show_auto_bbcode == "No")
        {
            
$outer_bbcode_stripped2 $bbcode;
            while (
true)
            {
        
$outer_bbcode_stripped=preg_replace("/^\[(\w+)(\=\'?(\w+\s*)+\'?)?\](?!.*\[\/\\1\].+)(.+)\[\/\\1\]$/si","\\4",$outer_bbcode_stripped2);
    
             if (
$outer_bbcode_stripped2 == $outer_bbcode_stripped)
                {
                
$bbcode$outer_bbcode_stripped;
                    break;
                }
                else
                {
                
$outer_bbcode_stripped2=$outer_bbcode_stripped;
                }
            }
        }
    
// End hack 
Once again, be sure to edit field123 in the first line to the nameofthe field you noted for the "Show Automatic BB Code" option.

Save and upload the file.

Version 1.2: RegExp fix should allow hex values for colors.

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #12  
Old 02-02-2005, 02:42 AM
carpefile carpefile is offline
 
Join Date: Jul 2004
Posts: 52
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Works great ! Thanx! My users love it. Any way to limit this to certain usergroups?
Reply With Quote
  #13  
Old 02-07-2005, 10:34 PM
skinny skinny is offline
 
Join Date: Jan 2002
Location: UK
Posts: 29
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This works very well on 3.0.6. Thanks for the hack, only takes a few minutes to install also
Reply With Quote
  #14  
Old 02-14-2005, 12:09 AM
carpefile carpefile is offline
 
Join Date: Jul 2004
Posts: 52
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Is there a way to make this an option rather than a requirement once installed?
I am having a problem with new people joining and that they must choose a default bbcode when registering. Some of them have no clue even what bbcode is, so its throwing a wrench into my board growing.

Many of my existing users love it to death, so I am hoping something can be done besides uninstalling it.
Reply With Quote
  #15  
Old 02-14-2005, 01:49 AM
Darth Cow's Avatar
Darth Cow Darth Cow is offline
 
Join Date: Nov 2001
Posts: 61
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by carpefile
Is there a way to make this an option rather than a requirement once installed?
I am having a problem with new people joining and that they must choose a default bbcode when registering. Some of them have no clue even what bbcode is, so its throwing a wrench into my board growing.

Many of my existing users love it to death, so I am hoping something can be done besides uninstalling it.
Yes, edit the option and set "Field Required" to "No."

Limiting it to certain usergroups is beyond the scope of the built in vBulletin options for profile fields.

However, you can only choose to make it actual works for certain usergroups easilly.

Change the line at the end of my code:

PHP Code:
          $post['message'] = $auto_bb_opentag $post['message'] . $auto_bb_closetag
To:

PHP Code:
if (is_member_of($bbuserinfo123))
{
          
$post['message'] = $auto_bb_opentag $post['message'] . $auto_bb_closetag;

That should work. Just change 123 to the appropriate usergroup you want to enable it for.

As for not accepting hex values, let me fix that. Replace the regular expression with the updated one in the first post.
Reply With Quote
  #16  
Old 02-19-2005, 10:44 AM
Creed's Avatar
Creed Creed is offline
 
Join Date: May 2002
Location: The Matrix
Posts: 281
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This is what I did with mine, works like a charm, and is much easier on the end user:

I created two User Profile Fields:

Type: Single-Line Text Box
Title: Font Color
Description: Enter your preferred font color for each post
Private Field: Yes
Field Searchable on Members List: No
Show on Members List: No

Type: Singe Selection Menu
Title: Font Face
Description: Select your preferred font face for each post
Options:
{
Arial
Arial Black
Arial Narrow
Book Antiqua
Century Gothic
Comic Sans MS
Courier New
Fixedsys
Franklin Gothic Medium
Garamond
Georgia
Impact
Lucida Console
Lucida Sans Unicode
Microsoft Sans Serif
Palatino Linotype
System
Tahoma
Times New Roman
Trebuchet MS
Verdana
}
Private Field: Yes
Field Searchable on Members List: No
Show on Members List: No

Then in your functions_newpost file edit do this (where fieldx is the field number for font color, and fieldx2 is the field number for font face):

Code:
// Darth Cow's auto BB code hack
          if ($bbuserinfo['fieldx'] != "" && $bbuserinfo['fieldx2'] != "")
	{
	$auto_bb_opentag = "[color=" . $bbuserinfo['fieldx'] . "]" . "[FONT=" . $bbuserinfo['fieldx2'] . "]";
	}
		else if ($bbuserinfo['fieldx'] != "")
	{
	$auto_bb_opentag = "[color=" . $bbuserinfo['fieldx'] . "]";
	}
		else if ($bbuserinfo['field16'] != "")
	{
	$auto_bb_opentag = "[font=" . $bbuserinfo['fieldx2'] . "]";
	}
		else
	{
	$auto_bb_opentag ;
	}
     
    preg_match_all("/\[(\w+)(\=\"?\'?(\w+\s*)+\"?\'?)?\]/",$auto_bb_opentag, $auto_bb_tags, PREG_SET_ORDER);
          $auto_bb_closetags = array_reverse($auto_bb_tags);
          $auto_bb_closetag = "";
          foreach ($auto_bb_closetags as $auto_bb_tag)
          {
              $auto_bb_closetag .= "[/" . $auto_bb_tag[1] . "]";
          }
      
          $post['message'] = $auto_bb_opentag . $post['message'] . $auto_bb_closetag;
      // End hack
It is working absolutely flawlessly for me
Reply With Quote
  #17  
Old 03-27-2006, 05:19 PM
antialiasis's Avatar
antialiasis antialiasis is offline
 
Join Date: Jan 2006
Location: Iceland
Posts: 346
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Could this be converted to 3.5.4?
Reply With Quote
Reply

Thread Tools

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:26 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.04149 seconds
  • Memory Usage 2,311KB
  • Queries Executed 21 (?)
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
  • (2)bbcode_code
  • (6)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete