SimplePortal
Customization => Custom Coding => Topic started by: yaosurfer on November 09, 2011, 10:05:36 AM
-
Hi there gang!
Is it possible to create a block with custom code that will display most recently attached (embed in post) video?
Thanks !
-
Various ways to do that, but are you using Aeva Media to embed videos?
-
Thanks for the reply. Yes in this instance forum is supported by Aeva Media. Just to clarify ... I do not want to post most recent / random video from Aeva Media gallery. It has to be most recent / random video posted on the forum.
Regards
-
Is this on post-basis or thread-basis?
-
Ideally on posts but both versions (post - thread) would be much appreciated for testing purposes ;)
-
The way I'm thinking of doing this is to call the recentPosts() function that SMF uses to acquire a list of recently made posts, and then use a regex on it to search the posts for an embed, and then list the most recent one and pass it on (and cache it).
The only problem is that if no embedding has happened for a while, then there is a possibility that it won't show any post, since none would have any. In that case you would need to check every possible post, or just rely on the old cache of the last video (which is far better).
What BBC are you using to embed videos, if any at all?
-
Here, try this out. It should work properly in a sense, it is made for YouTube videos really (though it should detect other swfs fine).
<?php
if (!cache_get_data('recent_video'))
{
$posts = ssi_recentPosts(150, null, null, 'array', false);
$search = '';
foreach ($posts as $post)
$search .= $post['body'];
$matches = array();
preg_match_all('%http://(?:\S+\.swf\b|\S+?youtube\S+)%', $search, $matches);
cache_put_data('recent_video', $matches);
}
else
$matches = cache_get_data('recent_video');
if (!empty($matches) && !empty($matches[0][0]))
echo str_replace(array('"', '"'), '', $matches[0][0]);
?>
-
Just a btw: since it has to run a rather large regex on all posts for a match, it's cached forever. I just realized that because of this, it won't update when someone makes a new post unless you dump out the cache.
You can make it automatically dump out every xxx seconds or so, I would recommended every 3 or 6 hours.
To do this (for 3 hours), in my code find the following lines:
if (!cache_get_data('recent_video'))
cache_put_data('recent_video', $matches);
$matches = cache_get_data('recent_video');
And replace each one with the equiv:
if (!cache_get_data('recent_video', 10800))
cache_put_data('recent_video', $matches, 10800);
$matches = cache_get_data('recent_video', 10800);
-
Sweet ! unfortunately it is calling and displaying raw link without showing the actual video :(
And there is no bbc coding around it as far I am aware of. The only support for displaying the images and videos is Aeva Media.
Thank you
-
Hmm. Not sure where Aeva Media picks up the tags from, thought it was some giant url buffer edit or something, maybe it uses parse_bbc or similar.
Try this, and see if it shows the video,
Find:
echo str_replace(array('"', '"'), '', $matches[0][0]);
Replace with:
echo str_replace(array('"', '"'), '', parse_bbc($matches[0][0]));
-
I did something:
- used to be raw/plain text
- after the change the text is displayed as a "link type" therefore when mouse-over, it will simply underline the link (able to click the link)
-
So it hyperlinked it, huh?
I'm not sure what Aeva Media does to display the actual embed. You could ask the author about it (I'm sure they can tell you what you need to do easily), or you could manually edit the HTML embed in there.
You can add HTML to it as such:
echo '<html tags>' . str_replace(array('"', '"'), '', $matches[0][0]) . '</other html tags>';
-
The code is pulling the link from the forum so definitely this is a good start. Now the question is how to display it. Unfortunately I am not a coder :( Thanks for support Classic Sonic!
-
Well, that's a good sign. I'm looking at Aeva now and have tried some variations of using its functions to display a specific url to match, but it doesn't seem to be easy.
If this was only for YouTube links, I can easily make it work. Is that okay?
-
The most common are youtube and vimeo.
- any website would be supercalifragilisticexpialidocious
- youtube and vimeo I could cry from happiness
- youtube I will be more than happy
Thanks !
-
Find:
if (!empty($matches) && !empty($matches[0][0]))
echo str_replace(array('"', '"'), '', $matches[0][0]);
Replace with:
if (!empty($matches) && !empty($matches[0][0]))
{
$video = str_replace(array('"', '"'), '', $matches[0][0]);
echo '<object width="300" height="250"><param name="movie" value="', $video, '&hl=en&fs=1&color1=0x5d1719&color2=0xcd311b"></param><param name="allowFullScreen" value="true"></param><embed src="', $video, '&hl=en&fs=1&color1=0x5d1719&color2=0xcd311b" type="application/x-shockwave-flash" allowfullscreen="true" width="300" height="250"></embed></object>';
}
-
Yeap it works .... only youtube but it does the job. Thank you Classic Sonic! :applause:
Btw if anyone have an idea how to embed vimeo (or any other video sharing website) please add it here ;)
-
I just found one small problem with this code .... :'(
Just investigated a little bit further. And now I see empty space. There might be 2 reasons for that:
1. With this seconds setup ... it will hold the video for that time but after it runs out .... it leaves blank
eg. if it is set on 1h it will check for new vid every 1h, if it wont find any ... it will show empty space
2. someone post a link with youtube inside of it (but it is not related directly to video)
Is there a simple fix for it ?
Thank you
-
Try clearing your cache, for starters.
If you used a timed cache like above, then the cache is automatically emptied in order to show the last video.
I suppose I could modify it to insert yet another variable into the cache to remind itself, if you want.
I don't understand what you mean in 2
-
Yeap clearing the cache of the entire forum did the trick. But I prefer to be it rather automatic and like you mentioned "remind it self".
not a coder here .... but I assume that the code above search the forum for eg. "word word youtube word word" and it will try to load it anyway? I came to that conclusion after someone posted a link to youtube play list. And that's when things started to go wrong.
After all I am not sure about the main reasons of "empty block" ... but I would be grateful for solution.
Thanks
-
I want to use same coding to bring/search Youtube videos on portal.
But I have two different video boards and I would like to add only one
board's video on portal so how can I make changes that only specific
boards video appear on portal?
-
Sorry about my English.
please help I want mor Recently attached video 3 or more.
thank you Leekoberries.
(http://uppic.zubza.com/images/1331196021353_video.jpg)
-
Sorry about my English.
please help I want mor Recently attached video 3 or more.
thank you Leekoberries.
(http://uppic.zubza.com/images/1331196021353_video.jpg)
I want to use same coding to bring/search Youtube videos on portal.
Would you please start you own seperate topics for the requests otherwise these will go unanswered if unseen.
But I have two different video boards and I would like to add only one
board's video on portal so how can I make changes that only specific
boards video appear on portal?