Exemplo n.º 1
0
 public function scripts()
 {
     if (lasso_user_can('edit_posts')) {
         wp_enqueue_style('lasso-style', LASSO_URL . '/public/assets/css/lasso.css', LASSO_VERSION, true);
         wp_enqueue_script('jquery-ui-autocomplete');
         wp_enqueue_script('jquery-ui-draggable');
         wp_enqueue_script('jquery-ui-sortable');
         wp_enqueue_script('jquery-ui-slider');
         // media uploader
         wp_enqueue_media();
         // url for json api
         $home_url = function_exists('json_get_url_prefix') ? json_get_url_prefix() : false;
         $article_object = lasso_editor_get_option('article_class', 'lasso_editor');
         $article_object = empty($article_object) && lasso_get_supported_theme_class() ? lasso_get_supported_theme_class() : $article_object;
         $featImgClass = lasso_editor_get_option('featimg_class', 'lasso_editor');
         $titleClass = lasso_editor_get_option('title_class', 'lasso_editor');
         $toolbar_headings = lasso_editor_get_option('toolbar_headings', 'lasso_editor');
         $objectsNoSave = lasso_editor_get_option('dont_save', 'lasso_editor');
         // post id reference
         $postid = get_the_ID();
         $strings = array('save' => __('Save', 'lasso'), 'saving' => __('Saving...', 'lasso'), 'saved' => __('Saved!', 'lasso'), 'adding' => __('Adding...', 'lasso'), 'added' => __('Added!', 'lasso'), 'loading' => __('Loading...', 'lasso'), 'loadMore' => __('Load More', 'lasso'), 'noPostsFound' => __('No more posts found', 'lasso'), 'galleryCreated' => __('Gallery Created!', 'lasso'), 'galleryUpdated' => __('Gallery Updated!', 'lasso'), 'justWrite' => __('Just write...', 'lasso'), 'chooseImage' => __('Choose an image', 'lasso'), 'updateImage' => __('Update Image', 'lasso'), 'insertImage' => __('Insert Image', 'lasso'), 'selectImage' => __('Select Image', 'lasso'), 'removeFeatImg' => __('Remove featured image?', 'lasso'), 'updateSelectedImg' => __('Update Selected Image', 'lasso'), 'chooseImages' => __('Choose images', 'lasso'), 'editImage' => __('Edit Image', 'lasso'), 'addImages' => __('Add Images', 'lasso'), 'addNewGallery' => __('Add New Gallery', 'lasso'), 'selectGallery' => __('Select Lasso Gallery Image', 'lasso'), 'useSelectedImages' => __('Use Selected Images', 'lasso'), 'publishPost' => __('Publish Post?', 'lasso'), 'publishYes' => __('Yes, publish it!', 'lasso'), 'deletePost' => __('Trash Post?', 'lasso'), 'deleteYes' => __('Yes, trash it!', 'lasso'), 'warning' => __('Oh snap!', 'laso'), 'cancelText' => __('O.K. got it!', 'lasso'), 'missingClass' => __('It looks like we are missing the Article CSS class. Lasso will not function correctly without this CSS class.', 'lasso'), 'missingConfirm' => __('Update Settings', 'lasso'), 'helperText' => __('one more letter', 'lasso'), 'editingBackup' => __('You are currently editing a backup copy of this post.'));
         $api_url = trailingslashit(home_url()) . 'lasso-internal-api';
         $gallery_class = new gallery();
         $gallery_nonce_action = $gallery_class->nonce_action;
         $gallery_nonce = wp_create_nonce($gallery_nonce_action);
         // localized objects
         $objects = array('ajaxurl' => esc_url($api_url), 'editor' => 'lasso--content', 'article_object' => $article_object, 'featImgClass' => $featImgClass, 'titleClass' => $titleClass, 'strings' => $strings, 'settingsLink' => function_exists('is_multisite') && is_multisite() ? network_admin_url('settings.php?page=lasso-editor') : admin_url('admin.php?page=lasso-editor-settings'), 'post_status' => get_post_status($postid), 'postid' => $postid, 'permalink' => get_permalink(), 'edit_others_pages' => current_user_can('edit_others_pages') ? 'true' : 'false', 'edit_others_posts' => current_user_can('edit_others_posts') ? 'true' : 'false', 'userCanEdit' => current_user_can('edit_post', $postid), 'can_publish_posts' => current_user_can('publish_posts'), 'can_publish_pages' => current_user_can('publish_pages'), 'author' => is_user_logged_in() ? get_current_user_ID() : false, 'nonce' => wp_create_nonce('lasso_editor'), 'handle' => lasso_editor_settings_toolbar(), 'toolbar' => lasso_editor_text_toolbar(), 'toolbarHeadings' => $toolbar_headings, 'component_modal' => lasso_editor_component_modal(), 'component_sidebar' => lasso_editor_component_sidebar(), 'components' => lasso_editor_components(), 'wpImgEdit' => lasso_editor_wpimg_edit(), 'featImgControls' => lasso_editor_image_controls(), 'featImgNonce' => $gallery_nonce, 'getGallImgNonce' => $gallery_nonce, 'createGallNonce' => $gallery_nonce, 'swapGallNonce' => $gallery_nonce, 'titleNonce' => wp_create_nonce('lasso_update_title'), 'wpImgNonce' => wp_create_nonce('lasso_update_wpimg'), 'deletePost' => wp_create_nonce('lasso_delete_post'), 'searchPosts' => wp_create_nonce('lasso_search_posts'), 'component_options' => lasso_editor_options_blob(), 'newPostModal' => lasso_editor_newpost_modal(), 'allPostModal' => lasso_editor_allpost_modal(), 'mapFormFooter' => lasso_map_form_footer(), 'refreshRequired' => lasso_editor_refresh_message(), 'objectsNoSave' => $objectsNoSave, 'supportedNoSave' => lasso_supported_no_save(), 'postCategories' => lasso_get_objects('category'), 'postTags' => lasso_get_objects('tag'), 'noResultsDiv' => lasso_editor_empty_results(), 'noRevisionsDiv' => lasso_editor_empty_results('revision'), 'mapTileProvider' => function_exists('aesop_map_tile_provider') ? aesop_map_tile_provider($postid) : false, 'mapLocations' => get_post_meta($postid, 'ase_map_component_locations'), 'mapStart' => get_post_meta($postid, 'ase_map_component_start_point', true), 'mapZoom' => get_post_meta($postid, 'ase_map_component_zoom', true), 'revisionModal' => lasso_editor_revision_modal());
         // wp api client
         wp_enqueue_script('wp-api-js', LASSO_URL . '/public/assets/js/source/util--wp-api.js', array('jquery', 'underscore', 'backbone'), LASSO_VERSION, true);
         $settings = array('root' => home_url($home_url), 'nonce' => wp_create_nonce('wp_json'));
         wp_localize_script('wp-api-js', 'WP_API_Settings', $settings);
         $postfix = defined('SCRIPT_DEBUG') && true === SCRIPT_DEBUG ? '' : '.min';
         wp_enqueue_script('lasso', LASSO_URL . "/public/assets/js/lasso{$postfix}.js", array('jquery'), LASSO_VERSION, true);
         wp_localize_script('lasso', 'lasso_editor', apply_filters('lasso_localized_objects', $objects));
     }
 }
Exemplo n.º 2
0
    /**
     *  Render Meta Box content.
     *
     * @param WP_Post $post The post object.
     * @since 1.3
     *
     */
    public function render_map_box($post)
    {
        echo '<div class="aesop-map-data" style="display: hidden;">';
        wp_nonce_field('ase_map_meta', 'ase_map_meta_nonce');
        echo '</div>';
        echo "Starting location: <input type='text' id='aesop-map-address'/>";
        echo __('<em>Hint: Type to search for locations</em>', 'aesop-core');
        echo '<div id="aesop-map" style="height:350px;"></div>';
        $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);
        ?>
			<!-- Aesop Maps -->
			<script>

				jQuery(document).ready(function(){

					var start_point = <?php 
        echo $ase_map_start_point;
        ?>
;
					var start_zoom = <?php 
        echo absint($ase_map_zoom);
        ?>
;

					var map = L.map('aesop-map',{
						scrollWheelZoom: false,
						zoom: start_zoom,
						center: start_point
					});

					setMapCenter(start_point[0],start_point[1]);

					jQuery('#aesop-map-address').geocomplete().bind('geocode:result', function(event, result){
						var lat = result.geometry.location.k;
						var lng = result.geometry.location.B;
						map.panTo(new L.LatLng(lat,lng));
						setMapCenter(lat,lng);
  					});

					L.tileLayer('<?php 
        echo $tiles;
        ?>
', {
						maxZoom: 20
					}).addTo(map);

					<?php 
        if (!empty($ase_map_locations)) {
            ?>
						var ase_map_locations = <?php 
            echo $ase_map_locations;
            ?>
					<?php 
        }
        ?>

					ase_map_locations.forEach(function(location) {
						createMapMarker([location['lat'],location['lng']],location['title']).addTo(map);
						createMarkerField( marker._leaflet_id, encodeMarkerData(location['lat'], location['lng'], location['title']) );
					});

					// adding a new marker
					map.on('click', onMapClick);
					map.on('dragend', onMapDrag);
					map.on('zoomend', onMapZoom);

					function setMapCenter(k, B) {
						var ldata = encodeLocationData(k,B);
						jQuery('input[name="ase-map-component-start-point"]').remove();
						jQuery('.aesop-map-data').append('<input type="hidden" name="ase-map-component-start-point" data-ase="map" value="' + ldata + '">');
						jQuery('#aesop-map-address').val(k + ', ' + B);
					}

					function setMapZoom(z) {
						jQuery('input[name="ase-map-component-zoom"]').remove();
						jQuery('.aesop-map-data').append('<input type="hidden" name="ase-map-component-zoom" data-ase="map" value="' + z + '">');
					}

					function onMarkerDrag(e) {
						updateMarkerField(e.target);
					}

					function onMapDrag(e) {
						var mapCenter = e.target.getCenter()
						setMapCenter(rnd(mapCenter.lat),rnd(mapCenter.lng));
					}

					function onMapZoom(e) {
						setMapZoom(e.target.getZoom());
					}

					function rnd(n) {
						return Math.round(n * 100) / 100
					}

					function onMapClick(e) {

					    var geojsonFeature = {

					        "type": "Feature",
					        "properties": {},
					        "geometry": {
					                "type": "Point",
					                "coordinates": [e.latlng.lat, e.latlng.lng]
					        }
					    }

					    var marker;

					    L.geoJson(geojsonFeature, {

					        pointToLayer: function(feature, latlng){

					            marker = L.marker(e.latlng, {

					                title: 'Resource Location',
					                alt: 'Resource Location',
					                riseOnHover: true,
					                draggable: true,

					            }).bindPopup("\
					            	<input type='text' name='ase_marker_text[]' value='Location Title'>\
					            	<a class='marker-update-button dashicons dashicons-yes'/></a>\
					            	<a class='marker-delete-button dashicons dashicons-trash'/></a>\
					            	");

					            marker.on('popupopen', onPopupOpen);
					            marker.on('dragend', onMarkerDrag);

					            return marker;
					        }
					    }).addTo(map);

					   	createMarkerField( marker._leaflet_id, encodeMarkerData(e.latlng.lat, e.latlng.lng, 'Location Title') );

					}

					// open popup
					function onPopupOpen() {

					    var tempMarker = this;

					    // To remove marker on click of delete button in the popup of marker
					    jQuery('.marker-delete-button:visible').click(function () {
					    	jQuery('input[data-marker="' + tempMarker._leaflet_id + '"]').remove();
					      	map.removeLayer(tempMarker);
					    });

					    // Update the title of the location
					    jQuery('.marker-update-button:visible').click(function (t) {
					    	var title = t.target.previousElementSibling.value;
					    	var tdata = encodeMarkerData(tempMarker._latlng.lat, tempMarker._latlng.lng, title);
					    	jQuery('input[data-marker="' + tempMarker._leaflet_id + '"]').val(tdata);
					    	tempMarker.options.title = title;
					    	tempMarker.closePopup();
					    	tempMarker.bindPopup("\
						            	<input type='text' name='ase_marker_text[]' value='" + title + "'>\
						            	<a class='marker-update-button dashicons dashicons-yes'/></a>\
						            	<a class='marker-delete-button dashicons dashicons-trash'/></a>\
						            	");
					    });
					}

					// create map marker
					function createMapMarker(latlng, title) {
			            marker = L.marker(latlng, {
			              	title: title,
			              	alt: title,
			              	riseOnHover: true,
			              	draggable: true,
			            }).bindPopup("\
			            	<input type='text' name='ase_marker_text[]' value='" + title + "'>\
			            	<a class='marker-update-button dashicons dashicons-yes'/></a>\
			            	<a class='marker-delete-button dashicons dashicons-trash'/></a>\
			            	");
			            marker.on('popupopen', onPopupOpen);
			            marker.on('dragend', onMarkerDrag);
			            return marker;
					}

					function getAllMarkers() {
					    var allMarkersObjArray = []; // for marker objects
					    var allMarkersGeoJsonArray = []; // for readable geoJson markers
					    jQuery.each(map._layers, function (ml) {
					        if (map._layers[ml].feature) {
					          	allMarkersObjArray.push(this)
					          	allMarkersGeoJsonArray.push(JSON.stringify(this.toGeoJSON()))
					        }
					    })
					}

					// let's create a hidden form element for the marker
					function createMarkerField(mid, mdata) {
					  	jQuery('.aesop-map-data').append('<input type="hidden" name="ase-map-component-locations[]" data-ase="map" data-marker="' + mid + '" value="' + mdata + '">');
					}

					function updateMarkerField(m) {
						var tdata = encodeMarkerData(m._latlng.lat, m._latlng.lng, m.options.title);
						jQuery('input[data-marker="' + m._leaflet_id + '"]').val(tdata);
					}

					// encode the information into a string
					function encodeMarkerData(mlat, mlng, mtitle) {
						return encodeURIComponent(JSON.stringify({lat: mlat, lng: mlng, title: mtitle}));
					}

					// encode location into a string
					function encodeLocationData(mlat, mlng) {
						return encodeURIComponent(JSON.stringify({lat: mlat, lng: mlng}));
					}

					// decode the information
					function decodeMarkerData(mdata) {
						return decodeURIComponent(JSON.parse(mdata));
					}
				});
			</script>
		<?php 
    }
Exemplo n.º 3
0
    public function aesop_map_loader()
    {
        global $post;
        $id = isset($post) ? $post->ID : null;
        $markers = isset($post) ? get_post_meta($id, 'ase_map_component_locations', false) : false;
        $start = isset($post) && self::get_map_meta($id, 'ase_map_component_start') ? self::get_map_meta($id, 'ase_map_component_start') : self::start_fallback($markers);
        $zoom = isset($post) && self::get_map_meta($id, 'ase_map_component_zoom') ? self::get_map_meta($id, 'ase_map_component_zoom') : 12;
        $default_location = is_single();
        $location = apply_filters('aesop_map_component_appears', $default_location);
        $tiles = isset($post) ? aesop_map_tile_provider($post->ID) : false;
        if (function_exists('aesop_component_exists') && aesop_component_exists('map') && $location) {
            ?>
			<!-- Aesop Locations -->
			<script>

				<?php 
            if ($markers) {
                ?>

					var map = L.map('aesop-map-component',{
						scrollWheelZoom: false,
						zoom: <?php 
                echo wp_filter_nohtml_kses(round($zoom));
                ?>
,
						center: [<?php 
                echo $start;
                ?>
]
					});

					L.tileLayer('<?php 
                echo $tiles;
                ?>
', {
						maxZoom: 20
					}).addTo(map);

					<?php 
                foreach ($markers as $marker) {
                    $lat = $marker['lat'];
                    $long = $marker['lng'];
                    $text = $marker['title'] ? $marker['title'] : null;
                    $loc = sprintf('%s,%s', esc_attr($lat), esc_attr($long));
                    // if market content is set run a popup
                    if ($text) {
                        ?>

							L.marker([<?php 
                        echo $loc;
                        ?>
]).addTo(map).bindPopup('<?php 
                        echo aesop_component_media_filter($text);
                        ?>
').openPopup();

						<?php 
                    } else {
                        ?>

							L.marker([<?php 
                        echo $loc;
                        ?>
]).addTo(map);

						<?php 
                    }
                }
            } else {
                if (is_user_logged_in()) {
                    $url = admin_url('post.php?post=' . $id . '&action=edit');
                    $editlink = sprintf('<a href="%s">here</a>', $url);
                    ?>
jQuery('#aesop-map-component').append('<div class="aesop-error aesop-content"><?php 
                    echo __("Your map appears to be empty! Setup and configure your map markers in this post {$editlink}.", 'aesop-core');
                    ?>
</div>');<?php 
                }
            }
            ?>
			</script>

		<?php 
        }
        //end if
    }