ElkArte Community

Elk Development => Bug Reports => Topic started by: Frenzie on November 04, 2017, 12:11:12 pm

Title: Bbc integration issues
Post by: Frenzie on November 04, 2017, 12:11:12 pm
Did something change about integrate_bbc_codes? I'm doing some pre-upgrade checks and most things seem to be working alright, but not Headers BBC (https://www.elkarte.net/community/index.php?topic=3471.0) or these BBCs from SMF:

Code: [Select]
	public static function bbc_codes(&$codes, &$no_autolink_tags, &$itemcodes)
{
$codes[] = array(
'tag' => 'glow',
'type' => 'unparsed_commas',
'test' => '[#0-9a-zA-Z\-]',
'before' => '<span style="text-shadow: $1 0 0 4px">',
'after' => '</span>',
);
$codes[] = array(
'tag' => 'shadow',
'type' => 'unparsed_commas',
'test' => '[#0-9a-zA-Z\-]{3,12},(left|right|top|bottom|[0123]\d{0,2})\]',
'before' => '<span style="text-shadow: $1 $2">',
'after' => '</span>',
'validate' => create_function('&$tag, &$data, $disabled', '
if ($data[1] == \'top\' || (is_numeric($data[1]) && $data[1] < 50))
$data[1] = \'0 -2px 1px\';
elseif ($data[1] == \'right\' || (is_numeric($data[1]) && $data[1] < 100))
$data[1] = \'2px 0 1px\';
elseif ($data[1] == \'bottom\' || (is_numeric($data[1]) && $data[1] < 190))
$data[1] = \'0 2px 1px\';
elseif ($data[1] == \'left\' || (is_numeric($data[1]) && $data[1] < 280))
$data[1] = \'-2px 0 1px\';
else
$data[1] = \'1px 1px 1px\';'),
);
}
The forum has a nice green checkmark next to integrate_bbc_codes, but it's not actually doing anything.
Title: Re: Bbc integration issues
Post by: inter on November 04, 2017, 12:44:26 pm
@Frenzie bbcode in 1.1 changed
You can see how I updated the example ~ link ~ (https://bitbucket.org/interlab/elk-spoiler-modern/src/59c23682fb047b6bc7e90a7186ba54ec6c0c846b/elk-1.1.x/SpoilerModern.hook.php?at=master&fileviewer=file-view-default)
Title: Re: Bbc integration issues
Post by: Frenzie on November 04, 2017, 12:53:56 pm
@inter Thanks!
Title: Re: Bbc integration issues
Post by: Frenzie on November 04, 2017, 04:29:38 pm
Okay, whose idea was it to name that hook bbc_codes_parsing instead of integrate_bbc_codes_parsing.  >:(  :'(

Quote from: Some semi-random debug outputintegrate_additional_bbc, integrate_autolink_load, integrate_news_html_parser, integrate_html_parser_load, integrate_news_bbc_parser, integrate_item_codes, bbc_codes_parsing

Edit:
@emanuele Could you maybe give me a hint regarding what I'm missing? It's not working.

Code: [Select]
	public static function bbc_codes_parsing(&$codes, &$itemcodes)
{
$codes[] = array(
BBC\Codes::ATTR_TAG => 'glow',
BBC\Codes::ATTR_TYPE => BBC\Codes::TYPE_UNPARSED_COMMAS,
BBC\Codes::ATTR_TEST => '[#0-9a-zA-Z\-]',
BBC\Codes::ATTR_BEFORE => '<span style="text-shadow: $1 0 0 4px">',
BBC\Codes::ATTR_AFTER => '</span>',
BBC\Codes::ATTR_QUOTED => BBC\Codes::OPTIONAL,
BBC\Codes::ATTR_BLOCK_LEVEL => false,
BBC\Codes::ATTR_AUTOLINK => true,
BBC\Codes::ATTR_LENGTH => 4,
);
$codes[] = array(
BBC\Codes::ATTR_TAG => 'shadow',
BBC\Codes::ATTR_TYPE => BBC\Codes::TYPE_UNPARSED_COMMAS,
BBC\Codes::ATTR_TEST => '[#0-9a-zA-Z\-]{3,12},(left|right|top|bottom|[0123]\d{0,2})\]',
BBC\Codes::ATTR_BEFORE => '<span style="text-shadow: $1 $2">',
BBC\Codes::ATTR_AFTER => '</span>',
BBC\Codes::ATTR_VALIDATE => function(&$tag, &$data, $disabled) {
if ($data[0] == 'top' || (is_numeric($data[1]) && $data[1] < 50))
$data[1] = '0 -2px 1px';
elseif ($data[1] == 'right' || (is_numeric($data[1]) && $data[1] < 100))
$data[1] = '2px 0 1px';
elseif ($data[1] == 'bottom' || (is_numeric($data[1]) && $data[1] < 190))
$data[1] = '0 2px 1px';
elseif ($data[1] == 'left' || (is_numeric($data[1]) && $data[1] < 280))
$data[1] = '-2px 0 1px';
else
$data[1] = '1px 1px 1px';},
BBC\Codes::ATTR_QUOTED => BBC\Codes::OPTIONAL,
BBC\Codes::ATTR_BLOCK_LEVEL => false,
BBC\Codes::ATTR_AUTOLINK => true,
BBC\Codes::ATTR_LENGTH => 6,
);
// test; working
$codes[] = array(
BBC\Codes::ATTR_TAG => 'j',
BBC\Codes::ATTR_TYPE => BBC\Codes::TYPE_PARSED_CONTENT,
BBC\Codes::ATTR_BEFORE => '<strong class="bbc_strong">',
BBC\Codes::ATTR_AFTER => '</strong>',
BBC\Codes::ATTR_BLOCK_LEVEL => false,
BBC\Codes::ATTR_AUTOLINK => true,
BBC\Codes::ATTR_LENGTH => 1,
);
}
Title: Re: Bbc integration issues
Post by: ahrasis on November 04, 2017, 11:53:52 pm
Thanks for raising bbc issue. Reminds me of finishing mine too.
Title: Re: Bbc integration issues
Post by: vbgamer45 on November 05, 2017, 01:48:19 am
Was trying to fix one that i was using in rssfeedposter html bbc
Title: Re: Bbc integration issues
Post by: emanuele on November 05, 2017, 03:35:45 am
When I reach a proper computer I'll check it better.
The naming is likely a refactoring overlook...

/me takes note to create a test for hooks naming convention
Title: Re: Bbc integration issues
Post by: Frenzie on November 05, 2017, 04:53:19 am
I suppose the lack of integrate_ is technically a bug report but otherwise it may just be a support question. Unless BBC\Codes::TYPE_UNPARSED_COMMAS is broken. ;)
Title: Re: Bbc integration issues
Post by: Spuds on November 05, 2017, 08:12:03 am
You should try integrate_additional_bbc to add new codes to the system, not the item codes hook.
Title: Re: Bbc integration issues
Post by: Spuds on November 05, 2017, 08:18:39 am
Quote from: vbgamer45 – Was trying to fix one that i was using in rssfeedposter html bbc
You may need to wait for 1.1.1 for help in protecting code blocks via integrate_preparse_code. 

Preparse was also redone and no longer loops on the preg_split but instead replaces code blocks with tokenized holders.  As such integrate_preparse_code, specifically the old $i value has no real meaning, its always 0 but has all of the code in the data string.  Its not the old 0 is above the code .... 

In 1.1.1 I added an integrate_preparse_tokenized_code hook, that one will have the code blocks safe from processing so you can take that data and safely work on it w/o affecting whats inside the code blocks.
Title: Re: Bbc integration issues
Post by: Frenzie on November 05, 2017, 08:39:51 am
Quote from: Spuds – You should try integrate_additional_bbc to add new codes to the system, not the item codes hook.
Will do, but note that the test at the bottom works so even without having tried it I doubt that'd make a different wrt what I'm missing.

Edit: @Spuds Unfortunately as expected no change.
Title: Re: Bbc integration issues
Post by: Spuds on November 07, 2017, 10:20:06 am
Before I call this a bug .... Looking at your code,

1) glow ... I'm not sure why you chose TYPE_UNPARSED_COMMAS since it looks like you just want to extract a color name or color code and use that.   I'd first try by changing the type and then make sure you capture the entire thing, right now the test is only going to pass (and return) a single character, so that needs to expand (done dirty below)
Code: [Select]
				self::ATTR_TYPE => self::TYPE_UNPARSED_EQUALS,
self::ATTR_TEST => '[#0-9a-zA-Z\-]*?',

2) shadow ... this looks fine except for the test, you don't need or want to add that trailing \] in the test as the system does that for you now.
Code: [Select]
			self::ATTR_TEST => '[#0-9a-zA-Z\-]{3,12},(left|right|top|bottom|[0123]\d{0,2})',
Title: Re: Bbc integration issues
Post by: Frenzie on November 07, 2017, 11:08:27 am
Quote from: Spuds – 1) glow ... I'm not sure why you chose TYPE_UNPARSED_COMMAS since it looks like you just want to extract a color name or color code and use that.   I'd first try by changing the type and then make sure you capture the entire thing, right now the test is only going to pass (and return) a single character, so that needs to expand (done dirty below)
Code: [Select]
				self::ATTR_TYPE => self::TYPE_UNPARSED_EQUALS,
self::ATTR_TEST => '[#0-9a-zA-Z\-]*?',

This is SMF code that was removed from Elk for some reason.[1] I didn't choose anything other than to copy/paste it into an extension. :P

What I want is for it to remain perfectly compatible, and the surest way to do so is not to change it at all.

Anyway, real life glow usage looks like this:

Code: [Select]
[glow=green,2,300]I'm green.[/glow]

Looks a lot like commas to me. ;)
By certain unnamed parties (https://github.com/elkarte/Elkarte/commit/0626c1f1e7c6b37dbd29c1c76444a4cbab687c74).
Title: Re: Bbc integration issues
Post by: Frenzie on November 07, 2017, 11:31:09 am
I see what you're getting at though.

SMF docs: https://wiki.simplemachines.org/smf/Glow

Basically the full glow was always an IE-only thing https://github.com/elkarte/Elkarte/commit/075c90c06d76f63e5458021c829b153ca8e7d992

In any case, it should properly eat comma values even if it might be temporarily unsupported in the output.  ;D
Title: Re: Bbc integration issues
Post by: Spuds on November 07, 2017, 12:05:16 pm
At that point in Elk it appears we had already dropped the IE glow support, so the code was just glow=blue or whatever.  Never documented or probably tested since it was removed then.  The old SMF code is
Code: [Select]
			array(
'tag' => 'glow',
'type' => 'unparsed_commas',
'test' => '[#0-9a-zA-Z\-]{3,12},([012]\d{1,2}|\d{1,2})(,[^]]+)?\]',
'before' => $context['browser']['is_ie'] ? '<table border="0" cellpadding="0" cellspacing="0" style="display: inline; vertical-align: middle; font: inherit;"><tr><td style="filter: Glow(color=$1, strength=$2); font: inherit;">' : '<span style="text-shadow: $1 1px 1px 1px">',
'after' => $context['browser']['is_ie'] ? '</td></tr></table> ' : '</span>',
),

If you want to support the old glow codes, I'd update the test to
Code: [Select]
 '[#0-9a-zA-Z\-]{3,12},([012]\d{1,2}|\d{1,2})(,[^]]+)?
  That will parse the commas but not use them at all as only the first capture (the color name $1) will be used in the span ... in theory.
Title: Re: Bbc integration issues
Post by: Frenzie on November 07, 2017, 02:27:01 pm
Regardless of that particular aspect of it, what changed exactly? Like you said, it looks like it should match just one character, but that's the working Elk 1.0 code.

Edit: btw, even in the SMF code I have no idea what that "300" at the end is supposed to be doing. Could that be from another forum? >_>


In any case, the second value sets the pixel spread on the glow, so in the shadow it should just be a bunch of $2px $2px…
Title: Re: Bbc integration issues
Post by: Spuds on November 07, 2017, 06:43:11 pm
Mr. BBC's prediction for using glow is pain, nothing but pain :P

No idea on the 300 ...  some of the SMF stuff goes back to early IE days, so maybe that was needed as the direction vector in an old version of filter:glow say IE5.5? shrug  Then MS likely dropped it at some point but it had to still be accounted for to support any old tags even though it was not used.

Don't know why your code worked in 1.0 :/  Perhaps a old bug or maybe the way the comma code was implemented, certainly strange.