3
3
* $RCSfile: AdminModules.inc,v $
5
5
* Gallery - a web based photo album viewer and editor
6
* Copyright (C) 2000-2005 Bharat Mediratta
6
* Copyright (C) 2000-2006 Bharat Mediratta
8
8
* This program is free software; you can redistribute it and/or modify
9
9
* it under the terms of the GNU General Public License as published by
19
19
* along with this program; if not, write to the Free Software
20
20
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
24
* @version $Revision: 1.52 $ $Date: 2005/08/23 03:49:02 $
23
* @version $Revision: 1.56 $ $Date: 2006/01/17 01:52:01 $
25
24
* @package GalleryCore
26
25
* @subpackage UserInterface
27
26
* @author Bharat Mediratta <bharat@menalto.com>
40
39
* @see GalleryController::handleRequest
42
41
function handleRequest() {
45
42
$ret = GalleryCoreApi::assertUserIsSiteAdministrator();
46
if ($ret->isError()) {
47
44
return array($ret->wrap(__FILE__, __LINE__), null);
47
$status = $error = array();
53
49
list($moduleId, $action) = GalleryUtilities::getRequestVariables('moduleId', 'action');
54
50
if (!empty($moduleId) && !empty($action)) {
55
51
list($ret, $module) = GalleryCoreApi::loadPlugin('module', $moduleId, true);
56
if ($ret->isError()) {
57
53
return array($ret->wrap(__FILE__, __LINE__), null);
60
56
list ($ret, $isActive) = $module->isActive();
61
if ($ret->isError()) {
62
58
return array($ret->wrap(__FILE__, __LINE__), null);
68
64
$ret = $module->installOrUpgrade();
69
if ($ret->isError()) {
70
66
return array($ret->wrap(__FILE__, __LINE__), null);
73
69
list($ret, $autoConfigured) = $module->autoConfigure();
74
if ($ret->isError()) {
75
71
return array($ret->wrap(__FILE__, __LINE__), null);
96
92
/* Can't activate if we're already active! */
98
94
list ($ret, $needsConfiguration) = $module->needsConfiguration();
99
if ($ret->isError()) {
100
96
return array($ret->wrap(__FILE__, __LINE__), null);
103
99
/* Can't activate if we need to be configured! */
104
100
if ($needsConfiguration) {
105
return array(GalleryStatus::error(ERROR_BAD_PARAMETER, __FILE__, __LINE__),
101
return array(GalleryCoreApi::error(ERROR_BAD_PARAMETER, __FILE__, __LINE__),
109
105
list ($ret, $redirect) = $module->activate();
110
if ($ret->isError()) {
111
107
return array($ret->wrap(__FILE__, __LINE__), null);
123
119
/* Can't deactivate if we're not active! */
125
121
list ($ret, $redirect) = $module->deactivate();
126
if ($ret->isError()) {
127
123
return array($ret->wrap(__FILE__, __LINE__), null);
129
125
if (empty($redirect)) {
146
return array(GalleryStatus::error(ERROR_BAD_PARAMETER, __FILE__, __LINE__),
142
return array(GalleryCoreApi::error(ERROR_BAD_PARAMETER, __FILE__, __LINE__),
161
157
$results['status'] = $status;
162
158
$results['error'] = $error;
164
return array(GalleryStatus::success(), $results);
160
return array(null, $results);
177
173
* @see GalleryView::loadTemplate
179
175
function loadTemplate(&$template, &$form) {
182
176
$ret = GalleryCoreApi::assertUserIsSiteAdministrator();
183
if ($ret->isError()) {
184
178
return array($ret->wrap(__FILE__, __LINE__), null);
187
list ($ret, $coreModule) = GalleryCoreApi::loadPlugin('module', 'core');
188
if ($ret->isError()) {
189
return array($ret->wrap(__FILE__, __LINE__), null);
181
list ($ret, $coreModule) = GalleryCoreApi::loadPlugin('module', 'core');
183
return array($ret->wrap(__FILE__, __LINE__), null);
192
186
/* Load the module list */
193
187
list ($ret, $moduleStatus) = GalleryCoreApi::fetchPluginStatus('module', true);
194
if ($ret->isError()) {
195
189
return array($ret->wrap(__FILE__, __LINE__), null);
205
199
foreach ($moduleStatus as $moduleId => $status) {
206
200
if (!empty($status['active'])) {
207
201
list($ret, $module) = GalleryCoreApi::loadPlugin('module', $moduleId);
208
if ($ret->isError() && !($ret->getErrorCode() & ERROR_PLUGIN_VERSION_MISMATCH)) {
202
if ($ret && !($ret->getErrorCode() & ERROR_PLUGIN_VERSION_MISMATCH)) {
209
203
return array($ret->wrap(__FILE__, __LINE__), null);
214
208
/* Reload the module list, which may now be updated because of obsolete modules. */
215
209
list ($ret, $moduleStatus) = GalleryCoreApi::fetchPluginStatus('module', true);
216
if ($ret->isError()) {
217
211
return array($ret->wrap(__FILE__, __LINE__), null);
225
219
foreach ($moduleStatus as $moduleId => $status) {
226
220
/* Get the selected module's admin view (even if the module needs upgrading) */
227
221
list($ret, $module) = GalleryCoreApi::loadPlugin('module', $moduleId, true);
228
if ($ret->isError()) {
229
223
return array($ret->wrap(__FILE__, __LINE__), null);
233
227
$entry['name'] = $module->translate($module->getName());
234
228
$entry['action'] = array();
235
229
$coreApiCompatible = GalleryUtilities::isCompatibleWithApi(
236
$module->getRequiredCoreApi(), GalleryCoreApi::getApiVersion());
230
$module->getRequiredCoreApi(), GalleryCoreApi::getApiVersion());
237
231
$moduleApiCompatible = GalleryUtilities::isCompatibleWithApi(
238
$module->getRequiredModuleApi(), GalleryModule::getApiVersion());
232
$module->getRequiredModuleApi(), GalleryModule::getApiVersion());
239
233
if ($coreApiCompatible && $moduleApiCompatible) {
240
234
if (empty($status['active'])) {
241
235
$version = $status['version'];
265
259
* to be configured before being activated.
267
261
list ($ret, $needsConfig) = $module->needsConfiguration();
268
if ($ret->isError()) {
269
263
return array($ret->wrap(__FILE__, __LINE__), null);
272
266
if ($needsConfig) {
273
267
$configView = $module->getConfigurationView();
274
$entry['action'][] = array('text' => $coreModule->translate('configure'),
268
$entry['action'][] = array('text' =>
269
$coreModule->translate('configure'),
275
270
'view' => $configView);
277
272
$entry['action'][] = array('text' => $coreModule->translate('activate'),
304
299
$entry['description'] = $module->translate($module->getDescription());
305
300
$entry['version'] = $module->getVersion();
306
301
$entry['installedVersion'] = isset($status['version']) ? $status['version'] : null;
307
$group = $module->getGroup();
308
$entry = array_merge($entry, empty($group) ?
309
array('group' => 'other', 'groupLabel' => $module->translate('Other')) : $group);
302
$modules[] = array_merge($entry, $module->getGroup());
313
305
usort($modules, array($this, 'moduleSort'));
314
$AdminModules['modules'] = $modules;
316
/* Render the HTML body */
317
$template->setVariable('AdminModules', $AdminModules);
306
$template->setVariable('AdminModules', array('modules' => $modules));
318
307
$template->setVariable('controller', 'core.AdminModules');
320
return array(GalleryStatus::success(),
321
310
array('body' => 'modules/core/templates/AdminModules.tpl'));
324
313
function moduleSort($a, $b) {
325
314
static $groupOrder;
326
315
if (!isset($groupOrder)) {
327
// gallery first, toolkits second, other last
316
/* gallery first, toolkits second, other last */
328
317
$groupOrder = array('gallery' => 1, 'toolkits' => 2, '' => 3, 'other' => 4);
330
319
$ag = $a['group'];