Commit 89d15521 authored by shammash's avatar shammash Committed by lechuck
Browse files

updated video-sidebar-widgets to 5.2

parent b4534175
<?php
/*
* Widget - Post Meta Video Widget
*/
//Post Meta Video Widget Class to extend WP_Widget class
class PostMetaVideoWidget extends WP_Widget {
//function to set up widget in admin
function PostMetaVideoWidget() {
$widget_ops = array( 'classname' => 'postmetavideo',
'description' => __('A Video Widget that is controlled by Post or Page custom field settings.', 'postmetavideo') );
$control_ops = array( 'width' => 200, 'height' => 350, 'id_base' => 'postmetavideo' );
$this->WP_Widget( 'postmetavideo', __('Post Meta Video Widget', 'postmetavideo'), $widget_ops, $control_ops );
}
//function to echo out widget on sidebar
function widget( $args, $instance ) {
extract( $args );
if(is_single()||is_page()):
//get post meta and output video
global $post;
$post_id = $post->ID;
$videosource = get_post_meta($post_id,'vsw_pmvw_video_source',true);
$videoid = get_post_meta($post_id,'vsw_pmvw_video_id',true);
$videowidth = get_post_meta($post_id,'vsw_pmvw_video_width',true);
$videoheight = get_post_meta($post_id,'vsw_pmvw_video_height',true);
$videocaption = get_post_meta($post_id,'vsw_pmvw_video_caption',true);
$autoplaysetting = get_post_meta($post_id,'vsw_pmvw_video_autoplay',true);
if(!empty($videoid)): // output only if video id is present!
$title = $instance['title'];
echo $before_widget;
// if user written title echo out
if ($title){
echo $before_title . $title . $after_title;
}
//function to show video in blog sidebar, please look for it in helper-functions.php
VSWShowVideo($videosource,$videoid,$autoplaysetting,$videowidth,$videoheight,'false','false');
if($videocaption){
echo "<p class=\"VideoCaption\">$videocaption</p>";
}
echo $after_widget;
endif; // !empty($videoid) check
endif; // is_single()||is_page() check
}//end of function widget
//function to update widget setting
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags( $new_instance['title'] );
return $instance;
}//end of function update
//function to create Widget Admin form
function form($instance) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '') );
$instance['title'] = strip_tags( $instance['title'] );
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>">Widget Title:</label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>"
type="text" value="<?php echo $instance['title']; ?>" />
</p>
<div class="description">
<p>
Please use only one widget per sidebar. If there is multiple sidebars per post/page, please use only one widget on one sidebar.
</p>
<p>
The video output by this widget, will only be shown on Posts or Pages.
</p>
<p>
The settings for this widget is in your <a href="<?php echo admin_url().'post-new.php#vsw_post_meta_video_widget_setting';?>">Post Editor</a> or <a href="<?php echo admin_url().'post-new.php?post_type=page#vsw_post_meta_video_widget_setting';?>">Page Editor</a>. Please look for "Post Meta Video Widget Settings". This Widget will output Video according to individual post meta setting (Custom Field Setting).
</p>
<p>If you are not using this widget, you can disable this component <a href="<?php echo admin_url().'options-general.php?page=video_sidebar_widget_settings';?>">here</a> by checking on it and save changes.
</p>
</div>
<p>
Thank you for reading this!
</p>
<?php
}//end of function form($instance)
}//end of Class
/*
*Post meta box on right side of post editor
*/
// WP 3.0+
// add_action( 'add_meta_boxes', 'vsw_add_custom_box' );
$options = get_option('vsw_plugin_options'); // check whether to load post meta box.
if(empty($options['hide_pmvw'])){
// backwards compatible
add_action( 'admin_init', 'vsw_add_custom_box', 1);
/* Do something with the data entered */
add_action( 'save_post', 'vsw_save_postdata' );
}
/* Adds a box to the main column on the Post and Page edit screens */
function vsw_add_custom_box() {
add_meta_box(
'vsw_post_meta_video_widget_setting',
__( 'Post Meta Video Widget Settings', 'vsw_textdomain' ),
'vsw_inner_custom_box',
'post',
'side'
);
add_meta_box(
'vsw_post_meta_video_widget_setting',
__( 'Post Meta Video Widget Settings', 'vsw_textdomain' ),
'vsw_inner_custom_box',
'page',
'side'
);
}
/* Prints the box content */
function vsw_inner_custom_box(){
// Use nonce for verification
wp_nonce_field( plugin_basename( __FILE__ ), 'vsw_noncename' );
?>
<div class="description" id="vsw_post_meta_description" style="display:none;">
<p>
This is the widgets setting form for Post Meta Video Widget, which is a component of Video Sidebar Widgets Plugin. You can find the widget <a href="<?php echo admin_url().'widgets.php';?>">here</a>.
</p>
<p>
The video output by this widget, will only be shown on Posts or Pages.
</p>
<p>If you are not using this widget, you can disable this component <a href="<?php echo admin_url().'options-general.php?page=video_sidebar_widget_settings';?>">here</a> by checking on it and save changes.
</p>
<p>
Thank you for reading this!
</p>
</div>
<div>
<p>
<a href="#" onclick="document.getElementById('vsw_post_meta_description').style.display='block';return false;">What are these settings for?</a>
</p>
</div>
<?php
//retrieve all post meta setting to fill the form.
global $post;
$post_id = $post->ID;
$vsw_pmvw_video_source = get_post_meta($post_id,'vsw_pmvw_video_source',true);
$vsw_pmvw_video_id = get_post_meta($post_id,'vsw_pmvw_video_id',true);
$vsw_pmvw_video_width = get_post_meta($post_id,'vsw_pmvw_video_width',true);
$vsw_pmvw_video_height = get_post_meta($post_id,'vsw_pmvw_video_height',true);
$vsw_pmvw_video_caption = get_post_meta($post_id,'vsw_pmvw_video_caption',true);
$vsw_pmvw_video_autoplay = get_post_meta($post_id,'vsw_pmvw_video_autoplay',true);
?>
<p><u>Video Preview in fixed width and height</u></p>
<p>
<?php
VSWShowVideo($vsw_pmvw_video_source,$vsw_pmvw_video_id,$vsw_pmvw_video_autoplay,$vsw_pmvw_video_width,$vsw_pmvw_video_height,'true','false');
?>
</p>
<p>
<label for="vsw_pmvw_video_source">Select Video Source:</label>
<select id="vsw_pmvw_video_source" name="vsw_pmvw_video_source" class="widefat" style="width:100%;">
<?php
$network = array('YouTube','Vimeo','MySpace','Veoh','Blip','WordPress','Viddler','DailyMotion','Revver','Metacafe','Tudou','Youku','cn6','Google');
foreach($network as $net){
echo "<option value='$net'";
if($vsw_pmvw_video_source == $net){
echo 'selected="selected"';
}
echo" >$net</option>";
}
?>
</select>
</p>
<p>
<label for="vsw_pmvw_video_id">Video ID: </label>
<input class="widefat" id="vsw_pmvw_video_id" name="vsw_pmvw_video_id" type="text" value="<?php echo $vsw_pmvw_video_id; ?>" /></p>
<p>
<label for="vsw_pmvw_video_width">Video Width: </label>
<input class="widefat" id="vsw_pmvw_video_width" name="vsw_pmvw_video_width" type="text" value="<?php echo $vsw_pmvw_video_width; ?>" />
</p>
<p>
<label for="vsw_pmvw_video_height">Video Height: </label>
<input class="widefat" id="vsw_pmvw_video_height" name="vsw_pmvw_video_height" type="text" value="<?php echo $vsw_pmvw_video_height; ?>" />
</p>
<p>
<label for="vsw_pmvw_video_caption">Video Caption: </label>
<input class="widefat" id="vsw_pmvw_video_caption" name="vsw_pmvw_video_caption" type="text" value="<?php echo $vsw_pmvw_video_caption; ?>" />
</p>
<?php
// check whether autoplay feature supported by video network
if($vsw_pmvw_video_autoplay == '1'):
$source = $vsw_pmvw_video_source;
$msg = "<p class='description'>Sorry, auto play option not supported by ".$source."</p>";
switch ($source) {
case 'WordPress':
echo $msg;
break;
case 'Tudou':
echo $msg;
break;
case 'Youku':
echo $msg;
break;
case 'Blip':
echo "<p class='description'>Sorry, auto play option for BlipTv was removed as it is causing error in Internet Explorer</p>";
break;
case 'cn6':
echo "<p class='description'>Sorry, auto play option not supported by 6.cn</p>";
break;
}
endif;
?>
<p>
<label for="vsw_pmvw_video_autoplay">Auto Play:</label>
<select id="vsw_pmvw_video_autoplay"
name="vsw_pmvw_video_autoplay" class="widefat" style="width:100%;">';
<option value='0' <?php if($vsw_pmvw_video_autoplay == '0'){echo 'selected="selected"';}?>>No</option>
<option value='1' <?php if($vsw_pmvw_video_autoplay == '1'){echo 'selected="selected"';}?>>Yes</option>
</select>
</p>
<?php
}
/* When the post is saved, saves our custom data */
function vsw_save_postdata( $post_id ){
// verify if this is an auto save routine.
// If it is our form has not been submitted, so we dont want to do anything
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
// verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times
if ( !wp_verify_nonce( $_POST['vsw_noncename'], plugin_basename( __FILE__ ) ) )
return;
// Check permissions
if ( 'page' == $_POST['post_type'] )
{
if ( !current_user_can( 'edit_page', $post_id ) )
return;
}
else
{
if ( !current_user_can( 'edit_post', $post_id ) )
return;
}
// OK, we're authenticated: we need to find and save the data
$data1 = $_POST['vsw_pmvw_video_source'];
$data2 = $_POST['vsw_pmvw_video_id'];
$data3 = $_POST['vsw_pmvw_video_width'];
$data4 = $_POST['vsw_pmvw_video_height'];
$data5 = $_POST['vsw_pmvw_video_caption'];
$data6 = $_POST['vsw_pmvw_video_autoplay'];
global $post;
$post_id = $post->ID;
update_post_meta($post_id,'vsw_pmvw_video_source',$data1);
update_post_meta($post_id,'vsw_pmvw_video_id',$data2);
update_post_meta($post_id,'vsw_pmvw_video_width',$data3);
update_post_meta($post_id,'vsw_pmvw_video_height',$data4);
update_post_meta($post_id,'vsw_pmvw_video_caption',$data5);
update_post_meta($post_id,'vsw_pmvw_video_autoplay',$data6);
}
?>
\ No newline at end of file
<?php
/**
* Widget - Random Video Widget
*
*/
class RandomVideoSidebarWidget extends WP_Widget {
function RandomVideoSidebarWidget() {
$widget_ops = array( 'classname' => 'randomvideosidebar', 'description' => __('A Random Video Widget. Randomly selects 1 of the 5 preset videos for display', 'randomvideosidebar') );
$control_ops = array( 'width' => 705, 'height' => 600, 'id_base' => 'randomvideosidebar' );
$this->WP_Widget( 'randomvideosidebar', __('Random Video Sidebar Widget', 'randomvideosidebar'), $widget_ops, $control_ops );
}
function widget( $args, $instance ) {
extract( $args );
$RV_title = apply_filters('widget_title', $instance['RV_title'] );
$RV_width = $instance['RV_width'];
$RV_height = $instance['RV_height'];
$RV_autoplay = $instance['RV_autoplay'];
$RV_id1 = $instance['RV_id1'];
$RV_source1 = $instance['RV_source1'];
$RV_cap1 = $instance['RV_cap1'];
$RV_id2 = $instance['RV_id2'];
$RV_source2 = $instance['RV_source2'];
$RV_cap2 = $instance['RV_cap2'];
$RV_id3 = $instance['RV_id3'];
$RV_source3 = $instance['RV_source3'];
$RV_cap3 = $instance['RV_cap3'];
$RV_id4 = $instance['RV_id4'];
$RV_source4 = $instance['RV_source4'];
$RV_cap4 = $instance['RV_cap4'];
$RV_id5 = $instance['RV_id5'];
$RV_source5 = $instance['RV_source5'];
$RV_cap5 = $instance['RV_cap5'];
//define empty variable to prevent WordPress debug error
$rv_flashvar = "";
$rv_flashvar2 = "";
echo $before_widget;
if ( $RV_title )
echo $before_title . $RV_title . $after_title;
//using rand() to select which video to show
$selection = rand(1,5);
switch($selection){
case 1:
$Embed_id = $RV_id1;
$Embed_source = $RV_source1;
$Embed_cap = $RV_cap1;
break;
case 2:
$Embed_id = $RV_id2;
$Embed_source = $RV_source2;
$Embed_cap = $RV_cap2;
break;
case 3:
$Embed_id = $RV_id3;
$Embed_source = $RV_source3;
$Embed_cap = $RV_cap3;
break;
case 4:
$Embed_id = $RV_id4;
$Embed_source = $RV_source4;
$Embed_cap = $RV_cap4;
break;
case 5:
$Embed_id = $RV_id5;
$Embed_source = $RV_source5;
$Embed_cap = $RV_cap5;
break;
}
//test for empty $Embed_id and empty $Embed_source. if empty,
//assign to same as first video id and source
If(empty($Embed_id)){
$Embed_id = $RV_id1;
$Embed_source = $RV_source1;
$Embed_cap = $RV_cap1;
}
$select_source = $Embed_source;
switch ($select_source) {
case "":
$rv_value = "";
$rv_flashvar = "";
$rv_flashvar2 = "";
$rv_cap = "";
break;
case 'YouTube':
$rv_value = "http://www.youtube.com/v/$Embed_id&autoplay=$RV_autoplay&loop=0&rel=0";
$rv_flashvar = "";
$rv_flashvar2 = "";
$rv_cap = $Embed_cap;
break;
case 'Vimeo':
$rv_value = "http://vimeo.com/moogaloop.swf?clip_id=$Embed_id&amp;server=vimeo.com&amp;loop=0&amp;fullscreen=1&amp;autoplay=$RV_autoplay";
$rv_flashvar = "";
$rv_flashvar2 = "";
$rv_cap = $Embed_cap;
break;
case 'MySpace':
$rv_value = "http://mediaservices.myspace.com/services/media/embed.aspx/m=$Embed_id,t=1,mt=video,ap=$RV_autoplay";
$rv_flashvar = "";
$rv_flashvar2 = "";
$rv_cap = $Embed_cap;
break;
case 'Veoh':
$rv_value = "http://www.veoh.com/static/swf/webplayer/WebPlayer.swf?version=AFrontend.5.4.2.20.1002&permalinkId=$Embed_id";
$rv_value.= "&player=videodetailsembedded&id=anonymous&videoAutoPlay=$RV_autoplay";
$rv_flashvar = "";
$rv_flashvar2 = "";
$rv_cap = $Embed_cap;
break;
case 'Blip':
$rv_value = "http://blip.tv/play/$Embed_id";
$rv_flashvar = "";
$rv_flashvar2 = "";
$rv_cap = $Embed_cap;
break;
case 'WordPress':
$rv_value = "http://s0.videopress.com/player.swf?v=1.02";
$rv_flashvar = "<param name='flashvars' value='$Embed_id'>";
$rv_flashvar2 = 'flashvars="guid='.$Embed_id.'"';
$rv_cap = $Embed_cap;
break;
case 'Viddler':
$rv_value = "http://www.viddler.com/player/$Embed_id";
if($RV_autoplay=='1'){
$rv_flashvar = "<param name=\"flashvars\" value=\"autoplay=t\" />\n";
$rv_flashvar2 = 'flashvars="autoplay=t" ';
}
$rv_cap = $Embed_cap;
break;
case 'DailyMotion':
$rv_value = "http://www.dailymotion.com/swf/$Embed_id&autoStart=$RV_autoplay&related=0";
$rv_flashvar = "";
$rv_flashvar2 = "";
$rv_cap = $Embed_cap;
break;
case 'Revver':
$rv_value = "http://flash.revver.com/player/1.0/player.swf?mediaId=$Embed_id&autoStart=$RV_autoplay";
$rv_flashvar = "";
$rv_flashvar2 = "";
$rv_cap = $Embed_cap;
break;
case 'Metacafe':
$rid = split('/',$Embed_id);
$rv_value = "http://www.metacafe.com/fplayer/$rid[0]/$rid[1].swf";
if($RV_autoplay=='1'){
$rv_flashvar = "";
$rv_flashvar2 = 'flashVars="playerVars=showStats=no|autoPlay=yes|"';
}
$rv_cap = $Embed_cap;
break;
case 'Tudou':
$rv_value = "$Embed_id";
$rv_flashvar = "";
$rv_flashvar2 = "";
$rv_cap = $Embed_cap;
break;
case 'Youku':
$rv_value = "$Embed_id";
$rv_flashvar = "";
$rv_flashvar2 = "";
$rv_cap = $Embed_cap;
break;
case 'cn6':
$rv_value = "$Embed_id";
$rv_flashvar = "";
$rv_flashvar2 = "";
$rv_cap = $Embed_cap;
break;
case 'Google':
$rv_value = "http://video.google.com/googleplayer.swf?docid=$Embed_id&hl=en&fs=true";
if($RV_autoplay=='1'){
$rv_flashvar = "";
$rv_flashvar2 = 'FlashVars="autoPlay=true&playerMode=embedded"';
}
$rv_cap = $Embed_cap;
break;
case 'Tangle':
$rv_value = "http://www.tangle.com/flash/swf/flvplayer.swf";
if($RV_autoplay=='1'){
$rv_flashvar = "";
$rv_flashvar2 = "FlashVars=\"viewkey=$Embed_id&autoplay=$RV_autoplay\"";
}else{
$rv_flashvar = "";
$rv_flashvar2 = "FlashVars=\"viewkey=$Embed_id\"";
}
$rv_cap = $Embed_cap;
break;
}
echo "\n<object width=\"$RV_width\" height=\"$RV_height\">\n";
echo $rv_flashvar;
echo "<param name=\"allowfullscreen\" value=\"true\" />\n";
echo "<param name=\"allowscriptaccess\" value=\"always\" />\n";
echo "<param name=\"movie\" value=\"$rv_value\" />\n";
echo "<param name=\"wmode\" value=\"transparent\">\n";
echo "<embed src=\"$rv_value\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" ";
echo "allowfullscreen=\"true\" allowscriptaccess=\"always\" ";
echo $rv_flashvar2;
echo "width=\"$RV_width\" height=\"$RV_height\">\n";
echo "</embed>\n";
echo "</object>\n\n";
echo "<p class=\"VideoCaption\">$rv_cap</p>";
echo $after_widget;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['RV_title'] = strip_tags( $new_instance['RV_title'] );