<?php

  
function sf_theme_widget_google_video($args) {
      
extract($args);
      
$options get_option('sf_theme_widget_google_video');
      if (!
is_home() && $options['onlyhome'])
        return;
      if (!
$options['url'] || !preg_match('|\?docid=([^&]+).*?$|i'$options['url'], $M))
        return;
      
$title $options['title'];
      
$url htmlspecialchars($options['url']);
      print 
$before_widget $before_title '<a href="' $url '">' $title '</a>' $after_title;
      print 
'<embed style="width:139px; height:120px;" id="VideoPlayback" type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docId='.$M[1].'" flashvars=""> </embed>';
      print 
$after_widget;
  }

  function 
sf_theme_widget_google_video_control() {
      global 
$wpdb;
      
$options get_option('sf_theme_widget_google_video');
      if ( !
is_array($options) )
          
$options = array('title'=>'Video''url'=>'http://video.google.com/videoplay?docid=-7408504973132978571');
      if ( 
$_POST['google_video-submit'] ) {
          
$options['title'] = strip_tags(stripslashes($_POST['google_video-title']));
          
$options['url'] = strip_tags(stripslashes($_POST['google_video-url']));
          
$options['onlyhome'] = isset($_POST['google_video-onlyhome']);
          
update_option('sf_theme_widget_google_video'$options);
      }
      
$title htmlspecialchars($options['title'], ENT_QUOTES);
      
$url htmlspecialchars($options['url'], ENT_QUOTES);
      
$onlyhome $options['onlyhome'] ? 'checked="checked"' '';
      
?>
      <label for="google_video-title" style="line-height:35px;display:block;">Titel</label><input style="width: 200px;" id="google_video-title" name="google_video-title" type="text" value="<?php echo $title?>" />
      <label for="google_video-url" style="line-height:35px;display:block;">URL</label><input style="width: 325px;" id="google_video-url" name="google_video-url" type="text" value="<?php echo $url?>" />
      <p style="text-align:right;margin-right:15px;"><label for="google_video-onlyhome">Vis kun på forsiden? <input class="checkbox" type="checkbox" <?php echo $onlyhome?> id="google_video-onlyhome" name="google_video-onlyhome" /></label></p>
      <input type="hidden" id="google_video-submit" name="google_video-submit" value="1" />
      <?php
    
}

function 
sf_theme_widget_google_video_init() {
    if (!
function_exists('register_sidebar'))
        return;
    
register_sidebar_widget('Google Video''sf_theme_widget_google_video');
    
register_widget_control('Google Video''sf_theme_widget_google_video_control'350200);
}

add_action('init''sf_theme_widget_google_video_init');

?>