-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfield.geocoder.php
120 lines (101 loc) · 3.04 KB
/
field.geocoder.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php defined('BASEPATH') or exit('No direct script access allowed');
/**
* PyroStreams Geocoder Field Type
*
* Generate longitude and latitude from a specified location
*
* @package PyroStreams
* @author David Lewis
* @copyright Copyright (c) 2012, David Lewis
*/
class Field_geocoder {
public $field_type_slug = 'geocoder';
public $db_col_type = 'varchar';
public $version = '1.0.0';
public $author = array('name' => 'David Lewis', 'url' => 'http://jedihorsemanship.com');
// --------------------------------------------------------------------------
/**
* Output form input
*
* @access public
* @param $data array
* @return string
*/
public function form_output($data) {
$value = json_decode($data['value']);
$options = array(
'name' => $data['form_slug'],
'id' => $data['form_slug'],
'value' => $data['value'],
'type' => 'hidden',
);
$html = '<span id="'.$data['form_slug'].'_msg" class="stream_map_msg"></span>';
$html .= '<div id="'.$data['form_slug'].'_map" class="stream_map"></div>';
$options_input = array(
'id' => $data['form_slug'].'_input',
// jhubb81 added name attribute to generated address_input to allow for proper javascript validation
'name' => $data['form_slug'].'_input',
# Check if addres exists to maintain backward compatibility
'value' => (!empty($value->address)) ? $value->address : $data['value'],
'type' => 'text',
);
return form_input($options).form_input($options_input).$html;
}
// --------------------------------------------------------------------------
/**
* Tag output variables
*
* Outputs 'latitude' & 'longitude' variables
*
* @access public
* @param string
* @param array
* @return array
*/
public function pre_output_plugin($input) {
if ( ! $input) return null;
$location = json_decode($input);
# Maintain backward compatability
if (!is_object($location)) {
$pieces = explode(',', $input);
if (count($pieces) != 2) return null;
$array = array(
'lat' => $pieces[0],
'lng' => $pieces[1],
'address' => null,
);
$location = (object) $array;
}
$data = array(
'latitude' => $location->lat,
'longitude' => $location->lng,
'lat' => $location->lat,
'lng' => $location->lng,
'address' => $location->address,
);
return $data;
}
/**
* Event
*
* Load assets
*
* @access public
* @param $field object
* @return void
*/
public function event($field) {
$this->CI->type->add_misc('<script src="//maps.google.com/maps/api/js?sensor=false"></script>');
$this->CI->type->add_js('geocoder', 'geocoder.js');
$this->CI->type->add_css('geocoder', 'geocoder.css');
$this->CI->type->add_misc('<script type="text/javascript">
$(document).ready(function() {
initialize("'.$field->field_slug.'");
$(".tabs").bind("tabsshow", function(event, ui) {
google.maps.event.trigger(map, "resize");
mapLocation();
});
});
</script>');
}
}