Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezimage.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezimage.php 9705 2002-08-15 14:20:29Z gl $
5 //
6 // Definition of eZImage class
7 //
8 // Created on: <21-Sep-2000 11:22:21 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 //
28
31
82 // include_once( "classes/ezdb.php" );
83 // include_once( "classes/ezdatetime.php" );
84 // include_once( "classes/eztexttool.php" );
85
86 // include_once( "ezimagecatalogue/classes/ezimagevariation.php" );
87 // include_once( "ezimagecatalogue/classes/ezimagevariationgroup.php" );
88 // include_once( "ezimagecatalogue/classes/ezimagecategory.php" );
89
90 // include_once( "ezarticle/classes/ezarticle.php" );
91 // include_once( "eztrade/classes/ezproduct.php" );
92 // include_once( "ezforum/classes/ezforum.php" );
93
94 class eZImage
95 {
99 function __construct( $id = "" )
100 {
101 $this->PhotographerID = 0;
102 $this->UserID = 0;
103 $this->WritePermission = 0;
104 $this->ReadPermission = 0;
105 $this->NewImage = false;
106 if ( $id != "" )
107 {
108 $this->ID = $id;
109 $this->get( $this->ID );
110 }
111 }
112
116 function store()
117 {
118 $db =& eZDB::globalDatabase();
119
120 $db->begin();
121
122 $name = $db->escapeString( $this->Name );
123 $description = $db->escapeString( $this->Description );
124 $caption = $db->escapeString( $this->Caption );
125 $filename = $db->escapeString( $this->FileName );
126 $originalfilename = $db->fieldName( $this->OriginalFileName );
127 $keywords = $db->escapeString( $this->Keywords );
128
129 if ( !isset( $this->ID ) )
130 {
131 $db->lock( "eZImageCatalogue_Image" );
132
133 $timeStamp =& (new eZDateTime())->timeStamp( true );
134
135 $this->ID = $db->nextID( "eZImageCatalogue_Image", "ID" );
136 $res = $db->query( "INSERT INTO eZImageCatalogue_Image
137 ( ID,
138 Name,
139 Caption,
140 Description,
141 FileName,
142 UserID,
143 WritePermission,
144 ReadPermission,
145 OriginalFileName,
146 PhotographerID,
147 Keywords,
148 Created )
149 VALUES ( '$this->ID',
150 '$name',
151 '$caption',
152 '$description',
153 '$filename',
154 '$this->UserID',
155 '$this->WritePermission',
156 '$this->ReadPermission',
157 '$originalfilename',
158 '$this->PhotographerID',
159 '$keywords',
160 '$timeStamp' )");
161 $db->unlock();
162 }
163 else
164 {
165 if ( $this->NewImage )
166 {
167 $variationArray =& $this->variations();
168
169 foreach ( $variationArray as $variation )
170 {
171 $variation->delete();
172 }
173 }
174
175 $res = $db->query( "UPDATE eZImageCatalogue_Image SET
176 Name='$name',
177 Caption='$caption',
178 Description='$description',
179 FileName='$filename',
180 UserID='$this->UserID',
181 WritePermission='$this->WritePermission',
182 ReadPermission='$this->ReadPermission',
183 OriginalFileName='$originalfilename',
184 PhotographerID='$this->PhotographerID',
185 Keywords='$keywords'
186 WHERE ID='$this->ID'
187 " );
188 }
189
190 if ( $res == false )
191 $db->rollback();
192 else
193 $db->commit();
194 }
195
196 /*
197 function &search( $name, $literal = false )
198 {
199 $db =& eZDB::globalDatabase();
200 $res = array();
201
202 $query = new eZQuery( array( "Name", "Caption", "Description", "Keywords" ),
203 $name );
204 $query->setIsLiteral( $literal );
205 $where =& $query->buildQuery();
206
207 $db->array_query( $image_array,
208 "SELECT ID FROM eZImageCatalogue_Image WHERE $where" );
209
210 foreach( $image_array as $image )
211 {
212 $res[] =& new eZImage( $image[$db->fieldName("ID")] );
213 }
214 return $res;
215 }*/
216
221 static public function search( &$queryText, $offset = 0, $limit = 30, $userID = -1 )
222 {
223 $db =& eZDB::globalDatabase();
224 $ret = false;
225 $returnArray = array();
226 if ( $userID > -1 )
227 $user = new eZUser( $userID );
228 else
229 $user =& eZUser::currentUser();
230 $groupString = "AND i.ID=p.ObjectID AND c.ID=icl.CategoryID AND icl.ImageID=i.ID AND cp.ObjectID=c.ID AND cp.ReadPermission='1' AND ( ( ( (p.GroupID='-1' AND cp.GroupID='-1')";
231 if ( $user )
232 {
233 foreach ( $user->groups( false ) as $group )
234 {
235 $groupString .= "OR (p.GroupID='$group' AND cp.GroupID='$group') ";
236 $groupString .= "OR (p.GroupID='-1' AND cp.GroupID='$group') ";
237 $groupString .= "OR (p.GroupID='$group' AND cp.GroupID='-1') ";
238 }
239 }
240 $groupString .= ") AND p.ReadPermission='1' ) OR ( i.UserID='$userID' ) )";
241 $query = new eZQuery( array( "i.Name", "i.Description", "i.Caption" ), $queryText );
242 $query->setPartialCompare( true );
243 $queryString = "SELECT i.ID, i.Name as Count FROM eZImageCatalogue_Image as i";
244 if ( $user && $user->hasRootAccess() )
245 {
246 $groupString = "";
247 }
248 else
249 {
250 $queryString .= ", eZImageCatalogue_ImagePermission as p, eZImageCatalogue_Category as c,
251 eZImageCatalogue_ImageCategoryLink as icl, eZImageCatalogue_CategoryPermission as cp";
252 }
253 $queryString .= " WHERE (" . $query->buildQuery() . ") $groupString ";
254 $queryString .= " GROUP BY i.ID ORDER BY i.Name";
255 $limit = array( "Limit" => $limit,
256 "Offset" => $offset );
257 $db->array_query( $fileArray, $queryString, $limit );
258 foreach ( $fileArray as $file )
259 {
260 $returnArray[] = new eZImage( $file[$db->fieldName( "ID" )] );
261 }
262 return $returnArray;
263 }
264
269 static public function searchCount( $name, $literal = false )
270 {
271 $db =& eZDB::globalDatabase();
272 $ret = false;
273 $fileArray = array();
274 $returnArray = array();
275 $queryText = $name;
276
277 $user = eZUser::currentUser();
278
279 if( $user )
280 $userID = $user->id();
281 else
282 $userID = 0;
283
284 if ( $userID > -1 )
285 $user = new eZUser( $userID );
286 else
287 $user =& eZUser::currentUser();
288 $groupString = "AND i.ID=p.ObjectID AND c.ID=icl.CategoryID AND icl.ImageID=i.ID AND cp.ObjectID=c.ID AND cp.ReadPermission='1' AND ( ( ( (p.GroupID='-1' AND cp.GroupID='-1')";
289 if ( $user )
290 {
291 foreach ( $user->groups( false ) as $group )
292 {
293 $groupString .= "OR (p.GroupID='$group' AND cp.GroupID='$group') ";
294 $groupString .= "OR (p.GroupID='-1' AND cp.GroupID='$group') ";
295 $groupString .= "OR (p.GroupID='$group' AND cp.GroupID='-1') ";
296 }
297 }
298 $groupString .= ") AND p.ReadPermission='1' ) OR ( i.UserID='$userID' ) )";
299 $query = new eZQuery( array( "i.Name", "i.Description", "i.Caption" ), $queryText );
300 $query->setPartialCompare( true );
301 $queryString = "SELECT COUNT(i.ID) AS Count FROM eZImageCatalogue_Image as i";
302 if ( $user && $user->hasRootAccess() )
303 {
304 $groupString = "";
305 }
306 else
307 {
308 $queryString .= ", eZImageCatalogue_ImagePermission as p, eZImageCatalogue_Category as c,
309 eZImageCatalogue_ImageCategoryLink as icl, eZImageCatalogue_CategoryPermission as cp";
310 }
311 $queryString .= " WHERE (" . $query->buildQuery() . ") $groupString ";
312 $queryString .= " GROUP BY i.ID ORDER BY i.Name";
313 $db->array_query( $fileArray, $queryString );
314 // $ret = $fileArray[0][$db->fieldName( "Count" )];
315 $ret = count($fileArray);
316
317 return $ret;
318 }
319
323 function delete()
324 {
325 $db =& eZDB::globalDatabase();
326
327 if ( isset( $this->ID ) )
328 {
329 $variationArray =& $this->variations();
330
331 foreach ( $variationArray as $variation )
332 {
333 $variation->delete();
334 }
335
336 $db->query( "DELETE FROM eZImageCatalogue_Image WHERE ID='$this->ID'" );
337 $db->query( "DELETE FROM eZImageCatalogue_ImagePermission WHERE ObjectID='$this->ID'" );
338 $db->query( "DELETE FROM eZImageCatalogue_ImageCategoryLink WHERE ImageID='$this->ID'" );
339 $db->query( "DELETE FROM eZImageCatalogue_ImageCategoryDefinition WHERE ImageID='$this->ID'" );
340 $db->query( "DELETE FROM eZImageCatalogue_ImageMap WHERE ImageID='$this->ID'" );
341 $db->query( "DELETE FROM eZImageCatalogue_ImageForumLink WHERE ImageID='$this->ID'" );
342
343 // Delete from the filesystem
344 if ( file_exists( $this->filePath( true ) ) )
345 {
346 eZPBFile::unlink( $this->filePath( true ) );
347 }
348 }
349 }
350
354 function get( $id="" )
355 {
356 $db =& eZDB::globalDatabase();
357
358 $ret = false;
359 if ( $id != "" )
360 {
361 $db->array_query( $image_array, "SELECT * FROM eZImageCatalogue_Image WHERE ID='$id'" );
362 if ( count( $image_array ) > 0 )
363 {
364 if ( count( $image_array ) > 1 )
365 {
366 print( "<br /><b>Error: Image's with the same ID was found in the database. This shouldent happen.</b><br />" );
367 }
368 $this->ID =& $image_array[0][$db->fieldName( "ID" )];
369 $this->Name =& $image_array[0][$db->fieldName( "Name" )];
370 $this->Caption =& $image_array[0][$db->fieldName( "Caption" )];
371 $this->Description =& $image_array[0][$db->fieldName( "Description" )];
372 $this->FileName =& $image_array[0][$db->fieldName( "FileName" )];
373 $this->OriginalFileName =& $image_array[0][$db->fieldName( "OriginalFileName" )];
374 $this->UserID =& $image_array[0][$db->fieldName( "UserID" )];
375 $this->WritePermission =& $image_array[0][$db->fieldName( "WritePermission" )];
376 $this->ReadPermission =& $image_array[0][$db->fieldName( "ReadPermission" )];
377 $this->PhotographerID =& $image_array[0][$db->fieldName( "PhotographerID" )];
378 $this->Keywords =& $image_array[0][$db->fieldName( "Keywords" )];
379
380 $ret = true;
381 }
382 }
383
384 return $ret;
385 }
386
391 static public function getByOriginalFileName( $id = "" )
392 {
393 $db =& eZDB::globalDatabase();
394 $ret = new eZImage();
395 if ( $id != "" )
396 {
397 $db->array_query( $image_array, "SELECT * FROM eZImageCatalogue_Image WHERE OriginalFileName='$id'" );
398 if ( count( $image_array ) > 0 )
399 {
400 if ( count( $image_array ) > 1 )
401 {
402 print( "<br /><b>Error: Image's with the same was found in the database. This shouldn't happen.</b><br />" );
403 }
404 $ret = new eZImage( $image_array[0][$db->fieldName( "ID" )] );
405 }
406 }
407 return $ret;
408 }
409
414 function existsInCategory( $category )
415 {
416 $ret = false;
417 if ( is_a( $category, "eZImageCategory" ) )
418 {
419 $db =& eZDB::globalDatabase();
420 $catID = $category->id();
421
422 $db->array_query( $ret_array, "SELECT ID FROM eZImageCatalogue_ImageCategoryLink
423 WHERE ImageID='$this->ID' AND CategoryID='$catID'" );
424
425 if ( count( $ret_array ) == 1 )
426 {
427 $ret = true;
428 }
429 }
430 return $ret;
431 }
432
437 function setCategoryDefinition( $value )
438 {
439 if ( is_a( $value, "eZImageCategory" ) )
440 {
441 $db =& eZDB::globalDatabase();
442
443 $db->begin();
444
445 $categoryID = $value->id();
446
447 $db->query( "DELETE FROM eZImageCatalogue_ImageCategoryDefinition
448 WHERE ImageID='$this->ID'" );
449
450 $db->lock( "eZImageCatalogue_ImageCategoryDefinition" );
451
452 $nextID = $db->nextID( "eZImageCatalogue_ImageCategoryDefinition", "ID" );
453
454 $query = "INSERT INTO eZImageCatalogue_ImageCategoryDefinition ( ID, CategoryID, ImageID )
455 VALUES ( '$nextID', '$categoryID', '$this->ID' )";
456
457 $res = $db->query( $query );
458
459 $db->unlock();
460
461 if ( $res == false )
462 $db->rollback( );
463 else
464 $db->commit();
465 }
466 }
467
471 function categoryDefinition( )
472 {
473 $db =& eZDB::globalDatabase();
474
475 $db->array_query( $res, "SELECT CategoryID FROM
476 eZImageCatalogue_ImageCategoryDefinition
477 WHERE ImageID='$this->ID'" );
478
479 $category = false;
480 if ( count( $res ) == 1 )
481 {
482 $category = new eZImageCategory( $res[0][$db->fieldName( "CategoryID" )] );
483 }
484 else
485 {
486 return -1;
487 }
488
489 return $category;
490 }
491
497 function &getAll()
498 {
499 $db =& eZDB::globalDatabase();
500 $return_array = array();
501 $category_array = array();
502 $db->array_query( $category_array, "SELECT ID FROM eZImageCatalogue_Image ORDER BY Name" );
503 for ( $i = 0; $i < count( $category_array ); $i++ )
504 {
505 $return_array[$i] = new eZImage( $category_array[$i][$db->fieldName("ID")], 0 );
506 }
507 return $return_array;
508 }
509
515 static public function getUnassigned( $offset = -1, $limit = -1 )
516 {
517 $db =& eZDB::globalDatabase();
518 $returnArray = array();
519 $imageArray = array();
520
521 if ( $offset > 0 || $limit > 0 )
522 $limitArray = array( "Offset" => $offset, "Limit" => $limit );
523 else
524 $limitArray = array();
525
526 $db->array_query( $imageArray, "SELECT Image.ID, Link.ImageID
527 FROM eZImageCatalogue_Image AS Image
528 LEFT JOIN eZImageCatalogue_ImageCategoryLink AS Link
529 ON Image.ID=Link.ImageID
530 WHERE ImageID IS NULL", $limitArray );
531
532 foreach ( $imageArray as $image )
533 {
534 $returnArray[] = new eZImage( $image[$db->fieldName( "ID" )] );
535 }
536
537 return $returnArray;
538 }
539
543 static public function countUnassigned()
544 {
545 $db =& eZDB::globalDatabase();
546
547 $db->query_single( $image, "SELECT COUNT(Image.ID) as Count, Link.ImageID
548 FROM eZImageCatalogue_Image AS Image
549 LEFT JOIN eZImageCatalogue_ImageCategoryLink AS Link
550 ON Image.ID=Link.ImageID
551 WHERE ImageID IS NULL
552 GROUP By ImageID" );
553
554 return $image[$db->fieldName( "Count" )];
555 }
556
566 function checkReadPermission( &$currentUser )
567 {
568 $ret = false;
569
570 $read = $this->readPermission();
571
572 if ( is_a( $currentUser, "eZUser" ) )
573 {
574 if ( $read == "User" )
575 {
576 if ( $this->UserID != 0 )
577 {
578 if ( $currentUser->id() == $this->UserID )
579 {
580 $ret = "User";
581 }
582 else
583 {
584 return $ret;
585 }
586 }
587 }
588 else if ( $read == "Group" )
589 {
590 if ( $this->UserID != 0 )
591 {
592 $currentGroups =& $currentUser->groups();
593 foreach ( $currentGroups as $Groups )
594 {
595 $user = new eZUser( $this->UserID );
596 $userGroups =& $user->groups();
597
598 foreach ( $userGroups as $userGroup )
599 {
600 if ( $Groups->id() == $userGroup->id() )
601 {
602 $ret = "Group";
603 }
604 else
605 {
606 return $ret;
607 }
608 }
609 }
610 }
611 }
612 else if ( $read == "All" )
613 {
614 $ret = "Group";
615 }
616 }
617 else
618 {
619 if ( $read == "All" )
620 {
621 $ret = "All";
622 }
623 }
624
625 return $ret;
626
627 }
628
638 function checkWritePermission( &$currentUser )
639 {
640 $ret = false;
641
642 $write = $this->writePermission();
643
644 if ( is_a( $currentUser, "eZUser" ) )
645 {
646
647 if ( $write == "User" )
648 {
649 if ( $this->UserID != 0 )
650 {
651 if ( $currentUser->id() == $this->UserID )
652 {
653 $ret = "User";
654 }
655 else
656 {
657 return $ret;
658 }
659 }
660 }
661 else if ( $write == "Group" )
662 {
663 if ( $this->UserID != 0 )
664 {
665 $currentGroups =& $currentUser->groups();
666 foreach ( $currentGroups as $Groups )
667 {
668 $user = new eZUser( $this->UserID );
669 $userGroups =& $user->groups();
670
671 foreach ( $userGroups as $userGroup )
672 {
673 if ( $Groups->id() == $userGroup->id() )
674 {
675 $ret = "Group";
676 }
677 else
678 {
679 return $ret;
680 }
681 }
682 }
683 }
684 }
685 else if ( $write == "All" )
686 {
687 $ret = "Group";
688 }
689 }
690 else
691 {
692 if ( $write == "All" )
693 {
694 $ret = "All";
695 }
696 }
697
698 return $ret;
699 }
700
704 function id()
705 {
706 if ( isset( $this->ID ) )
707 return $this->ID;
708 else
709 return;
710 }
711
715 function &name( $html = true )
716 {
717 if ( $this->Name )
718 {
719 $this->Name = stripslashes($this->Name);
720 if ( $html )
721 return eZTextTool::fixhtmlentities( htmlspecialchars( $this->Name ) );
722 else
723 return $this->Name;
724 }
725 else
726 {
727 if ( $html && $this->OriginalFileName != null )
728 return eZTextTool::fixhtmlentities( htmlspecialchars( $this->OriginalFileName ) );
729 else
730 return $this->OriginalFileName;
731 }
732 }
733
737 function caption( $html = true )
738 {
739 if ( $html && $this->Caption != null)
740 {
741 $this->Caption = stripslashes($this->Caption);
742 return eZTextTool::fixhtmlentities( htmlspecialchars( $this->Caption ) );
743 }
744 else
745 return $this->Caption;
746 }
747
751 function description( $html = true )
752 {
753 $this->Description = stripslashes($this->Description);
754 if ( $html )
755 return eZTextTool::fixhtmlentities( htmlspecialchars( $this->Description ) );
756 else
757 return $this->Description;
758 }
759
763 function fileName()
764 {
765 return $this->FileName;
766 }
767
771 function originalFileName()
772 {
773 return $this->OriginalFileName;
774 }
775
776 function fileExists( $relative=false )
777 {
778 if ( $relative == true )
779 {
780 $path = "var/site/storage/ezimagecatalogue/" .$this->FileName;
781 }
782 else
783 {
784 $path = "/var/site/storage/ezimagecatalogue/" .$this->FileName;
785 }
786
787 $relPath = "var/site/storage/ezimagecatalogue/" . $this->FileName;
788
789 return file_exists( $relPath ) and is_file( $relPath );
790 }
797 function filePath( $relative = false )
798 {
799 $relPath = "var/site/storage/ezimagecatalogue/" . $this->FileName;
800
801 if ( $relative == true )
802 {
803 $path = "var/site/storage/ezimagecatalogue/" . $this->FileName;
804 }
805 else
806 {
807 $path = "/var/site/storage/ezimagecatalogue/" . $this->FileName;
808 }
809
810 if ( !file_exists( $relPath ) or !is_file( $relPath ) )
811 {
812 $path = "kernel/ezimagecatalogue/admin/images/failedimage.gif";
813 if ( !$relative )
814 $path = "/$path";
815 }
816 return $path;
817 }
818
819 /*
820 * Checks for a watermark version of the image, creates one if it doesn't exist, and returns the path.
821 */
822 function &watermarkPath( $relative = false )
823 {
824 $relPath = "ezimagecatalogue/catalogue/fullwatermarks/" . $this->FileName;
825
826 if ( $relative == true )
827 {
828 $path = "ezimagecatalogue/catalogue/fullwatermarks/" . $this->FileName;
829 }
830 else
831 {
832 $path = "/ezimagecatalogue/catalogue/fullwatermarks/" . $this->FileName;
833 }
834
835 if ( !file_exists( $relPath ) or !is_file( $relPath ) )
836 {
837 if (!$this->createWatermark()) {
838 $path = "ezimagecatalogue/admin/images/failedimage.gif";
839 if ( !$relative )
840 $path = "/$path";
841 }
842 }
843 return $path;
844 }
845
846 function &createWatermark() {
847 $ini =& eZINI::instance( 'site.ini' );
848 $sitePath = $ini->variable("site", "SitePath");
849 if ( $ini->hasVariable( "watermark", "watermarkImage" ) )
850 $watermark_image = $ini->variable( "watermark", "watermarkImage" );
851 if ( $ini->hasVariable( "watermark", "watermarkImageBr" ) )
852 $watermark_image_br = $ini->variable( "watermark", "watermarkImageBr" );
853 if ( $ini->hasVariable( "watermark", "watermarkImageBrSmall" ) )
854 $watermark_image_br_small = $ini->variable( "watermark", "watermarkImageBrSmall" );
855 $imagepath = $this->filePath( true);
856 $dest = 'ezimagecatalogue/catalogue/fullwatermarks/' . $this->FileName;
857 $actualsize = getimagesize($imagepath);
858 $actualheight = $actualsize[1];
859 $actualwidth = $actualsize[0];
860 if ($actualheight >= 400 | $actualwidth >= 400) {
861 $watermark_image_br = $watermark_image_br;
862 } else {
863 $watermark_image_br = $watermark_image_br_small;
864 }
865
866 // some lame error handling
867 if (!is_file($watermark_image_br)) {
868 // ezlog: new eZPBLog
869 eZPBLog::writeNotice( "User Site: Could not locate watermark image file." );
870 echo ('Could not locate watermark image file.');
871 print ('Could not locate watermark image file.');
872 }
873
874 $watermarkCodeBR = "/usr/bin/composite -gravity southeast $watermark_image_br $imagepath $dest";
875 if ($watermarkCodeBR != "") {
876
877 $err_water = system( $watermarkCodeBR, $ret_code_water );
878 if ( $ret_code_water == 0 )
879 {
880 @eZPBFile::chmod( $dest, 0644 );
881 $ret = true;
882 }
883 else
884 {
885 $ret = false;
886 }
887 }
888 return $ret;
889 }
890
894 function imagePath( $relative=false )
895 {
896 return $this->filePath( $relative );
897 }
898
909 function requestImageVariation( $width, $height, $convertToGray = false, $allow_error = false )
910 {
911 $group = new eZImageVariationGroup();
912 $variation = new eZImageVariation();
913
914 if ( $group->groupExists( $width, $height ) )
915 {
916 $group->get( $group->groupExists( $width, $height ) );
917
918 $ret = $variation->requestVariation( $this, $group, $convertToGray, $allow_error );
919 }
920 else
921 {
922 $group->setWidth( $width );
923 $group->setHeight( $height );
924 $group->store();
925
926
927 $ret = $variation->requestVariation( $this, $group, $convertToGray, $allow_error );
928 }
929
930 return $ret;
931 }
932
936 function writePermission()
937 {
938 switch( $this->WritePermission )
939 {
940 case 1:
941 {
942 $ret = "User";
943 }
944 break;
945
946 case 2:
947 {
948 $ret = "Group";
949 }
950 break;
951
952 case 3:
953 {
954 $ret = "All";
955 }
956 break;
957
958 default:
959 $ret = "User";
960 }
961
962 return $ret;
963 }
964
968 function readPermission()
969 {
970 switch( $this->ReadPermission )
971 {
972 case 1:
973 {
974 $ret = "User";
975 }
976 break;
977
978 case 2:
979 {
980 $ret = "Group";
981 }
982 break;
983
984 case 3:
985 {
986 $ret = "All";
987 }
988 break;
989
990 default:
991 $ret = "User";
992 }
993
994 return $ret;
995 }
996
1000 function user()
1001 {
1002 if ( $this->UserID != 0 )
1003 {
1004 $ret = new eZUser( $this->UserID );
1005 }
1006
1007 return $ret;
1008 }
1009
1010
1014 function setName( $value )
1015 {
1016 $this->Name = $value;
1017 }
1018
1022 function setCaption( $value )
1023 {
1024 $this->Caption = $value;
1025 }
1026
1030 function setDescription( $value )
1031 {
1032 $this->Description = $value;
1033 }
1034
1038 function setOriginalFileName( $value )
1039 {
1040 $this->OriginalFileName = $value;
1041 }
1042
1046 function checkImage( &$file )
1047 {
1048 if ( is_a( $file, "eZPBImageFile" ) )
1049 {
1050 $name = $file->tmpName();
1051 if ( !file_exists( $name ) or !is_file( $name ) )
1052 return false;
1053 return true;
1054 }
1055 return false;
1056 }
1057
1063 function setImage( &$file )
1064 {
1065 if ( is_a( $file, "eZPBImageFile" ) )
1066 {
1067 $this->OriginalFileName = $file->name();
1068 $tmpname = $file->tmpName();
1069 if ( !file_exists( $tmpname ) or !is_file( $tmpname ) )
1070 return false;
1071
1072 $info = eZPBImageFile::information( $this->OriginalFileName );
1073 $suffix = $info["suffix"];
1074 $postfix = $info["dot-suffix"];
1075
1076 if ( $postfix != "" )
1077 {
1078 // Copy the file since we support it directly
1079 if ( array_pop(explode('.', $file->tmpName() )) == $suffix ) {
1080 $fname = basename($file->tmpName(), '.'.$suffix);
1081 $tmpname = $fname . $uniqueID . '.' . $suffix;
1082 $postfix = "";
1083 }
1084 $file->copy( "var/site/storage/ezimagecatalogue/" . basename( $tmpname ) . $postfix );
1085 }
1086 else
1087 {
1088 // Convert it to jpg.
1089 // if ( !$file->convertCopy( "var/site/storage/ezimagecatalogue/" . basename( $file->tmpName() ) . ".jpg" ) )
1090 if ( !$file->convertCopy( "var/site/storage/ezimagecatalogue/" . basename( $file->tmpName() ) ) )
1091 return false;
1092 $postfix = ".jpg";
1093 }
1094 // $this->FileName = basename( $file->tmpName() ) . $postfix;
1095 $this->FileName = basename( $tmpname ) . $postfix;
1096
1097 $name = $file->name();
1098
1099 $this->OriginalFileName =& $name;
1100 $this->NewImage = true;
1101
1102 return true;
1103 }
1104 return false;
1105 }
1106
1115 function setWritePermission( $value )
1116 {
1117 switch ( $value )
1118 {
1119 case "User":
1120 {
1121 $value = 1;
1122 }
1123 break;
1124
1125 case "Group":
1126 {
1127 $value = 2;
1128 }
1129 break;
1130
1131 case "All":
1132 {
1133 $value = 3;
1134 }
1135 break;
1136
1137 default:
1138 $value = 1;
1139 }
1140
1141 $this->WritePermission = $value;
1142 }
1143
1152 function setReadPermission( $value )
1153 {
1154 switch ( $value )
1155 {
1156 case "User":
1157 {
1158 $value = 1;
1159 }
1160 break;
1161
1162 case "Group":
1163 {
1164 $value = 2;
1165 }
1166 break;
1167
1168 case "All":
1169 {
1170 $value = 3;
1171 }
1172 break;
1173
1174 default:
1175 $value = 1;
1176 }
1177
1178 $this->ReadPermission = $value;
1179 }
1180
1184 function setUser( $user )
1185 {
1186 if ( is_a( $user, "eZUser" ) )
1187 {
1188 $userID = $user->id();
1189
1190 $this->UserID = $userID;
1191 }
1192 }
1193
1197 function width()
1198 {
1199 if ( file_exists( $this->filePath( true ) ) and is_file( $this->filePath( true ) ) )
1200 {
1201 $size = getimagesize( $this->filePath( true ) );
1202 return $size[0];
1203 }
1204 else
1205 return 120;
1206 }
1207
1211 function height()
1212 {
1213 if ( file_exists( $this->filePath( true ) ) and is_file( $this->filePath( true ) ) )
1214 {
1215 $size = getimagesize( $this->filePath( true ) );
1216 return $size[1];
1217 }
1218 else
1219 return 40;
1220 }
1221
1225 function variations()
1226 {
1227 $db =& eZDB::globalDatabase();
1228
1229 $returnArray = array();
1230
1231 $db->array_query( $variationArray, "SELECT ID, Width, Height
1232 FROM eZImageCatalogue_ImageVariation
1233 WHERE ImageID='$this->ID' ORDER BY Width, Height" );
1234
1235 foreach ( $variationArray as $variation )
1236 {
1237 $returnArray[] = new eZImageVariation( $variation[$db->fieldName("ID")] );
1238 }
1239
1240 return $returnArray;
1241 }
1242
1246 function categories()
1247 {
1248 $db =& eZDB::globalDatabase();
1249
1250 $res = array();
1251 $db->array_query( $res, "SELECT CategoryID, ImageID FROM
1252 eZImageCatalogue_ImageCategoryLink
1253 WHERE ImageID='$this->ID'" );
1254 $category = false;
1255
1256 if ( count( $res ) > 0 )
1257 $category = array();
1258
1259 for ( $i = 0; $i < count( $res ); $i++ )
1260 {
1261 array_push( $category, $res[$i][$db->fieldName("CategoryID")] );
1262 }
1263
1264 return $category;
1265 }
1266
1267
1274 static public function isOwner( $user, $image )
1275 {
1276 if ( !is_a( $user, "eZUser" ) )
1277 return false;
1278
1279 $db =& eZDB::globalDatabase();
1280 $db->query_single( $res, "SELECT UserID from eZImageCatalogue_Image WHERE ID='$image'");
1281 $userID = $res[$db->fieldName("UserID")];
1282 if( $userID == $user->id() )
1283 return true;
1284
1285 return false;
1286 }
1287
1291 function setPhotographer( $author )
1292 {
1293 if ( is_a( $author, "eZAuthor" ) )
1294 $this->PhotographerID = $author->id();
1295 else if ( is_numeric( $author ) )
1296 $this->PhotographerID = $author;
1297 }
1298
1302 function photographer( $as_object = true )
1303 {
1304 return $as_object ? new eZAuthor( $this->PhotographerID ) : $this->PhotographerID;
1305 }
1306
1310 function setKeywords( $keywords )
1311 {
1312 if( $keywords != "" )
1313 {
1314 $this->Keywords = $keywords;
1315 }
1316 }
1317
1321 function keywords()
1322 {
1323 return $this->Keywords;
1324 }
1325
1329 function articles()
1330 {
1331 $db =& eZDB::globalDatabase();
1332
1333 $res = array();
1334 $db->array_query( $res, "SELECT ArticleID FROM
1335 eZArticle_ArticleImageLink
1336 WHERE ImageID='$this->ID'" );
1337 $articles = array();
1338
1339 for ( $i = 0; $i < count( $res ); $i++ )
1340 {
1341 $articles[] = new eZArticle( $res[$i][$db->fieldName("ArticleID")] );
1342 }
1343
1344 return $articles;
1345 }
1346
1350 function products()
1351 {
1352 $db =& eZDB::globalDatabase();
1353
1354 $res = array();
1355 $db->array_query( $res, "SELECT ProductID FROM
1356 eZTrade_ProductImageLink
1357 WHERE ImageID='$this->ID'" );
1358 $articles = array();
1359
1360 for ( $i = 0; $i < count( $res ); $i++ )
1361 {
1362 $articles[] = new eZProduct( $res[$i][$db->fieldName("ProductID")] );
1363 }
1364
1365 return $articles;
1366 }
1367
1371 public static function randomImage( $categoryID=0 )
1372 {
1373 $db =& eZDB::globalDatabase();
1374 $res = array();
1375
1376 if( $db->isA() == "mysql" )
1377 {
1378 if ( is_numeric ( $categoryID ) )
1379 $db->query_single( $res, "SELECT ImageID as ID, ((ImageID*0)+RAND()) AS Random FROM eZImageCatalogue_ImageCategoryLink WHERE CategoryID='$categoryID' ORDER BY Random LIMIT 1" );
1380 else
1381 $db->query_single( $res, "SELECT ID, ((ID*0)+RAND()) AS Random FROM eZImageCatalogue_Image ORDER BY Random LIMIT 1" );
1382
1383 if( is_array( $res ) )
1384 return new eZImage( $res["ID"] );
1385 }
1386 elseif( $db->isA() == "sqlite" )
1387 {
1388 if ( is_numeric( $categoryID ) )
1389 $db->query_single(
1390 $res,
1391 "SELECT ImageID as ID
1392 FROM eZImageCatalogue_ImageCategoryLink
1393 WHERE CategoryID='$categoryID'
1394 ORDER BY RANDOM()
1395 LIMIT 1"
1396 );
1397 else
1398 $db->query_single(
1399 $res,
1400 "SELECT ID
1401 FROM eZImageCatalogue_Image
1402 ORDER BY RANDOM()
1403 LIMIT 1"
1404 );
1405
1406 if( is_array( $res ) )
1407 return new eZImage( $res["ID"] );
1408 }
1409
1410 return new eZImage();
1411 }
1412
1416 function hasMap()
1417 {
1418 $db =& eZDB::globalDatabase();
1419
1420 $res = array();
1421 $db->array_query( $res, "SELECT * FROM eZImageCatalogue_ImageMap WHERE ImageID='$this->ID'" );
1422
1423 if ( count( $res ) > 0 )
1424 return true;
1425 else
1426 return false;
1427 }
1428
1432 function forum( $as_object = true )
1433 {
1434 $db =& eZDB::globalDatabase();
1435
1436 $db->array_query( $res, "SELECT ForumID FROM
1437 eZImageCatalogue_ImageForumLink
1438 WHERE ImageID='$this->ID'" );
1439 $forum = false;
1440 if ( count( $res ) == 1 )
1441 {
1442 if ( $as_object )
1443 $forum = new eZForum( $res[0][$db->fieldName( "ForumID" )] );
1444 else
1445 $forum = $res[0][$db->fieldName( "ForumID" )];
1446 }
1447 else
1448 {
1449 $forum = new eZForum();
1450 $forum->setName( $db->escapeString( $this->Name ) );
1451
1452 $forum->setIsModerated(false);
1453 // $moderatorgroup = new eZUserGroup( 1 ); //should be a variable - administrator groupid
1454 // $forum->setModerator( $moderatorgroup );
1455
1456 $forum->store();
1457
1458 $ini =& eZINI::instance( 'site.ini' );
1459 $linkModules = $ini->variable( "eZForumMain", "LinkModules" );
1460 $module_array = explode(',', $linkModules );
1461 unset ($linkModules);
1462 foreach ( $module_array as $module)
1463 {
1464 $moduleSubArray = explode( ':', $module );
1465 list($module_name, $forum_id) = $moduleSubArray;
1466 $linkModules[$module_name] = $forum_id;
1467 }
1468
1469 $category = new eZForumCategory( $linkModules['eZImageCatalogue'] );
1470
1471 $category->addForum( $forum );
1472
1473 $forumID = $forum->id();
1474
1475 $db->begin( );
1476
1477 $db->lock( "eZImageCatalogue_ImageForumLink" );
1478
1479 $nextID = $db->nextID( "eZImageCatalogue_ImageForumLink", "ID" );
1480
1481 $res = $db->query( "INSERT INTO eZImageCatalogue_ImageForumLink
1482 ( ID, ImageID, ForumID )
1483 VALUES
1484 ( '$nextID', '$this->ID', '$forumID' )" );
1485
1486 $db->unlock();
1487
1488 if ( $res == false )
1489 $db->rollback( );
1490 else
1491 $db->commit();
1492
1493
1494 if ( $as_object )
1495 $forum = new eZForum( $forumID );
1496 else
1497 $forum = $forumID;
1498 }
1499 return $forum;
1500 }
1501
1505 function imageIDFromForum( $ForumID )
1506 {
1507 $db =& eZDB::globalDatabase();
1508
1509 $ImageID = 0;
1510
1511 $db->array_query( $result, "SELECT ImageID FROM
1512 eZImageCatalogue_ImageForumLink
1513 WHERE ForumID='$ForumID' GROUP BY ImageID" );
1514
1515 if( count( $result ) > 0 )
1516 {
1517 $ProductID = $result[0][$db->fieldName("ImageID")];
1518 }
1519
1520 return $ImageID;
1521 }
1522 var $ID;
1523 var $Name;
1524 var $Caption;
1525 var $Description;
1526 var $FileName;
1527 var $OriginalFileName;
1528 var $ReadPermission;
1529 var $WritePermission;
1530 var $UserID;
1531 var $PhotographerID;
1532 var $NewImage;
1533 var $Keywords;
1534 }
1535
1536 ?>
$category
if( $Action=="Edit") $category
Definition: adedit.php:378
$i
$i
Definition: admin/adlist.php:91
$group
$group
Definition: admin/articleedit.php:799
$author
$author
Definition: admin/articleedit.php:834
$forum
$forum
Definition: admin/forumlist.php:50
$userID
else $userID
Definition: appointmentedit.php:121
$articles
$articles
Definition: authorview.php:64
eZArticle
Definition: ezarticle.php:82
eZAuthor
Definition: ezauthor.php:40
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZDateTime
Definition: ezdatetime.php:55
eZForumCategory
Definition: ezforumcategory.php:44
eZForum
Definition: ezforum.php:44
eZImageCategory
Definition: ezimagecategory.php:43
eZImageVariationGroup
Definition: ezimagevariationgroup.php:38
eZImageVariation
Definition: ezimagevariation.php:41
eZImage
Definition: ezimage.php:95
eZImage\setDescription
setDescription( $value)
Definition: ezimage.php:1030
eZImage\checkWritePermission
checkWritePermission(&$currentUser)
Definition: ezimage.php:638
eZImage\hasMap
hasMap()
Definition: ezimage.php:1416
eZImage\fileName
fileName()
Definition: ezimage.php:763
eZImage\$Name
$Name
Definition: ezimage.php:1523
eZImage\countUnassigned
static countUnassigned()
Definition: ezimage.php:543
eZImage\setName
setName( $value)
Definition: ezimage.php:1014
eZImage\forum
forum( $as_object=true)
Definition: ezimage.php:1432
eZImage\setPhotographer
setPhotographer( $author)
Definition: ezimage.php:1291
eZImage\caption
caption( $html=true)
Definition: ezimage.php:737
eZImage\imageIDFromForum
imageIDFromForum( $ForumID)
Definition: ezimage.php:1505
eZImage\createWatermark
& createWatermark()
Definition: ezimage.php:846
eZImage\products
products()
Definition: ezimage.php:1350
eZImage\setImage
setImage(&$file)
Definition: ezimage.php:1063
eZImage\getUnassigned
static getUnassigned( $offset=-1, $limit=-1)
Definition: ezimage.php:515
eZImage\height
height()
Definition: ezimage.php:1211
eZImage\name
& name( $html=true)
Definition: ezimage.php:715
eZImage\categories
categories()
Definition: ezimage.php:1246
eZImage\watermarkPath
& watermarkPath( $relative=false)
Definition: ezimage.php:822
eZImage\$OriginalFileName
$OriginalFileName
Definition: ezimage.php:1527
eZImage\setKeywords
setKeywords( $keywords)
Definition: ezimage.php:1310
eZImage\photographer
photographer( $as_object=true)
Definition: ezimage.php:1302
eZImage\readPermission
readPermission()
Definition: ezimage.php:968
eZImage\randomImage
static randomImage( $categoryID=0)
Definition: ezimage.php:1371
eZImage\originalFileName
originalFileName()
Definition: ezimage.php:771
eZImage\setWritePermission
setWritePermission( $value)
Definition: ezimage.php:1115
eZImage\imagePath
imagePath( $relative=false)
Definition: ezimage.php:894
eZImage\requestImageVariation
requestImageVariation( $width, $height, $convertToGray=false, $allow_error=false)
Definition: ezimage.php:909
eZImage\articles
articles()
Definition: ezimage.php:1329
eZImage\width
width()
Definition: ezimage.php:1197
eZImage\store
store()
Definition: ezimage.php:116
eZImage\isOwner
static isOwner( $user, $image)
Definition: ezimage.php:1274
eZImage\setCategoryDefinition
setCategoryDefinition( $value)
Definition: ezimage.php:437
eZImage\$Description
$Description
Definition: ezimage.php:1525
eZImage\searchCount
static searchCount( $name, $literal=false)
Definition: ezimage.php:269
eZImage\description
description( $html=true)
Definition: ezimage.php:751
eZImage\$NewImage
$NewImage
Definition: ezimage.php:1532
eZImage\writePermission
writePermission()
Definition: ezimage.php:936
eZImage\getAll
& getAll()
Definition: ezimage.php:497
eZImage\$UserID
$UserID
Definition: ezimage.php:1530
eZImage\id
id()
Definition: ezimage.php:704
eZImage\user
user()
Definition: ezimage.php:1000
eZImage\$ReadPermission
$ReadPermission
Definition: ezimage.php:1528
eZImage\__construct
__construct( $id="")
Definition: ezimage.php:99
eZImage\$PhotographerID
$PhotographerID
Definition: ezimage.php:1531
eZImage\setUser
setUser( $user)
Definition: ezimage.php:1184
eZImage\search
static search(&$queryText, $offset=0, $limit=30, $userID=-1)
Definition: ezimage.php:221
eZImage\setReadPermission
setReadPermission( $value)
Definition: ezimage.php:1152
eZImage\$Caption
$Caption
Definition: ezimage.php:1524
eZImage\setCaption
setCaption( $value)
Definition: ezimage.php:1022
eZImage\$Keywords
$Keywords
Definition: ezimage.php:1533
eZImage\$WritePermission
$WritePermission
Definition: ezimage.php:1529
eZImage\setOriginalFileName
setOriginalFileName( $value)
Definition: ezimage.php:1038
eZImage\checkReadPermission
checkReadPermission(&$currentUser)
Definition: ezimage.php:566
eZImage\fileExists
fileExists( $relative=false)
Definition: ezimage.php:776
eZImage\checkImage
checkImage(&$file)
Definition: ezimage.php:1046
eZImage\$FileName
$FileName
Definition: ezimage.php:1526
eZImage\$ID
$ID
Definition: ezimage.php:1522
eZImage\variations
variations()
Definition: ezimage.php:1225
eZImage\filePath
filePath( $relative=false)
Definition: ezimage.php:797
eZImage\keywords
keywords()
Definition: ezimage.php:1321
eZImage\getByOriginalFileName
static getByOriginalFileName( $id="")
Definition: ezimage.php:391
eZImage\existsInCategory
existsInCategory( $category)
Definition: ezimage.php:414
eZImage\categoryDefinition
categoryDefinition()
Definition: ezimage.php:471
eZPBFile\chmod
static chmod( $filename, $mode)
Definition: ezpbfile.php:371
eZPBFile\unlink
static unlink( $filename)
Definition: ezpbfile.php:352
eZPBImageFile\information
static & information( $file, $use_default=false)
Definition: ezpbimagefile.php:108
eZPBLog\writeNotice
static writeNotice( $notice)
Definition: ezpblog.php:166
eZProduct
Definition: ezproduct.php:71
eZQuery
Definition: ezquery.php:54
eZTextTool\fixhtmlentities
static fixhtmlentities( $string)
Definition: eztexttool.php:156
eZUser
Definition: ezuser.php:76
eZUser\currentUser
static & currentUser()
Definition: ezuser.php:896
$ini
$ini
Definition: classes/admin/linklist.php:64
$module
$module
Definition: classes/admin/linkselect.php:219
$result
$result
Definition: companysearch.php:94
$name
$name
Definition: companytypelist.php:194
$ImageID
$ImageID
Definition: companytypelist.php:201
$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
$file
$file
Definition: ezfilemanager/user/filedownload.php:35
$limit
$limit
Definition: ezimagecatalogue/admin/imagelist.php:312
$variation
$variation
Definition: ezimagecatalogue/user/menubox.php:55
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$res
$res
Definition: ezstats/admin/cron.php:45
$offset
$offset
Definition: ezstats/admin/cron.php:51
$categoryID
else $categoryID
Definition: productview.php:66
Name
if($user) if(isset( $next) && $next)<?=isset($all_fields_error) &&$all_fields_error ?><?=isset($password_error) &&$password_error ?></p ><? endif;?>< form method="post">< table border="0" cellspacing="2" cellpadding="2" class="boxtext" style="font-size=13;">< tr >< td style="color:<?= isset( $error['first_name'] ) ?> First Name
Definition: step1.php:127
$currentUser
$currentUser
Definition: surveyedit.php:54
$category_array
$category_array
Definition: todoedit.php:604
$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+.