00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 include_once( 'lib/ezxml/classes/ezxml.php' );
00043 include_once( 'lib/ezfile/classes/ezfile.php' );
00044 include_once( 'lib/ezfile/classes/ezdir.php' );
00045 include_once( 'lib/ezfile/classes/ezfilehandler.php' );
00046
00047 define( 'EZ_PACKAGE_VERSION', '3.5.2' );
00048 define( 'EZ_PACKAGE_DEVELOPMENT', false );
00049 define( 'EZ_PACKAGE_USE_CACHE', true );
00050 define( 'EZ_PACKAGE_CACHE_CODEDATE', 1069339607 );
00051
00052 define( 'EZ_PACKAGE_STATUS_ALREADY_EXISTS', 1 );
00053
00054 define( 'EZ_PACKAGE_NON_INTERACTIVE', -1 );
00055
00056 class eZPackage
00057 {
00058
00059
00060
00061 function eZPackage( $parameters = array(), $repositoryPath = false )
00062 {
00063 $this->setParameters( $parameters );
00064 if ( !$repositoryPath )
00065 $repositoryPath = eZPackage::repositoryPath();
00066 $this->RepositoryPath = $repositoryPath;
00067 $this->RepositoryInformation = null;
00068 }
00069
00070
00071
00072
00073 function remove()
00074 {
00075 $path = $this->path();
00076 if ( file_exists( $path ) )
00077 {
00078 eZDir::recursiveDelete( $path );
00079 }
00080 $this->setInstalled( false );
00081 }
00082
00083
00084
00085
00086 function setParameters( $parameters = array() )
00087 {
00088 $timestamp = mktime();
00089 if ( isset( $_SERVER['HOSTNAME'] ) )
00090 $host = $_SERVER['HOSTNAME'];
00091 else if ( isset( $_SERVER['HTTP_HOST'] ) )
00092 $host = $_SERVER['HTTP_HOST'];
00093 else
00094 $host = 'localhost';
00095 $packaging = array( 'timestamp' => $timestamp,
00096 'host' => $host,
00097 'packager' => false );
00098 include_once( 'lib/version.php' );
00099 $ezpublishVersion = eZPublishSDK::version( true );
00100 $ezpublishNamedVersion = eZPublishSDK::version( false, false, true );
00101 $ezpublish = array( 'version' => $ezpublishVersion,
00102 'named-version' => $ezpublishNamedVersion );
00103 $defaults = array( 'name' => false,
00104 'development' => EZ_PACKAGE_DEVELOPMENT,
00105 'summary' => false,
00106 'description' => false,
00107 'vendor' => false,
00108 'vendor-dir' => false,
00109 'priority' => false,
00110 'type' => false,
00111 'extension' => false,
00112 'install_type' => 'install',
00113 'ezpublish' => $ezpublish,
00114 'maintainers' => array(),
00115 'packaging' => $packaging,
00116 'source' => false,
00117 'documents' => array(),
00118 'groups' => array(),
00119 'changelog' => array(),
00120 'file-list' => array(),
00121 'simple-file-list' => array(),
00122 'version-number' => false,
00123 'release-number' => false,
00124 'release-timestamp' => false,
00125 'licence' => false,
00126 'state' => false,
00127 'dependencies' => array( 'provides' => array(),
00128 'requires' => array(),
00129 'obsoletes' => array(),
00130 'conflicts' => array() ),
00131 'install' => array(),
00132 'uninstall' => array() );
00133 $this->PolicyCache = array();
00134 $this->InstallData = array();
00135 $this->Parameters = array_merge( $defaults, $parameters );
00136 }
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 function typeList()
00158 {
00159 $typeList =& $GLOBALS['eZPackageTypeList'];
00160 if ( !isset( $typeList ) )
00161 {
00162 $typeList = array();
00163 $ini =& eZINI::instance( 'package.ini' );
00164 $types = $ini->variable( 'PackageSettings', 'TypeList' );
00165 foreach ( $types as $typeID => $typeName )
00166 {
00167 $typeList[] = array( 'name' => $typeName,
00168 'id' => $typeID );
00169 }
00170 }
00171 return $typeList;
00172 }
00173
00174
00175
00176
00177
00178
00179 function stateList()
00180 {
00181 $stateList =& $GLOBALS['eZPackageStateList'];
00182 if ( !isset( $stateList ) )
00183 {
00184 $stateList = array();
00185 $ini =& eZINI::instance( 'package.ini' );
00186 $states = $ini->variable( 'PackageSettings', 'StateList' );
00187 foreach ( $states as $stateID => $stateName )
00188 {
00189 $stateList[] = array( 'name' => $stateName,
00190 'id' => $stateID);
00191 }
00192 }
00193 return $stateList;
00194 }
00195
00196
00197
00198
00199
00200 function create( $name, $parameters = array(), $repositoryPath = false, $repositoryID = false )
00201 {
00202 $parameters['name'] = $name;
00203 $handler = new eZPackage( $parameters, $repositoryPath );
00204
00205 // New packages always use local repository
00206 if ( $repositoryID === false )
00207 $repositoryID = 'local';
00208 $repositoryInformation = $handler->repositoryInformation( $repositoryID );
00209 if ( $repositoryPath !== false )
00210 $repositoryInformation['path'] = $repositoryPath;
00211 $handler->setCurrentRepositoryInformation( $repositoryInformation );
00212 return $handler;
00213 }
00214
00215
00216
00217
00218 function attributes()
00219 {
00220 return array( 'is_local',
00221 'development',
00222 'name', 'summary', 'description',
00223 'vendor', 'vendor-dir', 'priority', 'type',
00224 'extension', 'source',
00225 'version-number', 'release-number', 'release-timestamp',
00226 'maintainers', 'documents', 'groups',
00227 'simple-file-list', 'file-list', 'file-count',
00228 'can_read', 'can_export', 'can_import', 'can_install',
00229 'changelog', 'dependencies',
00230 'is_installed',
00231 'install_type',
00232 'thumbnail-list',
00233 'install', 'uninstall',
00234 'licence', 'state',
00235 'ezpublish-version', 'ezpublish-named-version', 'packaging-timestamp',
00236 'packaging-host', 'packaging-packager' );
00237 }
00238
00239
00240
00241
00242 function setAttribute( $attributeName, $attributeValue )
00243 {
00244 if ( !in_array( $attributeName,
00245 array( 'development',
00246 'name', 'summary', 'description',
00247 'vendor', 'vendor-dir', 'priority', 'type',
00248 'install_type',
00249 'extension', 'source',
00250 'licence', 'state' ) ) )
00251 return false;
00252 if ( array_key_exists( $attributeName, $this->Parameters ) and
00253 !is_array( $this->Parameters[$attributeName] ))
00254 {
00255 $this->Parameters[$attributeName] = $attributeValue;
00256 return true;
00257 }
00258 return false;
00259 }
00260
00261
00262
00263
00264 function hasAttribute( $attributeName /*, $attributeList = false*/ )
00265 {
00266 return in_array( $attributeName, $this->attributes() );
00267 }
00268
00269
00270
00271
00272 function &attribute( $attributeName /*, $attributeList = false*/ )
00273 {
00274 if ( in_array( $attributeName,
00275 array( 'development',
00276 'name', 'summary', 'description',
00277 'vendor', 'vendor-dir', 'priority', 'type',
00278 'extension', 'source',
00279 'version-number', 'release-number', 'release-timestamp',
00280 'maintainers', 'documents', 'groups',
00281 'simple-file-list', 'file-list',
00282 'changelog', 'dependencies',
00283 'install', 'uninstall',
00284 'install_type',
00285 'licence', 'state', 'settings-files' ) ) )
00286 return $this->Parameters[$attributeName];
00287 else if ( $attributeName == 'is_installed' )
00288 return $this->isInstalled;
00289 else if ( $attributeName == 'ezpublish-version' )
00290 return $this->Parameters['ezpublish']['version'];
00291 else if ( $attributeName == 'ezpublish-named-version' )
00292 return $this->Parameters['ezpublish']['named-version'];
00293 else if ( $attributeName == 'packaging-timestamp' )
00294 return $this->Parameters['packaging']['timestamp'];
00295 else if ( $attributeName == 'packaging-host' )
00296 return $this->Parameters['packaging']['host'];
00297 else if ( $attributeName == 'packaging-packager' )
00298 return $this->Parameters['packaging']['packager'];
00299 else if ( $attributeName == 'can_read' )
00300 {
00301 $canRead = $this->canRead();
00302 return $canRead;
00303 }
00304 else if ( $attributeName == 'can_export' )
00305 {
00306 $canExport = $this->canExport();
00307 return $canExport;
00308 }
00309 else if ( $attributeName == 'can_import' )
00310 {
00311 $canImport = $this->canImport();
00312 return $canImport;
00313 }
00314 else if ( $attributeName == 'can_install' )
00315 {
00316 $canInstall = $this->canInstall();
00317 return $canInstall;
00318 }
00319 else if ( $attributeName == 'file-count' )
00320 {
00321 $fileCount = $this->fileCount();
00322 return $fileCount;
00323 }
00324 else if ( $attributeName == 'thumbnail-list' )
00325 {
00326 $thumbnailList = $this->thumbnailList( 'default' );
00327 return $thumbnailList;
00328 }
00329 else if ( $attributeName == 'is_local' )
00330 {
00331 $repositoryInformation = $this->currentRepositoryInformation();
00332 $isLocal = $repositoryInformation['type'] == 'local';
00333 return $isLocal;
00334 }
00335
00336 eZDebug::writeError( "No such attribute: $attributeName for eZPackage", 'eZPackage::attribute' );
00337 $attributeValue = null;
00338 return $attributeValue;
00339 }
00340
00341 function canUsePolicyFunction( $functionName )
00342 {
00343 include_once( "kernel/classes/datatypes/ezuser/ezuser.php" );
00344 $currentUser =& eZUser::currentUser();
00345 $accessResult = $currentUser->hasAccessTo( 'package', $functionName );
00346 if ( in_array( $accessResult['accessWord'], array( 'yes', 'limited' ) ) )
00347 {
00348 return true;
00349 }
00350 return false;
00351 }
00352
00353 function canRead()
00354 {
00355 return $this->canUsePackagePolicyFunction( 'read' );
00356 }
00357
00358 function canExport()
00359 {
00360 return $this->canUsePackagePolicyFunction( 'export' );
00361 }
00362
00363 function canImport()
00364 {
00365 return $this->canUsePackagePolicyFunction( 'import' );
00366 }
00367
00368 function canInstall()
00369 {
00370 return $this->canUsePackagePolicyFunction( 'install' );
00371 }
00372
00373 function canUsePackagePolicyFunction( $functionName )
00374 {
00375 $canUse =& $this->PolicyCache[$functionName];
00376 if ( !isset( $canUse ) )
00377 {
00378 include_once( "kernel/classes/datatypes/ezuser/ezuser.php" );
00379 $currentUser =& eZUser::currentUser();
00380 $accessResult = $currentUser->hasAccessTo( 'package', $functionName );
00381 $limitationList = array();
00382 $canUse = false;
00383 if ( $accessResult['accessWord'] == 'yes' )
00384 {
00385 $canUse = true;
00386 }
00387 else if ( $accessResult['accessWord'] == 'limited' )
00388 {
00389 $allRoles = array();
00390 $limitation =& $accessResult['policies'];
00391 foreach ( $limitation as $dummyKey => $val )
00392 {
00393 $limitationList[] =& $val;
00394 }
00395 $typeList = false;
00396 foreach( $limitationList as $limitationArray )
00397 {
00398 foreach ( $limitationArray as $key => $limitation )
00399 {
00400 if ( $key == 'Type' )
00401 {
00402 if ( !is_array( $typeList ) )
00403 $typeList = array();
00404 $typeList = array_merge( $typeList, $limitation );
00405 }
00406 }
00407 }
00408 if ( $typeList === false )
00409 {
00410 $canUse = true;
00411 }
00412 else
00413 {
00414 $canUse = in_array( $this->attribute( 'type' ), $typeList );
00415 }
00416 }
00417 }
00418 return $canUse;
00419 }
00420
00421 function fetchMaintainerRoleIDList( $packageType = false, $checkRoles = false )
00422 {
00423 $allRoles = false;
00424 if ( $checkRoles )
00425 {
00426 include_once( "kernel/classes/datatypes/ezuser/ezuser.php" );
00427 $currentUser =& eZUser::currentUser();
00428 $accessResult = $currentUser->hasAccessTo( 'package', 'create' );
00429 $limitationList = array();
00430 if ( $accessResult['accessWord'] == 'limited' )
00431 {
00432 $allRoles = array();
00433 $limitation =& $accessResult['policies'];
00434 foreach ( $limitation as $key => $val )
00435 {
00436 $limitationList[] =& $val;
00437 }
00438 foreach( $limitationList as $limitationArray )
00439 {
00440 $allowedType = true;
00441 $allowedRoles = false;
00442 foreach ( $limitationArray as $key => $limitation )
00443 {
00444 if ( $key == 'Role' )
00445 {
00446 $allowedRoles = $limitation;
00447 }
00448 else if ( $key == 'Type' )
00449 {
00450 $typeList = $limitation;
00451 if ( $packageType === false )
00452 {
00453 $allowedType = in_array( $packageType, $typeList );
00454 }
00455 }
00456 }
00457 if ( $allowedType and
00458 count( $allowedRoles ) > 0 )
00459 {
00460 $allRoles = array_merge( $allRoles, $allowedRoles );
00461 }
00462 }
00463 }
00464 }
00465 if ( is_array( $allRoles ) and count( $allRoles ) == 0 )
00466 return array();
00467 $ini =& eZINI::instance( 'package.ini' );
00468 $roleList = $ini->variable( 'MaintainerSettings', 'RoleList' );
00469 if ( $allRoles !== false )
00470 {
00471 $roleList = array_intersect( $roleList, $allRoles );
00472 }
00473 return $roleList;
00474 }
00475
00476 function fetchMaintainerRoleList( $packageType = false, $checkRoles = false )
00477 {
00478 $roleList = eZPackage::fetchMaintainerRoleIDList( $packageType, $checkRoles );
00479 $roleNameList = array();
00480 foreach ( $roleList as $roleID )
00481 {
00482 $roleName = eZPackage::maintainerRoleName( $roleID );
00483 $roleNameList[] = array( 'name' => $roleName,
00484 'id' => $roleID );
00485 }
00486 return $roleNameList;
00487 }
00488
00489 function maintainerRoleListForRoles()
00490 {
00491 $ini =& eZINI::instance( 'package.ini' );
00492 $roleList = $ini->variable( 'MaintainerSettings', 'RoleList' );
00493 $roleNameList = array();
00494 foreach ( $roleList as $roleID )
00495 {
00496 $roleName = eZPackage::maintainerRoleName( $roleID );
00497 $roleNameList[] = array( 'name' => $roleName,
00498 'id' => $roleID );
00499 }
00500 return $roleNameList;
00501 }
00502
00503 function maintainerRoleName( $roleID )
00504 {
00505 $nameMap = array( 'lead' => ezi18n( 'kernel/package', 'Lead' ),
00506 'developer' => ezi18n( 'kernel/package', 'Developer' ),
00507 'designer' => ezi18n( 'kernel/package', 'Designer' ),
00508 'contributor' => ezi18n( 'kernel/package', 'Contributor' ),
00509 'tester' => ezi18n( 'kernel/package', 'Tester' ) );
00510 if ( isset( $nameMap[$roleID] ) )
00511 return $nameMap[$roleID];
00512 return false;
00513 }
00514
00515 function appendMaintainer( $name, $email, $role = false )
00516 {
00517 $this->Parameters['maintainers'][] = array( 'name' => $name,
00518 'email' => $email,
00519 'role' => $role );
00520 }
00521
00522 function appendDocument( $name, $mimeType = false, $os = false, $audience = false,
00523 $create = false, $data = false )
00524 {
00525 if ( !$mimeType )
00526 $mimeType = 'text/plain';
00527 $this->Parameters['documents'][] = array( 'name' => $name,
00528 'mime-type' => $mimeType,
00529 'os' => $os,
00530 // 'create-document' => $create,
00531 'data' => $data,
00532 'audience' => $audience );
00533 if ( $create )
00534 {
00535 eZFile::create( $name, $this->path() . '/' . eZPackage::documentDirectory(),
00536 $data );
00537 }
00538 }
00539
00540 function appendGroup( $name )
00541 {
00542 $index = count( $this->Parameters['groups'] );
00543 $this->Parameters['groups'][$index] = array( 'name' => $name );
00544 }
00545
00546 function appendChange( $person, $email, $changes,
00547 $release = false, $timestamp = null )
00548 {
00549 if ( $timestamp === null )
00550 $timestamp = mktime();
00551 if ( !is_array( $changes ) )
00552 $changes = array( $changes );
00553 if ( !$release )
00554 $release = $this->Parameters['release-number'];
00555 if ( !$release )
00556 $release = 1;
00557 $this->Parameters['changelog'][] = array( 'timestamp' => $timestamp,
00558 'person' => $person,
00559 'email' => $email,
00560 'changes' => $changes,
00561 'release' => $release );
00562 }
00563
00564 function md5sum( $file )
00565 {
00566 if ( function_exists( 'md5_file' ) )
00567 {
00568 if ( file_exists( $file ) )
00569 {
00570 return md5_file( $file );
00571 }
00572 else
00573 eZDebug::writeError( "Could not open file $file for md5sum calculation" );
00574 }
00575 else
00576 {
00577 $fd = @fopen( $file, 'rb' );
00578 if ( $fd )
00579 {
00580 $data = '';
00581 while ( !@feof( $fd ) )
00582 {
00583 $data .= @fread( $fd, 4096 );
00584 }
00585 @fclose( $fd );
00586 return md5( $data );
00587 }
00588 }
00589 return false;
00590 }
00591
00592 function fileStorePath( $fileItem, $collectionName, $path = false, $installVariables = array() )
00593 {
00594 $type = $fileItem['type'];
00595 $variableName = $fileItem['variable-name'];
00596 if ( $type == 'file' )
00597 {
00598 $pathArray = array( $path, $fileItem['subdirectory'] );
00599 $pathArray[] = $fileItem['name'];
00600 $path = eZDir::path( $pathArray );
00601 }
00602 else if ( $type == 'design' )
00603 {
00604 $roleFileName = false;
00605 $design = $fileItem['design'];
00606 switch ( $fileItem['role'] )
00607 {
00608 case 'template':
00609 {
00610 $roleFileName = 'templates';
00611 } break;
00612 case 'image':
00613 {
00614 $roleFileName = 'images';
00615 } break;
00616 case 'stylesheet':
00617 {
00618 $roleFileName = 'stylesheets';
00619 } break;
00620 case 'font':
00621 {
00622 $roleFileName = 'fonts';
00623 } break;
00624 }
00625 if ( $variableName and
00626 isset( $installVariables[$variableName] ) )
00627 $design = $installVariables[$variableName];
00628 $pathArray = array( $path, 'design', $design, $roleFileName, $fileItem['subdirectory'] );
00629 if ( $fileItem['file-type'] != 'dir' )
00630 $pathArray[] = $fileItem['name'];
00631 $path = eZDir::path( $pathArray );
00632 }
00633 else if ( $type == 'ini' )
00634 {
00635 $roleValue = false;
00636 $roleFileName = false;
00637 switch ( $fileItem['role'] )
00638 {
00639 case 'override':
00640 {
00641 $roleFileName = 'override';
00642 } break;
00643 case 'siteaccess':
00644 {
00645 $roleFileName = 'siteaccess';
00646 $roleValue = $fileItem['role-value'];
00647 if ( $variableName and
00648 isset( $installVariables[$variableName] ) )
00649 $roleValue = $installVariables[$variableName];
00650 } break;
00651 case 'standard':
00652 default:
00653 {
00654 $roleFileName = '';
00655 } break;
00656 }
00657 $pathArray = array( $path, 'settings', $roleFileName, $roleValue, $fileItem['subdirectory'] );
00658 if ( $fileItem['file-type'] != 'dir' )
00659 $pathArray[] = $fileItem['name'];
00660 $path = eZDir::path( $pathArray );
00661 }
00662 return $path;
00663 }
00664
00665 function fileItemPath( $fileItem, $collectionName, $path = false )
00666 {
00667 // if ( !$path )
00668 // $path = $this->currentRepositoryPath();
00669 if ( !$path )
00670 {
00671 $repositoryInformation = $this->currentRepositoryInformation();
00672 $path = $repositoryInformation['path'];
00673 }
00674 $typeDir = $fileItem['type'];
00675 if ( $fileItem['type'] == 'design' )
00676 $typeDir .= '.' . $fileItem['design'];
00677 if ( isset( $fileItem['role'] ) && $fileItem['role'] )
00678 {
00679 $typeDir .= '.' . $fileItem['role'];
00680 if ( $fileItem['role-value'] )
00681 $typeDir .= '-' . $fileItem['role-value'];
00682 }
00683 $path .= '/' . $this->attribute( 'name' ) . '/' . eZPackage::filesDirectory() . '/' . $collectionName . '/' . $typeDir;
00684 if ( isset( $fileItem['subdirectory'] ) && $fileItem['subdirectory'] )
00685 $path .= '/' . $fileItem['subdirectory'];
00686 $path .= '/' . $fileItem['name'];
00687 return $path;
00688 }
00689
00690 function fileList( $collectionName )
00691 {
00692 $fileCollections = $this->Parameters['file-list'];
00693 if ( isset( $fileCollections[$collectionName] ) )
00694 return $fileCollections[$collectionName];
00695 return false;
00696 }
00697
00698 function thumbnailList( $collectionName )
00699 {
00700 $thumbnails = array();
00701 $fileList = $this->fileList( $collectionName );
00702 if ( !is_array( $fileList ) )
00703 return $thumbnails;
00704
00705 foreach ( $fileList as $fileItem )
00706 {
00707 if ( $fileItem['type'] == 'thumbnail' )
00708 {
00709 $thumbnails[] = $fileItem;
00710 }
00711 }
00712 return $thumbnails;
00713 }
00714
00715 function fileCount()
00716 {
00717 $count = 0;
00718 foreach ( $this->Parameters['file-list'] as $collection )
00719 {
00720 $count += count( $collection );
00721 }
00722 return $count;
00723 }
00724
00725 function appendFile( $file, $type, $role,
00726 $design, $filePath, $collection,
00727 $subDirectory = null, $md5 = null,
00728 $copyFile = false, $modified = null, $fileType = false,
00729 $roleValue = false, $variableName = false,
00730 $packagePath = false )
00731 {
00732 if ( !$collection )
00733 $collection = 'default';
00734 if ( $subDirectory === null )
00735 {
00736 $subDirectory = false;
00737 if ( preg_match( '#^(.+)/([^/]+)$#', $file, $matches ) )
00738 {
00739 $subDirectory = $matches[1];
00740 $file = $matches[2];
00741 }
00742 }
00743 if ( $packagePath )
00744 $subDirectory = $packagePath;
00745
00746 $fileItem = array( 'name' => $file,
00747 'subdirectory' => $subDirectory,
00748 'type' => $type,
00749 'role' => $role,
00750 'role-value' => $roleValue,
00751 'variable-name' => $variableName,
00752 'path' => $filePath,
00753 'file-type' => $fileType,
00754 'design' => $design );
00755 if ( $md5 === null )
00756 {
00757 $md5 = $this->md5sum( $filePath );
00758 }
00759 $fileItem['md5'] = $md5;
00760 $this->Parameters['file-list'][$collection][] = $fileItem;
00761
00762 if ( $copyFile )
00763 {
00764 // copying file
00765 $typeDir = $type;
00766 if ( $type == 'design' )
00767 $typeDir .= '.' . $fileItem['design'];
00768 if ( $role )
00769 {
00770 $typeDir .= '.' . $role;
00771 if ( $roleValue )
00772 $typeDir .= '-' . $roleValue;
00773 }
00774 $path = $this->path() . '/' . eZPackage::filesDirectory() . '/' . $collection . '/' . $typeDir;
00775 if ( $subDirectory )
00776 $path .= '/' . $subDirectory;
00777 if ( !file_exists( $path ) )
00778 eZDir::mkdir( $path, eZDir::directoryPermission(), true );
00779
00780 if ( is_dir( $fileItem['path'] ) )
00781 {
00782 eZDir::copy( $fileItem['path'], $path,
00783 $fileItem['name'] != false, true, false, eZDir::temporaryFileRegexp() );
00784 }
00785 else
00786 {
00787 eZFileHandler::copy( $fileItem['path'], $path . '/' . $fileItem['name'] );
00788 }
00789 }
00790 }
00791
00792
00793
00794
00795
00796 function appendProvides( $type, $name, $value, $parameters = false )
00797 {
00798 $dependencyParameters = array( 'type' => $type,
00799 'name' => $name,
00800 'value' => $value );
00801
00802 if ( $parameters !== false )
00803 $dependencyParameters = array_merge( $dependencyParameters, $parameters );
00804
00805 $this->appendDependency( 'provides', $dependencyParameters );
00806 }
00807
00808
00809
00810
00811
00812
00813 function appendDependency( $dependencySection, $parameters )
00814 {
00815 if ( !in_array( $dependencySection,
00816 array( 'provides', 'requires',
00817 'obsoletes', 'conflicts' ) ) )
00818 return false;
00819
00820 $this->Parameters['dependencies'][$dependencySection][] = $parameters;
00821 }
00822
00823 function dependencyOperatorText( $dependencyItem )
00824 {
00825 return '=';
00826 }
00827
00828 function createDependencyText( &$cli, $dependencyItem, $dependencySection )
00829 {
00830 $text = ( $cli->stylize( 'emphasize', $dependencyItem['type'] ) .
00831 '(' .
00832 $cli->stylize( 'emphasize', $dependencyItem['name'] ) .
00833 ')' );
00834 if ( $dependencyItem['value'] )
00835 $text .= ' ' . $this->dependencyOperatorText( $dependencyItem ) .' ' . $cli->stylize( 'symbol', $dependencyItem['value'] );
00836 $handler =& $this->packageHandler( $dependencyItem['type'] );
00837 if ( $handler )
00838 {
00839 $specialText = $handler->createDependencyText( $this, $dependencyItem, $dependencySection );
00840 if ( $specialText )
00841 $text .= ' ( ' . $specialText . ' ) ';
00842 }
00843 return $text;
00844 }
00845
00846 function groupDependencyItemsByType( $dependencyItems )
00847 {
00848 $types = array();
00849 foreach ( $dependencyItems as $dependencyItem )
00850 {
00851 if ( !isset( $types[$dependencyItem['type']] ) )
00852 $types[$dependencyItem['type']] = array();
00853 $types[$dependencyItem['type']][] = $dependencyItem;
00854 }
00855 return $types;
00856 }
00857
00858
00859
00860
00861 function dependencyItems( $dependencySection, $parameters = false )
00862 {
00863 if ( !in_array( $dependencySection,
00864 array( 'provides', 'requires',
00865 'obsoletes', 'conflicts' ) ) )
00866 return false;
00867
00868 if ( $parameters === false )
00869 {
00870 return $this->Parameters['dependencies'][$dependencySection];
00871 }
00872
00873 $matches = array();
00874 $dependencyItems = $this->Parameters['dependencies'][$dependencySection];
00875 foreach ( $dependencyItems as $dependencyItem )
00876 {
00877 $found = true;
00878
00879 foreach ( $parameters as $paramName => $paramValue )
00880 {
00881 if ( !isset( $dependencyItem[$paramName] ) ||
00882 $dependencyItem[$paramName] != $paramValue )
00883 {
00884 $found = false;
00885 break;
00886 }
00887 }
00888
00889 if ( $found )
00890 $matches[] = $dependencyItem;
00891 }
00892
00893 return $matches;
00894 }
00895
00896
00897
00898
00899 function installItemsList( $type = false, $os = false, $name = false, $isInstall = true )
00900 {
00901 $installName = 'install';
00902 if ( !$isInstall )
00903 $installName = 'uninstall';
00904 if ( !$name and !$type and !$os )
00905 {
00906 return $this->Parameters[$installName];
00907 }
00908 else
00909 {
00910 $matches = array();
00911 $installItems = $this->Parameters[$installName];
00912 foreach ( $installItems as $installItem )
00913 {
00914 $found = false;
00915 if ( $name and $installItem['name'] == $name )
00916 $found = true;
00917 if ( !$found and $type and $installItem['type'] == $type )
00918 $found = true;
00919 if ( !$found )
00920 {
00921 if ( $os )
00922 {
00923 if ( !$installItem['os'] )
00924 $found = true;
00925 else if ( $os and $installItem['os'] == $os )
00926 $found = true;
00927 }
00928 else
00929 $found = true;
00930 }
00931 if ( $found )
00932 $matches[] = $installItem;
00933 }
00934 return $matches;
00935 }
00936 }
00937
00938 function appendInstall( $type, $name, $os = false, $isInstall = true,
00939 $filename = false, $subdirectory = false,
00940 $parameters = false )
00941 {
00942 $installEntry = $parameters;
00943 $installEntry['type'] = $type;
00944 $installEntry['name'] = $name;
00945 $installEntry['os'] = $os;
00946 $installEntry['filename'] = $filename;
00947 $installEntry['sub-directory'] = $subdirectory;
00948 if ( $installEntry['filename'] )
00949 {
00950 $content = false;
00951 if ( isset( $installEntry['content'] ) )
00952 $content = $installEntry['content'];
00953 if ( get_class( $content ) == 'ezdomnode' )
00954 {
00955 $partContentNode =& $content;
00956 $path = $this->path();
00957 if ( $installEntry['sub-directory'] )
00958 {
00959 $path .= '/' . $installEntry['sub-directory'];
00960 }
00961 $filePath = $path . '/' . $installEntry['filename'] . '.xml';
00962 if ( !file_exists( $path ) )
00963 eZDir::mkdir( $path, eZDir::directoryPermission(), true );
00964 $partDOM = new eZDOMDocument();
00965 $partDOM->setRoot( $partContentNode );
00966 $this->storeDOM( $filePath, $partDOM );
00967 $installEntry['content'] = false;
00968 }
00969 }
00970 $installName = 'install';
00971 if ( !$isInstall )
00972 $installName = 'uninstall';
00973 $this->Parameters[$installName][] = $installEntry;
00974 }
00975
00976
00977
00978
00979 function setPackager( $timestamp = false, $host = false, $packager = false )
00980 {
00981 if ( $timestamp )
00982 $this->Parameters['packaging']['timestamp'] = $timestamp;
00983 if ( $host )
00984 $this->Parameters['packaging']['host'] = $host;
00985 if ( $packager )
00986 $this->Parameters['packaging']['packager'] = $packager;
00987 }
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997 function setRelease( $version = false, $release = false, $timestamp = false,
00998 $licence = false, $state = false )
00999 {
01000 if ( $version !== false )
01001 {
01002 $this->Parameters['version-number'] = $version;
01003 }
01004 if ( $release !== false )
01005 {
01006 $this->Parameters['release-number'] = $release;
01007 }
01008 if ( $timestamp !== false )
01009 {
01010 $this->Parameters['release-timestamp'] = $timestamp;
01011 }
01012 if ( $licence !== false )
01013 {
01014 $this->Parameters['licence'] = $licence;
01015 }
01016 if ( $state !== false )
01017 {
01018 $this->Parameters['state'] = $state;
01019 }
01020 }
01021
01022
01023
01024
01025
01026 function toString( $export = false )
01027 {
01028 $dom =& $this->domStructure( $export );
01029 $string = $dom->toString();
01030 return $string;
01031 }
01032
01033
01034
01035
01036
01037
01038 function storeCache( $directory = false )
01039 {
01040 if ( !file_exists( $directory ) )
01041 eZDir::mkdir( $directory, eZDir::directoryPermission(), true );
01042 include_once( 'lib/ezutils/classes/ezphpcreator.php' );
01043 $php = new eZPHPCreator( $directory, 'package.php' );
01044 $php->addComment( "Automatically created cache file for the package format\n" .
01045 "Do not modify this file" );
01046 $php->addSpace();
01047 $php->addVariable( 'CacheCodeDate', EZ_PACKAGE_CACHE_CODEDATE );
01048 $php->addSpace();
01049 $php->addVariable( 'Parameters', $this->Parameters, EZ_PHPCREATOR_VARIABLE_ASSIGNMENT,
01050 array( 'full-tree' => true ) );
01051 $php->addVariable( 'InstallData', $this->InstallData, EZ_PHPCREATOR_VARIABLE_ASSIGNMENT,
01052 array( 'full-tree' => true ) );
01053 $php->addVariable( 'RepositoryPath', $this->RepositoryPath );
01054 $php->store();
01055 }
01056
01057
01058
01059
01060 function store()
01061 {
01062 $path = $this->path();
01063 return $this->storePackageFile( $path );
01064 }
01065
01066
01067
01068
01069 function storePackageFile( $path, $storeCache = true )
01070 {
01071 if ( !file_exists( $path ) )
01072 {
01073 eZDir::mkdir( $path, eZDir::directoryPermission(), true );
01074 }
01075 $filePath = $path . '/' . eZPackage::definitionFilename();
01076
01077 $packageFileString = $this->toString( false );
01078 $result = $this->storeString( $filePath, $packageFileString );
01079
01080 //$this->cleanup();
01081 if ( $storeCache )
01082 $this->storeCache( $path . '/' . $this->cacheDirectory() );
01083 return $result;
01084 }
01085
01086 function removeFiles( $path )
01087 {
01088 if ( file_exists( $path ) )
01089 {
01090 eZDir::recursiveDelete( $path );
01091 }
01092 }
01093
01094 function exportToArchive( $archivePath )
01095 {
01096 $tempPath = eZPackage::temporaryExportPath() . '/' . $this->attribute( 'name' );
01097 $this->removeFiles( $tempPath );
01098
01099 // Create package temp dir and copy package's XML file there
01100 $this->storePackageFile( $tempPath, false );
01101
01102 // Copy package's directories
01103 $directoryList = array( $this->documentDirectory(),
01104 $this->filesDirectory(),
01105 $this->simpleFilesDirectory(),
01106 $this->settingsDirectory() );
01107 $installItems = $this->Parameters['install'];
01108 foreach( $installItems as $installItem )
01109 {
01110 if ( !in_array( $installItem['sub-directory'], $directoryList ) )
01111 $directoryList[] = $installItem['sub-directory'];
01112 }
01113
01114 $path = $this->path();
01115 foreach( $directoryList as $dirName )
01116 {
01117 $destDir = $tempPath;
01118 $dir = $path . '/' . $dirName;
01119 if ( file_exists( $dir ) )
01120 eZDir::copy( $dir, $destDir );
01121 }
01122
01123 include_once( 'lib/ezfile/classes/ezarchivehandler.php' );
01124
01125 $archive = eZArchiveHandler::instance( 'tar', 'gzip', $archivePath );
01126
01127 $packageBaseDirectory = $tempPath;
01128 $fileList = array();
01129 $fileList[] = $packageBaseDirectory;
01130
01131 $archive->createModify( $fileList, '', $packageBaseDirectory );
01132
01133 $this->removeFiles( $tempPath );
01134 return $archivePath;
01135 }
01136
01137 function &import( $archiveName, &$packageName, $dbAvailable = true, $repositoryID = false )
01138 {
01139 $tempDirPath = eZPackage::temporaryImportPath();
01140 if ( is_dir( $archiveName ) )
01141 {
01142 eZDebug::writeError( "Importing from directory is not supported." );
01143 $retValue = false;
01144 return $retValue;
01145 }
01146 else
01147 {
01148 $archivePath = $tempDirPath . '/' . $packageName;
01149 eZPackage::removeFiles( $archivePath );
01150 if ( !file_exists( $archivePath ) )
01151 {
01152 eZDir::mkdir( $archivePath, eZDir::directoryPermission(), true );
01153 }
01154 include_once( 'lib/ezfile/classes/ezarchivehandler.php' );
01155
01156 $archive = eZArchiveHandler::instance( 'tar', 'gzip', $archiveName );
01157 $fileList = array();
01158 $fileList[] = eZPackage::definitionFilename();
01159 if ( !$archive->extractList( $fileList, $archivePath, '' ) )
01160 {
01161 eZDebug::writeError( "Failed extracting package definition file from $archivePath" );
01162 $retValue = false;
01163 return $retValue;
01164 }
01165
01166 $package = eZPackage::fetch( $packageName, $tempDirPath, false, $dbAvailable );
01167 eZPackage::removeFiles( $archivePath );
01168
01169 if ( $package )
01170 {
01171 $packageName = $package->attribute( 'name' );
01172
01173 if ( !$repositoryID )
01174 $repositoryID = $package->attribute( 'vendor-dir' );
01175
01176 $existingPackage = eZPackage::fetch( $packageName, false, false, $dbAvailable );
01177 if ( $existingPackage )
01178 {
01179 $retValue = EZ_PACKAGE_STATUS_ALREADY_EXISTS;
01180 return $retValue;
01181 }
01182 unset( $archive );
01183 unset( $package );
01184
01185 $fullRepositoryPath = eZPackage::repositoryPath() . '/' . $repositoryID;
01186 $packagePath = $fullRepositoryPath . '/' . $packageName;
01187 if ( !file_exists( $packagePath ) )
01188 {
01189 eZDir::mkdir( $packagePath, eZDir::directoryPermission(), true );
01190 }
01191 $archive = eZArchiveHandler::instance( 'tar', 'gzip', $archiveName );
01192 $archive->extractModify( $packagePath, '' );
01193
01194 $package = eZPackage::fetch( $packageName, $fullRepositoryPath, false, $dbAvailable );
01195 if ( !$package )
01196 {
01197 eZDebug::writeError( "Failed loading imported package $packageName from $fullRepositoryPath" );
01198 }
01199 }
01200 else
01201 {
01202 eZDebug::writeError( "Failed loading temporary package $packageName" );
01203 }
01204
01205 return $package;
01206 }
01207 }
01208
01209
01210
01211
01212
01213 function suffix()
01214 {
01215 return 'ezpkg';
01216 }
01217
01218 function exportName()
01219 {
01220 return $this->attribute( 'name' ) . '-' . $this->attribute( 'version-number' ) . '-' . $this->attribute( 'release-number' ) . '.' . eZPackage::suffix();
01221 }
01222
01223
01224
01225
01226 function storeToFile( $filename )
01227 {
01228 return $this->storeString( $filename, $this->toString() );
01229 }
01230
01231
01232
01233
01234
01235 function storeDOM( $filename, $dom )
01236 {
01237 $data = $dom->toString();
01238 $this->storeString( $filename, $data );
01239 }
01240
01241
01242
01243
01244
01245
01246
01247 function storeString( $filename, $data )
01248 {
01249 $file = @fopen( $filename, 'w' );
01250 if ( $file )
01251 {
01252 fwrite( $file, $data );
01253 fclose( $file );
01254
01255 $siteConfig =& eZINI::instance( 'site.ini' );
01256 $filePermissions = $siteConfig->variable( 'FileSettings', 'StorageFilePermissions');
01257 @chmod( $filename, octdec( $filePermissions ) );
01258
01259 eZDebugSetting::writeNotice( 'kernel-ezpackage-store',
01260 "Stored file $filename",
01261 'eZPackage::storeString' );
01262 return true;
01263 }
01264 else
01265 {
01266 eZDebug::writeError( "Failed to write package '$filename'" );
01267 }
01268 return false;
01269 }
01270
01271
01272
01273
01274
01275
01276
01277 function &fetchDOMFromFile( $filename )
01278 {
01279 if ( file_exists( $filename ) )
01280 {
01281 $fd = fopen( $filename, 'rb' );
01282 if ( $fd )
01283 {
01284 $xmlText = fread( $fd, filesize( $filename ) );
01285 fclose( $fd );
01286
01287 $xml = new eZXML();
01288 $dom =& $xml->domTree( $xmlText, array ( 'CharsetConversion' => true ) );
01289 return $dom;
01290 }
01291 }
01292 $retValue = false;
01293 return $retValue;
01294 }
01295
01296
01297
01298
01299
01300
01301
01302 function fetchFromFile( $filename )
01303 {
01304 if ( !file_exists( $filename ) )
01305 {
01306 $retValue = false;
01307 return $retValue;
01308 }
01309
01310 $fd = fopen( $filename, 'rb' );
01311 if ( $fd )
01312 {
01313 $xmlText = fread( $fd, filesize( $filename ) );
01314 fclose( $fd );
01315
01316 $xml = new eZXML();
01317 $dom =& $xml->domTree( $xmlText, array ( 'CharsetConversion' => true ) );
01318
01319 $package = new eZPackage();
01320 $parameters = $package->parseDOMTree( $dom );
01321 if ( !$parameters )
01322 {
01323 $retValue = false;
01324 return $retValue;
01325 }
01326
01327 /*
01328 This has been disabled due to a previous bug which caused most
01329 packages to be created as development packages (even in a stable
01330 release).
01331
01332 if ( $package and
01333 !EZ_PACKAGE_DEVELOPMENT )
01334 {
01335 $development = $package->attribute( 'development' );
01336 if ( $development )
01337 {
01338 include_once( 'lib/ezutils/classes/ezcli.php' );
01339 if ( eZCLI::hasInstance() )
01340 {
01341 $cli =& eZCLI::instance();
01342 $cli->warning( "Could not load package from file " . $cli->stylize( 'emphasize', $filename ) );
01343 }
01344 $retValue = false;
01345 return $retValue;
01346 }
01347 }
01348 */
01349
01350 $root =& $dom->root();
01351 if ( !$root )
01352 {
01353 $retValue = false;
01354 return $retValue;
01355 }
01356
01357 return $package;
01358 }
01359 }
01360
01361
01362
01363
01364
01365
01366
01367
01368
01369
01370
01371
01372 function fetch( $packageName, $packagePath = false, $repositoryID = false, $dbAvailable = true )
01373 {
01374 $packageRepositories = eZPackage::packageRepositories( array( 'path' => $packagePath ) );
01375
01376 if ( $repositoryID === true )
01377 $repositoryID = 'local';
01378
01379 foreach ( $packageRepositories as $packageRepository )
01380 {
01381 if ( $repositoryID !== false and
01382 $packageRepository['id'] != $repositoryID )
01383 continue;
01384 $path = $packageRepository['path'];
01385
01386 $path .= '/' . $packageName;
01387 $filePath = $path . '/' . eZPackage::definitionFilename();
01388
01389 if ( file_exists( $filePath ) )
01390 {
01391 $fileModification = filemtime( $filePath );
01392 $package = false;
01393 $cacheExpired = false;
01394
01395 if ( eZPackage::useCache() )
01396 {
01397 $package = eZPackage::fetchFromCache( $path, $fileModification, $cacheExpired );
01398 }
01399
01400 if ( $package )
01401 {
01402 $package->setCurrentRepositoryInformation( $packageRepository );
01403 }
01404 else
01405 {
01406 $package = eZPackage::fetchFromFile( $filePath );
01407
01408 if ( $package )
01409 {
01410 $package->setCurrentRepositoryInformation( $packageRepository );
01411 if ( $packagePath )
01412 $package->RepositoryPath = $packagePath;
01413 if ( $cacheExpired and
01414 eZPackage::useCache() )
01415 {
01416 $package->storeCache( $path . '/' . eZPackage::cacheDirectory() );
01417 }
01418 }
01419 }
01420 if ( $dbAvailable )
01421 $package->getInstallState();
01422
01423 return $package;
01424 }
01425 }
01426 return false;
01427 }
01428
01429 function useCache()
01430 {
01431 return EZ_PACKAGE_USE_CACHE;
01432 }
01433
01434
01435
01436
01437 function fetchFromCache( $packagePath, $packageModification, &$cacheExpired )
01438 {
01439 $packageCachePath = $packagePath . '/' . eZPackage::cacheDirectory() . '/package.php';
01440
01441 if ( file_exists( $packageCachePath ) )
01442 {
01443 $cacheModification = filemtime( $packageCachePath );
01444 if ( $cacheModification >= $packageModification )
01445 {
01446 include( $packageCachePath );
01447 if ( !isset( $CacheCodeDate ) or
01448 $CacheCodeDate != EZ_PACKAGE_CACHE_CODEDATE )
01449 {
01450 $cacheExpired = true;
01451 return false;
01452 }
01453 if ( isset( $Parameters ) and
01454 isset( $InstallData ) )
01455 {
01456 $cacheExpired = false;
01457 $package = new eZPackage( $Parameters, $RepositoryPath );
01458 $package->InstallData = $InstallData;
01459 return $package;
01460 }
01461 }
01462 else
01463 $cacheExpired = true;
01464 }
01465 $cacheExpired = true;
01466 return false;
01467 }
01468
01469 // function handleExportList( $exportList )
01470 // {
01471 // $handlers = array();
01472 // foreach ( $exportList as $exportItem )
01473 // {
01474 // $exportType = $exportItem['type'];
01475 // $exportParameters = $exportItem['parameters'];
01476 // $exportHandler = 'kernel/classes/packagehandlers/' . $exportType . '/' . $exportType . 'exporthandler.php';
01477 // if ( file_exists( $exportHandler ) )
01478 // {
01479 // include_once( $exportHandler );
01480 // $exportClass = $exportType . 'ExportHandler';
01481 // if ( isset( $handlers[$exportType] ) )
01482 // {
01483 // $handler =& $handlers[$exportType];
01484 // $handler->reset();
01485 // }
01486 // else
01487 // {
01488 // $handler =& new $exportClass;
01489 // $handlers[$exportType] =& $handler;
01490 // }
01491 // $handler->handle( $this, $exportParameters );
01492 // }
01493 // }
01494 // }
01495
01496
01497
01498
01499 function path()
01500 {
01501 // $path = eZPackage::repositoryPath();
01502 // $path = $this->RepositoryPath;
01503 $path = $this->currentRepositoryPath();
01504 $path .= '/' . $this->attribute( 'name' );
01505 return $path;
01506 }
01507
01508
01509
01510
01511 function currentRepositoryPath()
01512 {
01513 $repositoryInformation = $this->currentRepositoryInformation();
01514 if ( $repositoryInformation )
01515 return $repositoryInformation['path'];
01516 return $this->RepositoryPath;
01517 }
01518
01519
01520
01521
01522
01523 function temporaryExportPath()
01524 {
01525 $path = eZDir::path( array( eZSys::cacheDirectory(),
01526 'packages',
01527 'export' . eZUser::currentUserID() ) );
01528 return $path;
01529 }
01530
01531
01532
01533
01534
01535 function temporaryImportPath()
01536 {
01537 $path = eZDir::path( array( eZSys::cacheDirectory(),
01538 'packages',
01539 'import' ) );
01540 return $path;
01541 }
01542
01543
01544
01545
01546
01547 function repositoryPath()
01548 {
01549 $ini =& eZINI::instance();
01550 $packageIni =& eZINI::instance( 'package.ini' );
01551
01552 return eZDir::path( array( 'var',
01553 $ini->variable( 'FileSettings', 'StorageDir' ),
01554 $packageIni->variable( 'RepositorySettings', 'RepositoryDirectory' ) ) );
01555 }
01556
01557
01558
01559
01560
01561 function cacheDirectory()
01562 {
01563 return '.cache';
01564 }
01565
01566
01567
01568
01569
01570 function definitionFilename()
01571 {
01572 return 'package.xml';
01573 }
01574
01575
01576
01577
01578
01579 function documentDirectory()
01580 {
01581 return 'documents';
01582 }
01583
01584
01585
01586
01587
01588 function filesDirectory()
01589 {
01590 return 'files';
01591 }
01592
01593
01594
01595
01596
01597 function simpleFilesDirectory()
01598 {
01599 return 'simplefiles';
01600 }
01601
01602 function settingsDirectory()
01603 {
01604 return 'settings';
01605 }
01606
01607
01608
01609
01610
01611 function fetchDependentPackages( $dependencyType, &$failedList )
01612 {
01613 $packages = array();
01614 $provides = $this->Parameters['dependencies'][$dependencyType];
01615
01616 if ( $provides != null )
01617 {
01618 foreach ( $provides as $provide )
01619 {
01620 // fetch only dependent packages, not package items.
01621 if ( $provide['type'] == 'ezpackage' )
01622 {
01623 // TODO: Add fetching from URL (not here ?)
01624 $package = $this->fetch( $provide['name'] );
01625
01626 if ( !$package )
01627 {
01628 $failedList[] = $provide['name'];
01629 continue;
01630 }
01631 $packages[] =& $package;
01632 }
01633 }
01634 }
01635 return $packages;
01636 }
01637
01638
01639
01640
01641
01642
01643
01644
01645
01646
01647
01648 function packageRepositories( $parameters = array() )
01649 {
01650 if ( isset( $parameters['path'] ) and $parameters['path'] )
01651 {
01652 $path = $parameters['path'];
01653 $packageRepositories = array( array( 'path' => $path,
01654 'id' => 'local',
01655 'name' => ezi18n( 'kernel/package', 'Local' ),
01656 'type' => 'local' ) );
01657 }
01658 else
01659 {
01660 $repositoryPath = eZPackage::repositoryPath();
01661 $packageRepositories = array( array( 'path' => $repositoryPath . '/local',
01662 'id' => 'local',
01663 'name' => ezi18n( 'kernel/package', 'Local' ),
01664 'type' => 'local' ) );
01665
01666 $subdirs = eZDir::findSubitems( $repositoryPath, 'd' );
01667 foreach( $subdirs as $dir )
01668 {
01669 if ( $dir == 'local' )
01670 continue;
01671
01672 $packageRepositories[] = array( 'path' => $repositoryPath . '/' . $dir,
01673 'id' => $dir,
01674 'name' => $dir,
01675 'type' => 'global' );
01676 }
01677 }
01678 return $packageRepositories;
01679 }
01680
01681
01682
01683
01684
01685 function repositoryInformation( $repositoryID )
01686 {
01687 $packageRepositories = eZPackage::packageRepositories();
01688 foreach ( $packageRepositories as $packageRepository )
01689 {
01690 if ( $packageRepository['id'] == $repositoryID )
01691 return $packageRepository;
01692 }
01693 return false;
01694 }
01695
01696
01697
01698
01699
01700 function setCurrentRepositoryInformation( $information )
01701 {
01702 $this->RepositoryInformation = $information;
01703 }
01704
01705
01706
01707
01708
01709
01710
01711 function currentRepositoryInformation()
01712 {
01713 return $this->RepositoryInformation;
01714 }
01715
01716
01717
01718
01719
01720
01721
01722 function fetchPackages( $parameters = array(), $filterArray = array() )
01723 {
01724 $packageRepositories = eZPackage::packageRepositories( $parameters );
01725
01726 $packages = array();
01727
01728 $requiredType = null;
01729 $requiredPriority = null;
01730 $requiredVendor = null;
01731 $requiredExtension = null;
01732 if ( isset( $filterArray['type'] ) )
01733 $requiredType = $filterArray['type'];
01734 if ( isset( $filterArray['priority'] ) )
01735 $requiredPriority = $filterArray['priority'];
01736 if ( isset( $filterArray['vendor'] ) )
01737 $requiredVendor = $filterArray['vendor'];
01738 if ( isset( $filterArray['extension'] ) )
01739 $requiredExtension = $filterArray['extension'];
01740 $repositoryID = false;
01741 if ( isset( $parameters['repository_id'] ) )
01742 $repositoryID = $parameters['repository_id'];
01743 $dbAvailable = true;
01744 if ( isset( $parameters['db_available'] ) )
01745 $dbAvailable = $parameters['db_available'];
01746
01747 foreach ( $packageRepositories as $packageRepository )
01748 {
01749 if ( strlen( $repositoryID ) == 0 or
01750 $repositoryID == $packageRepository['id'] )
01751 {
01752 $path = $packageRepository['path'];
01753 if ( file_exists( $path ) )
01754 {
01755 $fileList = array();
01756 $dir = opendir( $path );
01757 while( ( $file = readdir( $dir ) ) !== false )
01758 {
01759 if ( $file == '.' or
01760 $file == '..' )
01761 continue;
01762 $fileList[] = $file;
01763 }
01764 closedir( $dir );
01765 sort( $fileList );
01766 foreach ( $fileList as $file )
01767 {
01768 $dirPath = $path . '/' . $file;
01769 if ( !is_dir( $dirPath ) )
01770 continue;
01771 $filePath = $dirPath . '/' . eZPackage::definitionFilename();
01772 if ( file_exists( $filePath ) )
01773 {
01774 $fileModification = filemtime( $filePath );
01775 $name = $file;
01776 $packageCachePath = $dirPath . '/' . eZPackage::cacheDirectory() . '/package.php';
01777 unset( $package );
01778 $package = false;
01779 $cacheExpired = false;
01780 if ( eZPackage::useCache() )
01781 {
01782 $package = eZPackage::fetchFromCache( $dirPath, $fileModification, $cacheExpired );
01783 }
01784 if ( !$package )
01785 {
01786 $package = eZPackage::fetchFromFile( $filePath );
01787 if ( $package and
01788 $cacheExpired and
01789 eZPackage::useCache() )
01790 {
01791 $package->storeCache( $dirPath . '/' . eZPackage::cacheDirectory() );
01792 }
01793 }
01794 if ( !$package )
01795 continue;
01796
01797 if ( $dbAvailable )
01798 $package->getInstallState();
01799
01800 if ( $requiredType !== null )
01801 {
01802 $type = $package->attribute( 'type' );
01803 if ( $type != $requiredType )
01804 continue;
01805 }
01806
01807 if ( $requiredPriority !== null )
01808 {
01809 $type = $package->attribute( 'priority' );
01810 if ( $priority != $requiredPriority )
01811 continue;
01812 }
01813
01814 if ( $requiredExtension !== null )
01815 {
01816 $type = $package->attribute( 'extension' );
01817 if ( $extension != $requiredExtension )
01818 continue;
01819 }
01820
01821 if ( $requiredVendor !== null )
01822 {
01823 $type = $package->attribute( 'vendor' );
01824 if ( $vendor != $requiredVendor )
01825 continue;
01826 }
01827
01828 $package->setCurrentRepositoryInformation( $packageRepository );
01829
01830 $packages[] =& $package;
01831 }
01832 }
01833 }
01834 }
01835 }
01836 return $packages;
01837 }
01838
01839
01840
01841
01842
01843
01844
01845 function installItem( $item, &$installParameters )
01846 {
01847 $type = $item['type'];
01848 $name = $item['name'];
01849 $os = $item['os'];
01850 $filename = $item['filename'];
01851 $subdirectory = $item['sub-directory'];
01852 $content = false;
01853 if ( isset( $item['content'] ) )
01854 $content = $item['content'];
01855 $handler =& $this->packageHandler( $type );
01856 $installResult = false;
01857 if ( $handler )
01858 {
01859 if ( $handler->extractInstallContent() )
01860 {
01861 if ( !$content and
01862 $filename )
01863 {
01864 if ( $subdirectory )
01865 $filepath = $subdirectory . '/' . $filename . '.xml';
01866 else
01867 $filepath = $filename . '.xml';
01868
01869 $filepath = $this->path() . '/' . $filepath;
01870
01871 $dom =& $this->fetchDOMFromFile( $filepath );
01872 if ( $dom )
01873 $content =& $dom->root();
01874 else
01875 eZDebug::writeError( "Failed fetching dom from file $filepath" );
01876 }
01877 }
01878 $installData =& $this->InstallData[$type];
01879 if ( !isset( $installData ) )
01880 $installData = array();
01881 $installResult = $handler->install( $this, $type, $item,
01882 $name, $os, $filename, $subdirectory,
01883 $content, $installParameters,
01884 $installData );
01885 }
01886 return $installResult;
01887 }
01888
01889
01890
01891
01892 function install( &$installParameters )
01893 {
01894 if ( $this->Parameters['install_type'] != 'install' )
01895 return;
01896 $installItems = $this->Parameters['install'];
01897 if ( !isset( $installParameters['path'] ) )
01898 $installParameters['path'] = false;
01899 $installResult = true;
01900 foreach ( $installItems as $item )
01901 {
01902 if ( !$this->installItem( $item, $installParameters ) )
01903 {
01904 $installResult = false;
01905 }
01906 }
01907 $this->setInstalled();
01908 return $installResult;
01909 }
01910
01911 function uninstallItem( $item, &$uninstallParameters )
01912 {
01913 $type = $item['type'];
01914 $name = $item['name'];
01915 $os = $item['os'];
01916 $filename = $item['filename'];
01917 $subdirectory = $item['sub-directory'];
01918 $content = false;
01919 if ( isset( $item['content'] ) )
01920 $content = $item['content'];
01921
01922 $handler =& $this->packageHandler( $type );
01923 if ( $handler )
01924 {
01925 if ( $handler->extractInstallContent() )
01926 {
01927 if ( !$content and
01928 $filename )
01929 {
01930 if ( $subdirectory )
01931 $filepath = $subdirectory . '/' . $filename . '.xml';
01932 else
01933 $filepath = $filename . '.xml';
01934
01935 $filepath = $this->path() . '/' . $filepath;
01936
01937 $dom =& $this->fetchDOMFromFile( $filepath );
01938 if ( $dom )
01939 $content =& $dom->root();
01940 else
01941 eZDebug::writeError( "2 Failed fetching dom from file $filepath" );
01942 }
01943 }
01944
01945 if ( isset( $this->InstallData[$type] ) )
01946 {
01947 $installData =& $this->InstallData[$type];
01948 }
01949 else
01950 {
01951 unset( $installData );
01952 $installData = array();
01953 }
01954 $uninstallResult = $handler->uninstall( $this, $type, $item,
01955 $name, $os, $filename, $subdirectory,
01956 $content, $uninstallParameters,
01957 $installData );
01958 }
01959 return $uninstallResult;
01960 }
01961
01962
01963
01964
01965 function uninstall( $uninstallParameters = array() )
01966 {
01967 if ( $this->Parameters['install_type'] != 'install' )
01968 return;
01969 if ( !$this->isInstalled() )
01970 return;
01971 $uninstallItems = $this->uninstallItemsList();
01972 if ( !isset( $installParameters['path'] ) )
01973 $installParameters['path'] = false;
01974
01975 $uninstallResult = true;
01976 foreach ( $uninstallItems as $item )
01977 {
01978 if ( !$this->uninstallItem( $item, $uninstallParameters ) )
01979 {
01980 $uninstallResult = false;
01981 }
01982 }
01983
01984 $this->InstallData = array();
01985 $this->setInstalled( false );
01986 return $uninstallResult;
01987 }
01988
01989
01990
01991
01992 function &parseDOMTree( &$dom )
01993 {
01994 $root =& $dom->root();
01995 if ( !$root )
01996 {
01997 $retValue = false;
01998 return $retValue;
01999 }
02000
02001 /*
02002 This has been disabled due to a previous bug which caused most
02003 packages to be created as development packages (even in a stable
02004 release).
02005
02006 if ( !EZ_PACKAGE_DEVELOPMENT )
02007 {
02008 // If it has a warning we don't read it in production mode
02009 if ( $root->elementByName( 'warning' ) )
02010 {
02011 eZDebug::writeError( "Package not accepted, it has been build with a warning." );
02012 $retValue = false;
02013 return $retValue;
02014 }
02015 }
02016 */
02017
02018 // Read basic info
02019 $parameters = array();
02020 $parameters['name'] = $root->elementTextContentByName( 'name' );
02021 $parameters['vendor'] = $root->elementTextContentByName( 'vendor' );
02022 $parameters['summary'] = $root->elementTextContentByName( 'summary' );
02023 $parameters['description'] = $root->elementTextContentByName( 'description' );
02024 $parameters['vendor'] = $root->elementTextContentByName( 'vendor' );
02025 $parameters['priority'] = $root->elementAttributeValueByName( 'priority', 'value' );
02026 $parameters['type'] = $root->elementAttributeValueByName( 'type', 'value' );
02027
02028 if ( $parameters['vendor'] )
02029 {
02030 // Creating nice vendor directory name
02031 include_once( 'lib/ezi18n/classes/ezchartransform.php' );
02032 $trans =& eZCharTransform::instance();
02033 $parameters['vendor-dir'] = $trans->transformByGroup( $parameters['vendor'], 'urlalias' );
02034 }
02035 else
02036 {
02037 $parameters['vendor-dir'] = 'local';
02038 }
02039
02040 /*$parameters['is_active'] = true;
02041 $isActive = $root->attributeValue( 'is_active' );
02042 if ( $isActive )
02043 $parameters['is_active'] = $isActive == 'true';
02044 */
02045
02046 $parameters['install_type'] = 'install';
02047 $installType = $root->attributeValue( 'install_type' );
02048 if ( $installType )
02049 $parameters['install_type'] = $installType;
02050 $parameters['source'] = $root->elementTextContentByName( 'source' );
02051 $parameters['development'] = $root->attributeValue( 'development' ) == 'true';
02052 $extensionNode =& $root->elementByName( 'extension' );
02053 if ( $extensionNode )
02054 $parameters['extension'] = $extensionNode->attributeValue( 'name' );
02055 $ezpublishNode =& $root->elementByName( 'ezpublish' );
02056 $parameters['ezpublish']['version'] = $ezpublishNode->elementTextContentByName( 'version' );
02057 $parameters['ezpublish']['named-version'] = $ezpublishNode->elementTextContentByName( 'named-version' );
02058 $this->setParameters( $parameters );
02059
02060 // Read maintainers
02061 $maintainerList = $root->elementChildrenByName( 'maintainers' );
02062 if ( is_array( $maintainerList ) )
02063 {
02064 foreach ( $maintainerList as $maintainerNode )
02065 {
02066 $maintainerName = $maintainerNode->elementTextContentByName( 'name' );
02067 $maintainerEmail = $maintainerNode->elementTextContentByName( 'email' );
02068 $maintainerRole = $maintainerNode->elementTextContentByName( 'role' );
02069 $this->appendMaintainer( $maintainerName, $maintainerEmail, $maintainerRole );
02070 }
02071 }
02072
02073 // Read packaging info
02074 $packagingNode =& $root->elementByName( 'packaging' );
02075 $packagingTimestamp = $packagingNode->elementTextContentByName( 'timestamp' );
02076 $packagingHost = $packagingNode->elementTextContentByName( 'host' );
02077 $packagingPackager = $packagingNode->elementTextContentByName( 'packager' );
02078 $this->setPackager( $packagingTimestamp, $packagingHost, $packagingPackager );
02079
02080 // Read documents
02081 $documentList = $root->elementChildrenByName( 'documents' );
02082 if ( is_array( $documentList ) )
02083 {
02084 foreach ( $documentList as $documentNode )
02085 {
02086 $documentName = $documentNode->attributeValue( 'name' );
02087 $documentMimeType = $documentNode->attributeValue( 'mime-type' );
02088 $documentOS = $documentNode->attributeValue( 'os' );
02089 $documentAudience = $documentNode->attributeValue( 'audience' );
02090 $this->appendDocument( $documentName, $documentMimeType,
02091 $documentOS, $documentAudience,
02092 false, false );
02093 }
02094 }
02095
02096 // Read changelog
02097 $changelogList = $root->elementChildrenByName( 'changelog' );
02098 if ( is_array( $changelogList ) )
02099 {
02100 foreach ( $changelogList as $changelogEntryNode )
02101 {
02102 $changelogTimestamp = $changelogEntryNode->attributeValue( 'timestamp' );
02103 $changelogPerson = $changelogEntryNode->attributeValue( 'person' );
02104 $changelogEmail = $changelogEntryNode->attributeValue( 'email' );
02105 $changelogRelease = $changelogEntryNode->attributeValue( 'release' );
02106 $changelogChangeList = $changelogEntryNode->elementsTextContentByName( 'change' );
02107 $this->appendChange( $changelogPerson, $changelogEmail, $changelogChangeList,
02108 $changelogRelease, $changelogTimestamp );
02109 }
02110 }
02111
02112 // Read simple files
02113 $this->Parameters['simple-file-list'] = array();
02114 $simpleFilesNode =& $root->elementByName( 'simple-files' );
02115 if ( $simpleFilesNode )
02116 {
02117 $child = $simpleFilesNode->firstChild();
02118 if ( $child->nodeName == 'simple-file' )
02119 {
02120 $simpleFiles = $simpleFilesNode->Children;
02121 foreach( $simpleFiles as $simpleFile )
02122 {
02123 $key = $simpleFile->getAttribute( 'key' );
02124 $originalPath = $simpleFile->getAttribute( 'original-path' );
02125 $packagePath = $simpleFile->getAttribute( 'package-path' );
02126 $this->Parameters['simple-file-list'][$key] = array( 'original-path' => $originalPath,
02127 'package-path' => $packagePath );
02128 }
02129 }
02130 else
02131 $this->Parameters['simple-file-list'] = eZDOMDocument::createArrayFromDOMNode( $simpleFilesNode );
02132 }
02133
02134 // Read files
02135 $filesList = $root->elementChildrenByName( 'files' );
02136 if ( $filesList )
02137 {
02138 foreach ( $filesList as $fileCollectionNode )
02139 {
02140 $fileCollectionName = $fileCollectionNode->attributeValue( 'name' );
02141 $fileLists = $fileCollectionNode->elementsByName( 'file-list' );
02142 foreach ( $fileLists as $fileListNode )
02143 {
02144 $fileType = $fileListNode->attributeValue( 'type' );
02145 $fileDesign = $fileListNode->attributeValue( 'design' );
02146 $fileRole = $fileListNode->attributeValue( 'role' );
02147 $fileVariableName = $fileListNode->attributeValue( 'variable-name' );
02148 $fileRoleValue = $fileListNode->attributeValue( 'role-value' );
02149 $files = $fileListNode->elementsByName( 'file' );
02150 if ( count( $files ) > 0 )
02151 {
02152 foreach ( $files as $fileNode )
02153 {
02154 $fileFileType = $fileNode->attributeValue( 'type' );
02155 $fileName = $fileNode->attributeValue( 'name' );
02156 if ( $fileNode->attributeValue( 'variable-name' ) )
02157 $fileVariableName = $fileNode->attributeValue( 'variable-name' );
02158 $fileSubDirectory = $fileNode->attributeValue( 'sub-directory' );
02159 $filePath = $fileNode->attributeValue( 'path' );
02160 $fileMD5 = $fileNode->attributeValue( 'md5sum' );
02161 $this->appendFile( $fileName, $fileType, $fileRole,
02162 $fileDesign, $filePath, $fileCollectionName,
02163 $fileSubDirectory, $fileMD5, false, null,
02164 $fileFileType,
02165 $fileRoleValue, $fileVariableName );
02166 }
02167 }
02168 else
02169 {
02170 $this->appendFile( false, $fileType, $fileRole,
02171 $fileDesign, false, $fileCollectionName,
02172 false, false, false, null );
02173 }
02174 unset( $files );
02175 }
02176 }
02177 }
02178 // Read release info
02179 $versionNode =& $root->elementByName( 'version' );
02180 $versionNumber = false;
02181 $versionRelease = false;
02182 if ( $versionNode )
02183 {
02184 $versionNumber = $versionNode->elementTextContentByName( 'number' );
02185 $versionRelease = $versionNode->elementTextContentByName( 'release' );
02186 }
02187 $licence = $root->elementTextContentByName( 'licence' );
02188 $state = $root->elementTextContentByName( 'state' );
02189 $this->setRelease( $versionNumber, $versionRelease, false,
02190 $licence, $state );
02191
02192 $dependenciesNode =& $root->elementByName( 'dependencies' );
02193 if ( $dependenciesNode )
02194 {
02195 $providesList = $dependenciesNode->elementChildrenByName( 'provides' );
02196 $requiresList = $dependenciesNode->elementChildrenByName( 'requires' );
02197 $obsoletesList = $dependenciesNode->elementChildrenByName( 'obsoletes' );
02198 $conflictsList = $dependenciesNode->elementChildrenByName( 'conflicts' );
02199 $this->parseDependencyTree( $providesList, 'provides' );
02200 $this->parseDependencyTree( $requiresList, 'requires' );
02201 $this->parseDependencyTree( $obsoletesList, 'obsoletes' );
02202 $this->parseDependencyTree( $conflictsList, 'conflicts' );
02203 }
02204
02205 $settingsNode =& $root->elementByName( 'settings' );
02206
02207 if ( $settingsNode )
02208 {
02209 $settingsFileNodes = $settingsNode->Children;
02210 $this->Parameters['settings-files'] = array();
02211
02212 foreach( $settingsFileNodes as $settingsFileNode )
02213 {
02214 $this->Parameters['settings-files'][] = $settingsFileNode->getAttribute( 'filename' );
02215 }
02216 }
02217
02218 $installList = $root->elementChildrenByName( 'install' );
02219 $uninstallList = $root->elementChildrenByName( 'uninstall' );
02220 $this->parseInstallTree( $installList, true );
02221 $this->parseInstallTree( $uninstallList, false );
02222
02223 $installDataList = $root->elementChildrenByName( 'install-data' );
02224 if ( $installDataList )
02225 {
02226 $this->InstallData = array();
02227 foreach( $installDataList as $installDataNode )
02228 {
02229 if ( is_object( $installDataNode ) &&
02230 $installDataNode->attributeValue( 'name' ) == 'data' )
02231 {
02232 $installDataType = $installDataNode->attributeValue( 'type' );
02233 $installDataElements = $installDataNode->children();
02234 $installData = array();
02235 foreach ( array_keys( $installDataElements ) as $installDataElementKey )
02236 {
02237 $installDataElement =& $installDataElements[$installDataElementKey];
02238 if ( $installDataElement->attribute( 'name' ) == 'element' )
02239 {
02240 $name = $installDataElement->attributeValue( 'name' );
02241 $value = $installDataElement->attributeValue( 'value' );
02242 $installData[$name] = $value;
02243 }
02244 else if ( $installDataElement->attribute( 'name' ) == 'array' )
02245 {
02246 $arrayName = $installDataElement->attributeValue( 'name' );
02247 $installDataElementArray = $installDataElement->children();
02248 $array = array();
02249 foreach ( $installDataElementArray as $installDataElementArrayElement )
02250 {
02251 $name = $installDataElementArrayElement->attributeValue( 'name' );
02252 $value = $installDataElementArrayElement->attributeValue( 'value' );
02253 $array[$name] = $value;
02254 }
02255 $installData[$arrayName] = $array;
02256 }
02257 }
02258 if ( count( $installData ) > 0 )
02259 $this->InstallData[$installDataType] = $installData;
02260 }
02261 }
02262 }
02263
02264 $retValue = true;
02265 return $retValue;
02266 }
02267
02268
02269
02270
02271 function parseDependencyTree( &$dependenciesList, $dependencySection )
02272 {
02273 foreach ( array_keys( $dependenciesList ) as $dependencyKey )
02274 {
02275 $dependencyNode =& $dependenciesList[$dependencyKey];
02276 $dependencyType = $dependencyNode->attributeValue( 'type' );
02277 $dependencyParameters = $dependencyNode->attributeValues();
02278
02279 $additionalDependencyParameters = array();
02280 $handler =& $this->packageHandler( $dependencyType );
02281 if ( $handler )
02282 {
02283 $handler->parseDependencyNode( $this, $dependencyNode, $additionalDependencyParameters, $dependencySection );
02284 }
02285
02286 if ( count( $additionalDependencyParameters ) > 0 )
02287 $dependencyParameters = array_merge( $dependencyParameters, $additionalDependencyParameters );
02288
02289 $this->appendDependency( $dependencySection, $dependencyParameters );
02290 }
02291 }
02292
02293
02294
02295
02296 function parseInstallTree( $installList, $isInstall )
02297 {
02298 foreach( $installList as $installNode )
02299 {
02300 $installType = $installNode->attributeValue( 'type' );
02301 $installName = $installNode->attributeValue( 'name' );
02302 $installFilename = $installNode->attributeValue( 'filename' );
02303 $installSubdirectory = $installNode->attributeValue( 'sub-directory' );
02304 $installOS = $installNode->attributeValue( 'os' );
02305
02306 $handler =& $this->packageHandler( $installType );
02307 $installParameters = array();
02308 if ( $handler )
02309 {
02310 $handler->parseInstallNode( $this, $installNode, $installParameters, $isInstall );
02311 }
02312 if ( count( $installParameters ) == 0 )
02313 $installParameters = false;
02314
02315 $this->appendInstall( $installType, $installName, $installOS, $isInstall,
02316 $installFilename, $installSubdirectory,
02317 $installParameters );
02318 }
02319 }
02320
02321
02322
02323
02324 function &domStructure()
02325 {
02326 $exportFormat = false;
02327
02328 $dom = new eZDOMDocument();
02329 $root = $dom->createElementNode( 'package', array( 'version' => EZ_PACKAGE_VERSION,
02330 'development' => ( EZ_PACKAGE_DEVELOPMENT ? 'true' : 'false' ) ) );
02331 //$domUrlAttributeNode = $dom->createAttributeNode( 'ezpackage', 'http://ez.no/ezpackage', 'xmlns' );
02332 //$root->appendAttribute( $domUrlAttributeNode );
02333 $dom->setRoot( $root );
02334
02335 if ( EZ_PACKAGE_DEVELOPMENT )
02336 $root->appendChild( $dom->createElementTextNode( 'warning',
02337 "This format was made with a development version and will not work with any release versions.\n" .
02338 "The format of this file is also subject to change until the release version.\n" .
02339 "Upgrades to the development format will not be supported." ) );
02340
02341 $name = $this->attribute( 'name' );
02342 $nameAttributes = array();
02343 $summary = $this->attribute( 'summary' );
02344 $summaryAttributes = array();
02345 $description = $this->attribute( 'description' );
02346 $descriptionAttributes = array();
02347 $priority = $this->attribute( 'priority' );
02348 $priorityAttributes = array( 'value' => $priority );
02349 $type = $this->attribute( 'type' );
02350 $typeAttributes = array( 'value' => $type );
02351 $extension = $this->attribute( 'extension' );
02352 $extensionAttributes = array( 'name' => $extension );
02353 $installType = $this->attribute( 'install_type' );
02354 $vendorName = $this->attribute( 'vendor' );
02355 $source = $this->attribute( 'source' );
02356 $sourceAttributes = array();
02357
02358 // $ezpublish = $this->attribute( 'ezpublish' );
02359 $ezpublishVersion = $this->attribute( 'ezpublish-version' );
02360 $ezpublishNamedVersion = $this->attribute( 'ezpublish-named-version' );
02361
02362 $packagingTimestamp = $this->attribute( 'packaging-timestamp' );
02363 $packagingHost = $this->attribute( 'packaging-host' );
02364 $packagingPackager = $this->attribute( 'packaging-packager' );
02365
02366 $maintainers = $this->attribute( 'maintainers' );
02367 // $packaging = $this->attribute( 'packaging' );
02368 $documents = $this->attribute( 'documents' );
02369 $groups = $this->attribute( 'groups' );
02370
02371 // $release = $this->attribute( 'release' );
02372 $versionNumber = $this->attribute( 'version-number' );
02373 $releaseNumber = $this->attribute( 'release-number' );
02374 $releaseTimestamp = $this->attribute( 'release-timestamp' );
02375
02376 $licence = $this->attribute( 'licence' );
02377 $state = $this->attribute( 'state' );
02378
02379 $simpleFileList = $this->attribute( 'simple-file-list' );
02380 $fileList = $this->attribute( 'file-list' );
02381 $dependencies = $this->attribute( 'dependencies' );
02382 $install = $this->attribute( 'install' );
02383 $uninstall = $this->attribute( 'uninstall' );
02384 $changelog = $this->attribute( 'changelog' );
02385
02386 $rootNameTextNode = $dom->createElementTextNode( 'name', $name, $nameAttributes );
02387 $root->appendChild( $rootNameTextNode );
02388 if ( $summary )
02389 {
02390 $rootSummaryTextNode = $dom->createElementTextNode( 'summary', $summary, $summaryAttributes );
02391 $root->appendChild( $rootSummaryTextNode );
02392 }
02393
02394 if ( $description )
02395 {
02396 $rootDescriptionTextNode = $dom->createElementTextNode( 'description', $description, $descriptionAttributes );
02397 $root->appendChild( $rootDescriptionTextNode );
02398 }
02399
02400 if ( $vendorName )
02401 {
02402 $rootVendorTextNode = $dom->createElementTextNode( 'vendor', $vendorName );
02403 $root->appendChild( $rootVendorTextNode );
02404 }
02405
02406 if ( $priority )
02407 {
02408 $rootPriorityTextNode = $dom->createElementNode( 'priority', $priorityAttributes );
02409 $root->appendChild( $rootPriorityTextNode );
02410 }
02411
02412 if ( $type )
02413 {
02414 $rootTypeTextNode = $dom->createElementNode( 'type', $typeAttributes );
02415 $root->appendChild( $rootTypeTextNode );
02416 }
02417
02418 if ( $extension )
02419 {
02420 $rootExtensionTextNode = $dom->createElementNode( 'extension', $extensionAttributes );
02421 $root->appendChild( $rootExtensionTextNode );
02422 }
02423
02424 if ( $source )
02425 {
02426 $rootSourceTextNode = $dom->createElementTextNode( 'source', $source, $sourceAttributes );
02427 $root->appendChild( $rootSourceTextNode );
02428 }
02429
02430 $rootInstallTypeAttributeNode = $dom->createAttributeNode( 'install_type', $installType );
02431 $root->appendAttribute( $rootInstallTypeAttributeNode );
02432
02433 $ezpublishNode = $dom->createElementNode( 'ezpublish' );
02434 //$ezpublishLinkAttributeNode = $dom->createAttributeNode( 'ezpublish', 'http://ez.no/ezpublish', 'xmlns' );
02435 //$ezpublishNode->appendAttribute( $ezpublishLinkAttributeNode );
02436
02437 $ezpublishVersionTextNode = $dom->createElementTextNode( 'version', $ezpublishVersion );
02438 $ezpublishNode->appendChild( $ezpublishVersionTextNode );
02439
02440 $ezpublishNamedVersionTextNode = $dom->createElementTextNode( 'named-version', $ezpublishNamedVersion );
02441 $ezpublishNode->appendChild( $ezpublishNamedVersionTextNode );
02442
02443 $root->appendChild( $ezpublishNode );
02444
02445 if ( count( $maintainers ) > 0 )
02446 {
02447 $maintainersNode = $dom->createElementNode( 'maintainers' );
02448 foreach ( $maintainers as $maintainer )
02449 {
02450 unset( $maintainerNode );
02451 $maintainerNode = $dom->createElementNode( 'maintainer' );
02452
02453 unset( $maintainerName );
02454 $maintainerName = $dom->createElementTextNode( 'name', $maintainer['name'] );
02455 $maintainerNode->appendChild( $maintainerName );
02456
02457 unset( $maintainerEmail );
02458 $maintainerEmail = $dom->createElementTextNode( 'email', $maintainer['email'] );
02459 $maintainerNode->appendChild( $maintainerEmail );
02460 if ( $maintainer['role'] )
02461 {
02462 unset( $maintainerRole );
02463 $maintainerRole = $dom->createElementTextNode( 'role', $maintainer['role'] );
02464 $maintainerNode->appendChild( $maintainerRole );
02465 }
02466
02467 $maintainersNode->appendChild( $maintainerNode );
02468 }
02469 $root->appendChild( $maintainersNode );
02470 }
02471
02472 $packagingNode = $dom->createElementNode( 'packaging' );
02473
02474 $packagingTimestamp = $dom->createElementTextNode( 'timestamp', $packagingTimestamp );
02475 $packagingNode->appendChild( $packagingTimestamp );
02476
02477 $packagingHost = $dom->createElementTextNode( 'host', $packagingHost );
02478 $packagingNode->appendChild( $packagingHost );
02479 if ( $packagingPackager )
02480 {
02481 $packagingPackager = $dom->createElementTextNode( 'packager', $packagingPackager );
02482 $packagingNode->appendChild( $packagingPackager );
02483 }
02484
02485 $root->appendChild( $packagingNode );
02486
02487 // $root->appendChild( $dom->createElementNode( 'signature' ) );
02488
02489 if ( count( $documents ) > 0 )
02490 {
02491 $documentsNode = $dom->createElementNode( 'documents' );
02492 foreach ( $documents as $document )
02493 {
02494 unset( $documentNode );
02495 $documentNode = $dom->createElementNode( 'document',
02496 array( 'mime-type' => $document['mime-type'],
02497 'name' => $document['name'] ) );
02498 if ( $document['os'] )
02499 {
02500 unset( $documentOS );
02501 $documentOS = $dom->createAttributeNode( 'os', $document['os'] );
02502 $documentNode->appendAttribute( $documentOS );
02503 }
02504
02505 if ( $document['audience'] )
02506 {
02507 unset( $documentAudience );
02508 $documentAudience = $dom->createAttributeNode( 'audience', $document['audience'] );
02509 $documentNode->appendAttribute( );
02510 }
02511 $documentsNode->appendChild( $documentNode );
02512 }
02513 $root->appendChild( $documentsNode );
02514 }
02515
02516 if ( count( $groups ) > 0 )
02517 {
02518 $groupsNode = $dom->createElementNode( 'groups' );
02519 foreach ( $groups as $group )
02520 {
02521 $groupAttributes = array( 'name' => $group['name'] );
02522 unset( $groupNode );
02523 $groupNode = $dom->createElementNode( 'group', $groupAttributes );
02524 $groupsNode->appendChild( $groupNode );
02525 }
02526 $root->appendChild( $groupsNode );
02527 }
02528
02529 if ( count( $changelog ) > 0 )
02530 {
02531 $changelogNode = $dom->createElementNode( 'changelog' );
02532 foreach ( $changelog as $changeEntry )
02533 {
02534 unset( $changeEntryNode );
02535 $changeEntryNode = $dom->createElementNode( 'entry' );
02536
02537 unset( $changeEntryTimestamp );
02538 $changeEntryTimestamp = $dom->createAttributeNode( 'timestamp', $changeEntry['timestamp'] );
02539 $changeEntryNode->appendAttribute( $changeEntryTimestamp );
02540
02541 unset( $changeEntryPerson );
02542 $changeEntryPerson = $dom->createAttributeNode( 'person', $changeEntry['person'] );
02543 $changeEntryNode->appendAttribute( $changeEntryPerson );
02544
02545 unset( $changeEntryEmail );
02546 $changeEntryEmail = $dom->createAttributeNode( 'email', $changeEntry['email'] );
02547 $changeEntryNode->appendAttribute( $changeEntryEmail );
02548
02549 unset( $changeEntryRelease );
02550 $changeEntryRelease = $dom->createAttributeNode( 'release', $changeEntry['release'] );
02551 $changeEntryNode->appendAttribute( $changeEntryRelease );
02552
02553 foreach ( $changeEntry['changes'] as $change )
02554 {
02555 unset( $changeEntryChange );
02556 $changeEntryChange = $dom->createElementTextNode( 'change', $change );
02557 $changeEntryNode->appendChild( $changeEntryChange );
02558 }
02559 $changelogNode->appendChild( $changeEntryNode );
02560 }
02561 $root->appendChild( $changelogNode );
02562 }
02563
02564 // Handle simple files
02565 /* foreach( $simpleFileList as $key => $fileInfo )
02566 {
02567 if ( $export )
02568 {
02569 $sourcePath = $this->path() . '/' . $fileInfo['package-path'];
02570 $destinationPath = $exportPath . '/' . $fileInfo['package-path'];
02571 eZDir::mkdir( eZDir::dirpath( $destinationPath ), false, true );
02572 eZFileHandler::copy( $sourcePath, $destinationPath );
02573 }
02574 else if ( $simpleFileList[$key]['package-path'] == '' )
02575 {
02576 $suffix = eZFile::suffix( $fileInfo['original-path'] );
02577 $sourcePath = $fileInfo['original-path'];
02578 $fileInfo['package-path'] = eZPackage::simpleFilesDirectory() . '/' . substr( md5( mt_rand() ), 0, 8 ) . '.' . $suffix;
02579 $destinationPath = $this->path() . '/' . $fileInfo['package-path'];
02580 eZDir::mkdir( eZDir::dirpath( $destinationPath ), false, true );
02581 eZFileHandler::copy( $sourcePath, $destinationPath );
02582 $this->Parameters['simple-file-list'][$key] = $fileInfo;
02583 }
02584 }
02585 */
02586 // Avoid a PHP warning if 'simple-file-list' is not an array
02587 if ( is_array( $this->Parameters['simple-file-list'] ) )
02588 {
02589 // Old format commented out
02590 // May be used for back-compatiblity.
02591 //$rootSimpleFiles = $dom->createElementNodeFromArray( 'simple-files', $this->Parameters['simple-file-list'] );
02592
02593 $rootSimpleFiles =& $dom->createElement( 'simple-files' );
02594 foreach( $this->Parameters['simple-file-list'] as $key => $value )
02595 {
02596 $simpleFileNode =& $dom->createElement( 'simple-file' );
02597 $simpleFileNode->setAttribute( 'key', $key );
02598 $simpleFileNode->setAttribute( 'original-path', $value['original-path'] );
02599 $simpleFileNode->setAttribute( 'package-path', $value['package-path'] );
02600 $rootSimpleFiles->appendChild( $simpleFileNode );
02601 unset( $simpleFileNode );
02602 }
02603 $root->appendChild( $rootSimpleFiles );
02604 }
02605 else
02606 {
02607 $rootSimpleFiles = $dom->createElementNodeFromArray( 'simple-files', array() );
02608 $root->appendChild( $rootSimpleFiles );
02609 }
02610
02611 // Handle files
02612 $filesNode = $dom->createElementNode( 'files' );
02613 //$filesUrl = $dom->createAttributeNode( 'ezfile', 'http://ez.no/ezpackage', 'xmlns' );
02614 //$filesNode->appendAttribute( $filesUrl );
02615 $hasFileItems = false;
02616 foreach ( $fileList as $fileCollectionName => $fileCollection )
02617 {
02618 if ( count( $fileCollection ) > 0 )
02619 {
02620 $hasFileItems = true;
02621 $collectionAttributes = array();
02622 if ( $fileCollectionName )
02623 $collectionAttributes['name'] = $fileCollectionName;
02624 unset( $fileCollectionNode );
02625 $fileCollectionNode = $dom->createElementNode( 'collection',
02626 $collectionAttributes );
02627 unset( $fileLists );
02628 unset( $fileDesignLists );
02629 unset( $fileThumbnailLists );
02630 $fileList = array();
02631 $fileDesignList = array();
02632 $fileINIList = array();
02633 $fileThumbnailList = array();
02634 $fileListNode = null;
02635 foreach ( $fileCollection as $fileItem )
02636 {
02637 if ( $fileItem['type'] == 'design' )
02638 $fileListNode =& $fileDesignLists[$fileItem['design']][$fileItem['role']][$fileItem['role-value']][$fileItem['variable-name']];
02639 else if ( $fileItem['type'] == 'ini' )
02640 $fileListNode =& $fileINILists[$fileItem['role']][$fileItem['role-value']][$fileItem['variable-name']];
02641 else if ( $fileItem['type'] == 'thumbnail' )
02642 $fileListNode =& $fileThumbnailLists[$fileItem['role']];
02643 else
02644 $fileListNode =& $fileLists[$fileItem['type']][$fileItem['role']][$fileItem['role-value']][$fileItem['variable-name']];
02645
02646 if ( !$fileListNode ||
02647 $fileListNode->attributeValue( 'type' ) != $fileItem['type'] ||
02648 $fileListNode->attributeValue( 'role' ) != $fileItem['role'] ||
02649 $fileListNode->attributeValue( 'role-value' ) != $fileItem['role-value'] ||
02650 $fileListNode->attributeValue( 'variable-name' ) != $fileItem['variable-name'] )
02651 {
02652 $fileListAttributes = array( 'type' => $fileItem['type'] );
02653 if ( $fileItem['type'] == 'design' )
02654 $fileListAttributes['design'] = $fileItem['design'];
02655 if ( $fileItem['role'] )
02656 $fileListAttributes['role'] = $fileItem['role'];
02657 if ( $fileItem['role-value'] )
02658 $fileListAttributes['role-value'] = $fileItem['role-value'];
02659 if ( $fileItem['variable-name'] )
02660 $fileListAttributes['variable-name'] = $fileItem['variable-name'];
02661 unset( $fileListNode );
02662 $fileListNode = $dom->createElementNode( 'file-list',
02663 $fileListAttributes );
02664
02665 $fileCollectionNode->appendChild( $fileListNode );
02666 }
02667 $fileAttributes = array( 'name' => $fileItem['name'] );
02668 if ( $fileItem['subdirectory'] )
02669 $fileAttributes['sub-directory'] = $fileItem['subdirectory'];
02670 if ( !$exportFormat )
02671 $fileAttributes['path'] = $fileItem['path'];
02672 if ( $fileItem['md5'] )
02673 $fileAttributes['md5sum'] = $fileItem['md5'];
02674 if ( $fileItem['name'] )
02675 {
02676 unset( $fileListFile );
02677 $fileListFile = $dom->createElementNode( 'file', $fileAttributes );
02678 $fileListNode->appendChild( $fileListFile );
02679 }
02680 //$copyFile = $fileItem['copy-file'];
02681 /*if ( $export )
02682 {
02683 $typeDir = $fileItem['type'];
02684 if ( $fileItem['type'] == 'design' )
02685 $typeDir .= '.' . $fileItem['design'];
02686 if ( $fileItem['role'] )
02687 {
02688 $typeDir .= '.' . $fileItem['role'];
02689 if ( $fileItem['role-value'] )
02690 $typeDir .= '-' . $fileItem['role-value'];
02691 }
02692 $path = $this->path() . '/' . eZPackage::filesDirectory() . '/' . $fileCollectionName . '/' . $typeDir;
02693 $destinationPath = $exportPath . '/' . eZPackage::filesDirectory() . '/' . $fileCollectionName . '/' . $typeDir;
02694 if ( $fileItem['subdirectory'] )
02695 {
02696 $path .= '/' . $fileItem['subdirectory'];
02697 $destinationPath .= '/' . $fileItem['subdirectory'];
02698 }
02699 if ( $fileItem['name'] )
02700 $path .= '/' . $fileItem['name'];
02701 if ( !file_exists( $destinationPath ) )
02702 eZDir::mkdir( $destinationPath, eZDir::directoryPermission(), true );
02703
02704 if ( is_dir( $path ) )
02705 {
02706 $copiedFiles = eZDir::copy( $path, $destinationPath,
02707 $fileItem['name'] != false, true, false, eZDir::temporaryFileRegexp() );
02708
02709 foreach ( $copiedFiles as $copiedFile )
02710 {
02711 $copiedFileName = $copiedFile;
02712 $copiedSubdirectory = false;
02713 if ( preg_match( '#^(.+)/([^/]+)$#', $copiedFile, $matches ) )
02714 {
02715 $copiedSubdirectory = $matches[1];
02716 $copiedFileName = $matches[2];
02717 }
02718 $copiedFileAttributes = array( 'name' => $copiedFileName );
02719 if ( $copiedSubdirectory and $fileItem['name'] )
02720 $copiedSubdirectory = $fileItem['name'] . '/' . $copiedSubdirectory;
02721 else if ( $fileItem['name'] )
02722 $copiedSubdirectory = $fileItem['name'];
02723 if ( is_dir( $destinationPath . '/' . $copiedFile ) )
02724 {
02725 $copiedFileAttributes = array_merge( $copiedFileAttributes,
02726 array( 'type' => 'dir' ) );
02727 }
02728
02729 if ( $fileItem['subdirectory'] and $copiedSubdirectory )
02730 $copiedSubdirectory = $fileItem['subdirectory'] . '/' . $copiedSubdirectory;
02731 else if ( $fileItem['subdirectory'] )
02732 $copiedSubdirectory = $fileItem['subdirectory'];
02733 $copiedMD5Sum = $this->md5sum( $destinationPath . '/' . $copiedFile );
02734 if ( $copiedMD5Sum )
02735 $copiedFileAttributes['md5sum'] = $copiedMD5Sum;
02736 if ( $copiedSubdirectory )
02737 $copiedFileAttributes['sub-directory'] = $copiedSubdirectory;
02738
02739 unset( $fileListCopiedFile );
02740 $fileListCopiedFile = $dom->createElementNode( 'file', $copiedFileAttributes );
02741 $fileListNode->appendChild( $fileListCopiedFile );
02742 }
02743 }
02744 else
02745 {
02746 eZFileHandler::copy( $path, $destinationPath . '/' . $fileItem['name'] );
02747 }
02748 }
02749 else if ( $copyFile )
02750 {
02751 $typeDir = $fileItem['type'];
02752 if ( $fileItem['type'] == 'design' )
02753 $typeDir .= '.' . $fileItem['design'];
02754 if ( $fileItem['role'] )
02755 {
02756 $typeDir .= '.' . $fileItem['role'];
02757 if ( $fileItem['role-value'] )
02758 $typeDir .= '-' . $fileItem['role-value'];
02759 }
02760 $path = $this->path() . '/' . eZPackage::filesDirectory() . '/' . $fileCollectionName . '/' . $typeDir;
02761 if ( $fileItem['subdirectory'] )
02762 $path .= '/' . $fileItem['subdirectory'];
02763 if ( !file_exists( $path ) )
02764 eZDir::mkdir( $path, eZDir::directoryPermission(), true );
02765
02766 if ( is_dir( $fileItem['path'] ) )
02767 {
02768 eZDir::copy( $fileItem['path'], $path,
02769 $fileItem['name'] != false, true, false, eZDir::temporaryFileRegexp() );
02770 }
02771 else
02772 {
02773 eZFileHandler::copy( $fileItem['path'], $path . '/' . $fileItem['name'] );
02774 }
02775 } */
02776 }
02777 $filesNode->appendChild( $fileCollectionNode );
02778 }
02779 }
02780 if ( $hasFileItems )
02781 $root->appendChild( $filesNode );
02782
02783 $versionNode = $dom->createElementNode( 'version' );
02784 //$versionUrlAttributeNode = $dom->createAttributeNode( 'ezversion', 'http://ez.no/ezpackage', 'xmlns' );
02785 //$versionNode->appendAttribute( $versionUrlAttributeNode );
02786 $numberAttributes = array();
02787 $versionNumberTextNode = $dom->createElementTextNode( 'number', $versionNumber, $numberAttributes );
02788 $versionNode->appendChild( $versionNumberTextNode );
02789 $releaseAttributes = array();
02790 $versionReleaseNumberTextNode = $dom->createElementTextNode( 'release', $releaseNumber, $releaseAttributes );
02791 $versionNode->appendChild( $versionReleaseNumberTextNode );
02792 $root->appendChild( $versionNode );
02793 if ( $releaseTimestamp )
02794 {
02795 $timestampAttributes = array();
02796 $rootTimestampTextNode = $dom->createElementTextNode( 'timestamp', $releaseTimestamp, $timestampAttributes );
02797 $root->appendChild( $rootTimestampTextNode );
02798 }
02799 $licenceAttributes = array();
02800 if ( $licence )
02801 {
02802 $rootLicenceTextNode = $dom->createElementTextNode( 'licence', $licence, $licenceAttributes );
02803 $root->appendChild( $rootLicenceTextNode );
02804 }
02805
02806 $stateAttributes = array();
02807 if ( $state )
02808 {
02809 $rootStateTextNode = $dom->createElementTextNode( 'state', $state, $stateAttributes );
02810 $root->appendChild( $rootStateTextNode );
02811 }
02812
02813 $dependencyNode = $dom->createElementNode( 'dependencies' );
02814 //$dependencyLinkNode = $dom->createAttributeNode( 'ezdependency', 'http://ez.no/ezpackage', 'xmlns' );
02815 //$dependencyNode->appendAttribute( $dependencyLinkNode );
02816
02817 $providesNode = $dom->createElementNode( 'provides' );
02818 $dependencyNode->appendChild( $providesNode );
02819 $requiresNode = $dom->createElementNode( 'requires' );
02820 $dependencyNode->appendChild( $requiresNode );
02821 $obsoletesNode = $dom->createElementNode( 'obsoletes' );
02822 $dependencyNode->appendChild( $obsoletesNode );
02823 $conflictsNode = $dom->createElementNode( 'conflicts' );
02824 $dependencyNode->appendChild( $conflictsNode );
02825
02826 $this->createDependencyTree( $providesNode, 'provide', $dependencies['provides'] );
02827 $this->createDependencyTree( $requiresNode, 'require', $dependencies['requires'] );
02828 $this->createDependencyTree( $obsoletesNode, 'obsolete', $dependencies['obsoletes'] );
02829 $this->createDependencyTree( $conflictsNode, 'conflict', $dependencies['conflicts'] );
02830
02831 $root->appendChild( $dependencyNode );
02832
02833 $installNode = $dom->createElementNode( 'install' );
02834
02835 $uninstallNode = $dom->createElementNode( 'uninstall' );
02836
02837 $this->createInstallTree( $installNode, $dom, $install, 'install' );
02838 $this->createInstallTree( $uninstallNode, $dom, $uninstall, 'uninstall' );
02839
02840 $root->appendChild( $installNode );
02841 $root->appendChild( $uninstallNode );
02842
02843 if ( count( $this->InstallData ) > 0 )
02844 {
02845 $installDataNode = $dom->createElementNode( 'install-data' );
02846 foreach ( $this->InstallData as $installDataType => $installData )
02847 {
02848 if ( count( $installData ) > 0 )
02849 {
02850 unset( $dataNode );
02851 $dataNode = $dom->createElementNode( 'data', array( 'type' => $installDataType ) );
02852 $installDataNode->appendChild( $dataNode );
02853 foreach ( $installData as $installDataName => $installDataValue )
02854 {
02855 if ( is_array( $installDataValue ) )
02856 {
02857 unset( $dataArrayNode );
02858 $dataArrayNode = $dom->createElementNode( 'array', array( 'name' => $installDataName ) );
02859 $dataNode->appendChild( $dataArrayNode );
02860 foreach ( $installDataValue as $installDataValueName => $installDataValueValue )
02861 {
02862 unset( $dataArrayElement );
02863 $dataArrayElement = $dom->createElementNode( 'element', array( 'name' => $installDataValueName,
02864 'value' => $installDataValueValue ) );
02865 $dataArrayNode->appendChild( $dataArrayElement );
02866 }
02867 }
02868 else
02869 {
02870 unset( $dataArrayElement );
02871 $dataArrayElement = $dom->createElementNode( 'element', array( 'name' => $installDataName,
02872 'value' => $installDataValue ) );
02873 $dataNode->appendChild( $dataArrayElement );
02874 }
02875 }
02876 }
02877 }
02878 $root->appendChild( $installDataNode );
02879 }
02880
02881 return $dom;
02882 }
02883
02884
02885
02886
02887
02888
02889
02890 function createInstallTree( &$installNode, &$dom, $list, $installType )
02891 {
02892 foreach ( $list as $installItem )
02893 {
02894 $type = $installItem['type'];
02895 // if ( ( isset( $installItem['content'] ) and
02896 // $installItem['content'] ) or
02897 // $installItem['filename'] )
02898 {
02899 unset( $installItemNode );
02900 $installItemNode = $dom->createElementNode( 'item',
02901 array( 'type' => $type ) );
02902 $installNode->appendChild( $installItemNode );
02903 $content = false;
02904 if ( isset( $installItem['content'] ) )
02905 $content = $installItem['content'];
02906 if ( $installItem['os'] )
02907 {
02908 unset( $installItemOS );
02909 $installItemOS = $dom->createAttributeNode( 'os', $installItem['os'] );
02910 $installItemNode->appendAttribute( $installItemOS );
02911 }
02912
02913 if ( $installItem['name'] )
02914 {
02915 unset( $installItemName );
02916 $installItemName = $dom->createAttributeNode( 'name', $installItem['name'] );
02917 $installItemNode->appendAttribute( $installItemName );
02918 }
02919
02920 if ( $installItem['filename'] )
02921 {
02922 unset( $installItemFilename );
02923 $installItemFilename = $dom->createAttributeNode( 'filename', $installItem['filename'] );
02924 $installItemNode->appendAttribute( $installItemFilename );
02925 if ( $installItem['sub-directory'] )
02926 {
02927 unset( $installItemSubDirectory );
02928 $installItemSubDirectory = $dom->createAttributeNode( 'sub-directory', $installItem['sub-directory'] );
02929 $installItemNode->appendAttribute( $installItemSubDirectory );
02930 }
02931 }
02932 else
02933 {
02934 $installItemNode->appendChild( $content );
02935 }
02936
02937 $handler =& $this->packageHandler( $type );
02938 if ( $handler )
02939 {
02940 $handler->createInstallNode( $this, $installItemNode, $installItem, $installType );
02941 }
02942 }
02943 }
02944 }
02945
02946
02947
02948
02949
02950
02951 function createDependencyTree( &$dependenciesNode, $dependencyType, $list )
02952 {
02953 foreach ( $list as $dependencyItem )
02954 {
02955 unset( $dependencyNode );
02956 $dependencyNode = eZDOMDocument::createElementNode( $dependencyType );
02957 $dependencyNode->appendAttribute( eZDOMDocument::createAttributeNode( 'type', $dependencyItem['type'] ) );
02958 $dependencyNode->appendAttribute( eZDOMDocument::createAttributeNode( 'name', $dependencyItem['name'] ) );
02959 if ( $dependencyItem['value'] )
02960 $dependencyNode->appendAttribute( eZDOMDocument::createAttributeNode( 'value', $dependencyItem['value'] ) );
02961 $dependenciesNode->appendChild( $dependencyNode );
02962 $handler =& $this->packageHandler( $dependencyItem['name'] );
02963 if ( $handler )
02964 {
02965 $handler->createDependencyNode( $this, $dependencyNode, $dependencyItem, $dependencyType );
02966 }
02967 }
02968 }
02969
02970
02971
02972
02973 function &packageHandler( $handlerName )
02974 {
02975 $handlers =& $GLOBALS['eZPackageHandlers'];
02976 if ( !isset( $handlers ) )
02977 $handlers = array();
02978 $handler = false;
02979 if ( eZExtension::findExtensionType( array( 'ini-name' => 'package.ini',
02980 'repository-group' => 'PackageSettings',
02981 'repository-variable' => 'RepositoryDirectories',
02982 'extension-group' => 'PackageSettings',
02983 'extension-variable' => 'ExtensionDirectories',
02984 'subdir' => 'packagehandlers',
02985 'extension-subdir' => 'packagehandlers',
02986 'suffix-name' => 'packagehandler.php',
02987 'type-directory' => true,
02988 'type' => $handlerName,
02989 'alias-group' => 'PackageSettings',
02990 'alias-variable' => 'HandlerAlias' ),
02991 $result ) )
02992 {
02993 $handlerFile = $result['found-file-path'];
02994 if ( file_exists( $handlerFile ) )
02995 {
02996 include_once( $handlerFile );
02997 $handlerClassName = $result['type'] . 'PackageHandler';
02998 if ( isset( $handlers[$result['type']] ) )
02999 {
03000 $handler =& $handlers[$result['type']];
03001 $handler->reset();
03002 }
03003 else
03004 {
03005 $handler =& new $handlerClassName;
03006 $handlers[$result['type']] =& $handler;
03007 }
03008 }
03009 }
03010 return $handler;
03011 }
03012
03013
03014
03015
03016
03017
03018
03019 function appendSimpleFile( $key, $filepath )
03020 {
03021 if ( !isset( $this->Parameters['simple-file-list'] ) )
03022 {
03023 $this->Parameters['simple-file-list'] = array();
03024 }
03025
03026 $suffix = eZFile::suffix( $filepath );
03027 //$sourcePath = $fileInfo['original-path'];
03028 $packagePath = eZPackage::simpleFilesDirectory() . '/' . substr( md5( mt_rand() ), 0, 8 ) . '.' . $suffix;
03029 $destinationPath = $this->path() . '/' . $packagePath;
03030 eZDir::mkdir( eZDir::dirpath( $destinationPath ), false, true );
03031
03032 //SP DBfile
03033 require_once( 'kernel/classes/ezclusterfilehandler.php' );
03034 $fileHandler = eZClusterFileHandler::instance();
03035 $fileHandler->fileFetch( $filepath );
03036
03037 eZFileHandler::copy( $filepath, $destinationPath );
03038
03039 $this->Parameters['simple-file-list'][$key] = array( 'original-path' => $filepath,
03040 'package-path' => $packagePath );
03041 }
03042
03043
03044
03045
03046
03047
03048
03049
03050 function simpleFilePath( $fileKey )
03051 {
03052 if ( !isset( $this->Parameters['simple-file-list'] ) )
03053 {
03054 return false;
03055 }
03056 if ( !isset( $this->Parameters['simple-file-list'][$fileKey] ) )
03057 {
03058 return false;
03059 }
03060
03061 return $this->path() . '/' . $this->Parameters['simple-file-list'][$fileKey]['package-path'];
03062 }
03063
03064
03065
03066
03067
03068
03069
03070
03071
03072 function getVersion()
03073 {
03074 return $this->Parameters['version-number'] . '-' . $this->Parameters['release-number'];
03075 }
03076
03077
03078
03079
03080
03081 function setInstalled( $installed = true )
03082 {
03083 if ( $this->Parameters['install_type'] != 'install' )
03084 return;
03085
03086 $name = $this->Parameters['name'];
03087 $version = $this->getVersion();
03088 $db =& eZDB::instance();
03089 if ( $installed )
03090 {
03091 if ( !$this->getInstallState() )
03092 {
03093 $timestamp = mktime();
03094 $db->query( "INSERT INTO ezpackage ( name, version, install_date ) VALUES ( '$name', '$version', '$timestamp' )" );
03095 $this->isInstalled = true;
03096 }
03097 }
03098 else
03099 {
03100 $db->query( "DELETE FROM ezpackage WHERE name='$name' AND version='$version'" );
03101 $this->isInstalled = false;
03102 }
03103 }
03104
03105 function isInstalled()
03106 {
03107 return $this->isInstalled;
03108 }
03109
03110 function getInstallState()
03111 {
03112 // TODO installation date
03113
03114 if ( $this->Parameters['install_type'] != 'install' )
03115 return;
03116
03117 $name = $this->Parameters['name'];
03118 $version = $this->getVersion();
03119
03120 $db =& eZDB::instance();
03121 $result = $db->arrayQuery( "SELECT count(*) AS count FROM ezpackage WHERE name='$name' AND version='$version'" );
03122
03123 if ( !count( $result ) )
03124 return false;
03125 $installed = $result[0]['count'] == '0' ? false : true;
03126 $this->isInstalled = $installed;
03127 return $installed;
03128 }
03129
03130 var $isInstalled = false;
03131
03132
03133 var $Parameters;
03134
03135 }
03136
03137 ?>