array( 'name' => __( 'Aesop Map Marker', 'aesop-core' ), // name of the component 'type' => 'single', // single - wrap 'atts' => array( 'title' => array( 'type' => 'text', // a small text field 'default' => '', 'desc' => __( 'Title', 'aesop-core' ), 'tip' => __( 'By default we\'ll display an H2 heading with the text you specify here.', 'aesop-core' ) ), 'hidden' => array( 'type' => 'select', // a select dropdown 'values' => array( array( 'value' => 'off', 'name' => __( 'Off', 'aesop-core' ) ), array( 'value' => 'on', 'name' => __( 'On', 'aesop-core' ) ) ), 'default' => '', 'desc' => __( 'Hide this marker', 'aesop-core' ), 'tip' => __( 'Optionally hide this marker but retain the scroll to point in the map.', 'aesop-core' ) ) ) ) ); return array_merge( $shortcodes, $custom ); } /** * Add an icon to our placeholder * * @subpackage Component API * @since 1.3 */ public function icon() { $icon = '\f230'; // css code for dashicon $slug = 'map_marker'; // name of component wp_add_inline_style( 'ai-core-styles', '#aesop-generator-wrap li.'.$slug.' {display:none;} #aesop-generator-wrap li.'.$slug.' a:before {content: "'.$icon.'";}' ); } /** * New metabox to select map markers on the map * * @since 1.3 */ public function new_map_box() { $screens = apply_filters( 'aesop_map_meta_location', array( 'post','page' ) ); foreach ( $screens as $screen ) { add_meta_box( 'ase_map_component', __( 'Map Locations', 'aesop-core' ), array( $this, 'render_map_box' ), $screen ); } } /** * Render Meta Box content. * * @param WP_Post $post The post object. * @since 1.3 * */ public function render_map_box( $post ) { echo '
'; wp_nonce_field( 'ase_map_meta', 'ase_map_meta_nonce' ); echo '
'; echo "Starting location: "; echo __( 'Hint: Type to search for locations', 'aesop-core' ); echo __( '
Note: Aesop Map component uses Google Map API. Recommended: Obtain and set your own Google Map API Key by going to Appearance->Customize->Aesop Story Engine.
', 'aesop-core' ); echo '
'; $ase_map_locations = get_post_meta( $post->ID, 'ase_map_component_locations' ); $ase_map_start_point = get_post_meta( $post->ID, 'ase_map_component_start_point', true ); $get_map_zoom = get_post_meta( $post->ID, 'ase_map_component_zoom', true ); $ase_map_start_point = empty ( $ase_map_start_point ) ? array( 29.76, -95.38 ) : array( $ase_map_start_point['lat'], $ase_map_start_point['lng'] ); $ase_map_zoom = empty ( $get_map_zoom ) ? 12 : $get_map_zoom; $ase_map_start_point = json_encode( $ase_map_start_point ); $ase_map_locations = json_encode( $ase_map_locations ); $tiles = aesop_map_tile_provider( $post->ID ); ?>

'; $out .= __( 'Welcome to Aesop Story Engine 1.3. We need to upgrade any map markers that you might have. Click here to start the upgrade process.', 'aesop-core' ); $out .= '

'; echo $out; } } /** * Check to see if our old post meta exists * if it does exist then proceed with the upgrade * * @since 1.3 * @return string true if old meta exists, false if not */ public function aesop_check_for_old_markers() { $posts = get_posts( array( 'post_type' => array( 'page', 'post' ), 'posts_per_page' => 100 ) ); $return = ''; if ( $posts ) : foreach ( $posts as $post ) { $meta = get_post_meta( get_the_ID(), 'aesop_map_component_locations', true ); if ( ! empty ( $meta ) ) { $return = 'true'; } else { $return = 'false'; } } endif; return $return; } /** * When the user starts the upgrade process let's run a function to map the old meta to the new meta * * @since 1.3 */ public function upgrade_marker_meta() { check_ajax_referer( 'aesop-map-upgrade', 'security' ); if ( ! current_user_can( 'manage_options' ) ) { return; } // ok security passes so let's process some data if ( isset( $_POST['action'] ) && $_POST['action'] !== 'upgrade_marker_meta' ) { return; } // get the posts with the maps shortode $posts = get_posts( array( 'post_type' => array( 'page', 'post' ), 'posts_per_page' => 100 ) ); if ( $posts ) : foreach ( $posts as $post ) { $id = $post->ID; // at this point we have an array of posts that have our shortcodes // now let's loop through the map meta in this post and map to the new meta $old_locations = get_post_meta( $id, 'aesop_map_component_locations' ); if ( ! empty ( $old_locations ) ) { foreach ( $old_locations as $location ) { $translated = array(); $translated['lat'] = $location['lat']; $translated['lng'] = $location['long']; $translated['title'] = $location['content']; add_post_meta( $id, 'ase_map_component_locations', $translated ); } } $old_zoom = get_post_meta( $id, 'aesop_map_component_zoom' ); if ( ! empty ( $old_zoom ) && is_numeric( $old_zoom ) ) { update_post_meta( $id, 'ase_map_component_zoom', $old_zoom ); } $old_start_point = get_post_meta( $id, 'aesop_map_start', true ); if ( ! empty ( $old_start_point ) ) { echo $old_start_point; $old_start_point = explode( ',', $old_start_point ); if ( count( $old_start_point ) == 2 ) { $translated = array(); $translated['lat'] = $old_start_point[0]; $translated['lng'] = $old_start_point[1]; update_post_meta( $id, 'ase_map_component_start_point', $translated ); } } delete_post_meta( $id, 'aesop_map_component_locations' ); delete_post_meta( $id, 'aesop_map_start' ); delete_post_meta( $id, 'aesop_map_component_zoom' ); }//end foreach endif; update_option( 'ase_upgraded_to', AI_CORE_VERSION ); echo 'SUCCESS'; // die for ajax die(); } /** * Handles the click function for upgrading the old map meta to the new map meta * * @since 1.3 */ public function upgrade_click_handle() { $nonce = wp_create_nonce( 'aesop-map-upgrade' ); // only run if we have markers and have never upgraded if ( get_option( 'ase_upgraded_to' ) < AI_CORE_VERSION && 'true' == self::aesop_check_for_old_markers() ) { ?>

'; $out .= __( 'Welcome to Aesop Story Engine 1.5. We need to upgrade your Mapbox Map ID. Click here to start the upgrade process.', 'aesop-core' ); $out .= '

'; echo $out; } } /** * Handles the click function for upgrading mapbox id * * @since 1.5 */ public function upgrade_mapbox_click_handle() { $mapbox_upgrade_option = get_option( 'ase_mapbox_upgraded' ); $nonce = wp_create_nonce( 'aesop-mapbox-upgrade' ); $old_option = get_option( 'ase_mapbox_id' ); // only run if we haven't previously updated the mapbox id and it's still the default value if ( empty( $mapbox_upgrade_option ) && ( 'aesopinteractive.hkoag9o3' == $old_option || empty( $old_option ) ) ) { ?>