Пример #1
0
    function widget($args, $instance)
    {
        wp_enqueue_script('wp-clanwars-tabs');
        extract($args);
        $now = Utils::current_time_fixed('timestamp');
        $instance = wp_parse_args((array) $instance, $this->default_settings);
        $title = apply_filters('widget_title', empty($instance['title']) ? __('ClanWars', WP_CLANWARS_TEXTDOMAIN) : $instance['title']);
        $matches = array();
        $games = array();
        $options = array('id' => empty($instance['visible_games']) ? 'all' : $instance['visible_games'], 'orderby' => 'title', 'order' => 'asc');
        $_games = \WP_Clanwars\Games::get_game($options);
        $from_date = 0;
        if (isset($this->newer_than_options[$instance['hide_older_than']])) {
            $age = (int) $this->newer_than_options[$instance['hide_older_than']]['value'];
            if ($instance['hide_older_than'] === 'custom') {
                // custom
                $age = (int) $instance['custom_hide_duration'] * self::ONE_DAY;
                if ($age > 0) {
                    $from_date = $now - $age;
                }
            } else {
                if ($age > 0) {
                    // 0 means show all matches
                    $from_date = $now - $age;
                }
            }
        }
        foreach ($_games as $game) {
            $options = array('from_date' => $from_date, 'game_id' => $game->id, 'limit' => $instance['show_limit'], 'order' => 'desc', 'orderby' => 'date', 'sum_tickets' => true);
            $matchResult = \WP_Clanwars\Matches::get_match($options);
            if ($matchResult->count()) {
                $games[] = $game;
                $matches = array_merge($matches, $matchResult->getArrayCopy());
            }
        }
        usort($matches, array($this, '_sort_games'));
        ?>

		<?php 
        echo $before_widget;
        ?>
		<?php 
        if ($title && !$instance['hide_title']) {
            echo $before_title . $title . $after_title;
        }
        ?>

<ul class="clanwar-list<?php 
        if ($instance['display_game_icon']) {
            echo ' shows-game-icon';
        }
        ?>
">

	<?php 
        if (sizeof($games) > 1) {
            ?>
	<li>
		<ul class="tabs">
		<?php 
            $obj = new stdClass();
            $obj->id = 0;
            $obj->title = __('All', WP_CLANWARS_TEXTDOMAIN);
            $obj->abbr = __('All');
            $obj->icon = 0;
            array_unshift($games, $obj);
            for ($i = 0; $i < sizeof($games); $i++) {
                $game = $games[$i];
                $link = $game->id == 0 ? 'all' : 'game-' . $game->id;
                ?>
			<li<?php 
                if ($i == 0) {
                    echo ' class="selected"';
                }
                ?>
><a href="#<?php 
                echo $link;
                ?>
" title="<?php 
                echo esc_attr($game->title);
                ?>
"><?php 
                echo esc_html($game->abbr);
                ?>
</a></li>
		<?php 
            }
            ?>
		</ul>
	</li>
	<?php 
        }
        ?>

	<?php 
        foreach ($matches as $i => $match) {
            $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);
            $game_icon = wp_get_attachment_url($match->game_icon);
            $is_upcoming = $timestamp > $now;
            $is_playing = $now > $timestamp && $now < $timestamp + 3600 && ($t1 == 0 && $t2 == 0);
            $item_classes = ['clanwar-item', 'game-' . $match->game_id];
            if ($i % 2 != 0) {
                $item_classes[] = 'alt';
            }
            ?>
	<li class="<?php 
            esc_attr_e(join(' ', $item_classes));
            ?>
">

			<?php 
            if ($is_upcoming) {
                ?>
			<div class="upcoming"><?php 
                _e('Upcoming', WP_CLANWARS_TEXTDOMAIN);
                ?>
</div>
			<?php 
            } elseif ($is_playing) {
                ?>
			<div class="playing"><?php 
                _e('Playing', WP_CLANWARS_TEXTDOMAIN);
                ?>
</div>
			<?php 
            } else {
                ?>
			<div class="scores <?php 
                echo $wld_class;
                ?>
"><?php 
                echo sprintf(__('%d:%d', WP_CLANWARS_TEXTDOMAIN), $t1, $t2);
                ?>
</div>
			<?php 
            }
            ?>

			<div class="opponent-team">
			<?php 
            if ($instance['display_game_icon'] && $game_icon !== false) {
                ?>
			<img src="<?php 
                echo $game_icon;
                ?>
" alt="<?php 
                echo esc_attr($match->game_title);
                ?>
" class="icon" />
			<?php 
            }
            ?>

			<?php 
            $team1_flag = \WP_Clanwars\Utils::get_country_flag($match->team1_country);
            $team2_flag = \WP_Clanwars\Utils::get_country_flag($match->team2_country);
            if ($instance['display_both_teams']) {
                $team_title = sprintf('%s %s vs. %s %s', $team1_flag, esc_html($match->team1_title), $team2_flag, esc_html($match->team2_title));
            } else {
                $team_title = sprintf('%s %s', $team2_flag, esc_html($match->team2_title));
            }
            if ($match->post_id != 0) {
                echo sprintf('<a href="%s" title="%s">%s</a>', get_permalink($match->post_id), esc_attr($match->title), $team_title);
            } else {
                echo $team_title;
            }
            ?>
			</div>
			<div class="date"><?php 
            echo $date;
            ?>
</div>

	</li>
		<?php 
        }
        ?>
