[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") |
---|
| 33 | $query = 'lat IS NOT NULL AND lon IS NOT NULL'; |
---|
| 34 | elseif ($prefilter==="not geotagged") |
---|
| 35 | $query = 'lat IS NULL OR lon 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' => ' |
---|
[17705] | 55 | <label>{\'Latitude\'|@translate} (-90=S to 90=N) |
---|
[17286] | 56 | <input type="text" size="8" name="lat"> |
---|
| 57 | </label> |
---|
[17705] | 58 | <label>{\'Longitude\'|@translate} (-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 ) |
---|
[17286] | 76 | $update_query = 'lat='.$lat.', lon='.$lon; |
---|
| 77 | else |
---|
| 78 | $page['errors'][] = 'Invalid lat or lon value'; |
---|
| 79 | } |
---|
| 80 | elseif ( strlen($lat)==0 and strlen($lon)==0 ) |
---|
| 81 | $update_query = 'lat=NULL, lon=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 | } |
---|
[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; |
---|
| 99 | |
---|
| 100 | if (isset($_POST['submit'])) |
---|
| 101 | { |
---|
| 102 | $collection = explode(',', $_POST['element_ids']); |
---|
| 103 | |
---|
| 104 | $datas = array(); |
---|
| 105 | $errors = array(); |
---|
| 106 | |
---|
| 107 | $query = ' |
---|
| 108 | SELECT id, name |
---|
| 109 | FROM '.IMAGES_TABLE.' |
---|
| 110 | WHERE id IN ('.implode(',', $collection).') |
---|
| 111 | ;'; |
---|
| 112 | $result = pwg_query($query); |
---|
| 113 | |
---|
| 114 | while ($row = pwg_db_fetch_assoc($result)) |
---|
| 115 | { |
---|
| 116 | $data = array(); |
---|
| 117 | $error = false; |
---|
| 118 | $data['id'] = $row['id']; |
---|
| 119 | $data['lat'] = trim($_POST['lat-'.$row['id']]); |
---|
| 120 | $data['lon'] = trim($_POST['lon-'.$row['id']]); |
---|
| 121 | |
---|
| 122 | if ( strlen($data['lat'])>0 and strlen($data['lon'])>0 ) |
---|
| 123 | { |
---|
| 124 | if ( (double)$data['lat']>90 or (double)$data['lat']<-90 |
---|
| 125 | or (double)$data['lon']>180 or (double)$data['lon']<-180 ) |
---|
| 126 | $error = true; |
---|
| 127 | } |
---|
| 128 | elseif ( strlen($data['lat'])==0 and strlen($data['lon'])==0 ) |
---|
| 129 | { |
---|
| 130 | // nothing |
---|
| 131 | } |
---|
| 132 | else |
---|
| 133 | { |
---|
| 134 | $error = true; |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | if ($error) |
---|
| 138 | array_push($errors, $row['name']); |
---|
| 139 | else |
---|
| 140 | array_push($datas, $data); |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | mass_updates( |
---|
| 144 | IMAGES_TABLE, |
---|
| 145 | array( |
---|
| 146 | 'primary' => array('id'), |
---|
| 147 | 'update' => array('lat', 'lon') |
---|
| 148 | ), |
---|
| 149 | $datas |
---|
| 150 | ); |
---|
| 151 | |
---|
| 152 | if (count($errors)>0) |
---|
| 153 | { |
---|
| 154 | array_push($page['errors'], 'Invalid lat or lon value for files: '.implode(', ', $errors)); |
---|
| 155 | } |
---|
| 156 | } |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | add_event_handler('loc_end_element_set_unit', 'rvm_loc_end_element_set_unit'); |
---|
| 160 | function rvm_loc_end_element_set_unit() |
---|
| 161 | { |
---|
| 162 | global $template, $conf, $page, $is_category, $category_info; |
---|
| 163 | |
---|
| 164 | $query = ' |
---|
| 165 | SELECT id,lat,lon |
---|
| 166 | FROM '.IMAGES_TABLE; |
---|
| 167 | |
---|
| 168 | if ($is_category) |
---|
| 169 | { |
---|
| 170 | $category_info = get_cat_info($_SESSION['bulk_manager_filter']['category']); |
---|
| 171 | |
---|
| 172 | $conf['order_by'] = $conf['order_by_inside_category']; |
---|
| 173 | if (!empty($category_info['image_order'])) |
---|
| 174 | { |
---|
| 175 | $conf['order_by'] = ' ORDER BY '.$category_info['image_order']; |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | $query.= ' |
---|
| 179 | JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id'; |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | $query.= ' |
---|
| 183 | WHERE id IN ('.implode(',', $page['cat_elements_id']).')'; |
---|
| 184 | |
---|
| 185 | if ($is_category) |
---|
| 186 | { |
---|
| 187 | $query.= ' |
---|
| 188 | AND category_id = '.$_SESSION['bulk_manager_filter']['category']; |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | $query.= ' |
---|
| 192 | '.$conf['order_by'].' |
---|
| 193 | LIMIT '.$page['nb_images'].' OFFSET '.$page['start'].' |
---|
| 194 | ;'; |
---|
| 195 | $result = pwg_query($query); |
---|
| 196 | |
---|
| 197 | $tpl_vars = array(); |
---|
| 198 | while ($row = pwg_db_fetch_assoc($result)) |
---|
| 199 | { |
---|
| 200 | // remove last zeros for better display |
---|
| 201 | $row['lat'] = preg_replace('#\.([0-9]*?)([0]+)$#', '.$1', $row['lat']); |
---|
| 202 | $row['lon'] = preg_replace('#\.([0-9]*?)([0]+)$#', '.$1', $row['lon']); |
---|
| 203 | |
---|
| 204 | $tpl_vars[ $row['id'] ] = array( |
---|
| 205 | 'LAT' => rtrim($row['lat'], '.'), |
---|
| 206 | 'LON' => rtrim($row['lon'], '.'), |
---|
| 207 | ); |
---|
| 208 | } |
---|
| 209 | |
---|
| 210 | $template->assign('GEOTAG', $tpl_vars); |
---|
| 211 | |
---|
| 212 | $template->set_prefilter('batch_manager_unit', 'rvm_prefilter_batch_manager_unit'); |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | function rvm_prefilter_batch_manager_unit($content, &$smarty) |
---|
| 216 | { |
---|
| 217 | $search = '<td><strong>{\'Who can see this photo?\'|@translate}</strong></td>'; |
---|
| 218 | $add = '<td><strong>{\'Geotag\'|@translate}</strong></td> |
---|
| 219 | <td> |
---|
| 220 | <label>{\'Latitude\'|@translate} |
---|
| 221 | <input type="text" size="8" name="lat-{$element.ID}" value="{$GEOTAG[$element.ID].LAT}"> |
---|
| 222 | </label> |
---|
| 223 | <label>{\'Longitude\'|@translate} |
---|
| 224 | <input type="text" size="9" name="lon-{$element.ID}" value="{$GEOTAG[$element.ID].LON}"> |
---|
| 225 | </label> |
---|
| 226 | </td> |
---|
| 227 | </tr> |
---|
| 228 | |
---|
| 229 | <tr> |
---|
| 230 | '; |
---|
| 231 | return str_replace($search, $add.$search, $content); |
---|
| 232 | } |
---|
[17286] | 233 | ?> |
---|