Widgets added and PHP error fixed for version < 5.2

This commit is contained in:
Brian Miyaji
2014-02-05 19:51:28 +11:00
parent d1df5b757a
commit 1c0bc6a468
19 changed files with 359 additions and 143 deletions

View File

@@ -10,8 +10,8 @@ function sportspress_admin_enqueue_scripts() {
wp_enqueue_script( 'google-maps', 'http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places' );
wp_enqueue_script( 'jquery-locationpicker', SPORTSPRESS_PLUGIN_URL .'/assets/js/locationpicker.jquery.js', array( 'jquery' ), '0.1.6', true );
wp_enqueue_script( 'sportspress-admin', SPORTSPRESS_PLUGIN_URL .'/assets/js/admin.js', array( 'jquery' ), time(), true );
wp_localize_script( 'sportspress-admin', 'localized_strings', array(
'remove_text' => __( 'Remove', 'sportspress' )
) );
// Localize scripts.
wp_localize_script( 'sportspress-admin', 'localized_strings', array( 'remove_text' => __( 'Remove', 'sportspress' ) ) );
}
add_action( 'admin_enqueue_scripts', 'sportspress_admin_enqueue_scripts' );

View File

@@ -1,20 +1,17 @@
<?php
function sportspress_admin_menu( $position ) {
if ( ! current_user_can( 'manage_options' ) )
return;
global $menu, $submenu;
// Find where our placeholder is in the menu
foreach( $menu as $key => $data ) {
foreach( $menu as $key => $data ):
if ( is_array( $data ) && array_key_exists( 2, $data ) && $data[2] == 'edit.php?post_type=sp_separator' )
$position = $key;
}
$seperator_position = $key;
endforeach;
// Swap our placeholder post type with a menu separator
if ( $position ):
$menu[ $position ] = array( '', 'read', 'separator-sportspress', '', 'wp-menu-separator sportspress' );
if ( $seperator_position ):
$menu[ $seperator_position ] = array( '', 'read', 'separator-sportspress', '', 'wp-menu-separator sportspress' );
endif;
// Remove "Venues" and "Positions" links from Media submenu
@@ -66,4 +63,4 @@ if ( ! function_exists( 'sportspress_admin_menu_remove_venues' ) ) {
function sportspress_admin_menu_remove_venues( $arr = array() ) {
return $arr[0] != __( 'Venues', 'sportspress' );
}
}
}

View File

