source: extensions/rv_gmaps/trunk/admin/admin_boot.php @ 17286

Last change on this file since 17286 was 17286, checked in by rvelices, 12 years ago

rv_gmaps: photos are now geotagged in the batch manager instead of a special plugin page

File size: 2.7 KB
RevLine 
[17286]1<?php
2defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
3
4include_once( dirname(dirname(__FILE__)) .'/include/functions.php');
5
6add_event_handler('invalidate_user_cache', 'rvm_invalidate_cache' );
7
8add_event_handler('get_admin_plugin_menu_links', 'rvm_plugin_admin_menu' );
9function 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
20add_event_handler('get_batch_manager_prefilters', 'rvm_get_batch_manager_prefilters');
21function 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
29add_event_handler('perform_batch_manager_prefilters', 'rvm_perform_batch_manager_prefilters', 50, 2);
30function 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 = '
40SELECT id
41  FROM '.IMAGES_TABLE.'
42  WHERE '.$query;
43                $filter_sets[] = array_from_query($query, 'id');
44        }
45        return $filter_sets;
46}
47
48add_event_handler('loc_end_element_set_global', 'rvm_loc_end_element_set_global');
49function 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>Latitude (-90=S to 90=N)
56    <input type="text" size="8" name="lat">
57  </label>
58  <label>Longitude (-180=E to 180=W)
59    <input type="text" size="9" name="lon">
60  </label> (Empty values will erase coordinates)
61'));
62}
63
64add_event_handler('element_set_global_action', 'rvm_element_set_global_action', 50, 2);
65function 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)$lat>=-180 )
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 = '
88UPDATE '.IMAGES_TABLE.' SET '.$update_query.'
89  WHERE id IN ('.implode(',',$collection).')';
90    pwg_query($update_query);
91    rvm_invalidate_cache();
92  }
93}
94?>
Note: See TracBrowser for help on using the repository browser.