}
public function addTimelyCategories() {
- $category_counter = 0;
+ $category_counter = 0;
$categories = get_terms( 'events_categories' );
foreach ( $categories as $category ) {
- ++$category_counter;
+ ++$category_counter;
// first check to see if the category is already there
$sql = "
SELECT id
$this->oldCatMap[$category->term_id] = $found['id'];
}
}
- // Store the oldCatMap for the next pages.
- update_option( 'glm-member-event-old-cat-map', serialize( $this->oldCatMap ) );
- return "<p>Adding $category_counter Categories</p>";
+ // Store the oldCatMap for the next pages.
+ update_option( 'glm-member-event-old-cat-map', serialize( $this->oldCatMap ) );
+ return "<p>Adding $category_counter Categories</p>";
+ }
+ public function getOldCatMap()
+ {
+ return unserialize( get_option('glm-member-event-old-cat-map') );
}
- public function getOldCatMap()
- {
- return unserialize( get_option('glm-member-event-old-cat-map') );
- }
/**
* getTime
*
return $return;
}
public function importFromTimely() {
- $limit = 25;
- $debug = false;
- if ( isset( $_REQUEST['start'] ) ) {
- $start = filter_var( $_REQUEST['start'], FILTER_VALIDATE_INT );
- } else {
- $start = 0;
- }
- if ( $start === 0 ) {
- // clear the events tables first.
- $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events" );
- $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "recurrences" );
- $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times" );
- $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "event_categories" );
- $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "locations" );
- // Add the Categories from Time.ly.
- $return_string = $this->addTimelyCategories();
- } else {
- $this->oldCatMap = $this->getOldCatMap();
- }
+ $limit = 25;
+ $debug = false;
+ if ( isset( $_REQUEST['start'] ) ) {
+ $start = filter_var( $_REQUEST['start'], FILTER_VALIDATE_INT );
+ } else {
+ $start = 0;
+ }
+ if ( $start === 0 ) {
+ // clear the events tables first.
+ $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events" );
+ $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "recurrences" );
+ $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times" );
+ $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "event_categories" );
+ $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "locations" );
+ // Add the Categories from Time.ly.
+ $return_string = $this->addTimelyCategories();
+ } else {
+ $this->oldCatMap = $this->getOldCatMap();
+ }
$yearly_events =
$daily_events =
FROM " . $this->wpdb->prefix . "posts
WHERE post_type = 'ai1ec_event'
AND post_status = 'publish'";
- //$sql .= " AND ID IN ( SELECT post_id FROM " . $this->wpdb->prefix . "ai1ec_events
- //WHERE end >= " . time() . " )";
+ //$sql .= " AND ID IN ( SELECT post_id FROM " . $this->wpdb->prefix . "ai1ec_events
+ //WHERE end >= " . time() . " )";
//$sql .= " AND ID IN ( 1647 )";
- $sql .= " LIMIT $limit OFFSET $start";
+ $sql .= " LIMIT $limit OFFSET $start";
$results = $this->wpdb->get_results( $sql, ARRAY_A );
//echo '<p>Total events: ' . count( $results ) . '</p>';
- $event_counter = 0;
+ $event_counter = 0;
if ( !empty( $results ) ) {
foreach ( $results as $post ) {
if ( $debug ) {
echo '<div style="border:1px solid green;">';
}
- ++$event_counter;
+ ++$event_counter;
//echo '<pre>$post: ' . print_r($post, true) . '</pre>';
$sql = "
SELECT *
$event_import_data,
$event_data_format
);
- if ( $debug ) {
- var_dump( $is_insert );
- }
+ if ( $debug ) {
+ var_dump( $is_insert );
+ }
$event_id = $this->wpdb->insert_id;
- if ( $debug ) {
- var_dump( $event_id );
- }
- if ( !$event_id ) {
- $this->wpdb->print_error();
- echo '<pre>$event_import_data: ' . print_r($event_import_data, true) . '</pre>';
+ if ( $debug ) {
+ var_dump( $event_id );
+ }
+ if ( !$event_id ) {
+ $this->wpdb->print_error();
+ echo '<pre>$event_import_data: ' . print_r($event_import_data, true) . '</pre>';
echo '<pre>SQL Error: ' . $this->wpdb->last_error . '</pre>';
echo '<pre>SQL Error: ' . $this->wpdb->print_error() . '</pre>';
die('something is wrong no event_id');
)
);
}
- if ( $debug ) {
+ if ( $debug ) {
echo '<pre>$event_data: ' . print_r($event_data, true) . '</pre>';
- echo '<pre>$categories: ' . print_r($categories, true) . '</pre>';
- }
+ echo '<pre>$categories: ' . print_r($categories, true) . '</pre>';
+ }
$by_day_of_month =
$last_day_of_month = null;
$custom_times = array();
$curZone = date_default_timezone_get();
- if ( $debug ) {
+ if ( $debug ) {
echo '<pre>$curZone: ' . print_r($curZone, true) . '</pre>';
- }
+ }
if ( $event_data['timezone_name'] ) {
date_default_timezone_set( $event_data['timezone_name'] );
}
$curZone = date_default_timezone_get();
- if ( $debug ) {
+ if ( $debug ) {
echo '<pre>$curZone: ' . print_r($curZone, true) . '</pre>';
- }
+ }
$from_date = date( 'Y-m-d', $event_data['start'] );
- if ( $debug ) {
- echo '<pre>$from_date: ' . print_r($from_date, true) . '</pre>';
+ if ( $debug ) {
+ echo '<pre>$from_date: ' . print_r($from_date, true) . '</pre>';
$from_date_time = date( 'Y-m-d H:m:s', $event_data['start'] );
echo '<pre>$from_date_time: ' . print_r($from_date_time, true) . '</pre>';
- }
+ }
$to_date = date( 'Y-m-d', $event_data['end'] );
// check if the $to_date has 0 hr
// if the btime and etime are 00:00 then remove one day from $to_date
$ending_datetime->modify('- 1 day');
$to_date = $ending_datetime->format( 'Y-m-d' );
}
- if ( $debug ) {
- echo '<pre>$to_date: ' . print_r($to_date, true) . '</pre>';
+ if ( $debug ) {
+ echo '<pre>$to_date: ' . print_r($to_date, true) . '</pre>';
$to_date_time = date( 'Y-m-d H:m:s', $event_data['end'] );
echo '<pre>$to_date_time: ' . print_r($to_date_time, true) . '</pre>';
- }
+ }
$btime = date( 'H:i', $event_data['start'] );
- if ( $debug ) {
- echo '<pre>$btime: ' . print_r($btime, true) . '</pre>';
- }
+ if ( $debug ) {
+ echo '<pre>$btime: ' . print_r($btime, true) . '</pre>';
+ }
$etime = date( 'H:i', $event_data['end'] );
- if ( $debug ) {
- echo '<pre>$etime: ' . print_r($etime, true) . '</pre>';
+ if ( $debug ) {
+ echo '<pre>$etime: ' . print_r($etime, true) . '</pre>';
}
if ( $event_data['recurrence_rules'] ) {
$recurring_event = 1;
$recurrence_rules = explode( ';', $event_data['recurrence_rules'] );
- if ( $debug ) {
- echo '<pre>$recurrence_rules: ' . print_r($recurrence_rules, true) . '</pre>';
- }
+ if ( $debug ) {
+ echo '<pre>$recurrence_rules: ' . print_r($recurrence_rules, true) . '</pre>';
+ }
foreach ( $recurrence_rules as $rule ) {
// check for RDATE , which are the custom dates that need to be serialized
if(strpos($rule, 'RDATE') !== false){
$custom_times = explode(',', $rdate);
}
if ( preg_match( ';FREQ=(.*);', $rule, $matches ) ) {
- if ( $debug ) {
- echo '<pre>$matches: ' . print_r($matches, true) . '</pre>';
- }
+ if ( $debug ) {
+ echo '<pre>$matches: ' . print_r($matches, true) . '</pre>';
+ }
switch ( $matches[1] ) {
case "WEEKLY":
$weekly_events++;
break;
}
} else if ( preg_match( ';COUNT=(.*);', $rule, $matches ) ) {
- if ( $debug ) {
- echo '<pre>$matches: ' . print_r($matches, true) . '</pre>';
- }
+ if ( $debug ) {
+ echo '<pre>$matches: ' . print_r($matches, true) . '</pre>';
+ }
// set the end date to COUNT days from start
try {
$number_of_days = (int)$matches[1] - 1;
$to_date = $ending_date->format( 'Y-m-d' );
$recurring_event = 0;
} catch (Exception $e) {
- if ( $debug ) {
- echo '<pre>$e: ' . print_r($e, true) . '</pre>';
- }
- die();
+ if ( $debug ) {
+ echo '<pre>$e: ' . print_r($e, true) . '</pre>';
+ }
+ die();
}
} else if ( preg_match( ';UNTIL=(.*);', $rule, $matches ) ) {
$to_date = date( 'Y-m-d', strtotime( $matches[1] ) );
}else if ( preg_match( ';BYday=(.*);', $rule, $matches ) ) {
- if ( $debug ) {
- echo '<pre>1354 $matches: ' . print_r($matches, true) . '</pre>';
- }
+ if ( $debug ) {
+ echo '<pre>1354 $matches: ' . print_r($matches, true) . '</pre>';
+ }
// check if the selection is the nth week with a selected day, if not parse the input as a list if selected days
if(strpos($matches[1], ",") == false){
$week_number = substr($matches[1],0, 1);
date_default_timezone_set('UTC');
$serialized_custom_times = serialize($custom_times);
foreach($custom_times as $custom){
-
+
$convert = date('U',strtotime($custom));
$stamp[] = date('Y-m-d', $convert);
}
}
date_default_timezone_set($curZone);
}
- if ($recurring_event && $from_date == $to_date && empty( $custom_times ) ) {
- // Add two years to the recurring event if dates match
- $starting_datetime = new DateTime( $from_date );
- $ending_date = $starting_datetime->modify('2 years');
- $to_date = $ending_date->format( 'Y-m-d' );
- }
+ if ($recurring_event && $from_date == $to_date && empty( $custom_times ) ) {
+ // Add two years to the recurring event if dates match
+ $starting_datetime = new DateTime( $from_date );
+ $ending_date = $starting_datetime->modify('2 years');
+ $to_date = $ending_date->format( 'Y-m-d' );
+ }
$all_day = $event_data['allday'];
-
+
// instant event is an event with no end time
$start_time_only = $event_data['instant_event'];
if($start_time_only){
'last_day_of_month' => $last_day_of_month,
'specific_dates' => $serialized_custom_times
);
- if ( $debug ) {
- echo '<pre>$recur_data: ' . print_r($recur_data, true) . '</pre>';
- }
+ if ( $debug ) {
+ echo '<pre>$recur_data: ' . print_r($recur_data, true) . '</pre>';
+ }
$this->wpdb->insert(
GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'recurrences',
$recur_data,
$Recurrences->createRecurrenceTimesEntries( $recurr_id, true, true );
// location for the event
$has_location = ( $event_data['address'] || $event_data['venue'] );
+ $location_data = $location_format = array();
if ( $has_location ) {
- $location_data = $location_format = array();
$location_data['event'] = $event_id;
$location_format[] = '%d';
if ($event_data['venue']) {
);
$location_id = $this->wpdb->insert_id;
if ( !$location_id ) {
- if ( $debug ) {
- echo '<pre>$location_data: ' . print_r($location_data, true) . '</pre>';
- }
+ if ( $debug ) {
+ echo '<pre>$location_data: ' . print_r($location_data, true) . '</pre>';
+ }
die('no return id for location');
}
}
echo '</div>';
}
}
- $return_string .= "<p>Adding $event_counter Events</p>";
+ $return_string .= "<p>Adding $event_counter Events</p>";
}
- $return_string .= "<pre>
- Start: $start
- </pre>";
- $start += $limit;
- $return_string .= "<p><a href=\""
- . GLM_MEMBERS_PLUGIN_CURRENT_URL
- . "?page=glm-members-admin-menu-management&glm_action=events&option=timelyImport&import=true"
- . "&start=$start\">Next</a></p>";
- return $return_string;
+ $return_string .= "<pre>
+ Start: $start
+ </pre>";
+ $start += $limit;
+ $return_string .= "<p><a href=\""
+ . GLM_MEMBERS_PLUGIN_CURRENT_URL
+ . "?page=glm-members-admin-menu-management&glm_action=events&option=timelyImport&import=true"
+ . "&start=$start\">Next</a></p>";
+ return $return_string;
}
}