source: extensions/rv_gmaps/trunk/main.inc.php @ 12701

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

rv_gmaps auto sync gps with exif + towards full maps api v3 migration

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 4.4 KB
RevLine 
[3447]1<?php /*
2Plugin Name: RV Maps&Earth
[12701]3Version: 2.3.b-alpha
[3447]4Description: Extend your gallery with Google Maps and Google Earth ...
[4070]5Plugin URI: http://piwigo.org/ext/extension_view.php?eid=122
[3447]6Author: rvelices
7Author URI: http://www.modusoptimus.com/
8*/
[12701]9define( 'RVM_PLUGIN_VERSION', '2.3.b-alpha');
10defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
[3447]11
12add_event_handler('loc_end_index', 'rvm_end_index' );
13add_event_handler('loc_begin_index_category_thumbnails', 'rvm_index_cat_thumbs_displayed');
14add_event_handler('loc_begin_index_thumbnails', 'rvm_begin_index_thumbnails');
15
16add_event_handler('picture_pictures_data', 'rvm_picture_pictures_data' );
17add_event_handler('get_admin_plugin_menu_links', 'rvm_plugin_admin_menu' );
18
19global $rvm_dir;
20$rvm_dir = basename( dirname(__FILE__) );
21
[12701]22global $conf;
23if (@$conf['gmaps_auto_sync'])
24{
25  $conf['use_exif_mapping']['lat'] = 'lat';
26  $conf['use_exif_mapping']['lon'] = 'lon';
27  add_event_handler('format_exif_data', 'rvm_format_exif', EVENT_HANDLER_PRIORITY_NEUTRAL, 3);
28}
[3447]29
30function rvm_index_cat_thumbs_displayed()
31{
32        global $page;
33        $page['rvm_cat_thumbs_displayed'] = true;
34}
35
36function rvm_begin_index_thumbnails( $pictures )
37{
38        global $page;
39        foreach ($pictures as $picture)
40        {
41                if ( isset($picture['lat']) )
42                {
43                        $page['rvm_items_have_latlon'] = true;
44                        break;
45                }
46        }
47}
48
[8776]49define('RVM_ACTION_MODEL', '<a href="%s" title="%s" rel="nofollow" class="pwg-state-default pwg-button"%s><span class="pwg-icon pwg-icon-%s">&nbsp;</span><span class="pwg-button-text">%s</span></a>');
[8304]50
[3447]51function rvm_end_index()
52{
53        global $page, $filter, $template, $rvm_dir;
54
55        //if ( !is_admin() ) return; // TEMP
56        if ( isset($page['chronology_field']) || $filter['enabled'] )
57                return;
58
59        if ( 'categories' == @$page['section'])
60        { // flat or no flat ; has subcats or not;  ?
61                if ( ! @$page['rvm_cat_thumbs_displayed'] and empty($page['items']) )
62                        return;
63        }
64        else
65        {
66                if (
67                        !in_array( @$page['section'], array('tags','search','recent_pics','list') )
68                        )
69                        return;
70                if ( empty($page['items']) )
71                        return;
72        }
73
74        include_once( dirname(__FILE__) .'/include/functions.php');
75
76        if ( !empty($page['items']) )
77        {
78                if (!@$page['rvm_items_have_latlon'] and ! rvm_items_have_latlon( $page['items'] ) )
79                        return;
80        }
81        rvm_load_language();
82
83        $map_url = rvm_duplicate_map_index_url( array(), array('start') );
84        if ( !empty($map_url) )
85        {
86                $link_title = sprintf( l10n('displays %s on a map'), strip_tags($page['title']) );
[8776]87                $template->concat( 'PLUGIN_INDEX_ACTIONS' , "\n<li>".sprintf(RVM_ACTION_MODEL,
[8304]88                        $map_url, $link_title, '', 'map', 'map'
89                        ).'</li>');
[8776]90        }
[3447]91
92        {
93                $kml_url = rvm_duplicate_kml_index_url( array(), array('start') );
94                $link_title = sprintf( l10n('opens %s in Google Earth'), strip_tags($page['title']) );
[8776]95                $template->concat( 'PLUGIN_INDEX_ACTIONS' , "\n<li>".sprintf(RVM_ACTION_MODEL,
96                        $kml_url, $link_title, ' type="application/vnd.google-earth.kml+xml"', 'globe', 'earth'
[8304]97                        ).'</li>');
[3447]98        }
99}
100
101function rvm_picture_pictures_data($pictures)
102{
103        if ( isset($pictures['current']['lat']) and isset($pictures['current']['lon']) )
104        {
105                global $template;
106                $template->append('head_elements', '<meta name="geo.position" content="'.$pictures['current']['lat'].';'.$pictures['current']['lon'].'">' );
107                include_once( dirname(__FILE__) .'/include/functions.php');
108                rvm_load_language();
109                if ( isset($_GET['map']) )
110                        include_once( dirname(__FILE__) .'/include/picture_map.inc.php');
111                else
112                {
113                        global $rvm_dir;
114                        $map_url = rvm_duplicate_map_picture_url();
[12700]115                        $link_title = sprintf( l10n('displays %s on a map'), strip_tags($pictures['current']['name']) );
116                        $template->concat( 'PLUGIN_PICTURE_ACTIONS' , sprintf(RVM_ACTION_MODEL,
[8776]117                                        $map_url, $link_title, ' target="_top"', 'map', 'map'
[8304]118                                ));
[3447]119                }
120        }
121        else
122                if ( isset($_GET['map']) )
123                        redirect( duplicate_picture_url() );
124        return $pictures;
125}
126
127function rvm_plugin_admin_menu($menu)
128{
129        include_once( dirname(__FILE__) .'/include/functions.php');
130        add_event_handler('invalidate_user_cache', 'rvm_invalidate_cache' );
131
132        array_push($menu,
133                        array(
134                                'NAME' => 'Maps & Earth',
135                                'URL' => get_admin_plugin_menu_link(dirname(__FILE__).'/admin/admin.php')
136                        )
137                );
138        return $menu;
139}
140
[12701]141function rvm_format_exif($exif, $file, $map)
142{
143  if (isset($map['lat']))
144  {
145                include_once( dirname(__FILE__) .'/include/functions_metadata.php');
146                $ll = exif_to_lat_lon($exif);
147                if (is_array($ll))
148                {
149                        $exif[$map['lat']] = $ll[0];
150                        $exif[$map['lon']] = $ll[1];
151                }
152  }
153  return $exif;
154}
[3447]155?>
Note: See TracBrowser for help on using the repository browser.