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

« back to all changes in this revision

Viewing changes to modules/dcraw/module.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: module.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
20
20
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
21
21
 */
22
22
/**
23
 
 * @version $Revision: 1.13 $ $Date: 2005/09/10 20:28:12 $
 
23
 * @version $Revision: 1.18.2.1 $ $Date: 2006/04/05 00:19:53 $
24
24
 * @package Dcraw
25
25
 * @author Bharat Mediratta <bharat@menalto.com>
26
26
 */
41
41
        $this->setName($gallery->i18n('Dcraw'));
42
42
        $this->setDescription(
43
43
            $gallery->i18n('Graphics toolkit for processing images in raw format'));
44
 
        $this->setVersion('1.0.0');
45
 
        $this->setGroup('toolkits', $this->translate('Graphics Toolkits'));
 
44
        $this->setVersion('1.0.5');
 
45
        $this->setGroup('toolkits', $gallery->i18n('Graphics Toolkits'));
46
46
        $this->setCallbacks('getSiteAdminViews');
47
 
        $this->setRequiredCoreApi(array(6, 0));
48
 
        $this->setRequiredModuleApi(array(2, 0));
 
47
        $this->setRequiredCoreApi(array(7, 0));
 
48
        $this->setRequiredModuleApi(array(3, 0));
49
49
    }
50
50
 
51
51
    /**
56
56
        $ret = GalleryCoreApi::registerFactoryImplementation(
57
57
            'GalleryToolkit', 'DcrawToolkit', 'Dcraw',
58
58
            'modules/dcraw/classes/DcrawToolkit.class', 'dcraw', null);
59
 
        if ($ret->isError()) {
 
59
        if ($ret) {
60
60
            return $ret->wrap(__FILE__, __LINE__);
61
61
        }
62
62
 
63
 
        return GalleryStatus::success();
 
63
        return null;
64
64
    }
65
65
 
66
66
    /**
70
70
        global $gallery;
71
71
 
72
72
        list ($ret, $priority) = GalleryCoreApi::getToolkitPriorityById('Dcraw');
73
 
        if ($ret->isError()) {
 
73
        if ($ret) {
74
74
            return array($ret->wrap(__FILE__, __LINE__), null);
75
75
        }
76
76
 
77
77
        if (!$priority) {
78
78
            list ($ret, $priority) = GalleryCoreApi::getMaximumManagedToolkitPriority();
79
 
            if ($ret->isError()) {
 
79
            if ($ret) {
80
80
                return array($ret->wrap(__FILE__, __LINE__), null);
81
81
            }
82
82
            $priority++;
85
85
        $ret = GalleryCoreApi::registerToolkitOperation(
86
86
            'Dcraw', array('image/x-dcraw'), 'convert-to-image/x-portable-pixmap',
87
87
            array(), $gallery->i18n('Convert to PPM'), 'image/x-portable-pixmap', $priority);
88
 
        if ($ret->isError()) {
 
88
        if ($ret) {
89
89
            return array($ret->wrap(__FILE__, __LINE__), null);
90
90
        }
91
91
 
92
92
        $ret = GalleryCoreApi::registerToolkitProperty(
93
93
            'Dcraw', array('image/x-dcraw'), 'dimensions', 'int,int',
94
94
            $gallery->i18n('Get the width and height of the image'));
95
 
        if ($ret->isError()) {
 
95
        if ($ret) {
96
96
            return array($ret->wrap(__FILE__, __LINE__), null);
97
97
        }
98
98
 
101
101
                       'fff', 'k25', 'kdc', 'mos', 'mrw', 'nef', 'orf',
102
102
                       'pef', 'raf', 'rdc', 'srf', 'x3f') as $extension) {
103
103
            $ret = GalleryCoreApi::addMimeType($extension, 'image/x-dcraw', 0);
104
 
            if ($ret->isError()) {
 
104
            if ($ret) {
105
105
                if (!($ret->getErrorCode() & ERROR_COLLISION)) {
106
106
                    return array($ret->wrap(__FILE__, __LINE__), null);
107
107
                }
108
108
            }
109
109
        }
110
110
 
 
111
        /* Detect the version of the binary (it may have changed since last activation) */
 
112
        GalleryCoreApi::requireOnce('modules/dcraw/classes/DcrawToolkitHelper.class');
 
113
 
 
114
        list ($ret, $path) = $this->getParameter('path');
 
115
        if ($ret) {
 
116
            return array($ret->wrap(__FILE__, __LINE__), null);
 
117
        }
 
118
 
 
119
        list ($ret, $testResults, $version) = DcrawToolkitHelper::testBinary($path);
 
120
        if ($ret) {
 
121
            return array($ret->wrap(__FILE__, __LINE__), null);
 
122
        }
 
123
 
 
124
        $ret = $this->setParameter('version', $version);
 
125
        if ($ret) {
 
126
            return array($ret->wrap(__FILE__, __LINE__), null);
 
127
        }
 
128
 
111
129
        list ($ret, $redirect) = parent::activate($postActivationEvent);