</ul>

			<?php 
        echo $after_widget;
        ?>

		<?php 
    }
Пример #2
0
 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;
 }
Пример #3
0
 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' => __('&larr;'), 'next_text' => __('&rarr;'), 'total' => $pagination->get_num_pages(), 'current' => $current_page));
     $page_links_text = sprintf('<span class="displaying-num">' . __('Displaying %s&#8211;%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;
 }
Пример #4
0
 static function html_date_helper($prefix, $time = 0, $tab_index = 0, $select_class = '')
 {
     global $wp_locale;
     $tab_index_attribute = '';
     $tab_index = (int) $tab_index;
     if ($tab_index > 0) {
         $tab_index_attribute = " tabindex=\"{$tab_index}\"";
     }
     $select_class_attribute = '';
     if (!empty($select_class)) {
         $select_class_attribute = ' class="' . esc_attr($select_class) . '"';
     }
     if ($time == 0) {
         $time_adj = \WP_Clanwars\Utils::current_time_fixed('timestamp', 0);
     } else {
         $time_adj = $time;
     }
     $jj = date('d', $time_adj);
     $mm = date('m', $time_adj);
     $hh = date('H', $time_adj);
     $mn = date('i', $time_adj);
     $yy = date('Y', $time_adj);
     $month = "<select name=\"{$prefix}[mm]\"{$select_class_attribute}{$tab_index_attribute}>\n";
     for ($i = 1; $i < 13; $i = $i + 1) {
         $month .= "\t\t\t" . '<option value="' . zeroise($i, 2) . '"';
         if ($i == $mm) {
             $month .= ' selected="selected"';
         }
         $month .= '>' . $wp_locale->get_month($i) . "</option>\n";
     }
     $month .= '</select>';
     $day = '<input type="text" name="' . $prefix . '[jj]" value="' . $jj . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off"  />';
     $hour = '<input type="text" name="' . $prefix . '[hh]" value="' . $hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off"  />';
     $minute = '<input type="text" name="' . $prefix . '[mn]" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off"  />';
     $year = '<input type="text" name="' . $prefix . '[yy]" value="' . $yy . '" size="3" maxlength="4"' . $tab_index_attribute . ' autocomplete="off"  />';
     printf(before_last_bar(__('%1$s%5$s %2$s @ %3$s : %4$s|1: month input, 2: day input, 3: hour input, 4: minute input, 5: year input', WP_CLANWARS_TEXTDOMAIN)), $month, $day, $hour, $minute, $year);
 }