Beispiel #1
0
 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);
 }
    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);
        ?>
/>&nbsp;
				<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);
        ?>
/>&nbsp;
				<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();
 }