112
 
        if ($ret->isError()) {
 
130
        if ($ret) {
113
131
            return array($ret->wrap(__FILE__, __LINE__), null);
114
132
        }
115
133
 
116
 
        return array(GalleryStatus::success(), $redirect);
 
134
        return array(null, $redirect);
117
135
    }
118
136
 
119
137
    /**
126
144
         * be after the deactivation is done.
127
145
         */
128
146
        $ret = GalleryCoreApi::unregisterToolkit('Dcraw');
129
 
        if ($ret->isError()) {
 
147
        if ($ret) {
130
148
            return array($ret->wrap(__FILE__, __LINE__), null);
131
149
        }
132
150
 
133
151
        list ($ret, $redirect) = parent::deactivate($postDeactivationEvent);
134
 
        if ($ret->isError()) {
 
152
        if ($ret) {
135
153
            return array($ret->wrap(__FILE__, __LINE__), null);
136
154
        }
137
155
 
138
 
        return array(GalleryStatus::success(), $redirect);
 
156
        return array(null, $redirect);
139
157
    }
140
158
 
141
159
    /**
142
160
     * @see GalleryModule::needsConfiguration
143
161
     */
144
162
    function needsConfiguration() {
145
 
        list ($ret, $value) = $this->getParameter('path');
146
 
        if ($ret->isError()) {
147
 
            return array($ret->wrap(__FILE__, __LINE__), null);
148
 
        }
149
 
 
150
 
        return array(GalleryStatus::success(), empty($value));
151
 
    }
152
 
 
153
 
    /**
154
 
     * @see GalleryModule::isRecommendedDuringInstall
155
 
     */
156
 
    function isRecommendedDuringInstall() {
157
 
        return false;
 
163
        list ($ret, $path) = $this->getParameter('path');
 
164
        if ($ret) {
 
165
            return array($ret->wrap(__FILE__, __LINE__), null);
 
166
        }
 
167
 
 
168
        list ($ret, $version) = $this->getParameter('version');
 
169
        if ($ret) {
 
170
            return array($ret->wrap(__FILE__, __LINE__), null);
 
171
        }
 
172
 
 
173
        return array(null, empty($path) || empty($version));
158
174
    }
159
175
 
160
176
    /**
164
180
        global $gallery;
165
181
 
166
182
        list ($ret, $needsConfiguration) = $this->needsConfiguration();
167
 
        if ($ret->isError()) {
 
183
        if ($ret) {
168
184
            return array($ret->wrap(__FILE__, __LINE__), false);
169
185
        }
170
186
 
171
187
        if (!$needsConfiguration) {
172
 
            return array(GalleryStatus::success(), true);
 
188
            return array(null, true);
173
189
        }
174
190
 
175
191
        /* Try a bunch of likely seeming paths to see if any of them work. */
176
 
        $platform = $gallery->getPlatform();
 
192
        $platform =& $gallery->getPlatform();
177
193
        $slash = $platform->getDirectorySeparator();
178
194
 
179
195
        /*
217
233
            $paths[] = '/bin/dcraw';
218
234
            $paths[] = '/sw/bin/dcraw';
219
235
        } else {
220
 
            return array(GalleryStatus::success(), false);
 
236
            return array(null, false);
221
237
        }
222
238
 
223
239
        /* Load any classes we require */
224
 
        GalleryCoreApi::relativeRequireOnce('modules/dcraw/classes/DcrawToolkitHelper.class');
 
240
        GalleryCoreApi::requireOnce('modules/dcraw/classes/DcrawToolkitHelper.class');
225
241
 
226
242
        /* Now try each path in turn to see which ones work */
227
243
        foreach ($paths as $path) {
228
 
            list ($ret, $testResults) = DcrawToolkitHelper::testBinary($path);
229
 
            if ($ret->isError()) {
 
244
            list ($ret, $testResults, $version) = DcrawToolkitHelper::testBinary($path);
 
245
            if ($ret) {
230
246
                /* This path failed.  Continue with the next one */
231
247
                continue;
232
248
            }
242
258
            if ($failCount == 0) {
243
259
                /* We have a winner */
244
260
                $ret = GalleryCoreApi::setPluginParameter('module', 'dcraw', 'path', $path);
245
 
                if ($ret->isError()) {
 
261
                if ($ret) {
246
262
                    return array($ret->wrap(__FILE__, __LINE__), false);
247
263
                }
248
264
 
249
 
                return array(GalleryStatus::success(), true);
 
265
                return array(null, true);
250
266
            }
251
267
        }
252
268
 
253
 
        return array(GalleryStatus::success(), false);
 
269
        return array(null, false);
254
270
    }
255
271
 
256
272
    /**
257
273
     * @see GalleryModule::getSiteAdminViews
258
274
     */
259
275
    function getSiteAdminViews() {
260
 
        return array(GalleryStatus::success(),
 
276
        return array(null,
261
277
                     array(array('name' => $this->translate('Dcraw'),
262
278
                                 'view' => 'dcraw.AdminDcraw')));
263
279
    }