@@ -10,7 +10,7 @@ function sportspress_manage_posts_custom_column( $column, $post_id ) {
global $post;
switch ( $column ):
case 'sp_icon':
edit_post_link( get_the_post_thumbnail( $post_id, 'sportspress-icon' ), '', '', $post_id );
edit_post_link( get_the_post_thumbnail( $post_id, 'sportspress-fit-icon' ), '', '', $post_id );
break;
case 'sp_views':
echo sportspress_get_post_views( $post_id );

View File

@@ -0,0 +1,75 @@
<?php
function sportspress_media_buttons() {
//if ( ! in_array( array('post.php', 'page.php', 'page-new.php', 'post-new.php')
?>
<a href="#TB_inline?width=480&inlineId=select_sp_table" class="thickbox button sp-insert sp-insert-map" id="add_gform" title="<?php printf( __( 'Add %s', 'sportspress' ), __( 'Map', 'sportspress' ) ); ?>"><span class="sp-buttons-icon sp-map-buttons-icon "></span> <?php printf( __( 'Add %s', 'sportspress' ), __( 'Map', 'sportspress' ) ); ?></a>
<a href="#TB_inline?width=480&inlineId=select_sp_table" class="thickbox button sp-insert sp-insert-table" id="add_gform" title="<?php printf( __( 'Add %s', 'sportspress' ), __( 'League Table', 'sportspress' ) ); ?>"><span class="sp-buttons-icon sp-table-buttons-icon "></span> <?php printf( __( 'Add %s', 'sportspress' ), __( 'League Table', 'sportspress' ) ); ?></a>
<?php
}
add_action( 'media_buttons', 'sportspress_media_buttons', 20 );
/*
//Action target that displays the popup to insert a form to a post/page
public static function add_mce_popup(){
?>
<script>
function InsertForm(){
var form_id = jQuery("#add_form_id").val();
if(form_id == ""){
alert("<?php _e("Please select a form", "gravityforms") ?>");
return;
}
var form_name = jQuery("#add_form_id option[value='" + form_id + "']").text().replace(/[\[\]]/g, '');
var display_title = jQuery("#display_title").is(":checked");
var display_description = jQuery("#display_description").is(":checked");
var ajax = jQuery("#gform_ajax").is(":checked");
var title_qs = !display_title ? " title=\"false\"" : "";
var description_qs = !display_description ? " description=\"false\"" : "";
var ajax_qs = ajax ? " ajax=\"true\"" : "";
window.send_to_editor("[gravityform id=\"" + form_id + "\" name=\"" + form_name + "\"" + title_qs + description_qs + ajax_qs + "]");
}
</script>
<div id="select_gravity_form" style="display:none;">
<div class="wrap <?php echo GFCommon::get_browser_class() ?>">
<div>
<div style="padding:15px 15px 0 15px;">
<h3 style="color:#5A5A5A!important; font-family:Georgia,Times New Roman,Times,serif!important; font-size:1.8em!important; font-weight:normal!important;"><?php _e("Insert A Form", "gravityforms"); ?></h3>
<span>
<?php _e("Select a form below to add it to your post or page.", "gravityforms"); ?>
</span>
</div>
<div style="padding:15px 15px 0 15px;">
<select id="add_form_id">
<option value=""> <?php _e("Select a Form", "gravityforms"); ?> </option>
<?php
$forms = RGFormsModel::get_forms(1, "title");
foreach($forms as $form){
?>
<option value="<?php echo absint($form->id) ?>"><?php echo esc_html($form->title) ?></option>
<?php
}
?>
</select> <br/>
<div style="padding:8px 0 0 0; font-size:11px; font-style:italic; color:#5A5A5A"><?php _e("Can't find your form? Make sure it is active.", "gravityforms"); ?></div>
</div>
<div style="padding:15px 15px 0 15px;">
<input type="checkbox" id="display_title" checked='checked' /> <label for="display_title"><?php _e("Display form title", "gravityforms"); ?></label> &nbsp;&nbsp;&nbsp;
<input type="checkbox" id="display_description" checked='checked' /> <label for="display_description"><?php _e("Display form description", "gravityforms"); ?></label>&nbsp;&nbsp;&nbsp;
<input type="checkbox" id="gform_ajax" /> <label for="gform_ajax"><?php _e("Enable AJAX", "gravityforms"); ?></label>
</div>
<div style="padding:15px;">
<input type="button" class="button-primary" value="<?php _e("Insert Form", "gravityforms"); ?>" onclick="InsertForm();"/>&nbsp;&nbsp;&nbsp;
<a class="button" style="color:#bbb;" href="#" onclick="tb_remove(); return false;"><?php _e("Cancel", "gravityforms"); ?></a>
</div>
</div>
</div>
</div>
<?php
}
*/

View File

@@ -15,14 +15,12 @@ function sportspress_plugins_loaded() {
// Add image sizes
if ( function_exists( 'add_image_size' ) ) {
// Header
add_image_size( 'sportspress-header', 1600, 700, true );
// Standard (3:2)
add_image_size( 'sportspress-standard', 637, 425, true );
add_image_size( 'sportspress-standard-thumbnail', 303, 202, true );
// Wide (16:9)
add_image_size( 'sportspress-wide-header', 1600, 900, true );
add_image_size( 'sportspress-wide', 637, 358, true );
add_image_size( 'sportspress-wide-thumbnail', 303, 170, true );
@@ -33,9 +31,7 @@ function sportspress_plugins_loaded() {
// Fit (Proportional)
add_image_size( 'sportspress-fit', 637, 637, false );
add_image_size( 'sportspress-fit-thumbnail', 303, 303, false );
// Icon (Proportional)
add_image_size( 'sportspress-icon', 32, 32, false );
add_image_size( 'sportspress-fit-icon', 32, 32, false );
}

View File

@@ -1,16 +1,21 @@
<?php
function sportspress_pre_get_posts( $query ) {
if( !is_admin() )
return $query;
$post_type = $query->query['post_type'];
if ( is_admin() ):
$post_type = $query->query['post_type'];
if ( in_array( $post_type, array( 'sp_result', 'sp_outcome', 'sp_column', 'sp_statistic' ) ) ):
$query->set( 'orderby', 'menu_order' );
$query->set( 'order', 'ASC' );
elseif ( $post_type == 'sp_event' ):
$query->set( 'orderby', 'post_date' );
$query->set( 'order', 'ASC' );
if ( in_array( $post_type, array( 'sp_result', 'sp_outcome', 'sp_column', 'sp_statistic' ) ) ):
$query->set( 'orderby', 'menu_order' );
$query->set( 'order', 'ASC' );
elseif ( $post_type == 'sp_event' ):
$query->set( 'orderby', 'post_date' );
$query->set( 'order', 'ASC' );
endif;
else:
$post_type = $query->get( 'post_type' );
if ( $query->is_post_type_archive && $post_type == 'sp_event' ):
$query->set( 'order' , 'ASC' );
endif;
endif;
return $query;

View File

@@ -7,6 +7,10 @@ function sportspress_enqueue_scripts() {
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'google-maps', 'https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false', array(), '3.exp', true );
wp_enqueue_script( 'jquery-datatables', SPORTSPRESS_PLUGIN_URL .'assets/js/jquery.dataTables.min.js', array( 'jquery' ), '1.9.4', true );
wp_enqueue_script( 'jquery-countdown', SPORTSPRESS_PLUGIN_URL .'assets/js/jquery.countdown.min.js', array( 'jquery' ), '2.0.2', true );
wp_enqueue_script( 'sportspress', SPORTSPRESS_PLUGIN_URL .'assets/js/sportspress.js', array( 'jquery' ), time(), true );
// Localize scripts.
wp_localize_script( 'sportspress', 'localized_strings', array( 'days' => __( 'days', 'sportspress' ), 'hours' => __( 'hours', 'sportspress' ), 'mins' => __( 'mins', 'sportspress' ), 'secs' => __( 'secs', 'sportspress' ) ) );
}
add_action( 'wp_enqueue_scripts', 'sportspress_enqueue_scripts' );

View File

@@ -45,6 +45,8 @@ function sportspress_list_meta_init( $post ) {
if ( $players && $players != array(0) ):
add_meta_box( 'sp_statsdiv', __( 'Player List', 'sportspress' ), 'sportspress_list_stats_meta', 'sp_list', 'normal', 'high' );
endif;
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'sportspress_list_details_meta', 'sp_list', 'normal', 'high' );
}
function sportspress_list_player_meta( $post ) {
@@ -105,3 +107,7 @@ function sportspress_list_stats_meta( $post ) {
sportspress_edit_player_list_table( $columns, $data, $placeholders );
sportspress_nonce();
}
function sportspress_list_details_meta( $post ) {
wp_editor( $post->post_content, 'content' );
}

View File

@@ -5,8 +5,7 @@ function sportspress_separator_post_init() {
'public' => false,
'show_ui' => true,
'show_in_nav_menus' => false,
'show_in_admin_bar' => false,
'capability_type' => 'sp_private'
'show_in_admin_bar' => false
);
register_post_type( 'sp_separator', $args );
}

View File

@@ -10,7 +10,7 @@ function sportspress_table_post_init() {
'public' => true,
'has_archive' => false,
'hierarchical' => false,
'supports' => array( 'title', 'author', 'thumbnail', 'excerpt' ),
'supports' => array( 'title', 'author', 'thumbnail' ),
'register_meta_box_cb' => 'sportspress_table_meta_init',
'rewrite' => array( 'slug' => get_option( 'sp_table_slug', 'tables' ) ),
'show_in_menu' => 'edit.php?post_type=sp_team',
@@ -44,6 +44,8 @@ function sportspress_table_meta_init( $post ) {
if ( $teams && $teams != array(0) ):
add_meta_box( 'sp_columnsdiv', __( 'League Table', 'sportspress' ), 'sportspress_table_columns_meta', 'sp_table', 'normal', 'high' );
endif;
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'sportspress_table_details_meta', 'sp_table', 'normal', 'high' );
}
function sportspress_table_team_meta( $post, $test ) {
@@ -93,3 +95,7 @@ function sportspress_table_columns_meta( $post ) {
sportspress_nonce();
}
function sportspress_table_details_meta( $post ) {
wp_editor( $post->post_content, 'content' );
}

View File

@@ -0,0 +1,57 @@
<?php
if ( !function_exists( 'sportspress_countdown' ) ) {
function sportspress_countdown( $args = array() ) {
$id = sportspress_array_value( $args, 'id', null );
if ( $id ):
$post = get_post( $id );
else:
$options = array(
'post_type' => 'sp_event',
'posts_per_page' => 1,
'order' => 'ASC',
'post_status' => 'future',
'meta_query' => array(),
);
if ( isset( $args['team'] ) )
$options['meta_query'][] = array( 'key' => 'sp_team', 'value' => $args['team'] );
$posts = get_posts( $options );
$post = array_pop( $posts );
endif;
$output = '';
if ( isset( $post ) ):
$output .= '<div id="sp_countdown_wrap">';
$output .= '<h3 class="event-name"><a href="' . get_permalink( $post->ID ) . '">' . $post->post_title . '</a></h3>';
$leagues = get_the_terms( $post->ID, 'sp_league' );
if ( $leagues ):
foreach( $leagues as $league ):
$term = get_term( $league->term_id, 'sp_league' );
$output .= '<h5 class="event-league">' . $term->name . '</h5>';
endforeach;
endif;
$now = new DateTime( current_time( 'mysql', 0 ) );
$date = new DateTime( $post->post_date );
$interval = $date->diff( $now );
$output .= '<h3 class="countdown sp-countdown"><time datetime="' . $post->post_date . '" data-countdown="' . str_replace( '-', '/', $post->post_date ) . '">' .
'<span>' . sprintf( '%02s', $interval->d ) . ' <small>' . __( 'days', 'sportspress' ) . '</small></span> ' .
'<span>' . sprintf( '%02s', $interval->h ) . ' <small>' . __( 'hours', 'sportspress' ) . '</small></span> ' .
'<span>' . sprintf( '%02s', $interval->i ) . ' <small>' . __( 'mins', 'sportspress' ) . '</small></span> ' .
'<span>' . sprintf( '%02s', $interval->s ) . ' <small>' . __( 'secs', 'sportspress' ) . '</small></span>' .
'</time></h3>';
$output .= '</div>';
else:
return false;
endif;
return apply_filters( 'sportspress_countdown', $output );
}
}

View File

@@ -1,83 +0,0 @@
<?php
class SP_Widget_Countdown_Timer extends WP_Widget {
function __construct() {
$widget_ops = array('classname' => 'widget_countdown_timer widget_sp_countdown_timer', 'description' => __( 'SportsPress widget.', 'sportspress' ) );
parent::__construct('sp_countdown_timer', __( 'Countdown Timer', 'sportspress' ), $widget_ops);
}
function widget( $args, $instance ) {
extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? __( 'Countdown Timer', 'sportspress' ) : $instance['title'], $instance, $this->id_base);
echo $before_widget;
$id = empty($instance['id']) ? null : $instance['id'];
if ( $title )
echo $before_title . $title . $after_title;
if ( $id )
$post = get_post( $id );
if ( isset( $post ) ):
echo '<div id="sp_countdown_timer_wrap">';
echo '<h3 class="event-name"><a href="' . get_permalink( $post->ID ) . '">' . $post->post_title . '</a></h3>';
$leagues = get_the_terms( $post->ID, 'sp_league' );
if ( $leagues ):
foreach( $leagues as $league ):
$term = get_term( $league->term_id, 'sp_league' );
echo '<h5 class="event-league">' . $term->name . '</h5>';
endforeach;
endif;
$now = new DateTime( date("Y-m-d H:i:s") );
$date = new DateTime( $post->post_date );
$interval = $date->diff( $now );
echo '<h3 class="countdown-timer sp-countdown-timer"><time datetime="' . $post->post_date . '">' .
'<span class="d">' . $interval->d . ' <small>' . __( 'Days', 'sportspress' ) . '</small></span> ' .
'<span class="h">' . $interval->h . ' <small>' . __( 'Hours', 'sportspress' ) . '</small></span> ' .
'<span class="m">' . $interval->m . ' <small>' . __( 'Mins', 'sportspress' ) . '</small></span> ' .
'<span class="s">' . $interval->s . ' <small>' . __( 'Secs', 'sportspress' ) . '</small></span>' .
'</time></h3>';
echo '</div>';
endif;
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><label for="<?php echo $this->get_field_id('id'); ?>"><?php _e( 'Event:', 'sportspress' ); ?></label>
<?php
$args = array(
'post_type' => 'sp_event',
'name' => $this->get_field_name('id'),
'id' => $this->get_field_id('id'),
'selected' => $id,
'show_option_none' => '(' . __( 'Next Event', 'premier' ) . ')',
'values' => 'ID',
'class' => 'widefat',
'show_dates' => true,
'post_status' => 'future',
);
if ( ! sportspress_dropdown_pages( $args ) ):
sportspress_post_adder( 'sp_event' );
endif;
?>
</p>
<?php
}
}
add_action( 'widgets_init', create_function( '', 'return register_widget( "SP_Widget_Countdown_Timer" );' ) );

View File

@@ -0,0 +1,57 @@
<?php
class SP_Widget_Countdown extends WP_Widget {
function __construct() {
$widget_ops = array('classname' => 'widget_countdown widget_sp_countdown', 'description' => __( 'SportsPress widget.', 'sportspress' ) );
parent::__construct('sp_countdown', __( 'Countdown', 'sportspress' ), $widget_ops);
}
function widget( $args, $instance ) {
extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? __( 'Countdown', 'sportspress' ) : $instance['title'], $instance, $this->id_base);
echo $before_widget;
$id = empty($instance['id']) ? null : $instance['id'];
if ( $title )
echo $before_title . $title . $after_title;
echo sportspress_countdown( $instance );
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><label for="<?php echo $this->get_field_id('id'); ?>"><?php _e( 'Event:', 'sportspress' ); ?></label>
<?php
$args = array(
'post_type' => 'sp_event',
'name' => $this->get_field_name('id'),
'id' => $this->get_field_id('id'),
'selected' => $id,
'show_option_all' => '(' . __( 'Next Event', 'premier' ) . ')',
'values' => 'ID',
'class' => 'widefat',
'show_dates' => true,
'post_status' => 'future',
);
if ( ! sportspress_dropdown_pages( $args ) ):
sportspress_post_adder( 'sp_event' );
endif;
?>
</p>
<?php
}
}
add_action( 'widgets_init', create_function( '', 'return register_widget( "SP_Widget_Countdown" );' ) );

View File

@@ -2,7 +2,7 @@
.widget[id*="sp_recent_events-"] .widget-title h4:before,
.widget[id*="sp_future_events-"] .widget-title h4:before,
.widget[id*="sp_countdown_timer-"] .widget-title h4:before,
.widget[id*="sp_countdown-"] .widget-title h4:before,
.widget[id*="sp_events_calendar-"] .widget-title h4:before,
.widget[id*="sp_league_table-"] .widget-title h4:before {
font-family: 'themeboy';
@@ -22,25 +22,59 @@
.postbox .inside .sp-data-table-container {
overflow: auto;
}
.wp-media-buttons .button.sp-insert {
padding-left: 5px;
}
.wp-media-buttons .sp-insert span.sp-buttons-icon {
display: inline-block;
width: 18px;
height: 18px;
vertical-align: text-top;
margin: 0 2px;
}
.wp-media-buttons .sp-insert span.sp-buttons-icon:before {
font: 400 18px/1 dashicons;
speak: none;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
color: #888;
}
.wp-media-buttons .sp-insert span.sp-map-buttons-icon:before {
content: '\f231';
}
.wp-media-buttons .sp-insert span.sp-table-buttons-icon:before {
content: '\f185';
}
table.widefat.sp-data-table td {
line-height: 2;
}
table.widefat.sp-data-table td:first-child {
white-space: nowrap;
}
table.widefat.sp-data-table input[type="text"],
table.widefat.sp-data-table input[type="number"] {
min-width: 1.25em;
width: 100%;
}
table.widefat.sp-data-table input.name {
min-width: 0;
width: auto;
}
.sp-admin-config-table th,
.sp-admin-config-table td {
width: 20%;
}
table.widefat th.column-sp_icon,
table.widefat td.column-sp_icon {
width: 32px;

22
assets/js/jquery.countdown.min.js vendored Executable file
View File

@@ -0,0 +1,22 @@
/*!
* The Final Countdown for jQuery v2.0.2 (http://hilios.github.io/jQuery.countdown/)
* Copyright (c) 2013 Edson Hilios
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a(jQuery)}(function(a){"use strict";function b(a){if(a instanceof Date)return a;if(String(a).match(g))return String(a).match(/^[0-9]*$/)&&(a=Number(a)),new Date(a);throw new Error("Couldn't cast `"+a+"` to a date object.")}function c(a){return function(b){var c=b.match(/%(-|!)?[A-Z]{1}(:[^;]+;)?/gi);if(c)for(var e=0,f=c.length;f>e;++e){var g=c[e].match(/%(-|!)?([a-zA-Z]{1})(:[^;]+;)?/),i=new RegExp(g[0]),j=g[1]||"",k=g[3]||"",l=null;g=g[2],h.hasOwnProperty(g)&&(l=h[g],l=Number(a[l])),null!==l&&("!"===j&&(l=d(k,l)),""===j&&10>l&&(l="0"+l.toString()),b=b.replace(i,l.toString()))}return b=b.replace(/%%/,"%")}}function d(a,b){var c="s",d="";return a&&(a=a.replace(/(:|;|\s)/gi,"").split(/\,/),1===a.length?c=a[0]:(d=a[0],c=a[1])),1===Math.abs(b)?d:c}var e=100,f=[],g=[];g.push(/^[0-9]*$/.source),g.push(/([0-9]{1,2}\/){2}[0-9]{4}( [0-9]{1,2}(:[0-9]{2}){2})?/.source),g.push(/[0-9]{4}(\/[0-9]{1,2}){2}( [0-9]{1,2}(:[0-9]{2}){2})?/.source),g=new RegExp(g.join("|"));var h={Y:"years",m:"months",w:"weeks",d:"days",D:"totalDays",H:"hours",M:"minutes",S:"seconds"},i=function(b,c,d){this.el=b,this.$el=a(b),this.interval=null,this.offset={},this.setFinalDate(c),this.instanceNumber=f.length,f.push(this),this.$el.data("countdown-instance",this.instanceNumber),d&&(this.$el.on("update.countdown",d),this.$el.on("stoped.countdown",d),this.$el.on("finish.countdown",d)),this.start()};a.extend(i.prototype,{start:function(){if(null!==this.interval)throw new Error("Countdown is already running!");var a=this;this.update(),this.interval=setInterval(function(){a.update.call(a)},e)},stop:function(){clearInterval(this.interval),this.interval=null,this.dispatchEvent("stoped")},pause:function(){this.stop.call(this)},resume:function(){this.start.call(this)},remove:function(){this.stop(),delete f[this.instanceNumber]},setFinalDate:function(a){this.finalDate=b(a)},update:function(){return 0===this.$el.closest("html").length?(this.remove(),void 0):(this.totalSecsLeft=this.finalDate.valueOf()-(new Date).valueOf(),this.totalSecsLeft=Math.ceil(this.totalSecsLeft/1e3),this.totalSecsLeft=this.totalSecsLeft<0?0:this.totalSecsLeft,this.offset={seconds:this.totalSecsLeft%60,minutes:Math.floor(this.totalSecsLeft/60)%60,hours:Math.floor(this.totalSecsLeft/60/60)%24,days:Math.floor(this.totalSecsLeft/60/60/24)%7,totalDays:Math.floor(this.totalSecsLeft/60/60/24),weeks:Math.floor(this.totalSecsLeft/60/60/24/7),months:Math.floor(this.totalSecsLeft/60/60/24/30),years:Math.floor(this.totalSecsLeft/60/60/24/365)},0===this.totalSecsLeft?(this.stop(),this.dispatchEvent("finish")):this.dispatchEvent("update"),void 0)},dispatchEvent:function(b){var d=a.Event(b+".countdown");d.finalDate=this.finalDate,d.offset=a.extend({},this.offset),d.strftime=c(this.offset),this.$el.trigger(d)}}),a.fn.countdown=function(){var b=Array.prototype.slice.call(arguments,0);return this.each(function(){var c=a(this).data("countdown-instance");if(void 0!==c){var d=f[c],e=b[0];i.prototype.hasOwnProperty(e)?d[e].apply(d,b.slice(1)):null===String(e).match(/^[$A-Z_][0-9A-Z_$]*$/i)?d.setFinalDate.call(d,e):a.error("Method %s does not exist on jQuery.countdown".replace(/\%s/gi,e))}else new i(this,b[0],b[1])})}});

View File

@@ -9,6 +9,18 @@ function viewport() {
(function($) {
/* Countdown */
$("[data-countdown]").each(function() {
var $this = $(this), finalDate = $(this).data('countdown');
$this.countdown(finalDate, function(event) {
$this.html(event.strftime("<span>%D <small>" + localized_strings.days + "</small></span> "
+ "<span>%H <small>" + localized_strings.hours + "</small></span> "
+ "<span>%M <small>" + localized_strings.mins + "</small></span> "
+ "<span>%S <small>" + localized_strings.secs + "</small></span>" ));
});
});
/* Data Tables */
if (viewport().width > 640) {

View File

@@ -539,6 +539,22 @@ if ( !function_exists( 'sportspress_equation_selector' ) ) {
}
}
if ( !function_exists( 'sportspress_get_term_names' ) ) {
function sportspress_get_term_names( $id = null, $post_type = null ) {
if ( ! $id || ! $post_type )
return false;
$terms = get_the_terms( $id, $post_type );
$output = array();
foreach ( $terms as $term ):
$output[ $term->slug ] = $term->name;
endforeach;
return $output;
}
}
if ( !function_exists( 'sportspress_get_var_labels' ) ) {
function sportspress_get_var_labels( $post_type ) {
$args = array(
@@ -1631,7 +1647,8 @@ if ( !function_exists( 'sportspress_get_league_table_data' ) ) {
$stats = get_posts( $args );
$columns = array();
$priorities = array();
global $sportspress_column_priorities;
$sportspress_column_priorities = array();
foreach ( $stats as $stat ):
@@ -1646,8 +1663,8 @@ if ( !function_exists( 'sportspress_get_league_table_data' ) ) {
// Add order to priorities if priority is set and does not exist in array already
$priority = sportspress_array_value( sportspress_array_value( $meta, 'sp_priority', array() ), 0, 0 );
if ( $priority && ! array_key_exists( $priority, $priorities ) ):
$priorities[ $priority ] = array(
if ( $priority && ! array_key_exists( $priority, $sportspress_column_priorities ) ):
$sportspress_column_priorities[ $priority ] = array(
'column' => $stat->post_name,
'order' => sportspress_array_value( sportspress_array_value( $meta, 'sp_order', array() ), 0, 'DESC' )
);
@@ -1656,7 +1673,7 @@ if ( !function_exists( 'sportspress_get_league_table_data' ) ) {
endforeach;
// Sort priorities in descending order
ksort( $priorities );
ksort( $sportspress_column_priorities );
// Fill in empty placeholder values for each team
foreach ( $team_ids as $team_id ):
@@ -1696,29 +1713,7 @@ if ( !function_exists( 'sportspress_get_league_table_data' ) ) {
endforeach;
endforeach;
uasort( $merged, function( $a, $b ) use ( $priorities ) {
// Loop through priorities
foreach( $priorities as $priority ):
// Proceed if columns are not equal
if ( sportspress_array_value( $a, $priority['column'], 0 ) != sportspress_array_value( $b, $priority['column'], 0 ) ):
// Compare column values
$output = sportspress_array_value( $a, $priority['column'], 0 ) - sportspress_array_value( $b, $priority['column'], 0 );
// Flip value if descending order
if ( $priority['order'] == 'DESC' ) $output = 0 - $output;
return $output;
endif;
endforeach;
// Default sort by alphabetical
return strcmp( sportspress_array_value( $a, 'name', '' ), sportspress_array_value( $b, 'name', '' ) );
});
uasort( $merged, 'sportspress_sort_table_teams' );
// Rearrange data array to reflect statistics
$data = array();
@@ -1736,6 +1731,32 @@ if ( !function_exists( 'sportspress_get_league_table_data' ) ) {
}
}
function sportspress_sort_table_teams ( $a, $b ) {
global $sportspress_column_priorities;
// Loop through priorities
foreach( $sportspress_column_priorities as $priority ):
// Proceed if columns are not equal
if ( sportspress_array_value( $a, $priority['column'], 0 ) != sportspress_array_value( $b, $priority['column'], 0 ) ):
// Compare column values
$output = sportspress_array_value( $a, $priority['column'], 0 ) - sportspress_array_value( $b, $priority['column'], 0 );
// Flip value if descending order
if ( $priority['order'] == 'DESC' ) $output = 0 - $output;
return $output;
endif;
endforeach;
// Default sort by alphabetical
return strcmp( sportspress_array_value( $a, 'name', '' ), sportspress_array_value( $b, 'name', '' ) );
}
if ( !function_exists( 'sportspress_get_player_list_data' ) ) {
function sportspress_get_player_list_data( $post_id, $admin = false ) {
$league_id = sportspress_get_the_term_id( $post_id, 'sp_league', 0 );

View File

@@ -72,6 +72,12 @@ SportsPress is currently in beta and is undergoing testing. We are still activel
== Changelog ==
= 0.2.2 =
* Feature - League Table widget added.
* Feature - Events widget added.
* Feature - Countdown widget added.
* Fix - Syntax error fixed for PHP version 5.2 and below.
= 0.2.1 =
* Feature - Events Calendar widget added.
* Fix - Player settings table markup fixed.

View File

@@ -35,6 +35,7 @@ require_once dirname( __FILE__ ) . '/admin/globals/sports.php';
require_once dirname( __FILE__ ) . '/functions.php';
// Templates
require_once dirname( __FILE__ ) . '/admin/templates/countdown.php';
require_once dirname( __FILE__ ) . '/admin/templates/event-details.php';
require_once dirname( __FILE__ ) . '/admin/templates/event-players.php';
require_once dirname( __FILE__ ) . '/admin/templates/event-results.php';
@@ -75,7 +76,7 @@ require_once dirname( __FILE__ ) . '/admin/terms/position.php';
// Widgets
require_once dirname( __FILE__ ) . '/admin/widgets/recent-events.php';
require_once dirname( __FILE__ ) . '/admin/widgets/future-events.php';
require_once dirname( __FILE__ ) . '/admin/widgets/countdown-timer.php';
require_once dirname( __FILE__ ) . '/admin/widgets/countdown.php';
require_once dirname( __FILE__ ) . '/admin/widgets/events-calendar.php';
require_once dirname( __FILE__ ) . '/admin/widgets/league-table.php';
@@ -96,6 +97,7 @@ require_once dirname( __FILE__ ) . '/admin/hooks/manage-posts-columns.php';
require_once dirname( __FILE__ ) . '/admin/hooks/post-thumbnail-html.php';
require_once dirname( __FILE__ ) . '/admin/hooks/restrict-manage-posts.php';
require_once dirname( __FILE__ ) . '/admin/hooks/parse-query.php';
//require_once dirname( __FILE__ ) . '/admin/hooks/media-buttons.php';
require_once dirname( __FILE__ ) . '/admin/hooks/save-post.php';
// Filters