📄 go-pear.php
字号:
if (preg_match('/ok$/', $value)) { $value = preg_replace('/(ok)$/', '<span class="green">\1</span>', $value); }; if (preg_match('/^install ok:/', $value)) { $value = preg_replace('/^(install ok:)/', '<span class="green">\1</span>', $value); }; if (preg_match('/^Warning:/', $value)) { $value = '<span style="color: #ff0000">'.$value.'</span>'; }; $out[$line] = $value; }; $out = nl2br(implode("\n",$out)); ob_end_clean(); displayHTML('install', $out); } // Little hack, this will be fixed in PEAR later if ( WINDOWS ) { clearstatcache(); @unlink($bin_dir.DIRECTORY_SEPARATOR.'.tmppear'); } exit;}// Little hack, this will be fixed in PEAR laterif ( WINDOWS ) { clearstatcache(); @unlink($bin_dir.DIRECTORY_SEPARATOR.'.tmppear');}if (WINDOWS && !WEBINSTALLER) { win32CreateRegEnv();}// Set of functions following// {{{ download_url()function download_url($url, $destfile = null, $proxy = null){ $use_suggested_filename = ($destfile === null); if ($use_suggested_filename) { $destfile = basename($url); } $tmp = parse_url($url); if (empty($tmp['port'])) { $tmp['port'] = 80; } if (empty($proxy)) { $fp = fsockopen($tmp['host'], $tmp['port'], $errno, $errstr); //print "\nconnecting to $tmp[host]:$tmp[port]\n"; } else { $tmp_proxy = parse_url($proxy); $phost = $tmp_proxy['host']; $pport = $tmp_proxy['port']; $fp = fsockopen($phost, $pport, $errno, $errstr); //print "\nconnecting to $phost:$pport\n"; } if (!$fp) { bail("download of $url failed: $errstr ($errno)\n"); } if (empty($proxy)) { $path = $tmp['path']; } else { $path = "http://$tmp[host]:$tmp[port]$tmp[path]"; } if (isset($tmp['query'])) { $path .= "?$tmp[query]"; } if (isset($tmp['fragment'])) { $path .= "#$tmp[fragment]"; } $request = "GET $path HTTP/1.0\r\nHost: $tmp[host]:$tmp[port]\r\n". "User-Agent: go-pear\r\n"; if (!empty($proxy) && $tmp_proxy['user'] != '') { $request .= 'Proxy-Authorization: Basic ' . base64_encode($tmp_proxy['user'] . ':' . $tmp_proxy['pass']) . "\r\n";// print "\nauthenticating against proxy with : user = ${tmp_proxy['user']} \n";// print "and pass = ${tmp_proxy['pass']}\n"; } // if $request .= "\r\n"; fwrite($fp, $request); $cdh = "content-disposition:"; $cdhl = strlen($cdh); $content_length = 0; while ($line = fgets($fp, 2048)) { if (trim($line) == '') { break; } if (preg_match('/^Content-Length: (.*)$/i', $line, $matches)) { $content_length = trim($matches[1]); }; if ($use_suggested_filename && !strncasecmp($line, $cdh, $cdhl)) { if (eregi('filename="([^"]+)"', $line, $matches)) { $destfile = basename($matches[1]); } } } if ($content_length) { displayHTMLSetDownload($destfile); }; $wp = fopen($destfile, "wb"); if (!$wp) { bail("could not open $destfile for writing\n"); } $bytes_read = 0; $progress = 0; while ($data = fread($fp, 2048)) { fwrite($wp, $data); $bytes_read += strlen($data); if ($content_length != 0 && floor($bytes_read * 10 / $content_length) != $progress) { $progress = floor($bytes_read * 10 / $content_length); displayHTMLDownloadProgress($progress * 10); }; } fclose($fp); fclose($wp); return $destfile;}// }}}// {{{ which()function which($program, $dont_search_in = false){ if (WINDOWS) { if ($_path=my_env('Path')) { $dirs = explode(';', $_path); } else { $dirs = explode(';', my_env('PATH')); } if ($dont_search_in && ($key = array_search($dont_search_in, $dirs)) !== false) { unset($dirs[$key]); } foreach ($dirs as $dir) { $tmp = "$dir\\$program"; if (file_exists($ret = "$tmp.exe") || file_exists($ret = "$tmp.com") || file_exists($ret = "$tmp.bat") || file_exists($ret = "$tmp.cmd")) { return $ret; } } } else { $dirs = explode(':', my_env('PATH')); if ($dont_search_in && ($key = array_search($dont_search_in, $dirs)) !== false) { unset($dirs[$key]); } foreach ($dirs as $dir) { if (is_executable("$dir/$program")) { return "$dir/$program"; } } } return false;}// }}}// {{{ bail()function bail($msg = ''){ global $ptmp, $origpwd; if ($ptmp && is_dir($ptmp)) { chdir($origpwd); rm_rf($ptmp); } if ($msg && WEBINSTALLER) { $msg = @ob_get_contents() ."\n\n". $msg; @ob_end_clean(); displayHTML('error', $msg); exit; }; if ($msg && !WEBINSTALLER) { die($msg); }}// }}}// {{{ mkdir_p()function mkdir_p($dir, $mode = 0777){ $lastdir = ''; if (@is_dir($dir)) { return true; } $parent = dirname($dir); $parent_exists = (int)@is_dir($parent); $ok = true; if (!@is_dir($parent) && $parent != $dir) { $ok = mkdir_p(dirname($dir), $mode); } if ($ok) { $ok = @mkdir($dir, $mode); if (!$ok) { print "mkdir failed: $dir\n"; } } return $ok;}// }}}// {{{ rm_rf()function rm_rf($path){ if (@is_dir($path)) { $dp = opendir($path); while ($ent = readdir($dp)) { if ($ent == '.' || $ent == '..') { continue; } $file = $path . DIRECTORY_SEPARATOR . $ent; if (@is_dir($file)) { rm_rf($file); } else { unlink($file); } } closedir($dp); return rmdir($path); } else { return @unlink($path); }}// }}}// {{{ tmpdir()/* * Fixes for winXP/wrong tmp set by Urs Gehrig (urs@circle.ch) */function tmp_dir(){ if (WINDOWS){ if ( my_env('TEMP') ) { $_temp = my_env('TEMP'); } elseif ( my_env('TMP') ) { $_temp = my_env('TMP'); } elseif ( my_env('windir') ) { $_temp = my_env('windir') . '\temp'; } elseif ( my_env('SystemRoot') ) { $_temp = my_env('SystemRoot') . '\temp'; } // handle ugly ENV var like \Temp instead of c:\Temp $dirs = explode("\\", realpath($_temp)); if(strpos($_temp, ":") != 1) { unset($_temp); $_dirs = array(); foreach($dirs as $key => $val) { if((boolean)$val ) { $_dirs[] = str_replace("/", "", $val); } } unset($dirs); $dirs = $_dirs; array_unshift ($dirs, "c:" ); $_temp = $dirs[0]; for($i = 1;$i < count($dirs);$i++) { $_temp .= "//" . $dirs[$i]; } } $ptmp = $_temp; return $_temp; } if (my_env('TMPDIR')) { return my_env('TMPDIR'); } return '/tmp';}// }}}// {{{ my_env()/*(cox) In my system PHP 4.2.1 (both cgi & cli) $_ENV is empty but getenv() does work fine*/function my_env($var){ if (is_array($_ENV) && isset($_ENV[$var])) { return $_ENV[$var]; } return getenv($var);}// }}}// {{{ detect_install_dirs()function detect_install_dirs($_prefix = null) { global $prefix, $bin_dir, $php_dir, $php_bin, $doc_dir, $data_dir, $test_dir; if (WINDOWS) { if ($_prefix === null) { $prefix = getcwd(); } else { $prefix = $_prefix; } if (!@is_dir($prefix)) { if (@is_dir('c:\php4')) { $prefix = 'c:\php4'; } elseif (@is_dir('c:\php')) { $prefix = 'c:\php'; } } $bin_dir = '$prefix'; $php_dir = '$prefix\pear'; $doc_dir = '$php_dir\docs'; $data_dir = '$php_dir\data'; $test_dir = '$php_dir\tests'; /* * Detects php.exe */ if( $t=getenv('PHP_PEAR_PHP_BIN') ){ $php_bin = $t; } elseif ($t=getenv('PHP_BIN') ) { $php_bin = $t; } elseif ( $t=which('php') ) { $php_bin = $t; } elseif ( is_file($prefix.'\cli\php.exe') ) { $php_bin = $prefix.'\cli\php.exe'; } elseif ( is_file($prefix.'\php.exe') ) { $php_bin = $prefix.'\php.exe'; } if( $php_bin && !is_file($php_bin) ){ $php_bin = ''; } else { if(!ereg(":",$php_bin)){ $php_bin = getcwd().DIRECTORY_SEPARATOR.$php_bin; } } if (!is_file($php_bin)) { if (is_file('c:/php/cli/php.exe')) { $php_bin = 'c:/php/cli/php.exe'; } elseif (is_file('c:/php4/cli/php.exe')) { $php_bin = 'c:/php4/cli/php.exe'; } } } else { if ($_prefix === null) { $prefix = dirname(PHP_BINDIR); } else { $prefix = $_prefix; } $bin_dir = '$prefix/bin'; $php_dir = '$prefix/share/pear'; $doc_dir = '$php_dir/docs'; $data_dir = '$php_dir/data'; $test_dir = '$php_dir/tests'; // check if the user has installed PHP with PHP or GNU layout if (@is_dir("$prefix/lib/php/.registry")) { $php_dir = '$prefix/lib/php'; } elseif (@is_dir("$prefix/share/pear/lib/.registry")) { $php_dir = '$prefix/share/pear/lib'; $doc_dir = '$prefix/share/pear/docs'; $data_dir = '$prefix/share/pear/data'; $test_dir = '$prefix/share/pear/tests'; } elseif (@is_dir("$prefix/share/php/.registry")) { $php_dir = '$prefix/share/php'; } }}// }}}// {{{ displayHTMLHeaderfunction displayHTMLHeader(){?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head> <title>PEAR :: Installer :: Go-PEAR</title> <style type="text/css"> <!-- a { color:#000000; text-decoration: none; } a:visited { color:#000000; text-decoration: none; } a:active { color:#000000; text-decoration: none; } a:hover { color:#000000; text-decoration: underline; } a.green { color:#006600; text-decoration: none; } a.green:visited { color:#006600; text-decoration: none; } a.green:active { color:#006600; text-decoration: none; } a.green:hover { color:#006600; text-decoration: underline; } body, td, th { font-family: verdana,arial,helvetica,sans-serif; font-size: 90%; } p { font-family: verdana,arial,helvetica,sans-serif; } th.pack { color: #FFFFFF; background: #009933; text-align: right; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -