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