cvs: php4 /pear/Experimental/PEAR WebInstaller.php
| From: | Christian Stocker | Date: | Sun, 08 Jul 2001 10:44:02 +0000 |
| Subject: | cvs: php4 /pear/Experimental/PEAR WebInstaller.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-233@lists.php.net to get a copy of this message | ||
chregu Sun Jul 8 06:44:02 2001 EDT
Modified files:
/php4/pear/Experimental/PEAR WebInstaller.php
Log:
Cleaner code in the caching part
Index: php4/pear/Experimental/PEAR/WebInstaller.php
diff -u php4/pear/Experimental/PEAR/WebInstaller.php:1.3
php4/pear/Experimental/PEAR/WebInstaller.php:1.4
--- php4/pear/Experimental/PEAR/WebInstaller.php:1.3 Sun Jul 8 06:21:06 2001
+++ php4/pear/Experimental/PEAR/WebInstaller.php Sun Jul 8 06:44:01 2001
@@ -306,45 +306,42 @@
print "</tr></td></table></FORM>\n";
}
+
// }}}
+ // {{{ getPackages()
+ /** gets the Packages.xml from the server and saves it on the local disc for caching (if
possible)
+ * If the zlib-extension is compiled in, Packages.xml.gz is used instead.
+ */
function getPackages ()
{
+
+ // if we can write to the installdir, cache the Packages.xml there
+
+ $PackageFile = "Packages.xml";
+
+ // check if we have the zlib-extension compiled in
+ if (function_exists("gzfile")) { $useGz = True; $PackageFile .= ".gz";}
- // if we can write to the installdir cache the Packages.xml there
- if ( is_writeable($this->installdir."/Packages.xml") ||
!file_exists($this->installdir."/Packages.xml") &&
is_writeable($this->installdir) )
+ // check if we can write the Package.xml file for caching
+
+ if ( is_writeable($this->installdir."/$PackageFile") ||
!file_exists($this->installdir."/$PackageFile") &&
is_writeable($this->installdir) )
{
- $time = filemtime($this->installdir."/Packages.xml");
+ $time = filemtime($this->installdir."/$PackageFile");
if ($time < (time () - $this->cachetime )) {
print "Package-File to old. Get new one.<br>";
- if (function_exists("gzfile") && $fp =
@fopen($this->remotedir."/Packages.xml.gz","r")) {
- $fout = fopen($this->installdir."/Packages.xml.gz","w");
- while ($data = fread($fp,8192)) {
- fwrite ($fout, $data);
- }
- fclose($fout);
- }
- else
- {
- $data = file ($this->remotedir."/Packages.xml", "r");
- $fout = fopen($this->installdir."/Packages.xml","w");
+ $fp = fopen($this->remotedir."/$PackageFile","r");
+ $fout = fopen($this->installdir."/$PackageFile","w");
+ while ($data = fread($fp,8192)) {
fwrite ($fout, $data);
- fclose($fout);
}
-
+ fclose($fout);
+ fclose($fp);
}
- if (file_exists($this->installdir."/Packages.xml.gz"))
- {
- $Packages =
$this->infoFromDescriptionFile($this->installdir."/Packages.xml.gz",True);
- }
- else
- {
- $Packages =
$this->infoFromDescriptionFile($this->installdir."/Packages.xml");
- }
+ $Packages =
$this->infoFromDescriptionFile($this->installdir."/$PackageFile");
}
-
else
{
$Packages =
$this->infoFromDescriptionFile($this->remotedir."/Packages.xml");
@@ -352,6 +349,9 @@
return $Packages;
}
+ // }}}
+ // {{{ printCell()
+
function printCell($text)
{
if ($text)
@@ -364,6 +364,7 @@
}
}
+ // }}}
// {{{ _element_start()
@@ -436,11 +437,11 @@
// }}}
// {{{ infoFromDescriptionFile()
- function infoFromDescriptionFile($descfile,$GzFormat)
+ function infoFromDescriptionFile($descfile)
{
- $fp = @file_exists($descfile);
+ $fp = @fopen($descfile,"r");
if (!$fp) {
- return $this->raiseError("Unable to open $descfile");
+ return $this->raiseError("Unable to open $descfile in
".__FILE__.":".__LINE__);
}
$xp = @xml_parser_create();
@@ -461,7 +462,8 @@
// read the whole thing so we only get one cdata callback
// for each block of cdata
- if ($GzFormat && function_exists("gzfile") )
+
+ if (preg_match("/\.gz$/",$descfile))
{
$data = implode("",gzfile($descfile));
}