|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
require_once dirname( __FILE__ ) . '/geo-location/class.jetpack-geo-location.php'; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Geo-location shortcode for display of location data associated with a post. |
|
7
|
|
|
* |
|
8
|
|
|
* Usage with current global $post: |
|
9
|
|
|
* [geo-location] |
|
10
|
|
|
* |
|
11
|
|
|
* Usage with specific post ID: |
|
12
|
|
|
* [geo-location post=5] |
|
13
|
|
|
*/ |
|
14
|
|
|
add_shortcode( 'geo-location', 'jetpack_geo_shortcode' ); |
|
15
|
|
|
|
|
16
|
|
|
function jetpack_geo_shortcode( $attributes ) { |
|
17
|
|
|
$attributes = shortcode_atts( array( 'post' => null, 'id' => null ), $attributes ); |
|
18
|
|
|
return jetpack_geo_get_location( $attributes['post'] ? $attributes['post'] : $attributes['id'] ); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Get the geo-location data associated with the supplied post ID, if it's available |
|
23
|
|
|
* and marked as being available for public display. The returned array will contain |
|
24
|
|
|
* "latitude", "longitude" and "label" keys. |
|
25
|
|
|
* |
|
26
|
|
|
* If you do not supply a value for $post_id, the global $post will be used, if |
|
27
|
|
|
* available. |
|
28
|
|
|
* |
|
29
|
|
|
* @param integer|null $post_id |
|
30
|
|
|
* |
|
31
|
|
|
* @return array|null |
|
32
|
|
|
*/ |
|
33
|
|
|
function jetpack_geo_get_data( $post_id = null) { |
|
34
|
|
|
$geo = Jetpack_Geo_Location::init(); |
|
35
|
|
|
|
|
36
|
|
|
if ( ! $post_id ) { |
|
|
|
|
|
|
37
|
|
|
$post_id = $geo->get_post_id(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
$meta_values = $geo->get_meta_values( $post_id ); |
|
41
|
|
|
|
|
42
|
|
|
if ( ! $meta_values['is_public'] || ! $meta_values['is_populated'] ) { |
|
43
|
|
|
return null; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
return array( |
|
47
|
|
|
'latitude' => $meta_values['latitude'], |
|
48
|
|
|
'longitude' => $meta_values['longitude'], |
|
49
|
|
|
'label' => $meta_values['label'] |
|
50
|
|
|
); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Display the label HTML for the geo-location information associated with the supplied |
|
55
|
|
|
* post ID. |
|
56
|
|
|
* |
|
57
|
|
|
* If you do not supply a value for $post_id, the global $post will be used, if |
|
58
|
|
|
* available. |
|
59
|
|
|
* |
|
60
|
|
|
* @param integer|null $post_id |
|
61
|
|
|
* |
|
62
|
|
|
* @return void |
|
63
|
|
|
*/ |
|
64
|
|
|
function jetpack_geo_display_location( $post_id = null ) { |
|
65
|
|
|
echo jetpack_geo_get_location( $post_id ); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Return the label HTML for the geo-location information associated with the supplied |
|
70
|
|
|
* post ID. |
|
71
|
|
|
* |
|
72
|
|
|
* If you do not supply a value for $post_id, the global $post will be used, if |
|
73
|
|
|
* available. |
|
74
|
|
|
* |
|
75
|
|
|
* @param integer|null $post_id |
|
76
|
|
|
* |
|
77
|
|
|
* @return string |
|
78
|
|
|
*/ |
|
79
|
|
|
function jetpack_geo_get_location( $post_id = null ) { |
|
80
|
|
|
return Jetpack_Geo_Location::init()->get_location_label( $post_id ); |
|
81
|
|
|
} |
|
82
|
|
|
|
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: