Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 05-13-2012, 12:16 PM
PinkMilk PinkMilk is offline
 
Join Date: May 2010
Location: Earth
Posts: 193
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default bbcode font-size semantics

Currently vb uses <font> for bbcode font-size and so I'm trying to replace it with <span>

So far I've edited class_bbcode.php
Example (color):
PHP Code:
html' => '<font color="%2$s">%1$s</font>', 
to:
PHP Code:
html' => '<span style="color:%2$s;">%1$s</span>', 
and output seems fine except for font-size ...

PHP Code:
html' => '<font size="%2$s">%1$s</font>', 
to:
PHP Code:
html' => '<span style="font-size:%2$spx;">%1$s</span>', 
as it calls the old <font> sizes 1 - 7

so my question is where can I find where to change "default" font sizes 1 - 7 to say 10 - 20 (px)?
Reply With Quote
  #2  
Old 05-14-2012, 10:52 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Someone asked that question on stackoverflow: http://stackoverflow.com/questions/8...-size-10-to-px . Someone there came up with a conversion to ems.
Reply With Quote
  #3  
Old 05-14-2012, 12:11 PM
PinkMilk PinkMilk is offline
 
Join Date: May 2010
Location: Earth
Posts: 193
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks but that's not what I mean, converting sizes to Points/Pixels/Ems is the easy part, I'm needing to change how vbulletin converts the members bbcode choice:

PHP Code:
html' => '<span style="font-size:%2$spx;">%1$s</span>, 
Rather than:
PHP Code:
html' => '<font size="%2$s">%1$s</font>, 
Now one way I guess would be to add a "1" before the replace var turning 1 into 11, 2 into 12 etc etc
Code:
html' => '<span style="font-size:1%2$spx;">%1$s</span>,

..but I would still like to know where in vbulletin the font-size function, CSS or whatever is allowing me to choose specifically which font sizes I wish whether it be within a template or php file as I can't find where myself.
Reply With Quote
  #4  
Old 05-14-2012, 02:48 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Oh, OK. I think what you can do is change that code to use a callback like this:

Code:
			// [SIZE=XXX]
			$tag_list['option']['size'] = array(
				'callback' => 'handle_bbcode_size',
				'option_regex' => '#^[0-9\+\-]+$#',
				'strip_empty' => true
			);

Then write a function called handle_bbcode_size that takes the size number 1-7 as a parameter and returns the replacment html. That way you can write whatever php you want to do the conversion. (Edit: I think the function actually takes two parameters, the text between the tags and the font size number).

BTW, I haven't tried it, and looking at the other tags that have a callback I notice none of them have an option_regex so I don't know if that works with a callback or not.
Reply With Quote
  #5  
Old 04-15-2015, 04:38 AM
NeutralizeR NeutralizeR is offline
 
