'schema' => FILTER_SANITIZE_STRING,
'cattablename' => FILTER_SANITIZE_STRING,
'tablename' => FILTER_SANITIZE_STRING,
- 'sdate' => array(
+ 'sdate' => array(
'filter' => FILTER_VALIDATE_REGEXP,
'options' => array(
'regexp' => '%[0-9]{2}/[0-9]{2}/[0-9]{4}%'
'status' => false,
'menuItemRedirect' => 'error',
'modelRedirect' => 'index',
- 'view' => 'admin/error/index.html',
- 'data' => array(
+ 'view' => 'admin/error/index.html',
+ 'data' => array(
'reason' => 'User does not have rights to make configuration changes.'
)
);
$template_data = array(
'option' => $option,
'testResult' => $test_result,
- 'importResult' => $import_result,
- 'settingsUpdated' => $settings_updated,
+ 'importResult' => $import_result,
+ 'settingsUpdated' => $settings_updated,
'settingsUpdateError' => $settings_update_error,
'eventsSettings' => $event_settings
);
'status' => true,
'menuItemRedirect' => false,
'modelRedirect' => false,
- 'view' => 'admin/management/events.html',
- 'data' => $template_data
+ 'view' => 'admin/management/events.html',
+ 'data' => $template_data
);
}
public function addTimelyCategories() {
+ $category_counter = 0;
$categories = get_terms( 'events_categories' );
foreach ( $categories as $category ) {
+ ++$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>";
}
+ public function getOldCatMap()
+ {
+ return unserialize( get_option('glm-member-event-old-cat-map') );
+ }
/**
* getTime
*
return $return;
}
public function importFromTimely() {
- // 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" );
-
- $return = $this->addTimelyCategories();
+ $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 .= " LIMIT $limit OFFSET $start";
$results = $this->wpdb->get_results( $sql, ARRAY_A );
- echo '<p>Total events: ' . count( $results ) . '</p>';
+ //echo '<p>Total events: ' . count( $results ) . '</p>';
+ $event_counter = 0;
if ( !empty( $results ) ) {
foreach ( $results as $post ) {
- echo '<pre>$post: ' . print_r($post, true) . '</pre>';
+ ++$event_counter;
+ //echo '<pre>$post: ' . print_r($post, true) . '</pre>';
$sql = "
SELECT *
FROM " . $this->wpdb->prefix . "ai1ec_events
WHERE post_id = {$post['ID']}";
$event_data = $this->wpdb->get_row( $sql, ARRAY_A );
- echo '<pre>$event_data: ' . print_r($event_data, true) . '</pre>';
+ //echo '<pre>$event_data: ' . print_r($event_data, true) . '</pre>';
$cost_data = unserialize( $event_data['cost'] );
$cost = $cost_data['cost'];
$is_free = $cost_data['is_free'];
if ( has_post_thumbnail( $post['ID'] ) ) {
$thumbnail_id = get_post_thumbnail_id( $post['ID'] );
$thumb_src = wp_get_attachment_image_src( $thumbnail_id, 'large' );
- echo '<pre>$thumb_src: ' . print_r($thumb_src, true) . '</pre>';
+ //echo '<pre>$thumb_src: ' . print_r($thumb_src, true) . '</pre>';
$res = $image_upload->storeImage($thumb_src[0]);
- echo '<pre>$res: ' . print_r($res, true) . '</pre>';
+ //echo '<pre>$res: ' . print_r($res, true) . '</pre>';
if ( $res['newFileName'] ) {
$image = $res['newFileName'];
}
'approved' => $post['post_modified'],
'name' => $post['post_title'],
'name_slug' => $post['post_name'],
- 'intro' => substr( strip_tags( $post['post_content'] ), 0, 250 ),
+ 'intro' => mb_substr( strip_tags( $post['post_content'] ), 0, 80 ),
'descr' => $post['post_content'],
'image' => $image,
'file1' => null,
'%s',
'%s',
);
- $this->wpdb->insert(
+ if ( $debug ) {
+ //$this->wpdb->show_errors();
+ }
+ $is_insert = $this->wpdb->insert(
GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'events',
$event_import_data,
$event_data_format
);
+ if ( $debug ) {
+ var_dump( $is_insert );
+ }
$event_id = $this->wpdb->insert_id;
- var_dump( $event_id );
- if ( !$event_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>';
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');
)
);
}
- echo '<pre>$categories: ' . print_r($categories, true) . '</pre>';
+ if ( $debug ) {
+ echo '<pre>$categories: ' . print_r($categories, true) . '</pre>';
+ }
$by_day_of_month =
$last_day_of_month = null;
$week_of_month = 63;
$from_date = date( 'Y-m-d', $event_data['start'] );
- echo '<pre>$from_date: ' . print_r($from_date, true) . '</pre>';
+ if ( $debug ) {
+ echo '<pre>$from_date: ' . print_r($from_date, true) . '</pre>';
+ }
$to_date = date( 'Y-m-d', $event_data['end'] );
- echo '<pre>$to_date: ' . print_r($to_date, true) . '</pre>';
+ if ( $debug ) {
+ echo '<pre>$to_date: ' . print_r($to_date, true) . '</pre>';
+ }
$btime = date( 'H:i', $event_data['start'] );
- 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'] );
- 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'] );
- 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 ) ) {
- 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 ) ) {
- 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) {
- 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 ) ) {
- 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);
'last_day_of_month' => $last_day_of_month,
'specific_dates' => $serialized_custom_times
);
- 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,
);
$location_id = $this->wpdb->insert_id;
if ( !$location_id ) {
- 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');
}
}
}
+ $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;
}
}