<?php
/* * ************************* Sidebar Posts Widget ************************** */

add_action('widgets_init', 'sidebar_posts_widgets');

function sidebar_posts_widgets() {
    register_widget('SidebarPosts');
}

class SidebarPosts extends WP_Widget {

    function SidebarPosts() {
        $widget_ops = array('classname' => 'sidebarposts', 'description' => __('Enhanced display for your sidebar posts.', 'gp_lang'));
        $this->WP_Widget('sidebar-posts-widget', __('GP Sidebar Posts', 'gp_lang'), $widget_ops);
    }

    function string_limit_words($string, $word_limit) {
        $words = explode(' ', $string, ($word_limit + 1));
        if (count($words) > $word_limit)
            array_pop($words);
        return implode(' ', $words);
    }

    function widget($args, $instance) {
        global $gp_settings, $post, $wp_query, $paged;
        extract($args);
        $title = apply_filters('widget_title', $instance['title']);
        $cats = $instance['cats'];
        $number = $instance['number'];
        $images = $instance['images'];
        $image_width = $instance['image_width'];
        $image_height = $instance['image_height'];
        $post_title = $instance['post_title'];
        $post_artist_song = $instance['post_artist_song'];
        $post_from_to = $instance['post_from_to'];
        $post_cats = $instance['post_cats'];
        $post_meta = $instance['post_meta'];
        $gd_sort = $instance['gd_sort'];
        $gd_order = $instance['gd_order'];
        $after_text = htmlspecialchars_decode($instance['after_text']);

        require(ghostpool_inc . 'options.php');

        // Begin Widget
        echo $before_widget;
        ?>

        <div class="posts-widget">

            <?php
            if ($title)
                echo $before_title . $title . $after_title;

            $args = array(
                'posts_per_page' => $number,
                'gdsr_sort' => $gd_sort,
                'gdsr_order' => $gd_order,
                'cat' => $cats
            );

            $temp = $wp_query;
            $wp_query = null;
            $wp_query = new WP_Query();
            $wp_query->query($args);

            // Column Width	
            $column_width = "300";

            if ($wp_query->have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post();
                    $counter++;

                    // Post Type
                    $gp_settings['post_type'] = get_post_meta($post->ID, 'ghostpool_post_type', true);

                    // Display First Image
                    if ($images == "First Image") {
                        $image_counter = $counter == 1;
                    } else {
                        $image_counter = "";
                    }
                    ?>

                    <div <?php post_class('post-loop'); ?>>

                        <!--Begin Image-->
                                <?php if (has_post_thumbnail() && ($images == "All Images" OR $image_counter)) { ?>	
                            <div class="post-thumbnail<?php if ($image_width >= 175) { ?> thumbnail-no-wrap<?php } ?>">											
                                <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                    <?php $image = vt_resize(get_post_thumbnail_id(), '', $image_width, $image_height, true); ?>
                                    <img src="<?php echo $image[url]; ?>" width="<?php echo $image[width]; ?>" height="<?php echo $image[height]; ?>" alt="<?php if (get_post_meta(get_post_thumbnail_id(), '_wp_attachment_image_alt', true)) {
                        echo get_post_meta(get_post_thumbnail_id(), '_wp_attachment_image_alt', true);
                    } else {
                        echo get_the_title();
                    } ?>" />
                                </a>						
                            </div>						
                <?php } ?>
                        <!--End Image-->

                        <!--Begin Post Text-->
                        <div class="post-text">



                            <?php if ($post_title == "Yes") { ?>
                                <a href="<?php the_permalink(); ?>" class="post-title" title="<?php the_title(); ?>"><?php the_title(); ?></a>
                            <?php } ?>

                            <?php
                            if ($post_artist_song == "Yes") {
                                $artist = get_post_meta($post->ID, 'ghostpool_dedication_artist', true);
                                $song = get_post_meta($post->ID, 'ghostpool_dedication_song', true);
                                $artist_song = $artist . '. ' . $song;
                                ?>
                                
                                <a href="<?php the_permalink(); ?>" class="post-artist-song" title="<?php echo $artist_song; ?>"><span><?php echo $artist; ?></span>.&nbsp;<?php echo $song; ?></a>
                                <?php } ?>

                                <?php
                                if ($post_from_to == "Yes") {
                                    $from_user_id = get_the_author_meta('ID');
                                    $to_user_id = get_post_meta($post->ID, 'ghostpool_destination_user_id', true);
                                    $to_user = get_user_by('id', $to_user_id);
                                    ?>
                                <div class="post-meta">
                                    <span>FROM: <?php echo bp_core_get_userlink($from_user_id); ?></span>
                                <?php if ($to_user) { ?><span>TO: <?php echo bp_core_get_userlink($to_user->ID); ?></span>
                                <?php } else { ?>
                                        <span>TO: <?php echo get_post_meta($post->ID, 'ghostpool_destination_user_name', true); ?></span>
                                    <?php } ?>
                                </div>
                            <?php } ?>                                                    

                <?php if ($post_cats == "Yes") { ?>
                                <div class="post-cats"><?php the_category(', '); ?></div>
                <?php } ?>

                <?php if ($post_meta == "Yes") { ?>
                                <div class="post-meta">
                        <?php the_time(get_option('date_format')); ?><?php if ('open' == $post->comment_status) { ?> - <?php comments_popup_link(__('No Comments', 'gp_lang'), __('1 Comment', 'gp_lang'), __('% Comments', 'gp_lang'), 'comments-link', ''); ?><?php } ?>
                                </div>
                    <?php } ?>



                        </div>
                        <!--End Post Text-->

                    </div>

            <?php endwhile; ?>
                <br class="clear"/>
            <?php echo $after_text . "\n"; ?>
        <?php endif;
        $wp_query = null;
        $wp_query = $temp;
        wp_reset_query(); ?>

        </div>

        <?php
        echo $after_widget;
        // End Widget
    }

