Add League Table widget and display future events

This commit is contained in:
Brian Miyaji
2014-02-02 05:23:43 +11:00
parent bd8561cdba
commit eca5c08d16
7 changed files with 85 additions and 27 deletions

17
admin/hooks/the-posts.php Normal file
View File

@@ -0,0 +1,17 @@
<?php
function sportspress_the_posts( $posts ) {
global $wp_query, $wpdb;
if( is_single() && $wp_query->post_count == 0 && isset( $wp_query->query_vars['sp_event'] ) ) {
$posts = $wpdb->get_results( $wp_query->request );
}
return $posts;
}
//add_filter( 'the_posts', 'sportspress_the_posts' );
function sportspress_posts_where( $where, $that ) {
global $wpdb;
if( 'sp_event' == $that->query_vars['post_type'] && is_archive() )
$where = str_replace( "{$wpdb->posts}.post_status = 'publish'", "{$wpdb->posts}.post_status = 'publish' OR $wpdb->posts.post_status = 'future'", $where );
return $where;
}
add_filter( 'posts_where', 'sportspress_posts_where', 2, 10 );

View File

@@ -1,15 +0,0 @@
<?php
/**
* Register all of the default WordPress widgets on startup.
*
* Calls 'widgets_init' action after all of the WordPress widgets have been
* registered.
*
* @since 2.2.0
*/
function sportspress_widgets_init() {
register_widget('SportsPress_Widget_Calendar');
}
add_action('widgets_init', 'sportspress_widgets_init', 1);

View File

