Skip to content

Commit

Permalink
deploy: 540e3a0
Browse files Browse the repository at this point in the history
  • Loading branch information
joedolson committed Nov 6, 2023
1 parent bf83b55 commit 2ef07b2
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 90 deletions.
2 changes: 1 addition & 1 deletion mc_after_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="my-calendar-settings.php.html">my-calendar-settings.php</a>, <a href="my-calendar-settings.php.html#line2002">line 2002</a>
<a href="my-calendar-settings.php.html">my-calendar-settings.php</a>, <a href="my-calendar-settings.php.html#line1953">line 1953</a>
</li></ul></dd>


Expand Down
2 changes: 1 addition & 1 deletion mc_custom_sidebar_panels.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="my-calendar.php.html">my-calendar.php</a>, <a href="my-calendar.php.html#line303">line 303</a>
<a href="my-calendar.php.html">my-calendar.php</a>, <a href="my-calendar.php.html#line305">line 305</a>
</li></ul></dd>


Expand Down
2 changes: 1 addition & 1 deletion mc_format_tribe_event_for_import.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="my-calendar-import.php.html">my-calendar-import.php</a>, <a href="my-calendar-import.php.html#line176">line 176</a>
<a href="my-calendar-import.php.html">my-calendar-import.php</a>, <a href="my-calendar-import.php.html#line233">line 233</a>
</li></ul></dd>


Expand Down
2 changes: 1 addition & 1 deletion mc_imported_event.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="my-calendar-import.php.html">my-calendar-import.php</a>, <a href="my-calendar-import.php.html#line89">line 89</a>
<a href="my-calendar-import.php.html">my-calendar-import.php</a>, <a href="my-calendar-import.php.html#line142">line 142</a>
</li></ul></dd>


Expand Down
2 changes: 1 addition & 1 deletion mcs_submission_permissions.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="my-calendar.php.html">my-calendar.php</a>, <a href="my-calendar.php.html#line449">line 449</a>
<a href="my-calendar.php.html">my-calendar.php</a>, <a href="my-calendar.php.html#line469">line 469</a>
</li></ul></dd>


Expand Down
127 changes: 92 additions & 35 deletions my-calendar-import.php.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,47 +55,100 @@
}

