'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'] ) { ?>
'.__('Legacy SimpleMap settings deleted.', 'SimpleMap').'
'.__('Legacy SimpleMap NOT settings deleted.', 'SimpleMap').'