cvs: php4 /pear/Experimental/PEAR WebInstaller.php

From: Date: Sun, 08 Jul 2001 14:52:20 +0000
Subject: cvs: php4 /pear/Experimental/PEAR WebInstaller.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-238@lists.php.net to get a copy of this message
chregu Sun Jul 8 10:52:20 2001 EDT Modified files: /php4/pear/Experimental/PEAR WebInstaller.php Log: Included some information to be printed.

Index: php4/pear/Experimental/PEAR/WebInstaller.php diff -u php4/pear/Experimental/PEAR/WebInstaller.php:1.4 php4/pear/Experimental/PEAR/WebInstaller.php:1.5 --- php4/pear/Experimental/PEAR/WebInstaller.php:1.4 Sun Jul 8 06:44:01 2001 +++ php4/pear/Experimental/PEAR/WebInstaller.php Sun Jul 8 10:52:18 2001 @@ -29,6 +29,8 @@ * $installer->start(); * ?> * + * and put PEAR/WebInstaller.php (this script) anywhere in your include_path. + * * (http://php.chregu.tv/pear/ is just for testing purposes until this * system runs on pear.php.net, but feel free to use it till then) * @@ -52,6 +54,7 @@ * take the writeable off the directory..) * * TODO: + * - More Error Detection * - Grouping of Packages * - Show installed Packages (from /var/lib/php/packages.lst?) * - Add possibility to install a package (.tgz) from the local file @@ -97,6 +100,7 @@ /** how many seconds we should cache Packages.xml */ var $cachetime = 3600; + var $printlogger = True; // }}} // {{{ constructor @@ -130,13 +134,20 @@ // {{{ start() function start() { - global $HTTP_POST_VARS; + global $HTTP_POST_VARS,$HTTP_GET_VARS; //print header $this->header(); + $this->loggerStart(); + //if some checkboxes for installation were selected, install. - if ($HTTP_POST_VARS["InstPack"]) { + if ($HTTP_GET_VARS["help"]) { + + $this->help($HTTP_GET_VARS["help"]); + } + + elseif ($HTTP_POST_VARS["InstPack"]) { $this->installPackages(array_keys($HTTP_POST_VARS["InstPack"])); } @@ -156,9 +167,10 @@ require_once "PEAR/Installer.php"; $installer =& new PEAR_Installer(); $installer->phpdir = $this->installdir; + $this->loggerEnd(); print "<TABLE CELLSPACING=0 BORDER=0 CELLPADDING=1>"; print "<TR><TD BGCOLOR=\"#000000\">\n"; - print "<TABLE CELLSPACING=1 BORDER=0 CELLPADDING=3>\n"; + print "<TABLE CELLSPACING=1 BORDER=0 CELLPADDING=3 width=100%>\n"; print " <TR BGCOLOR=\"#e0e0e0\">\n"; print " <TH>Package</TH>\n"; print " <TH>Status</TH>\n"; @@ -201,8 +213,6 @@ } print "</td></tr>\n"; } - - print "</td></tr>"; print "</table>"; print "<TABLE CELLSPACING=1 BORDER=0 CELLPADDING=3 width=\"100%\">\n"; @@ -219,13 +229,20 @@ function printTable() { - + global $PHP_SELF; $Packages = $this->getPackages(); if (PEAR::IsError($Packages)) { - print $Packages->message; + if ($this->printlogger) { + $this->logger($Packages->message); + } + else + { + print $Packages->message; + } return $Packages; } + $this->loggerEnd(); print "<FORM action=\"$GLOBALS[PHP_SELF]\" method=\"post\">\n"; print "<TABLE CELLSPACING=0 BORDER=0 CELLPADDING=1>"; print "<TR><TD BGCOLOR=\"#000000\">\n"; @@ -239,7 +256,8 @@ print " <TH>Release notes</TH>\n"; print " </TR>\n"; $i = 0; - sort($Packages); + + ksort($Packages); foreach ( $Packages as $package) { if (++$i % 2) { @@ -254,12 +272,12 @@ print "<TR>\n"; - print "<TD align=\"right\" BGCOLOR=\"$bg2\">"; + print "<TD align=\"middle\" BGCOLOR=\"$bg2\">"; print "<input type=\"checkbox\" name=\"InstPack[".$package["name"]."-".$package["version"]."]\">\n"; print "</TD>\n"; print " <TD BGCOLOR=\"$bg1\">"; - $this->printCell ($package["name"]); + print $this->printCell ($package[name],"http://pear.php.net/pkginfo.php?package=$package[name]"); print "</TD>\n"; print "<TD BGCOLOR=\"$bg2\">"; @@ -302,9 +320,13 @@ print "<th align=left width=\"10%\" nowrap>\n"; print "PEAR Repository: </th><td>$this->remotedir</td></tr>\n"; + print " <TR BGCOLOR=\"#e0e0e0\">\n"; + print "<th align=left width=\"10%\" nowrap>\n"; + print "Caching Time: </th><td>$this->cachetime seconds</td></tr>\n"; + print "</table>\n"; print "</tr></td></table></FORM>\n"; - + print "<a href=\"$PHP_SELF?help=1\">Help</A>\n"; } // }}} @@ -314,7 +336,7 @@ * If the zlib-extension is compiled in, Packages.xml.gz is used instead. */ - function getPackages () + function getPackages ($TryGz = True) { // if we can write to the installdir, cache the Packages.xml there @@ -322,7 +344,7 @@ $PackageFile = "Packages.xml"; // check if we have the zlib-extension compiled in - if (function_exists("gzfile")) { $useGz = True; $PackageFile .= ".gz";} + if ($TryGz && function_exists("gzfile")) { $useGz = True; $PackageFile .= ".gz";} // check if we can write the Package.xml file for caching @@ -331,32 +353,58 @@ $time = filemtime($this->installdir."/$PackageFile"); if ($time < (time () - $this->cachetime )) { - print "Package-File to old. Get new one.<br>"; - $fp = fopen($this->remotedir."/$PackageFile","r"); + $this->logger("$PackageFile to old. Get new one."); + $fp = @fopen($this->remotedir."/$PackageFile","r"); + if (!$fp) { + if ($useGz) + { + $this->logger("$PackageFile could not be read. Try uncompressed one"); + return $this->getPackages(False); + } + else { + $this->logger("$PackageFile could not be read."); + return $this->raiseError("$PackageFile could not be read."); + } + } $fout = fopen($this->installdir."/$PackageFile","w"); while ($data = fread($fp,8192)) { fwrite ($fout, $data); } fclose($fout); fclose($fp); + $this->logger("Got $PackageFile"); } + else { + $this->logger("Cached $PackageFile seems new enough"); + } $Packages = $this->infoFromDescriptionFile($this->installdir."/$PackageFile"); } else { + $this->logger("$PackageFile can not be cached, because Install-Dir or $PackageFile is not writeable. Get it each time from the server"); $Packages = $this->infoFromDescriptionFile($this->remotedir."/Packages.xml"); } + $this->logger("Got Packages"); return $Packages; } // }}} // {{{ printCell() - function printCell($text) + function printCell($text,$link = Null) { if ($text) { + if ($link) { + print "<a href=\"$link\" style=\"color: #000000;\">"; + } + print "$text"; + + if ($link) { + print "</a>"; + } + } else { @@ -365,6 +413,9 @@ } // }}} + /* The following 4 functions are taken from PEAR/Common.php written by Stig Bakken + I had to adjust to use the Packages.xml format. + */ // {{{ _element_start() @@ -496,7 +547,7 @@ { print "<html> <head> - <title>PEAR::Installer</title>\n"; + <title>PEAR::WebInstaller</title>\n"; if (file_exists("./style.css")) { print '<link rel="stylesheet" href="/style.css">'; @@ -515,6 +566,62 @@ } // }}} + + function logger ($text) { + + if ($this->printlogger) { + if (++$this->logcol % 2) { + $bg1 = "#ffffff"; + $bg2 = "#f0f0f0"; + } + else { + $bg1 = "#f0f0f0"; + $bg2 = "#e0e0e0"; + } + print "<TR>\n"; + print "<TD BGCOLOR=\"$bg1\">".date("h:m:i",time())."</td>"; + print "<TD BGCOLOR=\"$bg2\">"; + print "$text\n"; + print "</TD>\n"; + print "</tr>"; + } + } + function loggerStart () { + if ($this->printlogger) { + print "<TABLE CELLSPACING=0 BORDER=0 CELLPADDING=1>"; + print "<TR><TD BGCOLOR=\"#000000\">\n"; + print "<TABLE CELLSPACING=1 BORDER=0 CELLPADDING=3 width=\"100%\">\n"; + } + } + + function loggerEnd () { + if ($this->printlogger) { + print "</table></td></tr></table>"; + } + } + function help ($Full = False) { +global $PHP_SELF; + $this->loggerEnd(); + print "From the WebInstaller.php introduction: <p>"; + + // $file = implode("",file(__FILE__)); + $file = file(__FILE__); + foreach($file as $line) + { + if ($Full != 2 && strstr($line,"require_once")){ + break; + } + $help .= $line; + } + highlight_string($help); + print "<p>"; + if ($Full != 2) { + print "<a href=\"$PHP_SELF?help=2\">See the full source</a><p>\n"; + } + + print "<a href=\"$PHP_SELF\">Back to the packages overview</A>\n"; + } + } ?>
« previous php.pear.cvs (#238) next »