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;
         }
         // !empty($videoid) check
     }
     // is_single()||is_page() check
 }
    function form($instance)
    {
        $instance = wp_parse_args((array) $instance, array('title2' => '', 'v_width2' => '', 'v_height2' => '', 'v_autoplay2' => '', 'v_id2' => '', 'v_source' => '', 'v_cap2' => ''));
        $instance['title2'] = strip_tags($instance['title2']);
        $instance['v_width2'] = strip_tags($instance['v_width2']);
        $instance['v_height2'] = strip_tags($instance['v_height2']);
        $instance['v_autoplay2'] = strip_tags($instance['v_autoplay2']);
        $instance['v_id2'] = strip_tags($instance['v_id2']);
        $instance['v_source'] = strip_tags($instance['v_source']);
        $instance['v_cap2'] = $instance['v_cap2'];
        //function to show video in widget admin form fixed width and height, please look for it below
        $autoplaysetting = '0';
        $videoid = $instance['v_id2'];
        $videosource = $instance['v_source'];
        $videowidth = "";
        $videoheight = "";
        //$admin = true // to show video in admin
        VSWShowVideo($videosource, $videoid, $autoplaysetting, $videowidth, $videoheight, 'true', 'false');
        ?>
				
						
				<p>
				<label for="<?php 
        echo $this->get_field_id('title2');
        ?>
">Widget Title:</label> 
				<input class="widefat" id="<?php 
        echo $this->get_field_id('title2');
        ?>
" name="<?php 
        echo $this->get_field_name('title2');
        ?>
"
				 type="text" value="<?php 
        echo $instance['title2'];
        ?>
" />
				</p>
				
				<p>
				<label for="<?php 
        echo $this->get_field_id('v_source');
        ?>
">Select Video Source:</label> 
				<select id="<?php 
        echo $this->get_field_id('v_source');
        ?>
" name="<?php 
        echo $this->get_field_name('v_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 ($instance['v_source'] == $net) {
                echo 'selected="selected"';
            }
            echo " >{$net}</option>";
        }
        ?>
				

				</select>
				</p>
				
				<p>
				<label for="<?php 
        echo $this->get_field_id('v_id2');
        ?>
">Video ID: </label>
				<input class="widefat" id="<?php 
        echo $this->get_field_id('v_id2');
        ?>
" 
                name="<?php 
        echo $this->get_field_name('v_id2');
        ?>
" type="text" value="<?php 
        echo $instance['v_id2'];
        ?>
" /></p>
				
				<p>
				<label for="<?php 
        echo $this->get_field_id('v_width2');
        ?>
">Video Width: </label>
				<input class="widefat" id="<?php 
        echo $this->get_field_id('v_width2');
        ?>
" 
                name="<?php 
        echo $this->get_field_name('v_width2');
        ?>
" type="text" value="<?php 
        echo $instance['v_width2'];
        ?>
" />
				</p>
				
				<p>
				<label for="<?php 
        echo $this->get_field_id('v_height2');
        ?>
">Video Height: </label>
				<input class="widefat" id="<?php 
        echo $this->get_field_id('v_height2');
        ?>
" 
                name="<?php 
        echo $this->get_field_name('v_height2');
        ?>
" type="text" value="<?php 
        echo $instance['v_height2'];
        ?>
" />
				</p>
				
                <p>
				<label for="<?php 
        echo $this->get_field_id('v_cap2');
        ?>
">Video Caption: </label>
				<input class="widefat" id="<?php 
        echo $this->get_field_id('v_cap2');
        ?>
" 
                name="<?php 
        echo $this->get_field_name('v_cap2');
        ?>
" type="text" value="<?php 
        echo $instance['v_cap2'];
        ?>
" />
				</p>
                
                
				<p>
				
				<?php 
        // check whether autoplay feature supported by video network
        $source = $instance['v_source'];
        $msg = "<p>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>Sorry, auto play option removed as it is causing error in Internet Explorer</p>";
                break;
            case 'cn6':
                echo "<p>Sorry, auto play option not supported by 6.cn</p>";
                break;
        }
        ?>
				
				<label for="<?php 
        echo $this->get_field_id('v_autoplay2');
        ?>