    function update($new_instance, $old_instance) {
        $instance = $old_instance;
        $instance['title'] = strip_tags($new_instance['title']);
        $instance['cats'] = strip_tags($new_instance['cats']);
        $instance['number'] = strip_tags($new_instance['number']);
        $instance['images'] = $_POST['images'];
        $instance['image_width'] = strip_tags($new_instance['image_width']);
        $instance['image_height'] = strip_tags($new_instance['image_height']);
        $instance['post_title'] = $_POST['post_title'];
        $instance['post_artist_song'] = $_POST['post_artist_song'];
        $instance['post_from_to'] = $_POST['post_from_to'];
        $instance['post_cats'] = $_POST['post_cats'];
        $instance['post_meta'] = $_POST['post_meta'];
        $instance['score_type'] = $_POST['score_type'];
        $instance['gd_sort'] = $_POST['gd_sort'];
        $instance['gd_order'] = $_POST['gd_order'];
        $instance['after_text'] = htmlspecialchars($new_instance['after_text']);
        return $instance;
    }

    function form($instance) {

        $defaults = array(
            'title' => '',
            'cats' => '',
            'number' => 1,
            'images' => __('All Images', 'gp_lang'),
            'image_width' => '50',
            'image_height' => '0',
            'post_title' => __('No', 'gp_lang'),
            'post_artist_song' => __('Yes', 'gp_lang'),
            'post_from_to' => __('Yes', 'gp_lang'),
            'post_cats' => __('Yes', 'gp_lang'),
            'score_type' => __('Site Score', 'gp_lang'),
            'post_meta' => __('Yes', 'gp_lang'),
            'gd_sort' => 'review',
            'gd_order' => 'desc',
            'after_text' => ''
        );
        $instance = wp_parse_args((array) $instance, $defaults);
        ?>

        <p>
            <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title', 'gp_lang'); ?>:</label>
            <br/><input type="text" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $instance['title']; ?>" />
        </p>
        <p>
            <label for="<?php echo $this->get_field_id('cats'); ?>"><?php _e('Category IDs', 'gp_lang'); ?>:</label>
            <br/><input type="text" id="<?php echo $this->get_field_id('cats'); ?>" name="<?php echo $this->get_field_name('cats'); ?>" value="<?php echo $instance['cats']; ?>" />
        </p>
        <p>
            <label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number Of Posts', 'gp_lang'); ?>:</label>
            <br/><input type="text" id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" value="<?php echo $instance['number']; ?>" size="3" />
        </p>	
        <p>
            <label for="images"><?php _e('Images', 'gp_lang'); ?>:</label>
            <select id="images" name="images">
                <option value="<?php _e('All Images', 'gp_lang'); ?>"<?php if ($instance['images'] == __('All Images', 'gp_lang')) {
            echo ' selected="selected"';
        } ?>><?php _e('All Images', 'gp_lang'); ?></option>		
                <option value="<?php _e('First Image', 'gp_lang'); ?>"<?php if ($instance['images'] == __('First Image', 'gp_lang')) {
            echo ' selected="selected"';
        } ?>><?php _e('First Image', 'gp_lang'); ?></option>			
                <option value="<?php _e('No Images', 'gp_lang'); ?>"<?php if ($instance['images'] == __('No Images', 'gp_lang')) {
            echo ' selected="selected"';
        } ?>><?php _e('No Images', 'gp_lang'); ?></option> 			       
            </select>
        </p>		
        <p>
            <label for="<?php echo $this->get_field_id('image_width'); ?>"><?php _e('Image Width (px)', 'gp_lang'); ?>:</label>
            <br/><input type="text" id="<?php echo $this->get_field_id('image_width'); ?>" name="<?php echo $this->get_field_name('image_width'); ?>" value="<?php echo $instance['image_width']; ?>" size="3" />
        </p>			
        <p>
            <label for="<?php echo $this->get_field_id('image_height'); ?>"><?php _e('Image Height (px)', 'gp_lang'); ?>:</label>
            <br/><input type="text" id="<?php echo $this->get_field_id('image_height'); ?>" name="<?php echo $this->get_field_name('image_height'); ?>" value="<?php echo $instance['image_height']; ?>" size="3" />
        </p>		
        <p>
            <label for="post_title"><?php _e('Display Post Title', 'gp_lang'); ?>:</label>
            <select id="post_title" name="post_title">
                <option value="<?php _e('Yes', 'gp_lang'); ?>"<?php if ($instance['post_title'] == __('Yes', 'gp_lang')) {
            echo ' selected="selected"';
        } ?>><?php _e('Yes', 'gp_lang'); ?></option>			
                <option value="<?php _e('No', 'gp_lang'); ?>"<?php if ($instance['post_title'] == __('No', 'gp_lang')) {
            echo ' selected="selected"';
        } ?>><?php _e('No', 'gp_lang'); ?></option> 			       
            </select>
        </p>
        <p>
            <label for="post_artist_song"><?php _e('Display Post Artist and Song', 'gp_lang'); ?>:</label>
            <select id="post_artist_song" name="post_artist_song">
                <option value="<?php _e('Yes', 'gp_lang'); ?>"<?php if ($instance['post_artist_song'] == __('Yes', 'gp_lang')) {
            echo ' selected="selected"';
        } ?>><?php _e('Yes', 'gp_lang'); ?></option>			
                <option value="<?php _e('No', 'gp_lang'); ?>"<?php if ($instance['post_artist_song'] == __('No', 'gp_lang')) {
            echo ' selected="selected"';
        } ?>><?php _e('No', 'gp_lang'); ?></option> 			       
            </select>
        </p>
        <p>
            <label for="post_from_to"><?php _e('Display Post From and To', 'gp_lang'); ?>:</label>
            <select id="post_from_to" name="post_from_to">
                <option value="<?php _e('Yes', 'gp_lang'); ?>"<?php if ($instance['post_from_to'] == __('Yes', 'gp_lang')) {
            echo ' selected="selected"';
        } ?>><?php _e('Yes', 'gp_lang'); ?></option>			
                <option value="<?php _e('No', 'gp_lang'); ?>"<?php if ($instance['post_from_to'] == __('No', 'gp_lang')) {
            echo ' selected="selected"';
        } ?>><?php _e('No', 'gp_lang'); ?></option> 			       
            </select>
        </p>

        <p>
            <label for="<?php echo $this->get_field_id('after_text'); ?>"><?php _e('After HTML text', 'gp_lang'); ?>:</label>
            <textarea id="<?php echo $this->get_field_id('after_text'); ?>" name="<?php echo $this->get_field_name('after_text'); ?>"  style="width:100%;height:100px;"><?php echo $instance['after_text']; ?></textarea>
        </p>


        <p>
            <label for="post_cats"><?php _e('Display Post Categories', 'gp_lang'); ?>:</label>
            <select id="post_cats" name="post_cats">
                <option value="<?php _e('Yes', 'gp_lang'); ?>"<?php if ($instance['post_cats'] == __('Yes', 'gp_lang')) {
            echo ' selected="selected"';
        } ?>><?php _e('Yes', 'gp_lang'); ?></option>			
                <option value="<?php _e('No', 'gp_lang'); ?>"<?php if ($instance['post_cats'] == __('No', 'gp_lang')) {
            echo ' selected="selected"';
        } ?>><?php _e('No', 'gp_lang'); ?></option> 			       
            </select>
        </p>
        <p>
            <label for="post_meta"><?php _e('Display Post Meta', 'gp_lang'); ?>:</label>
            <select id="post_meta" name="post_meta">
                <option value="<?php _e('Yes', 'gp_lang'); ?>"<?php if ($instance['post_meta'] == __('Yes', 'gp_lang')) {
            echo ' selected="selected"';
        } ?>><?php _e('Yes', 'gp_lang'); ?></option>			
                <option value="<?php _e('No', 'gp_lang'); ?>"<?php if ($instance['post_meta'] == __('No', 'gp_lang')) {
            echo ' selected="selected"';
        } ?>><?php _e('No', 'gp_lang'); ?></option> 			       
            </select>
        </p>
        <p>
            <label for="gd_sort"><?php _e('Sort By', 'gp_lang'); ?>:</label>
            <select id="gd_sort" name="gd_sort">
                <option value="date"<?php if ($instance['gd_sort'] == __('date', 'gp_lang')) {
            echo ' selected="selected"';
        } ?>><?php _e('Date', 'gp_lang'); ?></option>				
            </select>
        </p>
        <p>
            <label for="gd_order"><?php _e('Order', 'gp_lang'); ?>:</label>
            <select id="gd_order" name="gd_order">
                <option value="desc"<?php if ($instance['gd_order'] == "desc") {
            echo ' selected="selected"';
        } ?>><?php _e('Descending', 'gp_lang'); ?></option> 			
                <option value="asc"<?php if ($instance['gd_order'] == "asc") {
            echo ' selected="selected"';
        } ?>><?php _e('Ascending', 'gp_lang'); ?></option>							
            </select>
        </p>

        <input type="hidden" name="widget-options" id="widget-options" value="1" />

            <?php
        }

    }

    /*     * ************************* Footer Posts Widget ************************** */

    add_action('widgets_init', 'footer_posts_widgets');

    function footer_posts_widgets() {
        register_widget('FooterPosts');
    }

    class FooterPosts extends WP_Widget {

        function FooterPosts() {
            $widget_ops = array('classname' => 'footerposts', 'description' => __('Enhanced display for your footer posts.', 'gp_lang'));
            $this->WP_Widget('footer-posts-widget', __('GP Footer Posts', 'gp_lang'), $widget_ops);
        }

        function widget($args, $instance) {
            global $gp_settings, $post, $wp_query, $paged;
            extract($args);
            $title = apply_filters('widget_title', $instance['title']);
            $cats = $instance['cats'];
            $number = $instance['number'];
            $images = $instance['images'];
            $image_width = $instance['image_width'];
            $image_height = $instance['image_height'];
            $post_cats = $instance['post_cats'];
            $post_meta = $instance['post_meta'];
            $score_type = $instance['score_type'];
            $gd_sort = $instance['gd_sort'];
            $gd_order = $instance['gd_order'];

            require(ghostpool_inc . 'options.php');

            // Begin Widget
            echo $before_widget;
            ?>

        <div class="posts-widget">

            <?php
            if ($title)
                echo $before_title . $title . $after_title;

            $args = array(
                'posts_per_page' => $number,
                'gdsr_sort' => $gd_sort,
                'gdsr_order' => $gd_order,
                'cat' => $cats
            );

            $temp = $wp_query;
            $wp_query = null;
            $wp_query = new WP_Query();
            $wp_query->query($args);

            // Widget Width	
            if (is_active_sidebar('footer-1') && is_active_sidebar('footer-2') && is_active_sidebar('footer-3') && is_active_sidebar('footer-4')) {
                $column_width = "207.5";
            } elseif (is_active_sidebar('footer-1') && is_active_sidebar('footer-2') && is_active_sidebar('footer-3')) {
                $column_width = "286.6";
            } elseif (is_active_sidebar('footer-1') && is_active_sidebar('footer-2')) {
                $column_width = "445";
            } elseif (is_active_sidebar('footer-1')) {
                $column_width = "920";
            }

            if ($wp_query->have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post();
                    $counter++;

                    // Post Type
                    $gp_settings['post_type'] = get_post_meta($post->ID, 'ghostpool_post_type', true);

                    if (defined('STARRATING_INSTALLED')) {

                        $gp_gdsr = wp_gdsr_rating_article();

                        // Site Score Colors		
                        if ($gp_gdsr->review <= $theme_score_range_2) {
                            $site_score_color = ' style="background: ' . $theme_site_score_color_1 . ';"';
                        } elseif ($gp_gdsr->review >= $theme_score_range_3 && $gp_gdsr->review <= $theme_score_range_4) {
                            $site_score_color = ' style="background: ' . $theme_site_score_color_2 . ';"';
                        } elseif ($gp_gdsr->review >= $theme_score_range_5 && $gp_gdsr->review <= $theme_score_range_6) {
                            $site_score_color = ' style="background: ' . $theme_site_score_color_3 . ';"';
                        } elseif ($gp_gdsr->review >= $theme_score_range_7) {
                            $site_score_color = ' style="background: ' . $theme_site_score_color_4 . ';"';
                        }

                        // User Score Colors
                        if ($gp_gdsr->rating <= $theme_score_range_2) {
                            $user_score_color = ' style="background: ' . $theme_user_score_color_1 . ';"';
                        } elseif ($gp_gdsr->rating >= $theme_score_range_3 && $gp_gdsr->rating <= $theme_score_range_4) {
                            $user_score_color = ' style="background: ' . $theme_user_score_color_2 . ';"';
                        } elseif ($gp_gdsr->rating >= $theme_score_range_5 && $gp_gdsr->rating <= $theme_score_range_6) {
                            $user_score_color = ' style="background: ' . $theme_user_score_color_3 . ';"';
                        } elseif ($gp_gdsr->rating >= $theme_score_range_7) {
                            $user_score_color = ' style="background: ' . $theme_user_score_color_4 . ';"';
                        }
                    }

                    // Display First Image
                    if ($images == "First Image") {
                        $image_counter = $counter == 1;
                    } else {
                        $image_counter = "";
                    }

                    // Post Text Width
                    if (!has_post_thumbnail() OR $images == "No Images" OR ($images == "First Image" && !$image_counter) OR $image_width >= 175) {
                        $post_text_width = $column_width;
                    } else {
                        $post_text_width = $column_width - $image_width - 17;
                    }

                    // Post Left Width
                    if ($gp_settings['post_type'] == "Review" && ($score_type == "Site Score" && $gp_gdsr->review > 0) OR ($score_type == "User Score" && $gp_settings['user_voting'] != "Users cannot vote") OR ($score_type == "Site & User Score" && ($gp_gdsr->review > 0 OR $gp_settings['user_voting'] != "Users cannot vote"))) {
                        $post_left_width = $post_text_width - 49;
                    } else {
                        $post_left_width = $post_text_width;
                    }
                    ?>

                    <div <?php post_class('post-loop'); ?>>

                        <!--Begin Image-->
                <?php if (has_post_thumbnail() && ($images == "All Images" OR $image_counter)) { ?>	
                            <div class="post-thumbnail<?php if ($image_width >= 175) { ?> thumbnail-no-wrap<?php } ?>">					
                                    <?php if ($gp_settings['post_type'] == "Video") { ?><span class="video-icon"></span><?php } ?>
                                <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                                        <?php $image = vt_resize(get_post_thumbnail_id(), '', $image_width, $image_height, true); ?>
                                    <img src="<?php echo $image[url]; ?>" width="<?php echo $image[width]; ?>" height="<?php echo $image[height]; ?>" alt="<?php if (get_post_meta(get_post_thumbnail_id(), '_wp_attachment_image_alt', true)) {
                        echo get_post_meta(get_post_thumbnail_id(), '_wp_attachment_image_alt', true);
                    } else {
                        echo get_the_title();
                    } ?>" />
                                </a>						
                            </div>						
                <?php } ?>
                        <!--End Image-->

                        <!--Begin Post Text-->
                        <div class="post-text<?php if ($gp_settings['post_type'] == "Review" && ($score_type == "No Scores" OR ($gp_gdsr->review <= 0 && $gp_settings['user_voting'] == "Users cannot vote"))) { ?> hidden<?php } ?>" style="width: <?php echo $post_text_width; ?>px;">

                            <div class="left" style="width: <?php echo $post_left_width; ?>px;">

                                <a href="<?php the_permalink(); ?>" class="post-title" title="<?php the_title(); ?>"><?php the_title(); ?></a>

                <?php if ($post_cats == "Yes") { ?>
                                    <div class="post-cats"><?php the_category(', '); ?></div>
                <?php } ?>

                <?php if ($post_meta == "Yes") { ?>
                                    <div class="post-meta">
                    <?php the_time(get_option('date_format')); ?><?php if ('open' == $post->comment_status) { ?> - <?php comments_popup_link(__('No Comments', 'gp_lang'), __('1 Comment', 'gp_lang'), __('% Comments', 'gp_lang'), 'comments-link', ''); ?><?php } ?>
                                    </div>
                <?php } ?>

                            </div>

                            <!--Begin Scores-->
                <?php if (defined('STARRATING_INSTALLED') && $gp_settings['post_type'] == "Review" && ($score_type != "No Scores" && ($gp_gdsr->review > 0 OR $gp_settings['user_voting'] != "Users cannot vote"))) { ?>

                                <div class="post-scores">

                                    <!--Begin Site Score-->	
                    <?php if ($score_type != "User Score" && $gp_gdsr->review > 0) { ?>
                                        <div class="site-score"<?php echo $site_score_color; ?>>
                        <?php echo $gp_gdsr->review; ?>
                                        </div>
                    <?php } ?>
                                    <!--End Site Score-->	

                                    <!--Begin User Score-->			
                    <?php if ($score_type != "Site Score" && $gp_settings['user_voting'] != "Users cannot vote") { ?>
                                        <div class="user-score"<?php echo $user_score_color; ?>>
                        <?php echo $gp_gdsr->rating; ?>
                                        </div>
                    <?php } ?>
                                    <!--End User Score-->

                                </div>

                <?php } ?>
                            <!--End Scores-->

                        </div>
                        <!--End Post Text-->

                    </div>

            <?php endwhile;
        endif;
        $wp_query = null;
        $wp_query = $temp;
        wp_reset_query(); ?>

        </div>

        <?php
        echo $after_widget;
        // End Widget
    }

    function update($new_instance, $old_instance) {
        $instance = $old_instance;
        $instance['title'] = strip_tags($new_instance['title']);
        $instance['cats'] = strip_tags($new_instance['cats']);
        $instance['number'] = strip_tags($new_instance['number']);
        $instance['images'] = $_POST['images'];
        $instance['image_width'] = strip_tags($new_instance['image_width']);
        $instance['image_height'] = strip_tags($new_instance['image_height']);
        $instance['post_cats'] = $_POST['post_cats'];
        $instance['post_meta'] = $_POST['post_meta'];
        $instance['score_type'] = $_POST['score_type'];
        $instance['gd_sort'] = $_POST['gd_sort'];
        $instance['gd_order'] = $_POST['gd_order'];
        return $instance;
    }

    function form($instance) {

        $defaults = array('title' => '', 'cats' => '', 'number' => 5, 'images' => __('All Images', 'gp_lang'), 'image_width' => '50', 'image_height' => '0', 'post_cats' => __('Yes', 'gp_lang'), 'score_type' => __('Site Score', 'gp_lang'), 'post_meta' => __('Yes', 'gp_lang'), 'gd_sort' => 'review', 'gd_order' => 'desc');
        $instance = wp_parse_args((array) $instance, $defaults);
        ?>

        <p>
            <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title', 'gp_lang'); ?>:</label>
            <br/><input type="text" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $instance['title']; ?>" />
        </p>
        <p>
            <label for="<?php echo $this->get_field_id('cats'); ?>"><?php _e('Category IDs', 'gp_lang'); ?>:</label>
            <br/><input type="text" id="<?php echo $this->get_field_id('cats'); ?>" name="<?php echo $this->get_field_name('cats'); ?>" value="<?php echo $instance['cats']; ?>" />
        </p>
        <p>
            <label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number Of Posts', 'gp_lang'); ?>:</label>
            <br/><input type="text" id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" value="<?php echo $instance['number']; ?>" size="3" />
        </p>	
        <p>
            <label for="images"><?php _e('Images', 'gp_lang'); ?>:</label>
            <select id="images" name="images">
                <option value="<?php _e('All Images', 'gp_lang'); ?>"<?php if ($instance['images'] == __('All Images', 'gp_lang')) {
            echo ' selected="selected"';
        } ?>><?php _e('All Images', 'gp_lang'); ?></option>		
                <option value="<?php _e('First Image', 'gp_lang'); ?>"<?php if ($instance['images'] == __('First Image', 'gp_lang')) {
            echo ' selected="selected"';
        } ?>><?php _e('First Image', 'gp_lang'); ?></option>			
                <option value="<?php _e('No Images', 'gp_lang'); ?>"<?php if ($instance['images'] == __('No Images', 'gp_lang')) {
            echo ' selected="selected"';
        } ?>><?php _e('No Images', 'gp_lang'); ?></option> 			       
            </select>
        </p>		
        <p>
            <label for="<?php echo $this->get_field_id('image_width'); ?>"><?php _e('Image Width (px)', 'gp_lang'); ?>:</label>
            <br/><input type="text" id="<?php echo $this->get_field_id('image_width'); ?>" name="<?php echo $this->get_field_name('image_width'); ?>" value="<?php echo $instance['image_width']; ?>" size="3" />
        </p>			
        <p>
            <label for="<?php echo $this->get_field_id('image_height'); ?>"><?php _e('Image Height (px)', 'gp_lang'); ?>:</label>
            <br/><input type="text" id="<?php echo $this->get_field_id('image_height'); ?>" name="<?php echo $this->get_field_name('image_height'); ?>" value="<?php echo $instance['image_height']; ?>" size="3" />
        </p>		
        <p>
            <label for="post_cats"><?php _e('Display Post Categories', 'gp_lang'); ?>:</label>
            <select id="post_cats" name="post_cats">
                <option value="<?php _e('Yes', 'gp_lang'); ?>"<?php if ($instance['post_cats'] == __('Yes', 'gp_lang')) {
            echo ' selected="selected"';
        } ?>><?php _e('Yes', 'gp_lang'); ?></option>			
                <option value="<?php _e('No', 'gp_lang'); ?>"<?php if ($instance['post_cats'] == __('No', 'gp_lang')) {
            echo ' selected="selected"';
        } ?>><?php _e('No', 'gp_lang'); ?></option> 			       
            </select>
        </p>
        <p>
            <label for="post_meta"><?php _e('Display Post Meta', 'gp_lang'); ?>:</label>
            <select id="post_meta" name="post_meta">
                <option value="<?php _e('Yes', 'gp_lang'); ?>"<?php if ($instance['post_meta'] == __('Yes', 'gp_lang')) {
            echo ' selected="selected"';
        } ?>><?php _e('Yes', 'gp_lang'); ?></option>			
                <option value="<?php _e('No', 'gp_lang'); ?>"<?php if ($instance['post_meta'] == __('No', 'gp_lang')) {
            echo ' selected="selected"';
        } ?>><?php _e('No', 'gp_lang'); ?></option> 			       
            </select>
        </p>
        <p>
            <label for="score_type"><?php _e('Score Type', 'gp_lang'); ?>:</label>
            <select id="score_type" name="score_type">
                <option value="<?php _e('Site Score', 'gp_lang'); ?>" <?php if ($instance['score_type'] == __('Site Score', 'gp_lang')) {
            echo ' selected="selected"';
        } ?>><?php _e('Site Score', 'gp_lang'); ?></option>			
                <option value="<?php _e('User Score', 'gp_lang'); ?>" <?php if ($instance['score_type'] == __('User Score', 'gp_lang')) {
            echo ' selected="selected"';
        } ?>><?php _e('User Score', 'gp_lang'); ?></option> 	
                <option value="<?php _e('Site & User Score', 'gp_lang'); ?>" <?php if ($instance['score_type'] == __('Site & User Score', 'gp_lang')) {
            echo ' selected="selected"';
        } ?>><?php _e('Site & User Score', 'gp_lang'); ?></option> 	
                <option value="<?php _e('No Scores', 'gp_lang'); ?>" <?php if ($instance['score_type'] == __('No Scores', 'gp_lang')) {
            echo ' selected="selected"';
        } ?>><?php _e('No Scores', 'gp_lang'); ?></option> 					
            </select>
        </p>				
        <p>
            <label for="gd_sort"><?php _e('Sort By', 'gp_lang'); ?>:</label>
            <select id="gd_sort" name="gd_sort">
                <option value="date"<?php if ($instance['gd_sort'] == __('date', 'gp_lang')) {
            echo ' selected="selected"';
        } ?>><?php _e('Date', 'gp_lang'); ?></option>				
                <option value="review"<?php if ($instance['gd_sort'] == 'review') {
            echo ' selected="selected"';
        } ?>><?php _e('Site Score', 'gp_lang'); ?></option>			
                <option value="rating"<?php if ($instance['gd_sort'] == 'rating') {
            echo ' selected="selected"';
        } ?>><?php _e('User Score', 'gp_lang'); ?></option> 			
                <option value="votes"<?php if ($instance['gd_sort'] == 'votes') {
            echo ' selected="selected"';
        } ?>><?php _e('Votes', 'gp_lang'); ?></option>	                
            </select>
        </p>
        <p>
            <label for="gd_order"><?php _e('Order', 'gp_lang'); ?>:</label>
            <select id="gd_order" name="gd_order">
                <option value="desc"<?php if ($instance['gd_order'] == "desc") {
            echo ' selected="selected"';
        } ?>><?php _e('Descending', 'gp_lang'); ?></option> 			
                <option value="asc"<?php if ($instance['gd_order'] == "asc") {
            echo ' selected="selected"';
        } ?>><?php _e('Ascending', 'gp_lang'); ?></option>							
            </select>
        </p>

        <input type="hidden" name="widget-options" id="widget-options" value="1" />

        <?php
    }

}
?>