Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezmedia.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezmedia.php 9311 2002-02-28 09:55:43Z ce $
5 //
6 // Definition of eZMedia 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 //
30
59 // include_once( "classes/ezdb.php" );
60 // include_once( "classes/ezdatetime.php" );
61
62 // include_once( "ezmediacatalogue/classes/ezmediatype.php" );
63
64 class eZMedia
65 {
69 function __construct( $id="" )
70 {
71 $this->PhotographerID = 0;
72 $this->NewMedia = false;
73 if ( $id != "" )
74 {
75 $this->ID = $id;
76 $this->get( $this->ID );
77 }
78 }
79
83 function store()
84 {
85 $db =& eZDB::globalDatabase();
86
87 $db->begin( );
88
89 $name = $db->escapeString( $this->Name );
90 $description = $db->escapeString( $this->Description );
91 $caption = $db->escapeString( $this->Caption );
92 $filename = $db->escapeString( $this->FileName );
93 $originalfilename = $db->fieldName( $this->OriginalFileName );
94
95 if ( $this->ID == "" )
96 {
97 $db->lock( "eZMediaCatalogue_Media" );
98
99 $timeStamp = (new eZDateTime())->timeStamp( true );
100
101 $this->ID = $db->nextID( "eZMediaCatalogue_Media", "ID" );
102 $res = $db->query( "INSERT INTO eZMediaCatalogue_Media
103 ( ID,
104 Name,
105 Caption,
106 Description,
107 FileName,
108 UserID,
109 WritePermission,
110 ReadPermission,
111 OriginalFileName,
112 PhotographerID,
113 Created )
114 VALUES ( '$this->ID',
115 '$name',
116 '$caption',
117 '$description',
118 '$filename',
119 '$this->UserID',
120 '$this->WritePermission',
121 '$this->ReadPermission',
122 '$originalfilename',
123 '$this->PhotographerID',
124 '$timeStamp' )");
125 $db->unlock();
126 }
127 else
128 {
129 $res = $db->query( "UPDATE eZMediaCatalogue_Media SET
130 Name='$name',
131 Caption='$caption',
132 Description='$description',
133 FileName='$filename',
134 UserID='$this->UserID',
135 WritePermission='$this->WritePermission',
136 ReadPermission='$this->ReadPermission',
137 OriginalFileName='$originalfilename',
138 PhotographerID='$this->PhotographerID'
139 WHERE ID='$this->ID'
140 " );
141 }
142
143 if ( $res == false )
144 $db->rollback( );
145 else
146 $db->commit();
147 }
148
152 function delete( $id=false )
153 {
154 $db =& eZDB::globalDatabase();
155
156 if ( $id == false )
157 {
158 $id = $this->ID;
159 }
160
161 if ( isset( $id ) )
162 {
163 $db->query( "DELETE FROM eZMediaCatalogue_Media WHERE ID='$this->ID'" );
164 $db->query( "DELETE FROM eZMediaCatalogue_MediaPermission WHERE ObjectID='$this->ID'" );
165 $db->query( "DELETE FROM eZMediaCatalogue_MediaCategoryLink WHERE MediaID='$this->ID'" );
166 $db->query( "DELETE FROM eZMediaCatalogue_MediaCategoryDefinition WHERE MediaID='$this->ID'" );
167 $db->query( "DELETE FROM eZMediaCatalogue_TypeLink WHERE MediaID='$this->ID'" );
168
169 // Delete from the filesystem
170 if ( file_exists( $this->filePath( true ) ) )
171 {
172 eZPBFile::unlink( $this->filePath( true ) );
173 }
174 }
175 }
176
180 function get( $id="" )
181 {
182 $db =& eZDB::globalDatabase();
183
184 $ret = false;
185 if ( $id != "" )
186 {
187 $db->array_query( $media_array, "SELECT * FROM eZMediaCatalogue_Media WHERE ID='$id'" );
188 if( count( $media_array ) > 0 )
189 {
190 if ( count( $media_array ) > 1 )
191 {
192 print( "<br /><b>Error: Media's with the same ID was found in the database. This shouldent happen.</b><br />" );
193 }
194 $this->ID = $media_array[0][$db->fieldName("ID")];
195 $this->Name = $media_array[0][$db->fieldName("Name")];
196 $this->Caption = $media_array[0][$db->fieldName("Caption")];
197 $this->Description = $media_array[0][$db->fieldName("Description")];
198 $this->FileName = $media_array[0][$db->fieldName("FileName")];
199 $this->OriginalFileName = $media_array[0][$db->fieldName("OriginalFileName")];
200 $this->UserID = $media_array[0][$db->fieldName("UserID")];
201 $this->WritePermission = $media_array[0][$db->fieldName("WritePermission")];
202 $this->ReadPermission = $media_array[0][$db->fieldName("ReadPermission")];
203 $this->PhotographerID = $media_array[0][$db->fieldName("PhotographerID")];
204
205 $ret = true;
206 }
207 }
208
209 return $ret;
210 }
211
216 static public function getByOriginalFileName( $id = "" )
217 {
218 $db =& eZDB::globalDatabase();
219 $ret = new eZMedia();
220 if ( $id != "" )
221 {
222 $db->array_query( $media_array, "SELECT * FROM eZMediaCatalogue_Media WHERE OriginalFileName='$id'" );
223 if( count( $media_array ) > 0 )
224 {
225 if ( count( $media_array ) > 1 )
226 {
227 print( "<br /><b>Error: Media's with the same was found in the database. This shouldn't happen.</b><br />" );
228 }
229 $ret = new eZMedia( $media_array[0][$db->fieldName("ID")] );
230 }
231 }
232 return $ret;
233 }
234
239 function existsInCategory( &$category )
240 {
241 $ret = false;
242 if ( is_a( $category, "eZMediaCategory" ) )
243 {
244 $db =& eZDB::globalDatabase();
245 $catID = $category->id();
246
247 $db->array_query( $ret_array, "SELECT ID FROM eZMediaCatalogue_MediaCategoryLink
248 WHERE MediaID='$this->ID' AND CategoryID='$catID'" );
249
250 if ( count( $ret_array ) == 1 )
251 {
252 $ret = true;
253 }
254 }
255 return $ret;
256 }
257
262 function setCategoryDefinition( &$value )
263 {
264 if ( is_a( $value, "eZMediaCategory" ) )
265 {
266 $db =& eZDB::globalDatabase();
267
268 $db->begin( );
269
270 $categoryID = $value->id();
271
272 $db->query( "DELETE FROM eZMediaCatalogue_MediaCategoryDefinition
273 WHERE MediaID='$this->ID'" );
274
275 $db->lock( "eZMediaCatalogue_MediaCategoryDefinition" );
276
277 $nextID = $db->nextID( "eZMediaCatalogue_MediaCategoryDefinition", "ID" );
278
279 $query = "INSERT INTO eZMediaCatalogue_MediaCategoryDefinition ( ID, CategoryID, MediaID )
280 VALUES ( '$nextID', '$categoryID', '$this->ID' )";
281
282 $res = $db->query( $query );
283
284 $db->unlock();
285
286 if ( $res == false )
287 $db->rollback( );
288 else
289 $db->commit();
290 }
291 }
292
296 function categoryDefinition( )
297 {
298 $db =& eZDB::globalDatabase();
299
300 $db->array_query( $res, "SELECT CategoryID FROM
301 eZMediaCatalogue_MediaCategoryDefinition
302 WHERE MediaID='$this->ID'" );
303
304 $category = false;
305 if ( count( $res ) == 1 )
306 {
307 $category = new eZMediaCategory( $res[0][$db->fieldName("CategoryID")] );
308 }
309 else
310 {
311 return -1;
312 }
313
314 return $category;
315 }
316
322 function getUnassigned()
323 {
324 $db =& eZDB::globalDatabase();
325
326 $db->array_query( $mediaArray, "SELECT Media.ID, Link.MediaID
327 FROM eZMediaCatalogue_Media AS Media
328 LEFT JOIN eZMediaCatalogue_MediaCategoryLink AS Link
329 ON Media.ID=Link.MediaID
330 WHERE MediaID IS NULL" );
331
332 foreach ( $mediaArray as $media )
333 {
334 $returnArray[] = new eZMedia( $media[$db->fieldName( "ID" )] );
335 }
336
337 return $returnArray;
338 }
339
343 function countUnassigned()
344 {
345 $db =& eZDB::globalDatabase();
346
347 $db->query_single( $media, "SELECT COUNT(Media.ID) as Count, Link.MediaID
348 FROM eZMediaCatalogue_Media AS Media
349 LEFT JOIN eZMediaCatalogue_MediaCategoryLink AS Link
350 ON Media.ID=Link.MediaID
351 WHERE MediaID IS NULL
352 GROUP By MediaID" );
353 return $media[$db->fieldName("Count")];
354 }
355
359 function id()
360 {
361 return $this->ID;
362 }
363
367 function name( $html = true )
368 {
369 if ( !is_null( $this->Name ) && $html )
370 return htmlspecialchars( $this->Name );
371 else
372 return $this->Name;
373 }
374
378 function caption( $html = true )
379 {
380 $this->Caption = stripslashes($this->Caption);
381
382 if ( $html && !is_null( $this->Caption ) )
383 return htmlspecialchars( $this->Caption );
384 else
385 return $this->Caption;
386 }
387
391 function description( $html = true )
392 {
393 $this->Description = stripslashes($this->Description);
394
395 if ( !is_null( $this->Description ) && $html )
396 return htmlspecialchars( $this->Description );
397 else
398 return $this->Description;
399 }
400
404 function fileName()
405 {
406 return $this->FileName;
407 }
408
412 function originalFileName()
413 {
414 return $this->OriginalFileName;
415 }
416
417 function fileExists( $relative=false )
418 {
419 if ( $relative == true )
420 {
421 $path = "ezmediacatalogue/catalogue/" . $this->FileName;
422 }
423 else
424 {
425 $path = "/ezmediacatalogue/catalogue/" . $this->FileName;
426 }
427
428 $relPath = "ezmediacatalogue/catalogue/" . $this->FileName;
429
430 return file_exists( $relPath ) and is_file( $relPath );
431 }
432
439 function filePath( $relative=false )
440 {
441 $path = "var/site/storage/ezmediacatalogue/" . $this->FileName;
442
443 if ( !$relative )
444 {
445 $path = '/' . $path;
446 }
447
448 if ( !file_exists( $path ) or !eZPBFile::is_file( $path ) )
449 {
450 $path = "kernel/ezmediacatalogue/admin/medias/failedmedia.gif";
451 if ( !$relative )
452 $path = '/' . $path;
453 }
454 return $path;
455 }
456
460 function mediaPath( $relative = false )
461 {
462 return $this->filePath( $relative );
463 }
464
468 function user()
469 {
470 if ( $this->UserID != 0 )
471 {
472 $ret = new eZUser( $this->UserID );
473 }
474
475 return $ret;
476 }
477
478
482 function setName( &$value )
483 {
484 $this->Name = $value;
485 }
486
490 function setCaption( &$value )
491 {
492 $this->Caption = $value;
493 }
494
498 function setDescription( &$value )
499 {
500 $this->Description = $value;
501 }
502
506 function setOriginalFileName( &$value )
507 {
508 $this->OriginalFileName = $value;
509 }
510
514 function checkMedia( &$file )
515 {
516 if ( is_a( $file, "eZMediaFile" ) )
517 {
518 $name = $file->tmpName();
519 return true;
520 }
521 return false;
522 }
523
529 function setMedia( &$file )
530 {
531 if ( is_a( $file, "eZMediaFile" ) )
532 {
533 $this->OriginalFileName = $file->name();
534 $tmpname = $file->tmpName();
535
536 $info = eZMediaFile::information( $this->OriginalFileName );
537 $suffix = $info["suffix"];
538 $postfix = $info["dot-suffix"];
539
540 if ( $postfix != "" )
541 {
542 // Copy the file since we support it directly
543 $file->copy( "ezmediacatalogue/catalogue/" . basename( $file->tmpName() ) . $postfix );
544 }
545 else
546 {
547 $postfix = "";
548 }
549
550 $this->FileName = basename( $file->tmpName() ) . $postfix;
551
552 $name = $file->name();
553
554 $this->OriginalFileName =& $name;
555
556 return true;
557 }
558 return false;
559 }
560
564 function setUser( &$user )
565 {
566 if ( is_a( $user, "eZUser" ) )
567 {
568 $userID = $user->id();
569
570 $this->UserID = $userID;
571 }
572 }
573
577 function categories()
578 {
579 $db =& eZDB::globalDatabase();
580
581 $res = array();
582 $db->array_query( $res, "SELECT CategoryID, MediaID FROM
583 eZMediaCatalogue_MediaCategoryLink
584 WHERE MediaID='$this->ID'" );
585 $category = false;
586
587 if ( count( $res ) > 0 )
588 $category = array();
589
590 for ( $i = 0; $i < count( $res ); $i++ )
591 {
592 array_push( $category, $res[$i][$db->fieldName("CategoryID")] );
593 }
594
595 return $category;
596 }
597
604 static public function isOwner( &$user, &$media )
605 {
606 if( !is_a( $user, "eZUser" ) )
607 return false;
608
609 $db =& eZDB::globalDatabase();
610 $db->query_single( $res, "SELECT UserID from eZMediaCatalogue_Media WHERE ID='$media'");
611 $userID = $res[$db->fieldName("UserID")];
612 if( $userID == $user->id() )
613 return true;
614
615 return false;
616 }
617
621 function setPhotographer( &$author )
622 {
623 if ( is_a( $author, "eZAuthor" ) )
624 $this->PhotographerID = $author->id();
625 else if ( is_numeric( $author ) )
626 $this->PhotographerID = $author;
627 }
628
632 function &photographer()
633 {
634 return new eZAuthor( $this->PhotographerID );
635 }
636
640 function setType( &$type )
641 {
642 if ( is_a( $type, "eZMediaType" ) )
643 {
644 $db =& eZDB::globalDatabase();
645
646 $db->begin();
647
648 $typeID = $type->id();
649
650 $res[] = $db->query( "DELETE FROM eZMediaCatalogue_AttributeValue
651 WHERE MediaID='$this->ID'" );
652 $res[] = $db->query( "DELETE FROM eZMediaCatalogue_TypeLink
653 WHERE MediaID='$this->ID'" );
654
655 $db->lock( "eZMediaCatalogue_TypeLink" );
656
657 $nextID = $db->nextID( "eZMediaCatalogue_TypeLink", "ID" );
658
659 $query = "INSERT INTO eZMediaCatalogue_TypeLink
660 (ID, TypeID, MediaID)
661 VALUES
662 ('$nextID',
663 '$typeID',
664 '$this->ID')";
665
666 $res[] = $db->query( $query );
667
668 $db->unlock();
669
670 if ( in_array( false, $res ) )
671 $db->rollback();
672 else
673 $db->commit();
674
675 }
676 }
677
681 function type()
682 {
683 $db =& eZDB::globalDatabase();
684
685 $db->array_query( $res, "SELECT TypeID FROM
686 eZMediaCatalogue_TypeLink WHERE MediaID='$this->ID'" );
687
688 $type = false;
689
690 if ( count( $res ) == 1 )
691 {
692 $type = new eZMediaType( $res[0][$db->fieldName("TypeID")] );
693 }
694
695 return $type;
696 }
697
701 function removeType()
702 {
703 $db =& eZDB::globalDatabase();
704
705 // delete values
706 $db->query( "DELETE FROM eZMediaCatalogue_AttributeValue WHERE MediaID='$this->ID'" );
707
708 $db->query( "DELETE FROM eZMediaCatalogue_TypeLink WHERE MediaID='$this->ID'" );
709
710 }
711
712 function attributeString( )
713 {
714 $type = $this->type();
715
716 if ( $type )
717 {
718 $attributes = $type->attributes();
719 $attString = '';
720
721 foreach( $attributes as $attribute )
722 {
723 $attString .= " " . $attribute->name() . "=\"" . $attribute->value( $this ) . "\"";
724 }
725 }
726 return $attString;
727 }
728
729
730 var $ID;
731 var $Name;
732 var $Caption;
733 var $Description;
734 var $FileName;
735 var $OriginalFileName;
736 var $ReadPermission;
737 var $WritePermission;
738 var $UserID;
739 var $PhotographerID;
740 var $NewMedia;
741 }
742
743 ?>
$category
if( $Action=="Edit") $category
Definition: adedit.php:378
$i
$i
Definition: admin/adlist.php:91
$author
$author
Definition: admin/articleedit.php:834
$userID
else $userID
Definition: appointmentedit.php:121
eZAuthor
Definition: ezauthor.php:40
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZDateTime
Definition: ezdatetime.php:55
eZMediaCategory
Definition: ezmediacategory.php:55
eZMediaFile\information
& information( $file, $use_default=false)
Definition: ezmediafile.php:105
eZMediaType
Definition: ezmediatype.php:33
eZMedia
Definition: ezmedia.php:65
eZMedia\fileName
fileName()
Definition: ezmedia.php:404
eZMedia\categoryDefinition
categoryDefinition()
Definition: ezmedia.php:296
eZMedia\name
name( $html=true)
Definition: ezmedia.php:367
eZMedia\$Caption
$Caption
Definition: ezmedia.php:732
eZMedia\id
id()
Definition: ezmedia.php:359
eZMedia\setUser
setUser(&$user)
Definition: ezmedia.php:564
eZMedia\setPhotographer
setPhotographer(&$author)
Definition: ezmedia.php:621
eZMedia\removeType
removeType()
Definition: ezmedia.php:701
eZMedia\$UserID
$UserID
Definition: ezmedia.php:738
eZMedia\user
user()
Definition: ezmedia.php:468
eZMedia\checkMedia
checkMedia(&$file)
Definition: ezmedia.php:514
eZMedia\$OriginalFileName
$OriginalFileName
Definition: ezmedia.php:735
eZMedia\filePath
filePath( $relative=false)
Definition: ezmedia.php:439
eZMedia\photographer
& photographer()
Definition: ezmedia.php:632
eZMedia\setName
setName(&$value)
Definition: ezmedia.php:482
eZMedia\__construct
__construct( $id="")
Definition: ezmedia.php:69
eZMedia\$ReadPermission
$ReadPermission
Definition: ezmedia.php:736
eZMedia\description
description( $html=true)
Definition: ezmedia.php:391
eZMedia\$ID
$ID
Definition: ezmedia.php:730
eZMedia\$NewMedia
$NewMedia
Definition: ezmedia.php:740
eZMedia\$FileName
$FileName
Definition: ezmedia.php:734
eZMedia\$PhotographerID
$PhotographerID
Definition: ezmedia.php:739
eZMedia\setCategoryDefinition
setCategoryDefinition(&$value)
Definition: ezmedia.php:262
eZMedia\originalFileName
originalFileName()
Definition: ezmedia.php:412
eZMedia\isOwner
static isOwner(&$user, &$media)
Definition: ezmedia.php:604
eZMedia\existsInCategory
existsInCategory(&$category)
Definition: ezmedia.php:239
eZMedia\getByOriginalFileName
static getByOriginalFileName( $id="")
Definition: ezmedia.php:216
eZMedia\$Name
$Name
Definition: ezmedia.php:731
eZMedia\setMedia
setMedia(&$file)
Definition: ezmedia.php:529
eZMedia\getUnassigned
getUnassigned()
Definition: ezmedia.php:322
eZMedia\store
store()
Definition: ezmedia.php:83
eZMedia\$Description
$Description
Definition: ezmedia.php:733
eZMedia\fileExists
fileExists( $relative=false)
Definition: ezmedia.php:417
eZMedia\categories
categories()
Definition: ezmedia.php:577
eZMedia\countUnassigned
countUnassigned()
Definition: ezmedia.php:343
eZMedia\mediaPath
mediaPath( $relative=false)
Definition: ezmedia.php:460
eZMedia\attributeString
attributeString()
Definition: ezmedia.php:712
eZMedia\$WritePermission
$WritePermission
Definition: ezmedia.php:737
eZMedia\setOriginalFileName
setOriginalFileName(&$value)
Definition: ezmedia.php:506
eZMedia\caption
caption( $html=true)
Definition: ezmedia.php:378
eZMedia\type
type()
Definition: ezmedia.php:681
eZMedia\setDescription
setDescription(&$value)
Definition: ezmedia.php:498
eZMedia\setCaption
setCaption(&$value)
Definition: ezmedia.php:490
eZMedia\setType
setType(&$type)
Definition: ezmedia.php:640
eZPBFile\unlink
static unlink( $filename)
Definition: ezpbfile.php:352
eZPBFile\is_file
static is_file( $filename)
Definition: ezpbfile.php:287
eZUser
Definition: ezuser.php:76
$type
$type
Definition: classes/admin/linkselect.php:220
$name
$name
Definition: companytypelist.php:194
$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
$media
if(isset( $AddMedia)) $media
Definition: ezarticle/admin/medialist.php:76
$db
$db
Definition: ezarticle/user/authorlist.php:53
$suffix
$suffix
Definition: ezfilemanager/user/filedownload.php:168
$file
$file
Definition: ezfilemanager/user/filedownload.php:35
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$res
$res
Definition: ezstats/admin/cron.php:45
$attString
$attString
Definition: mediaview.php:62
$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
$user
$user
Definition: user/adlist.php:39
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.