forked from xbgmsharp/piwigo-forecast
/
maintain.class.php
88 lines (75 loc) · 2.53 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
<?php
/***********************************************
* File : maintain.class.php
* Project : piwigo-forecast
* Descr : Install / Uninstall method
*
* Created : 23.04.2015
*
* Copyright 2013-2015 <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!');
class forecast_maintain extends PluginMaintain {
private $default_config = array(
'add_before' => 'Average',
'height' => 200,
'link' => 'Overcast',
'show' => true,
'api_key' => '',
'unit' => 'auto',
'lang' => 'en'
);
function install($plugin_version, &$errors=array())
{
global $conf;
// Configuration
if (!isset($conf['forecast_conf']) || empty($conf['forecast_conf']))
{
$this->default_config['last_clean'] = time();
conf_update_param('forecast_conf', $this->default_config, true);
$q = 'UPDATE '.CONFIG_TABLE.' SET `comment` = "Configuration settings for piwigo-forecast plugin" WHERE `param` = "forecast_conf";';
pwg_query( $q );
}
else
{
$current_conf = safe_unserialize($conf['forecast_conf']);
conf_update_param('forecast_conf', array_merge($this->default_config, $current_conf), true);
}
// Create MySQL View
$q = 'DROP VIEW IF EXISTS `forecast`;';
pwg_query( $q );
$q = 'CREATE VIEW forecast AS SELECT `id`, `latitude`, `longitude`, UNIX_TIMESTAMP( IFNULL(`date_creation`, `date_available`) ) as `date` FROM '.IMAGES_TABLE.' WHERE `latitude` IS NOT NULL AND `longitude` is NOT NULL;';
pwg_query( $q );
}
function activate($plugin_version, &$errors=array()) {
}
function update($old_version, $new_version, &$errors=array())
{
$this->install($new_version, $errors);
}
function deactivate()
{
}
function uninstall()
{
global $conf;
conf_delete_param('forecast_conf');
$q = 'DROP VIEW forecast;';
pwg_query( $q );
}
}
?>