[17286] | 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") |
---|
[26331] | 33 | $query = 'latitude IS NOT NULL AND longitude IS NOT NULL'; |
---|
[17286] | 34 | elseif ($prefilter==="not geotagged") |
---|
[26331] | 35 | $query = 'latitude IS NULL OR longitude IS NULL'; |
---|
[17286] | 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' => ' |
---|
[17780] | 55 | <label>'.l10n('Latitude').' (-90=S to 90=N) |
---|
[17286] | 56 | <input type="text" size="8" name="lat"> |
---|
| 57 | </label> |
---|
[17780] | 58 | <label>'.l10n('Longitude').' (-180=E to 180=W) |
---|
[17286] | 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 |
---|
[17705] | 75 | and (double)$lon<=180 and (double)$lon>=-180 ) |
---|
[26331] | 76 | $update_query = 'latitude='.$lat.', longitude='.$lon; |
---|
[17286] | 77 | else |
---|
| 78 | $page['errors'][] = 'Invalid lat or lon value'; |
---|
| 79 | } |
---|
| 80 | elseif ( strlen($lat)==0 and strlen($lon)==0 ) |
---|
[26331] | 81 | $update_query = 'latitude=NULL, longitude=NULL'; |
---|
[17286] | 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 | } |
---|
[17705] | 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; |
---|
[17780] | 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 = ' |
---|
[17705] | 110 | SELECT id, name |
---|
| 111 | FROM '.IMAGES_TABLE.' |
---|
| 112 | WHERE id IN ('.implode(',', $collection).') |
---|
| 113 | ;'; |
---|
[17780] | 114 | $result = pwg_query($query); |
---|
| 115 | |
---|
| 116 | while ($row = pwg_db_fetch_assoc($result)) |
---|
| 117 | { |
---|
| 118 | if (!isset($_POST['lat-'.$row['id']])) |
---|
[17705] | 119 | { |
---|
[17780] | 120 | $form_errors++; |
---|
| 121 | continue; |
---|
| 122 | } |
---|
| 123 | $error = false; |
---|
| 124 | $data = array( |
---|
| 125 | 'id' => $row['id'], |
---|
[26331] | 126 | 'latitude' => trim($_POST['lat-'.$row['id']]), |
---|
| 127 | 'longitude' => trim($_POST['lon-'.$row['id']]) |
---|
[17780] | 128 | ); |
---|
| 129 | |
---|
[26331] | 130 | if ( strlen($data['latitude'])>0 and strlen($data['longitude'])>0 ) |
---|
[17780] | 131 | { |
---|
[26331] | 132 | if ( (double)$data['latitude']>90 or (double)$data['latitude']<-90 |
---|
| 133 | or (double)$data['longitude']>180 or (double)$data['longitude']<-180 ) |
---|
[17705] | 134 | $error = true; |
---|
| 135 | } |
---|
[26331] | 136 | elseif ( strlen($data['latitude'])==0 and strlen($data['longitude'])==0 ) |
---|
[17705] | 137 | { |
---|
[17780] | 138 | // nothing |
---|
[17705] | 139 | } |
---|
[17780] | 140 | else |
---|
| 141 | { |
---|
| 142 | $error = true; |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | if ($error) |
---|
| 146 | $errors[] = $row['name']; |
---|
| 147 | else |
---|
| 148 | $datas[] = $data; |
---|
[17705] | 149 | } |
---|
[17780] | 150 | |
---|
| 151 | mass_updates( |
---|
| 152 | IMAGES_TABLE, |
---|
| 153 | array( |
---|
| 154 | 'primary' => array('id'), |
---|
[26331] | 155 | 'update' => array('latitude', 'longitude') |
---|
[17780] | 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'; |
---|
[17705] | 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; |
---|
[17780] | 172 | |
---|
| 173 | $template->set_prefilter('batch_manager_unit', 'rvm_prefilter_batch_manager_unit'); |
---|
[17705] | 174 | } |
---|
| 175 | |
---|
[17780] | 176 | function rvm_prefilter_batch_manager_unit($content) |
---|
[17705] | 177 | { |
---|
[17780] | 178 | $needle = '</table>'; |
---|
| 179 | $pos = strpos($content, $needle); |
---|
| 180 | if ($pos!==false) |
---|
| 181 | { |
---|
| 182 | $add = '<tr><td><strong>{\'Geotag\'|@translate}</strong></td> |
---|
[17705] | 183 | <td> |
---|
| 184 | <label>{\'Latitude\'|@translate} |
---|
[26331] | 185 | <input type="text" size="8" name="lat-{$element.id}" value="{$element.latitude}"> |
---|
[17705] | 186 | </label> |
---|
| 187 | <label>{\'Longitude\'|@translate} |
---|
[26331] | 188 | <input type="text" size="9" name="lon-{$element.id}" value="{$element.longitude}"> |
---|
[17705] | 189 | </label> |
---|
| 190 | </td> |
---|
[17780] | 191 | </tr>'; |
---|
| 192 | $content = substr_replace($content, $add, $pos, 0); |
---|
| 193 | } |
---|
| 194 | return $content; |
---|
[17705] | 195 | } |
---|
[17286] | 196 | ?> |
---|