function on_browser_shortcode($atts) { $output = ''; extract(shortcode_atts(array('per_page' => 20), $atts)); $per_page = abs($per_page); $current_page = max(1, get_query_var('paged')); $now = Utils::current_time_fixed('timestamp'); $current_game = isset($_GET['game']) ? $_GET['game'] : false; $games = \WP_Clanwars\Games::get_game('id=all&orderby=title&order=asc'); $p = array('limit' => $per_page, 'order' => 'desc', 'orderby' => 'date', 'sum_tickets' => true, 'game_id' => $current_game, 'offset' => ($current_page - 1) * $per_page); $matches = \WP_Clanwars\Matches::get_match($p); $pagination = $matches->get_pagination(); $page_links = paginate_links(array('prev_text' => __('←'), 'next_text' => __('→'), 'total' => $pagination->get_num_pages(), 'current' => $current_page)); $page_links_text = sprintf('<span class="displaying-num">' . __('Displaying %s–%s of %s') . '</span>%s', number_format_i18n(($current_page - 1) * $per_page + 1), number_format_i18n(min($current_page * $per_page, $pagination->get_num_rows())), '<span class="total-type-count">' . number_format_i18n($pagination->get_num_rows()) . '</span>', $page_links); $output .= '<ul class="wp-clanwars-filter">'; $obj = new stdClass(); $obj->id = 0; $obj->title = __('All', WP_CLANWARS_TEXTDOMAIN); $obj->abbr = __('All'); $obj->icon = 0; array_unshift($games, $obj); $this_url = remove_query_arg(array('paged', 'game')); for ($i = 0; $i < sizeof($games); $i++) { $game = $games[$i]; $link = $game->id == 0 ? $this_url : add_query_arg('game', $game->id, $this_url); $output .= '<li' . ($game->id == $current_game ? ' class="selected"' : '') . '><a href="' . $link . '" title="' . esc_attr($game->title) . '">' . esc_html($game->abbr) . '</a></li>'; } $output .= '</ul>'; $output .= '<ul class="wp-clanwars-list">'; // generate table content foreach ($matches as $index => $match) { $output .= '<li class="match ' . ($index % 2 == 0 ? 'even' : 'odd') . '">'; // output match status $is_upcoming = false; $t1 = $match->team1_tickets; $t2 = $match->team2_tickets; $wld_class = $t1 == $t2 ? 'draw' : ($t1 > $t2 ? 'win' : 'loss'); $date = mysql2date(get_option('date_format') . ', ' . get_option('time_format'), $match->date); $timestamp = mysql2date('U', $match->date); $is_upcoming = $timestamp > $now; $is_playing = $now > $timestamp && $now < $timestamp + 3600 && ($t1 == 0 && $t2 == 0); if ($is_upcoming) { $output .= '<div class="upcoming">' . __('Upcoming', WP_CLANWARS_TEXTDOMAIN) . '</div>'; } elseif ($is_playing) { $output .= '<div class="playing">' . __('Playing', WP_CLANWARS_TEXTDOMAIN) . '</div>'; } else { $output .= '<div class="scores ' . $wld_class . '">' . sprintf(__('%d:%d', WP_CLANWARS_TEXTDOMAIN), $t1, $t2) . '</div>'; } // teams $output .= '<div class="wrap">'; // output game icon $game_icon = wp_get_attachment_url($match->game_icon); if ($game_icon !== false) { $output .= '<img src="' . $game_icon . '" alt="' . esc_attr($match->game_title) . '" class="icon" /> '; } $team2_title = esc_html($match->team2_title); if ($match->post_id != 0) { $team2_title = '<a href="' . get_permalink($match->post_id) . '" title="' . esc_attr($match->title) . '">' . $team2_title . '</a>'; } $output .= '<div class="opponent-team">' . Utils::get_country_flag($match->team2_country) . ' ' . $team2_title . '</div>'; //$output .= '<div class="home-team">' . Utils::get_country_flag($match->team1_country, true) . ' ' . esc_html($match->team1_title) . '</div>'; $output .= '<div class="date">' . esc_html($date) . '</div>'; $rounds = array(); $r = \WP_Clanwars\Rounds::get_rounds($match->id); foreach ($r as $v) { if (isset($rounds[$v->group_n])) { continue; } $image = wp_get_attachment_image_src($v->screenshot); if (!empty($image)) { $rounds[$v->group_n] = '<a href="' . esc_attr($image[0]) . '#' . $image[1] . 'x' . $image[2] . '" title="' . esc_attr($v->title) . '">' . esc_html($v->title) . '</a>'; } else { $rounds[$v->group_n] = $v->title; } } if (!empty($rounds)) { $maplist = implode(', ', array_values($rounds)); $output .= '<div class="maplist">' . $maplist . '</div>'; } $output .= '</div>'; $output .= '</li>'; } $output .= '</ul>'; $output .= '<div class="wp-clanwars-pagination">' . $page_links_text . '</div>'; return $output; }
static function delete_match($id) { global $wpdb; if (!is_array($id)) { $id = array($id); } $id = array_map('intval', $id); \WP_Clanwars\Rounds::delete_rounds_by_match($id); return $wpdb->query('DELETE FROM `' . self::table() . '` WHERE id IN(' . implode(',', $id) . ')'); }