Skip to content

Commit

Permalink
Additional template reconstruction.
Browse files Browse the repository at this point in the history
  • Loading branch information
joedolson committed Oct 25, 2023
1 parent 1569059 commit 16ad3e0
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 18 deletions.
13 changes: 13 additions & 0 deletions src/mc-templates/event/card-title.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/**
* Template: Single Event, List view.
*
* @category Templates
* @package My Calendar
* @author Joe Dolson
* @license GPLv2 or later
* @link https://www.joedolson.com/my-calendar/
*/

?>
<?php mc_template_tag( $data, 'title' ); ?>
14 changes: 14 additions & 0 deletions src/mc-templates/event/grid-title.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
* Template: Single Event, Grid view.
*
* @category Templates
* @package My Calendar
* @author Joe Dolson
* @license GPLv2 or later
* @link https://www.joedolson.com/my-calendar/
*/

?>
<?php mc_template_tag( $data, 'title' ); ?>

14 changes: 14 additions & 0 deletions src/mc-templates/event/list-title.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
* Template: Single Event, List view.
*
* @category Templates
* @package My Calendar
* @author Joe Dolson
* @license GPLv2 or later
* @link https://www.joedolson.com/my-calendar/
*/

?>
<?php mc_template_tag( $data, 'title' ); ?>

14 changes: 14 additions & 0 deletions src/mc-templates/event/mini-title.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
* Template: Single Event, Mini view.
*
* @category Templates
* @package My Calendar
* @author Joe Dolson
* @license GPLv2 or later
* @link https://www.joedolson.com/my-calendar/
*/

?>
<?php mc_template_tag( $data, 'title' ); ?>

18 changes: 18 additions & 0 deletions src/mc-templates/event/single-title.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* Template: Single Event, Single view.
*
* @category Templates
* @package My Calendar
* @author Joe Dolson
* @license GPLv2 or later
* @link https://www.joedolson.com/my-calendar/
*/

/**
* Event templates access any template tags using the function `mc_template_tag`. The object $event is available in all templates.
*/
?>
<?php mc_template_tag( $data, 'title' ); ?>


56 changes: 43 additions & 13 deletions src/my-calendar-output.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,13 @@ function my_calendar_draw_event( $event, $type, $process_date, $time, $template
'tags' => $tags,
);
$type = ( 'calendar' === $type ) ? 'grid' : $type;
$header = mc_load_template( 'event/' . $type . '-' . 'title', $data );
$body = mc_load_template( 'event/' . $type, $data );
if ( $header || $body ) {
$details = $header . $body;
}
$details = mc_load_template( 'event/' . $type, $data );
// If loading a template produces no results, then use legacy event templating.
if ( ! $details ) {
$details = mc_legacy_template_draw_event( $event, $type, $process_date, $time, $template, $id, $tags );
}
$details = apply_filters( 'mc_event_details_output', $details, $event );
$header = mc_draw_event_header( $data, $type, $template );
$details = $header . apply_filters( 'mc_event_details_output', $details, $event );
/**
* Runs right after a calendar event template is run.
*
Expand All @@ -260,21 +257,52 @@ function my_calendar_draw_event( $event, $type, $process_date, $time, $template
return $details;
}

/**
* Generate the container ID for an event.
*
* @param string $type Type of view.
* @param string $process_date Date in view.
* @param object $event My Calendar event.
*
* @return string
*/
function mc_event_container_id( $type, $process_date, $event ) {
$day_id = mc_date( 'd', strtotime( $process_date ), false );
$uid = 'mc_' . $type . '_' . $day_id . '_' . $event->occur_id;
$id = $event->occur_id;

return "$uid-$type-details-$id";
}

