Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: spiros on March 09, 2019, 03:33:47 AM

Title: Custom BBC tag code for php 7.2/3 compatibility
Post by: spiros on March 09, 2019, 03:33:47 AM
I have a custom tag and I want to adapt it (as done here (https://www.smfhacks.com/index.php?action=downloads;sa=view;down=215)). Is the way I do it correct?

Find
array(
'tag' => 'google',
'type' => 'unparsed_content',
'content' => '<a href="https://www.google.com/search?q=$1" target="_blank">$1</a>',
'validate' => create_function('&$tag, &$data, $disabled', '$data = strtr($data, array(\'<br />\' => \'\'));'),
                'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
'disabled_content' => '<span style="color: red;">Google Search: $1</span>',
),
array(
'tag' => 'google',
'type' => 'unparsed_equals',
'before' => '<a href="https://www.google.com/search?q=$1" target="_blank">',
                'after' => '</a>',
                'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
'disabled_before' => '<span style="color: red;">',
                'disabled_after' => ' ($1)</span>',
),


Replace

array(
'tag' => 'google',
'type' => 'unparsed_content',
'content' => '<a href="https://www.google.com/search?q=$1" target="_blank">$1</a>',
'validate' => function (&$tag, &$data, $disabled)
{
$data = strtr($data, array('<br>' => ''));
},
                'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
'disabled_content' => '<span style="color: red;">Google Search: $1</span>',
),
array(
'tag' => 'google',
'type' => 'unparsed_equals',
'before' => '<a href="https://www.google.com/search?q=$1" target="_blank">',
                'after' => '</a>',
                'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
'disabled_before' => '<span style="color: red;">',
                'disabled_after' => ' ($1)</span>',
),
Title: Re: Custom BBC tag code for php 7.2/3 compatibility
Post by: RichardAD on April 18, 2019, 08:00:59 AM
That is the correct way to update your code from using

   create_function( <args-text>, <source-code-text>)

to using anonymous function

   function(args) { source code }
   
special attention should be made if the original source code text contained text escapes such as \' or \".  You can get pretty dizzy if the original source code text also contained regex patterns
Title: Re: Custom BBC tag code for php 7.2/3 compatibility
Post by: Arantor on April 18, 2019, 08:32:12 AM
Generally that looks sound though the change of br format may bite you if not careful.