/**
* Import Tribe Events.
* Display current progress in importing.
*
* @return int Number of events imported.
* @return string
*/
function mc_import_source_tribe_events() {
$count = wp_count_posts( 'tribe_events' );
$total = 0;
foreach ( $count as $c ) {
$total = $total + (int) $c;
function mc_display_progress() {
$message = '';
if ( as_has_scheduled_action( 'mc_import_tribe' ) ) {
$count = mc_count_tribe_remaining();
$message = sprintf( __( 'Import from The Events Calendar is in progress. There are currently %d events remaining.', 'my-calendar' ), $count );
}
if ( $total &lt; 50 ) {
$num_posts = -1;
} else {
$num_posts = 25;
}
// Get all events not already imported.

return ( $message ) ? '&lt;div class="notice notice-info">&lt;p>' . $message . '&lt;/p>&lt;/div>' : '';
}

/**
* Count remaining events from Tribe Events Calendar.
*
* @return int
*/
function mc_count_tribe_remaining() {
$args = array(
'post_type' => 'tribe_events',
'numberposts' => $num_posts,
'numberposts' => -1,
'fields' => 'ids',
'post_status' => 'any',
'meta_query' => array(
'queries' => array(
array(
'key' => '_mc_imported',
'compare' => 'NOT EXISTS',
),
),
);
$events = get_posts( $args );
if ( 0 === count( $events ) ) {
as_unschedule_all_actions( 'mc_import_tribe' );
}

return count( $events );
}

/**
* Import Tribe Events.
*
* @return string Message about imported events.
*/
function mc_import_source_tribe_events() {
global $wpdb;
$count = wp_count_posts( 'tribe_events' );
$message = '';
$total = 0;
foreach ( $count as $c ) {
$total = $total + (int) $c;
}
if ( $total &lt; 50 ) {
$num_posts = -1;
} else {
$num_posts = 25;
}
// Get selection of events not already imported.
$query = "SELECT SQL_CALC_FOUND_ROWS $wpdb->posts.ID FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id AND $wpdb->postmeta.meta_key = '_mc_imported' ) WHERE 1=1 AND ( $wpdb->postmeta.post_id IS NULL ) AND $wpdb->posts.post_type = 'tribe_events' AND (($wpdb->posts.post_status &lt;> 'trash' AND $wpdb->posts.post_status &lt;> 'auto-draft')) GROUP BY wp_posts.ID ORDER BY $wpdb->posts.post_date DESC LIMIT 0, $num_posts";
$events = $wpdb->get_results( $query );
print_r( $events );

$ids = array();
foreach ( $events as $post_id ) {
$id = mc_import_source_tribe_event( $post_id );
if ( $id ) {
$ids[] = $id;
$count = count( $events );
if ( 0 === $count ) {
update_option( 'mc_import_tribe_completed', 'true' );
} else {
foreach ( $events as $post ) {
$id = mc_import_source_tribe_event( $post->ID );
if ( $id ) {
$ids[] = $id;
}
}

$completed = count( $ids );
if ( false === as_has_scheduled_action( 'mc_import_tribe' ) ) {
as_schedule_recurring_action( strtotime( '+1 minutes' ), 60, 'mc_import_tribe', array(), 'my-calendar' );
}
// translators: 1) Number of events imported, 2) total number of events found.
$message = '&lt;div class="notice notice-info">&lt;p>' . sprintf( __( '%1$d events imported. %2$d remaining. Remaining events are being imported in the background. You can feel free to leave this page.', 'my-calendar' ), $completed, $total ) . '&lt;/p>&lt;/div>';
}
$completed = count( $ids );
// translators: 1) Number of events imported, 2) total number of events found.
echo '&lt;div class="notice notice-success">&lt;p>' . sprintf( __( '%1$d events imported. %2$d remaining. Remaining events are being imported in the background. You can feel free to leave this page.', 'my-calendar' ), $completed, $total ) . '&lt;/p>&lt;/div>';

return $completed;
return $message;
}
add_action( 'mc_import_tribe', 'mc_import_source_tribe_events' );

/**
*
*/
function mc_check_tribe_imports() {
if ( 'true' === get_option( 'mc_import_tribe_completed' ) ) {
as_unschedule_all_actions( 'mc_import_tribe' );
}
}

/**
Expand All @@ -106,10 +159,10 @@
* @return bool|int False of new post ID.
*/
function mc_import_source_tribe_event( $post_id ) {
// If already imported, return the new event ID.
// If already imported, return false.
$imported = get_post_meta( $post_id, '_mc_imported', true );
if ( $imported ) {
return $imported;
return false;
}
$tribe_event = get_post( $post_id );
/**
Expand All @@ -132,6 +185,7 @@
if ( $check[0] ) {
$response = my_calendar_save( 'add', $check );
$event_id = $response['event_id'];
update_post_meta( $post_id, '_mc_imported', $event_id );
}

return $event_id;
Expand All @@ -146,18 +200,21 @@
*/
function mc_format_tribe_event_for_import( $event ) {
$terms = get_the_terms( $event, 'tribe_events_cat' );
foreach ( $terms as $term ) {
$cat_id = mc_category_by_name( $term->name );
if ( ! $cat_id ) {
$cat = array(
'category_name' => $term->name,
);
$cat_id = mc_create_category( $cat );
if ( is_array( $terms ) ) {
foreach ( $terms as $term ) {
$cat_id = mc_category_by_name( $term->name );
if ( ! $cat_id ) {
$cat = array(
'category_name' => $term->name,
);
$cat_id = mc_create_category( $cat );
}
// if category does not exist, create.
$category_ids[] = $cat_id;
}
// if category does not exist, create.
$category_ids[] = $cat_id;
} else {
$category_ids[] = 1;
}

$my_calendar_event = array(
// Event data.
'event_title' => $event->post_title,
Expand Down
51 changes: 1 addition & 50 deletions my-calendar-settings.php.html
Original file line number Diff line number Diff line change
Expand Up @@ -705,56 +705,7 @@
?>
&lt;/div>
&lt;div class="settings postbox-container jcd-wide">
&lt;div class="metabox-holder">
&lt;?php
if ( isset( $_POST['import'] ) &amp;&amp; 'true' === $_POST['import'] ) {
$nonce = $_REQUEST['_wpnonce'];
if ( ! wp_verify_nonce( $nonce, 'my-calendar-nonce' ) ) {
wp_die( 'My Calendar: Security check failed' );
}
$source = ( in_array( $_POST['source'], array( 'calendar', 'tribe' ), true ) ) ? $_POST['source'] : false;
if ( $source ) {
my_calendar_import( $source );
}
}
if ( function_exists( 'check_calendar' ) &amp;&amp; 'true' !== get_option( 'ko_calendar_imported' ) ) {
?>
&lt;div id="mc-importer" class='notice notice-info'>
&lt;p>
&lt;?php _e( 'You have the Calendar plugin by Kieran O\'Shea installed. You can import those events and categories into My Calendar.', 'my-calendar' ); ?>
&lt;/p>

&lt;form method="post" action="&lt;?php echo esc_url( admin_url( 'admin.php?page=my-calendar-config' ) ); ?>">
&lt;div>
&lt;input type="hidden" name="_wpnonce" value="&lt;?php echo wp_create_nonce( 'my-calendar-nonce' ); ?>"/>
&lt;input type="hidden" name="import" value="true" />
&lt;input type="hidden" name="source" value="calendar" />
&lt;input type="submit" value="&lt;?php _e( 'Import from Calendar', 'my-calendar' ); ?>" name="import-calendar" class="button-primary"/>
&lt;/div>
&lt;/form>
&lt;/div>
&lt;?php
}
delete_option( 'mc_tribe_imported' );
if ( function_exists( 'tribe_get_event' ) &amp;&amp; 'true' !== get_option( 'mc_tribe_imported' ) ) {
?>
&lt;div id="mc-importer" class='notice notice-info'>
&lt;p>
&lt;?php _e( 'You have The Events Calendar installed. You can import those events, venues, and categories into My Calendar.', 'my-calendar' ); ?>
&lt;/p>

&lt;form method="post" action="&lt;?php echo esc_url( admin_url( 'admin.php?page=my-calendar-config' ) ); ?>">
&lt;div>
&lt;input type="hidden" name="_wpnonce" value="&lt;?php echo wp_create_nonce( 'my-calendar-nonce' ); ?>"/>
&lt;input type="hidden" name="import" value="true" />
&lt;input type="hidden" name="source" value="tribe" />
&lt;input type="submit" value="&lt;?php _e( 'Import Events', 'my-calendar' ); ?>" name="import-calendar" class="button-primary"/>
&lt;/div>
&lt;/form>
&lt;/div>
&lt;?php
}
?>
&lt;div class="metabox-holder">
&lt;div class="ui-sortable meta-box-sortables">
&lt;div class="wptab postbox" aria-labelledby="tab_manage" role="tabpanel" id="my-calendar-manage">
&lt;h2>&lt;?php esc_html_e( 'My Calendar Management', 'my-calendar' ); ?>&lt;/h2>
Expand Down
20 changes: 20 additions & 0 deletions my-calendar.php.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
}
}

include( dirname( __FILE__ ) . '/action-scheduler/action-scheduler.php' );
include( dirname( __FILE__ ) . '/includes/date-utilities.php' );
include( dirname( __FILE__ ) . '/includes/general-utilities.php' );
include( dirname( __FILE__ ) . '/includes/event-utilities.php' );
Expand All @@ -177,6 +178,7 @@
include( dirname( __FILE__ ) . '/my-calendar-core.php' );
include( dirname( __FILE__ ) . '/my-calendar-install.php' );
include( dirname( __FILE__ ) . '/my-calendar-settings.php' );
include( dirname( __FILE__ ) . '/my-calendar-migrate.php' );
include( dirname( __FILE__ ) . '/my-calendar-categories.php' );
include( dirname( __FILE__ ) . '/my-calendar-locations.php' );
include( dirname( __FILE__ ) . '/my-calendar-location-manager.php' );
Expand Down Expand Up @@ -413,6 +415,21 @@
}
}

/**
* Test whether a system is present that My Calendar supports migration from.
*
* @return bool
*/
function mc_has_migration_path() {
if ( function_exists( 'check_calendar' ) &amp;&amp; 'true' !== get_option( 'ko_calendar_imported' ) ) {
return true;
}
if ( function_exists( 'tribe_get_event' ) &amp;&amp; 'true' !== get_option( 'mc_tribe_imported' ) ) {
return true;
}
return false;
}

/**
* Add My Calendar menu items to main admin menu
*/
Expand Down Expand Up @@ -465,6 +482,9 @@
}
add_submenu_page( 'my-calendar', __( 'Design', 'my-calendar' ), __( 'Design', 'my-calendar' ), $permission, 'my-calendar-design', 'my_calendar_design' );
add_submenu_page( 'my-calendar', __( 'Settings', 'my-calendar' ), __( 'Settings', 'my-calendar' ), 'mc_edit_settings', 'my-calendar-config', 'my_calendar_settings' );
if ( mc_has_migration_path() ) {
add_submenu_page( 'my-calendar', __( 'Migration', 'my-calendar' ), __( 'Migration', 'my-calendar' ), 'mc_edit_settings', 'my-calendar-migrate', 'my_calendar_migration' );
}
add_submenu_page( 'my-calendar', __( 'My Calendar Shortcode Generator', 'my-calendar' ), __( 'Shortcodes', 'my-calendar' ), 'mc_view_help', 'my-calendar-shortcodes', 'my_calendar_shortcodes' );
add_submenu_page( 'my-calendar', __( 'My Calendar Help', 'my-calendar' ), __( 'Help', 'my-calendar' ), 'mc_view_help', 'my-calendar-help', 'my_calendar_help' );
// Null submenu parent prevents this from appearing in the admin menu.
Expand Down

0 comments on commit 2ef07b2

Please sign in to comment.