<?php
/*
 * Shows thumbnails of the recent games
 *
 */

if ( !class_exists('WP_Widget_MABP_Recent_Games') ) {
  class WP_Widget_MABP_Recent_Games extends WP_Widget {

    // Constructor
    function WP_Widget_MABP_Recent_Games() {

      $widget_ops   = array('description' => __('Shows images of the most recent games.', 'myarcadetheme'));

      $this->WP_Widget('MABP_Recent_Games', __('MyArcade Recent Games', 'myarcadetheme'), $widget_ops);
    }

    // Display Widget
    function widget($args, $instance) {
      extract($args);

      $title = apply_filters('widget_title', esc_attr($instance['title']));
      $limit = intval($instance['limit']);

      global $post, $wpdb;

      echo $before_widget;

      if($title) {
        echo $before_title . $title . $after_title;
      }

      echo'<div class="most-popu"><ul class="sldr-ft">';
      // <-- START --> HERE COMES THE OUTPUT
      $games = new WP_Query("showposts=".$limit.myarcadetheme_mobile_tag().myarcadetheme_exclude_blog());

      if ( !empty($games) ) {

        while( $games->have_posts() ) : $games->the_post();
        ?>
        <!--<game>-->
        <li>
          <div class="gmcn-smal-2">
            <figure class="gm-imag">
              <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" itemprop="url">
                <?php myarcade_thumbnail( array( 'width' => 60, 'height' => 60 , 'class' => 'widgetimage', 'lazy_load' => myarcadetheme_get_option('lazy_load') ) ); ?><span class="fa-gamepad"><strong><?php _e('Play', 'myarcadetheme'); ?></strong></span>
              </a>
            </figure>
            <div class="gm-titl" itemprop="name">
              <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" itemprop="url"><?php myarcade_title(20); ?></a></div>

           <?php myarcadetheme_rate_and_view(); ?>
        </div>
      </li>
      <!--</game>-->
      <?php
      endwhile;
      wp_reset_query();
    }

      // <-- END --> HERE COMES THE OUTPUT
    echo'</ul></div>';
    echo $after_widget;
  }

    // Update Widget
  function update($new_instance, $old_instance) {

    $instance = $old_instance;
    $instance['title'] = strip_tags($new_instance['title']);
    $instance['limit'] = intval($new_instance['limit']);

    return $instance;
  }

    // Display Widget Control Form
  function form($instance) {
    global $wpdb;

    $instance = wp_parse_args((array) $instance, array('title' => __('Recent Games', 'myarcadetheme'), 'limit' => 12));

    $title = esc_attr($instance['title']);
    $limit = intval($instance['limit']);

    ?>

    <p>
      <label for="<?php echo $this->get_field_id('title'); ?>">
        <?php _e('Title', 'myarcadetheme'); ?>
        <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
      </label>
    </p>

    <p>
      <label for="<?php echo $this->get_field_id('limit'); ?>">
        <?php _e('Limit', 'myarcadetheme'); ?>
        <input class="widefat" id="<?php echo $this->get_field_id('limit'); ?>" name="<?php echo $this->get_field_name('limit'); ?>" type="text" value="<?php echo $limit; ?>" />
      </label>
    </p>

    <?php
  }
}
}
?>