cvs: pear /PEAR_Frontend_Web WebInstaller.php /PEAR_Frontend_Web/Frontend Web.php /PEAR_Frontend_Web/Frontend/Web Thumbs.db package.list.tpl.html
style.css

From: Date: Sat, 01 Jun 2002 22:54:22 +0000
Subject: cvs: pear /PEAR_Frontend_Web WebInstaller.php /PEAR_Frontend_Web/Frontend Web.php /PEAR_Frontend_Web/Frontend/Web Thumbs.db package.list.tpl.html
style.css
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-4345@lists.php.net to get a copy of this message
dickmann Sat Jun 1 18:54:22 2002 EDT Removed files: /pear/PEAR_Frontend_Web/Frontend/Web Thumbs.db Modified files: /pear/PEAR_Frontend_Web WebInstaller.php /pear/PEAR_Frontend_Web/Frontend Web.php /pear/PEAR_Frontend_Web/Frontend/Web package.list.tpl.html style.css Log: add paging of packages using PEAR::Pager. add PHPdoc comments. fix some minor bugs.

Index: pear/PEAR_Frontend_Web/WebInstaller.php diff -u pear/PEAR_Frontend_Web/WebInstaller.php:1.3 pear/PEAR_Frontend_Web/WebInstaller.php:1.4 --- pear/PEAR_Frontend_Web/WebInstaller.php:1.3 Sat Jun 1 15:00:57 2002 +++ pear/PEAR_Frontend_Web/WebInstaller.php Sat Jun 1 18:54:21 2002 @@ -116,7 +116,7 @@ PEAR::raiseError(''); }; - $URL .= '#'.$_GET["pkg"]; + $URL .= '?pageID='.$_GET['pageID'].'#'.$_GET["pkg"]; Header("Location: ".$URL); exit; case 'remote-info': Index: pear/PEAR_Frontend_Web/Frontend/Web.php diff -u pear/PEAR_Frontend_Web/Frontend/Web.php:1.5 pear/PEAR_Frontend_Web/Frontend/Web.php:1.6 --- pear/PEAR_Frontend_Web/Frontend/Web.php:1.5 Sat Jun 1 15:01:00 2002 +++ pear/PEAR_Frontend_Web/Frontend/Web.php Sat Jun 1 18:54:22 2002 @@ -16,12 +16,13 @@ | Author: Christian Dickmann <dickmann@php.net> | +----------------------------------------------------------------------+ - $Id: Web.php,v 1.5 2002/06/01 19:01:00 dickmann Exp $ + $Id: Web.php,v 1.6 2002/06/01 22:54:22 dickmann Exp $ */ require_once "PEAR.php"; require_once "HTML/IT.php"; require_once "Net/UserAgent/Detect.php"; +require_once "Pager/Pager.php"; class PEAR_Frontend_Web extends PEAR { @@ -52,6 +53,7 @@ // }}} + // XXX some methods from CLI following. should be deleted in the near future // {{{ displayLine(text) function displayLine($text) @@ -65,8 +67,49 @@ } // }}} - // {{{ displayError(eobj) - function initTemplate($file, $title = '', $icon = '', $useDHTML = true) + + // {{{ userConfirm(prompt, [default]) + + 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; + } + return false; + } + + // }}} + + /** + * 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 IntegratedTemplate(dirname(__FILE__)."/Web"); $tpl->loadTemplateFile($file); @@ -101,6 +144,20 @@ 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 + * + * @access public + * + * @return null does not return anything, but exit the script + */ + function displayError($eobj, $title = 'Error', $img = 'error') { $msg = ''; @@ -114,7 +171,7 @@ $msg = nl2br($msg."\n"); - $tpl = $this->initTemplate("error.tpl.html", $title, $img); + $tpl = $this->_initTemplate("error.tpl.html", $title, $img); $tpl->setVariable("Error", $msg); $command_map = array( @@ -136,6 +193,12 @@ // }}} // {{{ 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); @@ -143,38 +206,42 @@ } // }}} - // {{{ userConfirm(prompt, [default]) - - 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; - } - return false; - } - - // }}} - function _outputListAll($data, $title = 'Install / Upgrade / Remove PEAR Packages', $img = 'pkglist', $useDHTML = true) + /** + * 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); + $tpl = $this->_initTemplate("package.list.tpl.html", $title, $img, $useDHTML); + + // 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(); + $links['current'] = '&pageID='.$pager->getCurrentPage(); + $tpl->setVariable('Prev', $links['back']); + $tpl->setVariable('Next', $links['next']); + $tpl->setVariable('PagerFrom', $from); + $tpl->setVariable('PagerTo', $to); + $tpl->setVariable('PagerCount', $pager->numItems()); + foreach($data['data'] as $category => $packages) { foreach($packages as $row) @@ -184,20 +251,20 @@ $compare = version_compare($row[1], $row[2]); if (!$row[2]) { $inst = sprintf( - '<a href="%s?command=install&pkg=%s"><img src="%s?img=install" border="0" alt="install"></a>', - $_SERVER["PHP_SELF"], $row[0], $_SERVER["PHP_SELF"]); + '<a href="%s?command=install&pkg=%s%s"><img src="%s?img=install" border="0" alt="install"></a>', + $_SERVER["PHP_SELF"], $row[0], $links['current'], $_SERVER["PHP_SELF"]); $del = ''; } else if ($compare == 1) { $inst = sprintf( - '<a href="%s?command=upgrade&pkg=%s"><img src="%s?img=install" border="0" alt="upgrade"></a>', - $_SERVER["PHP_SELF"], $row[0], $_SERVER["PHP_SELF"]); + '<a href="%s?command=upgrade&pkg=%s%s"><img src="%s?img=install" border="0" alt="upgrade"></a>', + $_SERVER["PHP_SELF"], $row[0], $links['current'], $_SERVER["PHP_SELF"]); $del = sprintf( - '<a href="%s?command=uninstall&pkg=%s"><img src="%s?img=uninstall" border="0" alt="uninstall"></a>', - $_SERVER["PHP_SELF"], $row[0], $_SERVER["PHP_SELF"]); + '<a href="%s?command=uninstall&pkg=%s%s"><img src="%s?img=uninstall" border="0" alt="uninstall"></a>', + $_SERVER["PHP_SELF"], $row[0], $links['current'], $_SERVER["PHP_SELF"]); } else { $del = sprintf( - '<a href="%s?command=uninstall&pkg=%s"><img src="%s?img=uninstall" border="0" alt="uninstall"></a>', - $_SERVER["PHP_SELF"], $row[0], $_SERVER["PHP_SELF"]); + '<a href="%s?command=uninstall&pkg=%s%s"><img src="%s?img=uninstall" border="0" alt="uninstall"></a>', + $_SERVER["PHP_SELF"], $row[0], $links['current'], $_SERVER["PHP_SELF"]); $inst = ''; }; $info=sprintf('<a href="%s?command=remote-info&pkg=%s"><img src="%s?img=info" border="0" alt="info"></a>', @@ -224,12 +291,23 @@ $tpl->parseCurrentBlock(); }; $tpl->show(); - + + return true; } + /** + * Output details of one package + * + * @param array $data array containing all information about the package + * + * @access private + * + * @return boolean true (yep. i am an optimist) + */ + function _outputPackageInfo($data) { - $tpl = $this->initTemplate("package.info.tpl.html", 'Package Management :: '.$data['name'], 'pkglist'); + $tpl = $this->_initTemplate("package.info.tpl.html", 'Package Management :: '.$data['name'], 'pkglist'); $tpl->setVariable("Latest", $data['stable']); $tpl->setVariable("Installed", $data['installed']); @@ -289,6 +367,17 @@ } + /** + * Output all kinds of data depending on the command which called this method + * + * @param mixed $data datastructure containing the information to display + * @param string $command command from which this method was called + * + * @access public + * + * @return mixed highly depends on the command + */ + function outputData($data, $command) { switch ($command) @@ -309,10 +398,11 @@ case 'list-all': return $this->_outputListAll($data); case 'search': - return $this->_outputListAll($data, 'Package Search :: Result', 'pkgsearch', false); + return $this->_outputListAll($data, 'Package Search :: Result', 'pkgsearch', false, false); case 'remote-info': return $this->_outputPackageInfo($data); case 'install': + case 'upgrade': case 'uninstall': return true; case 'login': @@ -332,6 +422,24 @@ return true; } + /** + * Display a formular and return the given input (yes. needs to requests) + * + * @param string $command command from which this method was called + * @param array $prompts associative array. keys are the inputfieldnames + * and values are the description + * @param array $types (optional) array of inputfieldtypes (text, password, + * etc.) keys have to be the same like in $prompts + * @param array $defaults (optional) array of defaultvalues. again keys have + * to be the same like in $prompts + * @param string $title (optional) title of the page + * @param string $icon (optional) iconhandle for this page + * + * @access public + * + * @return array input sended by the user + */ + function userDialog($command, $prompts, $types = array(), $defaults = array(), $title = '', $icon = '') { if (isset($_GET["command"]) && $_GET["command"]==$command @@ -342,8 +450,16 @@ $result[$key] = $_POST[$key]; return $result; }; + + switch ($command) + { + case 'login': + $title = 'Login'; + $icon = 'login'; + break; + }; - $tpl = $this->initTemplate("userDialog.tpl.html", $title, $icon); + $tpl = $this->_initTemplate("userDialog.tpl.html", $title, $icon); $tpl->setVariable("Command", $command); $tpl->setVariable("Headline", nl2br($this->data[$command])); @@ -375,9 +491,20 @@ exit; } + /** + * Write message to log + * + * @param string $text message which has to written to log + * + * @access public + * + * @return boolean true + */ + function log($text) { $GLOBALS['_PEAR_Frontend_Web_log'] .= $text."\n"; + return true; } // }}} Index: pear/PEAR_Frontend_Web/Frontend/Web/package.list.tpl.html diff -u pear/PEAR_Frontend_Web/Frontend/Web/package.list.tpl.html:1.3 pear/PEAR_Frontend_Web/Frontend/Web/package.list.tpl.html:1.4 --- pear/PEAR_Frontend_Web/Frontend/Web/package.list.tpl.html:1.3 Sat Jun 1 15:01:01 2002 +++ pear/PEAR_Frontend_Web/Frontend/Web/package.list.tpl.html Sat Jun 1 18:54:22 2002 @@ -1,4 +1,20 @@ <!-- INCLUDE header.inc.tpl.html --> + <TABLE border="0"> + <TR> + <TD width="20"> + </TD> + <TD width="100" align="left"> + {Prev} + </TD> + <TD width="450" align="center"> + <span class="green">Displaying <b>{PagerFrom}</b> to <b>{PagerTo}</b> of <b>{PagerCount}</b> Categories</span> + </TD> + <TD width="100" align="right"> + {Next} + </TD> + </TR> + </TABLE> + <br> <!-- BEGIN Category --> <TABLE border="0" onClick="expandCategory('__{categoryName}');" class="DHTML_Category_Expand" > <TR> @@ -80,4 +96,20 @@ <!-- END Row --> </TABLE> <!-- END Category --> + <br> + <TABLE border="0"> + <TR> + <TD width="20"> + </TD> + <TD width="100" align="left"> + {Prev} + </TD> + <TD width="450" align="center"> + <span class="green">Displaying <b>{PagerFrom}</b> to <b>{PagerTo}</b> of <b>{PagerCount}</b> Categories</span> + </TD> + <TD width="100" align="right"> + {Next} + </TD> + </TR> + </TABLE> <!-- INCLUDE footer.inc.tpl.html --> Index: pear/PEAR_Frontend_Web/Frontend/Web/style.css diff -u pear/PEAR_Frontend_Web/Frontend/Web/style.css:1.3 pear/PEAR_Frontend_Web/Frontend/Web/style.css:1.4 --- pear/PEAR_Frontend_Web/Frontend/Web/style.css:1.3 Sat Jun 1 15:01:01 2002 +++ pear/PEAR_Frontend_Web/Frontend/Web/style.css Sat Jun 1 18:54:22 2002 @@ -62,6 +62,10 @@ font-style: italic; } +span.green { + color: #006600; +} + span.headline { font-family: verdana,arial,helvetica,sans-serif; font-size: 125%;
« previous php.pear.cvs (#4345) next »