function form($instance) { $instance = wp_parse_args((array) $instance, $this->default_settings); $games = \WP_Clanwars\Games::get_game('id=all&orderby=title&order=asc'); ?> <div class="wp-clanwars-widget-settings"> <p> <label for="<?php echo $this->get_field_id('title'); ?> "><?php _e('Title:', WP_CLANWARS_TEXTDOMAIN); ?> </label> <input class="widefat" name="<?php echo $this->get_field_name('title'); ?> " id="<?php echo $this->get_field_id('title'); ?> " value="<?php esc_attr_e($instance['title']); ?> " type="text" /> </p> <p> <input class="checkbox" name="<?php echo $this->get_field_name('hide_title'); ?> " id="<?php echo $this->get_field_id('hide_title'); ?> " value="1" type="checkbox" <?php checked($instance['hide_title'], true); ?> /> <label for="<?php echo $this->get_field_id('hide_title'); ?> "><?php _e('Hide title', WP_CLANWARS_TEXTDOMAIN); ?> </label> </p> <p> <input class="checkbox" name="<?php echo $this->get_field_name('display_both_teams'); ?> " id="<?php echo $this->get_field_id('display_both_teams'); ?> " value="1" type="checkbox" <?php checked($instance['display_both_teams'], true); ?> /> <label for="<?php echo $this->get_field_id('display_both_teams'); ?> "> <?php _e('Display both teams', WP_CLANWARS_TEXTDOMAIN); ?> </label> </p> <p> <input class="checkbox" name="<?php echo $this->get_field_name('display_game_icon'); ?> " id="<?php echo $this->get_field_id('display_game_icon'); ?> " value="1" type="checkbox" <?php checked($instance['display_game_icon'], true); ?> /> <label for="<?php echo $this->get_field_id('display_game_icon'); ?> "> <?php _e('Display game icon', WP_CLANWARS_TEXTDOMAIN); ?> </label> </p> <p><?php _e('Show games:', WP_CLANWARS_TEXTDOMAIN); ?> </p> <p> <?php foreach ($games as $item) { ?> <label for="<?php echo $this->get_field_id('visible_games-' . $item->id); ?> "><input type="checkbox" name="<?php echo $this->get_field_name('visible_games'); ?> []" id="<?php echo $this->get_field_id('visible_games-' . $item->id); ?> " value="<?php echo esc_attr($item->id); ?> " <?php checked(true, in_array($item->id, $instance['visible_games'])); ?> /> <?php esc_html_e($item->title); ?> </label><br/> <?php } ?> </p> <p><?php _e('Do not check any game if you want to show all games.', WP_CLANWARS_TEXTDOMAIN); ?> </p> <p> <label for="<?php echo $this->get_field_id('show_limit'); ?> "><?php _e('Show matches:', WP_CLANWARS_TEXTDOMAIN); ?> </label> <input type="text" size="3" name="<?php echo $this->get_field_name('show_limit'); ?> " id="<?php echo $this->get_field_id('show_limit'); ?> " value="<?php esc_attr_e($instance['show_limit']); ?> " /> </p> <p class="widget-setting-hide-older-than"> <label for="<?php echo $this->get_field_id('hide_older_than'); ?> "><?php _e('Hide matches older than', WP_CLANWARS_TEXTDOMAIN); ?> </label> <select name="<?php echo $this->get_field_name('hide_older_than'); ?> " id="<?php echo $this->get_field_id('hide_older_than'); ?> "> <?php foreach ($this->newer_than_options as $key => $option) { ?> <option value="<?php esc_attr_e($key); ?> "<?php selected($key, $instance['hide_older_than']); ?> ><?php esc_html_e($option['title']); ?> </option> <?php } ?> </select> </p> <p class="widget-setting-custom-hide-duration <?php if ($instance['hide_older_than'] !== 'custom') { esc_attr_e('hidden'); } ?> "> <label for="<?php echo $this->get_field_id('custom_hide_duration'); ?> "><?php _e('Custom (days): ', WP_CLANWARS_TEXTDOMAIN); ?> </label> <input type="text" size="3" name="<?php echo $this->get_field_name('custom_hide_duration'); ?> " id="<?php echo $this->get_field_id('custom_hide_duration'); ?> " value="<?php esc_attr_e($instance['custom_hide_duration']); ?> " /> </p> </div> <?php }
function prepare_items() { $per_page = $this->get_items_per_page(static::PER_PAGE_OPTION, static::PER_PAGE_DEFAULT); $current_page = $this->get_pagenum(); $orderby = isset($_REQUEST['orderby']) ? $_REQUEST['orderby'] : 'id'; $order = isset($_REQUEST['order']) ? $_REQUEST['order'] : 'desc'; $offset = ($current_page - 1) * $per_page; $limit = $per_page; $filter_games = \WP_Clanwars\ACL::user_can('which_games'); $args = array('id' => $filter_games, 'order' => $order, 'orderby' => $orderby, 'order' => $order, 'limit' => $limit, 'offset' => $limit * ($current_page - 1)); $games = \WP_Clanwars\Games::get_game($args); $pagination = $games->get_pagination(); $this->set_pagination_args(array('total_pages' => $pagination->get_num_pages(), 'total_items' => $pagination->get_num_rows(), 'per_page' => $per_page)); $this->items = $games->getArrayCopy(); }
function on_import_browse() { $query_args = Utils::extract_args(stripslashes_deep($_GET), array('q' => '')); $logged_into_cloud = CloudAPI::is_logged_in(); $cloud_account = CloudAPI::get_user_info(); $search_query = trim((string) $query_args['q']); $installed_games = \WP_Clanwars\Games::get_game('')->getArrayCopy(); $store_ids = array_filter(array_map(function ($game) { return $game->store_id; }, $installed_games)); $active_tab = ''; $install_action = 'wp-clanwars-import'; if (empty($search_query)) { $api_response = CloudAPI::get_popular(); $active_tab = 'popular'; } else { $api_response = CloudAPI::search($search_query); $active_tab = 'search'; } $api_games = array(); if (!is_wp_error($api_response)) { array_walk($api_response, function (&$game) use($store_ids) { $game->is_installed = in_array($game->_id, $store_ids); }); $api_games = $api_response; } else { $api_error_message = $api_response->get_error_message(); } $view = new View('import_browse'); $context = compact('api_games', 'api_error_message', 'search_query', 'active_tab', 'install_action', 'logged_into_cloud', 'cloud_account'); wp_enqueue_script('wp-clanwars-game-browser'); wp_enqueue_script('wp-clanwars-login'); $view->render($context); }
static function get_match($args) { global $wpdb; $defaults = array('from_date' => 0, 'id' => false, 'game_id' => false, 'sum_tickets' => false, 'limit' => 0, 'offset' => 0, 'orderby' => 'id', 'order' => 'asc'); $args = \WP_Clanwars\Utils::extract_args($args, $defaults); extract($args); $where_query = ''; $limit_query = ''; $order_query = ''; $order = strtolower($order); if ($order != 'asc' && $order != 'desc') { $order = 'asc'; } $order_query = 'ORDER BY t1.`' . $orderby . '` ' . $order; if ($id != 'all' && $id !== false) { if (!is_array($id)) { $id = array($id); } $id = array_map('intval', $id); $where_query[] = 't1.id IN (' . join(', ', $id) . ')'; } if ($game_id != 'all' && $game_id !== false) { if (!is_array($game_id)) { $game_id = array($game_id); } $game_id = array_map('intval', $game_id); $where_query[] = 't1.game_id IN (' . join(', ', $game_id) . ')'; } if ($from_date > 0) { $where_query[] = 't1.date >= FROM_UNIXTIME(' . intval($from_date) . ')'; } if ($limit > 0) { $limit_query = $wpdb->prepare('LIMIT %d, %d', $offset, $limit); } if (!empty($where_query)) { $where_query = 'WHERE ' . join(' AND ', $where_query); } $rounds_table = \WP_Clanwars\Rounds::table(); $games_table = \WP_Clanwars\Games::table(); $teams_table = \WP_Clanwars\Teams::table(); $matches_table = static::table(); if ($sum_tickets) { $subquery = <<<SQL \t \t\t\t( \t\t\t\tSELECT SUM(sumt1.tickets1) \t\t\t\tFROM `{$rounds_table}` AS sumt1 \t\t\t\tWHERE sumt1.match_id = t1.id \t\t\t) AS team1_tickets, \t\t\t( \t\t\t\tSELECT SUM(sumt2.tickets2) \t\t\t\tFROM `{$rounds_table}` AS sumt2 \t\t\t\tWHERE sumt2.match_id = t1.id \t\t\t) AS team2_tickets SQL; $subquery = trim($subquery); } else { $subquery = 'NULL'; } $query = <<<SQL \t\tSELECT \t\t\tt1.*, \t\t\tt2.title AS game_title, \t\t\tt2.abbr AS game_abbr, \t\t\tt2.icon AS game_icon, \t\t\ttt1.title AS team1_title, \t\t\ttt2.title AS team2_title, \t\t\ttt1.country AS team1_country, \t\t\ttt2.country AS team2_country, \t\t\t{$subquery} \t\tFROM `{$matches_table}` AS t1 \t\t\tLEFT JOIN `{$games_table}` AS t2 ON t1.game_id = t2.id \t\t\tLEFT JOIN `{$teams_table}` AS tt1 ON t1.team1 = tt1.id \t\t\tLEFT JOIN `{$teams_table}` AS tt2 ON t1.team2 = tt2.id \t\t{$where_query} \t\t{$order_query} \t\t{$limit_query} SQL; return \WP_Clanwars\DB::get_results($query); }