
Show a random Youtube video on a page. Tho I guess you can resize and place it in a sidebar as well.
Yes there are a gazillion ways to do this but what the heck, this the way I did it - quick and easy and some control over what is available without having to download a stack of vids.
Create the UDT as follows :
1 create a Text file with the linklist as described in the script - But you can do it like this -
paste the youtube URL's you want from youtube into the text file, one per new line.
Each URL looks like this: http://www.youtube.com/watch?v=TebeNC-_VjA
We want them like this : http://www.youtube.com/v/TebeNC-_VjA
So when you pasted all of them, do a replace for the "watch?v=" with "v/" on the file

Now save the file, name it with the name you will use in the script and upload it to the directory you will use.
Its pretty easy to edit your list later if you want, just edit your test filelist - means you save cluttering up your database, installing a another gallery script etc and so on....
2 paste this code into the new UDT and call it {tv} in this case
Code: Select all
// An Ultra simple Flat File random YOUTUBE show
// See it in use on gmwit.com
//
// Build an array from the list of YouTube videos
// Replace thevideolist.txt with the path to your text file
// This will probably be something like "/home/accountname/public_html/foldername/etc"
//
// First - create your TXT file using Notepad or similar. Data is entered onto a new line.
// Each data item is in the format of the exact youtube video eg http://www.youtube.com/v/TebeNC-_VjA
//
// Save the TXT file and FTP it to your server. The directory is given in the File_handle variable.
// Im using the full path from the root Dir onwars eg "/home/youraccount/public_html/filedirectory/filename.txt"
//
// To use with CMS Made Simple, Place this code into a User Defined Tage (UDT) and name it whatever you want
// If you rename the tag, then you must also rename the tag in the Template
// Note - this example calls this UDT {tv}
//
// To use it as a normal PHP script, replace the usual opening ?php and the ? end tags and remove the \ escape characters.
// Warning - There are no bells or whistles in the script
//
// modify the File_handle to the exact path to your file
//
$video_array = file('/home/accountname/public_html/foldername/thevideolist.txt');
// Randomly pick one video from the array
$video = $video_array[mt_rand(0, count($video_array) - 1)];
$video = trim($video);
echo $video;

Code: Select all
<div style="width:425px;text-align:left;border:1px solid #CCCCCC;padding:10px;">
<span style=" font-family: Arial,Verdana; font-size: 12px; color:black; line-height:12px">
Your text goes here <br>
You can remove the "span" and "div" components if you wish
</span>
<br><br>
<object width="425" height="350"><param name="movie" value="{tv}"></param><param name="wmode" value="transparent"></param><embed src="{tv}" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>
</div>
If someone wants to extend it - I'd love to see the outcome and script

I guess there are lots of other ways to do this - but i didnt need to overload my database or run admin, or try to incorporate a gallery script etc and I wanted control over what vids were shown - ie my list only and not ones from some "favourite list" or "most viewed" etc

Keep well