SimplePortal

Customization => Custom Coding => Topic started by: yaosurfer on November 09, 2011, 10:05:36 AM

Title: Recently attached video
Post 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 !
Title: Re: Recently attached video
Post by: ccbtimewiz on November 09, 2011, 03:28:13 PM
Various ways to do that, but are you using Aeva Media to embed videos?
Title: Re: Recently attached video
Post by: yaosurfer on November 09, 2011, 04:31:24 PM
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
Title: Re: Recently attached video
Post by: ccbtimewiz on November 09, 2011, 04:46:28 PM
Is this on post-basis or thread-basis?
Title: Re: Recently attached video
Post by: yaosurfer on November 09, 2011, 04:51:04 PM
Ideally on posts but both versions (post - thread) would be much appreciated for testing purposes ;)
Title: Re: Recently attached video
Post by: ccbtimewiz on November 09, 2011, 05:21:45 PM
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?
Title: Re: Recently attached video
Post by: ccbtimewiz on November 09, 2011, 05:43:00 PM
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).

Code: [Select]
<?php

if (!cache_get_data('recent_video'))
{
$posts ssi_recentPosts(150nullnull'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('"''&quot;'), ''$matches[0][0]);

?>
Title: Re: Recently attached video
Post by: ccbtimewiz on November 09, 2011, 05:51:29 PM
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:

Code: [Select]
if (!cache_get_data('recent_video'))
Code: [Select]
cache_put_data('recent_video', $matches);
Code: [Select]
$matches = cache_get_data('recent_video');
And replace each one with the equiv:

Code: [Select]
if (!cache_get_data('recent_video', 10800))
Code: [Select]
cache_put_data('recent_video', $matches, 10800);
Code: [Select]
$matches = cache_get_data('recent_video', 10800);
Title: Re: Recently attached video
Post by: yaosurfer on November 09, 2011, 05:56:21 PM
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
Title: Re: Recently attached video
Post by: ccbtimewiz on November 09, 2011, 05:59:35 PM
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:
Code: [Select]
echo str_replace(array('"', '&quot;'), '', $matches[0][0]);
Replace with:
Code: [Select]
echo str_replace(array('"', '&quot;'), '', parse_bbc($matches[0][0]));
Title: Re: Recently attached video
Post by: yaosurfer on November 09, 2011, 06:03:00 PM
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)
Title: Re: Recently attached video
Post by: ccbtimewiz on November 09, 2011, 06:05:47 PM
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:
Code: [Select]
echo '<html tags>' . str_replace(array('"', '&quot;'), '', $matches[0][0]) . '</other html tags>';
Title: Re: Recently attached video
Post by: yaosurfer on November 09, 2011, 06:14:31 PM
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!
Title: Re: Recently attached video
Post by: ccbtimewiz on November 09, 2011, 06:16:08 PM
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?
Title: Re: Recently attached video
Post by: yaosurfer on November 09, 2011, 06:19:23 PM
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 !
Title: Re: Recently attached video
Post by: ccbtimewiz on November 09, 2011, 06:35:33 PM
Find:
Code: [Select]
if (!empty($matches) && !empty($matches[0][0]))
echo str_replace(array('"', '&quot;'), '', $matches[0][0]);

Replace with:
Code: [Select]
if (!empty($matches) && !empty($matches[0][0]))
{
$video = str_replace(array('"', '&quot;'), '',  $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>';
}
Title: Re: Recently attached video
Post by: yaosurfer on November 09, 2011, 07:59:22 PM
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   ;)
Title: Re: Recently attached video
Post by: yaosurfer on November 10, 2011, 11:57:09 AM
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
Title: Re: Recently attached video
Post by: ccbtimewiz on November 10, 2011, 05:34:27 PM
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
Title: Re: Recently attached video
Post by: yaosurfer on November 10, 2011, 05:53:59 PM
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
Title: Re: Recently attached video
Post by: pixeleyes on December 21, 2011, 09:19:32 AM
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?
Title: Re: Recently attached video
Post by: nontanun on March 08, 2012, 03:29:13 AM
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)

Title: Re: Recently attached video
Post by: Old Fossil on March 08, 2012, 02:56:47 PM
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?
SimplePortal 2.3.8 © 2008-2024, SimplePortal