Wordpress Plugin: Allowing YouTube Videos to Play Full Screen
So I was wonder if someone here might be able offer a solution. I'll post the code below. Thanks for any suggestions.
Main php file:
<?php
/*
Plugin Name: WP YouTube
Plugin URI: http://www.jenst.se/2007/11/01/wp-youtube
Description: WP YouTube allows you to control all the YouTube videos at the same time.
Author: Jens Törnell
Version: 2.0
Author URI: http://www.jenst.se
*/
function wpytAddCSS(){
echo '<link rel="stylesheet" type="text/css" href="'.get_option('siteurl').'/wp-content/plugins/wp-youtube/wp-youtube.css" />';
}
add_action('admin_head', 'wpytAddCSS');
function wpyoutube($tagnameInput, $youTubeID) { // Function to be called within themes
$contentTotalOutput;
$data_all = get_option("wpytProfileData");
$explodera = explode (',', $data_all);
for ($i=0; $i<sizeof($explodera)-1; $i++) {
$tagname = explode ('%t=', $explodera[$i]);
$tagname = explode ('%', $tagname[1]);
$tagname = $tagname[0];
if($tagname == $tagnameInput) {
$autoplay = explode ('%a=', $explodera[$i]);
$autoplay = $autoplay[1]{0};
if ($autoplay == "y") { $autoplay = "1"; }
$validxhtml = explode ('%v=', $explodera[$i]);
$validxhtml = $validxhtml[1]{0};
$relatedvideos = explode ('%r=', $explodera[$i]);
$relatedvideos = $relatedvideos[1]{0};
if ($relatedvideos == "y") {
$relatedvideos = "1";
}
else {
$relatedvideos = "0";
}
$border = explode ('%b=', $explodera[$i]);
$border = $border[1]{0};
if ($border == "y") { $border = "1"; }
$width = explode ('%w=', $explodera[$i]);
$width = explode ('%', $width[1]);
$width = $width[0];
$height = explode ('%h=', $explodera[$i]);
$height = explode ('%', $height[1]);
$height = $height[0];
$color = explode ('%c=', $explodera[$i]);
$color = $color[1]{0};
if ($color == 1) { $color1 = "0xd6d6d6"; $color2 = "0xf0f0f0"; }
else if ($color == 2) { $color1 = "0x3a3a3a"; $color2 = "0x999999"; }
else if ($color == 3) { $color1 = "0x2b405b"; $color2 = "0x6b8ab6"; }
else if ($color == 4) { $color1 = "0x006699"; $color2 = "0x54abd6"; }
else if ($color == 5) { $color1 = "0x234900"; $color2 = "0x4e9e00"; }
else if ($color == 6) { $color1 = "0xe1600f"; $color2 = "0xfebd01"; }
else if ($color == 7) { $color1 = "0xcc2550"; $color2 = "0xe87a9f"; }
else if ($color == 8) { $color1 = "0x402061"; $color2 = "0x9461ca"; }
else if ($color == 9) { $color1 = "0x5d1719"; $color2 = "0xcd311b"; }
else { $color1 = "0xd6d6d6"; $color2 = "0xf0f0f0"; }
$tagtype = explode ('%tt=', $explodera[$i]);
$tagtype = $tagtype[1]{0};
if($tagtype==1) {
$tagstart = "[" . $tagname . "]";
$tagend = "[/" . $tagname . "]";
}
else if ($tagtype==2) {
$tagstart = "<" . $tagname . ">";
$tagend = "</" . $tagname . ">";
}
if ($validxhtml == 'y') {
$contentTotalOutput = '<object type="application/x-shockwave-flash"';
if ($width != "" || $height != "") { $contentTotalOutput .= ' style="'; }
if ($width != "") { $contentTotalOutput .= 'width:'.$width.'px; '; }
if ($width != "") { $contentTotalOutput .= 'height:'.$height.'px;'; }
if ($width != "" || $height != "") { $contentTotalOutput .= '"'; }
$contentTotalOutput .= ' data="http://www.youtube.com/v/'.$youTubeID;
$contentTotalOutput .='&rel='.$relatedvideos;
if ($color1 != "") { $contentTotalOutput .='&color1='.$color1.'&color2='.$color2; }
if ($border != "") { $contentTotalOutput .='&border='.$border; }
if ($autoplay != "") { $contentTotalOutput .= '&autoplay='.$autoplay; }
$contentTotalOutput .= '">';
$contentTotalOutput .= '<param name="movie" value="http://www.youtube.com/v/'.$youTubeID;
if ($relatedvideos != "") { $contentTotalOutput .='&rel='.$relatedvideos; }
if ($color1 != "") { $contentTotalOutput .='&color1='.$color1.'&color2='.$color2; }
if ($border != "") { $contentTotalOutput .='&border='.$border; }
if ($autoplay != "") { $contentTotalOutput .= '&autoplay='.$autoplay; }
$contentTotalOutput .= '" /></object>';
$contentTotalOutput .= $contentAfter[1]; //Efteråt
}
else {
$contentTotalOutput = '<object';
if ($width != "") { $contentTotalOutput .= ' width="'.$width.'"'; }
if ($height != "") { $contentTotalOutput .= ' height="'.$height.'"'; }
$contentTotalOutput .= '>';
$contentTotalOutput .= '<param name="movie" value="http://www.youtube.com/v/'.$youTubeID;
$contentTotalOutput .='&rel='.$relatedvideos;
if ($color1 != "") { $contentTotalOutput .='&color1='.$color1.'&color2='.$color2; }
if ($border != "") { $contentTotalOutput .='&border='.$border; }
if ($autoplay != "") { $contentTotalOutput .= '&autoplay='.$autoplay; }
$contentTotalOutput .= '"></param>';
$contentTotalOutput .= '<param name="wmode" value="transparent"></param>';
$contentTotalOutput .= '<embed src="http://www.youtube.com/v/'.$youTubeID;
if ($relatedvideos != "") { $contentTotalOutput .='&rel='.$relatedvideos; }
if ($color1 != "") { $contentTotalOutput .='&color1='.$color1.'&color2='.$color2; }
if ($border != "") { $contentTotalOutput .='&border='.$border; }
if ($autoplay != "") { $contentTotalOutput .= '&autoplay='.$autoplay; }
$contentTotalOutput .= '" type="application/x-shockwave-flash" wmode="transparent"';
if ($width != "") { $contentTotalOutput .= ' width="'.$width.'"'; }
if ($height != "") { $contentTotalOutput .= ' height="'.$height.'"'; }
$contentTotalOutput .= '></object>';
$contentTotalOutput .= $contentAfter[1]; //Efteråt
}
echo $contentTotalOutput;
}
}
}
function wpytRemoveProfileData() {
delete_option("wpytProfileData");
}
function wpytDeleteOldData() {
delete_option("option_youtube_width");
delete_option("option_youtube_height");
delete_option("option_youtube_tag_name");
delete_option("option_youtube_tagtype");
delete_option("option_youtube_color");
delete_option("option_youtube_border");
delete_option("option_youtube_related");
delete_option("option_youtube_valid");
delete_option("option_youtube_autoplay");
}
function wpytModifyContent($content){
$contentTotalOutput; // Total utskrivning
$data_all = get_option("wpytProfileData");
$explodera = explode (',', $data_all);
for ($i=0; $i<sizeof($explodera)-1; $i++) {
$autoplay = explode ('%a=', $explodera[$i]);
$autoplay = $autoplay[1]{0};
if ($autoplay == "y") { $autoplay = "1"; }
$validxhtml = explode ('%v=', $explodera[$i]);
$validxhtml = $validxhtml[1]{0};
$relatedvideos = explode ('%r=', $explodera[$i]);
$relatedvideos = $relatedvideos[1]{0};
if ($relatedvideos == "y") {
$relatedvideos = "1";
}
else {
$relatedvideos = "0";
}
$border = explode ('%b=', $explodera[$i]);
$border = $border[1]{0};
if ($border == "y") { $border = "1"; }
$width = explode ('%w=', $explodera[$i]);
$width = explode ('%', $width[1]);
$width = $width[0];
$height = explode ('%h=', $explodera[$i]);
$height = explode ('%', $height[1]);
$height = $height[0];
$color = explode ('%c=', $explodera[$i]);
$color = $color[1]{0};
if ($color == 1) { $color1 = "0xd6d6d6"; $color2 = "0xf0f0f0"; }
else if ($color == 2) { $color1 = "0x3a3a3a"; $color2 = "0x999999"; }
else if ($color == 3) { $color1 = "0x2b405b"; $color2 = "0x6b8ab6"; }
else if ($color == 4) { $color1 = "0x006699"; $color2 = "0x54abd6"; }
else if ($color == 5) { $color1 = "0x234900"; $color2 = "0x4e9e00"; }
else if ($color == 6) { $color1 = "0xe1600f"; $color2 = "0xfebd01"; }
else if ($color == 7) { $color1 = "0xcc2550"; $color2 = "0xe87a9f"; }
else if ($color == 8) { $color1 = "0x402061"; $color2 = "0x9461ca"; }
else if ($color == 9) { $color1 = "0x5d1719"; $color2 = "0xcd311b"; }
else { $color1 = "0xd6d6d6"; $color2 = "0xf0f0f0"; }
$tagtype = explode ('%tt=', $explodera[$i]);
$tagtype = $tagtype[1]{0};
$tagname = explode ('%t=', $explodera[$i]);
$tagname = explode ('%', $tagname[1]);
$tagname = $tagname[0];
if($tagtype==1) {
$tagstart = "[" . $tagname . "]";
$tagend = "[/" . $tagname . "]";
}
else if ($tagtype==2) {
$tagstart = "<" . $tagname . ">";
$tagend = "</" . $tagname . ">";
}
$contentBefore = explode($tagstart,$content);
$contentTotalOutput = $contentBefore[0];
for($j=1; $j<sizeof($contentBefore); $j++) {
if ($validxhtml == 'y') {
$contentAfter = explode ($tagend, $contentBefore[$j]);
$youTubeID = $contentAfter[0];
$contentTotalOutput .= '<object type="application/x-shockwave-flash"';
if ($width != "" || $height != "") { $contentTotalOutput .= ' style="'; }
if ($width != "") { $contentTotalOutput .= 'width:'.$width.'px; '; }
if ($width != "") { $contentTotalOutput .= 'height:'.$height.'px;'; }
if ($width != "" || $height != "") { $contentTotalOutput .= '"'; }
$contentTotalOutput .= ' data="http://www.youtube.com/v/'.$youTubeID;
$contentTotalOutput .='&rel='.$relatedvideos;
if ($color1 != "") { $contentTotalOutput .='&color1='.$color1.'&color2='.$color2; }
if ($border != "") { $contentTotalOutput .='&border='.$border; }
if ($autoplay != "") { $contentTotalOutput .= '&autoplay='.$autoplay; }
$contentTotalOutput .= '">';
$contentTotalOutput .= '<param name="movie" value="http://www.youtube.com/v/'.$youTubeID;
if ($relatedvideos != "") { $contentTotalOutput .='&rel='.$relatedvideos; }
if ($color1 != "") { $contentTotalOutput .='&color1='.$color1.'&color2='.$color2; }
if ($border != "") { $contentTotalOutput .='&border='.$border; }
if ($autoplay != "") { $contentTotalOutput .= '&autoplay='.$autoplay; }
$contentTotalOutput .= '" /></object>';
$contentTotalOutput .= $contentAfter[1];
}
else {
$contentAfter = explode ($tagend, $contentBefore[$j]);
$youTubeID = $contentAfter[0];
$contentTotalOutput .= '<object';
if ($width != "") { $contentTotalOutput .= ' width="'.$width.'"'; }
if ($height != "") { $contentTotalOutput .= ' height="'.$height.'"'; }
$contentTotalOutput .= '>';
$contentTotalOutput .= '<param name="movie" value="http://www.youtube.com/v/'.$youTubeID;
$contentTotalOutput .='&rel='.$relatedvideos;
if ($color1 != "") { $contentTotalOutput .='&color1='.$color1.'&color2='.$color2; }
if ($border != "") { $contentTotalOutput .='&border='.$border; }
if ($autoplay != "") { $contentTotalOutput .= '&autoplay='.$autoplay; }
$contentTotalOutput .= '"></param>';
$contentTotalOutput .= '<param name="wmode" value="transparent"></param>';
$contentTotalOutput .= '<embed src="http://www.youtube.com/v/'.$youTubeID;
if ($relatedvideos != "") { $contentTotalOutput .='&rel='.$relatedvideos; }
if ($color1 != "") { $contentTotalOutput .='&color1='.$color1.'&color2='.$color2; }
if ($border != "") { $contentTotalOutput .='&border='.$border; }
if ($autoplay != "") { $contentTotalOutput .= '&autoplay='.$autoplay; }
$contentTotalOutput .= '" type="application/x-shockwave-flash" wmode="transparent"';
if ($width != "") { $contentTotalOutput .= ' width="'.$width.'"'; }
if ($height != "") { $contentTotalOutput .= ' height="'.$height.'"'; }
$contentTotalOutput .= '></object>';
$contentTotalOutput .= $contentAfter[1]; //Efteråt
}
}
$content = $contentTotalOutput;
}
return $content;
}
add_filter('the_content','wpytModifyContent');
function wpytAdmin(){
if(isset($_POST['Submit'])){
$data_all = get_option("wpytProfileData");
$inputData = $_POST['codeString'];
$explodera = explode (',', $data_all);
update_option("wpytProfileData", $inputData);
echo "<div id=\"message\" class=\"updated fade\"><p><strong>WP YouTube profiles saved</strong></p></div>"."\n";
}
if(isset($_POST['removeProfileDataButton'])) {
wpytRemoveProfileData();
echo "<div id=\"message\" class=\"updated fade\"><p><strong>WP YouTube profile data deleted</strong></p></div>"."\n";
}
if(isset($_POST['deleteOldButton'])) {
wpytDeleteOldData();
echo "<div id=\"message\" class=\"updated fade\"><p><strong>WP YouTube old profile data deleted</strong></p></div>"."\n";
}
echo '<script src="'.get_option('siteurl').'/wp-content/plugins/wp-youtube/wp-youtube.js"></script>'."\n";
echo '<div class="wrap">'."\n";
echo '<input type="hidden" value="'.get_option('siteurl').'" id="siteURL" />'."\n";
$data_all = get_option("wpytProfileData");
// Import old WP YouTube values
$width = get_option("option_youtube_width");
$height = get_option("option_youtube_height");
$tagname = get_option("option_youtube_tag_name");
$tagtype = get_option("option_youtube_tagtype");
$color = get_option("option_youtube_color");
$border = get_option("option_youtube_border");
$relatedvideos = get_option("option_youtube_related");
$validxhtml = get_option("option_youtube_valid");
$autoplay = get_option("option_youtube_autoplay");
if($data_all == "" && ($width != "" || $height != "" || $tagname != "" || $color != "" || $relatedvideos != "" || $validxhtml != "" || $autoplay != "" || $tagtype!="" )){
for ($i=1;$i<10;$i++) {
if ($color =="wpyt_color".$i){
$color = $i;
}
}
if ($tagtype =="wpyt_tagtype1"){ $tagtype = 1; }
else if ($tagtype =="wpyt_tagtype2"){ $tagtype = 2; }
if ($border=="on"){ $border = "y"; }
if ($relatedvideos=="on"){ $relatedvideos = "y"; }
if ($validxhtml=="on"){ $validxhtml = "y"; }
if ($autoplay=="on"){ $autoplay = "y"; }
$length = 2;
for ($i=1; $i<$length; $i++) { $history .= $i . ","; }
echo "<form method='post' action='".$_SERVER['PHP_self']."' name='options' target='_self'>"."\n";
$inputData = get_option("wpytProfileData");
echo '<textarea style="width: 100%; display: none;" id="codeString" name="codeString">';
echo '%t=' . $tagname;
echo '%w=' . $width;
echo '%h=' . $height;
echo '%c=' . $color;
echo '%a=' . $autoplay;
echo '%v=' . $validxhtml;
echo '%r=' . $relatedvideos;
echo '%b=' . $border;
echo '%tt=' . $tagtype . ",";
echo '</textarea>'."\n";
echo '<textarea style="width: 100%; display: none;" id="history" name="history">' . $history . '</textarea>'."\n";
echo '<h2>WP YouTube - Profile editor</h2>'."\n";
echo '<p class="submit"><input class="button" style="float: left;" type="button" value="Create new profile" onclick="wpytAddElement('.$length.');" /><input type="submit" name="Submit" value="Save profiles »" onclick="return wpytOptionCheckEqual()" /></p>'."\n";
echo '<div id="myDiv">'."\n";
echo '<div id="introText" class="introText" style="color:black;';
if(sizeof($explodera) != 1){ echo 'display:none;'; }
echo '">Click <strong>"Create new profile"</strong> to get started or read the instructions</div>'."\n";
echo '<noscript class="introText"><br />Your browser does not support javascript! WP YouTube 2 requires Javascript to administrate.<br />'."\n";
echo 'If you can\'t use Javascript you can use <a href="http://www.jenst.se/2007/11/01/wp-youtube">WP YouTube 0.9</a></noscript>'."\n";
$js = "n";
$i=0;
echo '<div id="my'.($i).'Div">'."\n";
echo '<script type="text/javascript">document.write(wpytGenerateInnerHTML('.($i+1);
echo ',"'.$tagname;
echo '","'.$width;
echo '","'.$height;
if ($color!='%') { echo '","'.$color; } else { echo '","'.$color = ""; }
if ($autoplay!='n') { echo '","'.$autoplay; } else { echo '","'.$autoplay = ""; }
if ($border!='n') { echo '","'.$border; } else { echo '","'.$border = ""; }
if ($relatedvideos!='n') { echo '","'.$relatedvideos; } else { echo '","'.$relatedvideos = ""; }
if ($validxhtml!='n') { echo '","'.$validxhtml; } else { echo '","'.$validxhtml = ""; }
if ($tagtype!='%') { echo '","'.$tagtype; } else { echo '","'.$tagtype = ""; }
echo '","'.$js;
echo '")); </script>'."\n";
echo '</div>'."\n";
echo '<input id="length" type="hidden" value="' . ($length-1) . '" />'."\n";
// }
echo '<script type="text/javascript">alert(\'WP YouTube discovered a previous version of the plugin.\nClick \"Save profiles\" to use it!\n\nYou can remove old WP YouTube data at the bottom of this page.\');</script>';
}
else {
$explodera = explode (',', $data_all);
$length = sizeof($explodera);
$history = "";
for ($i=1; $i<$length; $i++) { $history .= $i . ","; }
echo "<form method='post' action='".$_SERVER['PHP_self']."' name='options' target='_self'>"."\n";
$inputData = get_option("wpytProfileData");
echo '<textarea style="width: 100%; display: none;" id="codeString" name="codeString">' . $inputData . '</textarea>'."\n";
echo '<textarea style="width: 100%; display: none;" rows="1" id="history" name="history">' . $history . '</textarea>'."\n";
echo '<h2>WP YouTube - Profile editor</h2>'."\n";
echo '<p class="submit"><input class="button" style="float: left;" type="button" value="Create new profile" onclick="wpytAddElement('.$length.');" /><input type="submit" name="Submit" value="Save profiles »" onclick="return wpytOptionCheckEqual()" /></p>'."\n";
echo '<div id="myDiv">'."\n";
echo '<div id="introText" class="introText" style="color:black;';
if(sizeof($explodera) != 1){ echo 'display:none;'; }
echo '">Click <strong>"Create new profile"</strong> to get started or read the instructions</div>'."\n";
echo '<noscript class="introText"><br />Your browser does not support javascript! WP YouTube 2 requires Javascript to administrate.<br />'."\n";
echo 'If you can\'t use Javascript you can use <a href="http://www.jenst.se/2007/11/01/wp-youtube">WP YouTube 0.9</a></noscript>'."\n";
for ($i=0; $i<sizeof($explodera)-1; $i++) {
$autoplay = explode ('%a=', $explodera[$i]);
$autoplay = $autoplay[1]{0};
$validxhtml = explode ('%v=', $explodera[$i]);
$validxhtml = $validxhtml[1]{0};
$relatedvideos = explode ('%r=', $explodera[$i]);
$relatedvideos = $relatedvideos[1]{0};
$border = explode ('%b=', $explodera[$i]);
$border = $border[1]{0};
$width = explode ('%w=', $explodera[$i]);
$width = explode ('%', $width[1]);
$width = $width[0];
$height = explode ('%h=', $explodera[$i]);
$height = explode ('%', $height[1]);
$height = $height[0];
$color = explode ('%c=', $explodera[$i]);
$color = $color[1]{0};
$tagtype = explode ('%tt=', $explodera[$i]);
$tagtype = $tagtype[1]{0};
$tagname = explode ('%t=', $explodera[$i]);
$tagname = explode ('%', $tagname[1]);
$tagname = $tagname[0];
$js = "n";
echo '<div id="my'.($i).'Div">'."\n";
echo '<script type="text/javascript">document.write(wpytGenerateInnerHTML('.($i+1);
echo ',"'.$tagname;
echo '","'.$width;
echo '","'.$height;
if ($color!='%') { echo '","'.$color; } else { echo '","'.$color = ""; }
if ($autoplay!='n') { echo '","'.$autoplay; } else { echo '","'.$autoplay = ""; }
if ($border!='n') { echo '","'.$border; } else { echo '","'.$border = ""; }
if ($relatedvideos!='n') { echo '","'.$relatedvideos; } else { echo '","'.$relatedvideos = ""; }
if ($validxhtml!='n') { echo '","'.$validxhtml; } else { echo '","'.$validxhtml = ""; }
if ($tagtype!='%') { echo '","'.$tagtype; } else { echo '","'.$tagtype = ""; }
echo '","'.$js;
echo '")); </script>'."\n";
echo '</div>'."\n";
}
echo '<input id="length" type="hidden" value="' . ($length-1) . '" />'."\n";
}
?>
</div>
<input type="hidden" value="0" id="theValue" />
<p class="submit">
<input id="removeAllButton" style="float: left;<?php if ($data_all == "") { echo ' display:none;'; } ?>" type="button" class="button delete" value="Remove all profiles" onclick="wpytRemoveAll()" />
<input type="submit" name="Submit" value="Save profiles »" />
</p>
<h2>Instructions - Get started</h2>
<ol>
<li><strong>Create new profile</strong><br />
The first thing you do is to create a new profile. The profile contains all the options you might need.<br />
ONE profile can be used with many videos, as many as you need.</li>
<li><strong>Set a tag name</strong><br />
If you create more than one profile the tag names must be unique. Save the profile / profiles when you are done.</li>
<li><strong>Find a YouTube ID</strong><br />
The ID is presented last of a YouTube URL:<br />
http://www.youtube.com/watch?v=<span style="color: red;">YjYT5OLoR8U</span></li>
<li><strong>Put in a post or a page</strong><br />
Put tag name and YouTube ID together and place it in a post or a page.<br /><br />
<strong>Example:</strong><br />
[your_tagname]<span style="color: red;">YjYT5OLoR8U</span>[/your_tagname].<br /><br />
You can always see what your tag looks like in your profile.</li>
</ol>
<h2>Information - Options</h2>
<table style="width: 100%;">
<tr>
<td style="width: 50%;"><strong>Tagname</strong><br />
Use only numbers and letters (a-z and 0-9)</td>
<td><strong>Width / Height</strong><br />
Maximum width and height</td>
</tr>
<tr>
<td><strong>Color</strong><br />
The color of the YouTube player</td>
<td><strong>Autoplay</strong><br />
Plays the video automatically on load</td>
</tr>
<tr>
<td><strong>ValidXHTML</strong><br />
The embeded code validates with <a href="http://validator.w3.org">W3C HTML validator</a></td>
<td><strong>Border</strong><br />
Border around the YouTube player</td>
</tr>
<tr>
<td><strong>Tag type</strong><br />
[ ] works in both visual and code mode.<br />
< > works only in code mode.</td>
<td><strong>Delete</strong><br />
Removes the profile. This action is not saved until you "Save profiles".</td>
</tr>
</table><br />
<h2>Information - Misc</h2>
<table style="width: 100%;">
<tr style="width: 50%;">
<td><strong>Save profiles</strong><br />
Saves all your profiles into a single database field</td>
<td><strong>Remove all profiles</strong><br />
Removes all your profiles. This action is not saved until you "Save profiles".</td>
</tr>
<tr>
<td><strong>Advanced theme use</strong><br />
Put tag name and YouTube ID together and place it in your theme:<br />
<?php wpyoutube ('your_tagname','<span style="color: red;">YjYT5OLoR8U</span>' ?>
</td>
</tr>
</table><br />
<h2>Database clean up (for uninstall)</h2>
<p>If you for some reason want to uninstall WP YouTube, you can delete the related data saved into the database.</p>
<input type="submit" name="removeProfileDataButton" class="button delete" value="Delete Options" onclick="return confirm('Remove options from database? (cannot be undone)')" />
<br /><br />
<h2>Delete old version WP YouTube data</h2>
<p>If you have decided to use this version of WP YouTube, there is no need to keep old database values.</p>
<input type="submit" name="deleteOldButton" class="button delete" value="Delete Options" onclick="return confirm('Remove old WP YouTube data from database? (cannot be undone)')" />
</form>
</div>
<?php
}
function wpytAddMenu() {
add_submenu_page('edit.php', 'WP YouTube Profile Editor', 'YouTube Profiles', 10, __FILE__, 'wpytAdmin');
}
add_action('admin_menu', 'wpytAddMenu');
?> JS File (not sure if this matters or not)
function wpytOptionCheckEqual (){
var codeString = document.getElementById('codeString').value;
var splitCode = codeString.split("%t=");
totalCount = splitCode.length-1;
var splitCodeText;
var splitText1;
var equalName = false;
var emptyName = false;
for(i=0;i<totalCount;i++) {
splitCodeText = splitCode[i+1].split("%");
splitText1 = splitCodeText[0];
for(j=0;j<totalCount;j++) {
splitCodeText2 = splitCode[j+1].split("%");
splitText2 = splitCodeText2[0];
if (splitText1 == splitText2 && j != i) {
equalName = true;
}
}
if (splitText1 == "") {
emptyName = true;
}
}
if (emptyName == true) {
alert('Profiles could NOT be saved.\nYou must have a tag name!');
return false;
}
if (equalName == true) {
alert('Profiles could NOT be saved.\nYou cannot have the same tag name twice!');
return false;
}
else {
return true;
}
}
function wpytGenerateInnerHTML(id, tagname, width, height, color, autoplay, border, relatedvideos, validxhtml, tagtype, js) {
id=id-1;
if(color == null) { color = 1; }
var html = '<table class="wpyt-profile" id="innerTable'+id+'" style="width: 100%; border: 1px solid #ccc;';
var siteURL = document.getElementById('siteURL').value;
html += '">';
html += '<tr>';
html += '<td rowspan="6">';
html += '<div id="youtube-preview'+id+'">';
html += '<img src="'+siteURL+'/wp-content/plugins/wp-youtube/youtube-preview/';
if (border =="y"){ html += 'border'; }
else { html += 'color'; }
html += color+'.gif" alt="" />';
html += '<\/div>';
html += '<\/td>';
html += '<td>Tag name:<\/td>\n<td>Width:<\/td>\n<td>Height:<\/td>\n';
html += '<\/tr>';
html += '<tr>';
html += '<td><input onkeyup="wpytOuterCodeStatic('+id+'), wpytProfileTag('+id+'), wpytProfileThemeTag('+id+');" name="tagname'+id+'" id="tagname'+id+'" type="text" style="width:90%;" value="'
if (js!=null) { html += tagname; } else { tagname='wpyt_profile'+(id+1); html += tagname; }
html += '" /><\/td>\n';
html += '<td><input onkeyup="wpytOuterCodeStatic('+id+')" id="width'+id+'" name="width'+id+'" type="text" style="width:90%;" value="';
if (js=='n') { html += width; } else { html += '425'; }
html += '" /><\/td>\n';
html += '<td><input onkeyup="wpytOuterCodeStatic('+id+')" id="height'+id+'" name="height'+id+'" type="text" style="width:90%;" value="';
if (js!=null) { html += height; } else { html += '355'; }
html += '" /><\/td>\n';
html += '<td rowspan="2">';
html += '<table>';
html += '<tr>';
html += '<td><input onclick="wpytOuterCodeStatic('+id+')" type="checkbox" name="autoplay'+id+'" id="autoplay'+id+'"';
if (autoplay == 'y') { html += ' checked'; }
html += '><\/td>\n';
html += '<td style="padding-right: 20px;">Autoplay<\/td>\n';
html += '<td><input onclick="wpytOuterCodeStatic('+id+'), wpytPreview('+id+',\''+color+'\',\''+border+'\');" type="checkbox" name="border'+id+'" id="border'+id+'"';
if (border == 'y') { html += ' checked'; }
html += '><\/td>\n';
html += '<td style="padding-right: 20px;">Border<\/td>\n';
html += '<td align="center" style="width: 50px;">[ <input id="tagtype1_'+id+'" onclick="wpytProfileTag('+id+'), wpytOuterCodeStatic('+id+')" type="radio" name="tagtype'+id+'" value="1"';
if (tagtype==1 || js!='n') { tagtype=1; html += ' checked="checked"'; }
html += '> ]<\/td>\n';
html += '<\/tr><tr>';
html += '<td><input onclick="wpytOuterCodeStatic('+id+')" type="checkbox" name="relatedvideos'+id+'" id="relatedvideos'+id+'"';
if (relatedvideos == 'y') { html += ' checked'; }
html += '><\/td>\n';
html += '<td style="padding-right: 20px;">Related videos<\/td>\n';
html += '<td><input onclick="wpytOuterCodeStatic('+id+')" type="checkbox" name="validxhtml'+id+'" id="validxhtml'+id+'"';
if (validxhtml == 'y') { html += ' checked'; }
html += '><\/td>\n';
html += '<td style="padding-right: 20px;">Valid XHTML <\/td>\n';
html += '<td align="center" style="width: 50px;">< <input id="tagtype2_'+id+'" onclick="wpytProfileTag('+id+'), wpytOuterCodeStatic('+id+')" type="radio" name="tagtype'+id+'" value="2"';
if (tagtype==2) { html += ' checked="checked"'; }
html += '> ><\/td>\n';
html += '<\/tr>';
html += '<\/table>';
html += '<\/td>\n';
html += '<\/tr>';
html += '<tr>';
html += '<td colspan="3">';
html += '<table style="width: 100%;">';
html += '<tr>';
html += '<td class="wpyt-color" style="background: #ababab;"><input onclick="wpytOuterCodeStatic('+id+'), wpytPreview('+id+',1,\''+border+'\');" type="radio" name="color'+id+'" value="1"';
if (color==1 || js!='n') { html += ' checked="checked"'; }
html += '><\/td>\n';
html += '<td class="wpyt-color" style="background: #6a6a6a;"><input onclick="wpytOuterCodeStatic('+id+'), wpytPreview('+id+',2,\''+border+'\');" type="radio" name="color'+id+'" value="2"';
if (color==2) { html += ' checked="checked"'; }
html += '><\/td>\n';
html += '<td class="wpyt-color" style="background: #4b6589;"><input onclick="wpytOuterCodeStatic('+id+'), wpytPreview('+id+',3,\''+border+'\');" type="radio" name="color'+id+'" value="3"';
if (color==3) { html += ' checked="checked"'; }
html += '><\/td>\n';
html += '<td class="wpyt-color" style="background: #2a89b8;"><input onclick="wpytOuterCodeStatic('+id+'), wpytPreview('+id+',4,\''+border+'\');" type="radio" name="color'+id+'" value="4"';
if (color==4) { html += ' checked="checked"'; }
html += '><\/td>\n';
html += '<td class="wpyt-color" style="background: #397400;"><input onclick="wpytOuterCodeStatic('+id+'), wpytPreview('+id+',5,\''+border+'\');" type="radio" name="color'+id+'" value="5"';
if (color==5) { html += ' checked="checked"'; }
html += '><\/td>\n';
html += '<td class="wpyt-color" style="background: #f08f08;"><input onclick="wpytOuterCodeStatic('+id+'), wpytPreview('+id+',6,\''+border+'\');" type="radio" name="color'+id+'" value="6"';
if (color==6) { html += ' checked="checked"'; }
html += '><\/td>\n';
html += '<td class="wpyt-color" style="background: #da5078;"><input onclick="wpytOuterCodeStatic('+id+'), wpytPreview('+id+',7,\''+border+'\');" type="radio" name="color'+id+'" value="7"';
if (color==7) { html += ' checked="checked"'; }
html += '><\/td>\n';
html += '<td class="wpyt-color" style="background: #6a4196;"><input onclick="wpytOuterCodeStatic('+id+'), wpytPreview('+id+',8,\''+border+'\');" type="radio" name="color'+id+'" value="8"';
if (color==8) { html += ' checked="checked"'; }
html += '><\/td>\n';
html += '<td class="wpyt-color" style="background: #95241a;"><input onclick="wpytOuterCodeStatic('+id+'), wpytPreview('+id+',9,\''+border+'\');" type="radio" name="color'+id+'" value="9"';
if (color==9) { html += ' checked="checked"'; }
html += '><\/td>\n';
html += '<\/tr>';
html += '<\/table>';
html += '<\/td>\n';
html += '<\/tr>';
html += '<td colspan="8">';
html += '<table style="width: 100%;">';
html += '<tr>';
html += '<td>';
html += '<br />';
html += '<div id="displayTag'+id+'">';
var tagOutput = '';
if (tagtype == 1) {
tagOutput += '[' + tagname + ']';
tagOutput += 'your_youtube_id';
tagOutput += '[/' + tagname + ']';
tagOutput += '<strong> (paste in posts or pages)</strong>';
}
else {
tagOutput += '<' + tagname + '>';
tagOutput += 'your_youtube_id';
tagOutput += '</' + tagname + '>';
tagOutput += '<strong> (paste in posts or pages, code editor required)</strong>';
}
html += tagOutput;
html += '<\/div>';
html += '<\/td><\/tr>\n';
html += '<tr>';
html += '<td>';
html += '<div id="displayThemeTag'+id+'">';
html += '<?php wpyoutube (\'' + tagname + '\', \'youtube_id\')'+' ?> <strong>(advanced theme use)</strong>';
html += '<\/div>';
html += '<\/td>\n';
html += '<\/td>';
html += '<\/tr>';
html += '<\/table>';
html += '<\/tr>';
html += '<tr>';
html += '<td colspan="8">';
html += '<input style="width: 100%;" type="hidden" id="innerCode'+id+'" name="innerCode'+id+'" value="';
html += '%t=' + tagname;
if(js=='n') { html += '%w=' + width; } else { html += '%w='; }
if(js=='n') {html += '%h=' + height; } else { html += '%h='; }
if(js=='n' && color!="") {html += '%c=' + color; }
if(js=='n' && autoplay!="") {html += '%a=' + autoplay; }
if(js=='n' && validxhtml!="") {html += '%v=' + validxhtml; }
if(js=='n' && relatedvideos!="") {html += '%r=' + relatedvideos; }
if(js=='n' && border!="" || border=='n') {html += '%b=' + border; }
if(js=='n' && tagtype!="") {html += '%tt=' + tagtype; }
html += '" />';
html += '<\/td>\n';
html += '<\/tr>';
html += '<tr>';
html += '<td><input class="button delete" value="Remove profile" type="button" onclick="wpytHistoryRemove('+(id+1)+')"/><\/td>\n';
html += '<\/table>';
return html;
}
function wpytPreview(id, color, border) {
var border = document.getElementById('border'+(id));
var previewImage = document.getElementById('youtube-preview'+id);
var siteURL = document.getElementById('siteURL').value;
var preview;
var color ="";
var getColor=document.getElementsByName('color' + id);
for (i=0; i<9; i++) {
if(getColor[i].checked) { color = i+1; }
}
preview = '<img src="'+siteURL+'/wp-content/plugins/wp-youtube/youtube-preview/';
if(border.checked == true){
preview += 'border';
}
else {
preview += 'color';
}
preview += color+'.gif" alt="" />';
previewImage.innerHTML = preview;
}
/*function wpytUpdateInnerHTML(id) {
var codeString = document.getElementById('codeString');
var innerCode = document.getElementById('innerCode' + id);
var width = document.getElementById('width' + id);
var height = document.getElementById('height' + id);
innerCode.value = width.value + "+" + height.value;
codeString.value = innerCode.value;
}*/
function wpytRemoveElement(id) {
var d = document.getElementById('myDiv');
var olddiv = document.getElementById("my" + id + "Div");
d.removeChild(olddiv);
}
function wpytProfileTag(id) {
var tagname = document.getElementById('tagname' + id).value;
var tagtype = document.getElementById('tagtype1_' + id);
var displayTag = document.getElementById('displayTag'+id);
var tagOutput = '';
if (tagtype.checked == true) {
tagOutput += '[' + tagname + ']';
tagOutput += 'your_youtube_id';
tagOutput += '[/' + tagname + ']';
tagOutput += '<strong> (paste in posts or pages)</strong>';
}
else {
tagOutput += '<' + tagname + '>';
tagOutput += 'youtube_id';
tagOutput += '</' + tagname + '>';
tagOutput += '<strong> (paste in posts or pages, code editor required)</strong>';
}
displayTag.innerHTML = tagOutput;
}
function wpytProfileThemeTag(id) {
var tagname = document.getElementById('tagname' + id).value;
var displayThemeTag = document.getElementById('displayThemeTag'+id);
displayThemeTag.innerHTML = '<?php wpyoutube (\'' + tagname + '\', \'<span style="color:red;">youtube_id<\/span>\')'+' ?>';
}
function wpytInnerCodeStatic(id) {
var innerCode = document.getElementById('innerCode' + id);
var tagname = document.getElementById('tagname' + id).value;
var width = document.getElementById('width' + id);
var height = document.getElementById('height' + id);
var autoplay = document.getElementById('autoplay' + id);
var validxhtml = document.getElementById('validxhtml' + id);
var relatedvideos = document.getElementById('relatedvideos' + id);
var border = document.getElementById('border' + id);
var color = "";
var tagtype = "";
var getColor=document.getElementsByName('color' + id);
var getTagtype=document.getElementsByName('tagtype' + id);
var innerTable = document.getElementById('innerTable' + id);
for (i=0; i<9; i++) {
if(getColor[i].checked) { color = i+1; }
}
for (i=0; i<2; i++) {
if(getTagtype[i].checked) { tagtype = i+1; }
}
if (autoplay.checked == true) { autoplay = "y"; } else { autoplay = "n" }
if (validxhtml.checked == true) { validxhtml = "y"; } else { validxhtml = "n" }
if (relatedvideos.checked == true) { relatedvideos = "y"; } else { relatedvideos = "n" }
if (border.checked == true) { border = "y"; } else { border = "n" }
innerCode.value = "%t=" + tagname;
innerCode.value += "%w=" + width.value;
innerCode.value += "%h=" + height.value;
if(color!='') { innerCode.value += "%c=" + color; }
if(autoplay!='n') { innerCode.value += "%a=" + autoplay; }
if(validxhtml!='n') { innerCode.value += "%v=" + validxhtml; }
if(relatedvideos!='n') { innerCode.value += "%r=" + relatedvideos; }
if(border!='n') { innerCode.value += "%b=" + border; }
innerCode.value += "%tt=" + tagtype;
}
function wpytOuterCodeStatic(id) {
var codeString = document.getElementById('codeString');
var innerCode = document.getElementById('innerCode' + id);
var history = document.getElementById('history').value;
var splitHistory = new Array();
splitHistory = history.split(",");
wpytInnerCodeStatic(id);
codeString.value = "";
for(i=0; i<splitHistory.length-1;i++) {
historyID = splitHistory[i]-1;
if (i==splitHistory.length-1) {
codeString.value += document.getElementById('innerCode' + historyID).value;
}
else {
codeString.value += document.getElementById('innerCode' + historyID).value + ",";
}
}
}
function wpytHistoryRemove(id) {
if (confirm('Remove this profile?'))
wpytRemoveElement(id-1);
var codeString = document.getElementById('codeString');
codeString.value = "";
var innerCode;
var history = document.getElementById('history');
history.value = history.value.replace((id)+",","");
teststring = history.value.split(",");
for(i=0;i<teststring.length-1;i++) {
codeString.value += document.getElementById('innerCode' + (teststring[i]-1)).value + ",";
}
if (history.value == "") {
var removeAllButton = document.getElementById('removeAllButton');
removeAllButton.style.display = "none";
var introText = document.getElementById('introText');
introText.style.display = "block";
}
}
function wpytHistoryOutput(id) {
var history = document.getElementById('history');
history.value += id + ",";
}
function wpytRemoveAll() {
if ( confirm("Remove all profiles? (is not saved until options is updated)")){
var history = document.getElementById('history');
var codeString = document.getElementById('codeString');
var splitHistory = new Array();
splitHistory = history.value.split(",");
for(i=0; i<splitHistory.length-1;i++) {
historyID = splitHistory[i]-1;
wpytRemoveElement(historyID);
}
history.value = "";
codeString.value = "";
var removeAllButton = document.getElementById('removeAllButton');
removeAllButton.style.display = "none";
var introText = document.getElementById('introText');
introText.style.display = "block";
}
}
function wpytAddElement() {
var introText = document.getElementById('introText');
introText.style.display = "none";
var removeAllButton = document.getElementById('removeAllButton');
removeAllButton.style.display = "block";
var ni = document.getElementById('myDiv');
var numi = document.getElementById('theValue');
var num = (document.getElementById('theValue').value -1)+ 2;
var length = document.getElementById('length').value;
numi.value = num;
num = parseInt(num) + parseInt(length);
wpytHistoryOutput(num);
var newdiv = document.createElement('div');
var divIdName = 'my'+(num-1)+'Div';
newdiv.setAttribute('id',divIdName);
newdiv.innerHTML = wpytGenerateInnerHTML(num);
ni.appendChild(newdiv);
var firstDiv = document.getElementsByTagName('div');
var divPosition;
for(i=0;i<firstDiv.length;i++) {
if (firstDiv[i].id == "myDiv") {
divPosition = i+1;
}
}
var reverseOrder = document.getElementsByTagName('div')[divPosition];
reverseOrder.parentNode.insertBefore(newdiv,reverseOrder);
wpytOuterCodeStatic(num-1);
} -
deepakg -
Thanks - 1 reply
{{ DiscussionBoard.errors[2852584].message }}-
Trivum -
Thanks
{{ DiscussionBoard.errors[2855247].message }} -
-
-
misskimberly -
Thanks - 1 reply
{{ DiscussionBoard.errors[2856153].message }}-
Trivum -
Thanks
{{ DiscussionBoard.errors[2857214].message }} -
-