From c37705024da3f9419dd5d4cc040c4d6ba7107ff9 Mon Sep 17 00:00:00 2001 From: savvasha Date: Fri, 31 Aug 2018 18:53:55 +0300 Subject: [PATCH] Add a "Full Info" event shortcode. It supports template order! --- assets/js/admin/editor-lang.php | 3 +- .../class-sp-meta-box-event-shortcode.php | 1 + includes/class-sp-ajax.php | 30 ++++ includes/class-sp-shortcodes.php | 12 ++ .../class-sp-shortcode-event-full.php | 139 ++++++++++++++++++ templates/post-excerpt.php | 4 +- 6 files changed, 187 insertions(+), 2 deletions(-) create mode 100644 includes/shortcodes/class-sp-shortcode-event-full.php diff --git a/assets/js/admin/editor-lang.php b/assets/js/admin/editor-lang.php index ee8c313f..0e0e00ca 100644 --- a/assets/js/admin/editor-lang.php +++ b/assets/js/admin/editor-lang.php @@ -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' ), diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-shortcode.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-shortcode.php index 787dc1b3..a1945b88 100644 --- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-shortcode.php +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-shortcode.php @@ -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 ) { ?> diff --git a/includes/class-sp-ajax.php b/includes/class-sp-ajax.php index 985d351a..36a17dd5 100644 --- a/includes/class-sp-ajax.php +++ b/includes/class-sp-ajax.php @@ -274,6 +274,36 @@ class SP_AJAX { self::scripts(); die(); } + + /** + * AJAX event_full shortcode + */ + public function event_full_shortcode() { + ?> +
+

+ +

+ +

+ + +

+
+ __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', @@ -137,6 +138,17 @@ class SP_Shortcodes { public static function event_teams( $atts ) { 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. diff --git a/includes/shortcodes/class-sp-shortcode-event-full.php b/includes/shortcodes/class-sp-shortcode-event-full.php new file mode 100644 index 00000000..7b69db03 --- /dev/null +++ b/includes/shortcodes/class-sp-shortcode-event-full.php @@ -0,0 +1,139 @@ +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 '
'; + 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 '
'; + } + } + + // 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 .= '
  • ' . apply_filters( 'gettext', $label, $label, 'sportspress' ) . '
  • '; + + // Render the template + $tab_content .= '
    ' . $buffer . '
    '; + + $i++; + } + + $ob .= '
    '; + + if ( ! empty( $tabs ) ) { + $ob .= ''; + } + + $ob .= $tab_content; + + $ob .= '
    '; + } + + echo $ob; + + } +} diff --git a/templates/post-excerpt.php b/templates/post-excerpt.php index 4fbac099..06c4b415 100644 --- a/templates/post-excerpt.php +++ b/templates/post-excerpt.php @@ -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 ) {