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