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

« back to all changes in this revision

Viewing changes to modules/watermark/ItemEditWatermark.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: ItemEditWatermark.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
21
21
 */
22
22
 
23
23
/**
24
 
 * @version $Revision: 1.13 $ $Date: 2005/08/23 03:49:57 $
 
24
 * @version $Revision: 1.15 $ $Date: 2006/01/13 06:50:03 $
25
25
 * @package Watermark
26
26
 * @subpackage UserInterface
27
27
 * @author Bharat Mediratta <bharat@menalto.com>
46
46
        $error = array();
47
47
 
48
48
        list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'watermark');
49
 
        if ($ret->isError()) {
50
 
            return array($ret->wrap(__FILE__, __LINE__), null, null);
 
49
        if ($ret) {
 
50
            return array($ret->wrap(__FILE__, __LINE__), null, null, null);
51
51
        }
52
52
 
53
53
        if (isset($form['action']['save'])) {
59
59
 
60
60
            if (empty($error)) {
61
61
                list ($ret, $watermark) = GalleryCoreApi::loadEntitiesById($form['watermarkId']);
62
 
                if ($ret->isError()) {
63
 
                    return array($ret->wrap(__FILE__, __LINE__), null, null);
 
62
                if ($ret) {
 
63
                    return array($ret->wrap(__FILE__, __LINE__), null, null, null);
64
64
                }
65
65
 
66
 
                GalleryCoreApi::relativeRequireOnce(
 
66
                GalleryCoreApi::requireOnce(
67
67
                    'modules/watermark/classes/WatermarkHelper.class');
68
68
                $ret = WatermarkHelper::watermarkItem(
69
69
                    $watermark, $item, $form['xPercent'], $form['yPercent'],
73
73
                              $form['whichDerivative']['resize']),
74
74
                          DERIVATIVE_TYPE_IMAGE_THUMBNAIL => isset(
75
75
                              $form['whichDerivative']['thumbnail'])));
76
 
                if ($ret->isError()) {
77
 
                    return array($ret->wrap(__FILE__, __LINE__), null, null);
 
76
                if ($ret) {
 
77
                    return array($ret->wrap(__FILE__, __LINE__), null, null, null);
78
78
                }
79
79
                $status = $module->translate('Watermark applied successfully');
80
80
            }
81
81
        } else if (isset($form['action']['remove'])) {
82
82
            list ($ret, $derivativeTable) =
83
83
                GalleryCoreApi::fetchDerivativesByItemIds(array($item->getId()));
84
 
            if ($ret->isError()) {
85
 
                return array($ret->wrap(__FILE__, __LINE__), null, null);
 
84
            if ($ret) {
 
85
                return array($ret->wrap(__FILE__, __LINE__), null, null, null);
86
86
            }
87
87
 
88
88
            if (isset($derivativeTable[$item->getId()])) {
95
95
 
96
96
                /* Lock them all */
97
97
                list ($ret, $lockId) = GalleryCoreApi::acquireWriteLock($ids);
