Advertisement:

Author Topic: Custom BBC tag code for php 7.2/3 compatibility  (Read 638 times)

Offline spiros

  • Language Moderator
  • SMF Hero
  • *
  • Posts: 1,732
  • Gender: Male
  • A different point of view
    • spiros.doikas on Facebook
    • doikas on LinkedIn
    • @greektranslator on Twitter
    • Greek Translation
Custom BBC tag code for php 7.2/3 compatibility
« on: March 09, 2019, 03:33:47 AM »
I have a custom tag and I want to adapt it (as done here). Is the way I do it correct?

Find
Code: [Select]
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

Code: [Select]
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>',
),

Offline RichardAD

  • Newbie
  • *
  • Posts: 6
Re: Custom BBC tag code for php 7.2/3 compatibility
« Reply #1 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

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 70,992
    • StoryBB/StoryBB on GitHub
Re: Custom BBC tag code for php 7.2/3 compatibility
« Reply #2 on: April 18, 2019, 08:32:12 AM »
Generally that looks sound though the change of br format may bite you if not careful.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.