forked from Piwigo/piwigo-openstreetmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaintain.inc.php
executable file
·163 lines (148 loc) · 4 KB
/
maintain.inc.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
<?php
/***********************************************
* File : maintain.inc.php
* Project : piwigo-openstreetmap
* Descr : Install / Uninstall method
*
* Created : 28.05.2013
*
* Copyright 2013-2014 <xbgmsharp@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
************************************************/
if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
function plugin_install()
{
if (!defined('OSM_PATH'))
define('OSM_PATH', PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)).'/');
// Remove unused files from previous version
$toremove = array("admin.tpl", "admin.php", "admin_boot.php",
"leaflet/leaflet.ie.css", "leaflet/MarkerCluster.Default.ie.css",
"admin/admin_sync.php", "admin/admin_sync.tpl", "admin/admin_batchmanager.php",
"include/functions_metadata.php");
foreach ($toremove as $file)
{
if (is_file(OSM_PATH.$file))
{
@unlink(OSM_PATH.$file);
}
}
$default_config = array(
'right_panel' => array(
'enabled' => true,
'add_before' => 'Average',
'height' => '200',
'zoom' => 12,
'link' => 'Location',
'linkcss' => null,
'showosm' => true,
),
'left_menu' => array(
'enabled' => true,
'link' => 'OS World Map',
'popup' => 0,
'popupinfo_name' => true,
'popupinfo_img' => true,
'popupinfo_link' => true,
'popupinfo_comment' => true,
'popupinfo_author' => true,
),
'map' => array(
'baselayer' => 'mapnik',
'custombaselayer' => null,
'custombaselayerurl' => null,
'noworldwarp' => false,
'attrleaflet' => true,
'attrimagery' => true,
'attrplugin' => true,
),
);
/* Add configuration to the config table */
$conf['osm_conf'] = serialize($default_config);
conf_update_param('osm_conf', $conf['osm_conf']);
$q = 'UPDATE '.CONFIG_TABLE.' SET `comment` = "Configuration settings for piwigo-openstreetmap plugin" WHERE `param` = "osm_conf";';
pwg_query( $q );
// Create world map link
$dir_name = basename( dirname(__FILE__) );
$c = <<<EOF
<?php
define('PHPWG_ROOT_PATH','./');
include_once( PHPWG_ROOT_PATH. 'plugins/$dir_name/osmmap2.php');
?>
EOF;
$fp = fopen( PHPWG_ROOT_PATH.'osmmap.php', 'w' );
fwrite( $fp, $c);
fclose( $fp );
}
function plugin_uninstall()
{
/* Delete all files */
/* Don't remove myself on restore settings
if (is_dir(OSM_PATH))
{
osm_deltree(OSM_PATH);
}
*/
// Remove world map link
@unlink(PHPWG_ROOT_PATH.'osmmap.php');
/* Remove configuration from the config table */
$q = 'DELETE FROM '.CONFIG_TABLE.' WHERE param = "osm_conf" LIMIT 1;';
pwg_query( $q );
/* Remove lat/lon col from previous PWG install */
//osm_drop_old_columns();
}
function plugin_activate()
{
global $conf;
if ( (!isset($conf['osm_conf']))
or (count($conf['osm_conf'], COUNT_RECURSIVE) != 25))
{
plugin_install();
}
}
function osm_deltree($path)
{
if (is_dir($path))
{
$fh = opendir($path);
while ($file = readdir($fh))
{
if ($file != '.' and $file != '..')
{
$pathfile = $path . '/' . $file;
if (is_dir($pathfile))
{
osm_deltree($pathfile);
}
else
{
@unlink($pathfile);
}
}
}
closedir($fh);
return @rmdir($path);
}
}
// Drop lat/lon col from previous PWG install
function osm_drop_old_columns()
{
/* TODO: delete columns if they exist in case of restore config */
$q = 'ALTER TABLE '.IMAGES_TABLE.' DROP COLUMN `lat`';
pwg_query( $q );
$q = 'ALTER TABLE '.IMAGES_TABLE.' DROP COLUMN `lon`';
pwg_query( $q );
}
?>