/
googlemaps.plugin.php
executable file
·167 lines (158 loc) · 4.97 KB
/
googlemaps.plugin.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
/**
* GoogleMaps
* easily/quickly insert Google Maps into your posts.
*
* @package googlemaps
* @version $Id$
* @author ayunyan <ayu@commun.jp>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link http://ayu.commun.jp/habari-googlemaps
*/
class GoogleMaps extends Plugin
{
/**
* action: plugin_activation
*
* @access public
* @param string $file
* @return void
*/
public function action_plugin_activation($file)
{
if (Plugins::id_from_file($file) != Plugins::id_from_file(__FILE__)) return;
Options::set('googlemaps__api_key', '');
Options::set('googlemaps__map_width', 500);
Options::set('googlemaps__map_height', 300);
Options::set('googlemaps__streetview_width', 500);
Options::set('googlemaps__streetview_height', 200);
}
/**
* action: init
*
* @access public
* @return void
*/
public function action_init()
{
$this->load_text_domain('googlemaps');
$api_key = Options::get('googlemaps__api_key');
if (empty($api_key)) return;
Stack::add('template_header_javascript', 'http://www.google.com/jsapi?key=' . $api_key);
Stack::add('template_header_javascript', Site::get_url('scripts') . '/jquery.js', 'jquery');
Stack::add('template_header_javascript', $this->get_url() . '/js/googlemaps.js');
}
/**
* action: update_check
*
* @access public
* @return void
*/
public function action_update_check()
{
Update::add('Google Maps', $this->info->guid, $this->info->version);
}
/**
* action: plugin_ui
*
* @access public
* @param string $plugin_id
* @param string $action
* @return void
*/
public function action_plugin_ui($plugin_id, $action)
{
if ($plugin_id != $this->plugin_id()) return;
if ($action == _t('Configure')) {
$form = new FormUI( strtolower(get_class($this)));
$form->append('text', 'api_key', 'googlemaps__api_key', _t('API Key: ', 'googlemaps'));
$map_width = $form->append('text', 'map_width', 'googlemaps__map_width', _t('Map Width: ', 'googlemaps'));
$map_width->add_validator('validate_regex', '/^[0-9]+$/');
$map_height = $form->append('text', 'map_height', 'googlemaps__map_height', _t('Map Height: ', 'googlemaps'));
$map_height->add_validator('validate_regex', '/^[0-9]+$/');
$streetview_width = $form->append('text', 'streetview_width', 'googlemaps__streetview_width', _t('Streetview Width: ', 'googlemaps'));
$streetview_width->add_validator('validate_regex', '/^[0-9]+$/');
$streetview_height = $form->append('text', 'streetview_height', 'googlemaps__streetview_height', _t('Streetview Height: ', 'googlemaps'));
$streetview_height->add_validator('validate_regex', '/^[0-9]+$/');
$form->append('submit', 'save', _t('Save'));
$form->out();
}
}
/**
* action: admin_header
*
* @access public
* @param object $theme
* @return void
*/
public function action_admin_header( $theme )
{
if ($theme->page != 'publish') return;
$api_key = Options::get('googlemaps__api_key');
if (empty($api_key)) return;
Stack::add('admin_header_javascript', 'http://www.google.com/jsapi?key=' . $api_key);
Stack::add('admin_header_javascript', $this->get_url() . '/js/googlemaps_admin.js');
}
/**
* action: template_header
*
* @access public
* @param object $theme
* @return void
*/
public function action_template_header($theme)
{
?>
<script type="text/javascript">
var habari_googlemaps = {
map_width: <?php Options::out('googlemaps__map_width'); ?>,
map_height: <?php Options::out('googlemaps__map_height'); ?>,
streetview_width: <?php Options::out('googlemaps__streetview_width'); ?>,
streetview_height: <?php Options::out('googlemaps__streetview_height'); ?>
};
</script>
<?php
}
/**
* action: form_publish
*
* @access public
* @param object $form
* @return void
*/
public function action_form_publish($form)
{
$container = $form->publish_controls->append('fieldset', 'googlemaps', _t('Google Maps'));
ob_start();
?>
<div id="googlemaps" class="container" style="width: 600px;">
<p>
<input type="text" id="googlemaps_address" name="googlemaps_address" />
<input type="button" id="googlemaps_search" value="<?php echo _t('Search'); ?>" />
<input type="button" id="googlemaps_streetview_toggle" value="<?php echo _t('Street View', 'googlemaps'); ?>" />
<input type="button" id="googlemaps_insert" value="<?php echo _t('Insert Map', 'googlemaps'); ?>" />
</p>
<div id="googlemaps_canvas"></div>
<div id="googlemaps_streetview_canvas" style="width: 600px; height: 300px;"></div>
</div>
<?php
$container->append('static', 'static1', ob_get_contents());
ob_end_clean();
}
/**
* filter: plugin_config
*
* @access public
* @param array $actions
* @param integer $plugin_id
* @return array
*/
public function filter_plugin_config($actions, $plugin_id)
{
if ($plugin_id == $this->plugin_id()) {
$actions[] = _t('Configure');
}
return $actions;
}
}
?>