'publish', 'post_type' => 'sm-location', 'posts_per_page' => -1 ) ); // Include CSV library require_once( SIMPLEMAP_PATH . '/classes/parsecsv.lib.php' ); $taxonomies = get_object_taxonomies( 'sm-location' ); foreach ( $locations as $key => $location ) { $location_data = array( 'name' => esc_attr( $location->post_title ), 'address' => esc_attr( get_post_meta( $location->ID, 'location_address', true ) ), 'address2' => esc_attr( get_post_meta( $location->ID, 'location_address2', true ) ), 'city' => esc_attr( get_post_meta( $location->ID, 'location_city', true ) ), 'state' => esc_attr( get_post_meta( $location->ID, 'location_state', true ) ), 'zip' => esc_attr( get_post_meta( $location->ID, 'location_zip', true ) ), 'country' => esc_attr( get_post_meta( $location->ID, 'location_country', true ) ), 'phone' => esc_attr( get_post_meta( $location->ID, 'location_phone', true ) ), 'email' => esc_attr( get_post_meta( $location->ID, 'location_email', true ) ), 'fax' => esc_attr( get_post_meta( $location->ID, 'location_fax', true ) ), 'url' => esc_attr( get_post_meta( $location->ID, 'location_url', true ) ), 'description' => esc_attr( $location->post_content ), 'special' => esc_attr( get_post_meta( $location->ID, 'location_special', true ) ), 'lat' => esc_attr( get_post_meta( $location->ID, 'location_lat', true ) ), 'lng' => esc_attr( get_post_meta( $location->ID, 'location_lng', true ) ), 'dateUpdated' => esc_attr( $location->post_modified ) ); foreach ( $taxonomies as $tax ) { $term_value = ''; if ( $terms = wp_get_object_terms( $location->ID, $tax, array( 'fields' => 'names' ) ) ) { $term_value = implode( ',', $terms ); } $location_data["tax_$tax"] = esc_attr( $term_value ); } $content[] = $location_data; } if ( ! empty( $content ) ) { $csv = new smParseCSV(); $csv->output( true, 'simplemap.csv', $content, array_keys( reset( $content ) ) ); die(); } } } // Exports a LEGACY SimpleMap CSV file to WordPress function export_legacy_csv() { global $simple_map, $sm_locations,$wpdb; if ( isset( $_GET['sm-action'] ) && 'export-legacy-csv' == $_GET['sm-action'] ) { // Include CSV library include_once( SIMPLEMAP_PATH . '/classes/parsecsv.lib.php' ); // Grab Categories if ( $categories = $wpdb->get_results( "SELECT * FROM `" . $wpdb->prefix . "simple_map_cats`" ) ) { foreach ( $categories as $key => $value ) { $cats[$value->id] = $value; } } // Grab locations if ( $locations = $wpdb->get_results( "SELECT * FROM `" . $wpdb->prefix . "simple_map`" ) ) { foreach( $locations as $key => $location ) { $catnames = ''; // Do Cats if ( isset( $location->category ) && 0 != $location->category ) { if ( isset( $cats[$location->category] ) ) $catnames = $cats[$location->category]->name; } $content[] = array( 'name' => esc_attr( $location->name ), 'address' => esc_attr( $location->address ), 'address2' => esc_attr( $location->address2 ), 'city' => esc_attr( $location->city ), 'state' => esc_attr( $location->state ), 'zip' => esc_attr( $location->zip ), 'country' => esc_attr( $location->country ), 'phone' => esc_attr( $location->phone ), 'fax' => esc_attr( $location->fax ), 'url' => esc_attr( $location->url ), 'description' => esc_attr( $location->description ), 'category' => esc_attr( $catnames ), 'tags' => esc_attr( $location->tags ), 'special' => esc_attr( $location->special ), 'lat' => esc_attr( $location->lat ), 'lng' => esc_attr( $location->lng ), 'dateUpdated' => esc_attr( $location->dateUpdated ) ); } $csv = new smParseCSV(); $csv->output (true, 'simplemap.csv', $content, array('name','address','address2','city','state','zip','country','phone','fax','url','description','category','tags','special','lat','lng','dateUpdated' ) ); die(); } else { $csv = new smParseCSV(); $csv->output (true, 'simplemap.csv', array( array( 'You have no locations in your legacy database' ) ) ); die(); } } } // Deletes legacy tables function delete_legacy_tables() { global $wpdb, $simple_map; if ( isset( $_GET['sm-action'] ) && 'delete-legacy-simplemap' == $_GET['sm-action'] ) { // Confirm we have both permisssion to do this and we have intent to do this. if ( current_user_can( 'manage_options' ) && check_admin_referer( 'delete-legacy-simplemap' ) ) { $drop_sm = 'DROP TABLE `' . $wpdb->prefix. 'simple_map`;'; $drop_cats = 'DROP TABLE `' . $wpdb->prefix . 'simple_map_cats`;'; $wpdb->query( $drop_sm ); $wpdb->query( $drop_cats ); if ( $simple_map->legacy_tables_exist() ) { wp_redirect( admin_url( 'admin.php?page=simplemap-import-export&sm-msg=3' ) ); die(); } else { wp_redirect( admin_url( 'admin.php?page=simplemap-import-export&sm-msg=2' ) ); die(); } } } } // All location data function get_location_data_types( $init = array() ) { static $types = null; if ( empty( $types ) ) { $types = array( 'name' => __( 'Name', 'SimpleMap' ), 'address' => __( 'Address', 'SimpleMap' ), 'address2' => __( 'Address 2', 'SimpleMap' ), 'city' => __( 'City', 'SimpleMap' ), 'state' => __( 'State', 'SimpleMap' ), 'zip' => __( 'Zip', 'SimpleMap' ), 'country' => __( 'Country', 'SimpleMap' ), 'phone' => __( 'Phone', 'SimpleMap' ), 'fax' => __( 'Fax', 'SimpleMap' ), 'email' => __( 'Email', 'SimpleMap' ), 'url' => __( 'URL', 'SimpleMap' ), 'description' => __( 'Description', 'SimpleMap' ), 'special' => __( 'Special', 'SimpleMap' ), 'lat' => __( 'Lat', 'SimpleMap' ), 'lng' => __( 'Lng', 'SimpleMap' ), ); $legacy_types = array( 'category' => __( 'Legacy Taxonomy: Categories', 'SimpleMap' ), 'tags' => __( 'Legacy Taxonomy: Tags', 'SimpleMap' ), 'days' => __( 'Legacy Taxonomy: Days', 'SimpleMap' ), 'times' => __( 'Legacy Taxonomy: Times', 'SimpleMap' ), ); foreach ( get_object_taxonomies( 'sm-location', 'objects' ) as $taxonomy => $tax_info ) { $types['tax_' . $taxonomy] = __( 'Taxonomy: ' . $tax_info->label, 'SimpleMap' ); } foreach ( $init as $key => $value ) { if ( substr( $key, 0, 4 ) === 'tax_' ) { $types[$key] = __( 'Taxonomy: ' . ucwords( substr( $key, strpos( $key, '-' ) + 1 ) ), 'SimpleMap' ); } elseif ( isset( $legacy_types[$key] ) ) { $types[$key] = $legacy_types[$key]; } } $types = apply_filters( 'sm-data-types', $types ); } return $types; } // Imports a CSV file to WordPress function import_csv() { global $simple_map, $sm_locations, $wpdb, $current_user, $blog_id; // Define Importing Constant define( 'WP_IMPORTING', true ); if ( isset( $_POST['sm-action'] ) && 'import-csv' == $_POST['sm-action'] && isset( $_POST['step'] ) && 2 == $_POST['step'] ) { ?>
show_toolbar( $sm_page_title ); ?>

