- Fixed #16160: Call to undefined function ezi18n()
[tinyz:tinyz.git] / kernel / setup / steps / ezstep_site_types.php
1 <?php
2 //
3 // Definition of eZStepSiteTypes class
4 //
5 // Created on: <16-Apr-2004 09:56:02 amos>
6 //
7 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
8 // SOFTWARE NAME: eZ Publish
9 // SOFTWARE RELEASE: 4.1.x
10 // COPYRIGHT NOTICE: Copyright (C) 1999-2010 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 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
29 //
30
31
32
33 /*!
34   \class eZStepSiteTypes ezstep_site_types.php
35   \brief The class eZStepSiteTypes does
36
37 */
38
39 class eZStepSiteTypes extends eZStepInstaller
40 {
41     /*!
42      Constructor
43     */
44     function eZStepSiteTypes( $tpl, $http, $ini, &$persistenceList )
45     {
46         $ini = eZINI::instance( 'package.ini' );
47         $indexURL = trim( $ini->variable( 'RepositorySettings', 'RemotePackagesIndexURL' ) );
48         if ( $indexURL === '' )
49         {
50             $indexURL = trim( $ini->variable( 'RepositorySettings', 'RemotePackagesIndexURLBase' ) );
51             if ( substr( $indexURL, -1, 1 ) !== '/' )
52             {
53                 $indexURL .= '/';
54             }
55             $indexURL .= eZPublishSDK::version( false, false, false ) . '/' . eZPublishSDK::version() . '/';
56         }
57         $this->IndexURL = $indexURL;
58
59         if ( substr( $this->IndexURL, -1, 1 ) == '/' )
60             $this->XMLIndexURL = $this->IndexURL . 'index.xml';
61         else
62             $this->XMLIndexURL = $this->IndexURL . '/index.xml';
63
64         $this->eZStepInstaller( $tpl, $http, $ini, $persistenceList,
65                                 'site_types', 'Site types' );
66     }
67
68     /**
69      * Downloads file.
70      *
71      * Sets $this->ErrorMsg in case of an error.
72      *
73      * \private
74      * \param $url            URL.
75      * \param $outDir         Directory where to put downloaded file to.
76      * \param $forcedFileName Force saving downloaded file under this name.
77      * \return false on error, path to downloaded package otherwise.
78      */
79     function downloadFile( $url, $outDir, $forcedFileName = false )
80     {
81         $fileName = $outDir . "/" . ( $forcedFileName ? $forcedFileName : basename( $url ) );
82
83         eZDebug::writeNotice( "Downloading file '$fileName' from $url" );
84
85         // Create the out directory if not exists.
86         if ( !file_exists( $outDir ) )
87             eZDir::mkdir( $outDir, false, true );
88
89         // First try CURL
90         if ( extension_loaded( 'curl' ) )
91         {
92             $ch = curl_init( $url );
93             $fp = eZStepSiteTypes::fopen( $fileName, 'wb' );
94
95             if ( $fp === false )
96             {
97                 $this->ErrorMsg = ezpI18n::translate( 'design/standard/setup/init', 'Cannot write to file' ) .
98                     ': ' . $this->FileOpenErrorMsg;
99                 return false;
100             }
101
102             curl_setopt( $ch, CURLOPT_FILE, $fp );
103             curl_setopt( $ch, CURLOPT_HEADER, 0 );
104             curl_setopt( $ch, CURLOPT_FAILONERROR, 1 );
105             // Get proxy
106             $ini = eZINI::instance();
107             $proxy = $ini->hasVariable( 'ProxySettings', 'ProxyServer' ) ? $ini->variable( 'ProxySettings', 'ProxyServer' ) : false;
108             if ( $proxy )
109             {
110                 curl_setopt ( $ch, CURLOPT_PROXY , $proxy );
111                 $userName = $ini->hasVariable( 'ProxySettings', 'User' ) ? $ini->variable( 'ProxySettings', 'User' ) : false;
112                 $password = $ini->hasVariable( 'ProxySettings', 'Password' ) ? $ini->variable( 'ProxySettings', 'Password' ) : false;
113                 if ( $userName )
114                 {
115                     curl_setopt ( $ch, CURLOPT_PROXYUSERPWD, "$userName:$password" );
116                 }
117             }
118
119             if ( !curl_exec( $ch ) )
120             {
121                 $this->ErrorMsg = curl_error( $ch );
122                 return false;
123             }
124
125             curl_close( $ch );
126             fclose( $fp );
127         }
128         else
129         {
130             $parsedUrl = parse_url( $url );
131             $checkIP = isset( $parsedUrl[ 'host' ] ) ? ip2long( gethostbyname( $parsedUrl[ 'host' ] ) ) : false;
132             if ( $checkIP === false )
133             {
134                 return false;
135             }
136
137             // If we don't have CURL installed we used standard fopen urlwrappers
138             // Note: Could be blocked by not allowing remote calls.
139             if ( !copy( $url, $fileName ) )
140             {
141                 $buf = eZHTTPTool::sendHTTPRequest( $url, 80, false, 'eZ Publish', false );
142
143                 $header = false;
144                 $body = false;
145                 if ( eZHTTPTool::parseHTTPResponse( $buf, $header, $body ) )
146                 {
147                     eZFile::create( $fileName, false, $body );
148                 }
149                 else
150                 {
151                     $this->ErrorMsg = ezpI18n::translate( 'design/standard/setup/init', 'Failed to copy %url to local file %filename', null,
152                                               array( "%url" => $url,
153                                                      "%filename" => $fileName ) );
154                     return false;
155                 }
156             }
157         }
158
159         return $fileName;
160     }
161
162     /**
163      * Downloads and imports package.
164      *
165      * Sets $this->ErrorMsg in case of an error.
166      *
167      * \param $forceDownload  download even if this package already exists.
168      * \private
169      * \return false on error, package object otherwise.
170      */
171     function downloadAndImportPackage( $packageName, $packageUrl, $forceDownload = false )
172     {
173         $package = eZPackage::fetch( $packageName, false, false, false );
174
175         if ( is_object( $package ) )
176         {
177             if ( $forceDownload )
178             {
179                 $package->remove();
180             }
181             else
182             {
183                 eZDebug::writeNotice( "Skipping download of package '$packageName': package already exists." );
184                 return $package;
185             }
186         }
187
188         $archiveName = $this->downloadFile( $packageUrl, /* $outDir = */ eZStepSiteTypes::tempDir() );
189         if ( $archiveName === false )
190         {
191             eZDebug::writeWarning( "Download of package '$packageName' from '$packageUrl' failed: $this->ErrorMsg" );
192             $this->ErrorMsg = ezpI18n::translate( 'design/standard/setup/init',
193                                       'Download of package \'%pkg\' failed. You may upload the package manually.',
194                                       false, array( '%pkg' => $packageName ) );
195
196             return false;
197         }
198
199         $package = eZPackage::import( $archiveName, $packageName, false );
200
201         // Remove downloaded ezpkg file
202         eZFileHandler::unlink( $archiveName );
203
204         if ( !$package instanceof eZPackage )
205         {
206             if ( $package == eZPackage::STATUS_INVALID_NAME )
207             {
208                 eZDebug::writeNotice( "The package name $packageName is invalid" );
209             }
210             else
211             {
212                 eZDebug::writeNotice( "Invalid package" );
213             }
214
215             $this->ErrorMsg = ezpI18n::translate( 'design/standard/setup/init', 'Invalid package' );
216             return false;
217         }
218
219         return $package;
220     }
221
222
223     /*!
224      * Download packages required by the given package.
225      *
226      * \private
227      */
228     function downloadDependantPackages( $sitePackage )
229     {
230         $dependencies = $sitePackage->attribute( 'dependencies' );
231         $requirements = $dependencies['requires'];
232         $remotePackagesInfo = $this->retrieveRemotePackagesList();
233
234         foreach ( $requirements as $req )
235         {
236             $requiredPackageName = $req['name'];
237
238             if ( isset( $req['min-version'] ) )
239                 $requiredPackageVersion = $req['min-version'];
240             else
241                 $requiredPackageVersion = 0;
242
243             $downloadNewPackage   = false;
244             $removeCurrentPackage = false;
245
246             // try to fetch the required package
247             $package = eZPackage::fetch( $requiredPackageName, false, false, false );
248
249             // if it already exists
250             if ( is_object( $package ) )
251             {
252                 // check its version
253                 $currentPackageVersion = $package->getVersion();
254
255                 // if existing package's version is less than required one
256                 // we remove the package and download newer one.
257
258                 if ( version_compare( $currentPackageVersion, $requiredPackageVersion ) < 0 )
259                 {
260                     $downloadNewPackage   = true;
261                     $removeCurrentPackage = true;
262                 }
263
264                 // else (if the version is greater or equal to the required one)
265                 // then do nothing (skip downloading)
266             }
267             else
268                 // if the package does not exist, we download it.
269                 $downloadNewPackage   = true;
270
271             if ( $removeCurrentPackage )
272             {
273                 $package->remove();
274                 unset( $package );
275             }
276
277             if ( $downloadNewPackage )
278             {
279                 if ( !isset( $remotePackagesInfo[$requiredPackageName]['url'] ) )
280                 {
281                     eZDebug::writeWarning( "Download of package '$requiredPackageName' failed: the URL is unknown." );
282                     $this->ErrorMsg = ezpI18n::translate( 'design/standard/setup/init',
283                                               'Download of package \'%pkg\' failed. You may upload the package manually.',
284                                               false, array( '%pkg' => $requiredPackageName ) );
285                     $this->ShowURL = true;
286
287                     return false;
288                 }
289
290                 $requiredPackageURL = $remotePackagesInfo[$requiredPackageName]['url'];
291                 $rc = $this->downloadAndImportPackage( $requiredPackageName, $requiredPackageURL );
292                 if( !is_object( $rc ) )
293                 {
294                     return false;
295                 }
296             }
297         }
298
299         return true;
300     }
301
302     /**
303      * Upload local package.
304      *
305      * \private
306      */
307     function uploadPackage()
308     {
309
310         if ( !eZHTTPFile::canFetch( 'PackageBinaryFile' ) )
311         {
312             $this->ErrorMsg = ezpI18n::translate( 'design/standard/setup/init',
313                                       'No package selected for upload' ) . '.';
314             return;
315         }
316
317         $file = eZHTTPFile::fetch( 'PackageBinaryFile' );
318         if ( !$file )
319         {
320             $this->ErrorMsg = ezpI18n::translate( 'design/standard/setup/init',
321                                       'Failed fetching upload package file' );
322             return;
323         }
324
325         $packageFilename = $file->attribute( 'filename' );
326         $packageName = $file->attribute( 'original_filename' );
327         if ( preg_match( "#^(.+)-[0-9](\.[0-9]+)-[0-9].ezpkg$#", $packageName, $matches ) )
328             $packageName = $matches[1];
329         $packageName = preg_replace( array( "#[^a-zA-Z0-9]+#",
330                                             "#_+#",
331                                             "#(^_)|(_$)#" ),
332                                      array( '_',
333                                             '_',
334                                             '' ), $packageName );
335         $package = eZPackage::import( $packageFilename, $packageName, false );
336
337         if ( is_object( $package ) )
338         {
339             // package successfully imported
340             return;
341         }
342         elseif ( $package == eZPackage::STATUS_ALREADY_EXISTS )
343         {
344             eZDebug::writeWarning( "Package '$packageName' already exists." );
345         }
346         else
347         {
348             $this->ErrorMsg = ezpI18n::translate( 'design/standard/setup/init',
349                                   'Uploaded file is not an eZ Publish package' );
350         }
351     }
352
353     /**
354      * Process POST data.
355      *
356      * \reimp
357      */
358     function processPostData()
359     {
360         if ( $this->Http->hasPostVariable( 'UploadPackageButton' ) )
361         {
362             $this->uploadPackage();
363             return false; // force displaying the same step.
364         }
365
366         if ( !$this->Http->hasPostVariable( 'eZSetup_site_type' ) )
367         {
368             $this->ErrorMsg = ezpI18n::translate( 'design/standard/setup/init',
369                                       'No site package chosen.' );
370             return false;
371         }
372
373         $sitePackageInfo = $this->Http->postVariable( 'eZSetup_site_type' );
374         $downloaded = false; // true - if $sitePackageName package has been downloaded.
375         if ( preg_match( '/^(\w+)\|(.+)$/', $sitePackageInfo, $matches ) )
376         {
377             // remote site package chosen: download it.
378             $sitePackageName = $matches[1];
379             $sitePackageURL  = $matches[2];
380
381             // we already know that we should download the package anyway as it has newer version
382             // so use force download mode
383             $package = $this->downloadAndImportPackage( $sitePackageName, $sitePackageURL, true );
384             if ( is_object( $package ) )
385             {
386                 $downloaded = true;
387                 $this->Message = ezpI18n::translate( 'design/standard/setup/init', 'Package \'%packageName\' and it\'s dependencies have been downloaded successfully. Press \'Next\' to continue.', false, array( '%packageName' => $sitePackageName ) );
388             }
389         }
390         else
391         {
392             // local (already imported) site package chosen: just fetch it.
393             $sitePackageName = $sitePackageInfo;
394
395             $package = eZPackage::fetch( $sitePackageName, false, false, false );
396             $this->ErrorMsg = ezpI18n::translate( 'design/standard/setup/init', 'Invalid package' ) . '.';
397         }
398
399         // Verify package.
400         if ( !is_object( $package ) || !$this->selectSiteType( $sitePackageName ) )
401             return false;
402
403         // Download packages that the site package requires.
404         $downloadDependandPackagesResult = $this->downloadDependantPackages( $package );
405         return $downloadDependandPackagesResult == false ? false : !$downloaded;
406     }
407
408     function init()
409     {
410         if ( $this->hasKickstartData() )
411         {
412             $data = $this->kickstartData();
413             $remoteSitePackages = $this->retrieveRemoteSitePackagesList();
414             $importedSitePackages = $this->fetchAvailableSitePackages();
415             $dependenciesStatus = array();
416
417             // check site package dependencies to show their status in the template
418             foreach ( $importedSitePackages as $sitePackage )
419             {
420                 $sitePackageName = $sitePackage->attribute( 'name' );
421                 $dependencies = $sitePackage->attribute( 'dependencies' );
422                 $requirements = $dependencies['requires'];
423
424                 foreach ( $requirements as $req )
425                 {
426                     $requiredPackageName    = $req['name'];
427                     $requiredPackageVersion = $req['min-version'];
428                     $packageOK = false;
429
430                     $package = eZPackage::fetch( $requiredPackageName, false, false, false );
431                     if ( is_object( $package ) )
432                     {
433                         $currentPackageVersion = $package->getVersion();
434                         if ( version_compare( $currentPackageVersion, $requiredPackageVersion ) >= 0 )
435                             $packageOK = true;
436                     }
437
438                     $dependenciesStatus[$sitePackageName][$requiredPackageName] = array( 'version' => $requiredPackageVersion,
439                                                                                      'status'  => $packageOK );
440                 }
441             }
442
443             $sitePackages = $this->createSitePackagesList( $remoteSitePackages, $importedSitePackages, $dependenciesStatus );
444             $chosenSitePackage = $data['Site_package'];
445             $downloaded = false;
446             foreach( $sitePackages as $sitePackagesInfo )
447             {
448                 if( $sitePackagesInfo['name'] == $chosenSitePackage )
449                 {
450                     $sitePackagesInfoChoosen = $sitePackagesInfo;
451                 }
452             }
453             if ( isset( $sitePackagesInfoChoosen ) and array_key_exists( 'url', $sitePackagesInfoChoosen ) )
454             {
455                 // we already know that we should download the package anyway as it has newer version
456                 // so use force download mode
457                 $package = $this->downloadAndImportPackage( $chosenSitePackage, $sitePackagesInfoChoosen['url'], true );
458                 if ( is_object( $package ) )
459                 {
460
461                     $downloadDependandPackagesResult = $this->downloadDependantPackages( $package );
462                     if ( $downloadDependandPackagesResult != false )
463                     {
464                         $downloaded = true;
465                     }
466                 }
467             }
468
469             if ( $downloaded and $this->selectSiteType( $chosenSitePackage ) )
470             {
471                 return $this->kickstartContinueNextStep();
472             }
473         }
474
475         if ( !isset( $this->ErrorMsg ) )
476             $this->ErrorMsg = false;
477
478         return false; // Always show site template selection
479     }
480
481     /**
482      * \private
483      */
484     function createSitePackagesList( $remoteSitePackages, $importedSitePackages, $dependenciesStatus )
485     {
486         $sitePackages = array();
487
488         if ( is_array( $remoteSitePackages ) )
489         {
490             foreach ( $remoteSitePackages as $packageInfo )
491             {
492                 $packageName = $packageInfo['name'];
493                 $sitePackages[$packageName] = $packageInfo;
494             }
495         }
496
497         foreach ( $importedSitePackages as $package )
498         {
499             $packageName = $package->attribute( 'name' );
500             $packageVersion = $package->getVersion();
501
502             if ( isset( $sitePackages[$packageName] ) )
503             {
504                 $remoteVersion = $sitePackages[$packageName]['version'];
505                 $localVersion = $packageVersion;
506
507                 if ( version_compare( $remoteVersion, $localVersion ) > 0 )
508                     continue;
509             }
510
511             $thumbnails = $package->attribute( 'thumbnail-list' );
512
513             $thumbnailPath = false;
514             if ( $thumbnails )
515             {
516                 $thumbnailFile = $thumbnails[0];
517                 $thumbnailPath = $package->fileItemPath( $thumbnailFile, 'default' );
518             }
519
520             $dependencies = $package->attribute( 'dependencies' );
521             $requirements = $dependencies['requires'];
522
523             $requiresPackageInfo = isset( $dependenciesStatus[$packageName] ) ? $dependenciesStatus[$packageName] : null;
524             $packageInfo = array(
525                 'name' => $packageName,
526                 'version' => $package->getVersion(),
527                 'type' => $package->attribute( 'type' ),
528                 'summary' => $package->attribute( 'summary' ),
529                 'description' => $package->attribute( 'description' ),
530                 'requires' => $requiresPackageInfo,
531                 );
532
533             if ( $thumbnailPath )
534                 $packageInfo['thumbnail_path'] = $thumbnailPath;
535
536             $sitePackages[$packageName] = $packageInfo;
537         }
538
539         // Set availability status for each package.
540         foreach ( $sitePackages as $idx => $packageInfo )
541             $sitePackages[$idx]['status'] = !isset( $packageInfo['url'] );
542
543         $sortBySummary = create_function('$x,$y', "return \$x['summary'] < \$y['summary'] ? -1 : 1;");
544         usort( $sitePackages, $sortBySummary );
545
546         return $sitePackages;
547     }
548
549     function display()
550     {
551         $remoteSitePackages = $this->retrieveRemoteSitePackagesList();
552         $importedSitePackages = $this->fetchAvailableSitePackages();
553         $dependenciesStatus = array();
554
555         // check site package dependencies to show their status in the template
556         foreach ( $importedSitePackages as $sitePackage )
557         {
558             $sitePackageName = $sitePackage->attribute( 'name' );
559             $dependencies = $sitePackage->attribute( 'dependencies' );
560             $requirements = $dependencies['requires'];
561
562             foreach ( $requirements as $req )
563             {
564                 $requiredPackageName    = $req['name'];
565                 $requiredPackageVersion = $req['min-version'];
566                 $packageOK = false;
567
568                 $package = eZPackage::fetch( $requiredPackageName, false, false, false );
569                 if ( is_object( $package ) )
570                 {
571                     $currentPackageVersion = $package->getVersion();
572                     if ( version_compare( $currentPackageVersion, $requiredPackageVersion ) >= 0 )
573                         $packageOK = true;
574                 }
575
576                 $dependenciesStatus[$sitePackageName][$requiredPackageName] = array( 'version' => $requiredPackageVersion,
577                                                                                      'status'  => $packageOK );
578             }
579         }
580
581         $sitePackages = $this->createSitePackagesList( $remoteSitePackages, $importedSitePackages, $dependenciesStatus );
582
583         $chosenSitePackage = $this->chosenSitePackage();
584
585         $this->Tpl->setVariable( 'site_packages', $sitePackages );
586         $this->Tpl->setVariable( 'dependencies_status', $dependenciesStatus );
587         $this->Tpl->setVariable( 'chosen_package', $chosenSitePackage );
588         $this->Tpl->setVariable( 'error', $this->ErrorMsg );
589         $this->Tpl->setVariable( 'index_url', $this->IndexURL );
590         $this->Tpl->setVariable( 'message', $this->Message );
591
592         // Return template and data to be shown
593         $result = array();
594         // Display template
595         $result['content'] = $this->Tpl->fetch( 'design:setup/init/site_types.tpl' );
596         $result['path'] = array( array( 'text' => ezpI18n::translate( 'design/standard/setup/init',
597                                                           'Site selection' ),
598                                         'url' => false ) );
599         return $result;
600     }
601
602     /**
603      * Fetches list of site packages already available locally.
604      *
605      * \private
606      */
607     function fetchAvailableSitePackages()
608     {
609         $packageList = eZPackage::fetchPackages( array( 'db_available' => false ), array( 'type' => 'site' ) );
610
611         return $packageList;
612     }
613
614     /**
615      * Fetches list of packages already available locally.
616      *
617      * \private
618      */
619     function fetchAvailablePackages( $type = false )
620     {
621         $typeArray  = array();
622         if ( $type )
623             $typeArray['type'] = $type;
624
625         $packageList = eZPackage::fetchPackages( array( 'db_available' => false ), $typeArray );
626
627         return $packageList;
628     }
629
630
631     /**
632      * Retrieve list of packages available to download.
633      *
634      * Example of return value:
635      * array(
636      *  'packages' => array(
637      *                      '<package_name1>' => array( "name" =>... , "version" =>... , "summary" => ... "url" =>... ),
638      *                      '<package_name2>' => array( "name" =>... , "version" =>... , "summary" => ... "url" =>... )
639      *                     )
640      *      );
641      *
642      */
643     function retrieveRemotePackagesList( $onlySitePackages = false )
644     {
645         // Download index file.
646         $idxFileName = $this->downloadFile( $this->XMLIndexURL, /* $outDir = */ eZStepSiteTypes::tempDir(), 'index.xml' );
647
648         if ( $idxFileName === false )
649         {
650             $this->ErrorMsg = ezpI18n::translate( 'design/standard/setup/init',
651                                       'Retrieving remote site packages list failed. ' .
652                                       'You may upload packages manually.' );
653
654             eZDebug::writeNotice( "Cannot download remote packages index file from '$this->XMLIndexURL'." );
655             return false;
656         }
657
658         // Parse it.
659         $dom = new DOMDocument( '1.0', 'utf-8' );
660         $dom->preserveWhiteSpace = false;
661         $success = $dom->load( realpath( $idxFileName ) );
662
663         @unlink( $idxFileName );
664
665         if ( !$success )
666         {
667             eZDebug::writeError( "Unable to open index file." );
668             return false;
669         }
670
671         $root = $dom->documentElement;
672
673         if ( $root->localName != 'packages' )
674         {
675             eZDebug::writeError( "Malformed index file." );
676             return false;
677         }
678
679         $packageList = array();
680         foreach ( $root->childNodes as $packageNode )
681         {
682             if ( $packageNode->localName != 'package' ) // skip unwanted chilren
683                 continue;
684             if ( $onlySitePackages && $packageNode->getAttribute( 'type' ) != 'site' )  // skip non-site packages
685                 continue;
686             $packageAttributes = array();
687             foreach ( $packageNode->attributes as $attributeNode )
688             {
689                 $packageAttributes[$attributeNode->localName] = $attributeNode->value;
690             }
691             $packageList[$packageAttributes['name']] = $packageAttributes;
692         }
693
694         return $packageList;
695     }
696
697     /**
698      * Retrieve list of site packages available to download.
699      * \private
700      */
701     function retrieveRemoteSitePackagesList()
702     {
703         return $this->retrieveRemotePackagesList( true );
704     }
705
706     /**
707      * Wrapper for standard fopen() doing error checking.
708      *
709      * \private
710      * \static
711      */
712     function fopen( $fileName, $mode )
713     {
714         $savedTrackErrorsFlag = ini_get( 'track_errors' );
715         ini_set( 'track_errors', 1 );
716
717         if ( ( $handle = @fopen( $fileName, 'wb' ) ) === false )
718             $this->FileOpenErrorMsg = $php_errormsg;
719
720         ini_set( 'track_errors', $savedTrackErrorsFlag );
721
722         return $handle;
723     }
724
725     /**
726      * Returns temporary directory used to download files to.
727      *
728      * \static
729      */
730     function tempDir()
731     {
732         return eZDir::path( array( eZSys::cacheDirectory(),
733                                     'packages' ) );
734     }
735
736     // current repository URL
737     public $IndexURL;
738     public $XMLIndexURL;
739
740     public $Error = 0;
741     public $ErrorMsg = false;
742     public $FileOpenErrorMsg = false;
743     public $Message = false;
744 }
745
746 ?>