public function widget($args, $instance)
 {
     extract($args);
     $title = apply_filters('widget_title', $instance['title']);
     $type = isset($instance['type']) ? $instance['type'] : false;
     $id = isset($instance['id']) ? $instance['id'] : false;
     $link = isset($instance['link']) ? $instance['link'] : false;
     echo $before_widget;
     if (!empty($title)) {
         echo $before_title . $title . $after_title;
     }
     $html = wp_trello::trello_output($type, $id, $link);
     echo $html;
     echo $after_widget;
 }
 function get_parent($object, $id)
 {
     $trello_objects = array(0 => 'organization', 1 => 'board', 2 => 'list', 3 => 'card');
     $singular = substr($object, 0, -1);
     $child_object = array_search($singular, $trello_objects);
     if ($child_object == 0) {
         return;
     }
     $parent_object = $trello_objects[$child_object - 1];
     $parent = wp_trello::get_data($parent_object, $id);
     return $parent;
 }
     /**
      * Generates the HTML output of the settings fields
      *
      * @param array callback args from add_settings_field()
      */
     function generate_setting($args)
     {
         $section = $args['section'];
         $defaults = array('id' => 'default_field', 'title' => 'Default Field', 'desc' => '', 'std' => '', 'type' => 'text', 'choices' => array(), 'class' => '');
         $defaults = apply_filters('wpsf_defaults', $defaults);
         extract(wp_parse_args($args['field'], $defaults));
         $options = get_option($this->option_group . '_settings');
         $el_id = $this->option_group . '_' . $section['section_id'] . '_' . $id;
         $val = isset($options[$el_id]) ? $options[$el_id] : $std;
         do_action('wpsf_before_field');
         do_action('wpsf_before_field_' . $el_id);
         switch ($type) {
             case 'text':
                 $val = esc_attr(stripslashes($val));
                 echo '<input type="text" name="' . $this->option_group . '_settings[' . $el_id . ']" id="' . $el_id . '" value="' . $val . '" class="regular-text ' . $class . '" />';
                 if ($desc) {
                     echo '<p class="description">' . $desc . '</p>';
                 }
                 break;
             case 'textarea':
                 $val = esc_html(stripslashes($val));
                 echo '<textarea name="' . $this->option_group . '_settings[' . $el_id . ']" id="' . $el_id . '" rows="5" cols="60" class="' . $class . '">' . $val . '</textarea>';
                 if ($desc) {
                     echo '<p class="description">' . $desc . '</p>';
                 }
                 break;
             case 'select':
                 $val = esc_html(esc_attr($val));
                 echo '<select name="' . $this->option_group . '_settings[' . $el_id . ']" id="' . $el_id . '" class="' . $class . '">';
                 foreach ($choices as $ckey => $cval) {
                     echo '<option value="' . $ckey . '"' . ($ckey == $val ? ' selected="selected"' : '') . '>' . $cval . '</option>';
                 }
                 echo '</select>';
                 if ($desc) {
                     echo '<p class="description">' . $desc . '</p>';
                 }
                 break;
             case 'radio':
                 $val = esc_html(esc_attr($val));
                 foreach ($choices as $ckey => $cval) {
                     echo '<span><input type="radio" name="' . $this->option_group . '_settings[' . $el_id . ']" id="' . $el_id . '_' . $ckey . '" value="' . $ckey . '" class="' . $class . '"' . ($ckey == $val ? ' checked="checked"' : '') . ' /> ' . $cval . '</span><br />';
                 }
                 if ($desc) {
                     echo '<p class="description">' . $desc . '</p>';
                 }
                 break;
             case 'checkbox':
                 $val = esc_attr(stripslashes($val));
                 echo '<input type="hidden" name="' . $this->option_group . '_settings[' . $el_id . ']" value="0" />';
                 echo '<span><input type="checkbox" name="' . $this->option_group . '_settings[' . $el_id . ']" id="' . $el_id . '" value="1" class="' . $class . '"' . ($val ? ' checked="checked"' : '') . ' /> ' . $desc . '</span>';
                 break;
             case 'checkboxes':
                 foreach ($choices as $ckey => $cval) {
                     $val = '';
                     if (isset($options[$el_id . '_' . $ckey])) {
                         $val = $options[$el_id . '_' . $ckey];
                     } elseif (is_array($std) && in_array($ckey, $std)) {
                         $val = $ckey;
                     }
                     $val = esc_html(esc_attr($val));
                     echo '<input type="hidden" name="' . $this->option_group . '_settings[' . $el_id . '_' . $ckey . ']" value="0" />';
                     echo '<span><input type="checkbox" name="' . $this->option_group . '_settings[' . $el_id . '_' . $ckey . ']" id="' . $el_id . '_' . $ckey . '" value="' . $ckey . '" class="' . $class . '"' . ($ckey == $val ? ' checked="checked"' : '') . ' /> ' . $cval . '</span><br />';
                 }
                 if ($desc) {
                     echo '<p class="description">' . $desc . '</p>';
                 }
                 break;
             case 'color':
                 $val = esc_attr(stripslashes($val));
                 echo '<div style="position:relative;">';
                 echo '<input type="text" name="' . $this->option_group . '_settings[' . $el_id . ']" id="' . $el_id . '" value="' . $val . '" class="' . $class . '" />';
                 echo '<div id="' . $el_id . '_cp" style="position:absolute;top:0;left:190px;background:#fff;z-index:9999;"></div>';
                 if ($desc) {
                     echo '<p class="description">' . $desc . '</p>';
                 }
                 echo '<script type="text/javascript">
 		        jQuery(document).ready(function($){ 
                     var colorPicker = $("#' . $el_id . '_cp");
                     colorPicker.farbtastic("#' . $el_id . '");
                     colorPicker.hide();
                     $("#' . $el_id . '").live("focus", function(){
                         colorPicker.show();
                     });
                     $("#' . $el_id . '").live("blur", function(){
                         colorPicker.hide();
                         if($(this).val() == "") $(this).val("#");
                     });
                 });
                 </script></div>';
                 break;
             case 'file':
                 $val = esc_attr($val);
                 echo '<input type="text" name="' . $this->option_group . '_settings[' . $el_id . ']" id="' . $el_id . '" value="' . $val . '" class="regular-text ' . $class . '" /> ';
                 echo '<input type="button" class="button wpsf-browse" id="' . $el_id . '_button" value="Browse" />';
                 echo '<script type="text/javascript">
                 jQuery(document).ready(function($){
             		$("#' . $el_id . '_button").click(function() {
             			tb_show("", "media-upload.php?post_id=0&amp;type=image&amp;TB_iframe=true");
             			window.original_send_to_editor = window.send_to_editor;
                     	window.send_to_editor = function(html) {
                     		var imgurl = $("img",html).attr("src");
                     		$("#' . $el_id . '").val(imgurl);
                     		tb_remove();
                     		window.send_to_editor = window.original_send_to_editor;
                     	};
             			return false;
             		});
                 });
                 </script>';
                 break;
             case 'editor':
                 wp_editor($val, $el_id, array('textarea_name' => $this->option_group . '_settings[' . $el_id . ']'));
                 if ($desc) {
                     echo '<p class="description">' . $desc . '</p>';
                 }
                 break;
             case 'custom':
                 echo $std;
                 break;
             case 'organizations':
                 $access_token = wp_trello::get_access_token();
                 $disabled = '';
                 if ($access_token == '') {
                     $choices = array(0 => 'Connect with Trello');
                     $disabled = ' disabled="disabled"';
                 } else {
                     $trello = new trello_oauth($access_token['oauth_token'], $access_token['oauth_token_secret']);
                     $orgs = $trello->getOrganizations();
                     $choices = $trello->getDropdown($orgs, 'organization');
                 }
                 $val = esc_html(esc_attr($val));
                 echo '<select name="' . $this->option_group . '_settings[' . $el_id . ']" id="' . $el_id . '" class="' . $class . '"' . $disabled . '>';
                 foreach ($choices as $ckey => $cval) {
                     echo '<option value="' . $ckey . '">' . $cval . '</option>';
                 }
                 echo '</select>  ID: <span id="org-id"></span>';
                 if ($desc) {
                     echo '<p class="description">' . $desc . '</p>';
                 }
                 break;
             case 'boards':
                 echo '<select name="' . $this->option_group . '_settings[' . $el_id . ']" id="' . $el_id . '" class="' . $class . '" disabled="disabled">';
                 echo '<option value="0">Select Board</option>';
                 echo '</select>  ID: <span id="board-id"></span>';
                 break;
             case 'lists':
                 echo '<select name="' . $this->option_group . '_settings[' . $el_id . ']" id="' . $el_id . '" class="' . $class . '" disabled="disabled">';
                 echo '<option value="0">Select List</option>';
                 echo '</select>  ID: <span id="list-id"></span>';
                 break;
             case 'cards':
                 echo '<select name="' . $this->option_group . '_settings[' . $el_id . ']" id="' . $el_id . '" class="' . $class . '" disabled="disabled">';
                 echo '<option value="0">Select Card</option>';
                 echo '</select>  ID: <span id="card-id"></span>';
                 break;
             default:
                 break;
         }
         do_action('wpsf_after_field');
         do_action('wpsf_after_field_' . $el_id);
     }