Join Date: Aug 2005
Posts: 355
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hello... Can you please help me on this? How can i use %2$s and %1$s in the sample function below?
PHP Code:
function handle_bbcode_size($text$size$fontsize '')  
{  
    
    
        if (
$size)
        {
            switch (
$size)
            {
                case 
'1':
                    
$fontsize '11px';
                    break;
                case 
'2':
                    
$fontsize '14px';
                    break;
                case 
'3':
                    
$fontsize '17px';
                    break;
                case 
'4':
                    
$fontsize '20px';
                    break;
                case 
'5':
                    
$fontsize '23px';
                    break;
                case 
'6':
                    
$fontsize '26px';
                    break;
                case 
'7':
                    
$fontsize '29px';
                    break;
            }
        }
        else
        {
            
$fontsize '14px';
        }            

            return 
'<span style="font-size:$fontsize">$text</span>';
        
    
        

Reply With Quote
  #6  
Old 04-17-2015, 02:04 AM
NeutralizeR NeutralizeR is offline
 
Join Date: Aug 2005
Posts: 355
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Can you please say if it is possible or not please?
Reply With Quote
  #7  
Old 04-17-2015, 09:54 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, I never did actually try it, as I mentioned above. But did you make the change to $tag_list that I posted above? It's in includes/class_bbcode.php. And the handle_bbcode_size function should go in there too, somewhere before the final } so that it's part of the class.
Reply With Quote
  #8  
Old 04-23-2015, 03:33 AM
NeutralizeR NeutralizeR is offline
 
Join Date: Aug 2005
Posts: 355
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
        if (($vbulletin->options['allowedbbcodes'] & ALLOW_BBCODE_SIZE) OR $force_all)
        {
            
// [SIZE=XXX]
            
$tag_list['option']['size'] = array(
                
'callback' => 'handle_bbcode_size',
                
'option_regex' => '#^[0-9\+\-]+$#',
                
'strip_empty' => true
            
);
        } 
PHP Code:
    /***Handles a [size] tag.********************** */
    
    
    
function handle_bbcode_size($text$size '')  
    {  


        if (
$size)
        {
            
            switch (
$size)
            {
                case 
'1':
                    
$size '12px';
                    break;
                case 
'2':
                    
$size '15px';
                    break;
                case 
'3':
                    
$size '18px';
                    break;
                case 
'4':
                    
$size '21px';
                    break;
                case 
'5':
                    
$size '24px';
                    break;
                case 
'6':
                    
$size '27px';
                    break;
                case 
'7':
                    
$size '30px';
                    break;
            }
        }
        else
        {
            
            
$size '15px';
        }            
                      
            return 
'<span style="font-size:' $size '">' $text'</span>';
        
    
        
    } 
It's working But there is another problem now.

I enter some text in WYSIWYG text area and select the text, then i pick a size like 5.

It changes the font size perfectly. (in the page source code it still says <font*)

I click the preview button (in newreply), the page reloads and it still displays font size as "5".

I check the page source code both in the preview table cell and WYSIWYG text area and they both display "<span style***" which is correct.

I click the preview button once again and this time i notice the text's font size is converted to default size and the size tag is completely removed.

Then I opened vbulletin_textedit.js and changed the line below:

Code:
option.innerHTML = '<font size="' + sizeoptions[n] + '">' + sizeoptions[n] + '</font>';
to:

Code:
option.innerHTML = '<span style="font-size:' + sizeoptions[n] + '">' + sizeoptions[n] + '</span>';
It didn't work. Something is still adding "<font size" tag...
Reply With Quote
  #9  
Old 04-23-2015, 09:53 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Oh, right, I forgot about the fact that it has to be able to go back and forth between bbcode and html. There's a file includes/class_wysiwygparser.php that goes from html to bbcode, and it uses the <font> tag instead of the font-size attribute. So you could either change your replacement to use the font tag (which I know isn't the way it's done these days), or else figure out how to change the code in class_wysiwygparser.php. I only glanced at it, but there's a function parse_style_attribute(), and it currently doesn't parse out the font size. You might be able to add a line to the $searchlist array to make it find the font size and insert a size tag for it. Probably something like:
Code:
array('tag' => 'size', 'option' => true, 'regex' => '#font-size:\s*([0-9]+px;?)#i', 'match' => 1)
then you'd also need code to convert the matched text to your font number. If this isn't something you can do, I'll give it a try later.
Reply With Quote
  #10  
Old 04-23-2015, 10:42 AM
NeutralizeR NeutralizeR is offline
 
Join Date: Aug 2005
Posts: 355
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
Oh, right, I forgot about the fact that it has to be able to go back and forth between bbcode and html. There's a file includes/class_wysiwygparser.php that goes from html to bbcode, and it uses the <font> tag instead of the font-size attribute. So you could either change your replacement to use the font tag (which I know isn't the way it's done these days), or else figure out how to change the code in class_wysiwygparser.php. I only glanced at it, but there's a function parse_style_attribute(), and it currently doesn't parse out the font size. You might be able to add a line to the $searchlist array to make it find the font size and insert a size tag for it. Probably something like:
Code:
array('tag' => 'size', 'option' => true, 'regex' => '#font-size:\s*([0-9]+px;?)#i', 'match' => 1)
then you'd also need code to convert the matched text to your font number. If this isn't something you can do, I'll give it a try later.
It's beyond my knowledge Thank you for your time! I'll be waiting.

--------------- Added 23 Apr 2015 at 15:47 ---------------

Btw, my vb version is 3.8.8 and i don't see a file named class_wysiwygparser.php. Maybe it's a vb 4.x file? There is file named functions_wysiwyg.php though.



Is this the related section?

PHP Code:
// ###################### Start WYSIWYG_fontparser #######################
function parse_wysiwyg_font($fontoptions$text)
{
    
$tags = array(
        
'font' => 'face=',
        
'size' => 'size=',
        
'color' => 'color='
    
);
    
$prependtags '';
    
$appendtags '';

    
$fontoptionlen strlen($fontoptions);

    foreach (
$tags AS $vbcode => $locate)
    {
        
$optionvalue parse_wysiwyg_tag_attribute($locate$fontoptions);
        if (
$optionvalue)
        {
            
$vbcode strtoupper($vbcode);
            
$prependtags .= "[$vbcode=$optionvalue]";
            
$appendtags "[/$vbcode]$appendtags";
        }
    }

    
parse_style_attribute($fontoptions$prependtags$appendtags);

    return 
$prependtags parse_wysiwyg_recurse('font'$text'parse_wysiwyg_font') . $appendtags;

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:31 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.04815 seconds
  • Memory Usage 2,334KB
  • Queries Executed 12 (?)
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
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (6)bbcode_code
  • (10)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)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
  • 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