/**
* Draw the header for a My Calendar event.
*
* @param array $data Array of event object, process date, id, tags, and time viewed.
* @param string $type View type.
* @param string $template Template value.
*
* @return string
*/
function mc_draw_event_header( $event, $type, $process_date, $time, $template, $id, $tags, $image ) {
function mc_draw_event_header( $data, $type, $template ) {
$event = $data['event'];
$tags = $data['tags'];
$id = $data['id'];
$process_date = $data['process_date'];
$time = $data['time'];
$open_uri = mc_get_option( 'open_uri' );
$image = mc_category_icon( $event );
$image = ( $image ) ? $image . ' ' : '';
$has_image = ( '' !== $image ) ? ' has-image' : '';
$event_classes = mc_event_classes( $event, $type );
$nofollow = ( stripos( $event_classes, 'past-event' ) !== false ) ? 'rel="nofollow"' : '';
$day_id = mc_date( 'd', strtotime( $process_date ), false );
$uid = 'mc_' . $type . '_' . $day_id . '_' . $event->occur_id;
$header = "\n\n <div id='$uid-$type-$id' class='$event_classes'>\n";
$container_id = mc_event_container_id( $type, $process_date, $event );
$parent_id = str_replace( 'details-', '', $container_id );
$header = "\n\n <div id='$parent_id' class='$event_classes'>\n";

$event_title = mc_draw_event_title( $event, $tags, $type, $image );
$event_title = mc_load_template( 'event/' . $type . '-' . 'title', $data );
if ( ! $event_title ) {
$event_title = mc_draw_event_title( $event, $tags, $type, $image );
}
/**
* Disable links on grid view.
*
Expand All @@ -298,13 +326,13 @@ function mc_draw_event_header( $event, $type, $process_date, $time, $template, $
$single_template = ( mc_get_template( 'title_solo' ) === '' ) ? '{title}' : mc_get_template( 'title_solo' );
$event_title_single = mc_draw_template( $tags, $single_template );
if ( ( 'modal' === $gridtype && 'calendar' === $type ) || ( 'modal' === $listtype && 'list' === $type ) ) {
$params = "id='modal-button-$uid-$type-details-$id' data-modal-content-id='$uid-$type-details-$id' data-modal-prefix-class='my-calendar' data-modal-close-text='" . esc_attr( __( 'Close', 'my-calendar' ) ) . "' data-modal-title='" . esc_attr( $event_title_single ) . "'";
$params = "id='modal-button-$container_id' data-modal-content-id='$container_id' data-modal-prefix-class='my-calendar' data-modal-close-text='" . esc_attr( __( 'Close', 'my-calendar' ) ) . "' data-modal-title='" . esc_attr( $event_title_single ) . "'";
$classes = 'js-modal button button-link';
} else {
$params = " aria-expanded='false'";
$classes = 'open';
}
$wrap = "<a href='#$uid-$type-details-$id' $params aria-controls='$uid-$type-details-$id' class='$type $classes et_smooth_scroll_disabled opl-link url summary$has_image'><span>";
$wrap = "<a href='#$container_id' $params aria-controls='$container_id' class='$type $classes et_smooth_scroll_disabled opl-link url summary$has_image'><span>";
$balance = '</span></a>';
}
} else {
Expand Down Expand Up @@ -350,6 +378,8 @@ function mc_draw_event_header( $event, $type, $process_date, $time, $template, $
if ( 'card' !== $type ) {
$header .= ( false === stripos( $title, 'summary' ) ) ? ' <span class="summary screen-reader-text">' . strip_tags( $event_title ) . '</span>' : $title;
}

return $header;
}

/**
Expand Down
16 changes: 11 additions & 5 deletions src/templates/legacy-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,20 @@ function mc_legacy_template_draw_event( $event, $type, $process_date, $time, $te
$display_link = ( $no_old_options ) ? get_option( 'mc_event_link' ) : '';
$display_image = ( $no_old_options ) ? get_option( 'mc_image' ) : '';
$display_reg = ( $no_old_options ) ? get_option( 'mc_event_registration' ) : '';
$day_id = mc_date( 'd', strtotime( $process_date ), false );
$uid = 'mc_' . $type . '_' . $day_id . '_' . $event->occur_id;
$image = mc_category_icon( $event );
$image = ( $image ) ? $image . ' ' : '';
$img = '';
$container_id = mc_event_container_id( $type, $process_date, $event );

$header = mc_draw_event_header( $event, $type, $process_date, $time, $template, $id, $data, $image );
$close_button = mc_close_button( "$uid-$type-details-$id" );
$data = array(
'event' => $event,
'process_date' => $process_date,
'time' => $time,
'id' => $id,
'tags' => $tags,
);
$header = mc_draw_event_header( $data, $type, $template );
$close_button = mc_close_button( $container_id );
$close = '';
if ( mc_show_details( $time, $type ) ) {
// Since 3.2.0, close button is added to event container in mini calendar.
Expand Down Expand Up @@ -354,7 +360,7 @@ function mc_legacy_template_draw_event( $event, $type, $process_date, $time, $te
if ( 'list' === $type || 'calendar' === $type ) {
$img_class .= ' single-details';
}
$container = "\n <div id='$uid-$type-details-$id' class='details$img_class' aria-labelledby='mc_$event->occur_id-title" . '-' . $id . "'>\n";
$container = "\n <div id='$container_id' class='details$img_class' aria-labelledby='mc_$event->occur_id-title" . '-' . $id . "'>\n";
/**
* Filter details before the event content..
*
Expand Down

0 comments on commit 16ad3e0

Please sign in to comment.