From: Steve Sutton $events: ' . print_r( $events, true ) . '
';
+ }
+ if ( $events ) {
+ foreach ( $events as $event ) {
+ $contact = array();
+ $image = '';
+ $event['DESCRIPTION']
+ = str_replace( '\n', "
", $event['DESCRIPTION'] );
+ $intro = substr( strip_tags( $event['DESCRIPTION'] ), 0 ,150);
+ if ( isset( $event['CONTACT'] ) ) {
+ $contact_data = explode( ',', str_replace( '\\', '', $event['CONTACT'] ) );
+ if ( $debug ) {
+ //$out .= '$contact_data: ' . print_r( $contact_data, true ) . '
';
+ }
+ $contact = array(
+ 'name' => $contact_data[0],
+ 'email' => $contact_data[1],
+ 'phone' => $contact_data[2],
+ );
+ } else {
+ $contact = array(
+ 'name' => '',
+ 'email' => '',
+ 'phone' => '',
+ );
+ }
+ if ( isset( $event['ATTACH'] ) ) {
+ $img_url = preg_replace( '%FMTTYPE=image/(jpeg|gif|png)[:]%', '', $event['ATTACH'] );
+ if ( $img_url ) {
+ $res = $image_upload->storeImage( $img_url );
+ $image = $res['newFileName'];
+ }
+ }
+ $event_data = array(
+ 'status' => $this->config['status_numb']['Active'],
+ 'ref_type' => 10,
+ 'created' => $ical->iCalDateToUnixTimestamp( $event['CREATED'] ),
+ 'updated' => $ical->iCalDateToUnixTimestamp( $event['CREATED'] ),
+ 'approved' => null,
+ 'ical_uid' => $event['UID'],
+ 'name' => $event['SUMMARY'],
+ 'intro' => $intro,
+ 'descr' => $event['DESCRIPTION'],
+ 'image' => $image,
+ 'url' => ( isset( $event['URL'] ) ? $event['URL']: '' ),
+ 'contact_email' => $contact['name'],
+ 'contact_name' => $contact['email'],
+ 'contact_phone' => $contact['phone'],
+ );
+ if ( $debug ) {
+ //$out .= '$event_data: ' . print_r( $event_data, true ) . '
';
+ }
+ $event_data_format = array(
+ '%d',
+ '%d',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ );
+ // check for this event record first to see if it can be
+ // updated instead of insert
+ $event_id = $this->wpdb->get_var(
+ $this->wpdb->prepare(
+ "SELECT id
+ FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events
+ WHERE ical_uid = %s",
+ $event['UID']
+ )
+ );
+ if ( $event_id ) {
+ $this->wpdb->update(
+ GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'events',
+ $event_data,
+ array( 'id' => $event_id ),
+ $event_data_format,
+ '%d'
+ );
+ } else {
+ $this->wpdb->insert(
+ GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'events',
+ $event_data,
+ $event_data_format
+ );
+ $event_id = $this->wpdb->insert_id;
+ }
+ if ( !$event_id ) {
+ die('something is wrong no event_id');
+ }
+ // generate the slug name for this new event
+ $event_abstract = new GlmDataEvents( $this->wpdb, $this->config );
+ $event_abstract->updateSlug( $event_id );
+ // Location Data
+ if ( isset( $event['LOCATION'] ) ) {
+ $location_data = explode( ',', str_replace( '\\', '', $event['LOCATION'] ) );
+ $place = ( isset( $location_data[0] ) ? $location_data[0]: '');
+ $address = ( isset( $location_data[1] ) ? $location_data[1]: '');
+ $city = ( isset( $location_data[2] ) ? $location_data[2]: '');
+ $state = ( isset( $location_data[3] ) ? $location_data[3]: '');
+ $zip = ( isset( $location_data[4] ) ? $location_data[4]: '');
+ $location = array(
+ 'event' => $event_id,
+ 'name' => $place,
+ 'address' => $address,
+ 'city' => $this->getCityId( $city ),
+ 'state' => $state,
+ 'zip' => $zip,
+ );
+ $location_format = array(
+ '%d', '%s', '%s', '%d', '%s', '%s'
+ );
+ if ( isset( $event['GEO'] ) ) {
+ $geo_data = explode( ';', $event['GEO'] );
+ $location['lat'] = $geo_data[0];
+ $location['lon'] = $geo_data[1];
+ $location_format[] = '%s';
+ $location_format[] = '%s';
+ }
+ // Remove any old location data for this event_id.
+ $this->wpdb->delete(
+ GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'locations',
+ array( 'event' => $event_id ),
+ '%d'
+ );
+ $this->wpdb->insert(
+ GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'locations',
+ $location,
+ $location_format
+ );
+ }
+ // Remove any old recurrences data for this event_id.
+ $this->wpdb->delete(
+ GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'recurrences',
+ array( 'event' => $event_id ),
+ '%d'
+ );
+ // Remove any old times data for this event_id.
+ $this->wpdb->delete(
+ GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'times',
+ array( 'event' => $event_id ),
+ '%d'
+ );
+ $serialized_times = null;
+ $day_of_week =
+ $day_of_month =
+ $month_of_year =
+ $week_of_month =
+ $by_day_of_month =
+ $last_day_of_month = null;
+ $start_time_only =
+ $all_day =
+ $recurring_event = 0;
+ $day_of_week = 127;
+ $month_of_year = 4095;
+ $week_of_month = 63;
+ $starting = $ical->iCalDateToUnixTimestamp( $event['DTSTART'] );
+ $ending = $ical->iCalDateToUnixTimestamp( $event['DTEND'] );
+ $from_date = date( 'Y-m-d', $starting );
+ $to_date = date( 'Y-m-d', $ending );
+ $btime = date( 'H:i', $starting );
+ $etime = date( 'H:i', $ending );
+ $freq = $byday = $until = '';
+ if ( isset( $event['RRULE'] ) ) {
+ $recurring_event = 1;
+ $rrule_data = explode( ';', $event['RRULE'] );
+ //echo '$rrule_data: ' . print_r( $rrule_data, true ) . '
';
+ if ( $rrule_data ) {
+ foreach ( $rrule_data as $rule ) {
+ if ( preg_match( '%FREQ=(.*)%', $rule, $matches ) ) {
+ $freq = trim( $matches[1] );
+ }
+ if ( preg_match( '%BYDAY=(.*)%', $rule, $matches ) ) {
+ $byday = trim( $matches[1] );
+ }
+ if ( preg_match( '%UNTIL=(.*)%', $rule, $matches ) ) {
+ $until = trim( $matches[1] );
+ }
+ }
+ }
+ if ( $freq === 'WEEKLY' && $byday ) {
+ // separated by commas
+ $days = explode( ',',$byday );
+ //echo '$days: ' . print_r( $days, true ) . '
';
+ if ( $days ) {
+ $day_of_week = 0;
+ foreach ( $days as $day ) {
+ if ( preg_match( '%([0-9])?([A-Z]{2})%', $day, $d_matches ) ) {
+ //echo '$d_matches: ' . print_r( $d_matches, true ) . '
';
+ if ( $d_matches[1] ) {
+ $week_of_month = pow(2, $d_matches[1] );
+ }
+ switch ( $d_matches[2] ) {
+ case "SU":
+ $day_of_week += pow(2, 0);
+ break;
+ case "MO":
+ $day_of_week += pow(2, 1);
+ break;
+ case "TU":
+ $day_of_week += pow(2, 2);
+ break;
+ case "WE":
+ $day_of_week += pow(2, 3);
+ break;
+ case "TH":
+ $day_of_week += pow(2, 4);
+ break;
+ case "FR":
+ $day_of_week += pow(2, 5);
+ break;
+ case "SA":
+ $day_of_week += pow(2, 6);
+ break;
+ }
+ }
+ }
+ }
+ }
+ if ( $until != '' ) {
+ //echo '$until: ' . print_r( $until, true ) . '
';
+ $test_date = $ical->iCalDateToUnixTimestamp( $until );
+ if ( $test_date ) {
+ $to_date = date( 'Y-m-d', $test_date );
+ }
+ //echo '$test_date: ' . print_r( date( 'm/d/Y', $test_date), true ) . '
';
+ }
+ }
+ if ( $btime === $etime ) {
+ if ( $btime === '00:00' ) {
+ $all_day = true;
+ } else {
+ $start_time_only = true;
+ }
+ }
+ if ( $btime && $etime && $etime === '00:00' ) {
+ $start_time_only = true;
+ }
+ // for the recurrences part
+ $recur_data = array(
+ 'event' => $event_id,
+ 'name' => 'Imported',
+ 'start_time' => $btime,
+ 'end_time' => $etime,
+ 'start_time_only' => $start_time_only,
+ 'from_date' => $from_date,
+ 'to_date' => $to_date,
+ 'all_day' => $all_day,
+ 'recurring' => $recurring_event,
+ 'month_of_year' => $month_of_year,
+ 'week_of_month' => $week_of_month,
+ 'day_of_week' => $day_of_week,
+ 'day_of_month' => $day_of_month,
+ 'by_day_of_month' => $by_day_of_month,
+ 'last_day_of_month' => $last_day_of_month,
+ 'specific_dates' => $serialized_times
+ );
+ $this->wpdb->insert(
+ GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'recurrences',
+ $recur_data,
+ array(
+ '%d',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%d',
+ '%d',
+ '%d',
+ '%d',
+ '%d',
+ '%d',
+ '%d',
+ '%d',
+ '%s'
+ )
+ );
+ $recurr_id = $this->wpdb->insert_id;
+ $Recurrences->createRecurrenceTimesEntries( $recurr_id, true, true );
+ ++$number_events;
+ }
+ }
+ if ( !$debug ) {
+ $out = $number_events . ' events imported';
+ }
+ return $out;
+ }
+ public function fetchIcalFile( $url )
+ {
+ $path = '/tmp';
+ $filename = tempnam( $path, "ICAL" );
+ $fp = fopen( $filename, 'w+' );
+ $ch = curl_init( $url );
+ curl_setopt( $ch, CURLOPT_TIMEOUT, 50 );
+ curl_setopt( $ch, CURLOPT_FILE, $fp );
+ curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
+ $fileData = curl_exec( $ch );
+ $httpCode = curl_getinfo( $ch );
+ curl_close( $ch );
+ fclose( $fp );
+ // Set correct file permissions
+ $oldUmask = umask( 0 );
+ chmod( $filename, 0660 );
+ umask( $oldUmask );
+ return $filename;
+ }
+ /**
+ * getCityId
+ *
+ * Given a city name find and return the id of the city.
+ * If a city cannot be found then create city with that name.
+ *
+ * @param mixed $city_name Name of the city
+ *
+ * @access public
+ * @return id of city
+ */
+ public function getCityId($city_name)
+ {
+ if ( !$city_name ) {
+ return false;
+ }
+ $sql = "
+ SELECT id
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "cities
+ WHERE name like '" . esc_sql( trim( $city_name ) ) . "'";
+ $cityId = $this->wpdb->get_row($sql, ARRAY_A);
+ if ( !$cityId ) {
+ // then add the city to the city table
+ $this->wpdb->insert(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX . 'cities',
+ array( 'name' => trim( $city_name ) ),
+ array( '%s' )
+ );
+ return $this->wpdb->insert_id;
+ } else {
+ return $cityId['id'];
+ }
+ }
+
+}
+
+?>
diff --git a/models/admin/management/events.php b/models/admin/management/events.php
index 599b6bb..4585756 100644
--- a/models/admin/management/events.php
+++ b/models/admin/management/events.php
@@ -219,10 +219,17 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement
array( 'id' => $feed_id ),
'%d'
);
+ if ( wp_next_scheduled( GLM_MEMBERS_EVENTS_PLUGIN_CRON_EVENT, array( $feed_id ) ) ) {
+ wp_clear_scheduled_hook( GLM_MEMBERS_EVENTS_PLUGIN_CRON_EVENT, array( $feed_id ) );
+ }
}
if ( $option2 === 'refresh' && $feed_id = filter_var( $_REQUEST['id'], FILTER_VALIDATE_INT ) ) {
- //$icalFeedResult .= '$_REQUEST: ' . print_r( $_REQUEST, true ) . '
';
- $icalFeedResult .= $this->importIcalFeed( $feed_id );
+ //$icalFeedResult .= $this->importIcalFeed( $feed_id );
+ // Set up the event schedule
+ if ( wp_next_scheduled( GLM_MEMBERS_EVENTS_PLUGIN_CRON_EVENT, array( $feed_id ) ) ) {
+ wp_clear_scheduled_hook( GLM_MEMBERS_EVENTS_PLUGIN_CRON_EVENT, array( $feed_id ) );
+ }
+ wp_schedule_event( time(), GLM_MEMBERS_EVENTS_PLUGIN_CRON_RECURRANCE, GLM_MEMBERS_EVENTS_PLUGIN_CRON_EVENT, array( $feed_id ) );
}
if ( isset( $_REQUEST['feed_url'] ) && $feed_url = filter_var( $_REQUEST['feed_url'], FILTER_VALIDATE_URL ) ) {
// Add this feed url to the table
@@ -234,6 +241,12 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement
),
'%s'
);
+ $feed_id = $this->wpdb->insert_id;
+
+ // Setup the event feed to pull on schedule
+ if ( !wp_next_scheduled( GLM_MEMBERS_EVENTS_PLUGIN_CRON_EVENT, $feed_id ) ) {
+ wp_schedule_event( time(), GLM_MEMBERS_EVENTS_PLUGIN_CRON_RECURRANCE, GLM_MEMBERS_EVENTS_PLUGIN_CRON_EVENT, array( $feed_id ) );
+ }
}
break;
@@ -300,59 +313,6 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement
if (isset($_REQUEST['action'])) {
$action = $_REQUEST['action'];
}
- switch ( $action ) {
- case 'redo':
- $Recurrences = new GlmDataEventsRecurrences($this->wpdb, $this->config);
- $db_host = 'ds4';
- $db_name = 'discoverkalamazoo';
- $db_user = 'postgres';
- $db_password = '';
- $this->connectPostgresDb($db_host, $db_name, $db_user, $db_password);
- $Recurrences = new GlmDataEventsRecurrences($this->wpdb, $this->config);
- $sql = "
- SELECT *
- FROM events.event
- WHERE edate >= current_date
- AND (btime != '' OR etime != '')";
- $events = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
- foreach ( $events as $event ) {
- echo '$event[btime]: ' . print_r($event['btime'], true) . '
';
- $begining = $this->getTime( $event['btime'] );
- echo '$begining: ' . print_r($begining, true) . '
';
- echo '$event[etime]: ' . print_r($event['etime'], true) . '
';
- $ending = $this->getTime( $event['etime'] );
- echo '$ending: ' . print_r($ending, true) . '
';
- // find the event with this old_event_id
- $result = $this->wpdb->get_results(
- "SELECT * FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "recurrences
- WHERE event IN (
- SELECT id
- FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX. "events
- WHERE old_event_id = " . $event['id'] . ")",
- ARRAY_A
- );
- echo '$result: ' . print_r($result, true) . '
';
- if ( $result[0] ) {
- // update the recurrence
- $return = $this->wpdb->update(
- GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'recurrences',
- array(
- 'start_time' => $begining,
- 'end_time' => $ending
- ),
- array( 'id' => $result[0]['id'] ),
- array(
- '%s',
- '%s'
- ),
- array( '%d' )
- );
- echo '$return: ' . print_r($return, true) . '
';
- $Recurrences->createRecurrenceTimesEntries( $result[0]['id'], true, true );
- }
- }
- $import_result = 'hello redo';
- }
break;
case 'settings':
@@ -420,6 +380,13 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement
$import_feeds = $importFeeds->getList();
+ if ( $import_feeds ) {
+ foreach ( $import_feeds as $key => &$feed ) {
+ // check the next run time
+ $feed['next_runtime'] = wp_next_scheduled( GLM_MEMBERS_EVENTS_PLUGIN_CRON_EVENT, array( (int)$feed['id'] ) );
+ }
+ }
+
// Compile template data
$template_data = array(
'import_feeds' => $import_feeds,
@@ -1718,357 +1685,6 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement
. "&start=$start\">Next
$events: ' . print_r( $events, true ) . ''; - } - if ( $events ) { - foreach ( $events as $event ) { - $contact = array(); - $image = ''; - $event['DESCRIPTION'] - = str_replace( '\n', "
$contact_data: ' . print_r( $contact_data, true ) . ''; - } - $contact = array( - 'name' => $contact_data[0], - 'email' => $contact_data[1], - 'phone' => $contact_data[2], - ); - } else { - $contact = array( - 'name' => '', - 'email' => '', - 'phone' => '', - ); - } - if ( isset( $event['ATTACH'] ) ) { - $img_url = preg_replace( '%FMTTYPE=image/(jpeg|gif|png)[:]%', '', $event['ATTACH'] ); - $res = $image_upload->storeImage( $img_url ); - $image = $res['newFileName']; - } - $event_data = array( - 'status' => $this->config['status_numb']['Active'], - 'ref_type' => 10, - 'created' => $ical->iCalDateToUnixTimestamp( $event['CREATED'] ), - 'updated' => $ical->iCalDateToUnixTimestamp( $event['CREATED'] ), - 'approved' => null, - 'ical_uid' => $event['UID'], - 'name' => $event['SUMMARY'], - 'intro' => $intro, - 'descr' => $event['DESCRIPTION'], - 'image' => $image, - 'url' => ( isset( $event['URL'] ) ? $event['URL']: '' ), - 'contact_email' => $contact['name'], - 'contact_name' => $contact['email'], - 'contact_phone' => $contact['phone'], - ); - if ( $debug ) { - //$out .= '
$event_data: ' . print_r( $event_data, true ) . ''; - } - $event_data_format = array( - '%d', - '%d', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - ); - // check for this event record first to see if it can be - // updated instead of insert - $event_id = $this->wpdb->get_var( - $this->wpdb->prepare( - "SELECT id - FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events - WHERE ical_uid = %s", - $event['UID'] - ) - ); - if ( $event_id ) { - $this->wpdb->update( - GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'events', - $event_data, - array( 'id' => $event_id ), - $event_data_format, - '%d' - ); - } else { - $this->wpdb->insert( - GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'events', - $event_data, - $event_data_format - ); - $event_id = $this->wpdb->insert_id; - } - if ( !$event_id ) { - die('something is wrong no event_id'); - } - // generate the slug name for this new event - $event_abstract = new GlmDataEvents( $this->wpdb, $this->config ); - $event_abstract->updateSlug( $event_id ); - // Location Data - if ( isset( $event['LOCATION'] ) ) { - $location_data = explode( ',', str_replace( '\\', '', $event['LOCATION'] ) ); - $place = ( isset( $location_data[0] ) ? $location_data[0]: ''); - $address = ( isset( $location_data[1] ) ? $location_data[1]: ''); - $city = ( isset( $location_data[2] ) ? $location_data[2]: ''); - $state = ( isset( $location_data[3] ) ? $location_data[3]: ''); - $zip = ( isset( $location_data[4] ) ? $location_data[4]: ''); - $location = array( - 'event' => $event_id, - 'name' => $place, - 'address' => $address, - 'city' => $this->getCityId( $city ), - 'state' => $state, - 'zip' => $zip, - ); - $location_format = array( - '%d', '%s', '%s', '%d', '%s', '%s' - ); - if ( isset( $event['GEO'] ) ) { - $geo_data = explode( ';', $event['GEO'] ); - $location['lat'] = $geo_data[0]; - $location['lon'] = $geo_data[1]; - $location_format[] = '%s'; - $location_format[] = '%s'; - } - // Remove any old location data for this event_id. - $this->wpdb->delete( - GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'locations', - array( 'event' => $event_id ), - '%d' - ); - $this->wpdb->insert( - GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'locations', - $location, - $location_format - ); - } - // Remove any old recurrences data for this event_id. - $this->wpdb->delete( - GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'recurrences', - array( 'event' => $event_id ), - '%d' - ); - // Remove any old times data for this event_id. - $this->wpdb->delete( - GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'times', - array( 'event' => $event_id ), - '%d' - ); - $serialized_times = null; - $day_of_week = - $day_of_month = - $month_of_year = - $week_of_month = - $by_day_of_month = - $last_day_of_month = null; - $start_time_only = - $all_day = - $recurring_event = 0; - $day_of_week = 127; - $month_of_year = 4095; - $week_of_month = 63; - $starting = $ical->iCalDateToUnixTimestamp( $event['DTSTART'] ); - $ending = $ical->iCalDateToUnixTimestamp( $event['DTEND'] ); - $from_date = date( 'Y-m-d', $starting ); - $to_date = date( 'Y-m-d', $ending ); - $btime = date( 'H:i', $starting ); - $etime = date( 'H:i', $ending ); - $freq = $byday = $until = ''; - if ( isset( $event['RRULE'] ) ) { - $recurring_event = 1; - $rrule_data = explode( ';', $event['RRULE'] ); - //echo '
$rrule_data: ' . print_r( $rrule_data, true ) . ''; - if ( $rrule_data ) { - foreach ( $rrule_data as $rule ) { - if ( preg_match( '%FREQ=(.*)%', $rule, $matches ) ) { - $freq = trim( $matches[1] ); - } - if ( preg_match( '%BYDAY=(.*)%', $rule, $matches ) ) { - $byday = trim( $matches[1] ); - } - if ( preg_match( '%UNTIL=(.*)%', $rule, $matches ) ) { - $until = trim( $matches[1] ); - } - } - } - if ( $freq === 'WEEKLY' && $byday ) { - // separated by commas - $days = explode( ',',$byday ); - //echo '
$days: ' . print_r( $days, true ) . ''; - if ( $days ) { - $day_of_week = 0; - foreach ( $days as $day ) { - if ( preg_match( '%([0-9])?([A-Z]{2})%', $day, $d_matches ) ) { - //echo '
$d_matches: ' . print_r( $d_matches, true ) . ''; - if ( $d_matches[1] ) { - $week_of_month = pow(2, $d_matches[1] ); - } - switch ( $d_matches[2] ) { - case "SU": - $day_of_week += pow(2, 0); - break; - case "MO": - $day_of_week += pow(2, 1); - break; - case "TU": - $day_of_week += pow(2, 2); - break; - case "WE": - $day_of_week += pow(2, 3); - break; - case "TH": - $day_of_week += pow(2, 4); - break; - case "FR": - $day_of_week += pow(2, 5); - break; - case "SA": - $day_of_week += pow(2, 6); - break; - } - } - } - } - } - if ( $until != '' ) { - //echo '
$until: ' . print_r( $until, true ) . ''; - $test_date = $ical->iCalDateToUnixTimestamp( $until ); - if ( $test_date ) { - $to_date = date( 'Y-m-d', $test_date ); - } - //echo '
$test_date: ' . print_r( date( 'm/d/Y', $test_date), true ) . ''; - } - } - if ( $btime === $etime ) { - if ( $btime === '00:00' ) { - $all_day = true; - } else { - $start_time_only = true; - } - } - if ( $btime && $etime && $etime === '00:00' ) { - $start_time_only = true; - } - // for the recurrences part - $recur_data = array( - 'event' => $event_id, - 'name' => 'Imported', - 'start_time' => $btime, - 'end_time' => $etime, - 'start_time_only' => $start_time_only, - 'from_date' => $from_date, - 'to_date' => $to_date, - 'all_day' => $all_day, - 'recurring' => $recurring_event, - 'month_of_year' => $month_of_year, - 'week_of_month' => $week_of_month, - 'day_of_week' => $day_of_week, - 'day_of_month' => $day_of_month, - 'by_day_of_month' => $by_day_of_month, - 'last_day_of_month' => $last_day_of_month, - 'specific_dates' => $serialized_times - ); - $this->wpdb->insert( - GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'recurrences', - $recur_data, - array( - '%d', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%d', - '%d', - '%d', - '%d', - '%d', - '%d', - '%d', - '%d', - '%s' - ) - ); - $recurr_id = $this->wpdb->insert_id; - $Recurrences->createRecurrenceTimesEntries( $recurr_id, true, true ); - ++$number_events; - } - } - if ( !$debug ) { - $out = $number_events . ' events imported'; - } - return $out; - } } ?> diff --git a/setup/adminHooks.php b/setup/adminHooks.php index c75852d..d4c1286 100644 --- a/setup/adminHooks.php +++ b/setup/adminHooks.php @@ -26,41 +26,19 @@ * Also note that parameters will be in the context of the main admin controller constructor. */ - -/* - Settingc up action hook for cron task. For cron not working so far. add_action( - 'glm_events_cron', - function ( $id, $host ) { + GLM_MEMBERS_EVENTS_PLUGIN_CRON_EVENT, + function( $id ) { echo '
$id: ' . print_r( $id, true ) . ''; - echo '
$host: ' . print_r( $host, true ) . ''; - $file = GLM_MEMBERS_EVENTS_PLUGIN_PATH . '/test_run.txt'; - if( !touch( $file ) ) { - $fp = fopen( $file, 'w+' ); - fclose( $fp ); - } + $this->controller( 'cron', 'icalFeed' ); }, 10, - 2 + 1 ); - */ -//do_action( 'glm_events_cron', 1, 'http://gaslightmedia.com' ); + /* -wp_schedule_event( - time(), - 'hourly', - function( $id, $host ){ - echo '
$id: ' . print_r( $id, true ) . ''; - echo '
$host: ' . print_r( $host, true ) . ''; - $file = GLM_MEMBERS_EVENTS_PLUGIN_PATH . 'test_run.txt'; - if( !touch( $file ) ) { - $fp = fopen( $file, 'w+' ); - fclose( $fp ); - } - } - array( - 'id' => 1, - 'host' => 'Forteen.com' - ) -); -*/ +include_once GLM_MEMBERS_EVENTS_MAIN_PLUGIN_PATH . '/lib/GlmDataAbstract/DataAbstract.php'; +include_once GLM_MEMBERS_EVENTS_PLUGIN_PATH . '/models/admin/management/events.php'; +$eventManagement = new GlmMembersAdmin_management_events( $this->wpdb, $this->config ); +add_action( GLM_MEMBERS_EVENTS_PLUGIN_CRON_EVENT, array( $eventManagement, 'importIcalFeed' ), 10, 1 ); + */ diff --git a/setup/frontHooks.php b/setup/frontHooks.php index 205dd5a..972d85d 100644 --- a/setup/frontHooks.php +++ b/setup/frontHooks.php @@ -132,3 +132,12 @@ if (isset($this->config['addOns']['glm-member-db'])) { ); } +add_action( + GLM_MEMBERS_EVENTS_PLUGIN_CRON_EVENT, + function( $id ) { + echo '
$id: ' . print_r( $id, true ) . ''; + //$this->controller( 'cron', 'icalFeed' ); + }, + 10, + 1 +); diff --git a/setup/validActions.php b/setup/validActions.php index c22203d..9912088 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -51,6 +51,9 @@ $glmMembersEventsAddOnValidActions = array( ), 'management' => array( 'events' => GLM_MEMBERS_EVENTS_PLUGIN_SLUG + ), + 'cron' => array( + 'icalFeed' => GLM_MEMBERS_EVENTS_PLUGIN_SLUG ) ), 'frontActions' => array( diff --git a/views/admin/events/editSchedule.html b/views/admin/events/editSchedule.html index 732310c..1974422 100644 --- a/views/admin/events/editSchedule.html +++ b/views/admin/events/editSchedule.html @@ -26,7 +26,7 @@ - +
- NOTE: This calendar only shows these specific dates and does not include other dates from the schedule. + NOTE: This calendar only shows these specific dates and does not include other dates from the schedule. See the Summary Calendar to view all dates for this event.
Click on Dates to select/remove those dates for this schedule.
- NOTE: This calendar only shows these specific dates and does not include other dates from the schedule. + NOTE: This calendar only shows these specific dates and does not include other dates from the schedule. See the Summary Calendar to view all dates for this event.
diff --git a/views/admin/management/events.html b/views/admin/management/events.html index 0b113f7..9b43bde 100644 --- a/views/admin/management/events.html +++ b/views/admin/management/events.html @@ -110,18 +110,22 @@