function widget($args, $instance)
 {
     extract($args, EXTR_SKIP);
     $title = empty($instance['title']) ? 'Video' : apply_filters('widget_title', $instance['title']);
     $video = empty($instance['video']) ? '' : apply_filters('widget_video', $instance['video']);
     if (!empty($video)) {
         global $footer_area;
         $width = 190;
         $height = 144;
         if ($footer_area) {
             $width = 220;
             $height = 165;
         }
         echo $before_widget;
         echo $before_title . $title . $after_title;
         $vidType = typeOflink($video);
         $allowed_video = array('youtube', 'vimeo', 'quicktime', 'flowplayer', 'flash');
         if (in_array($vidType, $allowed_video)) {
             echo '<div class="widget_video">' . "\n";
             echo WIPobjectPrint($video, $vidType, $width, $height, 'false', true);
             echo '</div>' . "\n";
         } else {
             print __('Unsuported video format', 'wip');
         }
         echo $after_widget;
     }
 }
    function upload_portfolio($id, $label, $desc = "")
    {
        global $post;
        $value = get_post_meta($post->ID, $id, true);
        $isThere = false;
        $imgURL = "";
        $video = "";
        $portfolios = get_option('bd_portfolio_data');
        if (!empty($portfolios)) {
            if (isset($portfolios[$value])) {
                foreach ($portfolios as $unique => $port) {
                    if ($unique == $value) {
                        if ($port['type'] == 'image') {
                            if (isset($port['image']) && is_array($port['image'])) {
                                $isThere = true;
                                $uploadPath = wp_upload_dir();
                                $imageDir = $uploadPath['basedir'] . $port['image']['subdir'] . '/' . $port['image']['image'];
                                $imageUrl = $uploadPath['baseurl'] . $port['image']['subdir'] . '/' . $port['image']['image'];
                                $theThumb = wip_resize($imageDir, $imageUrl, 215, 99999, false);
                                $imgURL = $theThumb['url'];
                            }
                        } elseif ($port['type'] == 'video') {
                            if ($port['video'] != "") {
                                $isThere = true;
                                $video = $port['video'];
                                $vidType = typeOflink($video);
                            }
                        }
                    }
                }
            }
        }
        ?>

				<div class="wip-meta-form" id="portfolio_o">
					
					<span class="wip-label"><?php 
        echo $label;
        ?>
</span>
					
					<div class="p-preview"<?php 
        if ($isThere) {
            echo ' style="display:block;"';
        } else {
            echo ' style="display:none;"';
        }
        ?>
>

						<?php 
        if ($imgURL != "") {
            echo '<img src="' . $imgURL . '" alt="" /><a id="delete_portfolio" href="#" title="delete"></a>';
        }
        ?>
						
						<?php 
        if ($video != "") {
            echo WIPobjectPrint($video, $vidType, '215', '161', 'false') . '<a id="delete_portfolio" href="#" title="delete"></a>';
        }
        ?>

					</div>
					
					<?php 
        if ($desc != "") {
            ?>
<div class="wip-desc"<?php 
            if ($isThere) {
                echo ' style="display:none;"';
            } else {
                echo ' style="display:block;"';
            }
            ?>
><?php 
            echo $desc;
            ?>
</div><?php 
        }
        ?>
					
					<div id="portfolio-bt-handle"<?php 
        if ($isThere) {
            echo ' style="display:none;"';
        } else {
            echo ' style="display:block;"';
        }
        ?>
>
						<div id="pp-wip-pp">
						<input name="portfolio_button_upload" id="portfolio_button_upload" class="button-primary" type="button" value="<?php 
        esc_attr_e('Select Image', 'wip');
        ?>
" />
						<input type="hidden" name="portfolio_image_nonce" value="<?php 
        echo wp_create_nonce('portfolio_image_nonce');
        ?>
" />
						</div>
						
						<span class="or">- OR -</span>
						<input type="text" name="portfolio-video" id="portfolio-video" value="Enter video URL" onfocus="if (this.value == 'Enter video URL') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Enter video URL';}" />
						<span class="upload_button insert_video">Insert Video</span>
						
						<div class="clear"></div>

						<div class="panel_file_progress"></div>
					</div>
					
					<input name="<?php 
        echo $id;
        ?>
" id="<?php 
        echo $id;
        ?>
" class="portfolio_id" type="hidden" value="<?php 
        if ($value != "") {
            echo stripslashes($value);
        } else {
            echo "";
        }
        ?>
" />
					<input name="thispostid" class="thispostid" type="hidden" value="<?php 
        echo $post->ID;
        ?>
" />
					
					
					
				</div>
	
	<?php 
    }
/**
 * Print portfolio object
 * use in single portfolio page
 */
function _wip_print_portfolio_object()
{
    global $post;
    $isThere = false;
    $imageUrl = "";
    $video = "";
    $type = "";
    $preview = "";
    $vidType = "";
    $postID = $post->ID;
    if (!is_object($postID)) {
        $postID = (int) $postID;
    }
    $portfolioObjectID = get_post_meta($postID, '_wip_bd_portfolio', true);
    $portfolioData = get_option('bd_portfolio_data');
    if (!empty($portfolioData)) {
        if (array_key_exists($portfolioObjectID, $portfolioData)) {
            $port = $portfolioData[$portfolioObjectID];
            if ($port['type'] == 'image') {
                if (isset($port['image']) && is_array($port['image'])) {
                    $isThere = true;
                    $type = 'image';
                    $uploadPath = wp_upload_dir();
                    $imageDir = $uploadPath['basedir'] . $port['image']['subdir'] . '/' . $port['image']['image'];
                    $imageUrl = $uploadPath['baseurl'] . $port['image']['subdir'] . '/' . $port['image']['image'];
                    $preview = wip_print_autoresize($imageDir, $imageUrl, 700, 9999, false);
                }
            } elseif ($port['type'] == 'video') {
                if ($port['video'] != "") {
                    $isThere = true;
                    $type = 'video';
                    $video = $port['video'];
                    $vidType = typeOflink($video);
                }
            }
        }
    }
    if (!$isThere) {
        print '<p>' . __('Please set your portfolio object, by uploading an image or enter a video URL in custom metabox under the text editor!', 'wip') . '</p>';
    }
    if ($type !== "") {
        if ($type == 'image') {
            echo '<a href="' . $imageUrl . '" rel="prettyPhoto" title="' . the_title_attribute('echo=0') . '"><img src="' . $preview . '" alt="' . the_title_attribute('echo=0') . '" /></a>' . "\n";
        } else {
            if ($type == 'video') {
                echo WIPobjectPrint($video, $vidType, '700', '525', 'false');
            }
        }
    }
    return false;
}