98
 
                if ($ret->isError()) {
99
 
                    return array($ret->wrap(__FILE__, __LINE__), null, null);
 
98
                if ($ret) {
 
99
                    return array($ret->wrap(__FILE__, __LINE__), null, null, null);
100
100
                }
101
101
 
102
102
                foreach ($derivatives as $derivative) {
103
103
                    list ($ret, $derivative) = $derivative->refresh();
104
 
                    if ($ret->isError()) {
105
 
                        return array($ret->wrap(__FILE__, __LINE__), null, null);
 
104
                    if ($ret) {
 
105
                        return array($ret->wrap(__FILE__, __LINE__), null, null, null);
106
106
                    }
107
107
 
108
108
                    $newPostFilters = GalleryCoreApi::removeDerivativeOperation(
113
113
                        $preferred = $derivative;
114
114
                    }
115
115
 
116
 
                    $ret = $derivative->save(true);
117
 
                    if ($ret->isError()) {
118
 
                        return array($ret->wrap(__FILE__, __LINE__), null, null);
 
116
                    $ret = $derivative->save();
 
117
                    if ($ret) {
 
118
                        return array($ret->wrap(__FILE__, __LINE__), null, null, null);
119
119
                    }
120
120
                }
121
121
 
122
122
 
123
123
                $ret = GalleryCoreApi::releaseLocks($lockId);
124
 
                if ($ret->isError()) {
125
 
                    return array($ret->wrap(__FILE__, __LINE__), null, null);
 
124
                if ($ret) {
 
125
                    return array($ret->wrap(__FILE__, __LINE__), null, null, null);
126
126
                }
127
127
            }
128
128
 
129
129
            if (isset($preferred)) {
130
130
                list ($ret, $preferred) = $preferred->refresh();
131
 
                if ($ret->isError()) {
132
 
                    return array($ret->wrap(__FILE__, __LINE__), null, null);
 
131
                if ($ret) {
 
132
                    return array($ret->wrap(__FILE__, __LINE__), null, null, null);
133
133
                }
134
134
 
135
135
                if ($preferred->hasNoOperations()) {
136
136
                    $ret = GalleryCoreApi::remapSourceIds(
137
137
                        $preferred->getId(), $preferred->getDerivativeSourceId());
138
 
                    if ($ret->isError()) {
139
 
                        return array($ret->wrap(__FILE__, __LINE__), null, null);
 
138
                    if ($ret) {
 
139
                        return array($ret->wrap(__FILE__, __LINE__), null, null, null);
140
140
                    }
141
141
 
142
142
                    $ret = GalleryCoreApi::deleteEntityById($preferred->getId());
143
 
                    if ($ret->isError()) {
144
 
                        return array($ret->wrap(__FILE__, __LINE__), null, null);
 
143
                    if ($ret) {
 
144
                        return array($ret->wrap(__FILE__, __LINE__), null, null, null);
145
145
                    }
146
146
                }
147
147
            }
148
148
            $status = $module->translate('Watermark removed successfully');
149
149
        }
150
150
 
151
 
        return array(GalleryStatus::success(), $error, $status);
 
151
        return array(null, $error, $status, false);
152
152
    }
153
153
 
154
154
    /**
161
161
        $ItemEditWatermark['showApplet'] = $thumbnail != null;
162
162
 
163
163
        list ($ret, $ItemEditWatermark['isAdmin']) = GalleryCoreApi::isUserInSiteAdminGroup();
164
 
        if ($ret->isError()) {
 
164
        if ($ret) {
165
165
            return array($ret->wrap(__FILE__, __LINE__), null, null);
166
166
        }
167
167
 
168
168
        /* Load up all watermarks */
169
 
        GalleryCoreApi::relativeRequireOnce('modules/watermark/classes/WatermarkHelper.class');
 
169
        GalleryCoreApi::requireOnce('modules/watermark/classes/WatermarkHelper.class');
170
170
        list ($ret, $watermarks) = WatermarkHelper::fetchWatermarks();
171
 
        if ($ret->isError()) {
 
171
        if ($ret) {
172
172
            return array($ret->wrap(__FILE__, __LINE__), null, null);
173
173
        }
174
174
 
175
175
        if (!empty($watermarks)) {
176
176
            foreach (array_keys($watermarks) as $watermarkId) {
177
 
                $watermarks[$watermarkId] = $watermarks[$watermarkId]->getMemberData();
 
177
                $watermarks[$watermarkId] = (array)$watermarks[$watermarkId];
178
178
            }
179
179
        }
180
180
 
232
232
        /* Grab the smallest derivative that's greater than 400px on a side */
233
233
        list ($ret, $derivatives) =
234
234
            GalleryCoreApi::fetchDerivativesByItemIds(array($item->getId()));
235
 
        if ($ret->isError()) {
 
235
        if ($ret) {
236
236
            return array($ret->wrap(__FILE__, __LINE__), null, null);
237
237
        }
238
238
        $smallestSize = null;
250
250
 
251
251
        $ItemEditWatermark = array();
252
252
        $ItemEditWatermark['watermarks'] = $watermarks;
253
 
        $ItemEditWatermark['item'] = $item->getMemberData();
 
253
        $ItemEditWatermark['item'] = (array)$item;
254
254
        $ItemEditWatermark['derivative'] =
255
 
            isset($displayDerivative) ? $displayDerivative->getMemberData() : null;
 
255
            isset($displayDerivative) ? (array)$displayDerivative : null;
256
256
 
257
257
        $template->setVariable('ItemEditWatermark', $ItemEditWatermark);
258
258
        $template->setVariable('controller', 'core.ItemEditWatermark');
259
 
        return array(GalleryStatus::success(),
 
259
        return array(null,
260
260
                     'modules/watermark/templates/ItemEditWatermark.tpl', 'modules_watermark');
261
261
    }
262
262
 
271
271
 
272
272
        list ($ret, $toolkit) =
273
273
            GalleryCoreApi::getToolkitByOperation($item->getMimeType(), 'composite');
274
 
        if ($ret->isError()) {
 
274
        if ($ret) {
275
275
            return false; /* Swallow the error for now */
276
276
        }
277
277
        if (isset($toolkit)) {
281
281
        /* Ok we have no composite for the item .. but maybe we do for its preferred? */
282
282
        list ($ret, $preferredTable) =
283
283
            GalleryCoreApi::fetchPreferredsByItemIds(array($item->getId()));
284
 
        if ($ret->isError()) {
 
284
        if ($ret) {
285
285
            return false; /* Swallow the error for now */
286
286
        }
287
287
 
289
289
            $preferred = $preferredTable[$item->getId()];
290
290
            list ($ret, $toolkit) =
291
291
                GalleryCoreApi::getToolkitByOperation($preferred->getMimeType(), 'composite');
292
 
            if ($ret->isError()) {
 
292
            if ($ret) {
293
293
                return false; /* Swallow the error for now */
294
294
            }
295
295
            if (isset($toolkit)) {
305
305
     */
306
306
    function getTitle() {
307
307
        list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'watermark');
308
 
        if ($ret->isError()) {
 
308
        if ($ret) {
309
309
            return array($ret->wrap(__FILE__, __LINE__), null);
310
310
        }
311
311
 
312
 
        return array(GalleryStatus::success(), $module->translate('Watermark'));
 
312
        return array(null, $module->translate('Watermark'));
313
313
    }
314
314
}
315
315
?>