[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/kernel/classes/ -> ezpackagecreationhandler.php (source)

   1  <?php
   2  //
   3  // Definition of eZPackageCreationHandler class
   4  //
   5  // Created on: <21-Nov-2003 11:52:36 amos>
   6  //
   7  // SOFTWARE NAME: eZ publish
   8  // SOFTWARE RELEASE: 3.9.0
   9  // BUILD VERSION: 17785
  10  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  11  // SOFTWARE LICENSE: GNU General Public License v2.0
  12  // NOTICE: >
  13  //   This program is free software; you can redistribute it and/or
  14  //   modify it under the terms of version 2.0  of the GNU General
  15  //   Public License as published by the Free Software Foundation.
  16  //
  17  //   This program is distributed in the hope that it will be useful,
  18  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20  //   GNU General Public License for more details.
  21  //
  22  //   You should have received a copy of version 2.0 of the GNU General
  23  //   Public License along with this program; if not, write to the Free
  24  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25  //   MA 02110-1301, USA.
  26  //
  27  //
  28  
  29  /*! \file ezpackagecreationhandler.php
  30  */
  31  
  32  /*!
  33    \ingroup package
  34    \class eZPackageCreationHandler ezpackagecreationhandler.php
  35    \brief The class eZPackageCreationHandler does
  36  
  37  */
  38  
  39  include_once ( 'kernel/classes/ezpackage.php' );
  40  include_once ( 'lib/ezutils/classes/ezextension.php' );
  41  
  42  class eZPackageCreationHandler
  43  {
  44      /*!
  45       Constructor
  46      */
  47      function eZPackageCreationHandler( $id, $name, $steps )
  48      {
  49          $this->Attributes = array( 'id' => $id,
  50                                     'name' => $name,
  51                                     'steps' => $steps,
  52                                     'step_map' => false,
  53                                     'current_steps' => $steps );
  54          $this->InitializeStepMethodMap = array();
  55          $this->ValidateStepMethodMap = array();
  56          $this->CommitStepMethodMap = array();
  57          $this->LoadStepMethodMap = array();
  58      }
  59  
  60      /*!
  61       Will go over the steps and make sure that:
  62       - The next and previous links are correct
  63       - Steps that aren't needed are removed
  64  
  65        It will also make sure that steps can be looked up by their ID.
  66      */
  67  	function generateStepMap( &$package, &$persistentData )
  68      {
  69          $steps = $this->attribute( 'steps' );
  70          $map = array();
  71          $lastStep = false;
  72          $currentSteps = array();
  73          for ( $i = 0; $i < count( $steps ); ++$i )
  74          {
  75              $step =& $steps[$i];
  76              if ( !isset( $step['previous_step'] ) )
  77              {
  78                  if ( $lastStep )
  79                      $step['previous_step'] = $lastStep['id'];
  80                  else
  81                      $step['previous_step'] = false;
  82              }
  83              if ( !isset( $step['next_step'] ) )
  84              {
  85                  if ( $i + 1 < count( $steps ) )
  86                      $step['next_step'] = $steps[$i+1]['id'];
  87                  else
  88                      $step['next_step'] = false;
  89              }
  90              if ( isset( $step['methods']['initialize'] ) )
  91                  $this->InitializeStepMethodMap[$step['id']] = $step['methods']['initialize'];
  92              if( isset( $step['methods']['load'] ) )
  93                  $this->LoadStepMethodMap[$step['id']] = $step['methods']['load'];
  94              if ( isset( $step['methods']['validate'] ) )
  95                  $this->ValidateStepMethodMap[$step['id']] = $step['methods']['validate'];
  96              if ( isset( $step['methods']['commit'] ) )
  97                  $this->CommitStepMethodMap[$step['id']] = $step['methods']['commit'];
  98              $isStepIncluded = true;
  99              if ( isset( $step['methods']['check'] ) )
 100              {
 101                  $checkMethod = $step['methods']['check'];
 102                  $isStepIncluded = $this->$checkMethod( $package, $persistentData );
 103              }
 104              if ( $isStepIncluded )
 105              {
 106                  $map[$step['id']] =& $step;
 107                  $lastStep =& $step;
 108                  $currentSteps[] =& $step;
 109              }
 110          }
 111          $this->StepMap = array( 'first' => &$steps[0],
 112                                  'map' => &$map,
 113                                  'steps' => &$steps );
 114          $this->Attributes['step_map'] =& $this->StepMap;
 115          $this->Attributes['current_steps'] = $currentSteps;
 116      }
 117  
 118      function attributes()
 119      {
 120          return array_keys( $this->Attributes );
 121      }
 122  
 123      function hasAttribute( $name )
 124      {
 125          return array_key_exists( $name, $this->Attributes );
 126      }
 127  
 128      function &attribute( $name )
 129      {
 130          if ( array_key_exists( $name, $this->Attributes ) )
 131              return $this->Attributes[$name];
 132          else
 133          {
 134              eZDebug::writeError( "Attribute '$name' does not exist", 'eZPackageCreationHandler::attribute' );
 135              $retValue = null;
 136              return $retValue;
 137          }
 138      }
 139  
 140      function initializeStepMethodMap()
 141      {
 142          return $this->InitializeStepMethodMap;
 143      }
 144  
 145      function loadStepMethodMap()
 146      {
 147          return $this->LoadStepMethodMap;
 148      }
 149  
 150      function validateStepMethodMap()
 151      {
 152          return $this->ValidateStepMethodMap;
 153      }
 154  
 155      function commitStepMethodMap()
 156      {
 157          return $this->CommitStepMethodMap;
 158      }
 159  
 160      /*!
 161       \return a process step map which has proper next/previous links,
 162               method maps and allows lookup of steps by ID.
 163      */
 164      function &stepMap()
 165      {
 166          return $this->StepMap;
 167      }
 168  
 169      /*!
 170       \virtual
 171      */
 172      function stepTemplate( $step )
 173      {
 174          $stepTemplateName = $step['template'];
 175          if ( isset( $step['use_standard_template'] ) and
 176               $step['use_standard_template'] )
 177              $stepTemplateDir = "create";
 178          else
 179              $stepTemplateDir = "creators/" . $this->attribute( 'id' );
 180          return array( 'name' => $stepTemplateName,
 181                        'dir' => $stepTemplateDir );
 182      }
 183  
 184      /*!
 185       \virtual
 186       This is called the first time the step is entered (ie. not on validations)
 187       and can be used to fill in values in the \a $persistentData variable
 188       for use in the template or later retrieval.
 189      */
 190      function initializeStep( &$package, &$http, $step, &$persistentData, &$tpl )
 191      {
 192          $methodMap = $this->initializeStepMethodMap();
 193          if ( count( $methodMap ) > 0 )
 194          {
 195              if ( isset( $methodMap[$step['id']] ) )
 196              {
 197                  $method = $methodMap[$step['id']];
 198                  return $this->$method( $package, $http, $step, $persistentData, $tpl );
 199              }
 200          }
 201      }
 202  
 203      /*!
 204       \virtual
 205       Called each time a step is loaded, and can be used to fetch and process input data in each step.
 206      */
 207      function loadStep( &$package, &$http, $currentStepID, &$persistentData, &$tpl, &$module )
 208      {
 209          $methodMap = $this->loadStepMethodMap();
 210          if ( count( $methodMap ) > 0 )
 211          {
 212              if ( isset( $methodMap[$currentStepID] ) )
 213              {
 214                  $method = $methodMap[$currentStepID];
 215                  return $this->$method( $package, $http, $currentStepID, $persistentData, $tpl, $module );
 216              }
 217          }
 218      }
 219  
 220      /*!
 221       This is called after a step is finished. Reimplement this function to validate
 222       the step values and give back errors.
 223       \return \c false if the next step should not be fetched (ie. errors) or
 224               \c true if the all is OK and the next step should be fetched.
 225               It is also possible to return a step identifier, in which case
 226               this will be the next step.
 227      */
 228      function validateStep( &$package, &$http, $currentStepID, &$stepMap, &$persistentData, &$errorList )
 229      {
 230          $nextStep = $this->validateAndAdvanceStep( $package, $http, $currentStepID, $stepMap, $persistentData, $errorList );
 231          if ( $nextStep === true )
 232          {
 233              if ( !isset( $stepMap['map'][$currentStepID] ) )
 234              {
 235                  $nextStep = $stepMap['first']['id'];
 236              }
 237              else
 238              {
 239                  $currentStep =& $stepMap['map'][$currentStepID];
 240                  $nextStep = $currentStep['next_step'];
 241              }
 242          }
 243          else if ( $nextStep === false )
 244              $nextStep = $currentStepID;
 245          return $nextStep;
 246      }
 247  
 248      /*!
 249       \virtual
 250      */
 251      function validateAndAdvanceStep( &$package, &$http, $currentStepID, &$stepMap, &$persistentData, &$errorList )
 252      {
 253          $methodMap = $this->validateStepMethodMap();
 254          if ( count( $methodMap ) > 0 )
 255          {
 256              if ( isset( $methodMap[$currentStepID] ) )
 257              {
 258                  $method = $methodMap[$currentStepID];
 259                  return $this->$method( $package, $http, $currentStepID, $stepMap, $persistentData, $errorList );
 260              }
 261          }
 262          return true;
 263      }
 264  
 265      /*!
 266       \virtual
 267       This is called after a step has validated it's information. It can
 268       be used to put values in the \a $persistentData variable for later retrieval.
 269      */
 270      function commitStep( &$package, &$http, $step, &$persistentData, &$tpl )
 271      {
 272          $methodMap = $this->commitStepMethodMap();
 273          if ( count( $methodMap ) > 0 )
 274          {
 275              if ( isset( $methodMap[$step['id']] ) )
 276              {
 277                  $method = $methodMap[$step['id']];
 278                  return $this->$method( $package, $http, $step, $persistentData, $tpl );
 279              }
 280          }
 281      }
 282  
 283      /*!
 284       \virtual
 285       Finalizes the creation process with the gathered information.
 286       This is usually the function that creates the package and
 287       adds the proper elements.
 288      */
 289      function finalize( &$package, &$http, &$persistentData )
 290      {
 291      }
 292  
 293      /*!
 294       \static
 295       \return a list of the available creators usable as a limitation in the role system.
 296      */
 297      function creatorLimitationList()
 298      {
 299          $creators =& eZPackageCreationHandler::creatorList();
 300          $list = array();
 301          foreach ( $creators as $creator )
 302          {
 303              $list[] = array( 'name' => $creator->attribute( 'name' ),
 304                               'id' => $creator->attribute( 'id' ) );
 305          }
 306          return $list;
 307      }
 308  
 309      /*!
 310       \static
 311       \return a list of the available creators.
 312      */
 313      function &creatorList( $checkRoles = false )
 314      {
 315          $allowedCreators = false;
 316  
 317          include_once ( "kernel/classes/datatypes/ezuser/ezuser.php" );
 318          $currentUser =& eZUser::currentUser();
 319          $accessResult = $currentUser->hasAccessTo( 'package', 'create' );
 320          $limitationList = array();
 321          $canCreate = false;
 322          if ( $accessResult['accessWord'] == 'no' )
 323          {
 324              $creators = array();
 325              return $creators;
 326          }
 327  
 328          if ( $accessResult['accessWord'] == 'limited' )
 329          {
 330              $limitationList =& $accessResult['policies'];
 331              foreach( $limitationList as $dummyKey => $limitationArray ) // TODO : fix this
 332              {
 333                  foreach ( $limitationArray as $key => $limitation )
 334                  {
 335                      if ( $key == 'CreatorType' )
 336                      {
 337                          if ( !is_array( $allowedCreators ) )
 338                              $allowedCreators = array();
 339                          $list = $limitation;
 340                          $allowedCreators = array_merge( $allowedCreators, $list );
 341                      }
 342                  }
 343              }
 344          }
 345  
 346          $creators =& $GLOBALS['eZPackageCreatorList'];
 347          if ( !isset( $creators ) )
 348          {
 349              $creators = array();
 350              $ini =& eZINI::instance( 'package.ini' );
 351              $list = $ini->variable( 'CreationSettings', 'HandlerList' );
 352              foreach ( $list as $name )
 353              {
 354                  if ( is_array( $allowedCreators ) and
 355                       !in_array( $name, $allowedCreators ) )
 356                       continue;
 357                  $handler =& eZPackageCreationHandler::instance( $name );
 358                  $creators[] =& $handler;
 359              }
 360          }
 361          return $creators;
 362      }
 363  
 364      /*!
 365       \return the package creation handler object for the handler named \a $handlerName.
 366      */
 367      function &instance( $handlerName )
 368      {
 369          $handlers =& $GLOBALS['eZPackageCreationHandlers'];
 370          if ( !isset( $handlers ) )
 371              $handlers = array();
 372          $handler = false;
 373          if ( eZExtension::findExtensionType( array( 'ini-name' => 'package.ini',
 374                                                      'repository-group' => 'PackageSettings',
 375                                                      'repository-variable' => 'RepositoryDirectories',
 376                                                      'extension-group' => 'PackageSettings',
 377                                                      'extension-variable' => 'ExtensionDirectories',
 378                                                      'subdir' => 'packagecreators',
 379                                                      'extension-subdir' => 'packagecreators',
 380                                                      'suffix-name' => 'packagecreator.php',
 381                                                      'type-directory' => true,
 382                                                      'type' => $handlerName,
 383                                                      'alias-group' => 'CreationSettings',
 384                                                      'alias-variable' => 'HandlerAlias' ),
 385                                               $result ) )
 386          {
 387              $handlerFile = $result['found-file-path'];
 388              if ( file_exists( $handlerFile ) )
 389              {
 390                  include_once( $handlerFile );
 391                  $handlerClassName = $result['type'] . 'PackageCreator';
 392                  if ( isset( $handlers[$result['type']] ) )
 393                  {
 394                      $handler =& $handlers[$result['type']];
 395                      $handler->reset();
 396                  }
 397                  else
 398                  {
 399                      $handler =& new $handlerClassName( $handlerName );
 400                      $handlers[$result['type']] =& $handler;
 401                  }
 402              }
 403          }
 404          return $handler;
 405      }
 406  
 407      /*!
 408       \static
 409       \return A ready to use creation step which takes care of package information.
 410      */
 411  	function packageInformationStep()
 412      {
 413          return array( 'id' => 'packageinfo',
 414                        'name' => ezi18n( 'kernel/package', 'Package information' ),
 415                        'methods' => array( 'initialize' => 'initializePackageInformation',
 416                                            'validate' => 'validatePackageInformation',
 417                                            'commit' => 'commitPackageInformation' ),
 418                        'use_standard_template' => true,
 419                        'template' => 'info.tpl' );
 420      }
 421  
 422      /*!
 423       \static
 424       \return A ready to use creation step which takes care of reading in maintainer information.
 425      */
 426  	function packageMaintainerStep()
 427      {
 428          return array( 'id' => 'packagemaintainer',
 429                        'name' => ezi18n( 'kernel/package', 'Package maintainer' ),
 430                        'methods' => array( 'initialize' => 'initializePackageMaintainer',
 431                                            'validate' => 'validatePackageMaintainer',
 432                                            'commit' => 'commitPackageMaintainer',
 433                                            'check' => 'checkPackageMaintainer' ),
 434                        'use_standard_template' => true,
 435                        'template' => 'maintainer.tpl' );
 436      }
 437  
 438      /*!
 439       \static
 440       \return A ready to use creation step which takes care of reading in a changelog entry.
 441      */
 442  	function packageChangelogStep()
 443      {
 444          return array( 'id' => 'packagechangelog',
 445                        'name' => ezi18n( 'kernel/package', 'Package changelog' ),
 446                        'methods' => array( 'initialize' => 'initializePackageChangelog',
 447                                            'validate' => 'validatePackageChangelog',
 448                                            'commit' => 'commitPackageChangelog' ),
 449                        'use_standard_template' => true,
 450                        'template' => 'changelog.tpl' );
 451      }
 452  
 453      /*!
 454       \static
 455       \return A ready to use creation step which takes care of fetching a thumbnail image.
 456      */
 457  	function packageThumbnailStep()
 458      {
 459          return array( 'id' => 'packagethumbnail',
 460                        'name' => ezi18n( 'kernel/package', 'Package thumbnail' ),
 461                        'methods' => array( 'initialize' => 'initializePackageThumbnail',
 462                                            'validate' => 'validatePackageThumbnail',
 463                                            'commit' => 'commitPackageThumbnail' ),
 464                        'use_standard_template' => true,
 465                        'template' => 'thumbnail.tpl' );
 466      }
 467  
 468      /*!
 469       \virtual
 470       \return the type installation this package uses.
 471  
 472       This method is called from the createPackage() method and will return \c 'install' by default.
 473       If you want the creator to have a different install type reimplement this function in the creator.
 474      */
 475      function packageInstallType( &$package, &$persistentData )
 476      {
 477          return 'install';
 478      }
 479  
 480      /*!
 481       \virtual
 482       \return the initial state of the package.
 483  
 484       The state of a package generally tells how stable a package is,
 485       see eZPackage::stateList() for more information on possible states.
 486       \note The default returns \c 'alpha'
 487      */
 488      function packageInitialState( &$package, &$persistentData )
 489      {
 490          return 'alpha';
 491      }
 492  
 493      /*!
 494       \virtual
 495       \return The initial changelog entry for a package.
 496       It is possible to get different initial texts by reimplementing this function.
 497  
 498       \note This function is called from initializePackageChangelog()
 499      */
 500      function initialChangelogEntry( &$package, &$http, $step, &$persistentData, &$tpl )
 501      {
 502          return '- Creation of package.';
 503      }
 504  
 505      /*!
 506       \virtual
 507       \return The package type taken from \a $package if the package exists,
 508               otherwise \c false.
 509       If the creator should have a specific package type this function should be reimplemented.
 510       See eZPackage::typeList() for more information on available types.
 511  
 512       \note This function is called from createPackage and checkPackageMaintainer()
 513      */
 514  	function packageType( &$package, &$persistentData )
 515      {
 516          if ( get_class( $package ) == 'ezpackage' )
 517          {
 518              return $package->attribute( 'type' );
 519          }
 520          return false;
 521      }
 522  
 523      /*!
 524       Creates a new package in \a $package and initializes it with the
 525       basic data. The information is taken from the \a $persistentData
 526       which must be filled in prior to this function is called.
 527       \return \c true if the package was created or \c false if it was only re-initialized.
 528       \sa packageType, packageInitialState and packageInstallType
 529      */
 530  	function createPackage( &$package, &$http, &$persistentData, &$cleanupFiles, $storePackage = true )
 531      {
 532          $createdPackage = false;
 533          if ( get_class( $package ) != 'ezpackage' )
 534          {
 535              $package = eZPackage::create( $persistentData['name'],
 536                                            array( 'summary' => $persistentData['summary'] ) );
 537              $createdPackage = true;
 538          }
 539          else
 540              $package->setAttribute( 'summary', $persistentData['summary'] );
 541  
 542          $package->setAttribute( 'is_active', false );
 543          $package->setAttribute( 'type', $this->packageType( $package, $persistentData ) );
 544  
 545          $package->setRelease( $persistentData['version'], '1', false,
 546                                $persistentData['licence'], $this->packageInitialState( $package, $persistentData ) );
 547  
 548          $package->setAttribute( 'description', $persistentData['description'] );
 549          $package->setAttribute( 'install_type', $this->packageInstallType( $package, $persistentData ) );
 550  
 551          $package->setAttribute( 'packaging-host', $persistentData['host'] );
 552          $package->setAttribute( 'packaging-packager', $persistentData['packager'] );
 553  
 554          $changelogPerson = $persistentData['changelog_person'];
 555          $changelogEmail = $persistentData['changelog_email'];
 556          $changelogEntries = $persistentData['changelog_entries'];
 557  
 558          $maintainerPerson = $persistentData['maintainer_person'];
 559          $maintainerEmail = $persistentData['maintainer_email'];
 560          $maintainerRole = $persistentData['maintainer_role'];
 561  
 562          if ( $maintainerPerson )
 563          {
 564              $package->appendMaintainer( $maintainerPerson, $maintainerEmail, $maintainerRole );
 565          }
 566  
 567          if ( $changelogPerson )
 568          {
 569              $package->appendChange( $changelogPerson, $changelogEmail, $changelogEntries );
 570          }
 571  
 572          if ( $persistentData['licence'] == 'GPL' )
 573          {
 574              eZPackageCreationHandler::appendLicence( $package );
 575          }
 576  
 577  
 578          $collections = array();
 579          $cleanupFiles = array();
 580  
 581          if ( isset( $persistentData['thumbnail'] ) and
 582               $persistentData['thumbnail'] )
 583          {
 584              $thumbnail = $persistentData['thumbnail'];
 585              $fileItem = array( 'file' => $thumbnail['filename'],
 586                                 'type' => 'thumbnail',
 587                                 'role' => false,
 588                                 'design' => false,
 589                                 'path' => $thumbnail['url'],
 590                                 'collection' => 'default',
 591                                 'file-type' => false,
 592                                 'role-value' => false,
 593                                 'variable-name' => 'thumbnail' );
 594  
 595              $package->appendFile( $fileItem['file'], $fileItem['type'], $fileItem['role'],
 596                                    $fileItem['design'], $fileItem['path'], $fileItem['collection'],
 597                                    null, null, true, null,
 598                                    $fileItem['file-type'], $fileItem['role-value'], $fileItem['variable-name'] );
 599              $cleanupFiles[] = $fileItem['path'];
 600  
 601              if ( !in_array( $fileItem['collection'], $collections ) )
 602                  $collections[] = $fileItem['collection'];
 603          }
 604  
 605          foreach ( $collections as $collection )
 606          {
 607              $installItems = $package->installItemsList( 'ezfile', false, $collection, true );
 608              if ( count( $installItems ) == 0 )
 609                  $package->appendInstall( 'ezfile', false, false, true,
 610                                           false, false,
 611                                           array( 'collection' => $collection ) );
 612              $dependencyItems = $package->dependencyItems( 'provides',
 613                                                         array( 'type'   => 'ezfile',
 614                                                                'name'   => 'collection',
 615                                    'valiue' => $collection ) );
 616              if ( count( $dependencyItems ) == 0 )
 617                  $package->appendDependency( 'provides',
 618                                              array( 'type'  => 'ezfile',
 619                                                     'name'  => 'collection',
 620                                                     'value' => $collection ) );
 621              $installItems = $package->installItemsList( 'ezfile', false, $collection, false );
 622              if ( count( $installItems ) == 0 )
 623                  $package->appendInstall( 'ezfile', false, false, false,
 624                                           false, false,
 625                                           array( 'collection' => $collection ) );
 626          }
 627  
 628          $package->setAttribute( 'is_active', true );
 629          if ( $storePackage )
 630              $package->store();
 631  
 632          return $createdPackage;
 633      }
 634  
 635      /*!
 636       \virtual
 637       This is called on the package information step to initialize the name, summary and description fields.
 638       Reimplementing this function allows the creator to fill in some default values for the information fields.
 639       \note The default does nothing.
 640      */
 641  	function generatePackageInformation( &$packageInformation, &$package, &$http, $step, &$persistentData )
 642      {
 643      }
 644  
 645      /*!
 646       Initializes the package information step with some default values.
 647       It will call generatePackageInformation() after the values are initialized.
 648      */
 649      function initializePackageInformation( &$package, &$http, $step, &$persistentData, &$tpl )
 650      {
 651          $persistentData['name'] = false;
 652          $persistentData['summary'] = false;
 653          $persistentData['description'] = false;
 654          $persistentData['licence'] = 'GPL';
 655          $persistentData['version'] = '1.0';
 656          if ( isset( $_SERVER['HOSTNAME'] ) )
 657              $host = $_SERVER['HOSTNAME'];
 658          else
 659              $host = $_SERVER['HTTP_HOST'];
 660          $persistentData['host'] = $host;
 661          $user =& eZUser::currentUser();
 662          $userObject =& $user->attribute( 'contentobject' );
 663          $packager = false;
 664          if ( $userObject )
 665              $packager = $userObject->attribute( 'name' );
 666          $persistentData['packager'] = $packager;
 667          $this->generatePackageInformation( $persistentData, $package, $http, $step, $persistentData );
 668  
 669          // Make sure the package name contains only valid characters
 670          include_once ( 'lib/ezi18n/classes/ezchartransform.php' );
 671          $trans =& eZCharTransform::instance();
 672          $persistentData['name'] = $trans->transformByGroup( $persistentData['name'], 'urlalias' );
 673      }
 674  
 675      /*!
 676       Reads in the package information values from POST variables and makes sure
 677       that the package name and package summary is filled in, the version is in correct
 678       format and that a package does not already exists with the same name.
 679      */
 680      function validatePackageInformation( &$package, &$http, $currentStepID, &$stepMap, &$persistentData, &$errorList )
 681      {
 682          $packageName = false;
 683          $packageSummary = false;
 684          $packageVersion = false;
 685          $packageDescription = false;
 686          $packageLicence = 'GPL';
 687          $packageHost = false;
 688          $packagePackager = false;
 689          if ( $http->hasPostVariable( 'PackageName' ) )
 690          {
 691              $packageName = trim( $http->postVariable( 'PackageName' ) );
 692          }
 693          if ( $http->hasPostVariable( 'PackageSummary' ) )
 694              $packageSummary = $http->postVariable( 'PackageSummary' );
 695          if ( $http->hasPostVariable( 'PackageDescription' ) )
 696              $packageDescription = $http->postVariable( 'PackageDescription' );
 697          if ( $http->hasPostVariable( 'PackageVersion' ) )
 698              $packageVersion = trim( $http->postVariable( 'PackageVersion' ) );
 699          if ( $http->hasPostVariable( 'PackageLicence' ) )
 700              $packageLicence = $http->postVariable( 'PackageLicence' );
 701          if ( $http->hasPostVariable( 'PackageHost' ) )
 702              $packageHost = $http->postVariable( 'PackageHost' );
 703          if ( $http->hasPostVariable( 'PackagePackager' ) )
 704              $packagePackager = $http->postVariable( 'PackagePackager' );
 705  
 706          $persistentData['name'] = $packageName;
 707          $persistentData['summary'] = $packageSummary;
 708          $persistentData['description'] = $packageDescription;
 709          $persistentData['version'] = $packageVersion;
 710          $persistentData['licence'] = $packageLicence;
 711          $persistentData['host'] = $packageHost;
 712          $persistentData['packager'] = $packagePackager;
 713  
 714          $result = true;
 715          if ( $packageName == '' )
 716          {
 717              $errorList[] = array( 'field' => ezi18n( 'kernel/package', 'Package name' ),
 718                                    'description' => ezi18n( 'kernel/package', 'Package name is missing' ) );
 719              $result = false;
 720          }
 721          else
 722          {
 723              $existingPackage = eZPackage::fetch( $packageName, false, true );
 724              if ( $existingPackage )
 725              {
 726                  $errorList[] = array( 'field' => ezi18n( 'kernel/package', 'Package name' ),
 727                                        'description' => ezi18n( 'kernel/package', 'A package named %packagename already exists, please give another name', false, array( '%packagename' => $packageName ) ) );
 728                  $result = false;
 729              }
 730              else
 731              {
 732                  // Make sure the package name contains only valid characters
 733                  include_once ( 'lib/ezi18n/classes/ezchartransform.php' );
 734                  $trans =& eZCharTransform::instance();
 735                  $validPackageName = $trans->transformByGroup( $packageName, 'urlalias' );
 736                  if ( strcmp( $validPackageName, $packageName ) != 0 )
 737                  {
 738                      $errorList[] = array( 'field' => ezi18n( 'kernel/package', 'Package name' ),
 739                                            '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 ) ) );
 740                      $result = false;
 741                  }
 742              }
 743          }
 744          if ( !$packageSummary )
 745          {
 746              $errorList[] = array( 'field' => ezi18n( 'kernel/package', 'Summary' ),
 747                                    'description' => ezi18n( 'kernel/package', 'Summary is missing' ) );
 748              $result = false;
 749          }
 750          if ( !preg_match( "#^[0-9](\.[0-9]([a-zA-Z]+[0-9]*)?)*$#", $packageVersion ) )
 751          {
 752              $errorList[] = array( 'field' => ezi18n( 'kernel/package', 'Version' ),
 753                                    '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' ) );
 754              $result = false;
 755          }
 756          return $result;
 757      }
 758  
 759      /*!
 760       Commits package information.
 761      */
 762      function commitPackageInformation( &$package, &$http, $step, &$persistentData, &$tpl )
 763      {
 764      }
 765  
 766      /*!
 767       Initializes the package changelog step with some values taken from the
 768       current users and the funcvtion initialChangelogEntry().
 769      */
 770      function initializePackageChangelog( &$package, &$http, $step, &$persistentData, &$tpl )
 771      {
 772          $user =& eZUser::currentUser();
 773          $userObject =& $user->attribute( 'contentobject' );
 774          if ( $userObject )
 775              $changelogPerson = $userObject->attribute( 'name' );
 776          $changelogEmail = $user->attribute( 'email' );
 777          $changelogText = '';
 778  
 779          $persistentData['changelog_person'] = $changelogPerson;
 780          $persistentData['changelog_email'] = $changelogEmail;
 781          if ( get_class( $package ) != 'ezpackage' )
 782          {
 783              $changelogText = $this->initialChangelogEntry( $package, $http, $step, $persistentData, $tpl );
 784          }
 785          $persistentData['changelog_text'] = $changelogText;
 786          $persistentData['changelog_entries'] = array();
 787      }
 788  
 789      /*!
 790       Checks if the POST variables contains a name and email for the changelog person and
 791       the changelog field contains some text.
 792      */
 793      function validatePackageChangelog( &$package, &$http, $currentStepID, &$stepMap, &$persistentData, &$errorList )
 794      {
 795          $changelogPerson = false;
 796          $changelogEmail = false;
 797          $changelogText = false;
 798          if ( $http->hasPostVariable( 'PackageChangelogPerson' ) )
 799              $changelogPerson = trim( $http->postVariable( 'PackageChangelogPerson' ) );
 800          if ( $http->hasPostVariable( 'PackageChangelogEmail' ) )
 801              $changelogEmail = $http->postVariable( 'PackageChangelogEmail' );
 802          if ( $http->hasPostVariable( 'PackageChangelogText' ) )
 803              $changelogText = $http->postVariable( 'PackageChangelogText' );
 804  
 805          $persistentData['changelog_person'] = $changelogPerson;
 806          $persistentData['changelog_email'] = $changelogEmail;
 807          $persistentData['changelog_text'] = $changelogText;
 808  
 809          $result = true;
 810          if ( trim( $changelogPerson ) == '' )
 811          {
 812              $errorList[] = array( 'field' => ezi18n( 'kernel/package', 'Name' ),
 813                                    'description' => ezi18n( 'kernel/package', 'You must enter a name for the changelog' ) );
 814              $result = false;
 815          }
 816          if ( trim( $changelogEmail ) == '' )
 817          {
 818              $errorList[] = array( 'field' => ezi18n( 'kernel/package', 'E-Mail' ),
 819                                    'description' => ezi18n( 'kernel/package', 'You must enter an e-mail for the changelog' ) );
 820              $result = false;
 821          }
 822          if ( trim( $changelogText ) == '' )
 823          {
 824              $errorList[] = array( 'field' => ezi18n( 'kernel/package', 'Changelog' ),
 825                                    'description' => ezi18n( 'kernel/package', 'You must supply some text for the changelog entry' ) );
 826              $result = false;
 827          }
 828          return $result;
 829      }
 830  
 831      /*!
 832       Parses the changelog entry text and turns into an array with change entries.
 833      */
 834      function commitPackageChangelog( &$package, &$http, $step, &$persistentData, &$tpl )
 835      {
 836          $changelogEntries = array();
 837          $changelogText = $persistentData['changelog_text'];
 838          $lines = preg_split( "#\r\n|\n|\r#", $changelogText );
 839          $currentEntries = false;
 840          foreach ( $lines as $line )
 841          {
 842              if ( strlen( $line ) > 0 and
 843                   ( $line[0] == '-' or $line[0] == '*' ) )
 844              {
 845                  if ( $currentEntries !== false )
 846                  {
 847                      $changelogEntries[] = implode( ' ', $currentEntries );
 848                  }
 849                  $currentEntries = array();
 850                  $currentEntries[] = trim( substr( $line, 1 ) );
 851              }
 852              else
 853              {
 854                  if ( $currentEntries === false )
 855                  {
 856                      $changelogEntries = array();
 857                  }
 858                  $currentEntries[] = trim( $line );
 859              }
 860          }
 861          if ( $currentEntries !== false )
 862          {
 863              $changelogEntries[] = implode( ' ', $currentEntries );
 864          }
 865          $persistentData['changelog_entries'] = $changelogEntries;
 866      }
 867  
 868      /*!
 869       Initializes the package maintainer step with some values taken from the current user.
 870      */
 871      function initializePackageMaintainer( &$package, &$http, $step, &$persistentData, &$tpl )
 872      {
 873          $maintainerPerson = false;
 874          $maintainerEmail = false;
 875          $user =& eZUser::currentUser();
 876             $userObject =& $user->attribute( 'contentobject' );
 877          if ( $userObject )
 878              $maintainerPerson = $userObject->attribute( 'name' );
 879          $maintainerEmail = $user->attribute( 'email' );
 880          $persistentData['maintainer_person'] = $maintainerPerson;
 881          $persistentData['maintainer_email'] = $maintainerEmail;
 882          $persistentData['maintainer_role'] = false;
 883      }
 884  
 885      /*!
 886       Checks if the POST variables has a name and email for the person.
 887      */
 888      function validatePackageMaintainer( &$package, &$http, $currentStepID, &$stepMap, &$persistentData, &$errorList )
 889      {
 890          $maintainerPerson = false;
 891          $maintainerEmail = false;
 892          $maintainerRole = false;
 893          if ( $http->hasPostVariable( 'PackageMaintainerPerson' ) )
 894              $maintainerPerson = trim( $http->postVariable( 'PackageMaintainerPerson' ) );
 895          if ( $http->hasPostVariable( 'PackageMaintainerEmail' ) )
 896              $maintainerEmail = $http->postVariable( 'PackageMaintainerEmail' );
 897          if ( $http->hasPostVariable( 'PackageMaintainerRole' ) )
 898              $maintainerRole = $http->postVariable( 'PackageMaintainerRole' );
 899  
 900          $persistentData['maintainer_person'] = $maintainerPerson;
 901          $persistentData['maintainer_email'] = $maintainerEmail;
 902          $persistentData['maintainer_role'] = $maintainerRole;
 903  
 904          $result = true;
 905          if ( trim( $maintainerPerson ) == '' )
 906          {
 907              $errorList[] = array( 'field' => ezi18n( 'kernel/package', 'Name' ),
 908                                    'description' => ezi18n( 'kernel/package', 'You must enter a name of the maintainer' ) );
 909              $result = false;
 910          }
 911          if ( trim( $maintainerEmail ) == '' )
 912          {
 913              $errorList[] = array( 'field' => ezi18n( 'kernel/package', 'E-Mail' ),
 914                                    'description' => ezi18n( 'kernel/package', 'You must enter an e-mail address of the maintainer' ) );
 915              $result = false;
 916          }
 917          return $result;
 918      }
 919  
 920      /*!
 921       Commits maintainer step data. Does nothing for now.
 922      */
 923      function commitPackageMaintainer( &$package, &$http, $step, &$persistentData, &$tpl )
 924      {
 925      }
 926  
 927      /*!
 928       Checks if the maintainer step is required and return \c true if so,
 929       otherwise \c false.
 930       The maintainer step is not required if the user has no maintainer roles to use
 931       or if the package already has a maintainer with the same name as the current user.
 932      */
 933  	function checkPackageMaintainer( &$package, &$persistentData )
 934      {
 935          $roleList = eZPackage::fetchMaintainerRoleIDList( $this->packageType( $package, $persistentData ), true );
 936          if ( count( $roleList ) > 0 )
 937          {
 938              if ( get_class( $package ) == 'ezpackage' )
 939              {
 940                  $maintainerPerson = false;
 941                  $user =& eZUser::currentUser();
 942                     $userObject =& $user->attribute( 'contentobject' );
 943                  if ( $userObject )
 944                      $maintainerPerson = $userObject->attribute( 'name' );
 945  
 946                  $maintainers = $package->attribute( 'maintainers' );
 947                  foreach ( $maintainers as $maintainer )
 948                  {
 949                      if ( $maintainer['person'] == $maintainerPerson )
 950                      {
 951                             return false;
 952                      }
 953                  }
 954              }
 955              return true;
 956          }
 957          return false;
 958      }
 959  
 960      /*!
 961       Initializes the package thumbnail step.
 962      */
 963      function initializePackageThumbnail( &$package, &$http, $step, &$persistentData, &$tpl )
 964      {
 965          $persistentData['thumbnail'] = false;
 966      }
 967  
 968      /*!
 969       Checks if the POST variables has a proper thumbnail image.
 970      */
 971      function validatePackageThumbnail( &$package, &$http, $currentStepID, &$stepMap, &$persistentData, &$errorList )
 972      {
 973          include_once ( 'lib/ezutils/classes/ezhttpfile.php' );
 974          // If we don't have an image we continue as normal
 975          if ( !eZHTTPFile::canFetch( 'PackageThumbnail' ) )
 976              return true;
 977  
 978          $file =& eZHTTPFile::fetch( 'PackageThumbnail' );
 979  
 980          $result = true;
 981          if ( $file )
 982          {
 983              include_once ( 'lib/ezutils/classes/ezmimetype.php' );
 984              $mimeData = eZMimeType::findByFileContents( $file->attribute( 'original_filename' ) );
 985              $dir = eZSys::storageDirectory() . '/temp';
 986              eZMimeType::changeDirectoryPath( $mimeData, $dir );
 987              $file->store( false, false, $mimeData );
 988              $persistentData['thumbnail'] = $mimeData;
 989          }
 990          return $result;
 991      }
 992  
 993      /*!
 994       Commits thumbnail step data. Does nothing for now.
 995      */
 996      function commitPackageThumbnail( &$package, &$http, $step, &$persistentData, &$tpl )
 997      {
 998      }
 999  
1000      /*!
1001       \static
1002       Appends the GPL licence file to the package object \a $package.
1003      */
1004      function appendLicence( &$package )
1005      {
1006          $package->appendDocument( 'LICENCE', false, false, false, true,
1007                                    "This file is part of the package " . $package->attribute( 'name' ) . ".\n" .
1008                                    "\n" .
1009                                    "This package is free software; you can redistribute it and/or modify\n" .
1010                                    "it under the terms of the GNU General Public License as published by\n" .
1011                                    "the Free Software Foundation; either version 2 of the License, or\n" .
1012                                    "(at your option) any later version.\n" .
1013                                    "\n" .
1014                                    "This package is distributed in the hope that it will be useful,\n" .
1015                                    "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" .
1016                                    "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n" .
1017                                    "GNU General Public License for more details.\n" .
1018                                    "\n" .
1019                                    "You should have received a copy of the GNU General Public License\n" .
1020                                    "along with this package; if not, write to the Free Software\n" .
1021                                    "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n" );
1022      }
1023  }
1024  
1025  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7