Complete refactoring and add style settings

This commit is contained in:
Brian Miyaji
2014-03-28 01:48:52 +11:00
parent d3b27c8c73
commit 7e6b4adb9b
83 changed files with 2063 additions and 7028 deletions

View File

@@ -51,9 +51,9 @@ class SP_Settings_Config extends SP_Settings_Page {
'type' => 'select',
'options' => SP()->sports->options,
),
array( 'type' => 'results' ),
array( 'type' => 'outcomes' ),
array( 'type' => 'columns' ),
@@ -69,51 +69,110 @@ class SP_Settings_Config extends SP_Settings_Page {
)); // End event settings
}
/**
* Output the settings
*/
public function output() {
global $current_section;
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('sportspress_tax_classes' ) ) ) );
if ( $current_section == 'standard' || in_array( $current_section, array_map( 'sanitize_title', $tax_classes ) ) ) {
$this->output_tax_rates();
} else {
$settings = $this->get_settings();
SP_Admin_Settings::output_fields( $settings );
}
}
/**
* Save settings
*/
public function save() {
global $current_section, $wpdb;
$settings = $this->get_settings();
SP_Admin_Settings::save_fields( $settings );
if ( isset( $_POST['sportspress_primary_result'] ) )
update_option( 'sportspress_primary_result', $_POST['sportspress_primary_result'] );
if ( ! $current_section ) {
if ( isset( $_POST['sportspress_sport'] ) && ! empty( $_POST['sportspress_sport'] ) && get_option( 'sportspress_sport', null ) != $_POST['sportspress_sport'] ):
$settings = $this->get_settings();
SP_Admin_Settings::save_fields( $settings );
$sport = SP()->sports->$_POST['sportspress_sport'];
} else {
// Get array of taxonomies to insert
$term_groups = sp_array_value( $sport, 'term', array() );
$this->save_tax_rates();
foreach( $term_groups as $taxonomy => $terms ):
// Find empty terms and destroy
$allterms = get_terms( $taxonomy, 'hide_empty=0' );
}
foreach( $allterms as $term ):
if ( $term->count == 0 )
wp_delete_term( $term->term_id, $taxonomy );
endforeach;
$wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_sp_tax_rates_%') OR `option_name` LIKE ('_transient_timeout_sp_tax_rates_%')" );
// Insert terms
foreach( $terms as $term ):
wp_insert_term( $term['name'], $taxonomy, array( 'slug' => $term['slug'] ) );
endforeach;
endforeach;
// Get array of post types to insert
$post_groups = sp_array_value( $sport, 'posts', array() );
// Loop through each post type
foreach( $post_groups as $post_type => $posts ):
$args = array(
'post_type' => $post_type,
'numberposts' => -1,
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => '_sp_preset',
'value' => 1
)
)
);
// Delete posts
$old_posts = get_posts( $args );
foreach( $old_posts as $post ):
wp_delete_post( $post->ID, true);
endforeach;
// Add posts
foreach( $posts as $index => $post ):
// Make sure post doesn't overlap
if ( ! get_page_by_path( $post['post_name'], OBJECT, $post_type ) ):
// Translate post title
$post['post_title'] = __( $post['post_title'], 'sportspress' );
// Set post type
$post['post_type'] = $post_type;
// Increment menu order by 2 and publish post
$post['menu_order'] = $index * 2 + 2;
$post['post_status'] = 'publish';
$id = wp_insert_post( $post );
// Flag as preset
update_post_meta( $id, '_sp_preset', 1 );
// Update meta
if ( array_key_exists( 'meta', $post ) ):
foreach ( $post['meta'] as $key => $value ):
update_post_meta( $id, $key, $value );
endforeach;
endif;
// Update terms
if ( array_key_exists( 'tax_input', $post ) ):
foreach ( $post['tax_input'] as $taxonomy => $terms ):
wp_set_object_terms( $id, $terms, $taxonomy, false );
endforeach;
endif;
endif;
endforeach;
endforeach;
endif;
}
/**
* Output results settings.
* Results settings
*
* @access public
* @return void
*/
public function results_setting() {
$main_result = get_option( 'sportspress_main_result', 0 );
$selection = get_option( 'sportspress_primary_result', 0 );
$args = array(
'post_type' => 'sp_result',
@@ -127,54 +186,57 @@ class SP_Settings_Config extends SP_Settings_Page {
<tr valign="top">
<th scope="row" class="titledesc"><?php _e( 'Results', 'sportspress' ) ?></th>
<td class="forminp">
<table class="widefat sp-admin-config-table">
<thead>
<tr>
<th scope="col"><?php _e( 'Primary', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Label', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Key', 'sportspress' ); ?></th>
<th scope="col" class="edit"></th>
</tr>
</thead>
<tfoot>
<tr>
<th class="radio"><input type="radio" id="sportspress_main_result_0" name="main_result" value="0" <?php checked( $main_result, 0 ); ?>></th>
<th colspan="3"><label for="main_result_0">
<?php
if ( sizeof( $data ) > 0 ):
$default = end( $data );
reset( $data );
printf( __( 'Default (%s)', 'sportspress' ), $default->post_title );
else:
_e( 'Default', 'sportspress' );
endif;
?>
</label></th>
</tr>
</tfoot>
<?php $i = 0; foreach ( $data as $row ): ?>
<tr<?php if ( $i % 2 == 0 ) echo ' class="alternate"'; ?>>
<td class="radio"><input type="radio" id="main_result_<?php echo $row->post_name; ?>" name="main_result" value="<?php echo $row->post_name; ?>" <?php checked( $main_result, $row->post_name ); ?>></td>
<td class="row-title"><label for="sportspress_main_result_<?php echo $row->post_name; ?>"><?php echo $row->post_title; ?></label></td>
<td><?php echo $row->post_name; ?>for / <?php echo $row->post_name; ?>against</td>
<td class="edit"><a class="button" href="<?php echo get_edit_post_link( $row->ID ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></s></td>
</tr>
<?php $i++; endforeach; ?>
</table>
<div class="tablenav bottom">
<div class="alignleft actions">
<a class="button" id="doaction" href="<?php echo admin_url( 'edit.php?post_type=sp_result' ); ?>"><?php _e( 'View All', 'sportspress' ); ?></a>
<a class="button" id="doaction2" href="<?php echo admin_url( 'post-new.php?post_type=sp_result' ); ?>"><?php _e( 'Add New', 'sportspress' ); ?></a>
<fieldset>
<legend class="screen-reader-text"><span><?php _e( 'Results', 'sportspress' ) ?></span></legend>
<table class="widefat sp-admin-config-table">
<thead>
<tr>
<th scope="col"><?php _e( 'Primary', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Label', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Key', 'sportspress' ); ?></th>
<th scope="col" class="edit"></th>
</tr>
</thead>
<tfoot>
<tr>
<th class="radio"><input type="radio" id="sportspress_primary_result_0" name="sportspress_primary_result" value="0" <?php checked( $selection, 0 ); ?>></th>
<th colspan="3"><label for="sportspress_primary_result_0">
<?php
if ( sizeof( $data ) > 0 ):
$default = end( $data );
reset( $data );
printf( __( 'Default (%s)', 'sportspress' ), $default->post_title );
else:
_e( 'Default', 'sportspress' );
endif;
?>
</label></th>
</tr>
</tfoot>
<?php $i = 0; foreach ( $data as $row ): ?>
<tr<?php if ( $i % 2 == 0 ) echo ' class="alternate"'; ?>>
<td class="radio"><input type="radio" id="sportspress_primary_result_<?php echo $row->post_name; ?>" name="sportspress_primary_result" value="<?php echo $row->post_name; ?>" <?php checked( $selection, $row->post_name ); ?>></td>
<td class="row-title"><label for="sportspress_primary_result_<?php echo $row->post_name; ?>"><?php echo $row->post_title; ?></label></td>
<td><?php echo $row->post_name; ?>for / <?php echo $row->post_name; ?>against</td>
<td class="edit"><a class="button" href="<?php echo get_edit_post_link( $row->ID ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></s></td>
</tr>
<?php $i++; endforeach; ?>
</table>
<div class="tablenav bottom">
<div class="alignleft actions">
<a class="button" id="doaction" href="<?php echo admin_url( 'edit.php?post_type=sp_result' ); ?>"><?php _e( 'View All', 'sportspress' ); ?></a>
<a class="button" id="doaction2" href="<?php echo admin_url( 'post-new.php?post_type=sp_result' ); ?>"><?php _e( 'Add New', 'sportspress' ); ?></a>
</div>
<br class="clear">
</div>
<br class="clear">
</div>
</fieldset>
</td>
</tr>
<?php
}
/**
* Output outcomes settings.
* Output outcomes settings
*
* @access public
* @return void
@@ -221,7 +283,7 @@ class SP_Settings_Config extends SP_Settings_Page {
}
/**
* Output columns settings.
* Output columns settings
*
* @access public
* @return void
@@ -275,7 +337,7 @@ class SP_Settings_Config extends SP_Settings_Page {
}
/**
* Output metrics settings.
* Output metrics settings
*
* @access public
* @return void
@@ -324,7 +386,7 @@ class SP_Settings_Config extends SP_Settings_Page {
}
/**
* Output performance settings.
* Output performance settings
*
* @access public
* @return void
@@ -375,4 +437,4 @@ class SP_Settings_Config extends SP_Settings_Page {
endif;
return new SP_Settings_Config();
return new SP_Settings_Config();