View Full Version : Using Dailymotion Api in BB Code Template
XiTCLUB
04-14-2014, 07:43 PM
Hi,
I wanted to use HTML5 schema in my BB code templates and wanted to fetch video data via dailymotion API and for that i have to create and echo variables inside template
The code i am using is
<?php
$id={vb:raw code};
$thumbnail_medium_url='https://api.dailymotion.com/video/'.$id.'?fields=thumbnail_720_url';
$json_thumbnail = file_get_contents($thumbnail_720_url);
$get_thumbnail = json_decode($json_thumbnail, TRUE);
$thumb=$get_thumbnail['thumbnail_720_url'];
?>
and i am echoing it like this
<?php echo $thumb ?>
but this is not working like it should and just printing whole statement as it is
Zachery
04-14-2014, 09:25 PM
You can't use PHP in the bbcode templates, or any templates for that matter.
XiTCLUB
04-14-2014, 09:52 PM
You can't use PHP in the bbcode templates, or any templates for that matter.
Yeah i see and i figure out things with Tutorials and template system and i came too close.
I created a Plugin with this code
function video_api_thumb($vid){
$id = $vid;
$thumbnail_720_url='https://api.dailymotion.com/video/'.$id.'?fields=thumbnail_720_url';
$json_thumbnail = file_get_contents($thumbnail_720_url);
$get_thumbnail = json_decode($json_thumbnail, TRUE);
$thumb=$get_thumbnail['thumbnail_720_url'];
}
$thumb_url = video_api_thumb('x17r8h7');
$templater = vB_Template::create('dailymotion_video_api');
$templater->render();
vB_Template::preRegister('bbcode_video',array('vid eo_thumb_url' => $thumb_url));
and used this in my bbcode_video
Thumbnail : {vb:raw video_thumb_url}
Now its printing Thumbnail URL in my thread view but i want to use dynamic video id instead of hard coded one i function ($thumb_url = video_api_thumb('x17r8h7');). how can i pass a video id to that plugin function so it will return fresh thumbnail ??
Zachery
04-14-2014, 11:38 PM
Take a look at the video bbcode related stuff.
XiTCLUB
04-15-2014, 09:51 AM
Take a look at the video bbcode related stuff.
There is something like this {vb:raw code} in "bbcode_video" in templates. now how can i send this {vb:raw code} to plugin ??
You can remove these two lines from your code:
$templater = vB_Template::create('dailymotion_video_api');
$templater->render();
because they aren't doing anything ($templater->render() returns a string).
I understand that you want the video id to be a parameter, but I don't understand where you want to enter it.
Edit: Maybe you want to provide the code as part of the bbocde? Which hook location are you using for your plugin?
By the way, have you looked at this mod: https://vborg.vbsupport.ru/showthread.php?t=230707 ? Maybe it already does what you want.
And I noticed that there are a couple older mods below in the "Similar Threads" section below. They are for older versions, but they still might work with vb4, or at least give you an idea of how to do it.
Edit: Oh, well, I guess you're trying to use the api to get the thumbnail and not just embed the video, so maybe those don't help.
Zachery
04-25-2014, 08:36 PM
Also, if you just want to use dailymotion, you can update the bbcode_video.xml file, no need for a lot of complicated nonsense.
XiTCLUB
04-26-2014, 05:20 AM
You can remove these two lines from your code:
$templater = vB_Template::create('dailymotion_video_api');
$templater->render();
because they aren't doing anything ($templater->render() returns a string).
I understand that you want the video id to be a parameter, but I don't understand where you want to enter it.
Edit: Maybe you want to provide the code as part of the bbocde? Which hook location are you using for your plugin?
Okay i have removed those lines and i am using hook location "global_start"
i want to get video id from thread where video is embedded and parse that id to my plugin function so i can get video_tubmnail, title, length and other stuff from dailymotion
--------------- Added 1398493348 at 1398493348 ---------------
Also, if you just want to use dailymotion, you can update the bbcode_video.xml file, no need for a lot of complicated nonsense.
I can see that you are not getting what i wanted to do. i am not stupid enough to get stuck on just embedding videos.
Zachery
04-26-2014, 06:50 AM
Please enlighten me, why can't you just update the video bbcode template?
XiTCLUB
04-26-2014, 09:03 AM
Please enlighten me, why can't you just update the video bbcode template?
Because it is not allowing me to run PHP directly into template to get meta data ofvideo from dailymotion API
I wanted to accomplish this thing
<div itemprop="video" itemscope itemtype="http://schema.org/VideoObject">
<h2>Video: <span itemprop="name">Title</span></h2>
<meta itemprop="duration" content="T1M33S" />
<meta itemprop="thumbnailUrl" content="thumbnail.jpg" />
<meta itemprop="contentURL" content="http://www.example.com/video123.flv" />
<meta itemprop="embedURL" content="http://www.example.com/videoplayer.swf?video=123" />
<meta itemprop="uploadDate" content="2011-07-05T08:00:00+08:00" />
<meta itemprop="expires" content="2012-01-30T19:00:00+08:00" />
<object ...>
<param ...>
<embed type="application/x-shockwave-flash" ...>
</object>
<span itemprop="description">Video description</span>
</div>
And now tell me how its possible by just updating videobb_code template ??
and if you help me out achieving this thing it can help the community very much and i will surely share the code with the community, so their video content get indexed just like youtube, dailymotion.
thumbnail shows alongside the search results so forum owners can get more traffic from their video content
OK, you could try this: use a plugin on hook bbcode_create to replace the video handling function that's in $this->tag_list with your own function. Then have your function check for the provider option of "dailymotion", and do your special handing (return whatever html you want), and if it's not "dailymotion", call the existing function (or copy the code from the existing function). Or I suppose in your case you could just register your extra information to the bbcode_video template as you are doing in your plugin, then call the existing code.
See includes/class_bbcode.php, function vB_BbcodeParser() and function handle_bbcode_video().
I believe vB_BbcodeParser() is the constructor for a base class, so you may want to check the actual class before replacing the video handling function, so that the classes in class_bbcode_alt.php will still work as the default (for instance, when a text-only version is being rendered).
You could also look at my "Private Message Quote Formatting" mod (the bbcode_create plugin code) for an example. In that case I was doing it only for private messages, so of course you wouldn't want the check for 'private', but otherwise it's basically what I tried to describe in the post above.
cellarius
04-26-2014, 04:38 PM
You can't use PHP in the bbcode templates, or any templates for that matter.
For using PHP in BBCodes, this may work for:
https://vborg.vbsupport.ru/showthread.php?t=264896
XiTCLUB
04-28-2014, 07:01 AM
OK, you could try this: use a plugin on hook bbcode_create to replace the video handling function that's in $this->tag_list with your own function. Then have your function check for the provider option of "dailymotion", and do your special handing (return whatever html you want), and if it's not "dailymotion", call the existing function (or copy the code from the existing function). Or I suppose in your case you could just register your extra information to the bbcode_video template as you are doing in your plugin, then call the existing code.
See includes/class_bbcode.php, function vB_BbcodeParser() and function handle_bbcode_video().
I believe vB_BbcodeParser() is the constructor for a base class, so you may want to check the actual class before replacing the video handling function, so that the classes in class_bbcode_alt.php will still work as the default (for instance, when a text-only version is being rendered).
Hi, Thank for your kind support i have edited the file "class_bbcode.php" and it solved my problem
Hi, Thank for your kind support i have edited the file "class_bbcode.php" and it solved my problem
...or you could do that. I guess I'm used to thinking of how to do things without edits.
Anyway, glad you solved it.
XiTCLUB
04-28-2014, 11:33 AM
...or you could do that. I guess I'm used to thinking of how to do things without edits.
Anyway, glad you solved it.
Yup i tried many ways but as i am not an expert PHP programer i have managed to solve the problem at my expertise level.
I will share the code once i got expected results in Google search
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.