">Auto Play:</label> 
				<select id="<?php 
        echo $this->get_field_id('v_autoplay2');
        ?>
" 
                name="<?php 
        echo $this->get_field_name('v_autoplay2');
        ?>
" class="widefat" style="width:100%;">';
				<option value='1' <?php 
        if ($instance['v_autoplay2'] == '1') {
            echo 'selected="selected"';
        }
        ?>
>Yes</option>
				<option value='0' <?php 
        if ($instance['v_autoplay2'] == '0') {
            echo 'selected="selected"';
        }
        ?>
>No</option>
				</select>
				</p>
				
				<?php 
    }
    function form($instance)
    {
        $instance = wp_parse_args((array) $instance, array('RV_title' => '', 'RV_width' => '', 'RV_height' => '', 'RV_autoplay' => '', 'RV_id1' => '', 'RV_source1' => '', 'RV_cap1' => '', 'RV_id2' => '', 'RV_source2' => '', 'RV_cap2' => '', 'RV_id3' => '', 'RV_source3' => '', 'RV_cap3' => '', 'RV_id4' => '', 'RV_source4' => '', 'RV_cap4' => '', 'RV_id5' => '', 'RV_source5' => '', 'RV_cap5' => ''));
        $instance['RV_title'] = strip_tags($instance['RV_title']);
        $instance['RV_width'] = strip_tags($instance['RV_width']);
        $instance['RV_height'] = strip_tags($instance['RV_height']);
        $instance['RV_autoplay'] = strip_tags($instance['RV_autoplay']);
        $instance['RV_id1'] = strip_tags($instance['RV_id1']);
        $instance['RV_source1'] = strip_tags($instance['RV_source1']);
        $instance['RV_cap1'] = $instance['RV_cap1'];
        $instance['RV_id2'] = strip_tags($instance['RV_id2']);
        $instance['RV_source2'] = strip_tags($instance['RV_source2']);
        $instance['RV_cap2'] = $instance['RV_cap2'];
        $instance['RV_id3'] = strip_tags($instance['RV_id3']);
        $instance['RV_source3'] = strip_tags($instance['RV_source3']);
        $instance['RV_cap3'] = $instance['RV_cap3'];
        $instance['RV_id4'] = strip_tags($instance['RV_id4']);
        $instance['RV_source4'] = strip_tags($instance['RV_source4']);
        $instance['RV_cap4'] = $instance['RV_cap4'];
        $instance['RV_id5'] = strip_tags($instance['RV_id5']);
        $instance['RV_source5'] = strip_tags($instance['RV_source5']);
        $instance['RV_cap5'] = $instance['RV_cap5'];
        ?>

<div style="width:400px;height:400px;float:left;margin:0px 15px 20px 5px">
<h2>General Settings</h2>
<br/>
<p class='description' style='padding-left:0px !important'>Please fill up settings before clicking on save to display video.</p>
<!--Title -->        
<p>
<label for="<?php 
        echo $this->get_field_id('RV_title');
        ?>
">Widget Title:</label> 
<input class="widefat" id="<?php 
        echo $this->get_field_id('RV_title');
        ?>
" name="<?php 
        echo $this->get_field_name('RV_title');
        ?>
" type="text" value="<?php 
        echo $instance['RV_title'];
        ?>
" />
</p>

<!--Width -->
<p>
<label for="<?php 
        echo $this->get_field_id('RV_width');
        ?>
">Video Width: </label>
<input class="widefat" id="<?php 
        echo $this->get_field_id('RV_width');
        ?>
" name="<?php 
        echo $this->get_field_name('RV_width');
        ?>
" type="text" value="<?php 
        echo $instance['RV_width'];
        ?>
" />
</p>

<!--Height -->
<p>
<label for="<?php 
        echo $this->get_field_id('RV_height');
        ?>
">Video Height: </label>
<input class="widefat" id="<?php 
        echo $this->get_field_id('RV_height');
        ?>
" name="<?php 
        echo $this->get_field_name('RV_height');
        ?>
" type="text" value="<?php 
        echo $instance['RV_height'];
        ?>
" />
</p>

<!--auto play -->
<p>
<label for="<?php 
        echo $this->get_field_id('RV_autoplay');
        ?>
">Auto Play: </label> 
<select id="<?php 
        echo $this->get_field_id('RV_autoplay');
        ?>
" name="<?php 
        echo $this->get_field_name('RV_autoplay');
        ?>
" class="widefat" style="width:100%;">';
<option value='1' <?php 
        if ($instance['RV_autoplay'] == '1') {
            echo 'selected="selected"';
        }
        ?>
>Yes</option>
<option value='0' <?php 
        if ($instance['RV_autoplay'] == '0') {
            echo 'selected="selected"';
        }
        ?>
>No</option>
</select>
</p>
<p class='description' style='padding-left:0px !important'>Autoplay is for front end only, does not autoplay in admin. Applies to all widgets.</p>
</div>

<div style="width:400px;height:500px;float:left;margin:0px 15px 20px 0px">
<!--first video setting -->
<h2>Video 1</h2>
<?php 
        //show video in Random Video Widget Admin
        $autoplaysetting = '0';
        $videoid = $instance['RV_id1'];
        $videosource = $instance['RV_source1'];
        $videowidth = "";
        $videoheight = "";
        //$admin = true // to show video in admin
        VSWShowVideo($videosource, $videoid, $autoplaysetting, $videowidth, $videoheight, 'true', 'false');
        ?>

<p>
<label for="<?php 
        echo $this->get_field_id('RV_source1');
        ?>
">Select Video 1 Source:</label> 
<select id="<?php 
        echo $this->get_field_id('RV_source1');
        ?>
" name="<?php 
        echo $this->get_field_name('RV_source1');
        ?>
" 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 ($instance['RV_source1'] == $net) {
                echo 'selected="selected"';
            }
            echo " >{$net}</option>";
        }
        ?>

