Update equation builder
This commit is contained in:
75
assets/css/equation.css
Normal file
75
assets/css/equation.css
Normal file
@@ -0,0 +1,75 @@
|
||||
.sp-equation-builder .button {
|
||||
margin: 2px;
|
||||
padding: 0 10px 1px;
|
||||
}
|
||||
|
||||
.sp-equation {
|
||||
background: #f9f9f9;
|
||||
border: 1px solid #ddd;
|
||||
-webkit-box-shadow: inset 0 1px 2px rgba(0,0,0,0.07);
|
||||
box-shadow: inset 0 1px 2px rgba(0,0,0,0.07);
|
||||
transition: .05s border-color ease-in-out;
|
||||
margin-top: 6px;
|
||||
padding: 23px;
|
||||
}
|
||||
|
||||
.sp-equation:hover,
|
||||
.sp-equation.ui-state-active {
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.sp-equation.ui-state-hover {
|
||||
border-color: #5b9dd9;
|
||||
-webkit-box-shadow: 0 0 2px rgba(30,140,190,0.8);
|
||||
box-shadow: 0 0 2px rgba(30,140,190,0.8);
|
||||
}
|
||||
|
||||
.sp-equation-variable {
|
||||
font-weight: bold;
|
||||
font-size: 14px;
|
||||
line-height: 32px;
|
||||
}
|
||||
|
||||
.sp-equation-formula .ui-sortable-placeholder {
|
||||
visibility: visible !important;
|
||||
margin: 2px;
|
||||
padding: 1 10px 1px;
|
||||
border: 1px dashed #bbb;
|
||||
background: transparent;
|
||||
height: 28px;
|
||||
}
|
||||
|
||||
.sp-equation-formula .button {
|
||||
position: relative;
|
||||
margin: 2px 4px;
|
||||
}
|
||||
|
||||
.sp-equation-formula .button .remove {
|
||||
font-weight: bold;
|
||||
font-size: 14px;
|
||||
position: absolute;
|
||||
top: -10px;
|
||||
left: -8px;
|
||||
border: 1px solid #ccc;
|
||||
background: #f7f7f7;
|
||||
display: block;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
line-height: 16px;
|
||||
text-align: center;
|
||||
border-radius: 50%;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.sp-equation-formula .button:hover .remove {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.sp-equation-formula .button.ui-sortable-helper .remove,
|
||||
.sp-equation-formula .button.ui-sortable-helper:hover .remove {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.sp-equation-formula .button .remove:hover {
|
||||
background: #e0e0e0;
|
||||
}
|
||||
@@ -1,10 +1,15 @@
|
||||
/* SportsPress */
|
||||
|
||||
.sp-scrollable-table-wrapper {
|
||||
overflow: auto;
|
||||
/* Header */
|
||||
.sp-header {
|
||||
position: relative;
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
/* Data Tables */
|
||||
.sp-scrollable-table-wrapper {
|
||||
overflow: auto;
|
||||
}
|
||||
.sp-data-table {
|
||||
width: 100%;
|
||||
position: relative;
|
||||
|
||||
37
assets/js/admin/equationbuilder.js
Normal file
37
assets/js/admin/equationbuilder.js
Normal file
@@ -0,0 +1,37 @@
|
||||
jQuery(document).ready(function($){
|
||||
$("#title").keyup(function() {
|
||||
val = $(this).val();
|
||||
if ( val == '' ) val = 'f(x)';
|
||||
$(".sp-equation-variable").text( val + ' =' );
|
||||
});
|
||||
|
||||
$(".sp-equation-parts .button").draggable({
|
||||
appendTo: "body",
|
||||
helper: "clone",
|
||||
cursor: "move",
|
||||
distance: 10,
|
||||
containment: "#sp_equationdiv",
|
||||
}).click(function() {
|
||||
$("<label class='button'></label>").text( $(this).text() ).append("<span class='remove'>×</span><input name='sp_equation[]' type='hidden' value='" + $(this).data("variable") + "'>").appendTo( $(".sp-equation-formula") );
|
||||
});
|
||||
|
||||
$(".sp-equation").droppable({
|
||||
activeClass: "ui-state-active",
|
||||
hoverClass: "ui-state-hover",
|
||||
accept: ".button:not(.ui-sortable-helper)",
|
||||
drop: function( event, ui ) {
|
||||
$("<label class='button'></label>").text( ui.draggable.text() ).append("<span class='remove'>×</span><input name='sp_equation[]' type='hidden' value='" + ui.draggable.data("variable") + "'>").appendTo( $(".sp-equation-formula") );
|
||||
}
|
||||
}).sortable({
|
||||
items: ".button",
|
||||
tolerance: "pointer",
|
||||
containment: "#sp_equationdiv",
|
||||
sort: function() {
|
||||
$( this ).removeClass( "ui-state-active" );
|
||||
}
|
||||
});
|
||||
|
||||
$(".sp-equation-formula").on("click", ".button .remove", function() {
|
||||
$(this).closest(".button").remove();
|
||||
});
|
||||
});
|
||||
@@ -11,6 +11,9 @@ function viewport() {
|
||||
|
||||
var sp_responsive_activated = false;
|
||||
|
||||
/* Header */
|
||||
$('body').prepend( '<div class="sp-header"></div>' );
|
||||
|
||||
/* Countdown */
|
||||
$("[data-countdown]").each(function() {
|
||||
var $this = $(this), finalDate = $(this).data('countdown');
|
||||
|
||||
@@ -48,7 +48,6 @@ class SP_Admin_Assets {
|
||||
wp_enqueue_style( 'sportspress-admin-dashboard-styles', SP()->plugin_url() . '/assets/css/dashboard.css', array(), SP_VERSION );
|
||||
}
|
||||
|
||||
|
||||
if ( in_array( $screen->id, array( 'widgets' ) ) ) {
|
||||
wp_enqueue_style( 'sportspress-admin-widgets-styles', SP()->plugin_url() . '/assets/css/widgets.css', array(), SP_VERSION );
|
||||
}
|
||||
@@ -57,6 +56,10 @@ class SP_Admin_Assets {
|
||||
wp_enqueue_style( 'sportspress-admin-customize-styles', SP()->plugin_url() . '/assets/css/customize.css', array(), SP_VERSION );
|
||||
}
|
||||
|
||||
if ( in_array( $screen->id, array( 'sp_column', 'sp_statistic' ) ) ) {
|
||||
wp_enqueue_style( 'sportspress-admin-equation-styles', SP()->plugin_url() . '/assets/css/equation.css', array(), SP_VERSION );
|
||||
}
|
||||
|
||||
do_action( 'sportspress_admin_css' );
|
||||
}
|
||||
|
||||
@@ -82,6 +85,8 @@ class SP_Admin_Assets {
|
||||
wp_register_script( 'jquery-locationpicker', SP()->plugin_url() . '/assets/js/locationpicker.jquery.js', array( 'jquery', 'google-maps' ), '0.1.6', true );
|
||||
|
||||
wp_register_script( 'sportspress-admin-locationpicker', SP()->plugin_url() . '/assets/js/admin/locationpicker.js', array( 'jquery', 'google-maps', 'jquery-locationpicker' ), SP_VERSION, true );
|
||||
|
||||
wp_register_script( 'sportspress-admin-equationbuilder', SP()->plugin_url() . '/assets/js/admin/equationbuilder.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-draggable', 'jquery-ui-droppable' ), SP_VERSION, true );
|
||||
|
||||
wp_register_script( 'sportspress-admin', SP()->plugin_url() . '/assets/js/admin/sportspress-admin.js', array( 'jquery', 'chosen', 'jquery-tiptip', 'jquery-caret', 'jquery-countdown' ), SP_VERSION, true );
|
||||
|
||||
@@ -120,11 +125,17 @@ class SP_Admin_Assets {
|
||||
|
||||
// Edit venue pages
|
||||
if ( in_array( $screen->id, array( 'edit-sp_venue' ) ) ) {
|
||||
|
||||
wp_enqueue_script( 'google-maps' );
|
||||
wp_enqueue_script( 'jquery-locationpicker' );
|
||||
wp_enqueue_script( 'sportspress-admin-locationpicker' );
|
||||
}
|
||||
|
||||
// Edit equation
|
||||
if ( in_array( $screen->id, array( 'sp_column', 'sp_statistic' ) ) ) {
|
||||
wp_enqueue_script( 'jquery-ui-core' );
|
||||
wp_enqueue_script( 'jquery-ui-draggable' );
|
||||
wp_enqueue_script( 'jquery-ui-droppable' );
|
||||
wp_enqueue_script( 'sportspress-admin-equationbuilder' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,7 +236,7 @@ class SP_Admin_Welcome {
|
||||
<h4><?php _e( 'Translators', 'sportspress' ); ?></h4>
|
||||
<p><?php _e( 'SportsPress has been kindly translated into several other languages thanks to our translation team. Want to see your name? <a href="https://www.transifex.com/projects/p/sportspress/">Translate SportsPress</a>.', 'sportspress' ); ?></p>
|
||||
<?php
|
||||
$translator_handles = array( 'Abdulelah', 'albertone', 'Andrew_Melim', 'aylaview', 'Bhelpful2', 'bizover', 'BOCo', 'dic_2008', 'hanro', 'i__k', 'JensZ', 'JuKi', 'karimjarro', 'King3R', 'massimo.marra', 'rochester', 'Selskei', 'Spirossmil', 'ThemeBoy', 'valentijnreza' );
|
||||
$translator_handles = array( 'Abdulelah', 'albertone', 'Andrew_Melim', 'aylaview', 'Bhelpful2', 'bizover', 'BOCo', 'dic_2008', 'hanro', 'i__k', 'JensZ', 'JuKi', 'karimjarro', 'King3R', 'massimo.marra', 'rochester', 'Selskei', 'sijo', 'Spirossmil', 'ThemeBoy', 'valentijnreza' );
|
||||
$translator_links = array();
|
||||
foreach ( $translator_handles as $handle ):
|
||||
$translator_links[] = '<a href="https://www.transifex.com/accounts/profile/' . $handle . '">' . $handle . '</a>';
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Meta Boxes
|
||||
* @version 0.8
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
@@ -40,9 +40,11 @@ class SP_Admin_Meta_Boxes {
|
||||
|
||||
// Save Statistic Meta Boxes
|
||||
add_action( 'sportspress_process_sp_statistic_meta', 'SP_Meta_Box_Statistic_Details::save', 10, 2 );
|
||||
add_action( 'sportspress_process_sp_statistic_meta', 'SP_Meta_Box_Statistic_Equation::save', 20, 2 );
|
||||
|
||||
// Save Column Meta Boxes
|
||||
add_action( 'sportspress_process_sp_column_meta', 'SP_Meta_Box_Column_Details::save', 10, 2 );
|
||||
add_action( 'sportspress_process_sp_column_meta', 'SP_Meta_Box_Column_Equation::save', 20, 2 );
|
||||
|
||||
// Save Event Meta Boxes
|
||||
add_action( 'sportspress_process_sp_event_meta', 'SP_Meta_Box_Event_Format::save', 10, 2 );
|
||||
@@ -92,7 +94,8 @@ class SP_Admin_Meta_Boxes {
|
||||
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'SP_Meta_Box_Outcome_Details::output', 'sp_outcome', 'normal', 'high' );
|
||||
|
||||
// Columns
|
||||
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'SP_Meta_Box_Column_Details::output', 'sp_column', 'normal', 'high' );
|
||||
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'SP_Meta_Box_Column_Details::output', 'sp_column', 'side', 'default' );
|
||||
add_meta_box( 'sp_equationdiv', __( 'Equation', 'sportspress' ), 'SP_Meta_Box_Column_Equation::output', 'sp_column', 'normal', 'high' );
|
||||
|
||||
// Metrics
|
||||
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'SP_Meta_Box_Metric_Details::output', 'sp_metric', 'normal', 'high' );
|
||||
@@ -100,8 +103,9 @@ class SP_Admin_Meta_Boxes {
|
||||
// Performance
|
||||
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'SP_Meta_Box_Performance_Details::output', 'sp_performance', 'normal', 'high' );
|
||||
|
||||
// Metrics
|
||||
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'SP_Meta_Box_Statistic_Details::output', 'sp_statistic', 'normal', 'high' );
|
||||
// Statistics
|
||||
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'SP_Meta_Box_Statistic_Details::output', 'sp_statistic', 'side', 'default' );
|
||||
add_meta_box( 'sp_equationdiv', __( 'Equation', 'sportspress' ), 'SP_Meta_Box_Statistic_Equation::output', 'sp_statistic', 'normal', 'high' );
|
||||
|
||||
// Events
|
||||
add_meta_box( 'sp_shortcodediv', __( 'Shortcodes', 'sportspress' ), 'SP_Meta_Box_Event_Shortcode::output', 'sp_event', 'side', 'default' );
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Meta Boxes
|
||||
* @version 0.8
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
@@ -36,14 +36,6 @@ class SP_Meta_Box_Column_Details extends SP_Meta_Box_Config {
|
||||
<input name="sp_default_key" type="hidden" id="sp_default_key" value="<?php echo $post->post_name; ?>">
|
||||
<input name="sp_key" type="text" id="sp_key" value="<?php echo $post->post_name; ?>">
|
||||
</p>
|
||||
<p><strong><?php _e( 'Equation', 'sportspress' ); ?></strong></p>
|
||||
<p class="sp-equation-selector">
|
||||
<?php
|
||||
foreach ( $equation as $piece ):
|
||||
self::select( $post->ID, $piece, array( 'team_event', 'outcome', 'result' ) );
|
||||
endforeach;
|
||||
?>
|
||||
</p>
|
||||
<p><strong><?php _e( 'Rounding', 'sportspress' ); ?></strong></p>
|
||||
<p class="sp-precision-selector">
|
||||
<input name="sp_precision" type="text" size="4" id="sp_precision" value="<?php echo $precision; ?>" placeholder="0">
|
||||
@@ -79,7 +71,6 @@ class SP_Meta_Box_Column_Details extends SP_Meta_Box_Config {
|
||||
*/
|
||||
public static function save( $post_id, $post ) {
|
||||
self::delete_duplicate( $_POST );
|
||||
update_post_meta( $post_id, 'sp_equation', implode( ' ', sp_array_value( $_POST, 'sp_equation', array() ) ) );
|
||||
update_post_meta( $post_id, 'sp_precision', (int) sp_array_value( $_POST, 'sp_precision', 1 ) );
|
||||
update_post_meta( $post_id, 'sp_priority', sp_array_value( $_POST, 'sp_priority', '0' ) );
|
||||
update_post_meta( $post_id, 'sp_order', sp_array_value( $_POST, 'sp_order', 'DESC' ) );
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Column Equation
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Meta Boxes
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'SP_Meta_Box_Equation' ) )
|
||||
include( 'class-sp-meta-box-equation.php' );
|
||||
|
||||
/**
|
||||
* SP_Meta_Box_Column_Equation
|
||||
*/
|
||||
class SP_Meta_Box_Column_Equation extends SP_Meta_Box_Equation {
|
||||
|
||||
/**
|
||||
* Output the metabox
|
||||
*/
|
||||
public static function output( $post ) {
|
||||
$equation = get_post_meta( $post->ID, 'sp_equation', true );
|
||||
self::builder( $post->post_title, $equation, array( 'team_event', 'outcome', 'result' ) );
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Meta Boxes
|
||||
* @version 0.8
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
@@ -22,118 +22,6 @@ class SP_Meta_Box_Config {
|
||||
self::delete_duplicate( $_POST );
|
||||
}
|
||||
|
||||
public static function select( $postid, $selected = null, $groups = array() ) {
|
||||
|
||||
if ( ! isset( $postid ) )
|
||||
return;
|
||||
|
||||
// Initialize options array
|
||||
$options = array();
|
||||
|
||||
// Add groups to options
|
||||
foreach ( $groups as $group ):
|
||||
switch ( $group ):
|
||||
case 'player_event':
|
||||
$options[ __( 'Events', 'sportspress' ) ] = array( '$eventsattended' => __( 'Attended', 'sportspress' ), '$eventsplayed' => __( 'Played', 'sportspress' ), '$eventsstarted' => __( 'Started', 'sportspress' ), '$eventssubbed' => __( 'Substituted', 'sportspress' ) );
|
||||
break;
|
||||
case 'team_event':
|
||||
$options[ __( 'Events', 'sportspress' ) ] = array( '$eventsplayed' => __( 'Played', 'sportspress' ) );
|
||||
break;
|
||||
case 'result':
|
||||
$options[ __( 'Results', 'sportspress' ) ] = self::optgroup( $postid, 'sp_result', array( 'for' => '→', 'against' => '←' ), null, false );
|
||||
break;
|
||||
case 'outcome':
|
||||
$options[ __( 'Outcomes', 'sportspress' ) ] = self::optgroup( $postid, 'sp_outcome', array() );
|
||||
$options[ __( 'Outcomes', 'sportspress' ) ]['$streak'] = __( 'Streak', 'sportspress' );
|
||||
$options[ __( 'Outcomes', 'sportspress' ) ]['$last5'] = __( 'Last 5', 'sportspress' );
|
||||
$options[ __( 'Outcomes', 'sportspress' ) ]['$last10'] = __( 'Last 10', 'sportspress' );
|
||||
break;
|
||||
case 'performance':
|
||||
$options[ __( 'Performance', 'sportspress' ) ] = self::optgroup( $postid, 'sp_performance' );
|
||||
break;
|
||||
case 'metric':
|
||||
$options[ __( 'Metric', 'sportspress' ) ] = self::optgroup( $postid, 'sp_metric' );
|
||||
break;
|
||||
endswitch;
|
||||
endforeach;
|
||||
|
||||
// Create array of operators
|
||||
$operators = array( '+' => '+', '-' => '−', '*' => '×', '/' => '÷', '(' => '(', ')' => ')' );
|
||||
|
||||
// Add operators to options
|
||||
$options[ __( 'Operators', 'sportspress' ) ] = $operators;
|
||||
|
||||
// Create array of constants
|
||||
$max = 10;
|
||||
$constants = array();
|
||||
for ( $i = 1; $i <= $max; $i ++ ):
|
||||
$constants[$i] = $i;
|
||||
endfor;
|
||||
|
||||
// Add 100 to constants
|
||||
$constants[100] = 100;
|
||||
|
||||
// Add constants to options
|
||||
$options[ __( 'Constants', 'sportspress' ) ] = (array) $constants;
|
||||
|
||||
?>
|
||||
<select name="sp_equation[]">
|
||||
<option value=""><?php _e( '— Select —', 'sportspress' ); ?></option>
|
||||
<?php
|
||||
|
||||
foreach ( $options as $label => $option ):
|
||||
printf( '<optgroup label="%s">', $label );
|
||||
|
||||
foreach ( $option as $key => $value ):
|
||||
printf( '<option value="%s" %s>%s</option>', $key, selected( true, $key == $selected, false ), $value );
|
||||
endforeach;
|
||||
|
||||
echo '</optgroup>';
|
||||
endforeach;
|
||||
|
||||
?>
|
||||
</select>
|
||||
<?php
|
||||
}
|
||||
|
||||
public static function optgroup( $postid, $type = null, $variations = null, $defaults = null, $totals = true ) {
|
||||
$arr = array();
|
||||
|
||||
// Get posts
|
||||
$args = array(
|
||||
'post_type' => $type,
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'orderby' => 'menu_order',
|
||||
'order' => 'ASC',
|
||||
'exclude' => $postid
|
||||
);
|
||||
$vars = get_posts( $args );
|
||||
|
||||
// Add extra vars to the array
|
||||
if ( isset( $defaults ) && is_array( $defaults ) ):
|
||||
foreach ( $defaults as $key => $value ):
|
||||
$arr[ $key ] = $value;
|
||||
endforeach;
|
||||
endif;
|
||||
|
||||
// Add vars to the array
|
||||
if ( isset( $variations ) && is_array( $variations ) ):
|
||||
foreach ( $vars as $var ):
|
||||
if ( $totals ) $arr[ '$' . $var->post_name ] = $var->post_title;
|
||||
foreach ( $variations as $key => $value ):
|
||||
$arr[ '$' . $var->post_name . $key ] = $var->post_title . ' ' . $value;
|
||||
endforeach;
|
||||
endforeach;
|
||||
else:
|
||||
foreach ( $vars as $var ):
|
||||
$arr[ '$' . $var->post_name ] = $var->post_title;
|
||||
endforeach;
|
||||
endif;
|
||||
|
||||
return (array) $arr;
|
||||
}
|
||||
|
||||
public static function delete_duplicate( &$post ) {
|
||||
global $wpdb;
|
||||
|
||||
@@ -152,5 +40,4 @@ class SP_Meta_Box_Config {
|
||||
|
||||
return $post_name_check;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
/**
|
||||
* Equation meta box functions
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Meta Boxes
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
/**
|
||||
* SP_Meta_Box_Equation
|
||||
*/
|
||||
class SP_Meta_Box_Equation {
|
||||
|
||||
/**
|
||||
* Save meta box data
|
||||
*/
|
||||
public static function save( $post_id, $post ) {
|
||||
update_post_meta( $post_id, 'sp_equation', implode( ' ', sp_array_value( $_POST, 'sp_equation', array() ) ) );
|
||||
}
|
||||
|
||||
public static function builder( $title = 'f(x)', $equation = '', $groups = array() ) {
|
||||
if ( $title == '' ) $title = 'f(x)';
|
||||
$options = array(); // Multidimensional equation part options
|
||||
$parts = array(); // Flattened equation part options
|
||||
|
||||
// Add groups to options
|
||||
foreach ( $groups as $group ):
|
||||
switch ( $group ):
|
||||
case 'player_event':
|
||||
$options['Events'] = array( '$eventsattended' => __( 'Attended', 'sportspress' ), '$eventsplayed' => __( 'Played', 'sportspress' ), '$eventsstarted' => __( 'Started', 'sportspress' ), '$eventssubbed' => __( 'Substituted', 'sportspress' ) );
|
||||
break;
|
||||
case 'team_event':
|
||||
$options['Events'] = array( '$eventsplayed' => __( 'Played', 'sportspress' ) );
|
||||
break;
|
||||
case 'result':
|
||||
$options['Results'] = self::optgroup( 'sp_result', array( 'for' => '(' . __( 'for', 'sportspress' ) . ')', 'against' => '(' . __( 'against', 'sportspress' ) . ')' ), null, false );
|
||||
break;
|
||||
case 'outcome':
|
||||
$options['Outcomes'] = self::optgroup( 'sp_outcome' );
|
||||
$options['Outcomes']['$streak'] = __( 'Streak', 'sportspress' );
|
||||
$options['Outcomes']['$last5'] = __( 'Last 5', 'sportspress' );
|
||||
$options['Outcomes']['$last10'] = __( 'Last 10', 'sportspress' );
|
||||
break;
|
||||
case 'performance':
|
||||
$options['Performance'] = self::optgroup( 'sp_performance' );
|
||||
break;
|
||||
case 'metric':
|
||||
$options['Metric'] = self::optgroup( 'sp_metric' );
|
||||
break;
|
||||
endswitch;
|
||||
endforeach;
|
||||
|
||||
// Create array of operators
|
||||
$operators = array( '+' => '+', '-' => '−', '*' => '×', '/' => '÷', '(' => '(', ')' => ')' );
|
||||
|
||||
// Add operators to options
|
||||
$options['Operators'] = $operators;
|
||||
|
||||
// Create array of constants
|
||||
$max = 10;
|
||||
$constants = array();
|
||||
for ( $i = 0; $i <= $max; $i ++ ):
|
||||
$constants[$i] = $i;
|
||||
endfor;
|
||||
|
||||
// Add 100 to constants
|
||||
$constants[100] = 100;
|
||||
|
||||
// Add constants to options
|
||||
$options['Constants'] = (array) $constants;
|
||||
?>
|
||||
<div class="sp-equation-builder">
|
||||
<div class="sp-data-table-container sp-equation-parts">
|
||||
<table class="widefat sp-data-table">
|
||||
<?php $i = 0; foreach ( $options as $label => $option ): ?>
|
||||
<tr<?php if ( $i % 2 == 0 ): ?> class="alternate"<?php endif; ?>>
|
||||
<th><?php _e( $label, 'sportspress' ) ?></th>
|
||||
<td>
|
||||
<?php foreach ( $option as $key => $value ): $parts[ $key ] = $value;
|
||||
?><span class="button" data-variable="<?php echo $key; ?>"><?php echo $value; ?></span><?php
|
||||
endforeach; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php $i++; endforeach; ?>
|
||||
</table>
|
||||
</div>
|
||||
<div class="sp-equation">
|
||||
<span class="sp-equation-variable"><?php echo $title; ?> = </span>
|
||||
<span class="sp-equation-formula"><?php
|
||||
if ( $equation !== '' ):
|
||||
$equation = explode( ' ', $equation );
|
||||
foreach ( $equation as $part ):
|
||||
if ( array_key_exists( $part, $parts ) ) {
|
||||
$name = $parts[ $part ];
|
||||
} else {
|
||||
$name = $part;
|
||||
} ?><span class="button"><?php echo $name; ?><span class="remove">×</span><input type="hidden" name="sp_equation[]" value="<?php echo $part; ?>"></span><?php
|
||||
endforeach;
|
||||
endif;
|
||||
?></span>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public static function optgroup( $type = null, $variations = null, $defaults = null, $totals = true ) {
|
||||
$arr = array();
|
||||
|
||||
// Get posts
|
||||
$args = array(
|
||||
'post_type' => $type,
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'orderby' => 'menu_order',
|
||||
'order' => 'ASC',
|
||||
);
|
||||
$vars = get_posts( $args );
|
||||
|
||||
// Add extra vars to the array
|
||||
if ( isset( $defaults ) && is_array( $defaults ) ):
|
||||
foreach ( $defaults as $key => $value ):
|
||||
$arr[ $key ] = $value;
|
||||
endforeach;
|
||||
endif;
|
||||
|
||||
// Add vars to the array
|
||||
if ( isset( $variations ) && is_array( $variations ) ):
|
||||
foreach ( $vars as $var ):
|
||||
if ( $totals ) $arr[ '$' . $var->post_name ] = $var->post_title;
|
||||
foreach ( $variations as $key => $value ):
|
||||
$arr[ '$' . $var->post_name . $key ] = $var->post_title . ' ' . $value;
|
||||
endforeach;
|
||||
endforeach;
|
||||
else:
|
||||
foreach ( $vars as $var ):
|
||||
$arr[ '$' . $var->post_name ] = $var->post_title;
|
||||
endforeach;
|
||||
endif;
|
||||
|
||||
return (array) $arr;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Meta Boxes
|
||||
* @version 0.8
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
@@ -23,7 +23,6 @@ class SP_Meta_Box_Metric_Details extends SP_Meta_Box_Config {
|
||||
*/
|
||||
public static function output( $post ) {
|
||||
wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' );
|
||||
$calculate = get_post_meta( $post->ID, 'sp_calculate', true );
|
||||
?>
|
||||
<p><strong><?php _e( 'Variable', 'sportspress' ); ?></strong></p>
|
||||
<p>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Meta Boxes
|
||||
* @version 0.8
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
@@ -23,7 +23,6 @@ class SP_Meta_Box_Statistic_Details extends SP_Meta_Box_Config {
|
||||
*/
|
||||
public static function output( $post ) {
|
||||
wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' );
|
||||
$equation = explode( ' ', get_post_meta( $post->ID, 'sp_equation', true ) );
|
||||
$precision = get_post_meta( $post->ID, 'sp_precision', true );
|
||||
|
||||
// Defaults
|
||||
@@ -34,14 +33,6 @@ class SP_Meta_Box_Statistic_Details extends SP_Meta_Box_Config {
|
||||
<input name="sp_default_key" type="hidden" id="sp_default_key" value="<?php echo $post->post_name; ?>">
|
||||
<input name="sp_key" type="text" id="sp_key" value="<?php echo $post->post_name; ?>">
|
||||
</p>
|
||||
<p><strong><?php _e( 'Equation', 'sportspress' ); ?></strong></p>
|
||||
<p class="sp-equation-selector">
|
||||
<?php
|
||||
foreach ( $equation as $piece ):
|
||||
self::select( $post->ID, $piece, array( 'player_event', 'outcome', 'performance', 'metric' ) );
|
||||
endforeach;
|
||||
?>
|
||||
</p>
|
||||
<p><strong><?php _e( 'Rounding', 'sportspress' ); ?></strong></p>
|
||||
<p class="sp-precision-selector">
|
||||
<input name="sp_precision" type="text" size="4" id="sp_precision" value="<?php echo $precision; ?>" placeholder="0">
|
||||
@@ -54,7 +45,6 @@ class SP_Meta_Box_Statistic_Details extends SP_Meta_Box_Config {
|
||||
*/
|
||||
public static function save( $post_id, $post ) {
|
||||
self::delete_duplicate( $_POST );
|
||||
update_post_meta( $post_id, 'sp_equation', implode( ' ', sp_array_value( $_POST, 'sp_equation', array() ) ) );
|
||||
update_post_meta( $post_id, 'sp_precision', (int) sp_array_value( $_POST, 'sp_precision', 1 ) );
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Statistic Equation
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Meta Boxes
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'SP_Meta_Box_Equation' ) )
|
||||
include( 'class-sp-meta-box-equation.php' );
|
||||
|
||||
/**
|
||||
* SP_Meta_Box_Statistic_Equation
|
||||
*/
|
||||
class SP_Meta_Box_Statistic_Equation extends SP_Meta_Box_Equation {
|
||||
|
||||
/**
|
||||
* Output the metabox
|
||||
*/
|
||||
public static function output( $post ) {
|
||||
$equation = get_post_meta( $post->ID, 'sp_equation', true );
|
||||
self::builder( $post->post_title, $equation, array( 'player_event', 'outcome', 'performance', 'metric' ) );
|
||||
}
|
||||
}
|
||||
@@ -107,6 +107,19 @@ class SP_Settings_General extends SP_Settings_Page {
|
||||
'checkboxgroup' => 'end',
|
||||
'desc_tip' => __( 'This will enable a script allowing the countdowns to be animated.', 'sportspress' ),
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Header Offset', 'sportspress' ),
|
||||
'id' => 'sportspress_header_offset',
|
||||
'class' => 'small-text',
|
||||
'default' => null,
|
||||
'placeholder' => __( 'Auto', 'sportspress' ),
|
||||
'desc' => 'px',
|
||||
'type' => 'number',
|
||||
'custom_attributes' => array(
|
||||
'step' => 1
|
||||
),
|
||||
),
|
||||
|
||||
array( 'type' => 'sectionend', 'id' => 'script_styling_options' ),
|
||||
|
||||
@@ -167,7 +180,7 @@ class SP_Settings_General extends SP_Settings_Page {
|
||||
<label for="sportspress_default_country"><?php _e( 'Base Location', 'sportspress' ); ?></label>
|
||||
</th>
|
||||
<td class="forminp">
|
||||
<legend class="screen-reader-text"><span><?php _e( 'Delimiter', 'sportspress' ); ?></span></legend>
|
||||
<legend class="screen-reader-text"><span><?php _e( 'Base Location', 'sportspress' ); ?></span></legend>
|
||||
<select name="sportspress_default_country" data-placeholder="<?php _e( 'Choose a country…', 'sportspress' ); ?>" title="Country" class="chosen-select<?php if ( is_rtl() ): ?> chosen-rtl<?php endif; ?>">
|
||||
<?php SP()->countries->country_dropdown_options( $selected ); ?>
|
||||
</select>
|
||||
|
||||
@@ -97,7 +97,13 @@ class SP_Frontend_Scripts {
|
||||
$enabled = get_option( 'sportspress_enable_frontend_css', 'yes' );
|
||||
$custom = get_option( 'sportspress_custom_css', null );
|
||||
|
||||
if ( $enabled == 'yes' || ! empty( $custom ) ) {
|
||||
$offset = get_option( 'sportspress_header_offset', '' );
|
||||
if ( $offset === '' ) {
|
||||
$template = get_option( 'template' );
|
||||
$offset = ( 'twentyfourteen' == $template ? 48 : 0 );
|
||||
}
|
||||
|
||||
if ( $enabled == 'yes' || ! empty( $custom ) || $offset != 0 ) {
|
||||
|
||||
$colors = get_option( 'sportspress_frontend_css_colors' );
|
||||
|
||||
@@ -122,6 +128,9 @@ class SP_Frontend_Scripts {
|
||||
echo '.sp-data-table tbody a,.sp-data-table tbody a:hover,.sp-calendar tbody a:focus{color: ' . $colors['link'] . ' !important}';
|
||||
}
|
||||
|
||||
if ( $offset != 0 )
|
||||
echo ' @media only screen and (min-width: 40.063em) {.sp-header{top: ' . $offset . 'px}}';
|
||||
|
||||
if ( ! empty( $custom ) )
|
||||
echo ' /* SportsPress Custom CSS */ ' . $custom;
|
||||
|
||||
|
||||
@@ -242,6 +242,8 @@ final class SportsPress {
|
||||
include_once( 'includes/widgets/class-sp-widget-league-table.php' );
|
||||
include_once( 'includes/widgets/class-sp-widget-player-list.php' );
|
||||
include_once( 'includes/widgets/class-sp-widget-player-gallery.php' );
|
||||
|
||||
do_action( 'sportspress_widgets' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user