@@ -2,7 +2,7 @@
if ( !function_exists( 'sportspress_events_calendar' ) ) {
function sportspress_events_calendar( $initial = true ) {
global $wpdb, $m, $wp_locale, $posts;
global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
// Quick check. If we have no posts at all, abort!
if ( !$posts )
@@ -12,8 +12,8 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) {
$week_begins = intval(get_option('start_of_week'));
// Get year and month from query vars
$year = isset( $_GET['sp_year'] ) ? $_GET['sp_year'] : 0;
$monthnum = isset( $_GET['sp_month'] ) ? $_GET['sp_month'] : 0;
$year = isset( $_GET['sp_year'] ) ? $_GET['sp_year'] : $year;
$monthnum = isset( $_GET['sp_month'] ) ? $_GET['sp_month'] : $monthnum;
// Let's figure out when we are
if ( !empty($monthnum) && !empty($year) ) {
@@ -80,7 +80,7 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) {
<tr>';
if ( $previous ) {
$calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a href="' . add_query_arg( array( 'sp_year' => $previous->year, 'sp_month' => $previous->month ), get_permalink() ) . '" title="' . esc_attr( sprintf(__('View events for %1$s %2$s', 'sportspress'), $wp_locale->get_month($previous->month), date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year)))) . '">&laquo; ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>';
$calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a href="' . add_query_arg( array( 'sp_year' => $previous->year, 'sp_month' => $previous->month ) ) . '" title="' . esc_attr( sprintf(__('%1$s %2$s', 'calendar caption', 'sportspress'), $wp_locale->get_month($previous->month), date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year)))) . '">&laquo; ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>';
} else {
$calendar_output .= "\n\t\t".'<td colspan="3" id="prev" class="pad">&nbsp;</td>';
}
@@ -88,7 +88,7 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) {
$calendar_output .= "\n\t\t".'<td class="pad">&nbsp;</td>';
if ( $next ) {
$calendar_output .= "\n\t\t".'<td colspan="3" id="next"><a href="' . add_query_arg( array( 'sp_year' => $next->year, 'sp_month' => $next->month ), get_permalink() ) . '" title="' . esc_attr( sprintf(__('View events for %1$s %2$s', 'sportspress'), $wp_locale->get_month($next->month), date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) ) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' &raquo;</a></td>';
$calendar_output .= "\n\t\t".'<td colspan="3" id="next"><a href="' . add_query_arg( array( 'sp_year' => $next->year, 'sp_month' => $next->month ) ) . '" title="' . esc_attr( sprintf(__('%1$s %2$s', 'calendar caption', 'sportspress'), $wp_locale->get_month($next->month), date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) ) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' &raquo;</a></td>';
} else {
$calendar_output .= "\n\t\t".'<td colspan="3" id="next" class="pad">&nbsp;</td>';
}

View File

@@ -2,8 +2,8 @@
class SportsPress_Widget_Calendar extends WP_Widget {
function __construct() {
$widget_ops = array('classname' => 'widget_calendar sp_widget_calendar', 'description' => __( 'A calendar of your site&#8217;s Events.') );
parent::__construct('sp_calendar', __('Events Calendar'), $widget_ops);
$widget_ops = array('classname' => 'widget_calendar widget_sp_calendar', 'description' => __( 'SportsPress widget.', 'sportspress' ) );
parent::__construct('sp_calendar', __( 'Events Calendar', 'sportspress' ), $widget_ops);
}
function widget( $args, $instance ) {
@@ -12,7 +12,7 @@ class SportsPress_Widget_Calendar extends WP_Widget {
echo $before_widget;
if ( $title )
echo $before_title . $title . $after_title;
echo '<div id="calendar_wrap sp_calendar_wrap">';
echo '<div id="calendar_wrap">';
echo sportspress_events_calendar();
echo '</div>';
echo $after_widget;
@@ -29,8 +29,9 @@ class SportsPress_Widget_Calendar extends WP_Widget {
$instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
$title = strip_tags($instance['title']);
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:', 'sportspress' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
<?php
}
}
add_action( 'widgets_init', create_function( '', 'return register_widget( "SportsPress_Widget_Calendar" );' ) );

54
admin/widgets/table.php Normal file
View File

@@ -0,0 +1,54 @@
<?php
class SportsPress_Widget_League_Table extends WP_Widget {
function __construct() {
$widget_ops = array('classname' => 'widget_league_table widget_sp_league_table', 'description' => __( 'SportsPress widget.', 'sportspress' ) );
parent::__construct('sp_table', __( 'League Table', 'sportspress', 'sportspress' ), $widget_ops);
}
function widget( $args, $instance ) {
extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
$id = empty($instance['id']) ? null : $instance['id'];
echo $before_widget;
if ( $title )
echo $before_title . $title . $after_title;
echo '<div id="sp_league_table_wrap">';
echo sportspress_league_table( $id );
echo '</div>';
echo $after_widget;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['id'] = intval($new_instance['id']);
return $instance;
}
function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => '' ) );
$title = strip_tags($instance['title']);
$id = intval($instance['id']);
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:', 'sportspress' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
<p>
<?php
$args = array(
'post_type' => 'sp_table',
'name' => $this->get_field_name('id'),
'id' => $this->get_field_id('id'),
'show_option_none' => __( '-- Select --', 'sportspress' ),
'selected' => $id,
'values' => 'ID',
);
sportspress_dropdown_pages( $args );
?>
</p>
<?php
}
}
add_action( 'widgets_init', create_function( '', 'return register_widget( "SportsPress_Widget_League_Table" );' ) );

View File

@@ -302,8 +302,8 @@ if ( !function_exists( 'sportspress_dropdown_pages' ) ) {
}
}
if ( !function_exists( 'sportspress_the_posts' ) ) {
function sportspress_the_posts( $post_id = null, $meta = 'post' ) {
if ( !function_exists( 'sportspress_posts' ) ) {
function sportspress_posts( $post_id = null, $meta = 'post' ) {
if ( ! isset( $post_id ) )
global $post_id;
$ids = get_post_meta( $post_id, $meta, false );

View File

@@ -73,9 +73,9 @@ require_once dirname( __FILE__ ) . '/admin/terms/position.php';
// Widgets
require_once dirname( __FILE__ ) . '/admin/widgets/calendar.php';
require_once dirname( __FILE__ ) . '/admin/widgets/table.php';
// Typical request actions
require_once dirname( __FILE__ ) . '/admin/hooks/widgets-init.php';
require_once dirname( __FILE__ ) . '/admin/hooks/plugins-loaded.php';
require_once dirname( __FILE__ ) . '/admin/hooks/after-setup-theme.php';
require_once dirname( __FILE__ ) . '/admin/hooks/wp-enqueue-scripts.php';
@@ -98,6 +98,7 @@ require_once dirname( __FILE__ ) . '/admin/hooks/save-post.php';
require_once dirname( __FILE__ ) . '/admin/hooks/admin-post-thumbnail-html.php';
require_once dirname( __FILE__ ) . '/admin/hooks/gettext.php';
require_once dirname( __FILE__ ) . '/admin/hooks/pre-get-posts.php';
require_once dirname( __FILE__ ) . '/admin/hooks/the-posts.php';
require_once dirname( __FILE__ ) . '/admin/hooks/sanitize-title.php';
require_once dirname( __FILE__ ) . '/admin/hooks/the-content.php';
require_once dirname( __FILE__ ) . '/admin/hooks/wp-insert-post-data.php';