vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   bbcode font-size semantics (https://vborg.vbsupport.ru/showthread.php?t=282857)

PinkMilk 05-13-2012 12:16 PM

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)?

kh99 05-14-2012 10:52 AM

Someone asked that question on stackoverflow: http://stackoverflow.com/questions/8...-size-10-to-px . Someone there came up with a conversion to ems.

PinkMilk 05-14-2012 12:11 PM

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.

kh99 05-14-2012 02:48 PM

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.

NeutralizeR 04-15-2015 04:38 AM

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>';
        
    
        



NeutralizeR 04-17-2015 02:04 AM

Can you please say if it is possible or not please? :)

kh99 04-17-2015 09:54 AM

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.

NeutralizeR 04-23-2015 03:33 AM

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...

kh99 04-23-2015 09:53 AM

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.

NeutralizeR 04-23-2015 10:42 AM

Quote:

Originally Posted by kh99 (Post 2543946)
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;




All times are GMT. The time now is 06:15 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01337 seconds
  • Memory Usage 1,809KB
  • 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
  • (6)bbcode_code_printable
  • (10)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete