Exemplo n.º 1
0
 /**
  * Searches for map collections within specified bounds.
  */
 public static function get_map_collections_in_bounds()
 {
     $north = stripslashes_deep($_REQUEST['data']['north']);
     $east = stripslashes_deep($_REQUEST['data']['east']);
     $south = stripslashes_deep($_REQUEST['data']['south']);
     $west = stripslashes_deep($_REQUEST['data']['west']);
     header('Content-Type: application/json');
     echo json_encode(XMapsDatabase::get_map_collections_in_bounds($north, $east, $south, $west));
     exit;
 }
Exemplo n.º 2
0
 /**
  * Adds custom post type meta boxes (currently map) to
  * custom post type pages.
  */
 public static function add_meta_boxes()
 {
     if (get_option('xmaps-google-maps-api-key') === false) {
         add_meta_box('xmaps-location', 'Location', function () {
             require 'fragments/post-type/nolocation.php';
         }, 'map-object', 'normal', 'high');
     } else {
         add_meta_box('xmaps-location', 'Location', function () {
             require 'fragments/post-type/location.php';
         }, 'map-object', 'normal', 'high');
     }
     add_meta_box('xmaps-collections', 'Collections', function ($post) {
         $collections = XMapsDatabase::get_map_object_collections($post->ID);
         require 'fragments/post-type/collections.php';
     }, 'map-object', 'side', 'default');
 }
Exemplo n.º 3
0
        $location = wp_filter_nohtml_kses($_POST['xmaps-location-entry']);
        if ($comment_object->comment_approved) {
            XMapsDatabase::add_or_update_map_object_location($comment_id, 'map-object-comment', $location);
        } else {
            update_comment_meta($comment_id, 'xmaps-location', $location);
        }
    }
}, 99, 2);
add_action('comment_unapproved_to_approved', function ($comment) {
    $location = get_comment_meta($comment->comment_ID, 'xmaps-location', true);
    if (false !== $location) {
        XMapsDatabase::add_or_update_map_object_location($comment->comment_ID, 'map-object-comment', $location);
    }
});
add_action('trashed_comment', function ($cid) {
    XMapsDatabase::delete_map_object_location($cid, 'map-object-comment');
});
add_action('comment_form_logged_in_after', function () {
    if (get_post_type() == 'map-object') {
        ?>
<input id="xmaps-location-entry" name="xmaps-location-entry" type="hidden" />
		<div id="xmaps-controls">
			Drawing mode:
			<select id="xmaps-controls-mode">
				<option value="point">Point</option>
				<option value="area">Area</option>
			</select>
			<button id="xmaps-controls-draw">Draw</button>
			<button id="xmaps-controls-clear">Clear Map</button>
		</div>
		<div id="comment-map"></div><?php 
Exemplo n.º 4
0
 /**
  * Save post metadata when a post is saved.
  *
  * @param int  $post_id The post ID.
  * @param post $post The post object.
  * @param bool $update Whether this is an existing post being updated or not.
  */
 public static function on_save_map_object($post_id, $post, $update)
 {
     XMapsDatabase::add_or_update_map_object_location($post_id, 'map-object', $_REQUEST['xmaps-location-entry']);
     XMapsDatabase::add_or_update_map_object_collections($post_id, $_REQUEST['xmaps-map-collection-entry']);
 }
    ?>
		<div class="entry-meta">
			<?php 
    xmaps_posted_on();
    ?>
		</div><!-- .entry-meta -->
		<?php 
}
?>
	</header><!-- .entry-header -->

	<div class="entry-content">
		<?php 
the_content(sprintf(wp_kses(__('Continue reading %s <span class="meta-nav">&rarr;</span>', 'xmaps'), array('span' => array('class' => array()))), the_title('<span class="screen-reader-text">"', '"</span>', false)));
wp_link_pages(array('before' => '<div class="page-links">' . esc_html__('Pages:', 'xmaps'), 'after' => '</div>'));
$map_objects = XMapsDatabase::get_collection_map_objects(get_the_ID());
foreach ($map_objects as $mo) {
    $mo[0]->permalink = get_permalink($mo[0]->ID);
}
?>
		<div id="xmaps-map" style="height: 480px;"></div>
		<script>
		jQuery( function( $ ) {
				var conf = {
					"center": new google.maps.LatLng(0, 0),
					"streetViewControl": false,
					"zoom": 1,
					"minZoom": 1,
					"maxZoom": 20,
					"mapTypeId": google.maps.MapTypeId.TERRAIN,
					"panControl": true,
Exemplo n.º 6
0
<?php

/**
 * Display fragment for Map Object post edit screen.
 *
 * @package xmaps
 * @author Dominic Price <*****@*****.**>
 * @license http://www.gnu.org/licenses/agpl-3.0.en.html
 * @link https://github.com/horizon-institute/xmaps
 */
$locations = XMapsDatabase::get_map_object_locations(get_the_ID(), 'map-object');
$location = '';
if (!empty($locations)) {
    $location = $locations[0];
}
?>
<div id="xmaps-controls">
	Drawing mode: 
	<select id="xmaps-controls-mode">
		<option value="point">Point</option>
		<option value="area">Area</option>
	</select>
	<button id="xmaps-controls-draw">Draw</button>
	<button id="xmaps-controls-clear">Clear Map</button>
</div>
<input type="hidden" name="xmaps-location-entry" id="xmaps-location-entry" 
		value="<?php 
echo esc_attr($location->location);
?>
" />
<div id="xmaps-map" style="height: 480px;"></div>
Exemplo n.º 7
0
 /**
  * Logs a user's location.
  *
  * @param WP $wp Wordpress object.
  * @return boolean True if the request was handled.
  */
 private static function location($wp)
 {
     if (isset($wp->query_vars['lat']) && isset($wp->query_vars['lon']) && isset($wp->query_vars['acc']) && isset($wp->query_vars['user-id']) && isset($wp->query_vars['collection-id'])) {
         $collection = get_post($wp->query_vars['collection-id']);
         if (!$collection) {
             return false;
         }
         $user = XMapsUser::get_user_by_api_key($wp->query_vars['key']);
         if ($user->id != $wp->query_vars['user-id']) {
             return false;
         }
         $geom = new Point($wp->query_vars['lon'], $wp->query_vars['lat']);
         $geom->setSRID(XMAPS_SRID);
         $wkt = new WKT();
         $location = $wkt->write($geom);
         XMapsDatabase::log_location($user->id, $wp->query_vars['key'], $wp->query_vars['collection-id'], $location, floatval($wp->query_vars['acc']));
         return true;
     }
     return false;
 }
		<?php 
if (is_single()) {
    the_title('<h1 class="entry-title">', '</h1>');
} else {
    the_title('<h2 class="entry-title"><a href="' . esc_url(get_permalink()) . '" rel="bookmark">', '</a></h2>');
}
?>
	</header><!-- .entry-header -->

	<div class="entry-content">
		<?php 
the_content(sprintf(wp_kses(__('Continue reading %s <span class="meta-nav">&rarr;</span>', 'xmaps'), array('span' => array('class' => array()))), the_title('<span class="screen-reader-text">"', '"</span>', false)));
the_meta();
wp_link_pages(array('before' => '<div class="page-links">' . esc_html__('Pages:', 'xmaps'), 'after' => '</div>'));
$locations = XMapsDatabase::get_map_object_locations(get_the_ID(), 'map-object');
$locations = array_merge($locations, XMapsDatabase::get_map_object_comment_locations(get_the_ID()));
?>
		<div id="xmaps-map" style="height: 480px;"></div>
		<script>
		jQuery( function( $ ) {
				var conf = {
					"center": new google.maps.LatLng(0, 0),
					"streetViewControl": false,
					"zoom": 1,
					"minZoom": 1,
					"maxZoom": 20,
					"mapTypeId": google.maps.MapTypeId.TERRAIN,
					"panControl": true,
					"mapTypeControl": true
			        };
				var map_div = $("#xmaps-map");
Exemplo n.º 9
0
    /**
     * Searches for map collections within specified bounds.
     *
     * @param float $north Northmost bound.
     * @param float $east Eastmost bound.
     * @param float $south Southmost bound.
     * @param float $west Westmost bound.
     */
    public static function get_map_collections_in_bounds($north, $east, $south, $west)
    {
        global $wpdb;
        $tbl_name = $wpdb->get_blog_prefix(get_current_blog_id()) . self::LOCATION_TABLE_SUFFIX;
        $sql = 'SELECT l.reference_id
			FROM ' . $tbl_name . ' l
			WHERE l.reference_type = \'map-object\'
			AND ST_Intersects(l.location,
			ST_GeomFromText(\'POLYGON((%f %f, %f %f,
		%f %f, %f %f, %f %f))\'))';
        $results = $wpdb->get_results($wpdb->prepare($sql, array($west, $south, $east, $south, $east, $north, $west, $north, $west, $south)), OBJECT);
        $collections = array();
        foreach ($results as $result) {
            $tbl_name = $wpdb->get_blog_prefix(get_current_blog_id) . self::COLLECTION_TABLE_SUFFIX;
            $sql = 'SELECT c.collection_id, p.post_title
				FROM ' . $tbl_name . ' AS c
				LEFT JOIN ' . $wpdb->posts . ' p 
				ON p.id = c.collection_id
				WHERE map_object_id = %d';
            $results2 = $wpdb->get_results($wpdb->prepare($sql, array($result->reference_id)), OBJECT);
            foreach ($results2 as $r) {
                if (!array_key_exists($r->collection_id, $collections)) {
                    $collections[$r->collection_id] = $r;
                    $map_objects = XMapsDatabase::get_collection_map_objects($r->collection_id);
                    $locs = [];
                    foreach ($map_objects as $mo) {
                        $mo = $mo[1];
                        $locs[] = $mo->location;
                    }
                    $g = geoPHP::load('GEOMETRYCOLLECTION(' . implode(',', $locs) . ')');
                    $r->location = $g->centroid()->out('wkt');
                }
            }
        }
        foreach ($collections as $key => $collection) {
            $collection->permalink = get_permalink($collection->collection_id);
        }
        return $collections;
    }
Exemplo n.º 10
0
require_once 'xmaps-post-type.php';
require_once 'xmaps-settings.php';
require_once 'xmaps-wa-api.php';
require_once 'xmaps-user.php';
register_activation_hook(__FILE__, function () {
    XMapsDatabase::create_tables(null);
    if (is_multisite()) {
        foreach (wp_get_sites() as $site) {
            XMapsDatabase::create_tables($site['blog_id']);
        }
    }
    XMapsPostType::register_post_types();
    flush_rewrite_rules();
});
add_action('wpmu_new_blog', function ($blog_id) {
    XMapsDatabase::create_tables($blog_id);
});
add_action('init', function () {
    XMapsPostType::register_post_types();
    remove_role('xmapper');
    add_role('xmapper', 'Mapper', array('read' => true, 'upload_files' => true, 'publish_xmaps' => true, 'read_private_xmaps' => false, 'edit_xmaps' => true, 'edit_published_xmaps' => true, 'edit_others_xmaps' => false, 'edit_private_xmaps' => true, 'delete_xmaps' => true, 'delete_published_xmaps' => true, 'delete_others_xmaps' => false, 'delete_private_xmaps' => true, 'manage_xmaps_tags' => true));
    global $wp_roles;
    $roles = $wp_roles->get_names();
    foreach ($roles as $k => $v) {
        if ('xmapper' == $k) {
            continue;
        }
        $role = $wp_roles->get_role($k);
        if ($role->has_cap('publish_posts')) {
            $role->add_cap('publish_xmaps');
        }