static function add_round($p) { global $wpdb; $data = \WP_Clanwars\Utils::extract_args($p, array('match_id' => 0, 'group_n' => 0, 'map_id' => 0, 'tickets1' => 0, 'tickets2' => 0)); if ($wpdb->insert(self::table(), $data, array('%d', '%d', '%d', '%d', '%d'))) { $insert_id = $wpdb->insert_id; return $insert_id; } return false; }
static function add_map($options) { global $wpdb; $defaults = array('title' => '', 'screenshot' => 0, 'game_id' => 0); $data = \WP_Clanwars\Utils::extract_args($options, $defaults); if ($wpdb->insert(self::table(), $data, array('%s', '%d', '%d'))) { return $wpdb->insert_id; } return false; }
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 add_game($options) { global $wpdb; $defaults = array('title' => '', 'abbr' => '', 'icon' => 0, 'store_id' => ''); $data = \WP_Clanwars\Utils::extract_args($options, $defaults); if ($wpdb->insert(self::table(), $data, array('%s', '%s', '%d', '%s'))) { return $wpdb->insert_id; } return false; }
static function add_match($p) { global $wpdb; $data = \WP_Clanwars\Utils::extract_args($p, array('title' => '', 'date' => \WP_Clanwars\Utils::current_time_fixed('timestamp', 0), 'post_id' => 0, 'team1' => 0, 'team2' => 0, 'game_id' => 0, 'match_status' => 0, 'description' => '', 'external_url' => '')); if ($wpdb->insert(self::table(), $data, array('%s', '%s', '%d', '%d', '%d', '%d', '%s', '%s'))) { $insert_id = $wpdb->insert_id; return $insert_id; } return false; }
static function add_team($args) { global $wpdb; $defaults = array('title' => '', 'logo' => 0, 'country' => '', 'home_team' => 0); $data = \WP_Clanwars\Utils::extract_args($args, $defaults); if ($wpdb->insert(self::table(), $data, array('%s', '%d', '%s', '%d'))) { $insert_id = $wpdb->insert_id; if ($data['home_team']) { self::set_hometeam($insert_id); } return $insert_id; } return false; }
static function html_country_select_helper($p = array(), $print = true) { $all_countries = self::all_countries(); extract(\WP_Clanwars\Utils::extract_args($p, array('select' => '', 'name' => '', 'id' => '', 'class' => '', 'show_popular' => false))); ob_start(); $attrs = array(); if (!empty($id)) { $attrs[] = 'id="' . esc_attr($id) . '"'; } if (!empty($name)) { $attrs[] = 'name="' . esc_attr($name) . '"'; } if (!empty($class)) { $attrs[] = 'class="' . esc_attr($class) . '"'; } $attrstr = implode(' ', $attrs); if (!empty($attrstr)) { $attrstr = ' ' . $attrstr; } echo '<select' . $attrstr . '>'; if ($show_popular) { $popular = \WP_Clanwars\Teams::most_popular_countries(); if (!empty($popular)) { foreach ($popular as $i => $data) { $abbr = $data['country']; $title = isset($all_countries[$abbr]) ? $all_countries[$abbr] : $abbr; echo '<option value="' . esc_attr($abbr) . '">' . esc_html($title) . '</option>'; } echo '<optgroup label="-----------------" style="font-family: monospace;"></optgroup>'; } } // copy array with array_merge so we don't sort global array $sorted_countries = array_merge(array(), $all_countries); asort($sorted_countries); foreach ($sorted_countries as $abbr => $title) { echo '<option value="' . esc_attr($abbr) . '"' . selected($abbr, $select, false) . '>' . esc_html($title) . '</option>'; } echo '</select>'; $output = ob_get_clean(); if ($print) { echo $output; return; } return $output; }