</select>
</p>

<p>
<label for="<?php 
        echo $this->get_field_id('RV_id1');
        ?>
">Video 1 ID: </label>
<input class="widefat" id="<?php 
        echo $this->get_field_id('RV_id1');
        ?>
" name="<?php 
        echo $this->get_field_name('RV_id1');
        ?>
" type="text" value="<?php 
        echo $instance['RV_id1'];
        ?>
" /></p>

<p>
<label for="<?php 
        echo $this->get_field_id('RV_cap1');
        ?>
">Video Caption: </label>
<input class="widefat" id="<?php 
        echo $this->get_field_id('RV_cap1');
        ?>
" name="<?php 
        echo $this->get_field_name('RV_cap1');
        ?>
" type="text" value="<?php 
        echo $instance['RV_cap1'];
        ?>
" /></p>

</div>
<div style="width:400px;height:500px;float:left;margin:0px 15px 20px 0px">

<!--second video setting -->
<h2>Video 2</h2>
<?php 
        //show video in Random Video Widget Admin
        $autoplaysetting = '0';
        $videoid = $instance['RV_id2'];
        $videosource = $instance['RV_source2'];
        $videowidth = "";
        $videoheight = "";
        //$admin = true // to show video in admin
        VSWShowVideo($videosource, $videoid, $autoplaysetting, $videowidth, $videoheight, 'true', 'false');
        ?>

<p>
<label for="<?php 
        echo $this->get_field_id('RV_source2');
        ?>
">Select Video 2 Source:</label> 
<select id="<?php 
        echo $this->get_field_id('RV_source2');
        ?>
" name="<?php 
        echo $this->get_field_name('RV_source2');
        ?>
" 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 ($instance['RV_source2'] == $net) {
                echo 'selected="selected"';
            }
            echo " >{$net}</option>";
        }
        ?>



</select>
</p>

<p>
<label for="<?php 
        echo $this->get_field_id('RV_id2');
        ?>
">Video 2 ID: </label>
<input class="widefat" id="<?php 
        echo $this->get_field_id('RV_id2');
        ?>
