[Solved] Recover a piece of Joomla field (video in attribs field)

georgie

Member
Hello

I would recover a piece of Joomla field (#_content___attribs) in a Fabrik calc field, not easy...

I explain : Joomla "attribs" field can store images, videos... I am interested only by videos. Finally I would display video in an iframe window.
So I have to isolate my string I wish with a calc field.
But the "attribs" is a little complex, for example:
Code:
{"spfeatured_image":"",
"post_format":"video",
"gallery":"",
"audio":"",
"video":"https:\/\/youtu.be\/BYa9IY31IK0",
"link_title":"",
"link_url":"",
"quote_text":"",
"quote_author":"",
"post_status":"","custom_post":""}

String I wish is each time between "video" and "link_title", so it would be possible, but... not easy for me!

From what I would someting like:
Code:
<iframe width="560" height="315" 
src="{MyVideoUrl}" 
title="{#_content___title}" 
frameborder="0" 
allow="autoplay; encrypted-media" 
allowfullscreen></iframe>

Can you help me?

#THX #Fabrik

Georges
 
It's JSON

$myattribs = your-attribs-string;
$attribs_obj = json_decode($myattribs);
$videoUrl = $attrib_obj->video;
 
Thanks you I understand the goal with JSON now...

But I can not recover my attribs field, I do not understand why...

I do this, without success:
Code:
$json_string = '{#_content___attribs}' ;

var_dump($json_string);

exit;

Arf...

With another field, I well recover data, but with attribs field, not.

Please do you know why?
 
Last edited:
Hello sorry but it is still me...

Indeed now I have no error, but my json decoded displays a null value...

I do this:
Code:
$My_Json_String = '{joo_content___attribs}' ;

$attribs_obj = json_decode($My_Json_String) ;

$videoUrl = $attribs_obj->video ;

// var_dump($videoUrl) ;
// exit;

return $videoUrl ;

Please do you see any error from me?

THX
 
Hello

Yes my $My_Json_String dumped is valid:
Code:
string(429) "{"spfeatured_image":"","post_format":"video","gallery":"","audio":"","video":"https:\/\/youtu.be\/BYa9IY31IK0","link_title":"","link_url":"","quote_text":"","quote_author":"","post_status":"","custom_post":""}"

But my $attribs_obj dumped is null.

...
 
OK, fixed.
Here my working code:
Code:
$My_Json_String = '{#_content___attribs}' ;

// Fix quotes
$json = str_replace('&quot;', '"', $My_Json_String);

$object = json_decode($json);

$videoUrl = $object->video;

// Recover only the Youtube Video Code (deleting the beginning of the url - to do an iframe after)
$videoCode = str_replace('https://youtu.be/', '', $videoUrl);

// Tests:
// var_dump($videoUrl); exit;
// echo '<pre>'. $videoCode .  '</pre>';

// Iframe
return '<iframe width="100%" height="250px" src="https://www.youtube.com/embed/'.$videoCode.'" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>' ;
 
Last edited:
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top