~ubuntu-branches/ubuntu/hardy/gallery2/hardy-security

« back to all changes in this revision

Viewing changes to modules/core/AdminModules.inc

  • Committer: Bazaar Package Importer
  • Author(s): Michael C. Schultheiss
  • Date: 2006-04-16 16:42:35 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060416164235-8uy0u4bfjdxpge2o
Tags: 2.1.1-1
* New upstream release (Closes: #362936)
  + Bugfixes for Postgres7 (Closes: #359000, #362152)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 * $RCSfile: AdminModules.inc,v $
4
4
 *
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
7
7
 *
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.
21
21
 */
22
 
 
23
22
/**
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
41
40
     */
42
41
    function handleRequest() {
43
 
        global $gallery;
44
 
 
45
42
        $ret = GalleryCoreApi::assertUserIsSiteAdministrator();
46
 
        if ($ret->isError()) {
 
43
        if ($ret) {
47
44
            return array($ret->wrap(__FILE__, __LINE__), null);
48
45
        }
49
46
 
50
 
        $status = array();
51
 
        $error = array();
 
47
        $status = $error = array();
52
48
 
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()) {
 
52
            if ($ret) {
57
53
                return array($ret->wrap(__FILE__, __LINE__), null);
58
54
            }
59
55
 
60
56
            list ($ret, $isActive) = $module->isActive();
61
 
            if ($ret->isError()) {
 
57
            if ($ret) {
62
58
                return array($ret->wrap(__FILE__, __LINE__), null);
63
59
            }
64
60
 
66
62
 
67
63
            case 'install':
68
64
                $ret = $module->installOrUpgrade();
69
 
                if ($ret->isError()) {
 
65
                if ($ret) {
70
66
                    return array($ret->wrap(__FILE__, __LINE__), null);
71
67
                }
72
68
 
73
69
                list($ret, $autoConfigured) = $module->autoConfigure();
74
 
                if ($ret->isError()) {
 
70
                if ($ret) {
75
71
                    return array($ret->wrap(__FILE__, __LINE__), null);
76
72
                }
77
73
 
83
79
 
84
80
            case 'upgrade':
85
81
                $ret = $module->installOrUpgrade();
86
 
                if ($ret->isError()) {
 
82
                if ($ret) {
87
83
                    return array($ret->wrap(__FILE__, __LINE__), null);
88
84
                }
89
85
 
96
92
                /* Can't activate if we're already active! */
97
93
                if (!$isActive) {
98
94
                    list ($ret, $needsConfiguration) = $module->needsConfiguration();
99
 
                    if ($ret->isError()) {
 
95
                    if ($ret) {
100
96
                        return array($ret->wrap(__FILE__, __LINE__), null);
101
97
                    }
102
98
 
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__),
106
102
                                     null);
107
103
                    }
108
104
 
109
105
                    list ($ret, $redirect) = $module->activate();
110
 
                    if ($ret->isError()) {
 
106
                    if ($ret) {
111
107
                        return array($ret->wrap(__FILE__, __LINE__), null);
112
108
                    }
113
109
 
123
119
                /* Can't deactivate if we're not active! */
124
120
                if ($isActive) {
125
121
                    list ($ret, $redirect) = $module->deactivate();
126
 
                    if ($ret->isError()) {
 
122
                    if ($ret) {
127
123
                        return array($ret->wrap(__FILE__, __LINE__), null);
128
124
                    }
129
125
                    if (empty($redirect)) {
143
139
                break;
144
140
 
145
141
            default:
146
 
                return array(GalleryStatus::error(ERROR_BAD_PARAMETER, __FILE__, __LINE__),
 
142
                return array(GalleryCoreApi::error(ERROR_BAD_PARAMETER, __FILE__, __LINE__),
147
143
                             null);
148
144
            }
149
145
        }
161
157
        $results['status'] = $status;
162
158
        $results['error'] = $error;
163
159
 
164
 
        return array(GalleryStatus::success(), $results);
 
160
        return array(null, $results);
165
161
    }
166
162
}
167
163
 
177
173
     * @see GalleryView::loadTemplate
178
174
     */
179
175
    function loadTemplate(&$template, &$form) {
180
 
        global $gallery;
181
 
 
182
176
        $ret = GalleryCoreApi::assertUserIsSiteAdministrator();
183
 
        if ($ret->isError()) {
 
177
        if ($ret) {
184
178
            return array($ret->wrap(__FILE__, __LINE__), null);
185
179
        }
186
180
 
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');
 
182
        if ($ret) {
 
183
            return array($ret->wrap(__FILE__, __LINE__), null);
190
184
        }
191
185
 
192
186
        /* Load the module list */
193
187
        list ($ret, $moduleStatus) = GalleryCoreApi::fetchPluginStatus('module', true);
194
 
        if ($ret->isError()) {
 
188
        if ($ret) {
195
189
            return array($ret->wrap(__FILE__, __LINE__), null);
196
190
        }
197
191
 
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);
210
204
                }
211
205
            }
213
207
 
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()) {
 
210
        if ($ret) {
217
211
            return array($ret->wrap(__FILE__, __LINE__), null);
218
212
        }
219
213
 
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()) {
 
222
            if ($ret) {
229
223
                return array($ret->wrap(__FILE__, __LINE__), null);
230
224
            }
231
225
 
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.
266
260
                         */
267
261
                        list ($ret, $needsConfig) = $module->needsConfiguration();
268
 
                        if ($ret->isError()) {
 
262
                        if ($ret) {
269
263
                            return array($ret->wrap(__FILE__, __LINE__), null);
270
264
                        }
271
265
 
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);
276
271
                        } else {
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);
310
 
            $modules[] = $entry;
 
302
            $modules[] = array_merge($entry, $module->getGroup());
311
303
        }
312
304
 
313
305
        usort($modules, array($this, 'moduleSort'));
314
 
        $AdminModules['modules'] = $modules;
315
 
 
316
 
        /* Render the HTML body */
317
 
        $template->setVariable('AdminModules', $AdminModules);
 
306
        $template->setVariable('AdminModules', array('modules' => $modules));
318
307
        $template->setVariable('controller', 'core.AdminModules');
319
308
 
320
 
        return array(GalleryStatus::success(),
 
309
        return array(null,
321
310
                     array('body' => 'modules/core/templates/AdminModules.tpl'));
322
311
    }
323
312
 
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);
329
318
        }
330
319
        $ag = $a['group'];