📄 web.php
字号:
<?php/* +----------------------------------------------------------------------+ | PHP Version 4 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2003 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/2_02.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Christian Dickmann <dickmann@php.net> | +----------------------------------------------------------------------+ $Id: Web.php,v 1.22 2003/01/04 11:55:56 mj Exp $*/require_once "PEAR.php";require_once "PEAR/Remote.php";require_once "HTML/Template/IT.php";require_once "Net/UserAgent/Detect.php";require_once "Pager/Pager.php";/*** PEAR_Frontend_Web is a HTML based Webfrontend for the PEAR Installer** The Webfrontend provides basic functionality of the Installer, such as* a package list grouped by categories, a search mask, the possibility* to install/upgrade/uninstall packages and some minor things.* PEAR_Frontend_Web makes use of the PEAR::HTML_IT Template engine which* provides the possibillity to skin the Installer.** @author Christian Dickmann <dickmann@php.net>* @package PEAR_Frontend_Web* @access private*/class PEAR_Frontend_Web extends PEAR{ // {{{ properties /** * What type of user interface this frontend is for. * @var string * @access public */ var $type = 'Web'; /** * Container, where values can be saved temporary * @var array * @access private */ var $_data = array(); // }}} var $config; var $_no_delete_pkgs = array( 'PEAR', 'PEAR_Frontend_Web', 'Archive_Tar', 'Console_Getopt', 'XML_RPC', 'Net_UserAgent_Detect', 'Pager'); // {{{ constructor function PEAR_Frontend_Web() { parent::PEAR(); $GLOBALS['_PEAR_Frontend_Web_log'] = ''; $this->config = $GLOBALS['_PEAR_Frontend_Web_config']; } // }}} // XXX some methods from CLI following. should be deleted in the near future // {{{ displayLine(text) function displayLine($text) { trigger_error("Frontend::display deprecated", E_USER_ERROR); } function display($text) { trigger_error("Frontend::display deprecated", E_USER_ERROR); } // }}} // {{{ userConfirm(prompt, [default]) function userConfirm($prompt, $default = 'yes') { trigger_error("Frontend::display deprecated", E_USER_ERROR); return false; } // }}} function displayStart() { $tpl = $this->_initTemplate("start.tpl.html", 'PEAR Installer'); $tpl->setVariable('Version', '0.1'); $tpl->show(); exit; } /** * Initialize a TemplateObject, add a title, and icon and add JS and CSS for DHTML * * @param string $file filename of the template file * @param string $title (optional) title of the page * @param string $icon (optional) iconhandle for this page * @param boolean $useDHTML (optional) add JS and CSS for DHTML-features * * @access private * * @return object Object of HTML/IT - Template - Class */ function _initTemplate($file, $title = '', $icon = '', $useDHTML = true) { $tpl = new HTML_Template_IT(dirname(__FILE__)."/Web"); $tpl->loadTemplateFile($file); $tpl->setVariable("InstallerURL", $_SERVER["PHP_SELF"]); $tpl->setVariable("ImgPEAR", $_SERVER["PHP_SELF"].'?img=pear'); if ($title) $tpl->setVariable("Title", $title); if ($icon) { $tpl->setCurrentBlock("TitleBlock"); $tpl->setVariable("_InstallerURL", $_SERVER["PHP_SELF"]); $tpl->setVariable("_Title", $title); $tpl->setVariable("_Icon", $icon); $tpl->parseCurrentBlock(); }; $tpl->setCurrentBlock(); if ($useDHTML && Net_UserAgent_Detect::getBrowser('ie5up') == 'ie5up') $dhtml = true; else $dhtml = false; if ($dhtml) { $tpl->setVariable("JS", 'dhtml'); $css = '<link rel="stylesheet" href="'.$_SERVER['PHP_SELF'].'?css=dhtml" />'; $tpl->setVariable("DHTMLcss", $css); } else { $tpl->setVariable("JS", 'nodhtml'); }; if (!isset($_SESSION['_PEAR_Frontend_Web_js']) || $_SESSION['_PEAR_Frontend_Web_js'] == false) { $tpl->setCurrentBlock('JSEnable'); $tpl->setVariable('RedirectURL', $_SERVER['REQUEST_URI']. (!empty($_GET) ? '&' : '?') .'enableJS=1'); $tpl->parseCurrentBlock(); $tpl->setCurrentBlock(); }; return $tpl; } // {{{ displayError(eobj) /** * Display an error page * * @param mixed $eobj PEAR_Error object or string containing the error message * @param string $title (optional) title of the page * @param string $img (optional) iconhandle for this page * @param boolean $popup (optional) popuperror or normal? * * @access public * * @return null does not return anything, but exit the script */ function displayError($eobj, $title = 'Error', $img = 'error', $popup = false) { $msg = ''; if (isset($GLOBALS['_PEAR_Frontend_Web_log']) && trim($GLOBALS['_PEAR_Frontend_Web_log'])) $msg = trim($GLOBALS['_PEAR_Frontend_Web_log'])."\n\n"; if (PEAR::isError($eobj)) $msg .= trim($eobj->getMessage()); else $msg .= trim($eobj); $msg = nl2br($msg."\n"); $tplfile = ($popup ? "error.popup.tpl.html" : "error.tpl.html"); $tpl = $this->_initTemplate($tplfile, $title, $img); $tpl->setVariable("Error", $msg); $command_map = array( "install" => "list-all", "uninstall" => "list-all", "upgrade" => "list-all", ); if (isset($_GET['command'])) { if (isset($command_map[$_GET['command']])) $_GET['command'] = $command_map[$_GET['command']]; $tpl->setVariable("param", '?command='.$_GET['command']); }; $tpl->show(); exit; } // }}} // {{{ displayFatalError(eobj) /** * Alias for PEAR_Frontend_Web::displayError() * * @see PEAR_Frontend_Web::displayError() */ function displayFatalError($eobj, $title = 'Error', $img = 'error') { $this->displayError($eobj, $title, $img); } function displayErrorImg($eobj) { $msg = ''; if (isset($GLOBALS['_PEAR_Frontend_Web_log']) && trim($GLOBALS['_PEAR_Frontend_Web_log'])) $msg = trim($GLOBALS['_PEAR_Frontend_Web_log'])."\n\n"; $_SESSION['_PEAR_Frontend_Web_LastError'] = $eobj; $_SESSION['_PEAR_Frontend_Web_LastError_log'] = $msg; echo '<script language="javascript">'; printf('window.open("%s?command=show-last-error", "PEAR", "width=600, height=400");', $_SERVER["PHP_SELF"]); echo ' </script>'; printf('<img src="%s?img=install_fail" border="0">', $_SERVER['PHP_SELF']); exit; } // }}} /** * Output a list of packages, grouped by categories. Uses Paging * * @param array $data array containing all data to display the list * @param string $title (optional) title of the page * @param string $img (optional) iconhandle for this page * @param boolean $useDHTML (optional) add JS and CSS for DHTML-features * @param boolean $paging (optional) use Paging or not * * @access private * * @return boolean true (yep. i am an optimist) */ function _outputListAll($data, $title = 'Install / Upgrade / Remove PEAR Packages', $img = 'pkglist', $useDHTML = false, $paging = true) { $tpl = $this->_initTemplate("package.list.tpl.html", $title, $img, $useDHTML); if (!isset($data['data'])) { $data['data'] = array(); }; // Use PEAR::Pager to page Packages $pager =& new Pager(array( 'itemData' => $data['data'], 'perPage' => ($paging ? 5 : count($data['data'])), 'linkClass' => 'green', )); $data['data'] = $pager->getPageData(); $links = $pager->getLinks(); list($from, $to) = $pager->getOffsetByPageId(); // Generate Linkinformation to redirect to _this_ page after performing an action $links['current'] = '&pageID='.$pager->getCurrentPageID(); if (isset($_GET['mode'])) $links['current'] .= '&mode='.$_GET['mode']; else $_GET['mode'] = ''; if (isset($_GET['command']) && $_GET['command'] == 'search') $links['current'] .= '&redirect=search&0='.$_REQUEST[0].'&1='.$_REQUEST[1]; $modes = array( 'installed' => 'list installed packages', '' => 'list all packages', 'notinstalled' => 'list not installed packages', 'upgrades' => 'list avail. upgrades', ); unset($modes[$_GET['mode']]); $i = 1; foreach($modes as $mode => $text) { $tpl->setVariable('mode'.$i, ((!empty($mode)) ? '&mode='.$mode : '')); $tpl->setVariable('mode'.$i.'text', $text); $i++; }; $tpl->setVariable('Prev', $links['back']); $tpl->setVariable('Next', $links['next']); $tpl->setVariable('PagerFrom', $from); $tpl->setVariable('PagerTo', $to); $tpl->setVariable('PagerCount', $pager->numItems()); if (is_array($data['data'])) foreach($data['data'] as $category => $packages) { foreach($packages as $row) { list($pkgName, $pkgVersionLatest, $pkgVersionInstalled, $pkgSummary) = $row; $tpl->setCurrentBlock("Row"); $tpl->setVariable("ImgPackage", $_SERVER["PHP_SELF"].'?img=package'); $images = array( 'install' => '<img src="'.$_SERVER["PHP_SELF"].'?img=install" width="13" height="13" border="0" alt="install">', 'uninstall' => '<img src="'.$_SERVER["PHP_SELF"].'?img=uninstall" width="18" height="17" border="0" alt="uninstall">', 'upgrade' => '<img src="'.$_SERVER["PHP_SELF"].'?img=install" width="13" height="13" border="0" alt="upgrade">', 'info' => '<img src="'.$_SERVER["PHP_SELF"].'?img=info" width="17" height="19" border="0" alt="info">', 'infoExt' => '<img src="'.$_SERVER["PHP_SELF"].'?img=infoplus" width="18" height="19" border="0" alt="extended info">', ); $urls = array( 'install' => sprintf('%s?command=install&pkg=%s%s', $_SERVER["PHP_SELF"], $pkgName, $links['current']), 'uninstall' => sprintf('%s?command=uninstall&pkg=%s%s', $_SERVER["PHP_SELF"], $pkgName, $links['current']), 'upgrade' => sprintf('%s?command=upgrade&pkg=%s%s', $_SERVER["PHP_SELF"], $pkgName, $links['current']), 'info' => sprintf('%s?command=remote-info&pkg=%s', $_SERVER["PHP_SELF"], $pkgName), 'infoExt' => sprintf('%s?package=%s', 'http://pear.php.net/package-info.php', $row[0]), ); $compare = version_compare($pkgVersionLatest, $pkgVersionInstalled); $id = 'id="'.$pkgName.'_href"'; if (!$pkgVersionInstalled || $pkgVersionInstalled == "- no -") { $inst = sprintf('<a href="%s" onClick="return perform(\'%s\');" %s>%s</a>', $urls['install'], $pkgName, $id, $images['install']); $del = ''; } else if ($compare == 1) { $inst = sprintf('<a href="%s" onClick="return perform(\'%s\');" %s>%s</a>', $urls['upgrade'], $pkgName, $id, $images['upgrade']); $del = sprintf('<a href="%s" onClick="return deletePkg(\'%s\');" %s >%s</a>', $urls['uninstall'], $pkgName, $id, $images['uninstall']); } else { $del = sprintf('<a href="%s" onClick="return deletePkg(\'%s\');" %s >%s</a>', $urls['uninstall'], $pkgName, $id, $images['uninstall']); $inst = ''; }; $info = sprintf('<a href="%s">%s</a>', $urls['info'], $images['info']); $infoExt = sprintf('<a href="%s">%s</a>', $urls['infoExt'], $images['infoExt']); if (in_array($pkgName, $this->_no_delete_pkgs)) $del = ''; $tpl->setVariable("Latest", $pkgVersionLatest); $tpl->setVariable("Installed", $pkgVersionInstalled); $tpl->setVariable("Install", $inst); $tpl->setVariable("Delete", $del); $tpl->setVariable("Info", $info); $tpl->setVariable("InfoExt", $infoExt); $tpl->setVariable("Package", $pkgName); $tpl->setVariable("Summary", nl2br($pkgSummary)); $tpl->parseCurrentBlock(); }; $tpl->setCurrentBlock("Category"); $tpl->setVariable("categoryName", $category); $tpl->setVariable("ImgCategory", $_SERVER["PHP_SELF"].'?img=category'); $tpl->parseCurrentBlock(); }; $tpl->show(); return true; } function _getPackageDeps($deps) { if (count($deps) == 0) { return "<i>No dependencies registered.</i>\n"; } else { $lastversion = ''; $rel_trans = array( 'lt' => 'older than %s', 'le' => 'version %s or older', 'eq' => 'version %s', 'ne' => 'any version but %s', 'gt' => 'newer than %s', 'ge' => '%s or newer', ); $dep_type_desc = array( 'pkg' => 'PEAR Package', 'ext' => 'PHP Extension', 'php' => 'PHP Version', 'prog' => 'Program',
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -