-
Notifications
You must be signed in to change notification settings - Fork 3
/
maintain.class.php
148 lines (131 loc) · 3.96 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
<?php
defined('PHPWG_ROOT_PATH') or die('Hacking attempt (maintain)!');
/**
* 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 easyrotate_maintain extends PluginMaintain
{
private $default_conf = array(
'rotate_hd' => false
);
private $dir;
private $rotateImage_installed;
function __construct($plugin_id)
{
parent::__construct($plugin_id); // always call parent constructor
// Class members can't be declared with computed values so initialization is done here
$this->dir = PHPWG_ROOT_PATH . PWG_LOCAL_DIR . 'EasyRotate/';
$this->rotateImage_installed = file_exists(PHPWG_PLUGINS_PATH . 'rotateImage/main.inc.php')?true:false;
}
/**
* Add an error message about the imageRotate plugin not being installed.
*
* @param string[] $errors The error array to add to.
*/
protected function addRotateImageError(&$errors)
{
load_language('plugin.lang', __DIR__ . '/');
$msg = sprintf(l10n('To install this plugin, you need to install the rotateImage plugin first.'));
if(is_array($errors))
{
array_push($errors, $msg);
}
else
{
$errors = array($msg);
}
}
/**
* 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;
if (!$this->rotateImage_installed)
{
$this->addRotateImageError($errors);
}
else
{
// add config parameter
if (empty($conf['easyrotate']))
{
// conf_update_param well serialize and escape array before database insertion
// the third parameter indicates to update $conf['easyrotate'] global variable as well
conf_update_param('easyrotate', $this->default_conf, true);
}
else
{
$old_conf = safe_unserialize($conf['easyrotate']);
conf_update_param('easyrotate', $old_conf, true);
}
// create a local directory
if (!file_exists($this->dir))
{
mkdir($this->dir, 0755);
}
}
}
/**
* 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())
{
global $pwg_loaded_plugins;
$rotateImage_active = false;
if(array_key_exists('rotateImage', $pwg_loaded_plugins))
{
$rotateImage_active = $pwg_loaded_plugins['rotateImage']['state'] == "active";
}
if (!$this->rotateImage_installed || !$rotateImage_active)
{
$this->addRotateImageError($errors);
}
}
/**
* 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())
{
$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('easyrotate');
// delete local folder
// use a recursive function if you plan to have nested directories
foreach (scandir($this->dir) as $file)
{
if ($file == '.' or $file == '..') continue;
unlink($this->dir.$file);
}
rmdir($this->dir);
}
}