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 include_once( 'kernel/classes/ezpackage.php' );
00042 include_once( 'lib/ezutils/classes/ezextension.php' );
00043
00044 class eZPackageCreationHandler
00045 {
00046
00047
00048
00049 function eZPackageCreationHandler( $id, $name, $steps )
00050 {
00051 $this->Attributes = array( 'id' => $id,
00052 'name' => $name,
00053 'steps' => $steps,
00054 'step_map' => false,
00055 'current_steps' => $steps );
00056 $this->InitializeStepMethodMap = array();
00057 $this->ValidateStepMethodMap = array();
00058 $this->CommitStepMethodMap = array();
00059 $this->LoadStepMethodMap = array();
00060 }
00061
00062
00063
00064
00065
00066
00067
00068
00069 function generateStepMap( &$package, &$persistentData )
00070 {
00071 $steps = $this->attribute( 'steps' );
00072 $map = array();
00073 $lastStep = false;
00074 $currentSteps = array();
00075 for ( $i = 0; $i < count( $steps ); ++$i )
00076 {
00077 $step =& $steps[$i];
00078 if ( !isset( $step['previous_step'] ) )
00079 {
00080 if ( $lastStep )
00081 $step['previous_step'] = $lastStep['id'];
00082 else
00083 $step['previous_step'] = false;
00084 }
00085 if ( !isset( $step['next_step'] ) )
00086 {
00087 if ( $i + 1 < count( $steps ) )
00088 $step['next_step'] = $steps[$i+1]['id'];
00089 else
00090 $step['next_step'] = false;
00091 }
00092 if ( isset( $step['methods']['initialize'] ) )
00093 $this->InitializeStepMethodMap[$step['id']] = $step['methods']['initialize'];
00094 if( isset( $step['methods']['load'] ) )
00095 $this->LoadStepMethodMap[$step['id']] = $step['methods']['load'];
00096 if ( isset( $step['methods']['validate'] ) )
00097 $this->ValidateStepMethodMap[$step['id']] = $step['methods']['validate'];
00098 if ( isset( $step['methods']['commit'] ) )
00099 $this->CommitStepMethodMap[$step['id']] = $step['methods']['commit'];
00100 $isStepIncluded = true;
00101 if ( isset( $step['methods']['check'] ) )
00102 {
00103 $checkMethod = $step['methods']['check'];
00104 $isStepIncluded = $this->$checkMethod( $package, $persistentData );
00105 }
00106 if ( $isStepIncluded )
00107 {
00108 $map[$step['id']] =& $step;
00109 $lastStep =& $step;
00110 $currentSteps[] =& $step;
00111 }
00112 }
00113 $this->StepMap = array( 'first' => &$steps[0],
00114 'map' => &$map,
00115 'steps' => &$steps );
00116 $this->Attributes['step_map'] =& $this->StepMap;
00117 $this->Attributes['current_steps'] = $currentSteps;
00118 }
00119
00120 function attributes()
00121 {
00122 return array_keys( $this->Attributes );
00123 }
00124
00125 function hasAttribute( $name )
00126 {
00127 return array_key_exists( $name, $this->Attributes );
00128 }
00129
00130 function &attribute( $name )
00131 {
00132 if ( array_key_exists( $name, $this->Attributes ) )
00133 return $this->Attributes[$name];
00134 else
00135 {
00136 eZDebug::writeError( "Attribute '$name' does not exist", 'eZPackageCreationHandler::attribute' );
00137 $retValue = null;
00138 return $retValue;
00139 }
00140 }
00141
00142 function initializeStepMethodMap()
00143 {
00144 return $this->InitializeStepMethodMap;
00145 }
00146
00147 function loadStepMethodMap()
00148 {
00149 return $this->LoadStepMethodMap;
00150 }
00151
00152 function validateStepMethodMap()
00153 {
00154 return $this->ValidateStepMethodMap;
00155 }
00156
00157 function commitStepMethodMap()
00158 {
00159 return $this->CommitStepMethodMap;
00160 }
00161
00162
00163
00164
00165
00166 function &stepMap()
00167 {
00168 return $this->StepMap;
00169 }
00170
00171
00172
00173
00174 function stepTemplate( $step )
00175 {
00176 $stepTemplateName = $step['template'];
00177 if ( isset( $step['use_standard_template'] ) and
00178 $step['use_standard_template'] )
00179 $stepTemplateDir = "create";
00180 else
00181 $stepTemplateDir = "creators/" . $this->attribute( 'id' );
00182 return array( 'name' => $stepTemplateName,
00183 'dir' => $stepTemplateDir );
00184 }
00185
00186
00187
00188
00189
00190
00191
00192 function initializeStep( &$package, &$http, $step, &$persistentData, &$tpl )
00193 {
00194 $methodMap = $this->initializeStepMethodMap();
00195 if ( count( $methodMap ) > 0 )
00196 {
00197 if ( isset( $methodMap[$step['id']] ) )
00198 {
00199 $method = $methodMap[$step['id']];
00200 return $this->$method( $package, $http, $step, $persistentData, $tpl );
00201 }
00202 }
00203 }
00204
00205
00206
00207
00208
00209 function loadStep( &$package, &$http, $currentStepID, &$persistentData, &$tpl, &$module )
00210 {
00211 $methodMap = $this->loadStepMethodMap();
00212 if ( count( $methodMap ) > 0 )
00213 {
00214 if ( isset( $methodMap[$currentStepID] ) )
00215 {
00216 $method = $methodMap[$currentStepID];
00217 return $this->$method( $package, $http, $currentStepID, $persistentData, $tpl, $module );
00218 }
00219 }
00220 }
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230 function validateStep( &$package, &$http, $currentStepID, &$stepMap, &$persistentData, &$errorList )
00231 {
00232 $nextStep = $this->validateAndAdvanceStep( $package, $http, $currentStepID, $stepMap, $persistentData, $errorList );
00233 if ( $nextStep === true )
00234 {
00235 if ( !isset( $stepMap['map'][$currentStepID] ) )
00236 {
00237 $nextStep = $stepMap['first']['id'];
00238 }
00239 else
00240 {
00241 $currentStep =& $stepMap['map'][$currentStepID];
00242 $nextStep = $currentStep['next_step'];
00243 }
00244 }
00245 else if ( $nextStep === false )
00246 $nextStep = $currentStepID;
00247 return $nextStep;
00248 }
00249
00250
00251
00252
00253 function validateAndAdvanceStep( &$package, &$http, $currentStepID, &$stepMap, &$persistentData, &$errorList )
00254 {
00255 $methodMap = $this->validateStepMethodMap();
00256 if ( count( $methodMap ) > 0 )
00257 {
00258 if ( isset( $methodMap[$currentStepID] ) )
00259 {
00260 $method = $methodMap[$currentStepID];
00261 return $this->$method( $package, $http, $currentStepID, $stepMap, $persistentData, $errorList );
00262 }
00263 }
00264 return true;
00265 }
00266
00267
00268
00269
00270
00271
00272 function commitStep( &$package, &$http, $step, &$persistentData, &$tpl )
00273 {
00274 $methodMap = $this->commitStepMethodMap();
00275 if ( count( $methodMap ) > 0 )
00276 {
00277 if ( isset( $methodMap[$step['id']] ) )
00278 {
00279 $method = $methodMap[$step['id']];
00280 return $this->$method( $package, $http, $step, $persistentData, $tpl );
00281 }
00282 }
00283 }
00284
00285
00286
00287
00288
00289
00290
00291 function finalize( &$package, &$http, &$persistentData )
00292 {
00293 }
00294
00295
00296
00297
00298
00299 function creatorLimitationList()
00300 {
00301 $creators =& eZPackageCreationHandler::creatorList();
00302 $list = array();
00303 foreach ( $creators as $creator )
00304 {
00305 $list[] = array( 'name' => $creator->attribute( 'name' ),
00306 'id' => $creator->attribute( 'id' ) );
00307 }
00308 return $list;
00309 }
00310
00311
00312
00313
00314
00315 function &creatorList( $checkRoles = false )
00316 {
00317 $allowedCreators = false;
00318
00319 include_once( "kernel/classes/datatypes/ezuser/ezuser.php" );
00320 $currentUser =& eZUser::currentUser();
00321 $accessResult = $currentUser->hasAccessTo( 'package', 'create' );
00322 $limitationList = array();
00323 $canCreate = false;
00324 if ( $accessResult['accessWord'] == 'no' )
00325 {
00326 $creators = array();
00327 return $creators;
00328 }
00329
00330 if ( $accessResult['accessWord'] == 'limited' )
00331 {
00332 $limitationList =& $accessResult['policies'];
00333 foreach( $limitationList as $dummyKey => $limitationArray )
00334 {
00335 foreach ( $limitationArray as $key => $limitation )
00336 {
00337 if ( $key == 'CreatorType' )
00338 {
00339 if ( !is_array( $allowedCreators ) )
00340 $allowedCreators = array();
00341 $list = $limitation;
00342 $allowedCreators = array_merge( $allowedCreators, $list );
00343 }
00344 }
00345 }
00346 }
00347
00348 $creators =& $GLOBALS['eZPackageCreatorList'];
00349 if ( !isset( $creators ) )
00350 {
00351 $creators = array();
00352 $ini =& eZINI::instance( 'package.ini' );
00353 $list = $ini->variable( 'CreationSettings', 'HandlerList' );
00354 foreach ( $list as $name )
00355 {
00356 if ( is_array( $allowedCreators ) and
00357 !in_array( $name, $allowedCreators ) )
00358 continue;
00359 $handler =& eZPackageCreationHandler::instance( $name );
00360 $creators[] =& $handler;
00361 }
00362 }
00363 return $creators;
00364 }
00365
00366
00367
00368
00369 function &instance( $handlerName )
00370 {
00371 $handlers =& $GLOBALS['eZPackageCreationHandlers'];
00372 if ( !isset( $handlers ) )
00373 $handlers = array();
00374 $handler = false;
00375 if ( eZExtension::findExtensionType( array( 'ini-name' => 'package.ini',
00376 'repository-group' => 'PackageSettings',
00377 'repository-variable' => 'RepositoryDirectories',
00378 'extension-group' => 'PackageSettings',
00379 'extension-variable' => 'ExtensionDirectories',
00380 'subdir' => 'packagecreators',
00381 'extension-subdir' => 'packagecreators',
00382 'suffix-name' => 'packagecreator.php',
00383 'type-directory' => true,
00384 'type' => $handlerName,
00385 'alias-group' => 'CreationSettings',
00386 'alias-variable' => 'HandlerAlias' ),
00387 $result ) )
00388 {
00389 $handlerFile = $result['found-file-path'];
00390 if ( file_exists( $handlerFile ) )
00391 {
00392 include_once( $handlerFile );
00393 $handlerClassName = $result['type'] . 'PackageCreator';
00394 if ( isset( $handlers[$result['type']] ) )
00395 {
00396 $handler =& $handlers[$result['type']];
00397 $handler->reset();
00398 }
00399 else
00400 {
00401 $handler =& new $handlerClassName( $handlerName );
00402 $handlers[$result['type']] =& $handler;
00403 }
00404 }
00405 }
00406 return $handler;
00407 }
00408
00409
00410
00411
00412
00413 function packageInformationStep()
00414 {
00415 return array( 'id' => 'packageinfo',
00416 'name' => ezi18n( 'kernel/package', 'Package information' ),
00417 'methods' => array( 'initialize' => 'initializePackageInformation',
00418 'validate' => 'validatePackageInformation',
00419 'commit' => 'commitPackageInformation' ),
00420 'use_standard_template' => true,
00421 'template' => 'info.tpl' );
00422 }
00423
00424
00425
00426
00427
00428 function packageMaintainerStep()
00429 {
00430 return array( 'id' => 'packagemaintainer',
00431 'name' => ezi18n( 'kernel/package', 'Package maintainer' ),
00432 'methods' => array( 'initialize' => 'initializePackageMaintainer',
00433 'validate' => 'validatePackageMaintainer',
00434 'commit' => 'commitPackageMaintainer',
00435 'check' => 'checkPackageMaintainer' ),
00436 'use_standard_template' => true,
00437 'template' => 'maintainer.tpl' );
00438 }
00439
00440
00441
00442
00443
00444 function packageChangelogStep()
00445 {
00446 return array( 'id' => 'packagechangelog',
00447 'name' => ezi18n( 'kernel/package', 'Package changelog' ),
00448 'methods' => array( 'initialize' => 'initializePackageChangelog',
00449 'validate' => 'validatePackageChangelog',
00450 'commit' => 'commitPackageChangelog' ),
00451 'use_standard_template' => true,
00452 'template' => 'changelog.tpl' );
00453 }
00454
00455
00456
00457
00458
00459 function packageThumbnailStep()
00460 {
00461 return array( 'id' => 'packagethumbnail',
00462 'name' => ezi18n( 'kernel/package', 'Package thumbnail' ),
00463 'methods' => array( 'initialize' => 'initializePackageThumbnail',
00464 'validate' => 'validatePackageThumbnail',
00465 'commit' => 'commitPackageThumbnail' ),
00466 'use_standard_template' => true,
00467 'template' => 'thumbnail.tpl' );
00468 }
00469
00470
00471
00472
00473
00474
00475
00476
00477 function packageInstallType( &$package, &$persistentData )
00478 {
00479 return 'install';
00480 }
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490 function packageInitialState( &$package, &$persistentData )
00491 {
00492 return 'alpha';
00493 }
00494
00495
00496
00497
00498
00499
00500
00501
00502 function initialChangelogEntry( &$package, &$http, $step, &$persistentData, &$tpl )
00503 {
00504 return '- Creation of package.';
00505 }
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516 function packageType( &$package, &$persistentData )
00517 {
00518 if ( get_class( $package ) == 'ezpackage' )
00519 {
00520 return $package->attribute( 'type' );
00521 }
00522 return false;
00523 }
00524
00525
00526
00527
00528
00529
00530
00531
00532 function createPackage( &$package, &$http, &$persistentData, &$cleanupFiles, $storePackage = true )
00533 {
00534 $createdPackage = false;
00535 if ( get_class( $package ) != 'ezpackage' )
00536 {
00537 $package = eZPackage::create( $persistentData['name'],
00538 array( 'summary' => $persistentData['summary'] ) );
00539 $createdPackage = true;
00540 }
00541 else
00542 $package->setAttribute( 'summary', $persistentData['summary'] );
00543
00544 $package->setAttribute( 'is_active', false );
00545 $package->setAttribute( 'type', $this->packageType( $package, $persistentData ) );
00546
00547 $package->setRelease( $persistentData['version'], '1', false,
00548 $persistentData['licence'], $this->packageInitialState( $package, $persistentData ) );
00549
00550 $package->setAttribute( 'description', $persistentData['description'] );
00551 $package->setAttribute( 'install_type', $this->packageInstallType( $package, $persistentData ) );
00552
00553 $package->setAttribute( 'packaging-host', $persistentData['host'] );
00554 $package->setAttribute( 'packaging-packager', $persistentData['packager'] );
00555
00556 $changelogPerson = $persistentData['changelog_person'];
00557 $changelogEmail = $persistentData['changelog_email'];
00558 $changelogEntries = $persistentData['changelog_entries'];
00559
00560 $maintainerPerson = $persistentData['maintainer_person'];
00561 $maintainerEmail = $persistentData['maintainer_email'];
00562 $maintainerRole = $persistentData['maintainer_role'];
00563
00564 if ( $maintainerPerson )
00565 {
00566 $package->appendMaintainer( $maintainerPerson, $maintainerEmail, $maintainerRole );
00567 }
00568
00569 if ( $changelogPerson )
00570 {
00571 $package->appendChange( $changelogPerson, $changelogEmail, $changelogEntries );
00572 }
00573
00574 if ( $persistentData['licence'] == 'GPL' )
00575 {
00576 eZPackageCreationHandler::appendLicence( $package );
00577 }
00578
00579
00580 $collections = array();
00581 $cleanupFiles = array();
00582
00583 if ( isset( $persistentData['thumbnail'] ) and
00584 $persistentData['thumbnail'] )
00585 {
00586 $thumbnail = $persistentData['thumbnail'];
00587 $fileItem = array( 'file' => $thumbnail['filename'],
00588 'type' => 'thumbnail',
00589 'role' => false,
00590 'design' => false,
00591 'path' => $thumbnail['url'],
00592 'collection' => 'default',
00593 'file-type' => false,
00594 'role-value' => false,
00595 'variable-name' => 'thumbnail' );
00596
00597 $package->appendFile( $fileItem['file'], $fileItem['type'], $fileItem['role'],
00598 $fileItem['design'], $fileItem['path'], $fileItem['collection'],
00599 null, null, true, null,
00600 $fileItem['file-type'], $fileItem['role-value'], $fileItem['variable-name'] );
00601 $cleanupFiles[] = $fileItem['path'];
00602
00603 if ( !in_array( $fileItem['collection'], $collections ) )
00604 $collections[] = $fileItem['collection'];
00605 }
00606
00607 foreach ( $collections as $collection )
00608 {
00609 $installItems = $package->installItemsList( 'ezfile', false, $collection, true );
00610 if ( count( $installItems ) == 0 )
00611 $package->appendInstall( 'ezfile', false, false, true,
00612 false, false,
00613 array( 'collection' => $collection ) );
00614 $dependencyItems = $package->dependencyItems( 'provides',
00615 array( 'type' => 'ezfile',
00616 'name' => 'collection',
00617 'valiue' => $collection ) );
00618 if ( count( $dependencyItems ) == 0 )
00619 $package->appendDependency( 'provides',
00620 array( 'type' => 'ezfile',
00621 'name' => 'collection',
00622 'value' => $collection ) );
00623 $installItems = $package->installItemsList( 'ezfile', false, $collection, false );
00624 if ( count( $installItems ) == 0 )
00625 $package->appendInstall( 'ezfile', false, false, false,
00626 false, false,
00627 array( 'collection' => $collection ) );
00628 }
00629
00630 $package->setAttribute( 'is_active', true );
00631 if ( $storePackage )
00632 $package->store();
00633
00634 return $createdPackage;
00635 }
00636
00637
00638
00639
00640
00641
00642
00643 function generatePackageInformation( &$packageInformation, &$package, &$http, $step, &$persistentData )
00644 {
00645 }
00646
00647
00648
00649
00650
00651 function initializePackageInformation( &$package, &$http, $step, &$persistentData, &$tpl )
00652 {
00653 $persistentData['name'] = false;
00654 $persistentData['summary'] = false;
00655 $persistentData['description'] = false;
00656 $persistentData['licence'] = 'GPL';
00657 $persistentData['version'] = '1.0';
00658 if ( isset( $_SERVER['HOSTNAME'] ) )
00659 $host = $_SERVER['HOSTNAME'];
00660 else
00661 $host = $_SERVER['HTTP_HOST'];
00662 $persistentData['host'] = $host;
00663 $user =& eZUser::currentUser();
00664 $userObject =& $user->attribute( 'contentobject' );
00665 $packager = false;
00666 if ( $userObject )
00667 $packager = $userObject->attribute( 'name' );
00668 $persistentData['packager'] = $packager;
00669 $this->generatePackageInformation( $persistentData, $package, $http, $step, $persistentData );
00670
00671
00672 include_once( 'lib/ezi18n/classes/ezchartransform.php' );
00673 $trans =& eZCharTransform::instance();
00674 $persistentData['name'] = $trans->transformByGroup( $persistentData['name'], 'urlalias' );
00675 }
00676
00677
00678
00679
00680
00681
00682 function validatePackageInformation( &$package, &$http, $currentStepID, &$stepMap, &$persistentData, &$errorList )
00683 {
00684 $packageName = false;
00685 $packageSummary = false;
00686 $packageVersion = false;
00687 $packageDescription = false;
00688 $packageLicence = 'GPL';
00689 $packageHost = false;
00690 $packagePackager = false;
00691 if ( $http->hasPostVariable( 'PackageName' ) )
00692 {
00693 $packageName = trim( $http->postVariable( 'PackageName' ) );
00694 }
00695 if ( $http->hasPostVariable( 'PackageSummary' ) )
00696 $packageSummary = $http->postVariable( 'PackageSummary' );
00697 if ( $http->hasPostVariable( 'PackageDescription' ) )
00698 $packageDescription = $http->postVariable( 'PackageDescription' );
00699 if ( $http->hasPostVariable( 'PackageVersion' ) )
00700 $packageVersion = trim( $http->postVariable( 'PackageVersion' ) );
00701 if ( $http->hasPostVariable( 'PackageLicence' ) )
00702 $packageLicence = $http->postVariable( 'PackageLicence' );
00703 if ( $http->hasPostVariable( 'PackageHost' ) )
00704 $packageHost = $http->postVariable( 'PackageHost' );
00705 if ( $http->hasPostVariable( 'PackagePackager' ) )
00706 $packagePackager = $http->postVariable( 'PackagePackager' );
00707
00708 $persistentData['name'] = $packageName;
00709 $persistentData['summary'] = $packageSummary;
00710 $persistentData['description'] = $packageDescription;
00711 $persistentData['version'] = $packageVersion;
00712 $persistentData['licence'] = $packageLicence;
00713 $persistentData['host'] = $packageHost;
00714 $persistentData['packager'] = $packagePackager;
00715
00716 $result = true;
00717 if ( $packageName == '' )
00718 {
00719 $errorList[] = array( 'field' => ezi18n( 'kernel/package', 'Package name' ),
00720 'description' => ezi18n( 'kernel/package', 'Package name is missing' ) );
00721 $result = false;
00722 }
00723 else
00724 {
00725 $existingPackage = eZPackage::fetch( $packageName, false, true );
00726 if ( $existingPackage )
00727 {
00728 $errorList[] = array( 'field' => ezi18n( 'kernel/package', 'Package name' ),
00729 'description' => ezi18n( 'kernel/package', 'A package named %packagename already exists, please give another name', false, array( '%packagename' => $packageName ) ) );
00730 $result = false;
00731 }
00732 else
00733 {
00734
00735 include_once( 'lib/ezi18n/classes/ezchartransform.php' );
00736 $trans =& eZCharTransform::instance();
00737 $validPackageName = $trans->transformByGroup( $packageName, 'urlalias' );
00738 if ( strcmp( $validPackageName, $packageName ) != 0 )
00739 {
00740 $errorList[] = array( 'field' => ezi18n( 'kernel/package', 'Package name' ),
00741 'description' => ezi18n( 'kernel/package', "The package name %packagename is not valid, it can only contain characters in the range a-z, 0-9 and underscore.", false, array( '%packagename' => $packageName ) ) );
00742 $result = false;
00743 }
00744 }
00745 }
00746 if ( !$packageSummary )
00747 {
00748 $errorList[] = array( 'field' => ezi18n( 'kernel/package', 'Summary' ),
00749 'description' => ezi18n( 'kernel/package', 'Summary is missing' ) );
00750 $result = false;
00751 }
00752 if ( !preg_match( "#^[0-9](\.[0-9]([a-zA-Z]+[0-9]*)?)*$#", $packageVersion ) )
00753 {
00754 $errorList[] = array( 'field' => ezi18n( 'kernel/package', 'Version' ),
00755 'description' => ezi18n( 'kernel/package', 'The version must only contain numbers (optionally followed by text) and must be delimited by dots (.), e.g. 1.0, 3.4.0beta1' ) );
00756 $result = false;
00757 }
00758 return $result;
00759 }
00760
00761
00762
00763
00764 function commitPackageInformation( &$package, &$http, $step, &$persistentData, &$tpl )
00765 {
00766 }
00767
00768
00769
00770
00771
00772 function initializePackageChangelog( &$package, &$http, $step, &$persistentData, &$tpl )
00773 {
00774 $user =& eZUser::currentUser();
00775 $userObject =& $user->attribute( 'contentobject' );
00776 if ( $userObject )
00777 $changelogPerson = $userObject->attribute( 'name' );
00778 $changelogEmail = $user->attribute( 'email' );
00779 $changelogText = '';
00780
00781 $persistentData['changelog_person'] = $changelogPerson;
00782 $persistentData['changelog_email'] = $changelogEmail;
00783 if ( get_class( $package ) != 'ezpackage' )
00784 {
00785 $changelogText = $this->initialChangelogEntry( $package, $http, $step, $persistentData, $tpl );
00786 }
00787 $persistentData['changelog_text'] = $changelogText;
00788 $persistentData['changelog_entries'] = array();
00789 }
00790
00791
00792
00793
00794
00795 function validatePackageChangelog( &$package, &$http, $currentStepID, &$stepMap, &$persistentData, &$errorList )
00796 {
00797 $changelogPerson = false;
00798 $changelogEmail = false;
00799 $changelogText = false;
00800 if ( $http->hasPostVariable( 'PackageChangelogPerson' ) )
00801 $changelogPerson = trim( $http->postVariable( 'PackageChangelogPerson' ) );
00802 if ( $http->hasPostVariable( 'PackageChangelogEmail' ) )
00803 $changelogEmail = $http->postVariable( 'PackageChangelogEmail' );
00804 if ( $http->hasPostVariable( 'PackageChangelogText' ) )
00805 $changelogText = $http->postVariable( 'PackageChangelogText' );
00806
00807 $persistentData['changelog_person'] = $changelogPerson;
00808 $persistentData['changelog_email'] = $changelogEmail;
00809 $persistentData['changelog_text'] = $changelogText;
00810
00811 $result = true;
00812 if ( trim( $changelogPerson ) == '' )
00813 {
00814 $errorList[] = array( 'field' => ezi18n( 'kernel/package', 'Name' ),
00815 'description' => ezi18n( 'kernel/package', 'You must enter a name for the changelog' ) );
00816 $result = false;
00817 }
00818 if ( trim( $changelogEmail ) == '' )
00819 {
00820 $errorList[] = array( 'field' => ezi18n( 'kernel/package', 'E-Mail' ),
00821 'description' => ezi18n( 'kernel/package', 'You must enter an e-mail for the changelog' ) );
00822 $result = false;
00823 }
00824 if ( trim( $changelogText ) == '' )
00825 {
00826 $errorList[] = array( 'field' => ezi18n( 'kernel/package', 'Changelog' ),
00827 'description' => ezi18n( 'kernel/package', 'You must supply some text for the changelog entry' ) );
00828 $result = false;
00829 }
00830 return $result;
00831 }
00832
00833
00834
00835
00836 function commitPackageChangelog( &$package, &$http, $step, &$persistentData, &$tpl )
00837 {
00838 $changelogEntries = array();
00839 $changelogText = $persistentData['changelog_text'];
00840 $lines = preg_split( "#\r\n|\n|\r#", $changelogText );
00841 $currentEntries = false;
00842 foreach ( $lines as $line )
00843 {
00844 if ( strlen( $line ) > 0 and
00845 ( $line[0] == '-' or $line[0] == '*' ) )
00846 {
00847 if ( $currentEntries !== false )
00848 {
00849 $changelogEntries[] = implode( ' ', $currentEntries );
00850 }
00851 $currentEntries = array();
00852 $currentEntries[] = trim( substr( $line, 1 ) );
00853 }
00854 else
00855 {
00856 if ( $currentEntries === false )
00857 {
00858 $changelogEntries = array();
00859 }
00860 $currentEntries[] = trim( $line );
00861 }
00862 }
00863 if ( $currentEntries !== false )
00864 {
00865 $changelogEntries[] = implode( ' ', $currentEntries );
00866 }
00867 $persistentData['changelog_entries'] = $changelogEntries;
00868 }
00869
00870
00871
00872
00873 function initializePackageMaintainer( &$package, &$http, $step, &$persistentData, &$tpl )
00874 {
00875 $maintainerPerson = false;
00876 $maintainerEmail = false;
00877 $user =& eZUser::currentUser();
00878 $userObject =& $user->attribute( 'contentobject' );
00879 if ( $userObject )
00880 $maintainerPerson = $userObject->attribute( 'name' );
00881 $maintainerEmail = $user->attribute( 'email' );
00882 $persistentData['maintainer_person'] = $maintainerPerson;
00883 $persistentData['maintainer_email'] = $maintainerEmail;
00884 $persistentData['maintainer_role'] = false;
00885 }
00886
00887
00888
00889
00890 function validatePackageMaintainer( &$package, &$http, $currentStepID, &$stepMap, &$persistentData, &$errorList )
00891 {
00892 $maintainerPerson = false;
00893 $maintainerEmail = false;
00894 $maintainerRole = false;
00895 if ( $http->hasPostVariable( 'PackageMaintainerPerson' ) )
00896 $maintainerPerson = trim( $http->postVariable( 'PackageMaintainerPerson' ) );
00897 if ( $http->hasPostVariable( 'PackageMaintainerEmail' ) )
00898 $maintainerEmail = $http->postVariable( 'PackageMaintainerEmail' );
00899 if ( $http->hasPostVariable( 'PackageMaintainerRole' ) )
00900 $maintainerRole = $http->postVariable( 'PackageMaintainerRole' );
00901
00902 $persistentData['maintainer_person'] = $maintainerPerson;
00903 $persistentData['maintainer_email'] = $maintainerEmail;
00904 $persistentData['maintainer_role'] = $maintainerRole;
00905
00906 $result = true;
00907 if ( trim( $maintainerPerson ) == '' )
00908 {
00909 $errorList[] = array( 'field' => ezi18n( 'kernel/package', 'Name' ),
00910 'description' => ezi18n( 'kernel/package', 'You must enter a name of the maintainer' ) );
00911 $result = false;
00912 }
00913 if ( trim( $maintainerEmail ) == '' )
00914 {
00915 $errorList[] = array( 'field' => ezi18n( 'kernel/package', 'E-Mail' ),
00916 'description' => ezi18n( 'kernel/package', 'You must enter an e-mail address of the maintainer' ) );
00917 $result = false;
00918 }
00919 return $result;
00920 }
00921
00922
00923
00924
00925 function commitPackageMaintainer( &$package, &$http, $step, &$persistentData, &$tpl )
00926 {
00927 }
00928
00929
00930
00931
00932
00933
00934
00935 function checkPackageMaintainer( &$package, &$persistentData )
00936 {
00937 $roleList = eZPackage::fetchMaintainerRoleIDList( $this->packageType( $package, $persistentData ), true );
00938 if ( count( $roleList ) > 0 )
00939 {
00940 if ( get_class( $package ) == 'ezpackage' )
00941 {
00942 $maintainerPerson = false;
00943 $user =& eZUser::currentUser();
00944 $userObject =& $user->attribute( 'contentobject' );
00945 if ( $userObject )
00946 $maintainerPerson = $userObject->attribute( 'name' );
00947
00948 $maintainers = $package->attribute( 'maintainers' );
00949 foreach ( $maintainers as $maintainer )
00950 {
00951 if ( $maintainer['person'] == $maintainerPerson )
00952 {
00953 return false;
00954 }
00955 }
00956 }
00957 return true;
00958 }
00959 return false;
00960 }
00961
00962
00963
00964
00965 function initializePackageThumbnail( &$package, &$http, $step, &$persistentData, &$tpl )
00966 {
00967 $persistentData['thumbnail'] = false;
00968 }
00969
00970
00971
00972
00973 function validatePackageThumbnail( &$package, &$http, $currentStepID, &$stepMap, &$persistentData, &$errorList )
00974 {
00975 include_once( 'lib/ezutils/classes/ezhttpfile.php' );
00976
00977 if ( !eZHTTPFile::canFetch( 'PackageThumbnail' ) )
00978 return true;
00979
00980 $file =& eZHTTPFile::fetch( 'PackageThumbnail' );
00981
00982 $result = true;
00983 if ( $file )
00984 {
00985 include_once( 'lib/ezutils/classes/ezmimetype.php' );
00986 $mimeData = eZMimeType::findByFileContents( $file->attribute( 'original_filename' ) );
00987 $dir = eZSys::storageDirectory() . '/temp';
00988 eZMimeType::changeDirectoryPath( $mimeData, $dir );
00989 $file->store( false, false, $mimeData );
00990 $persistentData['thumbnail'] = $mimeData;
00991 }
00992 return $result;
00993 }
00994
00995
00996
00997
00998 function commitPackageThumbnail( &$package, &$http, $step, &$persistentData, &$tpl )
00999 {
01000 }
01001
01002
01003
01004
01005
01006 function appendLicence( &$package )
01007 {
01008 $package->appendDocument( 'LICENCE', false, false, false, true,
01009 "This file is part of the package " . $package->attribute( 'name' ) . ".\n" .
01010 "\n" .
01011 "This package is free software; you can redistribute it and/or modify\n" .
01012 "it under the terms of the GNU General Public License as published by\n" .
01013 "the Free Software Foundation; either version 2 of the License, or\n" .
01014 "(at your option) any later version.\n" .
01015 "\n" .
01016 "This package is distributed in the hope that it will be useful,\n" .
01017 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" .
01018 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" .
01019 "GNU General Public License for more details.\n" .
01020 "\n" .
01021 "You should have received a copy of the GNU General Public License\n" .
01022 "along with this package; if not, write to the Free Software\n" .
01023 "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n" );
01024 }
01025 }
01026
01027 ?>