Skip to content

Commit 5732e09

Browse files
committed
fixes #202 compatibility with Piwigo 12 (will actually require Piwigo 12.2.0)
fixes #205 replace maintain.inc.php by maintain.class.php and make sure plugin configuration is not reset on each update
1 parent 6683aa2 commit 5732e09

9 files changed

Lines changed: 237 additions & 270 deletions

File tree

admin.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
include(dirname(__FILE__).'/admin/admin.php');
3+
?>

admin/admin.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@
4545
else
4646
$page['tab'] = $_GET['tab'];
4747

48-
$my_base_url = get_admin_plugin_menu_link(__FILE__);
48+
$my_base_url = get_root_url().'admin.php?page=plugin-piwigo_openstreetmap';
4949

5050
$tabsheet = new tabsheet();
51-
$tabsheet->add( 'config', '<span class="icon-cog"></span>' . l10n('Configuration'), add_url_params( $my_base_url, array('tab'=>'config') ) );
52-
$tabsheet->add( 'tag', '<span class="icon-tags"></span>' . l10n('Tags'), add_url_params( $my_base_url, array('tab'=>'tag') ) );
53-
$tabsheet->add( 'place', '<span class="osm-location"></span>' . l10n('OSM_PLACES'), add_url_params( $my_base_url, array('tab'=>'place') ) );
51+
$tabsheet->add( 'config', '<span class="icon-cog"></span>' . l10n('Configuration'), $my_base_url.'-config');
52+
$tabsheet->add( 'tag', '<span class="icon-tags"></span>' . l10n('Tags'), $my_base_url.'-tag');
53+
$tabsheet->add( 'place', '<span class="osm-location"></span>' . l10n('OSM_PLACES'), $my_base_url.'-place');
5454
$tabsheet->select($page['tab']);
5555

5656
$tabsheet->assign();

admin/admin_boot.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,6 @@
2626
// Check whether we are indeed included by Piwigo.
2727
if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
2828

29-
// Hook to a admin config page
30-
add_event_handler('get_admin_plugin_menu_links', 'osm_admin_menu');
31-
function osm_admin_menu($menu)
32-
{
33-
array_push($menu,
34-
array(
35-
'NAME' => '<span class="osm-globe"></span>OpenStreetMap',
36-
'URL' => get_admin_plugin_menu_link(dirname(__FILE__).'/admin.php')
37-
)
38-
);
39-
return $menu;
40-
}
41-
4229
// Batch_manager support
4330
include_once(dirname(__FILE__).'/admin_batchmanager.php');
4431

