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