Skip to content

Commit

Permalink
Add Visitor Conversion support to Event List widget & shortcode.
Browse files Browse the repository at this point in the history
This commit makes sure that time tags output inside the sc_get_events_list() function are manipulated by the JavaScript that is used to flip the output.

It does this by targeting some additional time tags, and finally putting the "sugar_calendar_get_time_tag()" function to good use.

Note that "All Day" events do not have time tags and are unaffected by this change.

See #144.
  • Loading branch information
JJJ committed Dec 17, 2020
1 parent 95a37e8 commit 134fbb8
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 21 deletions.
23 changes: 15 additions & 8 deletions sugar-calendar/includes/common/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ function sugar_calendar_get_time_tag( $args = array() ) {
$r = wp_parse_args( $args, array(
'time' => null,
'timezone' => null,
'format' => 'Y-m-d H:i:s',
'dtformat' => 'Y-m-d\TH:i:s',
'format' => null,
'dtformat' => DATE_ISO8601,
'data' => $ddata,
'attr' => $dattr
) );
Expand All @@ -223,14 +223,17 @@ function sugar_calendar_get_time_tag( $args = array() ) {
? $r['timezone']
: 'floating';

// Non-floating
// Get the DateTime object
$dto = sugar_calendar_get_datetime_object( $r['time'] );

// Non-floating so set time zone and get the offset
if ( ! empty( $r['timezone'] ) && ( 'floating' !== $r['timezone'] ) ) {

// Maybe set the time zone
$dto = sugar_calendar_set_datetime_timezone( $dto, $r['timezone'] );

// Add the offset
$r['data']['offset'] = sugar_calendar_get_timezone_offset( array(
'time' => $r['time'],
'timezone' => $r['timezone']
) );
$r['data']['offset'] = $dto->getOffset();
}

// Format the time
Expand All @@ -239,6 +242,7 @@ function sugar_calendar_get_time_tag( $args = array() ) {

// Default attribute string
$r['attr']['datetime'] = esc_attr( $dtf );
$r['attr']['title'] = esc_attr( $dtf );

// Default array
$arr = $r['attr'];
Expand All @@ -250,11 +254,14 @@ function sugar_calendar_get_time_tag( $args = array() ) {
}
}

// Default attribute string
$attr = '';

// Concatenate HTML tag attributes
if ( ! empty( $arr ) ) {

// Remove empties and duplicates
$arr = array_unique( array_filter( $arr ) );
$arr = array_filter( $arr );

// Build
foreach ( $arr as $key => $value ) {
Expand Down
7 changes: 6 additions & 1 deletion sugar-calendar/includes/common/time-zones.php
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,12 @@ function sugar_calendar_get_timezone_object( $timezone = '' ) {
return $timezone;
}

// Bail if time zone is floating
// Bail if time zone param is floating
if ( 'floating' === strtolower( $timezone ) ) {
return false;
}

// Bail if time zone environment is floating
if ( sugar_calendar_is_timezone_floating() ) {
return false;
}
Expand Down
16 changes: 8 additions & 8 deletions sugar-calendar/includes/languages/sugar-calendar.pot
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Sugar Calendar (Lite) 2.1.2\n"
"Report-Msgid-Bugs-To: https://sugarcalendar.com\n"
"POT-Creation-Date: 2020-12-17 03:35:36+00:00\n"
"POT-Creation-Date: 2020-12-17 16:48:22+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down Expand Up @@ -880,7 +880,7 @@ msgstr ""
#: sugar-calendar/includes/admin/list-tables/class-wp-list-table-week.php:210
#: sugar-calendar/includes/admin/meta-boxes.php:1039
#: sugar-calendar/includes/themes/legacy/event-display.php:145
#: sugar-calendar/includes/themes/legacy/events-list.php:135
#: sugar-calendar/includes/themes/legacy/events-list.php:144
msgid "All-day"
msgstr ""

Expand Down Expand Up @@ -1133,7 +1133,7 @@ msgstr ""

#: sugar-calendar/includes/admin/screen-options.php:247
#: sugar-calendar/includes/common/time-zones.php:274
#: sugar-calendar/includes/common/time-zones.php:804
#: sugar-calendar/includes/common/time-zones.php:809
msgid "Floating"
msgstr ""

Expand Down Expand Up @@ -1320,16 +1320,16 @@ msgid_plural "%s hours"
msgstr[0] ""
msgstr[1] ""

#: sugar-calendar/includes/common/time-zones.php:880
#: sugar-calendar/includes/common/time-zones.php:885
msgid "Default"
msgstr ""

#: sugar-calendar/includes/common/time-zones.php:887
#: sugar-calendar/includes/common/time-zones.php:888
#: sugar-calendar/includes/common/time-zones.php:892
#: sugar-calendar/includes/common/time-zones.php:893
msgid "UTC"
msgstr ""

#: sugar-calendar/includes/common/time-zones.php:937
#: sugar-calendar/includes/common/time-zones.php:942
msgid "Manual Offsets"
msgstr ""

Expand Down Expand Up @@ -1585,7 +1585,7 @@ msgstr ""
msgid "Location:"
msgstr ""

#: sugar-calendar/includes/themes/legacy/events-list.php:154
#: sugar-calendar/includes/themes/legacy/events-list.php:187
msgid "Read More"
msgstr ""

Expand Down
39 changes: 36 additions & 3 deletions sugar-calendar/includes/themes/legacy/events-list.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,52 @@ function sc_get_events_list( $display = 'upcoming', $category = null, $number =
echo '<span class="sc_event_title">' . get_the_title( $event_id ) . '</span></a>';

if ( ! empty( $show['date'] ) ) {
echo '<span class="sc_event_date">' . sc_get_formatted_date( $event_id ) . '</span>';
$date_tag = sugar_calendar_get_time_tag( array(
'time' => $event->start,
'timezone' => $event->start_tz,
'format' => sc_get_date_format(),
'dtformat' => 'Y-m-dO'
) );

echo '<span class="sc_event_date">' . $date_tag . '</span>';
}

if ( isset( $show['time'] ) && $show['time'] ) {
$start_time = sc_get_event_start_time( $event_id );
$end_time = sc_get_event_end_time( $event_id );
$tf = sc_get_time_format();

// Output all day
if ( $event->is_all_day() ) {
echo '<span class="sc_event_time">' . esc_html__( 'All-day', 'sugar-calendar' ) . '</span>';

// Output both
} elseif ( $end_time !== $start_time ) {
echo '<span class="sc_event_time">' . esc_html( $start_time ) . '&nbsp;&ndash;&nbsp;' . esc_html( $end_time ) . '</span>';

$start_tag = sugar_calendar_get_time_tag( array(
'time' => $event->start,
'timezone' => $event->start_tz,
'format' => $tf
) );

$end_tag = sugar_calendar_get_time_tag( array(
'time' => $event->end,
'timezone' => $event->end_tz,
'format' => $tf
) );

echo '<span class="sc_event_time">' . $start_tag . '&nbsp;&ndash;&nbsp;' . $end_tag . '</span>';

// Output only start
} elseif ( ! empty( $start_time ) ) {
echo '<span class="sc_event_time">' . esc_html( $start_time ) . '</span>';

$start_tag = sugar_calendar_get_time_tag( array(
'time' => $event->start,
'timezone' => $event->start_tz,
'format' => $tf
) );

echo '<span class="sc_event_time">' . $start_tag . '</span>';
}
}

Expand Down
2 changes: 1 addition & 1 deletion sugar-calendar/includes/themes/legacy/js/sc-time-zones.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ jQuery( document ).ready( function( $ ) {

// Get elements and browser time zone
var dates = $( '.sc-date-start time, .sc-date-end time' ),
times = $( '.sc_event_start_time time, .sc_event_end_time time' ),
times = $( '.sc_event_time time, .sc_event_start_time time, .sc_event_end_time time' ),
tz = Intl.DateTimeFormat().resolvedOptions().timeZone,
convert = wp.date.dateI18n;

Expand Down

0 comments on commit 134fbb8

Please sign in to comment.