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

Last change on this file since 8304 was 8304, checked in by rvelices, 13 years ago

rv_gmaps co;patible with piwigo trunk (future 2.2)

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