cvs: pear /PEAR_Frontend_Web WebInstaller.php /PEAR_Frontend_Web/Frontend Web.php

From: Date: Sun, 02 Jun 2002 12:26:00 +0000
Subject: cvs: pear /PEAR_Frontend_Web WebInstaller.php /PEAR_Frontend_Web/Frontend Web.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-4362@lists.php.net to get a copy of this message
dickmann Sun Jun 2 08:26:00 2002 EDT Modified files: /pear/PEAR_Frontend_Web WebInstaller.php /pear/PEAR_Frontend_Web/Frontend Web.php Log: add PHPdoc comments. some cosmetics

Index: pear/PEAR_Frontend_Web/WebInstaller.php diff -u pear/PEAR_Frontend_Web/WebInstaller.php:1.4 pear/PEAR_Frontend_Web/WebInstaller.php:1.5 --- pear/PEAR_Frontend_Web/WebInstaller.php:1.4 Sat Jun 1 18:54:21 2002 +++ pear/PEAR_Frontend_Web/WebInstaller.php Sun Jun 2 08:26:00 2002 @@ -1,98 +1,46 @@ <?php +/* + +----------------------------------------------------------------------+ + | PHP Version 4 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2002 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: WebInstaller.php,v 1.5 2002/06/02 12:26:00 dickmann Exp $ +*/ + + // Include needed files require_once 'PEAR.php'; require_once 'PEAR/Config.php'; require_once 'PEAR/Command.php'; - // Cient requests an Image/Stylesheet - if (isset($_GET["css"])) - { - $images = array( - "style" => "style.css", - "dhtml" => "dhtml.css", - ); - Header("Content-Type: text/css"); - readfile(dirname(__FILE__).'/Frontend/Web/'.$images[$_GET["css"]]); - exit; - }; - if (isset($_GET["js"])) - { - $js = array( - "dhtml" => "dhtml.js", - "nodhtml" => "nodhtml.js", - ); - Header("Content-Type: text/js"); - readfile(dirname(__FILE__).'/Frontend/Web/'.$js[$_GET["js"]]); - exit; - }; - if (isset($_GET["img"])) - { - $images = array( - "logout" => array( - "type" => "gif", - "file" => "logout.gif", - ), - "login" => array( - "type" => "gif", - "file" => "login.gif", - ), - "config" => array( - "type" => "gif", - "file" => "config.gif", - ), - "pkglist" => array( - "type" => "png", - "file" => "pkglist.png", - ), - "pkgsearch" => array( - "type" => "png", - "file" => "pkgsearch.png", - ), - "package" => array( - "type" => "jpeg", - "file" => "package.jpg", - ), - "category" => array( - "type" => "jpeg", - "file" => "category.jpg", - ), - "install" => array( - "type" => "gif", - "file" => "install.gif", - ), - "uninstall" => array( - "type" => "gif", - "file" => "trash.gif", - ), - "info" => array( - "type" => "gif", - "file" => "info.gif", - ), - "infoplus" => array( - "type" => "gif", - "file" => "infoplus.gif", - ), - "pear" => array( - "type" => "gif", - "file" => "pearsmall.gif", - ), - "error" => array( - "type" => "gif", - "file" => "error.gif", - ), - ); - Header("Content-Type: image/".$images[$_GET["img"]]['type']); - readfile(dirname(__FILE__).'/Frontend/Web/'.$images[$_GET["img"]]['file']); - exit; - }; - // Init PEAR Installer Code and WebFrontend PEAR_Command::setFrontendType("Web"); $ui = &PEAR_Command::getFrontendObject(); PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($ui, "displayFatalError")); + + // Cient requests an Image/Stylesheet/Javascript + if (isset($_GET["css"])) { + $ui->outputFrontendFile($_GET["css"], 'css'); + }; + if (isset($_GET["js"])) { + $ui->outputFrontendFile($_GET["js"], 'js'); + }; + if (isset($_GET["img"])) { + $ui->outputFrontendFile($_GET["img"], 'image'); + }; $config = &PEAR_Config::singleton($pear_user_config, ''); -// $config->store('user'); $verbose = $config->get("verbose"); $cmdopts = array(); $opts = array(); @@ -131,8 +79,10 @@ exit; case 'search': list($name, $description) = $ui->userDialog('search', - array('Package Name', 'Package Info'), - array(), array(), 'Package Search', 'pkgsearch'); + array('Package Name', 'Package Info'), // Prompts + array(), array(), // Types, Defaults + 'Package Search', 'pkgsearch' // Title, Icon + ); $command = $_GET["command"]; $params = array($name, $description); @@ -166,6 +116,7 @@ } }; + // If no other command is specified, the standard command 'list-all' is called $command = "list-all"; $params = array(); if (isset($_GET["info"])) Index: pear/PEAR_Frontend_Web/Frontend/Web.php diff -u pear/PEAR_Frontend_Web/Frontend/Web.php:1.6 pear/PEAR_Frontend_Web/Frontend/Web.php:1.7 --- pear/PEAR_Frontend_Web/Frontend/Web.php:1.6 Sat Jun 1 18:54:22 2002 +++ pear/PEAR_Frontend_Web/Frontend/Web.php Sun Jun 2 08:26:00 2002 @@ -16,7 +16,7 @@ | Author: Christian Dickmann <dickmann@php.net> | +----------------------------------------------------------------------+ - $Id: Web.php,v 1.6 2002/06/01 22:54:22 dickmann Exp $ + $Id: Web.php,v 1.7 2002/06/02 12:26:00 dickmann Exp $ */ require_once "PEAR.php"; @@ -24,6 +24,20 @@ 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 @@ -34,13 +48,6 @@ * @access public */ var $type = 'Web'; - var $lp = ''; // line prefix - var $tpl; - var $table; - var $data = array(); - var $_log; - - var $params = array(); // }}} @@ -58,12 +65,12 @@ function displayLine($text) { -// print "$this->lp$text<br>\n"; + trigger_error("Frontend::display deprecated", E_USER_ERROR); } function display($text) { - print $text; + trigger_error("Frontend::display deprecated", E_USER_ERROR); } // }}} @@ -72,25 +79,7 @@ function userConfirm($prompt, $default = 'yes') { - static $positives = array('y', 'yes', 'on', '1'); - static $negatives = array('n', 'no', 'off', '0'); - print "$this->lp$prompt [$default] : "; - $fp = fopen("php://stdin", "r"); - $line = fgets($fp, 2048); - fclose($fp); - $answer = strtolower(trim($line)); - if (empty($answer)) { - $answer = $default; - } - if (in_array($answer, $positives)) { - return true; - } - if (in_array($answer, $negatives)) { - return false; - } - if (in_array($default, $positives)) { - return true; - } + trigger_error("Frontend::display deprecated", E_USER_ERROR); return false; } @@ -175,9 +164,9 @@ $tpl->setVariable("Error", $msg); $command_map = array( - "install" => "list-all", + "install" => "list-all", "uninstall" => "list-all", - "upgrade" => "list-all", + "upgrade" => "list-all", ); if (isset($_GET['command'])) { if (isset($command_map[$_GET['command']])) @@ -187,7 +176,6 @@ $tpl->show(); exit; - return true; } // }}} @@ -202,7 +190,6 @@ function displayFatalError($eobj, $title = 'Error', $img = 'error') { $this->displayError($eobj, $title, $img); - exit(1); } // }}} @@ -298,7 +285,7 @@ /** * Output details of one package * - * @param array $data array containing all information about the package + * @param array $data array containing all information about the package * * @access private * @@ -361,10 +348,6 @@ }; $tpl->show(); - - - - } /** @@ -442,6 +425,7 @@ function userDialog($command, $prompts, $types = array(), $defaults = array(), $title = '', $icon = '') { + // If this is an POST Request, we can return the userinput if (isset($_GET["command"]) && $_GET["command"]==$command && $_SERVER["REQUEST_METHOD"] == "POST") { @@ -451,6 +435,7 @@ return $result; }; + // Assign title and icon to some commands switch ($command) { case 'login': @@ -466,15 +451,13 @@ if (is_array($prompts)) { $maxlen = 0; - foreach($prompts as $key => $prompt) - { + foreach($prompts as $key => $prompt) { if (strlen($prompt) > $maxlen) { $maxlen = strlen($prompt); }; }; - foreach($prompts as $key => $prompt) - { + foreach($prompts as $key => $prompt) { $tpl->setCurrentBlock("InputField"); $type = (isset($types[$key]) ? $types[$key] : 'text'); $tpl->setVariable("prompt", $prompt); @@ -505,6 +488,102 @@ { $GLOBALS['_PEAR_Frontend_Web_log'] .= $text."\n"; return true; + } + + /** + * Sends the required file along with Headers and exits the script + * + * @param string $handle handle of the requested file + * @param string $group group of the requested file + * + * @access public + * + * @return null nothing, because script exits + */ + + function outputFrontendFile($handle, $group) + { + $handles = array( + "css" => array( + "style" => "style.css", + "dhtml" => "dhtml.css", + ), + "js" => array( + "dhtml" => "dhtml.js", + "nodhtml" => "nodhtml.js", + ), + "image" => array( + "logout" => array( + "type" => "gif", + "file" => "logout.gif", + ), + "login" => array( + "type" => "gif", + "file" => "login.gif", + ), + "config" => array( + "type" => "gif", + "file" => "config.gif", + ), + "pkglist" => array( + "type" => "png", + "file" => "pkglist.png", + ), + "pkgsearch" => array( + "type" => "png", + "file" => "pkgsearch.png", + ), + "package" => array( + "type" => "jpeg", + "file" => "package.jpg", + ), + "category" => array( + "type" => "jpeg", + "file" => "category.jpg", + ), + "install" => array( + "type" => "gif", + "file" => "install.gif", + ), + "uninstall" => array( + "type" => "gif", + "file" => "trash.gif", + ), + "info" => array( + "type" => "gif", + "file" => "info.gif", + ), + "infoplus" => array( + "type" => "gif", + "file" => "infoplus.gif", + ), + "pear" => array( + "type" => "gif", + "file" => "pearsmall.gif", + ), + "error" => array( + "type" => "gif", + "file" => "error.gif", + ), + ), + ); + + $file = $handles[$group][$handle]; + switch ($group) + { + case 'css': + Header("Content-Type: text/css"); + readfile(dirname(__FILE__).'/Web/'.$file); + exit; + case 'image': + Header("Content-Type: image/".$file['type']); + readfile(dirname(__FILE__).'/Web/'.$file['file']); + exit; + case 'js': + Header("Content-Type: text/javascript"); + readfile(dirname(__FILE__).'/Web/'.$file); + exit; + }; } // }}}
« previous php.pear.cvs (#4362) next »