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" );' ) );