PEAR_Frontend_Web
[ class tree: PEAR_Frontend_Web ] [ index: PEAR_Frontend_Web ] [ all elements ]

Source for file Web.php

Documentation is available at Web.php

  1. <?php
  2. /*
  3.   +----------------------------------------------------------------------+
  4.   | PHP Version 4                                                        |
  5.   +----------------------------------------------------------------------+
  6.   | Copyright (c) 1997-2003 The PHP Group                                |
  7.   +----------------------------------------------------------------------+
  8.   | This source file is subject to version 2.02 of the PHP license,      |
  9.   | that is bundled with this package in the file LICENSE, and is        |
  10.   | available at through the world-wide-web at                           |
  11.   | http://www.php.net/license/2_02.txt.                                 |
  12.   | If you did not receive a copy of the PHP license and are unable to   |
  13.   | obtain it through the world-wide-web, please send a note to          |
  14.   | license@php.net so we can mail you a copy immediately.               |
  15.   +----------------------------------------------------------------------+
  16.   | Author: Christian Dickmann <dickmann@php.net>                        |
  17.   +----------------------------------------------------------------------+
  18.  
  19.   $Id: Web.php,v 1.37 2006/04/17 22:03:02 pajoye Exp $
  20. */
  21.  
  22. require_once "PEAR/Frontend.php";
  23. require_once "PEAR/Remote.php";
  24. require_once "HTML/Template/IT.php";
  25. require_once "Net/UserAgent/Detect.php";
  26.  
  27. /**
  28. * PEAR_Frontend_Web is a HTML based Webfrontend for the PEAR Installer
  29. *
  30. * The Webfrontend provides basic functionality of the Installer, such as
  31. * a package list grouped by categories, a search mask, the possibility
  32. * to install/upgrade/uninstall packages and some minor things.
  33. * PEAR_Frontend_Web makes use of the PEAR::HTML_IT Template engine which
  34. * provides the possibillity to skin the Installer.
  35. *
  36. @author  Christian Dickmann <dickmann@php.net>
  37. @package PEAR_Frontend_Web
  38. @access  private
  39. */
  40.  
  41. class PEAR_Frontend_Web extends PEAR_Frontend
  42. {
  43.     // {{{ properties
  44.  
  45.     /**
  46.      * What type of user interface this frontend is for.
  47.      * @var string 
  48.      * @access public
  49.      */
  50.     var $type 'Web';
  51.  
  52.     /**
  53.      * Container, where values can be saved temporary
  54.      * @var array 
  55.      * @access private
  56.      */
  57.     var $_data = array();
  58.     var $_savedOutput = array();
  59.  
  60.     // }}}
  61.     var $config;
  62.  
  63.     var $_no_delete_pkgs = array(
  64.         'PEAR',
  65.         'PEAR_Frontend_Web',
  66.         'Archive_Tar',
  67.         'Console_Getopt',
  68.         'XML_RPC',
  69.         'Net_UserAgent_Detect',
  70.     );
  71.  
  72.     var $_no_delete_chans = array(
  73.         'pear.php.net',
  74.         '__uri',
  75.         );
  76.  
  77.     /**
  78.      * Flag to determine whether to treat all output as information from a post-install script
  79.      * @var bool 
  80.      * @access private
  81.      */
  82.     var $_installScript = false;
  83.     // {{{ constructor
  84.  
  85.     function PEAR_Frontend_Web()
  86.     {
  87.         parent::PEAR();
  88.         $GLOBALS['_PEAR_Frontend_Web_log''';
  89.         $this->config &$GLOBALS['_PEAR_Frontend_Web_config'];
  90.     }
  91.  
  92.     // }}}
  93.  
  94.     function setConfig(&$config)
  95.     {
  96.         $this->config &$config;
  97.     }
  98.  
  99.     // {{{ displayLine()
  100.  
  101.     /* XXX some methods from CLI following. should be deleted in the near future */
  102.     function displayLine($text)
  103.     {
  104.         trigger_error("Frontend::display deprecated"E_USER_ERROR);
  105.     }
  106.  
  107.     // }}}
  108.     // {{{ display()
  109.  
  110.     function display($text)
  111.     {
  112.         trigger_error("Frontend::display deprecated"E_USER_ERROR);
  113.     }
  114.  
  115.     // }}}
  116.     // {{{ userConfirm()
  117.  
  118.     function userConfirm($prompt$default 'yes')
  119.     {
  120.         trigger_error("Frontend::display deprecated"E_USER_ERROR);
  121.         return false;
  122.     }
  123.  
  124.     // }}}
  125.     // {{{ displayStart(prompt, [default])
  126.  
  127.     function displayStart()
  128.     {
  129.         $tpl $this->_initTemplate("start.tpl.html"'PEAR Installer');
  130.         $tpl->setVariable('Version''0.5');
  131.         $tpl->show();
  132.         exit;
  133.     }
  134.  
  135.     // }}}
  136.     // {{{ _initTemplate()
  137.  
  138.     /**
  139.      * Initialize a TemplateObject, add a title, and icon and add JS and CSS for DHTML
  140.      *
  141.      * @param string  $file     filename of the template file
  142.      * @param string  $title    (optional) title of the page
  143.      * @param string  $icon     (optional) iconhandle for this page
  144.      * @param boolean $useDHTML (optional) add JS and CSS for DHTML-features
  145.      *
  146.      * @access private
  147.      *
  148.      * @return object Object of HTML/IT - Template - Class
  149.      */
  150.  
  151.     function _initTemplate($file$title ''$icon ''$useDHTML = true)
  152.     {
  153.         $tpl = new HTML_Template_IT(dirname(__FILE__)."/Web");
  154.         $tpl->loadTemplateFile($file);
  155.         $tpl->setVariable("InstallerURL"$_SERVER["PHP_SELF"]);
  156.         if ($this->config->get('preferred_mirror'!= $this->config->get('default_channel')) {
  157.             $mirror ' (mirror ' .$this->config->get('preferred_mirror'')';
  158.         else {
  159.             $mirror '';
  160.         }
  161.         $tpl->setVariable("_default_channel"$this->config->get('default_channel'$mirror);
  162.         $tpl->setVariable("ImgPEAR"$_SERVER["PHP_SELF"].'?img=pear');
  163.         if ($title{
  164.             $tpl->setVariable("Title"$title);
  165.         }
  166.         if ($icon{
  167.             $tpl->setCurrentBlock("TitleBlock");
  168.             $tpl->setVariable("_InstallerURL"$_SERVER["PHP_SELF"]);
  169.             $tpl->setVariable("_Title"$title);
  170.             $tpl->setVariable("_Icon"$icon);
  171.             $tpl->parseCurrentBlock();
  172.         }
  173.  
  174.         $tpl->setCurrentBlock();
  175.  
  176.         if ($useDHTML && Net_UserAgent_Detect::getBrowser('ie5up'== 'ie5up'{
  177.             $dhtml = true;
  178.         else {
  179.             $dhtml = false;
  180.         }
  181.  
  182.         if ($dhtml{
  183.             $tpl->setVariable("JS"'dhtml');
  184.             $css '<link rel="stylesheet" href="'.$_SERVER['PHP_SELF'].'?css=dhtml" />';
  185.             $tpl->setVariable("DHTMLcss"$css);
  186.         else {
  187.             $tpl->setVariable("JS"'nodhtml');
  188.         }
  189.  
  190.         if (!isset($_SESSION['_PEAR_Frontend_Web_js']|| $_SESSION['_PEAR_Frontend_Web_js'== false{
  191.             $tpl->setCurrentBlock('JSEnable');
  192.             $tpl->setVariable('RedirectURL'$_SERVER['REQUEST_URI'](!empty($_GET'&' '?'.'enableJS=1');
  193.             $tpl->parseCurrentBlock();
  194.             $tpl->setCurrentBlock();
  195.         }
  196.  
  197.         return $tpl;
  198.     }
  199.  
  200.     // }}}
  201.     // {{{ displayError()
  202.  
  203.     /**
  204.      * Display an error page
  205.      *
  206.      * @param mixed   $eobj  PEAR_Error object or string containing the error message
  207.      * @param string  $title (optional) title of the page
  208.      * @param string  $img   (optional) iconhandle for this page
  209.      * @param boolean $popup (optional) popuperror or normal?
  210.      *
  211.      * @access public
  212.      *
  213.      * @return null does not return anything, but exit the script
  214.      */
  215.  
  216.     function displayError($eobj$title 'Error'$img 'error'$popup = false)
  217.     {
  218.         $msg '';
  219.         if (isset($GLOBALS['_PEAR_Frontend_Web_log']&& trim($GLOBALS['_PEAR_Frontend_Web_log'])) {
  220.             $msg trim($GLOBALS['_PEAR_Frontend_Web_log'])."\n\n";
  221.         }
  222.  
  223.         if (PEAR::isError($eobj)) {
  224.             $msg .= trim($eobj->getMessage());
  225.         else {
  226.             $msg .= trim($eobj);
  227.         }
  228.  
  229.         $msg nl2br($msg."\n");
  230.  
  231.         $tplfile ($popup "error.popup.tpl.html" "error.tpl.html");
  232.         $tpl $this->_initTemplate($tplfile$title$img);
  233.  
  234.         $tpl->setVariable("Error"$msg);
  235.         $command_map = array(
  236.             "install"   => "list-all",
  237.             "uninstall" => "list-all",
  238.             "upgrade"   => "list-all",
  239.             );
  240.         if (isset($_GET['command'])) {
  241.             if (isset($command_map[$_GET['command']])) {
  242.                 $_GET['command'$command_map[$_GET['command']];
  243.             }
  244.             $tpl->setVariable("param"'?command='.$_GET['command']);
  245.         }
  246.  
  247.         $tpl->show();
  248.         exit;
  249.     }
  250.  
  251.     // }}}
  252.     // {{{ displayFatalError()
  253.  
  254.     /**
  255.      * Alias for PEAR_Frontend_Web::displayError()
  256.      *
  257.      * @see PEAR_Frontend_Web::displayError()
  258.      */
  259.  
  260.     function displayFatalError($eobj$title 'Error'$img 'error')
  261.     {
  262.         $this->displayError($eobj$title$img);
  263.     }
  264.  
  265.     function displayErrorImg($eobj)
  266.     {
  267.         $msg '';
  268.         if (isset($GLOBALS['_PEAR_Frontend_Web_log']&& trim($GLOBALS['_PEAR_Frontend_Web_log']))
  269.             $msg trim($GLOBALS['_PEAR_Frontend_Web_log'])."\n\n";
  270.  
  271.         $_SESSION['_PEAR_Frontend_Web_LastError']     $eobj;
  272.         $_SESSION['_PEAR_Frontend_Web_LastError_log'$msg;
  273.         echo '<script language="javascript">';
  274.         printf('window.open("%s?command=show-last-error", "PEAR", "width=600, height=400");',
  275.             $_SERVER["PHP_SELF"]);
  276.         echo ' </script>';
  277.         printf('<img src="%s?img=install_fail" border="0">'$_SERVER['PHP_SELF']);
  278.         exit;
  279.     }
  280.  
  281.     // }}}
  282.     // {{{ _outputListChannels()
  283.  
  284.     function _outputListChannels($data$title 'Manage Installer Channels',
  285.                             $img 'pkglist'$useDHTML = false$paging = true)
  286.     {
  287.         $tpl $this->_initTemplate("channel.list.tpl.html"$title$img$useDHTML);
  288.         if (!isset($data['data'])) {
  289.             $data['data'= array();
  290.         }
  291.         $pageId = isset($_GET['from']$_GET['from': 0;
  292.         $paging_data $this->__getData($pageId5count($data['data'])false);
  293.  
  294.         $data['data'array_slice($data['data']$pageId5);
  295.  
  296.         $links = array();
  297.         $from $paging_data['from'];
  298.         $to $paging_data['next'];
  299.  
  300.         // Generate Linkinformation to redirect to _this_ page after performing an action
  301.         $link_str '<a href="?command=%s&from=%s" class="paging_link">%s</a>';
  302.  
  303.         $command = isset($_GET['command']$_GET['command''list-channels';
  304.  
  305.         if ($paging_data['from']>1{
  306.             $links['back'sprintf($link_str$command$paging_data['prev']'&lt;&lt;');
  307.         else {
  308.             $links['back''';
  309.         }
  310.  
  311.         if $paging_data['next']{
  312.             $links['next'sprintf($link_str$command$paging_data['next']'&gt;&gt;');
  313.         else {
  314.             $links['next''';
  315.         }
  316.  
  317.         $links['current''&from=' $paging_data['from'];
  318.  
  319.         $tpl->setVariable('Prev'$links['back']);
  320.         $tpl->setVariable('Next'$links['next']);
  321.         $tpl->setVariable('PagerFrom'$from);
  322.         $tpl->setVariable('PagerTo'$to);
  323.         $tpl->setVariable('PagerCount'$paging_data['numrows']);
  324.         $reg &$this->config->getRegistry();
  325.         foreach($data['data'as $row{
  326.             list($channel$summary$row;
  327.             $tpl->setCurrentBlock("Row");
  328.             $tpl->setVariable("ImgPackage"$_SERVER["PHP_SELF"].'?img=package');
  329.             $images = array(
  330.                 'delete' => '<img src="'.$_SERVER["PHP_SELF"].'?img=uninstall" width="18" height="17"  border="0" alt="delete">',
  331.                 'info' => '<img src="'.$_SERVER["PHP_SELF"].'?img=info"  width="17" height="19" border="0" alt="info">',
  332.                 );
  333.             $urls   = array(
  334.                 'delete' => sprintf('%s?command=channel-delete&chan=%s%s',
  335.                     $_SERVER["PHP_SELF"]urlencode($channel)$links['current']),
  336.                 'info' => sprintf('%s?command=channel-info&chan=%s',
  337.                     $_SERVER["PHP_SELF"]urlencode($channel)),
  338.                 );
  339.  
  340.             // detect whether any packages from this channel are installed
  341.             $anyinstalled $reg->listPackages($channel);
  342.             $id 'id="'.$channel.'_href"';
  343.             if (is_array($anyinstalled&& count($anyinstalled)) {
  344.                 $del '';
  345.             else {
  346.                 $del sprintf('<a href="%s" onClick="return deleteChan(\'%s\');" %s >%s</a>',
  347.                     $urls['delete']$channel$id$images['delete']);
  348.             }
  349.             $info    sprintf('<a href="%s">%s</a>'$urls['info'],    $images['info']);
  350.  
  351.             if (in_array($channel$this->_no_delete_chans)) {
  352.                 $del '';
  353.             }
  354.  
  355.             $tpl->setVariable("NewChannelURL"$_SERVER['PHP_SELF']);
  356.             $tpl->setVariable("Delete"$del);
  357.             $tpl->setVariable("Info"$info);
  358.             $tpl->setVariable("Channel"$channel);
  359.             $tpl->setVariable("Summary"nl2br($summary));
  360.             $tpl->parseCurrentBlock();
  361.         }
  362.         $tpl->show();
  363.         return true;
  364.     }
  365.     // }}}
  366.     // {{{ _outputListAll()
  367.  
  368.     /**
  369.      * Output a list of packages, grouped by categories. Uses Paging
  370.      *
  371.      * @param array   $data     array containing all data to display the list
  372.      * @param string  $title    (optional) title of the page
  373.      * @param string  $img      (optional) iconhandle for this page
  374.      * @param boolean $useDHTML (optional) add JS and CSS for DHTML-features
  375.      * @param boolean $paging   (optional) use Paging or not
  376.      *
  377.      * @access private
  378.      *
  379.      * @return boolean true (yep. i am an optimist)
  380.      */
  381.  
  382.     function _outputListAll($data$title 'Install / Upgrade / Remove PEAR Packages',
  383.                             $img 'pkglist'$useDHTML = false$paging = true)
  384.     {
  385.         $tpl $this->_initTemplate("package.list.tpl.html"$title$img$useDHTML);
  386.  
  387.         if (!isset($data['data'])) {
  388.             $data['data'= array();
  389.         }
  390.  
  391.         $pageId = isset($_GET['from']$_GET['from': 0;
  392.         $paging_data $this->__getData($pageId5count($data['data'])false);
  393.  
  394.         $data['data'array_slice($data['data']$pageId5);
  395.  
  396.         $links = array();
  397.         $from $paging_data['from'];
  398.         $to $paging_data['next'];
  399.  
  400.         // Generate Linkinformation to redirect to _this_ page after performing an action
  401.         $link_str '<a href="?command=%s&from=%s&mode=%s" class="paging_link">%s</a>';
  402.  
  403.  
  404.  
  405.         $command = isset($_GET['command']$_GET['command']:'list-all';
  406.         $mode = isset($_GET['mode'])?$_GET['mode']:'';
  407.  
  408.  
  409.  
  410.         if ($paging_data['from']>1{
  411.             $links['back'sprintf($link_str$command$paging_data['prev']$mode'&lt;&lt;');
  412.         else {
  413.             $links['back''';
  414.         }
  415.  
  416.         if $paging_data['next']{
  417.             $links['next'sprintf($link_str$command$paging_data['next']$mode'&gt;&gt;');
  418.         else {
  419.             $links['next''';
  420.         }
  421.  
  422.         $links['current''&from=' $paging_data['from']  '&mode=' $mode;
  423.  
  424.         if (isset($_GET['command']&& $_GET['command'== 'search'{
  425.             $links['current'.= '&redirect=search&0='.$_REQUEST[0].'&1='.$_REQUEST[1];
  426.         }
  427.  
  428.         $modes = array(
  429.             'installed'    => 'list installed packages',
  430.             ''             => 'list all packages',
  431.             'notinstalled' => 'list non-installed packages',
  432.             'upgrades'     => 'list avail. upgrades',
  433.             );
  434.  
  435.         $i = 1;
  436.         foreach($modes as $mode => $text{
  437.             $tpl->setVariable('mode' $i !empty($mode'&mode='.$mode '');
  438.             $tpl->setVariable('mode' $i.'text'$text);
  439.             $i++;
  440.         }
  441.  
  442.         $tpl->setVariable('Prev'$links['back']);
  443.         $tpl->setVariable('Next'$links['next']);
  444.         $tpl->setVariable('PagerFrom'$from);
  445.         $tpl->setVariable('PagerTo'$to);
  446.         $tpl->setVariable('PagerCount'$paging_data['numrows']);
  447.  
  448.         $reg &$this->config->getRegistry();
  449.         foreach($data['data'as $category => $packages{
  450.             foreach($packages as $row{
  451.                 list($pkgName$pkgVersionLatest$pkgVersionInstalled$pkgSummary$row;
  452.                 $parsed $reg->parsePackageName($pkgName$this->config->get('default_channel'));
  453.                 $pkgChannel $parsed['channel'];
  454.                 $pkgName $parsed['package'];
  455.                 $tpl->setCurrentBlock("Row");
  456.                 $tpl->setVariable("ImgPackage"$_SERVER["PHP_SELF"].'?img=package');
  457.                 $images = array(
  458.                     'install' => '<img src="'.$_SERVER["PHP_SELF"].'?img=install" width="13" height="13" border="0" alt="install">',
  459.                     'uninstall' => '<img src="'.$_SERVER["PHP_SELF"].'?img=uninstall" width="18" height="17"  border="0" alt="uninstall">',
  460.                     'upgrade' => '<img src="'.$_SERVER["PHP_SELF"].'?img=install" width="13" height="13" border="0" alt="upgrade">',
  461.                     'info' => '<img src="'.$_SERVER["PHP_SELF"].'?img=info"  width="17" height="19" border="0" alt="info">',
  462.                     'infoExt' => '<img src="'.$_SERVER["PHP_SELF"].'?img=infoplus"  width="18" height="19" border="0" alt="extended info">',
  463.                     );
  464.                 $urls   = array(
  465.                     'install' => sprintf('%s?command=install&pkg=%s%s',
  466.                         $_SERVER["PHP_SELF"]$pkgName$links['current']),
  467.                     'uninstall' => sprintf('%s?command=uninstall&pkg=%s%s',
  468.                         $_SERVER["PHP_SELF"]$pkgName$links['current']),
  469.                     'upgrade' => sprintf('%s?command=upgrade&pkg=%s%s',
  470.                         $_SERVER["PHP_SELF"]$pkgName$links['current']),
  471.                     'info' => sprintf('%s?command=remote-info&pkg=%s',
  472.                         $_SERVER["PHP_SELF"]$pkgName),
  473.                     'infoExt' => 'http://' $this->config->get('preferred_mirror')
  474.                          . '/package/' $row[0],
  475.                     );
  476.  
  477.                 $compare version_compare($pkgVersionLatest$pkgVersionInstalled);
  478.                 $id 'id="'.$pkgName.'_href"';
  479.                 if (!$pkgVersionInstalled || $pkgVersionInstalled == "- no -"{
  480.                     $inst sprintf('<a href="%s" onClick="return perform(\'%s\');" %s>%s</a>',
  481.                         $urls['install']$pkgName$id$images['install']);
  482.                     $del '';
  483.                 else if ($compare == 1{
  484.                     $inst sprintf('<a href="%s" onClick="return perform(\'%s\');" %s>%s</a>',
  485.                         $urls['upgrade']$pkgName$id$images['upgrade']);
  486.                     $del sprintf('<a href="%s" onClick="return deletePkg(\'%s\');" %s >%s</a>',
  487.                         $urls['uninstall']$pkgName$id$images['uninstall']);
  488.                 else {
  489.                     $del sprintf('<a href="%s" onClick="return deletePkg(\'%s\');" %s >%s</a>',
  490.                         $urls['uninstall']$pkgName$id$images['uninstall']);
  491.                     $inst '';
  492.                 }
  493.                 $info    sprintf('<a href="%s">%s</a>'$urls['info'],    $images['info']);
  494.                 $infoExt sprintf('<a href="%s">%s</a>'$urls['infoExt']$images['infoExt']);
  495.  
  496.                 if ($reg->channelName($pkgChannel== 'pear.php.net' &&
  497.                       in_array($pkgName$this->_no_delete_pkgs)) {
  498.                     $del '';
  499.                 }
  500.  
  501.                 $tpl->setVariable("Latest"$pkgVersionLatest);
  502.                 $tpl->setVariable("Installed"$pkgVersionInstalled);
  503.                 $tpl->setVariable("Install"$inst);
  504.                 $tpl->setVariable("Delete"$del);
  505.                 $tpl->setVariable("Info"$info);
  506.                 $tpl->setVariable("InfoExt"$infoExt);
  507.                 $tpl->setVariable("Package"$pkgName);
  508.                 $tpl->setVariable("Channel"$pkgChannel);
  509.                 $tpl->setVariable("Summary"nl2br($pkgSummary));
  510.                 $tpl->parseCurrentBlock();
  511.             }
  512.             $tpl->setCurrentBlock("Category");
  513.             $tpl->setVariable("categoryName"$category);
  514.             $tpl->setVariable("ImgCategory"$_SERVER["PHP_SELF"].'?img=category');
  515.             $tpl->parseCurrentBlock();
  516.         }
  517.         $tpl->show();
  518.  
  519.         return true;
  520.     }
  521.  
  522.     function _getPackageDeps($deps)
  523.     {
  524.         if (count($deps== 0{
  525.             return "<i>No dependencies registered.</i>\n";
  526.         else {
  527.             $lastversion '';
  528.             $rel_trans = array(
  529.                 'lt' => 'older than %s',
  530.                 'le' => 'version %s or older',
  531.                 'eq' => 'version %s',
  532.                 'ne' => 'any version but %s',
  533.                 'gt' => 'newer than %s',
  534.                 'ge' => '%s or newer',
  535.                 );
  536.             $dep_type_desc = array(
  537.                 'pkg'    => 'PEAR Package',
  538.                 'ext'    => 'PHP Extension',
  539.                 'php'    => 'PHP Version',
  540.                 'prog'   => 'Program',
  541.                 'ldlib'  => 'Development Library',
  542.                 'rtlib'  => 'Runtime Library',
  543.                 'os'     => 'Operating System',
  544.                 'websrv' => 'Web Server',
  545.                 'sapi'   => 'SAPI Backend',
  546.                 );
  547.             $result "      <dl>\n";
  548.             foreach($deps as $row{
  549.  
  550.                 // Print link if it's a PEAR package
  551.                 if ($row['type'== 'pkg'{
  552.                     $row['name'sprintf('<a class="green" href="%s?command=remote-info&pkg=%s">%s</a>',
  553.                         $_SERVER['PHP_SELF']$row['name']$row['name']);
  554.                 }
  555.  
  556.                 if (isset($rel_trans[$row['relation']])) {
  557.                     $rel sprintf($rel_trans[$row['relation']]$row['version']);
  558.                     $result .= sprintf("%s: %s %s",
  559.                            $dep_type_desc[$row['type']]$row['name']$rel);
  560.                 else {
  561.                     $result .= sprintf("%s: %s"$dep_type_desc[$row['type']]$row['name']);
  562.                 }
  563.                 $lastversion $row['version'];
  564.                 $result .= '<br>';
  565.             }
  566.             if ($lastversion{
  567.             }
  568.             $result .= "      </dl>\n";
  569.         }
  570.         return $result;
  571.     }
  572.  
  573.     /**
  574.      * Output details of one package
  575.      *
  576.      * @param array $data array containing all information about the package
  577.      *
  578.      * @access private
  579.      *
  580.      * @return boolean true (yep. i am an optimist)
  581.      */
  582.  
  583.     function _outputPackageInfo($data)
  584.     {
  585.         include_once "PEAR/Downloader.php";
  586.         $tpl $this->_initTemplate("package.info.tpl.html"'Package Management :: '.$data['name']'pkglist');
  587.  
  588.         $tpl->setVariable("PreferredMirror"$this->config->get('preferred_mirror'));
  589.         $dl &new PEAR_Downloader($thisarray()$this->config);
  590.         $info $dl->_getPackageDownloadUrl(array('package' => $data['name'],
  591.             'channel' => $this->config->get('default_channel')'version' => $data['stable']));
  592.         if (isset($info['url'])) {
  593.             $tpl->setVariable("DownloadURL"$info['url']);
  594.         else {
  595.             $tpl->setVariable("DownloadURL"$_SERVER['PHP_SELF']);
  596.         }
  597.         $tpl->setVariable("Latest"$data['stable']);
  598.         $tpl->setVariable("Installed"$data['installed']);
  599.         $tpl->setVariable("Package"$data['name']);
  600.         $tpl->setVariable("License"$data['license']);
  601.         $tpl->setVariable("Category"$data['category']);
  602.         $tpl->setVariable("Summary"nl2br($data['summary']));
  603.         $tpl->setVariable("Description"nl2br($data['description']));
  604.         $deps @$data['releases'][$data['stable']]['deps'];
  605.         $tpl->setVariable("Dependencies"$this->_getPackageDeps($deps));
  606.  
  607.         $compare version_compare($data['stable']$data['installed']);
  608.  
  609.         $images = array(
  610.             'install' => '<img src="'.$_SERVER["PHP_SELF"].'?img=install" width="13" height="13" border="0" alt="install">',
  611.             'uninstall' => '<img src="'.$_SERVER["PHP_SELF"].'?img=uninstall" width="18" height="17"  border="0" alt="uninstall">',
  612.             'upgrade' => '<img src="'.$_SERVER["PHP_SELF"].'?img=install" width="13" height="13" border="0" alt="upgrade">',
  613.             );
  614.  
  615.         $opt_img = array();
  616.         $opt_text = array();
  617.         if (!$data['installed'|| $data['installed'== "- no -"{
  618.             $opt_img[sprintf(
  619.                 '<a href="%s?command=install&pkg=%s&redirect=info">%s</a>',
  620.                 $_SERVER["PHP_SELF"]$data['name']$images['install']);
  621.             $opt_text[sprintf(
  622.                 '<a href="%s?command=install&pkg=%s&redirect=info" class="green">Install package</a>',
  623.                 $_SERVER["PHP_SELF"]$data['name']);
  624.         else if ($compare == 1{
  625.             $opt_img[sprintf(
  626.                 '<a href="%s?command=upgrade&pkg=%s&redirect=info">%s</a><br>',
  627.                 $_SERVER["PHP_SELF"]$data['name']$images['upgrade']);
  628.             $opt_text[sprintf(
  629.                 '<a href="%s?command=upgrade&pkg=%s&redirect=info" class="green">Upgrade package</a>',
  630.                 $_SERVER["PHP_SELF"]$data['name']);
  631.             if (!in_array($data['name']$this->_no_delete_pkgs)) {
  632.                 $opt_img[sprintf(
  633.                     '<a href="%s?command=uninstall&pkg=%s&redirect=info" %s>%s</a>',
  634.                     $_SERVER["PHP_SELF"]$data['name'],
  635.                     'onClick="return confirm(\'Do you really want to uninstall \\\''.$data['name'].'\\\'?\')"',
  636.                     $images['uninstall']);
  637.                 $opt_text[sprintf(
  638.                     '<a href="%s?command=uninstall&pkg=%s&redirect=info" class="green" %s>Uninstall package</a>',
  639.                     $_SERVER["PHP_SELF"]$data['name'],
  640.                     'onClick="return confirm(\'Do you really want to uninstall \\\''.$data['name'].'\\\'?\')"');
  641.            }
  642.         else {
  643.             if (!in_array($data['name']$this->_no_delete_pkgs)) {
  644.                 $opt_img[sprintf(
  645.                     '<a href="%s?command=uninstall&pkg=%s&redirect=info" %s>%s</a>',
  646.                     $_SERVER["PHP_SELF"]$data['name'],
  647.                     'onClick="return confirm(\'Do you really want to uninstall \\\''.$data['name'].'\\\'?\')"',
  648.                     $images['uninstall']);
  649.                 $opt_text[sprintf(
  650.                     '<a href="%s?command=uninstall&pkg=%s&redirect=info" class="green" %s>Uninstall package</a>',
  651.                     $_SERVER["PHP_SELF"]$data['name'],
  652.                     'onClick="return confirm(\'Do you really want to uninstall \\\''.$data['name'].'\\\'?\')"');
  653.            }
  654.         }
  655.  
  656.         if (isset($opt_img[0]))
  657.         {
  658.             $tpl->setVariable("Opt_Img_1"$opt_img[0]);
  659.             $tpl->setVariable("Opt_Text_1"$opt_text[0]);
  660.         }
  661.         if (isset($opt_img[1]))
  662.         {
  663.             $tpl->setVariable("Opt_Img_2"$opt_img[1]);
  664.             $tpl->setVariable("Opt_Text_2"$opt_text[1]);
  665.         }
  666.  
  667.         $tpl->show();
  668.         return true;
  669.     }
  670.  
  671.     /**
  672.      * Output details of one channel
  673.      *
  674.      * @param array $data array containing all information about the channel
  675.      *
  676.      * @access private
  677.      *
  678.      * @return boolean true (yep. i am an optimist)
  679.      */
  680.  
  681.     function _outputChannelInfo($data)
  682.     {
  683.         $tpl $this->_initTemplate("channel.info.tpl.html",
  684.             'Channel Management :: '.$data['main']['data']['server'][1]'pkglist');
  685.  
  686.         $tpl->setVariable("Channel"$data['main']['data']['server'][1]);
  687.         if (isset($data['main']['data']['alias'])) {
  688.             $tpl->setVariable("Alias"$data['main']['data']['alias'][1]);
  689.         else {
  690.             $tpl->setVariable("Alias"$data['main']['data']['server'][1]);
  691.         }
  692.         $tpl->setVariable("Summary"$data['main']['data']['summary'][1]);
  693.         $tpl->setVariable("ValidationPackage"$data['main']['data']['vpackage'][1]);
  694.         $tpl->setVariable("ChannelValidationPackageVersion",
  695.             $data['main']['data']['vpackageversion'][1]);
  696.         if (!in_array($data['main']['data']['server'][1]array('pear.php.net''__uri'))) {
  697.             // see if the validation package is installed.  If not, allow the user to install it
  698.             $reg &$this->config->getRegistry();
  699.             do {
  700.                 if ($reg->packageExists($data['main']['data']['vpackage'][1],
  701.                       $data['main']['data']['server'][1])) {
  702.                     $installed = true;
  703.                     if ($reg->packageInfo($data['main']['data']['vpackage'][1]'version',
  704.                           $data['main']['data']['server'][1]==
  705.                           $data['main']['data']['vpackageversion'][1]{
  706.                         break; // poor man's throw
  707.                     }
  708.                 else {
  709.                     $installed = false;
  710.                 }
  711.                 // finish this
  712.                 $pname $reg->parsedPackageNameToString(array('channel' =>
  713.                     $data['main']['data']['server'][1],
  714.                     'package' => $data['main']['data']['vpackage'][1],
  715.                     'version' => $data['main']['data']['vpackageversion'][1]));
  716.                 $opt_img[sprintf(
  717.                     '<a href="%s?command=install&pkg=%s&redirect=info">%s</a>',
  718.                     $_SERVER["PHP_SELF"]$pname
  719.                     '<img src="'.$_SERVER["PHP_SELF"].'?img=install" width="13" height="13" border="0" alt="install">');
  720.                 $opt_text[sprintf(
  721.                     '<a href="%s?command=install&pkg=%s&redirect=info" class="green">Install package</a>',
  722.                     $_SERVER["PHP_SELF"]$data['name']);
  723.             while (false);
  724.         }
  725.         $tpl->show();
  726.         return true;
  727.     }
  728.  
  729.     /**
  730.      * Output all kinds of data depending on the command which called this method
  731.      *
  732.      * @param mixed  $data    datastructure containing the information to display
  733.      * @param string $command (optional) command from which this method was called
  734.      *
  735.      * @access public
  736.      *
  737.      * @return mixed highly depends on the command
  738.      */
  739.  
  740.     function outputData($data$command '_default')
  741.     {
  742.         switch ($command{
  743.             case 'config-show':
  744.                 $prompt  = array();
  745.                 $default = array();
  746.                 foreach($data['data'as $group{
  747.                     foreach($group as $row{
  748.                         $prompt[$row[1]]  $row[0];
  749.                         $default[$row[1]] $row[2];
  750.                     }
  751.                 }
  752.                 $title 'Configuration :: '.$GLOBALS['pear_user_config'];
  753.                 $GLOBALS['_PEAR_Frontend_Web_Config'=
  754.                     $this->userDialog($command$promptarray()$default$title'config');
  755.                 return true;
  756.             case 'list-all':
  757.                 return $this->_outputListAll($data);
  758.             case 'list-channels':
  759.                 return $this->_outputListChannels($data);
  760.             case 'search':
  761.                 return $this->_outputListAll($data'Package Search :: Result''pkgsearch'falsefalse);
  762.             case 'remote-info':
  763.                 return $this->_outputPackageInfo($data);
  764.             case 'channel-info':
  765.                 return $this->_outputChannelInfo($data);
  766.             case 'install':
  767.             case 'upgrade':
  768.             case 'uninstall':
  769.                 return true;
  770.             case 'login':
  771.                 if ($_SERVER["REQUEST_METHOD"!= "POST")
  772.                     $this->_data[$command$data;
  773.                 return true;
  774.             case 'logout':
  775.                 $this->displayError($data'Logout''logout');
  776.                 break;
  777.             case 'package':
  778.             case 'channel-discover':
  779.             case 'channel-delete':
  780.             case 'update-channels':
  781.                 $this->_savedOutput[$data;
  782.                 break;
  783.             default:
  784.                 if ($this->_installScript{
  785.                     $this->_savedOutput[$_SESSION['_PEAR_Frontend_Web_SavedOutput'][$data;
  786.                     break;
  787.                 }
  788.                 /* TODO: figure out a sane way to manage the inconsisten new error msg */
  789.                 if (!is_array($data)) {
  790.                     echo $data;
  791.                 }
  792.         }
  793.  
  794.         return true;
  795.     }
  796.  
  797.     function startSession()
  798.     {
  799.         if ($this->_installScript{
  800.             if (!isset($_SESSION['_PEAR_Frontend_Web_SavedOutput'])) {
  801.                 $_SESSION['_PEAR_Frontend_Web_SavedOutput'= array();
  802.             }
  803.             $this->_savedOutput $_SESSION['_PEAR_Frontend_Web_SavedOutput'];
  804.         else {
  805.             $this->_savedOutput = array();
  806.         }
  807.     }
  808.  
  809.     function finishOutput($command$redirectLink = false)
  810.     {
  811.         unset($_SESSION['_PEAR_Frontend_Web_SavedOutput']);
  812.         $tpl $this->_initTemplate('info.tpl.html'"$command output");
  813.         foreach($this->_savedOutput as $row{
  814.             $tpl->setCurrentBlock('Infoloop');
  815.             $tpl->setVariable("Info"$row);
  816.             $tpl->parseCurrentBlock();
  817.         }
  818.         if ($redirectLink{
  819.             $tpl->setCurrentBlock('Infoloop');
  820.             $tpl->setVariable("Info"'<a href="' $redirectLink['link''">' .
  821.                 $redirectLink['text''</a>');
  822.             $tpl->parseCurrentBlock();
  823.         }
  824.         $tpl->show();
  825.     }
  826.  
  827.     /**
  828.      * @param array An array of PEAR_Task_Postinstallscript objects (or related scripts)
  829.      * @param PEAR_PackageFile_v2 
  830.      */
  831.     function runPostinstallScripts(&$scripts$pkg)
  832.     {
  833.         if (!isset($_SESSION['_PEAR_Frontend_Web_Scripts'])) {
  834.             $saves = array();
  835.             foreach ($scripts as $i => $task{
  836.                 $saves[$i= (array) $task->_obj;
  837.             }
  838.             $_SESSION['_PEAR_Frontend_Web_Scripts'$saves;
  839.             $nonsession = true;
  840.         else {
  841.             $nonsession = false;
  842.         }
  843.         foreach ($scripts as $i => $task{
  844.             if (!isset($_SESSION['_PEAR_Frontend_Web_ScriptIndex'])) {
  845.                 $_SESSION['_PEAR_Frontend_Web_ScriptIndex'$i;
  846.             }
  847.             if ($i != $_SESSION['_PEAR_Frontend_Web_ScriptIndex']{
  848.                 continue;
  849.             }
  850.             if (!$nonsession{
  851.                 // restore values from previous sessions to the install script
  852.                 foreach ($_SESSION['_PEAR_Frontend_Web_Scripts'][$ias $name => $val{
  853.                     if ($name{0== '_'{
  854.                         // only public variables will be restored
  855.                         continue;
  856.                     }
  857.                     $scripts[$i]->_obj->$name $val;
  858.                 }
  859.             }
  860.             $this->_installScript = true;
  861.             $this->startSession();
  862.             $this->runInstallScript($scripts[$i]->_params$scripts[$i]->_obj$pkg);
  863.             $saves $scripts;
  864.             foreach ($saves as $i => $task{
  865.                 $saves[$i= (array) $task->_obj;
  866.             }
  867.             $_SESSION['_PEAR_Frontend_Web_Scripts'$saves;
  868.             unset($_SESSION['_PEAR_Frontend_Web_ScriptIndex']);
  869.         }
  870.         $this->_installScript = false;
  871.         unset($_SESSION['_PEAR_Frontend_Web_Scripts']);
  872.         $this->finishOutput($pkg->getPackage(' Install Script',
  873.             array('link' => $GLOBALS['URL'.
  874.             '?command=remote-info&pkg='.$pkg->getPackage(),
  875.                 'text' => 'Click for ' .$pkg->getPackage(' Information'));
  876.     }
  877.  
  878.     /**
  879.      * Instruct the runInstallScript method to skip a paramgroup that matches the
  880.      * id value passed in.
  881.      *
  882.      * This method is useful for dynamically configuring which sections of a post-install script
  883.      * will be run based on the user's setup, which is very useful for making flexible
  884.      * post-install scripts without losing the cross-Frontend ability to retrieve user input
  885.      * @param string 
  886.      */
  887.     function skipParamgroup($id)
  888.     {
  889.         $_SESSION['_PEAR_Frontend_Web_ScriptSkipSections'][$sectionName= true;
  890.     }
  891.  
  892.     /**
  893.      * @param array $xml contents of postinstallscript tag
  894.      * @param object $script post-installation script
  895.      * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2$pkg 
  896.      * @param string $contents contents of the install script
  897.      */
  898.     function runInstallScript($xml&$script&$pkg)
  899.     {
  900.         if (!isset($_SESSION['_PEAR_Frontend_Web_ScriptCompletedPhases'])) {
  901.             $_SESSION['_PEAR_Frontend_Web_ScriptCompletedPhases'= array();
  902.             $_SESSION['_PEAR_Frontend_Web_ScriptSkipSections'= array();
  903.         }
  904.         if (isset($_SESSION['_PEAR_Frontend_Web_ScriptObj'])) {
  905.             foreach ($_SESSION['_PEAR_Frontend_Web_ScriptObj'as $name => $val{
  906.                 if ($name{0== '_'{
  907.                     // only public variables will be restored
  908.                     continue;
  909.                 }
  910.                 $script->$name $val;
  911.             }
  912.         else {
  913.             $_SESSION['_PEAR_Frontend_Web_ScriptObj'= (array) $script;
  914.         }
  915.         if (!is_array($xml|| !isset($xml['paramgroup'])) {
  916.             $script->run(array()'_default');
  917.         else {
  918.             if (!isset($xml['paramgroup'][0])) {
  919.                 $xml['paramgroup'][0= array($xml['paramgroup']);
  920.             }
  921.             foreach ($xml['paramgroup'as $i => $group{
  922.                 if (isset($_SESSION['_PEAR_Frontend_Web_ScriptSkipSections'][$group['id']])) {
  923.                     continue;
  924.                 }
  925.                 if (isset($_SESSION['_PEAR_Frontend_Web_ScriptSection'])) {
  926.                     if ($i $_SESSION['_PEAR_Frontend_Web_ScriptSection']{
  927.                         $lastgroup $group;
  928.                         continue;
  929.                     }
  930.                 }
  931.                 if (isset($_SESSION['_PEAR_Frontend_Web_answers'])) {
  932.                     $answers $_SESSION['_PEAR_Frontend_Web_answers'];
  933.                 }
  934.                 if (isset($group['name'])) {
  935.                     if (isset($answers)) {
  936.                         if (isset($answers[$group['name']])) {
  937.                             switch ($group['conditiontype']{
  938.                                 case '=' :
  939.                                     if ($answers[$group['name']] != $group['value']{
  940.                                         continue 2;
  941.                                     }
  942.                                 break;
  943.                                 case '!=' :
  944.                                     if ($answers[$group['name']] == $group['value']{
  945.                                         continue 2;
  946.                                     }
  947.                                 break;
  948.                                 case 'preg_match' :
  949.                                     if (!@preg_match('/' $group['value''/',
  950.                                           $answers[$group['name']])) {
  951.                                         continue 2;
  952.                                     }
  953.                                 break;
  954.                                 default :
  955.                                     $this->_clearScriptSession();
  956.                                 return;
  957.                             }
  958.                         }
  959.                     else {
  960.                         $this->_clearScriptSession();
  961.                         return;
  962.                     }
  963.                 }
  964.                 if (!isset($group['param'][0])) {
  965.                     $group['param'= array($group['param']);
  966.                 }
  967.                 $_SESSION['_PEAR_Frontend_Web_ScriptSection'$i;
  968.                 if (!isset($answers)) {
  969.                     $answers = array();
  970.                 }
  971.                 if (isset($group['param'])) {
  972.                     if (method_exists($script'postProcessPrompts')) {
  973.                         $prompts $script->postProcessPrompts($group['param']$group['name']);
  974.                         if (!is_array($prompts|| count($prompts!= count($group['param'])) {
  975.                             $this->outputData('postinstall''Error: post-install script did not ' .
  976.                                 'return proper post-processed prompts');
  977.                             $prompts $group['param'];
  978.                         else {
  979.                             foreach ($prompts as $i => $var{
  980.                                 if (!is_array($var|| !isset($var['prompt']||
  981.                                       !isset($var['name']||
  982.                                       ($var['name'!= $group['param'][$i]['name']||
  983.                                       ($var['type'!= $group['param'][$i]['type'])) {
  984.                                     $this->outputData('postinstall''Error: post-install script ' .
  985.                                         'modified the variables or prompts, severe security risk. ' .
  986.                                         'Will instead use the defaults from the package.xml');
  987.                                     $prompts $group['param'];
  988.                                 }
  989.                             }
  990.                         }
  991.                         $answers array_merge($answers,
  992.                             $this->confirmDialog($prompts$pkg->getPackage()));
  993.                     else {
  994.                         $answers array_merge($answers,
  995.                             $this->confirmDialog($group['param']$pkg->getPackage()));
  996.                     }
  997.                 }
  998.                 if ($answers{
  999.                     array_unshift($_SESSION['_PEAR_Frontend_Web_ScriptCompletedPhases'],
  1000.                         $group['id']);
  1001.                     if (!$script->run($answers$group['id'])) {
  1002.                         $script->run($_SESSION['_PEAR_Frontend_Web_ScriptCompletedPhases'],
  1003.                             '_undoOnError');
  1004.                         $this->_clearScriptSession();
  1005.                         return;
  1006.                     }
  1007.                 else {
  1008.                     $script->run(array()'_undoOnError');
  1009.                     $this->_clearScriptSession();
  1010.                     return;
  1011.                 }
  1012.                 $lastgroup $group;
  1013.                 foreach ($group['param'as $param{
  1014.                     // rename the current params to save for future tests
  1015.                     $answers[$group['id''::' $param['name']] $answers[$param['name']];
  1016.                     unset($answers[$param['name']]);
  1017.                 }
  1018.                 // save the script's variables and user answers for the next round
  1019.                 $_SESSION['_PEAR_Frontend_Web_ScriptObj'= (array) $script;
  1020.                 $_SESSION['_PEAR_Frontend_Web_answers'$answers;
  1021.                 $_SERVER['REQUEST_METHOD''';
  1022.             }
  1023.         }
  1024.         $this->_clearScriptSession();
  1025.     }
  1026.  
  1027.     function _clearScriptSession()
  1028.     {
  1029.         unset($_SESSION['_PEAR_Frontend_Web_ScriptObj']);
  1030.         unset($_SESSION['_PEAR_Frontend_Web_answers']);
  1031.         unset($_SESSION['_PEAR_Frontend_Web_ScriptSection']);
  1032.         unset($_SESSION['_PEAR_Frontend_Web_ScriptCompletedPhases']);
  1033.         unset($_SESSION['_PEAR_Frontend_Web_ScriptSkipSections']);
  1034.     }
  1035.  
  1036.     /**
  1037.      * Ask for user input, confirm the answers and continue until the user is satisfied
  1038.      * @param array an array of arrays, format array('name' => 'paramname', 'prompt' =>
  1039.      *               'text to display', 'type' => 'string'[, default => 'default value'])
  1040.      * @param string Package Name
  1041.      * @return array|false
  1042.      */
  1043.     function confirmDialog($params$pkg)
  1044.     {
  1045.         $answers = array();
  1046.         $prompts $types = array();
  1047.         foreach ($params as $param{
  1048.             $prompts[$param['name']] $param['prompt'];
  1049.             $types[$param['name']] $param['type'];
  1050.             if (isset($param['default'])) {
  1051.                 $answers[$param['name']] $param['default'];
  1052.             else {
  1053.                 $answers[$param['name']] '';
  1054.             }
  1055.         }
  1056.         $attempt = 0;
  1057.         do {
  1058.             if ($attempt{
  1059.                 $_SERVER['REQUEST_METHOD''';
  1060.             }
  1061.             $title !$attempt $pkg ' Install Script Input' 'Please fill in all values';
  1062.             $answers $this->userDialog('run-scripts'$prompts$types$answers$title'',
  1063.                 array('pkg' => $pkg));
  1064.             if ($answers === false{
  1065.                 return false;
  1066.             }
  1067.             $attempt++;
  1068.         while (count(array_filter($answers)) != count($prompts));
  1069.         $_SERVER['REQUEST_METHOD''POST';
  1070.         return $answers;
  1071.     }
  1072.  
  1073.     /**
  1074.      * Display a formular and return the given input (yes. needs to requests)
  1075.      *
  1076.      * @param string $command  command from which this method was called
  1077.      * @param array  $prompts  associative array. keys are the inputfieldnames
  1078.      *                          and values are the description
  1079.      * @param array  $types    (optional) array of inputfieldtypes (text, password,
  1080.      *                          etc.) keys have to be the same like in $prompts
  1081.      * @param array  $defaults (optional) array of defaultvalues. again keys have
  1082.      *                          to be the same like in $prompts
  1083.      * @param string $title    (optional) title of the page
  1084.      * @param string $icon     (optional) iconhandle for this page
  1085.      * @param array  $extra    (optional) extra parameters to put in the form action
  1086.      *
  1087.      * @access public
  1088.      *
  1089.      * @return array input sended by the user
  1090.      */
  1091.  
  1092.     function userDialog($command$prompts$types = array()$defaults = array()$title '',
  1093.                         $icon ''$extra = array())
  1094.     {
  1095.         // If this is an POST Request, we can return the userinput
  1096.         if (isset($_GET["command"]&& $_GET["command"]==$command
  1097.             && $_SERVER["REQUEST_METHOD"== "POST"{
  1098.             if (isset($_POST['cancel'])) {
  1099.                 return false;
  1100.             }
  1101.             $result = array();
  1102.             foreach($prompts as $key => $prompt{
  1103.                 $result[$key$_POST[$key];
  1104.             }
  1105.             return $result;
  1106.         }
  1107.  
  1108.         // If this is an Answer GET Request , we can return the userinput
  1109.         if (isset($_GET["command"]&& $_GET["command"]==$command
  1110.             && isset($_GET["userDialogResult"]&& $_GET["userDialogResult"]=='get'{
  1111.             $result = array();
  1112.             foreach($prompts as $key => $prompt{
  1113.                 $result[$key$_GET[$key];
  1114.             }
  1115.             return $result;
  1116.         }
  1117.  
  1118.         // Assign title and icon to some commands
  1119.         if ($command == 'login'{
  1120.             $title 'Login';
  1121.             $icon 'login';
  1122.         }
  1123.  
  1124.         $tpl $this->_initTemplate("userDialog.tpl.html"$title$icon);
  1125.         $tpl->setVariable("Command"$command);
  1126.         $extrap '';
  1127.         if (count($extra)) {
  1128.             $extrap '&';
  1129.             foreach ($extra as $name => $value{
  1130.                 $extrap .= urlencode($name'=' urlencode($value);
  1131.             }
  1132.         }
  1133.         $tpl->setVariable("extra"$extrap);
  1134.         if (isset($this->_data[$command])) {
  1135.             $tpl->setVariable("Headline"nl2br($this->_data[$command]));
  1136.         }
  1137.  
  1138.         if (is_array($prompts)) {
  1139.             $maxlen = 0;
  1140.             foreach($prompts as $key => $prompt{
  1141.                 if (strlen($prompt$maxlen{
  1142.                     $maxlen strlen($prompt);
  1143.                 }
  1144.             }
  1145.  
  1146.             foreach($prompts as $key => $prompt{
  1147.                 $tpl->setCurrentBlock("InputField");
  1148.                 $type    (isset($types[$key])    $types[$key]    'text');
  1149.                 $default (isset($defaults[$key]$defaults[$key'');
  1150.                 $tpl->setVariable("prompt"$prompt);
  1151.                 $tpl->setVariable("name"$key);
  1152.                 $tpl->setVariable("default"$default);
  1153.                 $tpl->setVariable("type"$type);
  1154.                 if ($maxlen > 25{
  1155.                     $tpl->setVariable("width"'width="275"');
  1156.                 }
  1157.                 $tpl->parseCurrentBlock();
  1158.             }
  1159.         }
  1160.         if ($command == 'run-scripts'{
  1161.             $tpl->setVariable("cancel"'<input type="submit" value="Cancel" name="cancel">');
  1162.         }
  1163.         $tpl->show();
  1164.         exit;
  1165.     }
  1166.  
  1167.     /**
  1168.      * Write message to log
  1169.      *
  1170.      * @param string $text message which has to written to log
  1171.      *
  1172.      * @access public
  1173.      *
  1174.      * @return boolean true
  1175.      */
  1176.  
  1177.     function log($text)
  1178.     {
  1179.         $GLOBALS['_PEAR_Frontend_Web_log'.= $text."\n";
  1180.         $this->_savedOutput[$text;
  1181.         return true;
  1182.     }
  1183.  
  1184.     /**
  1185.      * Sends the required file along with Headers and exits the script
  1186.      *
  1187.      * @param string $handle handle of the requested file
  1188.      * @param string $group  group of the requested file
  1189.      *
  1190.      * @access public
  1191.      *
  1192.      * @return null nothing, because script exits
  1193.      */
  1194.  
  1195.     function outputFrontendFile($handle$group)
  1196.     {
  1197.         $handles = array(
  1198.             "css" => array(
  1199.                 "style" => "style.css",
  1200.                 "dhtml" => "dhtml.css",
  1201.                 ),
  1202.             "js" => array(
  1203.                 "dhtml" => "dhtml.js",
  1204.                 "nodhtml" => "nodhtml.js",
  1205.                 ),
  1206.             "image" => array(
  1207.                 "logout" => array(
  1208.                     "type" => "gif",
  1209.                     "file" => "logout.gif",
  1210.                     ),
  1211.                 "login" => array(
  1212.                     "type" => "gif",
  1213.                     "file" => "login.gif",
  1214.                     ),
  1215.                 "config" => array(
  1216.                     "type" => "gif",
  1217.                     "file" => "config.gif",
  1218.                     ),
  1219.                 "pkglist" => array(
  1220.                     "type" => "png",
  1221.                     "file" => "pkglist.png",
  1222.                     ),
  1223.                 "pkgsearch" => array(
  1224.                     "type" => "png",
  1225.                     "file" => "pkgsearch.png",
  1226.                     ),
  1227.                 "package" => array(
  1228.                     "type" => "jpeg",
  1229.                     "file" => "package.jpg",
  1230.                     ),
  1231.                 "category" => array(
  1232.                     "type" => "jpeg",
  1233.                     "file" => "category.jpg",
  1234.                     ),
  1235.                 "install" => array(
  1236.                     "type" => "gif",
  1237.                     "file" => "install.gif",
  1238.                     ),
  1239.                 "install_wait" => array(
  1240.                     "type" => "gif",
  1241.                     "file" => "install_wait.gif",
  1242.                     ),
  1243.                 "install_ok" => array(
  1244.                     "type" => "gif",
  1245.                     "file" => "install_ok.gif",
  1246.                     ),
  1247.                 "install_fail" => array(
  1248.                     "type" => "gif",
  1249.                     "file" => "install_fail.gif",
  1250.                     ),
  1251.                 "uninstall" => array(
  1252.                     "type" => "gif",
  1253.                     "file" => "trash.gif",
  1254.                     ),
  1255.                 "info" => array(
  1256.                     "type" => "gif",
  1257.                     "file" => "info.gif",
  1258.                     ),
  1259.                 "infoplus" => array(
  1260.                     "type" => "gif",
  1261.                     "file" => "infoplus.gif",
  1262.                     ),
  1263.                 "pear" => array(
  1264.                     "type" => "gif",
  1265.                     "file" => "pearsmall.gif",
  1266.                     ),
  1267.                 "error" => array(
  1268.                     "type" => "gif",
  1269.                     "file" => "error.gif",
  1270.                     ),
  1271.                 "manual" => array(
  1272.                     "type" => "gif",
  1273.                     "file" => "manual.gif",
  1274.                     ),
  1275.                 "download" => array(
  1276.                     "type" => "gif",
  1277.                     "file" => "download.gif",
  1278.                     ),
  1279.                 ),
  1280.             );
  1281.  
  1282.         $file $handles[$group][$handle];
  1283.         switch ($group{
  1284.             case 'css':
  1285.                 header("Content-Type: text/css");
  1286.                 readfile(dirname(__FILE__).'/Web/'.$file);
  1287.                 exit;
  1288.             case 'image':
  1289.                 $filename dirname(__FILE__).'/Web/'.$file['file'];
  1290.                 header("Content-Type: image/".$file['type']);
  1291.                 header("Expires: ".gmdate("D, d M Y H:i:s \G\M\T"time(+ 60*60*24*100));
  1292.                 header("Last-Modified: ".gmdate("D, d M Y H:i:s \G\M\T"filemtime($filename)));
  1293.                 header("Cache-Control: public");
  1294.                 header("Pragma: ");
  1295.                 readfile($filename);
  1296.                 exit;
  1297.             case 'js':
  1298.                 header("Content-Type: text/javascript");
  1299.                 readfile(dirname(__FILE__).'/Web/'.$file);
  1300.                 exit;
  1301.         }
  1302.     }
  1303.  
  1304.     /*
  1305.      * From DB::Pager. Removing Pager dependency.
  1306.      * @private
  1307.      */
  1308.     function __getData($from$limit$numrows$maxpages = false)
  1309.     {
  1310.         if (empty($numrows|| ($numrows < 0)) {
  1311.             return null;
  1312.         }
  1313.         $from (empty($from)) ? 0 : $from;
  1314.  
  1315.         if ($limit <= 0{
  1316.             return false;
  1317.         }
  1318.  
  1319.         // Total number of pages
  1320.         $pages ceil($numrows/$limit);
  1321.         $data['numpages'$pages;
  1322.  
  1323.         // first & last page
  1324.         $data['firstpage'= 1;
  1325.         $data['lastpage']  $pages;
  1326.  
  1327.         // Build pages array
  1328.         $data['pages'= array();
  1329.         for ($i=1; $i <= $pages$i++{
  1330.             $offset $limit ($i-1);
  1331.             $data['pages'][$i$offset;
  1332.             // $from must point to one page
  1333.             if ($from == $offset{
  1334.                 // The current page we are
  1335.                 $data['current'$i;
  1336.             }
  1337.         }
  1338.         if (!isset($data['current'])) {
  1339.             return PEAR::raiseError (null'wrong "from" param'null,
  1340.                                      nullnull'DB_Error'true);
  1341.         }
  1342.               // Limit number of pages (Goole algorithm)
  1343.         if ($maxpages{
  1344.             $radio floor($maxpages/2);
  1345.             $minpage $data['current'$radio;
  1346.             if ($minpage < 1{
  1347.                 $minpage = 1;
  1348.             }
  1349.             $maxpage $data['current'$radio - 1;
  1350.             if ($maxpage $data['numpages']{
  1351.                 $maxpage $data['numpages'];
  1352.             }
  1353.             foreach (range($minpage$maxpageas $page{
  1354.                 $tmp[$page$data['pages'][$page];
  1355.             }
  1356.             $data['pages'$tmp;
  1357.             $data['maxpages'$maxpages;
  1358.         else {
  1359.             $data['maxpages'= null;
  1360.         }
  1361.  
  1362.         // Prev link
  1363.         $prev $from $limit;
  1364.         $data['prev'($prev >= 0$prev : null;
  1365.  
  1366.         // Next link
  1367.         $next $from $limit;
  1368.         $data['next'($next $numrows$next : null;
  1369.  
  1370.         // Results remaining in next page & Last row to fetch
  1371.         if ($data['current'== $pages{
  1372.             $data['remain'= 0;
  1373.             $data['to'$numrows;
  1374.         else {
  1375.             if ($data['current'== ($pages - 1)) {
  1376.                 $data['remain'$numrows ($limit*($pages-1));
  1377.             else {
  1378.                 $data['remain'$limit;
  1379.             }
  1380.             $data['to'$data['current'$limit;
  1381.         }
  1382.         $data['numrows'$numrows;
  1383.         $data['from']    $from + 1;
  1384.         $data['limit']   $limit;
  1385.  
  1386.         return $data;
  1387.     }
  1388.  
  1389.     // }}}
  1390. }
  1391.  
  1392. ?>

Documentation generated on Mon, 11 Mar 2019 14:39:22 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.