Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezfilepackagehandler.php
Go to the documentation of this file.
1 <?php
17 class eZFilePackageHandler extends eZPackageHandler
18 {
19 public function __construct()
20 {
21 parent::__construct( 'ezfile' );
22 }
23
24 function install( $package, $installType, $parameters,
25 $name, $os, $filename, $subdirectory,
26 $content, &$installParameters,
27 &$installData )
28 {
29 $collectionName = $parameters['collection'];
30 $installVariables = array();
31 if ( isset( $installParameters['variables'] ) )
32 $installVariables = $installParameters['variables'];
33 $iniFileVariables = false;
34 if ( isset( $installParameters['ini'] ) )
35 $iniFileVariables = $installParameters['ini'];
36 $fileList = $package->fileList( $collectionName );
37 if ( $fileList )
38 {
39 foreach ( $fileList as $fileItem )
40 {
41 $newFilePath = false;
42 if ( $fileItem['type'] == 'thumbnail' )
43 {
44 }
45 else
46 {
47 $filePath = $package->fileItemPath( $fileItem, $collectionName );
48 if ( is_dir( $filePath ) )
49 {
50 $newFilePath = $package->fileStorePath( $fileItem, $collectionName, $installParameters['path'], $installVariables );
51 eZDir::mkdir( $newFilePath, false, true );
52 }
53 else
54 {
55 $newFilePath = $package->fileStorePath( $fileItem, $collectionName, $installParameters['path'], $installVariables );
56 if ( preg_match( "#^(.+)/[^/]+$#", $newFilePath, $matches ) )
57 {
58 eZDir::mkdir( $matches[1], false, true );
59 }
60 eZFileHandler::copy( $filePath, $newFilePath );
61 }
62 }
63 if ( $fileItem['type'] == 'ini' and $iniFileVariables and $newFilePath )
64 {
65 $fileRole = $fileItem['role'];
66 $fileRoleValue = $fileItem['role-value'];
67 $fileVariableName = $fileItem['variable-name'];
68 $fileName = $fileItem['name'];
69 if ( $fileVariableName and
70 isset( $installParameters['variables'][$fileVariableName] ) )
71 $fileRoleValue = $installParameters['variables'][$fileVariableName];
72 if ( isset( $iniFileVariables[$fileRole][$fileRoleValue][$fileName] ) )
73 {
74 $variables = $iniFileVariables[$fileRole][$fileRoleValue][$fileName];
75 $ini = eZINI::fetchFromFile( $newFilePath );
76 $ini->setVariables( $variables );
77 $ini->save( false, false, false, false, false );
78 }
79 }
80 }
81 }
82 return true;
83 }
84
85 function add( $packageType, $package, $cli, $parameters )
86 {
87 $collections = array();
88 foreach ( $parameters['file-list'] as $fileItem )
89 {
90 $package->appendFile( $fileItem['file'], $fileItem['type'], $fileItem['role'],
91 $fileItem['design'], $fileItem['path'], $fileItem['collection'],
92 null, null, true, null,
93 $fileItem['file-type'], $fileItem['role-value'], $fileItem['variable-name'],
94 $fileItem['package-path'] );
95 if ( !in_array( $fileItem['collection'], $collections ) )
96 $collections[] = $fileItem['collection'];
97 $addString = "Adding " . $cli->stylize( 'mark', $fileItem['type'] );
98 if ( $fileItem['type'] != 'design' )
99 $addString .= " " . $cli->stylize( 'file', $fileItem['file'] );
100 if ( $fileItem['type'] == 'design' )
101 $addString .= " " . $cli->stylize( 'dir', $fileItem['design'] );
102 if ( ( $fileItem['type'] == 'design' or $fileItem['type'] == 'ini' ) and
103 $fileItem['role'] )
104 $addString .= " using role " . $cli->stylize( 'italic', $fileItem['role'] );
105 if ( $fileItem['variable-name'] )
106 $addString .= " bound to variable " . $cli->stylize( 'variable', $fileItem['variable-name'] );
107 // . " (" . $fileItem['design'] . ", " . $fileItem['role'] . ")";
108 // if ( $fileItem['variable-name'] )
109 // $addString .= '[' . $fileItem['variable-name'] . ']';
110 $cli->notice( $addString );
111 }
112 foreach ( $collections as $collection )
113 {
114 $installItems = $package->installItemsList( 'ezfile', false, $collection, true );
115 if ( count( $installItems ) == 0 )
116 $package->appendInstall( 'ezfile', false, false, true,
117 false, false,
118 array( 'collection' => $collection ) );
119 $dependencyItems = $package->dependencyItems( 'provides',
120 array( 'type' => 'ezfile',
121 'name' => 'collection',
122 'value' => $collection ) );
123 if ( count( $dependencyItems ) == 0 )
124 $package->appendDependency( 'provides',
125 array( 'type' => 'ezfile',
126 'name' => 'collection',
127 'value' => $collection ) );
128 $installItems = $package->installItemsList( 'ezfile', false, $collection, false );
129 if ( count( $installItems ) == 0 )
130 $package->appendInstall( 'ezfile', false, false, false,
131 false, false,
132 array( 'collection' => $collection ) );
133 }
134 }
135
136 function handleAddParameters( $packageType, $package, $cli, $arguments )
137 {
138 return $this->handleParameters( $packageType, $package, $cli, 'add', $arguments );
139 }
140
141 function handleParameters( $packageType, $package, $cli, $type, $arguments )
142 {
143 $fileList = array();
144 $currentType = 'file';
145 $currentVariableName = false;
146 $currentRole = false;
147 $currentRoleValue = false;
148 $currentDesign = false;
149 $currentCollection = 'default';
150 $packagePath = false;
151 if ( $packageType == 'design' )
152 {
153 $currentType = 'design';
154 }
155 else if ( $packageType == 'dir' )
156 {
157 $currentType = 'dir';
158 }
159 else if ( $packageType == 'ini' )
160 {
161 $currentType = 'ini';
162 $currentRole = 'standard';
163 }
164 else if ( $packageType == 'template' )
165 {
166 $currentType = 'design';
167 $currentRole = 'template';
168 }
169 else if ( $packageType == 'thumbnail' )
170 {
171 $currentType = 'thumbnail';
172 $currentRole = false;
173 }
174 for ( $i = 0; $i < count( $arguments ); ++$i )
175 {
176 $argument = $arguments[$i];
177 if ( $argument[0] == '-' )
178 {
179 if ( strlen( $argument ) > 1 and
180 $argument[1] == '-' )
181 {
182 }
183 else
184 {
185 $flag = substr( $argument, 1, 1 );
186 if ( $flag == 't' or
187 $flag == 'r' or
188 $flag == 'n' or
189 $flag == 'v' or
190 $flag == 'd' or
191 $flag == 'p' or
192 $flag == 'c' )
193 {
194 if ( strlen( $argument ) > 2 )
195 {
196 $data = substr( $argument, 2 );
197 }
198 else
199 {
200 $data = $arguments[$i+1];
201 ++$i;
202 }
203 if ( $flag == 't' )
204 {
205 if ( !in_array( $data, array( 'design', 'ini', 'file', 'thumbnail' ) ) )
206 {
207 $cli->error( "Unknown file type $data, allowed values are design, ini, thumbnail and file" );
208 return false;
209 }
210 $currentType = $data;
211 $currentRole = false;
212 $currentDesign = false;
213 if ( $currentType == 'design' )
214 {
215 $currentRole = 'template';
216 $currentDesign = 'standard';
217 }
218 }
219 else if ( $flag == 'r' )
220 {
221 if ( $currentType != 'design' and
222 $currentType != 'ini' )
223 {
224 $cli->error( "The current file type is not 'design' or 'ini' ($currentType), cannot set specific roles for files" );
225 return false;
226 }
227 if ( !$this->roleExists( $currentType, $data ) )
228 {
229 $cli->error( "Unknown file role $data for file type $currentType" );
230 return false;
231 }
232 $currentRole = $data;
233 }
234 else if ( $flag == 'v' )
235 {
236 $currentRoleValue = $data;
237 }
238 else if ( $flag == 'n' )
239 {
240 $currentVariableName = $data;
241 }
242 else if ( $flag == 'p' )
243 {
244 $packagePath = $data;
245 }
246 else if ( $flag == 'd' )
247 {
248 if ( $currentType != 'design' )
249 {
250 $cli->error( "The current file type is not 'design' ($currentType), cannot set specific designs for files" );
251 return false;
252 }
253 if ( !$this->designExists( $data ) )
254 {
255 $cli->error( "The design $data does not exist" );
256 return false;
257 }
258 $currentDesign = $data;
259 }
260 else if ( $flag == 'c' )
261 {
262 $currentCollection = $data;
263 }
264 }
265 }
266 }
267 else
268 {
269 $file = $argument;
270 $type = $currentType;
271 $role = $currentRole;
272 $roleValue = $currentRoleValue;
273 $design = $currentDesign;
274 $realFilePath = $this->fileExists( $file, $type, $role, $roleValue, $design,
275 $triedFiles );
276 if ( !$realFilePath )
277 {
278 $error = ( "File " . $cli->stylize( 'file', $file ) . " does not exist\n" .
279 "The following files were searched for:\n" );
280 $files = array();
281 foreach ( $triedFiles as $triedFile )
282 {
283 $files[] = $cli->stylize( 'file', $triedFile );
284 }
285 $cli->output( $error . implode( "\n", $files ) );
286 return false;
287 }
288 $fileFileType = false;
289 if ( is_dir( $realFilePath ) )
290 $fileFileType = 'dir';
291 if ( $currentType == 'ini' and
292 $fileFileType == 'dir' )
293 {
294 $iniFiles = eZDir::recursiveFind( $realFilePath, "" );
295 $fileFileType = 'file';
296 foreach ( $iniFiles as $iniFile )
297 {
298 $iniFile = $this->iniMatch( $iniFile, $role, $roleValue, $file, $triedFiles );
299 if ( !$iniFile )
300 continue;
301 $fileList[] = array( 'file' => $file,
302 'package-path' => $packagePath,
303 'type' => $type,
304 'role' => $role,
305 'role-value' => $roleValue,
306 'variable-name' => $currentVariableName,
307 'file-type' => $fileFileType,
308 'design' => $design,
309 'collection' => $currentCollection,
310 'path' => $iniFile );
311 }
312 }
313 else
314 {
315 $fileList[] = array( 'file' => $file,
316 'package-path' => $packagePath,
317 'type' => $type,
318 'role' => $role,
319 'role-value' => $roleValue,
320 'variable-name' => $currentVariableName,
321 'file-type' => $fileFileType,
322 'design' => $design,
323 'collection' => $currentCollection,
324 'path' => $realFilePath );
325 }
326 $realPath = false;
327 }
328 }
329 if ( count( $fileList ) == 0 )
330 {
331 $cli->error( "No files were added" );
332 return false;
333 }
334 return array( 'file-list' => $fileList );
335 }
336
337 function roleExists( $type, $role )
338 {
339 if ( $type == 'design' )
340 return in_array( $role,
341 array( 'template', 'image', 'stylesheet', 'font' ) );
342 if ( $type == 'ini' )
343 return in_array( $role,
344 array( 'standard', 'siteaccess', 'override' ) );
345 return false;
346 }
347
348 function designExists( $design )
349 {
350 return file_exists( 'design/' . $design );
351 }
352
353 function fileExists( &$file, &$type, &$role, &$roleValue, &$design,
354 &$triedFiles )
355 {
356 $triedFiles = array();
357 switch ( $type )
358 {
359 case 'file':
360 {
361 if ( file_exists( $file ) )
362 return $file;
363 $triedFiles[] = $file;
364 } break;
365 case 'dir':
366 {
367 if ( file_exists( $file ) and is_dir( $file ) )
368 return $file;
369 $triedFiles[] = $file;
370 } break;
371 case 'ini':
372 {
373 $filePath = $file;
374 if ( file_exists( $filePath ) )
375 {
376 $filePath = $this->iniMatch( $filePath, $role, $roleValue, $file, $triedFiles );
377 if ( $filePath )
378 return $filePath;
379 }
380 } break;
381 case 'thumbnail':
382 {
383 if ( file_exists( $file ) )
384 {
385 $filePath = $file;
386 // if ( preg_match( "#^(.+)/([^/]+)$#", $file, $matches ) )
387 // {
388 // $file = $matches[2];
389 // }
390 if ( preg_match( "#^(.+)\.([^.]+)$#", $file, $matches ) )
391 {
392 $file = 'thumbnail.' . $matches[2];
393 }
394 return $filePath;
395 }
396 $triedFiles[] = $file;
397 } break;
398 case 'design':
399 {
400 $roleFileName = false;
401 switch ( $role )
402 {
403 case 'template':
404 {
405 $roleFileName = 'templates';
406 } break;
407 case 'image':
408 {
409 $roleFileName = 'images';
410 } break;
411 case 'stylesheet':
412 {
413 $roleFileName = 'stylesheets';
414 } break;
415 case 'font':
416 {
417 $roleFileName = 'fonts';
418 } break;
419 }
420 $designDirectories = array( 'design' );
421 $extensionBaseDirectory = eZExtension::baseDirectory();
422 $ini = eZINI::instance( 'design.ini' );
423 $extensionDesigns = $ini->variable( 'ExtensionSettings', 'DesignExtensions' );
424 foreach ( $extensionDesigns as $extensionDesign )
425 {
426 $designDirectories[] = $extensionBaseDirectory . '/' . $extensionDesign . '/design';
427 }
428 if ( file_exists( $file ) )
429 {
430 $preg = '#^';
431 $i = 0;
432 foreach ( $designDirectories as $designDirectory )
433 {
434 if ( $i > 0 )
435 $preg .= '|';
436 $preg .= '(?:' . $designDirectory . ')';
437 ++$i;
438 }
439 $preg .= '/([^/]+)/(.+)$#';
440 $realFile = $file;
441 if ( preg_match( $preg, $file, $matches ) )
442 {
443 $design = $matches[1];
444 if ( preg_match( '#^(template(?:s)|image(?:s)|stylesheet(?:s)|font(?:s))/(.+)$#', $matches[2], $matches ) )
445 {
446 $role = $matches[1];
447 $file = $matches[2];
448 }
449 else
450 {
451 $file = $matches[2];
452 $role = false;
453 }
454 }
455 else
456 {
457 $type = 'file';
458 $role = false;
459 $design = false;
460 }
461 return $realFile;
462 }
463 $triedFiles[] = $file;
464 if ( !$design )
465 {
466 foreach ( $designDirectories as $designDirectory )
467 {
468 $filePath = $designDirectory . '/standard/' . $roleFileName . '/' . $file;
469 if ( file_exists( $filePath ) )
470 {
471 $design = 'standard';
472 return $filePath;
473 }
474 $triedFiles[] = $filePath;
475 if ( !file_exists( $designDirectory ) or
476 !is_dir( $designDirectory ) )
477 continue;
478 $dirHandler = @opendir( $designDirectory );
479 if ( !$dirHandler )
480 continue;
481 while ( ( $designSubDirectory = @readdir( $dirHandler ) ) !== false )
482 {
483 if ( $designSubDirectory == '.' or $designSubDirectory == '..' )
484 continue;
485 $filePath = $designDirectory . '/' . $designSubDirectory . '/' . $roleFileName . '/' . $file;
486 if ( file_exists( $filePath ) )
487 {
488 @closedir( $dirHandler );
489 $design = $designSubDirectory;
490 return $filePath;
491 }
492 $triedFiles[] = $filePath;
493 }
494 @closedir( $dirHandler );
495 }
496 }
497 foreach ( $designDirectories as $designDirectory )
498 {
499 if ( !file_exists( $designDirectory ) or
500 !is_dir( $designDirectory ) )
501 continue;
502
503 $filePath = $designDirectory . '/' . $file;
504 if ( file_exists( $filePath ) )
505 {
506 if ( preg_match( "#^([^/]+)/(.+)$#", $file, $matches ) )
507 {
508 $design = $matches[1];
509 $file = $matches[2];
510 }
511 else
512 {
513 $design = $file;
514 $file = false;
515 }
516 return $filePath;
517 }
518
519 $filePath = $designDirectory . '/' . $design . '/' . $roleFileName . '/' . $file;
520 if ( file_exists( $filePath ) )
521 return $filePath;
522 $triedFiles[] = $filePath;
523 }
524 } break;
525 }
526 return false;
527 }
528
529 function iniMatch( $filePath, &$role, &$roleValue, &$file, &$triedFiles )
530 {
531 if ( preg_match( "#^settings/siteaccess/([^/]+)/([^/]+)$#", $filePath, $matches ) )
532 {
533 $role = 'siteaccess';
534 $roleValue = $matches[1];
535 $file = $matches[2];
536 return $filePath;
537 }
538 else if ( preg_match( "#^settings/override/([^/]+)$#", $filePath, $matches ) )
539 {
540 $role = 'override';
541 $roleValue = false;
542 $file = $matches[1];
543 return $filePath;
544 }
545 else if ( preg_match( "#^settings/([^/]+)$#", $filePath, $matches ) )
546 {
547 $role = 'standard';
548 $roleValue = false;
549 $file = $matches[1];
550 return $filePath;
551 }
552 $triedFiles[] = $filePath;
553 $filePath = 'settings';
554 if ( $role == 'siteaccess' )
555 {
556 $filePath = 'settings/siteaccess';
557 if ( $roleValue )
558 $filePath .= '/' . $roleValue;
559 }
560 else if ( $role == 'override' )
561 $filePath = 'settings/override';
562 $filePath .= '/' . $file;
563 if ( file_exists( $filePath ) )
564 {
565 return $filePath;
566 }
567 $triedFiles[] = $filePath;
568 $filePath = $file;
569 if ( file_exists( $filePath ) )
570 {
571 if ( preg_match( "#^.+/([^/]+)$#", $filePath, $matches ) )
572 $file = $matches[1];
573 return $filePath;
574 }
575 $triedFiles[] = $filePath;
576 return false;
577 }
578
579 function createInstallNode( $package, $installNode, $installItem, $installType )
580 {
581 $installNode->setAttribute( 'collection', $installItem['collection'] );
582 }
583
584 function parseInstallNode( $package, $installNode, &$installParameters, $isInstall )
585 {
586 $collection = $installNode->getAttribute( 'collection' );
587 $installParameters['collection'] = $collection;
588 }
589 }
590
591 ?>
eZDir\mkdir
static mkdir( $dir, $perm=false, $recursive=false)
Definition: ezdir.php:73
eZDir\recursiveFind
static recursiveFind( $dir, $suffix)
Definition: ezdir.php:361
eZExtension\baseDirectory
static baseDirectory(eZINI|null $siteINI=null)
Definition: ezextension.php:39
eZFileHandler\copy
static copy( $sourceFilename, $destinationFilename)
Definition: ezfilehandler.php:356
eZFilePackageHandler
Handles content classes in the package system.
Definition: ezfilepackagehandler.php:18
eZFilePackageHandler\add
add( $packageType, $package, $cli, $parameters)
Definition: ezfilepackagehandler.php:85
eZFilePackageHandler\fileExists
fileExists(&$file, &$type, &$role, &$roleValue, &$design, &$triedFiles)
Definition: ezfilepackagehandler.php:353
eZFilePackageHandler\iniMatch
iniMatch( $filePath, &$role, &$roleValue, &$file, &$triedFiles)
Definition: ezfilepackagehandler.php:529
eZFilePackageHandler\designExists
designExists( $design)
Definition: ezfilepackagehandler.php:348
eZFilePackageHandler\handleParameters
handleParameters( $packageType, $package, $cli, $type, $arguments)
Definition: ezfilepackagehandler.php:141
eZFilePackageHandler\parseInstallNode
parseInstallNode( $package, $installNode, &$installParameters, $isInstall)
Definition: ezfilepackagehandler.php:584
eZFilePackageHandler\roleExists
roleExists( $type, $role)
Definition: ezfilepackagehandler.php:337
eZFilePackageHandler\__construct
__construct()
Definition: ezfilepackagehandler.php:19
eZFilePackageHandler\handleAddParameters
handleAddParameters( $packageType, $package, $cli, $arguments)
Definition: ezfilepackagehandler.php:136
eZFilePackageHandler\install
install( $package, $installType, $parameters, $name, $os, $filename, $subdirectory, $content, &$installParameters, &$installData)
Definition: ezfilepackagehandler.php:24
eZFilePackageHandler\createInstallNode
createInstallNode( $package, $installNode, $installItem, $installType)
Definition: ezfilepackagehandler.php:579
eZPackageHandler
The class eZPackageHandler does.
Definition: ezpackagehandler.php:18
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.