" name="<?php 
        echo $this->get_field_name('RV_id2');
        ?>
" type="text" value="<?php 
        echo $instance['RV_id2'];
        ?>
" /></p>

<p>
<label for="<?php 
        echo $this->get_field_id('RV_cap2');
        ?>
">Video Caption: </label>
<input class="widefat" id="<?php 
        echo $this->get_field_id('RV_cap2');
        ?>
" name="<?php 
        echo $this->get_field_name('RV_cap2');
        ?>
" type="text" value="<?php 
        echo $instance['RV_cap2'];
        ?>
" /></p>

</div>
<div style="width:400px;height:500px;float:left;margin:0px 15px 20px 0px">

<!--third video setting -->
<h2>Video 3</h2>
<?php 
        //show video in Random Video Widget Admin
        $autoplaysetting = '0';
        $videoid = $instance['RV_id3'];
        $videosource = $instance['RV_source3'];
        $videowidth = "";
        $videoheight = "";
        //$admin = true // to show video in admin
        VSWShowVideo($videosource, $videoid, $autoplaysetting, $videowidth, $videoheight, 'true', 'false');
        ?>

<p>
<label for="<?php 
        echo $this->get_field_id('RV_source3');
        ?>
">Select Video 3 Source:</label> 
<select id="<?php 
        echo $this->get_field_id('RV_source3');
        ?>
" name="<?php 
        echo $this->get_field_name('RV_source3');
        ?>
" 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 ($instance['RV_source3'] == $net) {
                echo 'selected="selected"';
            }
            echo " >{$net}</option>";
        }
        ?>

</select>
</p>

<p>
<label for="<?php 
        echo $this->get_field_id('RV_id3');
        ?>
">Video 3 ID: </label>
<input class="widefat" id="<?php 
        echo $this->get_field_id('RV_id3');
        ?>
" name="<?php 
        echo $this->get_field_name('RV_id3');
        ?>
" type="text" value="<?php 
        echo $instance['RV_id3'];
        ?>
" /></p>

<p>
<label for="<?php 
        echo $this->get_field_id('RV_cap3');
        ?>
">Video Caption: </label>
<input class="widefat" id="<?php 
        echo $this->get_field_id('RV_cap3');
        ?>
" name="<?php 
        echo $this->get_field_name('RV_cap3');
        ?>
" type="text" value="<?php 
        echo $instance['RV_cap3'];
        ?>
" /></p>


</div>
<div style="width:400px;height:500px;float:left;margin:0px 15px 20px 5px">

<!--fourth video setting -->
<h2>Video 4</h2>
<?php 
        //show video in Random Video Widget Admin
        $autoplaysetting = '0';
        $videoid = $instance['RV_id4'];
        $videosource = $instance['RV_source4'];
        $videowidth = "";
        $videoheight = "";
        //$admin = true // to show video in admin
        VSWShowVideo($videosource, $videoid, $autoplaysetting, $videowidth, $videoheight, 'true', 'false');
        ?>

<p>
<label for="<?php 
        echo $this->get_field_id('RV_source4');
        ?>
">Select Video 4 Source:</label> 
<select id="<?php 
        echo $this->get_field_id('RV_source4');
        ?>
" name="<?php 
        echo $this->get_field_name('RV_source4');
        ?>
" 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 ($instance['RV_source4'] == $net) {
                echo 'selected="selected"';
            }
            echo " >{$net}</option>";
        }
        ?>

</select>
</p>

<p>
<label for="<?php 
        echo $this->get_field_id('RV_id4');
        ?>
">Video 4 ID: </label>
<input class="widefat" id="<?php 
        echo $this->get_field_id('RV_id4');
        ?>
" name="<?php 
        echo $this->get_field_name('RV_id4');
        ?>
" type="text" value="<?php 
        echo $instance['RV_id4'];
        ?>
" /></p>

<p>
<label for="<?php 
        echo $this->get_field_id('RV_cap4');
        ?>
">Video Caption: </label>
<input class="widefat" id="<?php 
        echo $this->get_field_id('RV_cap4');
        ?>
