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