auto( $file_location ); if ( isset( $csv->data ) ) { echo '
    '; /* We're going to do some pre-processing to prevent WP's wp_get_unique_slug from pinging the database * a ridiculous amount of times in the event that this file is importing several thousand locations with * same name (like a franchise). */ $post_names = array(); $taxes = $simple_map->get_taxonomy_settings(); foreach ( $taxes as $taxonomy => $tax_info ) { $taxes[$taxonomy] = $tax_info['field']; } $types = $this->get_location_data_types( current( $csv->data ) ); $columns = array(); foreach ( $types as $key => $value ) { $taxonomy = null; // If custom taxonomies don't exist, register them temporarily in the event that we need to import them. if ( substr( $key, 0, 7 ) === 'tax_sm-' ) { $taxonomy = substr( $key, 4 ); $taxes[$taxonomy] = $key; } // Allow legacy taxonomy column names elseif ( array_search( $key, $taxes ) ) { $taxonomy = $key; } if ( isset( $taxonomy ) ) { $sm_locations->register_location_taxonomy( $taxonomy, $simple_map->get_taxonomy_settings( $taxonomy ) ); } $columns[$key] = str_replace( 'col_', '', array_search( $key, $_POST ) ); } $active_taxes = get_object_taxonomies( 'sm-location' ); $taxes = array_intersect_key( $taxes, array_flip( $active_taxes ) ); foreach ( $csv->data as $row => $location ) { // Give me 20 seconds for each location. That should be more than enough time. set_time_limit ( 20 ); // Convert assoc to int array since I can't trust the headings from the user $location = array_values( $location ); // Use the information the user gave me via select boxes to map columns to correct attributes foreach ( $columns as $key => $column ) { if ( isset( $location[$column] ) ) { $to_insert[$key] = trim( $location[$column] ); } else { $to_insert[$key] = ''; } } // Combine legacy taxonomy fields into new taxonomy fields. $legacy_taxes = $simple_map->get_taxonomy_settings(); foreach ( $legacy_taxes as $taxonomy => $legacy_taxonomy ) { $old_key = $legacy_taxonomy['field']; $key = 'tax_' . $taxonomy; if ( isset( $to_insert[$old_key] ) ) { $to_insert += array( $key => '' ); $to_insert[$key] = implode( ',', array_filter( array( $to_insert[$key], $to_insert[$old_key] ) ) ); unset( $to_insert[$old_key] ); } } // Prep and insert if ( isset( $to_insert ) ) { $options = $simple_map->get_options(); $geocoded = ''; // Maybe geo encode if ( ( empty( $to_insert['lat'] ) || empty( $to_insert['lng'] ) ) ) { if ( $geo = $simple_map->geocode_location( $to_insert['address'], $to_insert['city'], $to_insert['state'], $to_insert['zip'], $to_insert['country'], '' ) ) { $geocoded = __( 'geocoded and ', 'SimpleMap' ); if ( isset( $geo['lat'] ) ) { $to_insert['lat'] = $geo['lat']; } if ( isset( $geo['lng'] ) ) { $to_insert['lng'] = $geo['lng']; } } } // Prevent dup names before getting to wp_unique_slug function $clean_name = sanitize_title( $to_insert['name'] ); // Start by check to see if this post's name has been used before if ( isset( $post_names[$clean_name] ) ) { // Set the int to the value of the post_name key (this is set the first time we import a post with this title). $post_names_int = $post_names[$clean_name]; // Just to be safe, lets make sure the incremented name doesn't exist. Loop till we find one available. while( isset( $post_names[$clean_name . '-' . $post_names_int] ) ) { $post_names_int++; } // Set the new unique slug $unique_title = $clean_name . '-' . $post_names_int; // Add the post_name to the post attributes array we're about to insert $vars['post_name'] = $unique_title; // Update the original slug for this title with the new int $post_names[$clean_name] = $post_names[$unique_title] = $post_names_int; } else { // If we made it here, its the first time we're inserting a post with this title (this import anyway). // Add it to the post attributes array we're about to send to wp_insert_post $vars['post_name'] = $clean_name; // Log this title as used in the post_names array with an int of 1 $post_names[$clean_name] = 1; } // Prep for WordPress function wp_get_current_user(); $vars['post_title'] = $to_insert['name']; $vars['post_author'] = $current_user->ID; $vars['post_type'] = 'sm-location'; $vars['post_status'] = 'publish'; $vars['post_content'] = $to_insert['description']; // Insert into WordPress post table if ( $id = wp_insert_post( $vars ) ) { update_post_meta( $id, 'location_address', $to_insert['address'] ); update_post_meta( $id, 'location_address2', $to_insert['address2'] ); update_post_meta( $id, 'location_city', $to_insert['city'] ); update_post_meta( $id, 'location_state', $to_insert['state'] ); update_post_meta( $id, 'location_zip', $to_insert['zip'] ); update_post_meta( $id, 'location_country', $to_insert['country'] ); update_post_meta( $id, 'location_phone', $to_insert['phone'] ); update_post_meta( $id, 'location_fax', $to_insert['fax'] ); update_post_meta( $id, 'location_email', $to_insert['email'] ); update_post_meta( $id, 'location_url', $to_insert['url'] ); update_post_meta( $id, 'location_special', $to_insert['special'] ); update_post_meta( $id, 'location_lat', $to_insert['lat'] ); update_post_meta( $id, 'location_lng', $to_insert['lng'] ); foreach ( $taxes as $taxonomy => $tax_field ) { if ( isset( $to_insert[$tax_field] ) ) { // Place comma separated values into array $terms = explode( ',', $to_insert[$tax_field] ); // Loop through array. If term does not exist, create it. // Then associate the term with the location. foreach ( (array) $terms as $key => $name ) { $name = trim( $name ); // Skip it if we have bad data if ( empty( $name ) ) { continue; } // Grab or create and grab the category ID if ( $term_obj = get_term_by( 'name', $name, $taxonomy ) ) { $term_id = $term_obj->term_id; } else { $term_array = wp_insert_term( $name, $taxonomy ); if ( is_wp_error( $term_array ) ) { continue; } $term_id = $term_array['term_id']; } // This is just a failsafe. It also gives us access to vars the WP API created rather than from the CSV if ( ! is_wp_error( $term_id ) && $term = get_term( (int) $term_id, $taxonomy ) ) { if ( ! is_wp_error( $term ) ) { // Associate (last var appends term to rather than replaces existing terms) wp_set_object_terms( $id, $term->name, $taxonomy, true ); unset( $term ); } } } } } echo "
  1. " . sprintf( esc_attr( $to_insert['name'] ) . __( ' was successfully %simported', 'SimpleMap' ), $geocoded ) . "
  2. "; } else { echo "
  3. " . esc_attr( $to_insert['name'] ) . __( ' failed to import properly', 'SimpleMap' ) . "
  4. "; } unset( $to_insert ); unset( $geocoded ); } } echo ""; echo "

    " . sprintf( __( 'View them here', 'SimpleMap' ), admin_url( 'edit.php?post_type=sm-location' ) ) . "

    "; } // Import is finished, delete csv and redirect to edit locaitons page if ( file_exists( $file_location ) ) { unlink( $file_location ); } } ?>
get_options(); /* if ( !isset( $options['api_key'] ) ) $options['api_key'] = ''; */ extract( $options ); ?>
show_toolbar( $sm_page_title ); ?>

', '' );?>

|

get_location_data_types( current($csv->data) ); foreach( $csv->titles as $col => $title ) { echo ""; } ?> data ); if ( $row_count < 50 ) { foreach( $csv->data as $csv_row => $csv_row_data ) { ?> $tdv ) { ?>data[$numb] as $td => $tdv ) { ?>
" . $this->column_select( $col, $title ) . "
writable by WordPress: %s', 'http://codex.wordpress.org/Changing_File_Permissions#Permission_Scheme_for_WordPress', '' . WP_PLUGIN_DIR . '' ), 'SimpleMap' ); } ?>
"; $select .= ""; foreach( $this->get_location_data_types() as $type => $label ) { $select .= ""; } $select .= ""; return $select; } // Prints the options page function print_page() { if ( isset( $_POST['sm-action'] ) && 'import-csv' == $_POST['sm-action'] ) { $step = isset( $_POST['step'] ) ? absint( $_POST['step'] ) : 1; // Check for uploaded file with no errors. if ( ( 1 == $step && isset( $_FILES['simplemap-csv-upload'] ) && ! $_FILES['simplemap-csv-upload']['error'] > 0 ) || 2 == $step ) { switch( $step ) { case 2: $this->import_csv(); break; case 1: default : $this->do_csv_preview(); } } } else { global $simple_map; $options = $simple_map->get_options(); /* if ( !isset( $options['api_key'] ) ) $options['api_key'] = ''; */ extract( $options ); ?>
show_toolbar( $sm_page_title ); // Messages if ( isset( $_GET['sm-msg'] ) && '2' == $_GET['sm-msg'] ) echo '

'.__('Legacy SimpleMap settings deleted.', 'SimpleMap').'

'; if ( isset( $_GET['sm-msg'] ) && '3' == $_GET['sm-msg'] ) echo '

'.__('Legacy SimpleMap NOT settings deleted.', 'SimpleMap').'

'; ?>

', ''); ?>


" . __( sprintf( 'Please make the following directory writable by WordPress: %s', 'http://codex.wordpress.org/Changing_File_Permissions#Permission_Scheme_for_WordPress', '' . WP_PLUGIN_DIR . '' ), 'SimpleMap' ); ?>

API key if you need your locaitons geocoded.", 'SimpleMap' ), admin_url( "admin.php?page=simplemap" ) ); ?>

%s was purchased on %s by %s (%s). It will remain valid for this URL until %s.", get_ftps_site( $simplemap_ps ), date( "F d, Y", get_ftps_purchase_date( $simplemap_ps ) ), get_ftps_name( $simplemap_ps ), get_ftps_email( $simplemap_ps ), date( "F d, Y", get_ftps_exp_date( $simplemap_ps ) ) ); ?>

|

legacy_tables_exist() ) : ?>