" name="<?php 
        echo $this->get_field_name('RV_cap4');
        ?>
" type="text" value="<?php 
        echo $instance['RV_cap4'];
        ?>
" /></p>

</div>
<div style="width:400px;height:500px;float:left;margin:0px 15px 20px 0px">

<!--fifth video setting -->
<h2>Video 5</h2>
<?php 
        //show video in Random Video Widget Admin
        $autoplaysetting = '0';
        $videoid = $instance['RV_id5'];
        $videosource = $instance['RV_source5'];
        $videowidth = "";
        $videoheight = "";
        //$admin = true // to show video in admin
        VSWShowVideo($videosource, $videoid, $autoplaysetting, $videowidth, $videoheight, 'true', 'false');
        ?>

<p>
<label for="<?php 
        echo $this->get_field_id('RV_source5');
        ?>
">Select Video 5 Source:</label> 
<select id="<?php 
        echo $this->get_field_id('RV_source5');
        ?>
" name="<?php 
        echo $this->get_field_name('RV_source5');
        ?>
" 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 ($instance['RV_source5'] == $net) {
                echo 'selected="selected"';
            }
            echo " >{$net}</option>";
        }
        ?>

</select>
</p>

<p>
<label for="<?php 
        echo $this->get_field_id('RV_id5');
        ?>
">Video 5 ID: </label>
<input class="widefat" id="<?php 
        echo $this->get_field_id('RV_id5');
        ?>
" name="<?php 
        echo $this->get_field_name('RV_id5');
        ?>
" type="text" value="<?php 
        echo $instance['RV_id5'];
        ?>
" /></p>

<p>
<label for="<?php 
        echo $this->get_field_id('RV_cap5');
        ?>
">Video Caption: </label>
<input class="widefat" id="<?php 
        echo $this->get_field_id('RV_cap5');
        ?>
" name="<?php 
        echo $this->get_field_name('RV_cap5');
        ?>
" type="text" value="<?php 
        echo $instance['RV_cap5'];
        ?>
" /></p>

</div>
<p style="clear:both"></p>


        <?php 
    }
예제 #4
0
function vsw_show_video_class($id, $source, $width, $height, $autoplay)
{
    $vsw_id = $id;
    $vsw_width = $width;
    $vsw_height = $height;
    //convert string of source to lowercase
    $source = strtolower($source);
    //should have used all lowercase in previous functions
    //now have to switch it.
    switch ($source) {
        case "":
            $vsw_source = "";
            break;
        case 'youtube':
            $vsw_source = 'YouTube';
            break;
        case 'vimeo':
            $vsw_source = 'Vimeo';
            break;
        case 'myspace':
            $vsw_source = 'MySpace';
            break;
        case 'veoh':
            $vsw_source = 'Veoh';
            break;
        case 'bliptv':
            $vsw_source = 'Blip';
            break;
        case 'wordpress':
            $vsw_source = 'WordPress';
            break;
        case 'viddler':
            $vsw_source = 'Viddler';
            break;
        case 'dailymotion':
            $vsw_source = 'DailyMotion';
            break;
        case 'revver':
            $vsw_source = 'Revver';
            break;
        case 'metacafe':
            $vsw_source = 'Metacafe';
            break;
        case 'tudou':
            $vsw_source = 'Tudou';
            break;
        case 'youku':
            $vsw_source = 'Youku';
            break;
        case 'cn6':
            $vsw_source = 'cn6';
            break;
        case 'google':
            $vsw_source = 'Google';
            break;
        case 'tangle':
            $vsw_source = 'Tangle';
            break;
    }
    //string to lowercase
    $autoplay = strtolower($autoplay);
    //switch autoplay yes or no to 1 or 0
    switch ($autoplay) {
        case "":
            $vsw_autoplay = 0;
            break;
        case 'no':
            $vsw_autoplay = 0;
            break;
        case 'yes':
            $vsw_autoplay = 1;
            break;
    }
    $vsw_code = VSWShowVideo($vsw_source, $vsw_id, $vsw_autoplay, $vsw_width, $vsw_height, 'false', 'true');
    return $vsw_code;
}