Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezimagefile.php
Go to the documentation of this file.
1 <?php
18 class eZImageFile extends eZPersistentObject
19 {
20 static function definition()
21 {
22 static $definition = array( 'fields' => array( 'id' => array( 'name' => 'id',
23 'datatype' => 'integer',
24 'default' => 0,
25 'required' => true ),
26 'contentobject_attribute_id' => array( 'name' => 'ContentObjectAttributeID',
27 'datatype' => 'integer',
28 'default' => 0,
29 'required' => true,
30 'foreign_class' => 'eZContentObjectAttribute',
31 'foreign_attribute' => 'id',
32 'multiplicity' => '1..*' ),
33 'filepath' => array( 'name' => 'Filepath',
34 'datatype' => 'string',
35 'default' => '',
36 'required' => true ) ),
37 'keys' => array( 'id' ),
38 'class_name' => 'eZImageFile',
39 'name' => 'ezimagefile' );
40 return $definition;
41 }
42
43 static function create( $contentObjectAttributeID, $filepath )
44 {
45 $row = array( "contentobject_attribute_id" => $contentObjectAttributeID,
46 "filepath" => $filepath );
47 return new eZImageFile( $row );
48 }
49
50 static function fetchForContentObjectAttribute( $contentObjectAttributeID, $asObject = false )
51 {
52 $rows = eZPersistentObject::fetchObjectList( eZImageFile::definition(),
53 null,
54 array( "contentobject_attribute_id" => $contentObjectAttributeID ),
55 null,
56 null,
57 $asObject );
58 if ( !$asObject )
59 {
60 $files = array();
61 foreach ( $rows as $row )
62 {
63 $files[] = $row['filepath'];
64 }
65 return array_unique( $files );
66 }
67 else
68 return $rows;
69 }
70
80 static function fetchImageAttributesByFilepath( $filepath, $contentObjectAttributeID )
81 {
82 $db = eZDB::instance();
83 $contentObjectAttributeID = (int) $contentObjectAttributeID;
84
85 $cond = array( 'id' => $contentObjectAttributeID );
86 $fields = array( 'contentobject_id', 'contentclassattribute_id' );
87 $limit = array( 'offset' => 0, 'length' => 1 );
88 $rows = eZPersistentObject::fetchObjectList( eZContentObjectAttribute::definition(),
89 $fields,
90 $cond,
91 null,
92 $limit,
93 false );
94 if ( count( $rows ) != 1 )
95 return array();
96
97 $contentObjectID = (int)( $rows[0]['contentobject_id'] );
98 $contentClassAttributeID = (int)( $rows[0]['contentclassattribute_id'] );
99 // Transform ", &, < and > to entities since they are being transformed in entities by DOM
100 // See eZImageAliasHandler::initialize()
101 // Ref https://jira.ez.no/browse/EZP-20090
102 $filepath = $db->escapeString(
103 htmlspecialchars(
104 $filepath,
105 // Forcing default flags to be able to specify encoding. See http://php.net/htmlspecialchars
106 version_compare( PHP_VERSION, '5.4.0', '>=' ) ? ENT_COMPAT | ENT_HTML401 : ENT_COMPAT,
107 'UTF-8'
108 )
109 );
110 // Escape _ in like to avoid it to act as a wildcard !
111 $filepath = addcslashes( $filepath, "_" );
112 $query = "SELECT id, version, language_code
113 FROM ezcontentobject_attribute
114 WHERE contentobject_id = $contentObjectID AND
115 contentclassattribute_id = $contentClassAttributeID AND
116 data_text LIKE '%url=\"$filepath\"%'";
117 if ( $db->databaseName() == 'oracle' )
118 {
119 $query .= " ESCAPE '\'";
120 }
121 $rows = $db->arrayQuery( $query );
122 return $rows;
123 }
124
136 static function fetchByFilepath( $contentObjectAttributeID, $filepath, $asObject = true )
137 {
138 // Fetch by file path without $contentObjectAttributeID
139 if ( $contentObjectAttributeID === false )
140
141 return eZPersistentObject::fetchObject( eZImageFile::definition(),
142 null,
143 array( 'filepath' => $filepath ),
144 $asObject );
145
146 return eZPersistentObject::fetchObject( eZImageFile::definition(),
147 null,
148 array( 'contentobject_attribute_id' => $contentObjectAttributeID,
149 'filepath' => $filepath ),
150 $asObject );
151 }
152
160 static function fetchListByFilePath( $filePath )
161 {
162 return eZPersistentObject::fetchObjectList(
163 eZImageFile::definition(),
164 array( 'contentobject_attribute_id', 'filepath' ),
165 array( 'filepath' => $filePath ),
166 null,
167 null,
168 false
169 );
170 }
171
172 static function moveFilepath( $contentObjectAttributeID, $oldFilepath, $newFilepath )
173 {
174 $db = eZDB::instance();
175 $db->begin();
176
177 eZImageFile::removeFilepath( $contentObjectAttributeID, $oldFilepath );
178 $result = eZImageFile::appendFilepath( $contentObjectAttributeID, $newFilepath );
179
180 $db->commit();
181 return $result;
182 }
183
184 static function appendFilepath( $contentObjectAttributeID, $filepath, $ignoreUnique = false )
185 {
186 if ( empty( $filepath ) )
187 return false;
188
189 if ( !$ignoreUnique )
190 {
191 // Fetch ezimagefile objects having the $filepath
192 $imageFiles = eZImageFile::fetchByFilepath( false, $filepath, false );
193 // Checking If the filePath already exists in ezimagefile table
194 if ( isset( $imageFiles[ 'contentobject_attribute_id' ] ) )
195 return false;
196 }
197 $fileObject = eZImageFile::fetchByFilepath( $contentObjectAttributeID, $filepath );
198 if ( $fileObject )
199 return false;
200 $fileObject = eZImageFile::create( $contentObjectAttributeID, $filepath );
201 $fileObject->store();
202 return true;
203 }
204
205 static function removeFilepath( $contentObjectAttributeID, $filepath )
206 {
207 if ( empty( $filepath ) )
208 return false;
209 $fileObject = eZImageFile::fetchByFilepath( $contentObjectAttributeID, $filepath );
210 if ( !$fileObject )
211 return false;
212 $fileObject->remove();
213 return true;
214 }
215
216 static function removeForContentObjectAttribute( $contentObjectAttributeID )
217 {
218 eZPersistentObject::removeObject( eZImageFile::definition(), array( 'contentobject_attribute_id' => $contentObjectAttributeID ) );
219 }
220
230 public static function isReferencedByOtherAttributes( $filepath, $attributeId, $attributeVersion, $languageCode )
231 {
232 $db = eZDB::instance();
233 $filepath = $db->escapeString( $filepath );
234
235 // Check eZImageFile and eZContentobjectAttribute for references to the alias file, in another version/language
236 $rows = $db->arrayQuery(
237 sprintf(
238 "
239 SELECT count(*) as count FROM ezcontentobject_attribute
240 INNER JOIN ezimagefile ON ezcontentobject_attribute.id=ezimagefile.contentobject_attribute_id
241 WHERE ezimagefile.filepath='%s'
242 AND ezcontentobject_attribute.data_text LIKE '%%url=\"%s\"%%'
243 AND ezcontentobject_attribute.id = %d
244 AND ( ezcontentobject_attribute.version != %d OR ezcontentobject_attribute.language_code != '%s' )
245 ",
246 $filepath, htmlspecialchars($filepath, ENT_XML1 | ENT_COMPAT),
247 $attributeId,
248 $attributeVersion,
249 $languageCode
250 )
251 );
252
253 return (int)$rows[0]['count'] > 0;
254 }
255
263 public static function isReferencedByOtherImageFiles( $filepath, $attributeId )
264 {
265 $db = eZDB::instance();
266 $filepath = $db->escapeString( $filepath );
267
268 $rows = $db->arrayQuery(
269 sprintf(
270 "
271 SELECT count(*) as count FROM ezcontentobject_attribute
272 INNER JOIN ezimagefile ON ezcontentobject_attribute.id=ezimagefile.contentobject_attribute_id
273 WHERE ezimagefile.filepath='%s'
274 AND ezcontentobject_attribute.id != %d
275 ",
276 $filepath,
277 $attributeId
278 )
279 );
280
281 return (int)$rows[0]['count'] > 0;
282 }
283
284
286 public $ContentObjectAttributeID;
287 public $Filepath;
288 public $id;
289 }
290
291 ?>
eZContentObjectAttribute\definition
static definition()
Definition: ezcontentobjectattribute.php:38
eZDB\instance
static instance( $databaseImplementation=false, $databaseParameters=false, $forceNewInstance=false)
Definition: ezdb.php:117
eZImageFile
The class eZImageFile handles registered images.
Definition: ezimagefile.php:19
eZImageFile\isReferencedByOtherImageFiles
static isReferencedByOtherImageFiles( $filepath, $attributeId)
Definition: ezimagefile.php:263
eZImageFile\appendFilepath
static appendFilepath( $contentObjectAttributeID, $filepath, $ignoreUnique=false)
Definition: ezimagefile.php:184
eZImageFile\$Filepath
$Filepath
Definition: ezimagefile.php:287
eZImageFile\removeForContentObjectAttribute
static removeForContentObjectAttribute( $contentObjectAttributeID)
Definition: ezimagefile.php:216
eZImageFile\fetchForContentObjectAttribute
static fetchForContentObjectAttribute( $contentObjectAttributeID, $asObject=false)
Definition: ezimagefile.php:50
eZImageFile\moveFilepath
static moveFilepath( $contentObjectAttributeID, $oldFilepath, $newFilepath)
Definition: ezimagefile.php:172
eZImageFile\isReferencedByOtherAttributes
static isReferencedByOtherAttributes( $filepath, $attributeId, $attributeVersion, $languageCode)
Definition: ezimagefile.php:230
eZImageFile\fetchListByFilePath
static fetchListByFilePath( $filePath)
Definition: ezimagefile.php:160
eZImageFile\$ContentObjectAttributeID
$ContentObjectAttributeID
Definition: ezimagefile.php:286
eZImageFile\fetchImageAttributesByFilepath
static fetchImageAttributesByFilepath( $filepath, $contentObjectAttributeID)
Definition: ezimagefile.php:80
eZImageFile\fetchByFilepath
static fetchByFilepath( $contentObjectAttributeID, $filepath, $asObject=true)
Definition: ezimagefile.php:136
eZImageFile\definition
static definition()
Definition: ezimagefile.php:20
eZImageFile\create
static create( $contentObjectAttributeID, $filepath)
Definition: ezimagefile.php:43
eZImageFile\$id
$id
Definition: ezimagefile.php:288
eZImageFile\removeFilepath
static removeFilepath( $contentObjectAttributeID, $filepath)
Definition: ezimagefile.php:205
eZPersistentObject
Definition: ezpersistentobject.php:33
eZPersistentObject\fetchObject
static fetchObject( $def, $field_filters, $conds, $asObject=true, $grouping=null, $custom_fields=null)
Definition: ezpersistentobject.php:213
eZPersistentObject\removeObject
static removeObject( $def, $conditions=null, $extraConditions=null)
Definition: ezpersistentobject.php:271
eZPersistentObject\count
static count( $def, $conds=null, $field=null)
Definition: ezpersistentobject.php:187
eZPersistentObject\fetchObjectList
static fetchObjectList( $def, $field_filters=null, $conds=null, $sorts=null, $limit=null, $asObject=true, $grouping=false, $custom_fields=null, $custom_tables=null, $custom_conds=null)
Definition: ezpersistentobject.php:806
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.