Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

image.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: image.php 9691 2002-08-06 15:15:45Z gl $
5 //
6 // Created on: <14-Jun-2001 13:18:27 amos>
7 //
8 // This source file is part of Exponential Basic, publishing software.
9 //
10 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
11 //
12 // This program is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License
14 // as published by the Free Software Foundation; either version 2
15 // of the License, or (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
25 //
26
27 // include_once( "ezimagecatalogue/classes/ezimage.php" );
28 // include_once( "ezimagecatalogue/classes/ezimagevariation.php" );
29 // include_once( "ezimagecatalogue/classes/ezimagecategory.php" );
30 // include_once( "ezuser/classes/ezobjectpermission.php" );
31 // include_once( "ezxmlrpc/classes/ezxmlrpcarray.php" );
32 // include_once( "ezxmlrpc/classes/ezxmlrpcbool.php" );
33 // include_once( "ezxmlrpc/classes/ezxmlrpcint.php" );
34 // include_once( "classes/ezlocale.php" );
35 // include_once( "ezsitemanager/classes/ezsection.php" );
36
37 if( $Command == "info" )
38 {
39 $image = new eZImage();
40 if ( !$image->get( $ID ) )
41 {
42 $Error = createErrorMessage( EZERROR_NONEXISTING_OBJECT );
43 }
44 else
45 {
46 $ret = array( "Name" => new eZXMLRPCString( $image->name( false ) ) );
47 $ReturnData = new eZXMLRPCStruct( $ret );
48 }
49 }
50 else if ( $Command == "permission" )
51 {
52 $img = new eZImage( $ID );
53 $cat = $img->categoryDefinition();
54 $CategoryID = $cat->id();
55 $read_c = eZObjectPermission::hasPermission( $CategoryID, "imagecatalogue_category", "r", $User );
56 $edit_c = eZObjectPermission::hasPermission( $CategoryID, "imagecatalogue_category", 'w', $User );
57 $read = ( eZObjectPermission::hasPermission( $ID, "imagecatalogue_image", "r", $User ) and
58 $read_c );
59 $edit = ( eZObjectPermission::hasPermission( $ID, "imagecatalogue_image", 'w', $User ) and
60 $edit_c );
61 // $read = eZObjectPermission::hasPermissionWithDefinition( $ID, "imagecatalogue_image", "r", $User, $CategoryID );
62 // $edit = eZObjectPermission::hasPermissionWithDefinition( $ID, "imagecatalogue_image", 'w', $User, $CategoryID );
63
64 $ret = array( "Read" => new eZXMLRPCBool( $read ),
65 "Edit" => new eZXMLRPCBool( $edit ) );
66 $ReturnData = new eZXMLRPCStruct( $ret );
67 }
68 else if( $Command == "data" ) // Dump image info!
69 {
70 unset( $width );
71 unset( $height );
72 if ( is_object( $Data["Size"] ) )
73 {
74 $size = $Data["Size"]->value();
75 if ( is_object( $size["Width"] ) and is_object( $size["Height"] ) )
76 {
77 $width = $size["Width"]->value();
78 $height = $size["Height"]->value();
79 }
80 }
81
82 if ( isset( $width ) and isset( $height ) )
83 {
84 $writeGroups = eZObjectPermission::getGroups( $ID, "imagecatalogue_image", 'w', false );
85 $readGroups = eZObjectPermission::getGroups( $ID, "imagecatalogue_image", 'r', false );
86
87 $rgp = array();
88 $wgp = array();
89 foreach( $readGroups as $group )
90 $rgp[] = new eZXMLRPCInt( $group );
91 foreach( $writeGroups as $group )
92 $wgp[] = new eZXMLRPCInt( $group );
93
94 $image = new eZImage( $ID );
95 $variation = $image->requestImageVariation( $width, $height, false, true );
96 if ( !is_bool( $variation ) )
97 {
98 $size = 0;
99 if ( $image->fileExists( true ) )
100 {
101 $imagePath =& $image->filePath( true );
102 $size = eZPBFile::filesize( $imagePath );
103 $user = $image->user();
104 $user_id = is_a( $user, "eZUser" ) ? $user->id() : 0;
105 $cat_def = $image->categoryDefinition();
106 $cat_def_id = is_a( $cat_def, "eZImageCategory" ) ? $cat_def->id() : 0;
107 $cats = $image->categories();
108 $cats = array_diff( $cats, array( $cat_def_id ) );
109
110 $section_id = 0;
111 $cat_def_id = 0;
112 $cat_def = $image->categoryDefinition();
113 if ( is_object( $cat_def ) )
114 {
115 $cat_def_id = $cat_def->id();
116 $section_id = eZImageCategory::sectionIDStatic( $cat_def_id );
117 }
118 $section_lang = false;
119 if ( $section_id != 0 )
120 {
121 $section = new eZSection( $section_id );
122 $section_lang = $section->language();
123 }
124
125 $photoid = $image->photographer( false );
126 $ret = array(
127 "Name" => new eZXMLRPCString( $image->name( false ) ),
128 "Caption" => new eZXMLRPCString( $image->caption( false ) ),
129 "Description" => new eZXMLRPCString( $image->description( false ) ),
130 "FileName" => new eZXMLRPCString( $image->fileName() ),
131 "OriginalFileName" => new eZXMLRPCString( $image->originalFileName() ),
132 "FileSize" => new eZXMLRPCInt( $size ),
133 "UserID" => new eZXMLRPCInt( $user_id ),
134 "PhotographerID" => new eZXMLRPCInt( $photoid > 0 ? $photoid : 0 ),
135 "ReadGroups" => new eZXMLRPCArray( $rgp ),
136 "WriteGroups" => new eZXMLRPCArray( $wgp ),
137 "Categories" => new eZXMLRPCArray( $cats, "integer" ),
138 "Category" => new eZXMLRPCInt( $cat_def_id ),
139 "WebURL" => new eZXMLRPCString( rewriteHTTPURL( "/" . $variation->imagePath() ) ),
140 "Size" => createSizeStruct( $variation->width(), $variation->height() ),
141 "RequestSize" => createSizeStruct( $width, $height )
142 );
143 if ( $section_lang != false )
144 {
145 $charsetLocale = new eZLocale( $section_lang );
146 $section_charset = $charsetLocale->languageISO();
147 $ret["Section"] = new eZXMLRPCStruct( array( "Language" => $section_lang,
148 "Charset" => $section_charset ) );
149 }
150 $ReturnData = new eZXMLRPCStruct( $ret );
151 }
152 else
153 $Error = createErrorMessage( EZERROR_CUSTOM, "Image $ID does not exist on disk",
154 EZIMAGECATALOGUE_NONEXISTING_IMAGE );
155 }
156 else
157 $Error = createErrorMessage( EZERROR_CUSTOM, "Couldn't convert image $ID",
158 EZIMAGECATALOGUE_CONVERT_ERROR );
159 }
160 else
161 {
162 $Error = createErrorMessage( EZERROR_CUSTOM, "Missing width and height in image request",
163 EZIMAGECATALOGUE_SIZE_MISSING );
164 }
165 }
166 else if ( $Command == "storedata" )
167 {
168 if ( isset( $Data["Title"] ) and isset( $Data["Caption"] ) and isset( $Data["Description"] ) and isset( $Data["PhotographerID"] ) )
169 {
170 $title = $Data["Title"]->value();
171 $caption = $Data["Caption"]->value();
172 $description = $Data["Description"]->value();
173 $photographer = $Data["PhotographerID"]->value();
174 $readgroups = $Data["ReadGroups"]->value();
175 $writegroups = $Data["WriteGroups"]->value();
176 $category_id = $Data["Category"]->value();
177 $categories = $Data["Categories"]->value();
178
179 $image = new eZImage();
180 if ( $ID != 0 )
181 {
182 if ( !$image->get( $ID ) )
183 $Error = createErrorMessage( EZERROR_NONEXISTING_OBJECT );
184 }
185 if ( !$Error )
186 {
187 $image->setName( $title );
188 $image->setCaption( $caption );
189 $image->setDescription( $description );
190 $image->setPhotographer( $photographer > 0 ? $photographer : 0 );
191 if ( isset( $Data["Image"] ) and isset( $Data["ImageFileName"] ) )
192 {
193 $image_data = $Data["Image"]->value();
194 $orig_file = $Data["ImageFileName"]->value();
195 $image_file = new eZPBImageFile();
196 $image_file->dumpDataToFile( $image_data, $orig_file );
197 if ( !$image->setImage( $image_file ) )
198 {
199 $Error = createErrorMessage( EZERROR_CUSTOM, "Failed to set image sent by client to image $ID",
200 EZIMAGECATALOGUE_BAD_IMAGE );
201 }
202 }
203 if ( !$Error )
204 {
205 $image->store();
206 $ID = $image->id();
207
208 $old_category = $image->categoryDefinition();
209
210 $category = new eZImageCategory( $category_id );
211 $image->setCategoryDefinition( $category );
212
213 // categories...
214 $old_categories =& $image->categories();
215 if ( is_bool( $old_categories ) )
216 $old_categories = array();
217 $new_categories = array();
218 foreach( $categories as $cat )
219 {
220 $new_categories[] = $cat->value();
221 }
222 $new_cats = $new_categories;
223 if ( $category_id > 0 )
224 $new_categories = array_unique( array_merge( $new_categories, $category_id ) );
225 $remove_categories = array_diff( $old_categories, $new_categories );
226 $add_categories = array_diff( $new_categories, $old_categories );
227 $cur_categories = array_intersect( $old_categories, $new_categories );
228
229 foreach ( $remove_categories as $categoryItem )
230 {
231 eZImageCategory::removeImage( $image, $categoryItem );
232 }
233 foreach ( $add_categories as $categoryItem )
234 {
235 eZImageCategory::addImage( $image, $categoryItem );
236 }
237
238 // permissions...
239 eZObjectPermission::removePermissions( $ID, "imagecatalogue_image", 'r' );
240 foreach( $readgroups as $readgroup )
241 eZObjectPermission::setPermission( $readgroup->value(), $ID, "imagecatalogue_image", 'r' );
242
243 eZObjectPermission::removePermissions( $ID, "imagecatalogue_image", 'w' );
244 foreach( $writegroups as $writegroup )
245 eZObjectPermission::setPermission( $writegroup->value(), $ID, "imagecatalogue_image", 'w' );
246
247 $ID = $image->id();
248
249 $par = array();
250
251 $par =& createPath( $category, "ezimagecatalogue", "category" );
252
253 $add_locs =& createURLArray( $add_categories, "ezimagecatalogue", "category" );
254 $cur_locs =& createURLArray( $cur_categories, "ezimagecatalogue", "category" );
255 $old_locs =& createURLArray( $remove_categories, "ezimagecatalogue", "category" );
256
257 $ReturnData = new eZXMLRPCStruct( array( "Location" => createURLStruct( "ezimagecatalogue", "image", $ID ),
258 "Name" => new eZXMLRPCString( $image->name( false ) ),
259 "Path" => new eZXMLRPCArray( $par ),
260 "NewLocations" => $add_locs,
261 "ChangedLocations" => $cur_locs,
262 "RemovedLocations" => $old_locs,
263 "UpdateType" => new eZXMLRPCString( $Command )
264 )
265 );
266 $Command = "update";
267 }
268 }
269 }
270 else
271 {
272 $Error = createErrorMessage( EZERROR_BAD_REQUEST_DATA );
273 }
274 }
275 else if ( $Command == "search" )
276 {
277 $keywords = $Data["Keywords"]->value();
278 $texts = array();
279 foreach( $keywords as $keyword )
280 {
281 $texts[] = $keyword->value();
282 }
283 $elements = array();
284 $result =& eZImage::search( $texts, true );
285 foreach( $result as $item )
286 {
287 $cat =& $item->categoryDefinition();
288 if ( is_a( $cat, "eZImageCategory" ) )
289 {
290 $cats =& $item->categories();
291 if ( is_array( $cats ) and count( $cats ) > 0 )
292 {
293 $cat = new eZImageCategory( $cats[0] );
294 }
295 else
296 continue;
297 }
298 $itemid = $item->id();
299 $catid = $cat->id();
300 $elements[] = new eZXMLRPCStruct( array( "Name" => new eZXMLRPCString( $item->name( false ) ),
301 "CategoryName" => new eZXMLRPCString( $cat->name( false ) ),
302 "Location" => createURLStruct( "ezimagecatalogue", "image", $item->id() ),
303 "CategoryLocation" => createURLStruct( "ezimagecatalogue", "category", $cat->id() ),
304 "HasPreview" => new eZXMLRPCBool( true ),
305 "WebURL" => new eZXMLRPCString( rewriteWebURL( "/imagecatalogue/imageview/$itemid/" ) ),
306 "CategoryWebURL" => new eZXMLRPCString( rewriteWebURL( "/imagecatalogue/image/list/$catid/" ) )
307 ) );
308 }
309 $ret = array( "Elements" => new eZXMLRPCArray( $elements ) );
310 handleSearchData( $ret );
311 $ReturnData = new eZXMLRPCStruct( $ret );
312 }
313 else if( $Command == "delete" )
314 {
315 $image = new eZImage();
316 if ( $image->get( $ID ) )
317 {
318 $category = $image->categoryDefinition();
319 $par =& createPath( $category, "ezimagecatalogue", "category" );
320
321 $ReturnData = new eZXMLRPCStruct( array( "Location" => createURLStruct( "ezimagecatalogue", "image", $ID ),
322 "Path" => new eZXMLRPCArray( $par ),
323 "UpdateType" => new eZXMLRPCString( $Command )
324 )
325 );
326 $Command = "update";
327 $image->delete();
328 }
329 else
330 $Error = createErrorMessage( EZERROR_NONEXISTING_OBJECT );
331 }
332
333 ?>
$category
if( $Action=="Edit") $category
Definition: adedit.php:378
$CategoryID
$CategoryID
Definition: admin/articleedit.php:53
$group
$group
Definition: admin/articleedit.php:799
eZImageCategory
Definition: ezimagecategory.php:43
eZImageCategory\addImage
static addImage( $value, $categoryid=false)
Definition: ezimagecategory.php:547
eZImageCategory\sectionIDStatic
static sectionIDStatic( $categoryID)
Definition: ezimagecategory.php:835
eZImageCategory\removeImage
static removeImage( $value, $categoryid=false)
Definition: ezimagecategory.php:594
eZImage
Definition: ezimage.php:95
eZImage\search
static search(&$queryText, $offset=0, $limit=30, $userID=-1)
Definition: ezimage.php:221
eZLocale
Definition: ezlocale.php:119
eZObjectPermission\hasPermission
static hasPermission( $objectID, $moduleTable, $permission, $user=false)
Definition: ezobjectpermission.php:76
eZObjectPermission\getGroups
static getGroups( $objectID, $moduleTable, $permission, $GroupReturn=true)
Definition: ezobjectpermission.php:365
eZObjectPermission\setPermission
static setPermission( $group, $objectID, $moduleTable, $permission)
Definition: ezobjectpermission.php:236
eZObjectPermission\removePermissions
static removePermissions( $objectID, $moduleTable, $permission)
Definition: ezobjectpermission.php:320
eZPBFile\filesize
static filesize( $filename)
Definition: ezpbfile.php:339
eZPBImageFile
Definition: ezpbimagefile.php:71
eZSection
Definition: ezsection.php:45
eZXMLRPCArray
Definition: ezxmlrpcarray.php:37
eZXMLRPCBool
Definition: ezxmlrpcbool.php:37
eZXMLRPCInt
Definition: ezxmlrpcint.php:37
eZXMLRPCString
Definition: ezxmlrpcstring.php:37
eZXMLRPCStruct
Definition: ezxmlrpcstruct.php:37
$item
$item
Definition: classes/admin/linklist.php:228
$result
$result
Definition: companysearch.php:94
$categories
$categories
Definition: ezarticle/admin/categoryedit.php:636
$size
if($file_debug) $size
Definition: ezfilemanager/user/filedownload.php:165
$cat
if(isset( $DeleteCategories)) $cat
Definition: ezforum/admin/categoryedit.php:49
$Error
if(isset( $EditButton)) if(!empty( $CancelButton)) if(!empty( $PreviewButton)) if( $Action=="preview") switch( $Action) $Error
Definition: ezforum/user/messageedit.php:134
$section
$section
Definition: ezimagecatalogue/user/categoryedit.php:393
$variation
$variation
Definition: ezimagecatalogue/user/menubox.php:55
EZIMAGECATALOGUE_SIZE_MISSING
const EZIMAGECATALOGUE_SIZE_MISSING
Definition: ezimagecatalogue/xmlrpc/datasupplier.php:29
EZIMAGECATALOGUE_BAD_IMAGE
const EZIMAGECATALOGUE_BAD_IMAGE
Definition: ezimagecatalogue/xmlrpc/datasupplier.php:30
EZIMAGECATALOGUE_CONVERT_ERROR
const EZIMAGECATALOGUE_CONVERT_ERROR
Definition: ezimagecatalogue/xmlrpc/datasupplier.php:28
EZIMAGECATALOGUE_NONEXISTING_IMAGE
const EZIMAGECATALOGUE_NONEXISTING_IMAGE
Definition: ezimagecatalogue/xmlrpc/datasupplier.php:27
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$elements
$elements
Definition: formedit.php:355
$ReturnData
$ReturnData
Definition: tag.php:48
$user
$user
Definition: user/adlist.php:39
$image
$image
Definition: user/articlelist.php:242
$height
$height
Definition: user/imageview.php:171
$width
$width
Definition: user/imageview.php:170
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.