Add a "Full Info" event shortcode. It supports template order!

This commit is contained in:
savvasha
2018-08-31 18:53:55 +03:00
parent 329de03646
commit c37705024d
6 changed files with 187 additions and 2 deletions

View File

@@ -4,7 +4,7 @@ $shortcodes = '';
$options = array(
'event' => array(
'details', 'results', 'performance', 'venue', 'officials', 'teams',
'details', 'results', 'performance', 'venue', 'officials', 'teams', 'full',
),
'team' => array(),
'player' => array(
@@ -33,6 +33,7 @@ $raw = apply_filters( 'sportspress_tinymce_strings', array(
'venue' => __( 'Venue', 'sportspress' ),
'officials' => __( 'Officials', 'sportspress' ),
'teams' => __( 'Teams', 'sportspress' ),
'full' => __( 'Full Info', 'sportspress' ),
'calendar' => __( 'Calendar', 'sportspress' ),
'statistics' => __( 'Statistics', 'sportspress' ),
'team' => __( 'Team', 'sportspress' ),

View File

@@ -26,6 +26,7 @@ class SP_Meta_Box_Event_Shortcode {
'event_venue' => __( 'Venue', 'sportspress' ),
'event_officials' => __( 'Officials', 'sportspress' ),
'event_teams' => __( 'Teams', 'sportspress' ),
'event_full' => __( 'Full Info', 'sportspress' ),
) );
if ( $shortcodes ) {
?>

View File

@@ -275,6 +275,36 @@ class SP_AJAX {
die();
}
/**
* AJAX event_full shortcode
*/
public function event_full_shortcode() {
?>
<div class="wrap sp-thickbox-content" id="sp-thickbox-event_full">
<p>
<label>
<?php printf( __( 'Select %s:', 'sportspress' ), __( 'Event', 'sportspress' ) ); ?>
<?php
$args = array(
'post_type' => 'sp_event',
'name' => 'id',
'values' => 'ID',
);
sp_dropdown_pages( $args );
?>
</label>
</p>
<?php do_action( 'sportspress_ajax_shortcode_form', 'event-full' ); ?>
<p class="submit">
<input type="button" class="button-primary" value="<?php _e( 'Insert Shortcode', 'sportspress' ); ?>" onclick="insertSportsPress('event_full');" />
<a class="button-secondary" onclick="tb_remove();" title="<?php _e( 'Cancel', 'sportspress' ); ?>"><?php _e( 'Cancel', 'sportspress' ); ?></a>
</p>
</div>
<?php
self::scripts();
die();
}
/**
* AJAX event_calendar shortcode
*/

View File

@@ -22,6 +22,7 @@ class SP_Shortcodes {
'event_venue' => __CLASS__ . '::event_venue',
'event_officials' => __CLASS__ . '::event_officials',
'event_teams' => __CLASS__ . '::event_teams',
'event_full' => __CLASS__ . '::event_full',
'countdown' => __CLASS__ . '::countdown',
'player_details' => __CLASS__ . '::player_details',
'player_statistics' => __CLASS__ . '::player_statistics',
@@ -138,6 +139,17 @@ class SP_Shortcodes {
return self::shortcode_wrapper( array( 'SP_Shortcode_Event_Teams', 'output' ), $atts );
}
/**
* Event full info shortcode.
*
* @access public
* @param mixed $atts
* @return string
*/
public static function event_full( $atts ) {
return self::shortcode_wrapper( array( 'SP_Shortcode_Event_Full', 'output' ), $atts );
}
/**
* Countdown shortcode.
*

View File

@@ -0,0 +1,139 @@
<?php
/**
* Event Full info Shortcode
*
* @author ThemeBoy
* @category Shortcodes
* @package SportsPress/Shortcodes/Event_Full
* @version 2.6.9
*/
class SP_Shortcode_Event_Full {
/**
* Output the event full shortcode.
*
* @param array $atts
*/
public static function output( $atts ) {
if ( ! isset( $atts['id'] ) && isset( $atts[0] ) && is_numeric( $atts[0] ) )
$atts['id'] = $atts[0];
$type = 'event';
$content = apply_filters( 'the_content', get_post_field( 'post_content', $atts['id'] ) );
// Get layout setting
$layout = (array) get_option( 'sportspress_' . $type . '_template_order', array() );
// Get templates
$templates = SP()->templates->$type;
// Combine layout setting with available templates
$templates = array_merge( array_flip( $layout ), $templates );
$templates = apply_filters( 'sportspress_' . $type . '_templates', $templates );
// Split templates into sections and tabs
$slice = array_search( 'tabs', array_keys( $templates ) );
if ( $slice ) {
$section_templates = array_slice( $templates, 0, $slice );
$tab_templates = array_slice( $templates, $slice );
} else {
$section_templates = $templates;
$tab_templates = array();
}
ob_start();
// Before template hook
do_action( 'sportspress_before_single_' . $type );
// Loop through sections
if ( ! empty( $section_templates ) ) {
foreach ( $section_templates as $key => $template ) {
// Ignore templates that are unavailable or that have been turned off
if ( ! is_array( $template ) ) continue;
if ( ! isset( $template['option'] ) ) continue;
if ( 'yes' !== get_option( $template['option'], sp_array_value( $template, 'default', 'yes' ) ) ) continue;
// Render the template
echo '<div class="sp-section-content sp-section-content-' . $key . '">';
if ( 'content' === $key ) {
echo $content;
// Template content hook
do_action( 'sportspress_single_' . $type . '_content' );
} elseif ( 'excerpt' === $key ) {
sp_get_template( 'post-excerpt.php', $atts );
} else {
//call_user_func( $template['action'] );
sp_get_template( 'event-' . $key . '.php', $atts );
}
echo '</div>';
}
}
// After template hook
do_action( 'sportspress_after_single_' . $type );
$ob = ob_get_clean();
$tabs = '';
if ( ! empty( $tab_templates ) ) {
$i = 0;
$tab_content = '';
foreach ( $tab_templates as $key => $template ) {
// Ignore templates that are unavailable or that have been turned off
if ( ! is_array( $template ) ) continue;
if ( ! isset( $template['option'] ) ) continue;
if ( 'yes' !== get_option( $template['option'], sp_array_value( $template, 'default', 'yes' ) ) ) continue;
// Put tab content into buffer
ob_start();
if ( 'content' === $key ) {
echo $content;
// Template content hook
do_action( 'sportspress_single_' . $type . '_content' );
} elseif ( 'excerpt' === $key ) {
sp_get_template( 'post-excerpt.php', $atts );
} else {
//call_user_func( $template['action'] );
sp_get_template( 'event-' . $key . '.php', $atts );
}
$buffer = ob_get_clean();
// Trim whitespace from buffer
$buffer = trim( $buffer );
// Continue if tab content is empty
if ( empty( $buffer ) ) continue;
// Get template label
$label = sp_array_value( $template, 'label', $template['title'] );
// Add to tabs
$tabs .= '<li class="sp-tab-menu-item' . ( 0 === $i ? ' sp-tab-menu-item-active' : '' ) . '"><a href="#sp-tab-content-' . $key . '" data-sp-tab="' . $key . '">' . apply_filters( 'gettext', $label, $label, 'sportspress' ) . '</a></li>';
// Render the template
$tab_content .= '<div class="sp-tab-content sp-tab-content-' . $key . '" id="sp-tab-content-' . $key . '"' . ( 0 === $i ? ' style="display: block;"' : '' ) . '>' . $buffer . '</div>';
$i++;
}
$ob .= '<div class="sp-tab-group">';
if ( ! empty( $tabs ) ) {
$ob .= '<ul class="sp-tab-menu">' . $tabs . '</ul>';
}
$ob .= $tab_content;
$ob .= '</div>';
}
echo $ob;
}
}

View File

@@ -9,7 +9,9 @@
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
$id = get_the_ID();
if ( ! isset( $id ) )
$id = get_the_ID();
$post = get_post( $id );
$excerpt = $post->post_excerpt;
if ( $excerpt ) {