Customization > Blocks and Modifications
Youtube Block - 1.0
Kryzen:
Youtube Block
v1.0
This block allows you to show a Youtube video within a block. I couldn't find an existing block that does this, so I decided to create one myself. The current version is 1.0 and I hope to release v1.1 soon.
Installing is very simple. Just create a new PHP code block and use this code:
--- Code: ---/**
* Youtube Block
*
* Written for: Simple Portal
* Written by: Dr. Deejay
* Compatible with: Simple Portal 2.3
* Version: 1.0
*
* When using this block, you agree that you will,
* not redistribute this block, with or without any
* changes. This code may not be used as a base for
* another software and should not be used for illegal
* purposes.
*/
$youtube = array();
/**
* Settings
*/
// The id of the video
$youtube['id'] = 't5AqJww06bw';
// Text to show below the video. Leave empty to disable
$youtube['label'] = 'My video';
// The size of the Youtube block. 1 is the smallest, 3 is the biggest
$youtube['size'] = 1;
/**
* The Youtube video display block
*/
if(!function_exists('sp_youtube')) {
/**
* The function doesn't exist yet. Create it.
*/
function sp_youtube($vid = '', $label = '', $size = '')
{
// Don't allow html stuff
$vid = htmlspecialchars($vid);
// Check if it is empty. If it is, it's invalid
if(empty($vid))
echo '
<div class="smalltext">Video not found.</div>';
// Let's see what we can do.
else {
// Echo the thing.
echo '
<div class="centertext">
<iframe ' . $size . ' src="http://www.youtube.com/embed/' . $vid . '" frameborder="0" allowfullscreen></iframe>';
// Show a label?
if(!empty($label))
echo '
<br /><div class="smalltext">' . $label . '</div>';
echo '
</div>';
}
}
}
// Generate the height and width
if($youtube['size'] == 1)
$vidsize = 'width="150" height="100"';
elseif($youtube['size'] == 2)
$vidsize = 'width="300" height="200"';
elseif($youtube['size'] == 3)
$vidsize = 'width="1280" height="720"';
else
$vidsize = 'width="150" height="100"';
// Call the function
sp_youtube($youtube['id'], $youtube['label'], $vidsize);
--- End code ---
Enjoy!
Dr. Deejay
KnightRaider:
Thanks you very much dr. deejay, I wish i had waited for this lol :P.
Kryzen:
You're welcome, glad you like it :)
ricland:
Brilliantly done.
Works so seamlessly.
Kryzen:
Thanks :)
Navigation
[0] Message Index
[#] Next page
Go to full version