1 | <?php |
---|
2 | defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); |
---|
3 | |
---|
4 | include_once( dirname(dirname(__FILE__)) .'/include/functions.php'); |
---|
5 | |
---|
6 | add_event_handler('get_admin_plugin_menu_links', 'rvm_plugin_admin_menu' ); |
---|
7 | function rvm_plugin_admin_menu($menu) |
---|
8 | { |
---|
9 | array_push($menu, |
---|
10 | array( |
---|
11 | 'NAME' => 'Maps & Earth', |
---|
12 | 'URL' => get_admin_plugin_menu_link(dirname(__FILE__).'/admin.php') |
---|
13 | ) |
---|
14 | ); |
---|
15 | return $menu; |
---|
16 | } |
---|
17 | |
---|
18 | add_event_handler('get_batch_manager_prefilters', 'rvm_get_batch_manager_prefilters'); |
---|
19 | function rvm_get_batch_manager_prefilters($prefilters) |
---|
20 | { |
---|
21 | rvm_load_language(); |
---|
22 | $prefilters[] = array('ID' => 'geotagged', 'NAME' => l10n('Geotagged')); |
---|
23 | $prefilters[] = array('ID' => 'not geotagged', 'NAME' => l10n('Not geotagged')); |
---|
24 | return $prefilters; |
---|
25 | } |
---|
26 | |
---|
27 | add_event_handler('perform_batch_manager_prefilters', 'rvm_perform_batch_manager_prefilters', 50, 2); |
---|
28 | function rvm_perform_batch_manager_prefilters($filter_sets, $prefilter) |
---|
29 | { |
---|
30 | if ($prefilter==="geotagged") |
---|
31 | $query = 'latitude IS NOT NULL AND longitude IS NOT NULL'; |
---|
32 | elseif ($prefilter==="not geotagged") |
---|
33 | $query = 'latitude IS NULL OR longitude IS NULL'; |
---|
34 | |
---|
35 | if ( isset($query) ) |
---|
36 | { |
---|
37 | $query = ' |
---|
38 | SELECT id |
---|
39 | FROM '.IMAGES_TABLE.' |
---|
40 | WHERE '.$query; |
---|
41 | $filter_sets[] = array_from_query($query, 'id'); |
---|
42 | } |
---|
43 | return $filter_sets; |
---|
44 | } |
---|
45 | |
---|
46 | add_event_handler('loc_end_element_set_global', 'rvm_loc_end_element_set_global'); |
---|
47 | function rvm_loc_end_element_set_global() |
---|
48 | { |
---|
49 | rvm_load_language(); |
---|
50 | global $template; |
---|
51 | $template->append('element_set_global_plugins_actions', |
---|
52 | array('ID' => 'geotag', 'NAME'=>l10n('Geotag'), 'CONTENT' => ' |
---|
53 | <label>'.l10n('Latitude').' (-90=S to 90=N) |
---|
54 | <input type="text" size="8" name="lat"> |
---|
55 | </label> |
---|
56 | <label>'.l10n('Longitude').' (-180=E to 180=W) |
---|
57 | <input type="text" size="9" name="lon"> |
---|
58 | </label> (Empty values will erase coordinates) |
---|
59 | ')); |
---|
60 | } |
---|
61 | |
---|
62 | add_event_handler('element_set_global_action', 'rvm_element_set_global_action', 50, 2); |
---|
63 | function rvm_element_set_global_action($action, $collection) |
---|
64 | { |
---|
65 | if ($action!=="geotag") |
---|
66 | return; |
---|
67 | global $page; |
---|
68 | $lat = trim($_POST['lat']); |
---|
69 | $lon = trim($_POST['lon']); |
---|
70 | if ( strlen($lat)>0 and strlen($lon)>0 ) |
---|
71 | { |
---|
72 | if ( (double)$lat<=90 and (double)$lat>=-90 |
---|
73 | and (double)$lon<=180 and (double)$lon>=-180 ) |
---|
74 | $update_query = 'latitude='.$lat.', longitude='.$lon; |
---|
75 | else |
---|
76 | $page['errors'][] = 'Invalid lat or lon value'; |
---|
77 | } |
---|
78 | elseif ( strlen($lat)==0 and strlen($lon)==0 ) |
---|
79 | $update_query = 'latitude=NULL, longitude=NULL'; |
---|
80 | else |
---|
81 | $page['errors'][] = 'Both lat/lon must be empty or not empty'; |
---|
82 | |
---|
83 | if (isset($update_query)) |
---|
84 | { |
---|
85 | $update_query = ' |
---|
86 | UPDATE '.IMAGES_TABLE.' SET '.$update_query.' |
---|
87 | WHERE id IN ('.implode(',',$collection).')'; |
---|
88 | pwg_query($update_query); |
---|
89 | } |
---|
90 | } |
---|
91 | |
---|
92 | add_event_handler('loc_begin_element_set_unit', 'rvm_loc_begin_element_set_unit'); |
---|
93 | function rvm_loc_begin_element_set_unit() |
---|
94 | { |
---|
95 | global $page; |
---|
96 | |
---|
97 | if (!isset($_POST['submit'])) |
---|
98 | return; |
---|
99 | |
---|
100 | $collection = explode(',', $_POST['element_ids']); |
---|
101 | |
---|
102 | $datas = array(); |
---|
103 | $errors = array(); |
---|
104 | $form_errors = 0; |
---|
105 | |
---|
106 | $query = ' |
---|
107 | SELECT id, name |
---|
108 | FROM '.IMAGES_TABLE.' |
---|
109 | WHERE id IN ('.implode(',', $collection).') |
---|
110 | ;'; |
---|
111 | $result = pwg_query($query); |
---|
112 | |
---|
113 | while ($row = pwg_db_fetch_assoc($result)) |
---|
114 | { |
---|
115 | if (!isset($_POST['lat-'.$row['id']])) |
---|
116 | { |
---|
117 | $form_errors++; |
---|
118 | continue; |
---|
119 | } |
---|
120 | $error = false; |
---|
121 | $data = array( |
---|
122 | 'id' => $row['id'], |
---|
123 | 'latitude' => trim($_POST['lat-'.$row['id']]), |
---|
124 | 'longitude' => trim($_POST['lon-'.$row['id']]) |
---|
125 | ); |
---|
126 | |
---|
127 | if ( strlen($data['latitude'])>0 and strlen($data['longitude'])>0 ) |
---|
128 | { |
---|
129 | if ( (double)$data['latitude']>90 or (double)$data['latitude']<-90 |
---|
130 | or (double)$data['longitude']>180 or (double)$data['longitude']<-180 ) |
---|
131 | $error = true; |
---|
132 | } |
---|
133 | elseif ( strlen($data['latitude'])==0 and strlen($data['longitude'])==0 ) |
---|
134 | { |
---|
135 | // nothing |
---|
136 | } |
---|
137 | else |
---|
138 | { |
---|
139 | $error = true; |
---|
140 | } |
---|
141 | |
---|
142 | if ($error) |
---|
143 | $errors[] = $row['name']; |
---|
144 | else |
---|
145 | $datas[] = $data; |
---|
146 | } |
---|
147 | |
---|
148 | mass_updates( |
---|
149 | IMAGES_TABLE, |
---|
150 | array( |
---|
151 | 'primary' => array('id'), |
---|
152 | 'update' => array('latitude', 'longitude') |
---|
153 | ), |
---|
154 | $datas |
---|
155 | ); |
---|
156 | |
---|
157 | if (count($errors)>0) |
---|
158 | { |
---|
159 | $page['errors'][] = 'Invalid lat or lon value for files: '.implode(', ', $errors); |
---|
160 | } |
---|
161 | if ($form_errors) |
---|
162 | $page['errors'][] = 'Maps & Earth: Invalid form submission for '.$form_errors.' photos'; |
---|
163 | } |
---|
164 | |
---|
165 | add_event_handler('loc_end_element_set_unit', 'rvm_loc_end_element_set_unit'); |
---|
166 | function rvm_loc_end_element_set_unit() |
---|
167 | { |
---|
168 | global $template, $conf, $page, $is_category, $category_info; |
---|
169 | |
---|
170 | $template->set_prefilter('batch_manager_unit', 'rvm_prefilter_batch_manager_unit'); |
---|
171 | } |
---|
172 | |
---|
173 | function rvm_prefilter_batch_manager_unit($content) |
---|
174 | { |
---|
175 | $needle = '</table>'; |
---|
176 | $pos = strpos($content, $needle); |
---|
177 | if ($pos!==false) |
---|
178 | { |
---|
179 | $add = '<tr><td><strong>{\'Geotag\'|@translate}</strong></td> |
---|
180 | <td> |
---|
181 | <label>{\'Latitude\'|@translate} |
---|
182 | <input type="text" size="8" name="lat-{$element.id}" value="{$element.latitude}"> |
---|
183 | </label> |
---|
184 | <label>{\'Longitude\'|@translate} |
---|
185 | <input type="text" size="9" name="lon-{$element.id}" value="{$element.longitude}"> |
---|
186 | </label> |
---|
187 | </td> |
---|
188 | </tr>'; |
---|
189 | $content = substr_replace($content, $add, $pos, 0); |
---|
190 | } |
---|
191 | return $content; |
---|
192 | } |
---|
193 | ?> |
---|