main.inc.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/*
33
Plugin Name: OpenStreetMap
4-
Version: 2.9.a
4+
Version: auto
55
Description: OpenStreetMap integration for piwigo
66
Plugin URI: http://piwigo.org/ext/extension_view.php?eid=701
77
Author: xbmgsharp
@@ -18,7 +18,7 @@
1818
global $conf;
1919

2020
// Prepare configuration
21-
$conf['osm_conf'] = unserialize($conf['osm_conf']);
21+
$conf['osm_conf'] = safe_unserialize($conf['osm_conf']);
2222

2323
// GPX support
2424
include_once(dirname(__FILE__).'/gpx.inc.php');

maintain.class.php

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
<?php
2+
defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
3+
4+
/**
5+
* This class is used to expose maintenance methods to the plugins manager
6+
* It must extends PluginMaintain and be named "PLUGINID_maintain"
7+
* where PLUGINID is the directory name of your plugin.
8+
*/
9+
class piwigo_openstreetmap_maintain extends PluginMaintain
10+
{
11+
private $default_conf = array(
12+
'right_panel' => array(
13+
'enabled' => true,
14+
'add_before' => 'Average',
15+
'height' => '200',
16+
'zoom' => 12,
17+
'link' => 'Location',
18+
'linkcss' => null,
19+
'showosm' => true,
20+
),
21+
'left_menu' => array(
22+
'enabled' => true,
23+
'link' => 'OSWORLDMAP',
24+
'popup' => 0,
25+
'popupinfo_name' => true,
26+
'popupinfo_img' => true,
27+
'popupinfo_link' => true,
28+
'popupinfo_comment' => true,
29+
'popupinfo_author' => true,
30+
'zoom' => 2,
31+
'center' => '0,0',
32+
'layout' => 2,
33+
),
34+
'category_description' => array(
35+
'enabled' => true,
36+
'index' => 0,
37+
'height' => '200',
38+
'width' => 'auto',
39+
),
40+
'main_menu' => array(
41+
'enabled' => false,
42+
'height' => '200',
43+
),
44+
'gpx' => array(
45+
'height' => '500',
46+
'width' => '320',
47+
),
48+
'batch' => array(
49+
'global_height' => '200',
50+
'unit_height' => '200',
51+
),
52+
'map' => array(
53+
'baselayer' => 'mapnik',
54+
'custombaselayer' => null,
55+
'custombaselayerurl' => null,
56+
'noworldwarp' => false,
57+
'attrleaflet' => true,
58+
'attrimagery' => true,
59+
'attrplugin' => true,
60+
),
61+
'pin' => array(
62+
'pin' => 1,
63+
'pinpath' => '',
64+
'pinsize' => '',
65+
'pinshadowpath' => '',
66+
'pinshadowsize' => '',
67+
'pinoffset' => '',
68+
'pinpopupoffset' => '',
69+
),
70+
);
71+
72+
private $table;
73+
74+
function __construct($plugin_id)
75+
{
76+
parent::__construct($plugin_id); // always call parent constructor
77+
78+
global $prefixeTable;
79+
80+
// Class members can't be declared with computed values so initialization is done here
81+
$this->table = $prefixeTable . 'osm_places';
82+
}
83+
84+
/**
85+
* Plugin installation
86+
*
87+
* Perform here all needed step for the plugin installation such as create default config,
88+
* add database tables, add fields to existing tables, create local folders...
89+
*/
90+
function install($plugin_version, &$errors=array())
91+
{
92+
global $conf;
93+
94+
// add config parameter
95+
if (empty($conf['osm_conf']))
96+
{
97+
conf_update_param('osm_conf', $this->default_conf, true);
98+
}
99+
else
100+
{
101+
$old_conf = safe_unserialize($conf['osm_conf']);
102+
103+
foreach ($this->default_conf as $conf_settings_group_key => $conf_settings_group_value)
104+
{
105+
if (!isset($old_conf[$conf_settings_group_key]))
106+
{
107+
$old_conf[$conf_settings_group_key] = $conf_settings_group_value;
108+
}
109+
else
110+
{
111+
foreach ($conf_settings_group_value as $key => $value)
112+
{
113+
if (!isset($old_conf[$conf_settings_group_key][$key]))
114+
{
115+
$old_conf[$conf_settings_group_key][$key] = $value;
116+
}
117+
}
118+
}
119+
}
120+
121+
conf_update_param('osm_conf', $old_conf, true);
122+
}
123+
124+
// add a new table
125+
pwg_query('
126+
CREATE TABLE IF NOT EXISTS `'.$this->table.'` (
127+
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
128+
`latitude` double(8,6) NOT NULL,
129+
`longitude` double(9,6) NOT NULL,
130+
`name` varchar(255) DEFAULT NULL,
131+
`parentId` mediumint(8),
132+
PRIMARY KEY (id)
133+
) ENGINE=MyISAM DEFAULT CHARSET=utf8
134+
;');
135+
136+
// change "longitude" type, created as double(8,6) in a previous version of the plugin
137+
$columns = query2array('SHOW COLUMNS FROM `'.$this->table.'` LIKE "longitude";');
138+
if ('double(9,6)' != $columns[0]['Type'])
139+
{
140+
pwg_query('ALTER TABLE `'.$this->table.'` CHANGE `longitude` `longitude` double(9,6) NOT NULL;');
141+
}
142+
143+
if (conf_get_param('osm_add_osmmap.php', true))
144+
{
145+
$c = <<<EOF
146+
<?php
147+
define('PHPWG_ROOT_PATH','./');
148+
if (isset(\$_GET['v']) and \$_GET['v'] == 1)
149+
include_once( PHPWG_ROOT_PATH. 'plugins/piwigo-openstreetmap/osmmap.php');
150+
else if (isset(\$_GET['v']) and \$_GET['v'] == 2)
151+
include_once( PHPWG_ROOT_PATH. 'plugins/piwigo-openstreetmap/osmmap2.php');
152+
else if (isset(\$_GET['v']) and \$_GET['v'] == 3)
153+
include_once( PHPWG_ROOT_PATH. 'plugins/piwigo-openstreetmap/osmmap3.php');
154+
else if (isset(\$_GET['v']) and \$_GET['v'] == 4)
155+
include_once( PHPWG_ROOT_PATH. 'plugins/piwigo-openstreetmap/osmmap4.php');
156+
else
157+
include_once( PHPWG_ROOT_PATH. 'plugins/piwigo-openstreetmap/osmmap3.php');
158+
?>
159+
EOF;
160+
file_put_contents(PHPWG_ROOT_PATH.'osmmap.php', $c);
161+
}
162+
}
163+
164+
/**
165+
* Plugin activation
166+
*
167+
* This function is triggered after installation, by manual activation or after a plugin update
168+
* for this last case you must manage updates tasks of your plugin in this function
169+
*/
170+
function activate($plugin_version, &$errors=array())
171+
{
172+
}
173+
174+
/**
175+
* Plugin deactivation
176+
*
177+
* Triggered before uninstallation or by manual deactivation
178+
*/
179+
function deactivate()
180+
{
181+
}
182+
183+
/**
184+
* Plugin (auto)update
185+
*
186+
* This function is called when Piwigo detects that the registered version of
187+
* the plugin is older than the version exposed in main.inc.php
188+
* Thus it's called after a plugin update from admin panel or a manual update by FTP
189+
*/
190+
function update($old_version, $new_version, &$errors=array())
191+
{
192+
// I (mistic100) chosed to handle install and update in the same method
193+
// you are free to do otherwize
194+
$this->install($new_version, $errors);
195+
}
196+
197+
/**
198+
* Plugin uninstallation
199+
*
200+
* Perform here all cleaning tasks when the plugin is removed
201+
* you should revert all changes made in 'install'
202+
*/
203+
function uninstall()
204+
{
205+
// delete configuration
206+
conf_delete_param('osm_conf');
207+
208+
// delete table
209+
pwg_query('DROP TABLE `'. $this->table .'`;');
210+
211+
if (conf_get_param('osm_remove_osmmap.php', true))
212+
{
213+
@unlink(PHPWG_ROOT_PATH.'osmmap.php');
214+
}
215+
}
216+
}

0 commit comments

Comments
 (0)