PDA

View Full Version : Need help with preg_match plugin


unitedpunjab
07-18-2017, 02:40 PM
I have tried various $post variables and hook locations.
Couldn't get it working.
Kindly assist if it is doable.


$fost = $post['postparsed'];
if (preg_match( '/embed([^"]+)', $fost , $match ))
{
$test = $match[1];
}


then echo $test in headinclude template.

Dave
07-18-2017, 02:43 PM
You might want to tell us what you want to accomplish first. :)

unitedpunjab
07-18-2017, 03:13 PM
I want to get the youtube video id from thread / post and use it for meta og:image. in headinclude. or showthread.

Got it working for https://vborg.vbsupport.ru/showthread.php?threadid=323668

with preg_match in php script (amp.php).

--------------- Added 1500478984 at 1500478984 ---------------

This is the code I am trying to plugin-fy.


$post['message'] = $bbcode_parser->parse($post['pagetext'], 'nonforum', false);

if (preg_match( '/embed([^"]+)/', $post['message'] , $match ))
{
$imgstr = 'https://img.youtube.com/vi/'.$match[1].'/0.jpg';
}

unitedpunjab
07-20-2017, 10:33 AM
This works in "postbit_display_start" hook, "$test" returns da value I want but only in "postbit" template.

How do i get the value in headinclude or showthread template ?


$fost = $this->post['pagetext'];
if (preg_match( '/youtube.com\/watch\?v=([^"]+)\[/', $fost , $match ))
{
$test = $match[1];
}


Edit: this worked


$find = '$YTIMG';
$vbulletin->templatecache['SHOWTHREAD'] = str_replace($find, $ytimg, $vbulletin->templatecache['SHOWTHREAD']);