📄 webinstaller.php
字号:
{
print " <font color=\"red\">(Directory is NOT writeable!)</font>";
}
print "</td></tr>\n";
print " <TR BGCOLOR=\"#f0f0f0\">\n";
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";
}
// }}}
// {{{ 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 ($TryGz = True)
{
// 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 ($TryGz && function_exists("gzfile")) { $useGz = True; $PackageFile .= ".gz";}
// check if we can write the Package.xml file for caching
if ( (file_exists($this->installdir."/$PackageFile") && is_writeable($this->installdir."/$PackageFile")) || !file_exists($this->installdir."/$PackageFile") && is_writeable($this->installdir) )
{
$time = filemtime($this->installdir."/$PackageFile");
if ($time < (time () - $this->cachetime )) {
$this->logger("$PackageFile too 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,$link = Null)
{
if ($text)
{
if ($link) {
print "<a href=\"$link\" style=\"color: #000000;\">";
}
print "$text";
if ($link) {
print "</a>";
}
}
else
{
print " ";
}
}
// }}}
/* 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()
function _element_start($xp, $name, $attribs)
{
array_push($this->element_stack, $name);
$this->current_element = $name;
$this->current_attributes = $attribs;
}
// }}}
// {{{ _element_end()
function _element_end($xp, $name)
{
array_pop($this->element_stack);
if ($name == "PACKAGE")
{
$this->AllPackages[$this->pkginfo["name"]] = $this->pkginfo;
$this->pkginfo = array();
}
$this->current_element = $this->element_stack[sizeof($this->element_stack)-1];
}
// }}}
// {{{ _pkginfo_cdata()
function _pkginfo_cdata($xp, $data)
{
$next = $this->element_stack[sizeof($this->element_stack)-1];
switch ($this->current_element) {
case "NAME":
$this->pkginfo["name"] .= $data;
break;
case "SUMMARY":
$this->pkginfo["summary"] .= $data;
break;
case "USER":
$this->pkginfo["maintainer_handle"] .= $data;
break;
case "EMAIL":
$this->pkginfo["maintainer_email"] .= $data;
break;
case "VERSION":
$this->pkginfo["version"] .= $data;
break;
case "DATE":
$this->pkginfo["release_date"] .= $data;
break;
case "NOTES":
$this->pkginfo["release_notes"] .= $data;
break;
case "DIR":
if (!$this->installdir) {
break;
}
$dir = trim($data);
// XXX add to file list
break;
case "FILE":
$role = strtolower($this->current_attributes["ROLE"]);
$file = trim($data);
// XXX add to file list
break;
}
}
// }}}
// {{{ infoFromDescriptionFile()
function infoFromDescriptionFile($descfile)
{
$fp = @fopen($descfile,"r");
if (!$fp) {
return $this->raiseError("Unable to open $descfile in ".__FILE__.":".__LINE__);
}
$xp = @xml_parser_create();
if (!$xp) {
return $this->raiseError("Unable to create XML parser.");
}
xml_set_object($xp, $this);
xml_set_element_handler($xp, "_element_start", "_element_end");
xml_set_character_data_handler($xp, "_pkginfo_cdata");
xml_parser_set_option($xp, XML_OPTION_CASE_FOLDING, true);
$this->element_stack = array();
$this->pkginfo = array();
$this->current_element = false;
$this->destdir = '';
// read the whole thing so we only get one cdata callback
// for each block of cdata
if (preg_match("/\.gz$/",$descfile))
{
$data = implode("",gzfile($descfile));
}
else
{
$data = implode("",file($descfile));
}
if (!@xml_parse($xp, $data, 1)) {
$msg = sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xp)),
xml_get_current_line_number($xp));
xml_parser_free($xp);
return $this->raiseError($msg);
}
xml_parser_free($xp);
foreach ($this->pkginfo as $k => $v) {
$this->pkginfo[$k] = trim($v);
}
return $this->AllPackages;
}
// }}}
// {{{ header()
function header ()
{
print "<html>
<head>
<title>PEAR::WebInstaller</title>\n";
if (file_exists("./style.css"))
{
print '<link rel="stylesheet" href="/style.css">';
}
print "</head>
<body bgcolor=\"#FFFFFF\">
<h3>PEAR::WebInstaller</h3>";
}
// }}}
// {{{ footer()
function footer () {
print "</body></html>";
}
// }}}
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 = 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";
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -