-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
100 lines (55 loc) · 2.31 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/*
Plugin Name: OpenStreetMap Maps
Plugin URI: http://www.osclass.org/
Description: This plugin shows an OpenStreetMap on the location space of every item.
Version: 1.0.3
Author: Oleksiy Muzalyev
Author URI: http://forums.osclass.org/index.php?action=profile;u=37193
Plugin update URI: openstreetmaps-maps_2
*/
/* Register and get your free API key, MAPQUEST_API_KEY, at https://developer.mapquest.com/ . It takes a minute or so. */
const MAPQUEST_API_KEY ='your_API_key_here'; // it should look like this: MAPQUEST_API_KEY ='Mf0UOnA76bfMm6Gzpqj8dFFBMGxP7KhY';
/* ============= Do not change anything below this line. ============= */
function osm_maps_location() {
$item = osc_item();
osc_osm_maps_header();
require 'map.php';
}
// HELPER
function osc_osm_maps_header() {
echo '<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />',
'<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>',
'<style> #map { height: 240px; width: 100%;}</style>';
}
function osm_insert_geo_location ( $item ) {
$itemId = $item['pk_i_id'];
$aItem = Item::newInstance()->findByPrimaryKey ( $itemId );
$address = '';
$addr_comp = array();
if ( isset ( $aItem['s_address'] ) ) {
$addr_comp[] = $aItem['s_address'];
}
if ( isset ( $aItem['s_city'] ) ) {
$addr_comp[] = $aItem['s_city'];
}
if ( isset ( $aItem['s_region'] ) ) {
$addr_comp[] = $aItem['s_region'];
}
if ( isset ( $aItem['s_country'] ) ) {
$addr_comp[] = $aItem['s_country'];
}
$address = implode ( ',', $addr_comp );
if ( $xml = simplexml_load_file ( sprintf ( 'http://open.mapquestapi.com/nominatim/v1/search.php?key=' . MAPQUEST_API_KEY . '&q=%s&format=xml&addressdetails=1&limit=1', $address ) ) ) {
foreach ( $xml->place as $mpl ) {
$lat = $mpl['lat'];
$lng = $mpl['lon'];
}
ItemLocation::newInstance()->update ( array ( 'd_coord_lat' => $lat ,'d_coord_long' => $lng ) , array('fk_i_item_id' => $itemId ) );
}
}
osc_add_hook('location', 'osm_maps_location');
osc_add_hook('posted_item', 'osm_insert_geo_location');
osc_add_hook('edited_item', 'osm_insert_geo_location');
osc_register_plugin(osc_plugin_path(__FILE__), '') ;
?>