Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezimagevariation.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezimagevariation.php 9854 2003-06-12 14:33:53Z br $
5 //
6 // Definition of eZImageVariation class
7 //
8 // Created on: <21-Sep-2000 17:28:57 bf>
9 //
10 // This source file is part of Exponential Basic, publishing software.
11 //
12 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
13 //
14 // This program is free software; you can redistribute it and/or
15 // modify it under the terms of the GNU General Public License
16 // as published by the Free Software Foundation; either version 2
17 // of the License, or (at your option) any later version.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
27 //
30
35 // include_once( "classes/ezdb.php" );
36 // include_once( "classes/ezimagefile.php" );
37 // // include_once( "classes/ezimage.php" );
38 // // include_once( "classes/ezimagevariationgroup.php" );
39
40 class eZImageVariation
41 {
45 function __construct( $id="" )
46 {
47 $this->ImageID = 0;
48 $this->VariationGroupID = 0;
49 $this->Width = 0;
50 $this->Height = 0;
51 $this->ImagePath = "";
52 $this->Modification = "";
53
54 if ( $id != "" )
55 {
56 $this->ID = $id;
57 $this->get( $this->ID );
58 }
59 }
60
64 function store()
65 {
66 $db =& eZDB::globalDatabase();
67 $db->begin();
68
69 $db->lock( "eZImageCatalogue_ImageVariation" );
70
71 $this->ID = $db->nextID( "eZImageCatalogue_ImageVariation", "ID" );
72
73 $ret = $db->query( "Select ID FROM eZImageCatalogue_ImageVariation WHERE ID='$this->ID'" );
74 // if ( $ret == true )
75 // $db->query( "DELETE FROM eZImageCatalogue_ImageVariation WHERE ID='$this->ID'" );
76
77 if( $ret == false )
78 {
79 $query = "INSERT INTO eZImageCatalogue_ImageVariation
80 ( ID, ImageID, VariationGroupID, Width, Height, ImagePath, Modification ) VALUES
81 ( '$this->ID',
82 '$this->ImageID',
83 '$this->VariationGroupID',
84 '$this->Width',
85 '$this->Height',
86 '$this->ImagePath',
87 '$this->Modification' )";
88 $res = $db->query( $query );
89 }
90 $db->unlock();
91
92 if ( $res == false )
93 $db->rollback( );
94 else
95 $db->commit();
96
97 return $res;
98 }
99
103 function get( $id="" )
104 {
105 $db =& eZDB::globalDatabase();
106
107 if ( $id != "" )
108 {
109 $query = "SELECT * FROM eZImageCatalogue_ImageVariation WHERE ID='$id'";
110
111 $db->array_query( $image_variation_array, $query );
112 if ( count( $image_variation_array ) > 1 )
113 {
114 print( "Error: ImageVariations's with the same ID was found in the database. This shouldent happen." );
115 }
116 else if( count( $image_variation_array ) == 1 )
117 {
118 $this->ID =& $image_variation_array[0][$db->fieldName("ID")];
119 $this->ImageID =& $image_variation_array[0][$db->fieldName("ImageID")];
120 $this->VariationGroupID =& $image_variation_array[0][$db->fieldName("VariationGroupID")];
121 $this->ImagePath =& $image_variation_array[0][$db->fieldName("ImagePath")];
122 $this->Width =& $image_variation_array[0][$db->fieldName("Width")];
123 $this->Height =& $image_variation_array[0][$db->fieldName("Height")];
124 $this->Modification =& $image_variation_array[0][$db->fieldName("Modification")];
125 }
126 }
127 }
128
132 function delete()
133 {
134 $db =& eZDB::globalDatabase();
135
136 if ( isset( $this->ID ) )
137 {
138 $db->query( "DELETE FROM eZImageCatalogue_ImageVariation WHERE ID='$this->ID'" );
139 }
140
141 // Delete from the filesystem
142 if ( file_exists( $this->imagePath( true ) ) )
143 {
144 eZPBFile::unlink( $this->imagePath( true ) );
145 }
146 }
147
148
152 function getByGroupAndImage( $groupID, $imageID, $modification )
153 {
154 $db =& eZDB::globalDatabase();
155 $ret = false;
156
157 if ( $groupID != "" )
158 {
159 $db->array_query( $image_variation_array, "SELECT * FROM eZImageCatalogue_ImageVariation
160 WHERE VariationGroupID='$groupID'
161 AND ImageID='$imageID' AND Modification='$modification'", array( "Limit" => 1, "Offset" => 0 ) );
162
163 if ( count( $image_variation_array ) > 0 )
164 {
165 $this->ID =& $image_variation_array[0][$db->fieldName("ID")];
166 $this->ImageID =& $image_variation_array[0][$db->fieldName("ImageID")];
167 $this->VariationGroupID =& $image_variation_array[0][$db->fieldName("VariationGroupID")];
168 $this->ImagePath =& $image_variation_array[0][$db->fieldName("ImagePath")];
169 $this->Width =& $image_variation_array[0][$db->fieldName("Width")];
170 $this->Height =& $image_variation_array[0][$db->fieldName("Height")];
171 $this->Modification =& $image_variation_array[0][$db->fieldName("Modification")];
172
173 $ret = true;
174 }
175
176 if ( !file_exists( $this->ImagePath ) or !is_file( $this->ImagePath ) )
177 {
178 $ret = false;
179 }
180 }
181
182 return $ret;
183 }
184
190 function requestVariation( &$image, &$variationGroup, $convertToGray = false, $allow_error = false )
191 {
192 $ret = false;
193
194 if ( is_a( $image, "eZImage" ) && is_a( $variationGroup, "eZImageVariationGroup" ) )
195 {
196 $variation = new eZImageVariation();
197
198 $modification = "";
199 if ( $convertToGray == true )
200 $modification .= "gray";
201
202 if ( $variation->getByGroupAndImage( $variationGroup->id(), $image->id(), $modification ) == true )
203 {
204 $ret =& $variation;
205 }
206 else
207 {
208 if ( !$image->fileExists( true ) )
209 return $allow_error ? false : eZImageVariation::createErrorImage();
210
211 $imageFile = new eZPBImageFile();
212 $imageFile->getFile( $image->filePath( true ) );
213 $imageFile->setType( "image/jpeg" );
214
215 $info = eZPBImageFile::information( $image->originalFileName(), true );
216 $suffix = $info["suffix"];
217 $postfix = $info["dot-suffix"];
218 $imageFile->setType( $info["image-type"] );
219
220 $dest = "var/site/storage/ezimagecatalogue/variations/" . $image->id() . "-"
221 . $variationGroup->width() . "x". $variationGroup->height() . $modification . $postfix;
222
223 $result = $imageFile->scaleCopy( $dest, $variationGroup->width(), $variationGroup->height(), $convertToGray );
224
225 if ( !is_bool( $result ) and $result == "locked" )
226 {
227 if ( $variation->getByGroupAndImage( $variationGroup->id(), $image->id(), $modification ) )
228 {
229 $ret =& $variation;
230 }
231 else {
232 if (file_exists($dest) or is_file($dest))
233 {
234 $variation->setImagePath($dest);
235 $variation->store();
236 $ret =& $variation;
237 }
238 else {
239 return $allow_error ? false : eZImageVariation::createErrorImage();
240 print( "<br><b>Timeout when retrieveing variation</b><br>" );
241 }
242 }
243 }
244 else if ( $result )
245 {
246 if ( !file_exists( $dest ) or !is_file( $dest ) )
247 return $allow_error ? false : eZImageVariation::createErrorImage();
248 $size = GetImageSize( $dest );
249 if ( !$size )
250 return $allow_error ? false : eZImageVariation::createErrorImage();
251
252 $variation->setWidth( $size[0] );
253 $variation->setHeight( $size[1] );
254 $variation->setImagePath( $dest );
255 $variation->setImageID( $image->id() );
256 $variation->setVariationGroupID( $variationGroup->id() );
257 $variation->setModification( $modification );
258
259 $variation->store();
260
261 $ret = $variation;
262 }
263 else
264 return $allow_error ? false : eZImageVariation::createErrorImage();
265 }
266 }
267
268 return $ret;
269 }
270
274 function imageID()
275 {
276 return $this->ImageID;
277 }
278
282 function variationGroupID()
283 {
284 return $this->VariationGroupID;
285 }
286
290 function imagePath()
291 {
292 return $this->ImagePath;
293 }
294
298 function width()
299 {
300 return $this->Width;
301 }
302
306 function height()
307 {
308 return $this->Height;
309 }
310
314 function id()
315 {
316 return $this->ID;
317 }
318
322 function setImageID( $value )
323 {
324 $this->ImageID = $value;
325 }
326
330 function setVariationGroupID( $value )
331 {
332 $this->VariationGroupID = $value;
333 }
334
338 function setImagePath( $value )
339 {
340 $this->ImagePath = $value;
341 }
342
346 function setWidth( $value )
347 {
348 $this->Width = $value;
349 }
350
354 function setHeight( $value )
355 {
356 $this->Height = $value;
357 }
358
362 function setModification( $value )
363 {
364 $this->Modification = $value;
365 }
366
367
371 function createErrorImage()
372 {
373 $imageVar = new eZImageVariation();
374 $imageVar->setImagePath( "kernel/ezimagecatalogue/admin/images/failedimage.gif" );
375 $imageVar->ImageID = -1;
376 $imageVar->setWidth( 120 );
377 $imageVar->setHeight( 40 );
378 return $imageVar;
379 }
380
381 var $ID;
382 var $ImageID;
383 var $VariationGroupID;
384 var $ImagePath;
385 var $Width;
386 var $Height;
387 var $Modification;
388 }
389
390 ?>
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZImageVariation
Definition: ezimagevariation.php:41
eZImageVariation\$ImagePath
$ImagePath
Definition: ezimagevariation.php:384
eZImageVariation\$ImageID
$ImageID
Definition: ezimagevariation.php:382
eZImageVariation\$VariationGroupID
$VariationGroupID
Definition: ezimagevariation.php:383
eZImageVariation\setHeight
setHeight( $value)
Definition: ezimagevariation.php:354
eZImageVariation\setVariationGroupID
setVariationGroupID( $value)
Definition: ezimagevariation.php:330
eZImageVariation\width
width()
Definition: ezimagevariation.php:298
eZImageVariation\getByGroupAndImage
getByGroupAndImage( $groupID, $imageID, $modification)
Definition: ezimagevariation.php:152
eZImageVariation\$ID
$ID
Definition: ezimagevariation.php:381
eZImageVariation\setImagePath
setImagePath( $value)
Definition: ezimagevariation.php:338
eZImageVariation\store
store()
Definition: ezimagevariation.php:64
eZImageVariation\height
height()
Definition: ezimagevariation.php:306
eZImageVariation\imagePath
imagePath()
Definition: ezimagevariation.php:290
eZImageVariation\$Height
$Height
Definition: ezimagevariation.php:386
eZImageVariation\__construct
__construct( $id="")
Definition: ezimagevariation.php:45
eZImageVariation\setModification
setModification( $value)
Definition: ezimagevariation.php:362
eZImageVariation\id
id()
Definition: ezimagevariation.php:314
eZImageVariation\setWidth
setWidth( $value)
Definition: ezimagevariation.php:346
eZImageVariation\$Modification
$Modification
Definition: ezimagevariation.php:387
eZImageVariation\$Width
$Width
Definition: ezimagevariation.php:385
eZImageVariation\createErrorImage
createErrorImage()
Definition: ezimagevariation.php:371
eZImageVariation\imageID
imageID()
Definition: ezimagevariation.php:274
eZImageVariation\setImageID
setImageID( $value)
Definition: ezimagevariation.php:322
eZImageVariation\variationGroupID
variationGroupID()
Definition: ezimagevariation.php:282
eZImageVariation\requestVariation
requestVariation(&$image, &$variationGroup, $convertToGray=false, $allow_error=false)
Definition: ezimagevariation.php:190
eZPBFile\unlink
static unlink( $filename)
Definition: ezpbfile.php:352
eZPBImageFile
Definition: ezpbimagefile.php:71
eZPBImageFile\information
static & information( $file, $use_default=false)
Definition: ezpbimagefile.php:108
$result
$result
Definition: companysearch.php:94
$id
$id
Definition: companytypelist.php:193
file_exists
static file_exists( $inifilename)
Definition: eZPBINIFile.php:195
$query
if(isset( $Year) &&!is_numeric( $Year)||isset( $Month) &&!is_numeric( $Month)) $query
Definition: entryexitpages.php:65
$db
$db
Definition: ezarticle/user/authorlist.php:53
$size
if($file_debug) $size
Definition: ezfilemanager/user/filedownload.php:165
$suffix
$suffix
Definition: ezfilemanager/user/filedownload.php:168
$groupID
$groupID
Definition: ezgroupeventcalendar/user/dayview.php:90
$variation
$variation
Definition: ezimagecatalogue/user/menubox.php:55
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$res
$res
Definition: ezstats/admin/cron.php:45
$image
$image
Definition: user/articlelist.php:242
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.