Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions admin/pages/class-settings-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,28 +133,36 @@ private function get_fields() {
'general' => array(
'title' => null,
'fields' => array(
'general-main-country' => array(
'general-main-country' => array(
'title' => __( 'Default Country', 'calendar-plus' ),
'args' => $settings['country'],
),
'general-main-display-country' => array(
'general-main-display-country' => array(
'title' => __( 'Display country in locations address', 'calendar-plus' ),
'args' => $settings['display_location_country'],
'sanitize' => 'isset',
),
'general-main-time-format' => array(
'general-main-time-format' => array(
'title' => __( 'Time format selector', 'calendar-plus' ),
'args' => $settings['time_format'],
),
'general-main-events-page' => array(
'general-main-events-page' => array(
'title' => __( 'Events Page', 'calendar-plus' ),
'args' => absint( $settings['events_page_id'] ),
'sanitize' => 'absint',
),
'general-main-replace-sidebar' => array(
'general-main-replace-sidebar' => array(
'title' => __( 'Replace Calendar Plus sidebar for', 'calendar-plus' ),
'args' => $settings['replace_sidebar'],
),
'general-main-update-rss-imported-events' => array(
'title' => __( 'Keep RSS imported events updated', 'calendar-plus' ),
'args' => $settings['update_rss_imported_events'],
),
'general-main-update-ical-imported-events' => array(
'title' => __( 'Keep iCal imported events updated', 'calendar-plus' ),
'args' => $settings['update_ical_imported_events'],
),
),
),
'gmaps' => array(
Expand Down
15 changes: 15 additions & 0 deletions admin/settings-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ function render_general_main_replace_sidebar_field( $replace_sidebar ) {

}

function render_general_main_update_rss_imported_events_field( $keep_updated ) {
?>
<input type="checkbox" name="<?php echo calendarp_get_settings_slug();?>[update_rss_imported_events]" <?php checked( '1', $keep_updated ); ?> value="1"/>
<?php
}

function render_general_main_update_ical_imported_events_field( $keep_updated ) {
if ( is_null( $keep_updated ) ) {
$keep_updated = '1';
}
?>
<input type="checkbox" name="<?php echo calendarp_get_settings_slug();?>[update_ical_imported_events]" <?php checked( '1', $keep_updated ); ?> value="1"/>
<?php
}

function render_media_event_thumbnail_field( $args ) {
?>

Expand Down
10 changes: 10 additions & 0 deletions includes/helpers/helpers-ical.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,16 @@ function calendarp_ical_sync_events() {
continue;
}

if ( $feed['type'] === 'rss') {
$update_events_setting = calendarp_get_setting( 'update_rss_imported_events' );
} else {
$update_events_setting = calendarp_get_setting( 'update_ical_imported_events' );
if ( false === $update_events_setting ) {
$update_events_setting = '1';
}
}
$feed['update_events'] = $update_events_setting === '1';

$syncer = new Calendar_Plus_iCal_Sync( $events, $feed );
$synced_events = $syncer->sync();

Expand Down
37 changes: 33 additions & 4 deletions includes/ical/class-calendar-plus-ical-sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ class Calendar_Plus_iCal_Sync {
*/
protected $default_status;

/**
* Update events or keep them original
* @var bool
*/
protected $update_events;

/**
* Parent feed url
* @var string
*/
protected $feed_url;

/**
* Calendar_Plus_iCal_Sync constructor.
*
Expand All @@ -41,14 +53,18 @@ public function __construct( $events, $args = [] ) {
$this->events = $events;

$args = wp_parse_args( $args, [
'author' => 0,
'category' => 0,
'status' => 'publish',
'author' => 0,
'category' => 0,
'status' => 'publish',
'update_events' => false,
'source' => '',
] );

$this->event_author = $args['author'] ? $args['author'] : get_current_user_id();
$this->event_category = $args['category'];
$this->default_status = $args['status'];
$this->update_events = $args['update_events'];
$this->feed_url = $args['source'];
}

/**
Expand Down Expand Up @@ -89,6 +105,8 @@ protected function sync_event( $event_data ) {
'categories' => [],
] );

$event_data_hash = md5( serialize( $event_data ) );

if ( 'publish' === $event_data['post_status'] ) {
$event_data['post_status'] = $this->default_status;
}
Expand All @@ -109,7 +127,14 @@ protected function sync_event( $event_data ) {
return $event->ID;
}

if ( ! $event_data['last_updated'] || $event_data['last_updated'] === $event->get_meta( 'ical_last_updated' ) ) {
update_post_meta( $event->ID, '_event_feed_url', $this->feed_url );

if ( ! $this->update_events ) {
return false;
}

$old_event_hash = $event->get_meta( 'ical_hash' );
if ( $old_event_hash === $event_data_hash ) {
return false;
}

Expand All @@ -128,6 +153,8 @@ protected function sync_event( $event_data ) {
}

$post_id = wp_insert_post( $post_args );

update_post_meta( $post_id, '_event_feed_url', $this->feed_url );
}

update_post_meta( $post_id, '_event_uid', $event_data['uid'] );
Expand Down Expand Up @@ -162,6 +189,8 @@ protected function sync_event( $event_data ) {
update_post_meta( $post_id, '_ical_last_updated', $event_data['last_updated'] );
}

update_post_meta( $post_id, '_ical_hash', $event_data_hash );

do_action('calendarp_ical_sync_update_insert', $post_id, $post_args, $event_data );

return $post_id;
Expand Down