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.34 2005/08/08 03:13:12 cellog 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.         'Pager');
  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.         $tpl $this->_initTemplate("package.info.tpl.html"'Package Management :: '.$data['name']'pkglist');
  586.  
  587.         $tpl->setVariable("PreferredMirror"$this->config->get('preferred_mirror'));
  588.         $dl &new PEAR_Downloader($thisarray()$this->config);
  589.         $info $dl->_getPackageDownloadUrl(array('package' => $data['name'],
  590.             'channel' => $this->config->get('default_channel')'version' => $data['stable']));
  591.         if (isset($info['url'])) {
  592.             $tpl->setVariable("DownloadURL"$info['url']);
  593.         else {
  594.             $tpl->setVariable("DownloadURL"$_SERVER['PHP_SELF']);
  595.         }
  596.         $tpl->setVariable("Latest"$data['stable']);
  597.         $tpl->setVariable("Installed"$data['installed']);
  598.         $tpl->setVariable("Package"$data['name']);
  599.         $tpl->setVariable("License"$data['license']);
  600.         $tpl->setVariable("Category"$data['category']);
  601.         $tpl->setVariable("Summary"nl2br($data['summary']));
  602.         $tpl->setVariable("Description"nl2br($data['description']));
  603.         $deps @$data['releases'][$data['stable']]['deps'];
  604.         $tpl->setVariable("Dependencies"$this->_getPackageDeps($deps));
  605.  
  606.         $compare version_compare($data['stable']$data['installed']);
  607.  
  608.         $images = array(
  609.             'install' => '<img src="'.$_SERVER["PHP_SELF"].'?img=install" width="13" height="13" border="0" alt="install">',
  610.             'uninstall' => '<img src="'.$_SERVER["PHP_SELF"].'?img=uninstall" width="18" height="17"  border="0" alt="uninstall">',
  611.             'upgrade' => '<img src="'.$_SERVER["PHP_SELF"].'?img=install" width="13" height="13" border="0" alt="upgrade">',
  612.             );
  613.  
  614.         $opt_img = array();
  615.         $opt_text = array();
  616.         if (!$data['installed'|| $data['installed'== "- no -"{
  617.             $opt_img[sprintf(
  618.                 '<a href="%s?command=install&pkg=%s&redirect=info">%s</a>',
  619.                 $_SERVER["PHP_SELF"]$data['name']$images['install']);
  620.             $opt_text[sprintf(
  621.                 '<a href="%s?command=install&pkg=%s&redirect=info" class="green">Install package</a>',
  622.                 $_SERVER["PHP_SELF"]$data['name']);
  623.         else if ($compare == 1{
  624.             $opt_img[sprintf(
  625.                 '<a href="%s?command=upgrade&pkg=%s&redirect=info">%s</a><br>',
  626.                 $_SERVER["PHP_SELF"]$data['name']$images['upgrade']);
  627.             $opt_text[sprintf(
  628.                 '<a href="%s?command=upgrade&pkg=%s&redirect=info" class="green">Upgrade package</a>',
  629.                 $_SERVER["PHP_SELF"]$data['name']);
  630.             if (!in_array($data['name']$this->_no_delete_pkgs)) {
  631.                 $opt_img[sprintf(
  632.                     '<a href="%s?command=uninstall&pkg=%s&redirect=info" %s>%s</a>',
  633.                     $_SERVER["PHP_SELF"]$data['name'],
  634.                     'onClick="return confirm(\'Do you really want to uninstall \\\''.$data['name'].'\\\'?\')"',
  635.                     $images['uninstall']);
  636.                 $opt_text[sprintf(
  637.                     '<a href="%s?command=uninstall&pkg=%s&redirect=info" class="green" %s>Uninstall package</a>',
  638.                     $_SERVER["PHP_SELF"]$data['name'],
  639.                     'onClick="return confirm(\'Do you really want to uninstall \\\''.$data['name'].'\\\'?\')"');
  640.            }
  641.         else {
  642.             if (!in_array($data['name']$this->_no_delete_pkgs)) {
  643.                 $opt_img[sprintf(
  644.                     '<a href="%s?command=uninstall&pkg=%s&redirect=info" %s>%s</a>',
  645.                     $_SERVER["PHP_SELF"]$data['name'],
  646.                     'onClick="return confirm(\'Do you really want to uninstall \\\''.$data['name'].'\\\'?\')"',
  647.                     $images['uninstall']);
  648.                 $opt_text[sprintf(
  649.                     '<a href="%s?command=uninstall&pkg=%s&redirect=info" class="green" %s>Uninstall package</a>',
  650.                     $_SERVER["PHP_SELF"]$data['name'],
  651.                     'onClick="return confirm(\'Do you really want to uninstall \\\''.$data['name'].'\\\'?\')"');
  652.            }
  653.         }
  654.  
  655.         if (isset($opt_img[0]))
  656.         {
  657.             $tpl->setVariable("Opt_Img_1"$opt_img[0]);
  658.             $tpl->setVariable("Opt_Text_1"$opt_text[0]);
  659.         }
  660.         if (isset($opt_img[1]))
  661.         {
  662.             $tpl->setVariable("Opt_Img_2"$opt_img[1]);
  663.             $tpl->setVariable("Opt_Text_2"$opt_text[1]);
  664.         }
  665.  
  666.         $tpl->show();
  667.         return true;
  668.     }
  669.  
  670.     /**
  671.      * Output details of one channel
  672.      *
  673.      * @param array $data array containing all information about the channel
  674.      *
  675.      * @access private
  676.      *
  677.      * @return boolean true (yep. i am an optimist)
  678.      */
  679.  
  680.     function _outputChannelInfo($data)
  681.     {
  682.         $tpl $this->_initTemplate("channel.info.tpl.html",
  683.             'Channel Management :: '.$data['main']['data']['server'][1]'pkglist');
  684.  
  685.         $tpl->setVariable("Channel"$data['main']['data']['server'][1]);
  686.         if (isset($data['main']['data']['alias'])) {
  687.             $tpl->setVariable("Alias"$data['main']['data']['alias'][1]);
  688.         else {
  689.             $tpl->setVariable("Alias"$data['main']['data']['server'][1]);
  690.         }
  691.         $tpl->setVariable("Summary"$data['main']['data']['summary'][1]);
  692.         $tpl->setVariable("ValidationPackage"$data['main']['data']['vpackage'][1]);
  693.         $tpl->setVariable("ChannelValidationPackageVersion",
  694.             $data['main']['data']['vpackageversion'][1]);
  695.         if (!in_array($data['main']['data']['server'][1]array('pear.php.net''__uri'))) {
  696.             // see if the validation package is installed.  If not, allow the user to install it
  697.             $reg &$this->config->getRegistry();
  698.             do {
  699.                 if ($reg->packageExists($data['main']['data']['vpackage'][1],
  700.                       $data['main']['data']['server'][1])) {
  701.                     $installed = true;
  702.                     if ($reg->packageInfo($data['main']['data']['vpackage'][1]'version',
  703.                           $data['main']['data']['server'][1]==
  704.                           $data['main']['data']['vpackageversion'][1]{
  705.                         break; // poor man's throw
  706.                     }
  707.                 else {
  708.                     $installed = false;
  709.                 }
  710.                 // finish this
  711.                 $pname $reg->parsedPackageNameToString(array('channel' =>
  712.                     $data['main']['data']['server'][1],
  713.                     'package' => $data['main']['data']['vpackage'][1],
  714.                     'version' => $data['main']['data']['vpackageversion'][1]));
  715.                 $opt_img[sprintf(
  716.                     '<a href="%s?command=install&pkg=%s&redirect=info">%s</a>',
  717.                     $_SERVER["PHP_SELF"]$pname
  718.                     '<img src="'.$_SERVER["PHP_SELF"].'?img=install" width="13" height="13" border="0" alt="install">');
  719.                 $opt_text[sprintf(
  720.                     '<a href="%s?command=install&pkg=%s&redirect=info" class="green">Install package</a>',
  721.                     $_SERVER["PHP_SELF"]$data['name']);
  722.             while (false);
  723.         }
  724.         $tpl->show();
  725.         return true;
  726.     }
  727.  
  728.     /**
  729.      * Output all kinds of data depending on the command which called this method
  730.      *
  731.      * @param mixed  $data    datastructure containing the information to display
  732.      * @param string $command (optional) command from which this method was called
  733.      *
  734.      * @access public
  735.      *
  736.      * @return mixed highly depends on the command
  737.      */
  738.  
  739.     function outputData($data$command '_default')
  740.     {
  741.         switch ($command{
  742.             case 'config-show':
  743.                 $prompt  = array();
  744.                 $default = array();
  745.                 foreach($data['data'as $group{
  746.                     foreach($group as $row{
  747.                         $prompt[$row[1]]  $row[0];
  748.                         $default[$row[1]] $row[2];
  749.                     }
  750.                 }
  751.                 $title 'Configuration :: '.$GLOBALS['pear_user_config'];
  752.                 $GLOBALS['_PEAR_Frontend_Web_Config'=
  753.                     $this->userDialog($command$promptarray()$default$title'config');
  754.                 return true;
  755.             case 'list-all':
  756.                 return $this->_outputListAll($data);
  757.             case 'list-channels':
  758.                 return $this->_outputListChannels($data);
  759.             case 'search':
  760.                 return $this->_outputListAll($data'Package Search :: Result''pkgsearch'falsefalse);
  761.             case 'remote-info':
  762.                 return $this->_outputPackageInfo($data);
  763.             case 'channel-info':
  764.                 return $this->_outputChannelInfo($data);
  765.             case 'install':
  766.             case 'upgrade':
  767.             case 'uninstall':
  768.                 return true;
  769.             case 'login':
  770.                 if ($_SERVER["REQUEST_METHOD"!= "POST")
  771.                     $this->_data[$command$data;
  772.                 return true;
  773.             case 'logout':
  774.                 $this->displayError($data'Logout''logout');
  775.                 break;
  776.             case 'package':
  777.             case 'channel-discover':
  778.             case 'channel-delete':
  779.             case 'update-channels':
  780.                 $this->_savedOutput[$data;
  781.                 break;
  782.             default:
  783.                 if ($this->_installScript{
  784.                     $this->_savedOutput[$_SESSION['_PEAR_Frontend_Web_SavedOutput'][$data;
  785.                     break;
  786.                 }
  787.                 echo $data;
  788.         }
  789.  
  790.         return true;
  791.     }
  792.  
  793.     function startSession()
  794.     {
  795.         if ($this->_installScript{
  796.             if (!isset($_SESSION['_PEAR_Frontend_Web_SavedOutput'])) {
  797.                 $_SESSION['_PEAR_Frontend_Web_SavedOutput'= array();
  798.             }
  799.             $this->_savedOutput $_SESSION['_PEAR_Frontend_Web_SavedOutput'];
  800.         else {
  801.             $this->_savedOutput = array();
  802.         }
  803.     }
  804.  
  805.     function finishOutput($command$redirectLink = false)
  806.     {
  807.         unset($_SESSION['_PEAR_Frontend_Web_SavedOutput']);
  808.         $tpl $this->_initTemplate('info.tpl.html'"$command output");
  809.         foreach($this->_savedOutput as $row{
  810.             $tpl->setCurrentBlock('Infoloop');
  811.             $tpl->setVariable("Info"$row);
  812.             $tpl->parseCurrentBlock();
  813.         }
  814.         if ($redirectLink{
  815.             $tpl->setCurrentBlock('Infoloop');
  816.             $tpl->setVariable("Info"'<a href="' $redirectLink['link''">' .
  817.                 $redirectLink['text''</a>');
  818.             $tpl->parseCurrentBlock();
  819.         }
  820.         $tpl->show();
  821.     }
  822.  
  823.     /**
  824.      * @param array An array of PEAR_Task_Postinstallscript objects (or related scripts)
  825.      * @param PEAR_PackageFile_v2 
  826.      */
  827.     function runPostinstallScripts(&$scripts$pkg)
  828.     {
  829.         if (!isset($_SESSION['_PEAR_Frontend_Web_Scripts'])) {
  830.             $saves = array();
  831.             foreach ($scripts as $i => $task{
  832.                 $saves[$i= (array) $task->_obj;
  833.             }
  834.             $_SESSION['_PEAR_Frontend_Web_Scripts'$saves;
  835.             $nonsession = true;
  836.         else {
  837.             $nonsession = false;
  838.         }
  839.         foreach ($scripts as $i => $task{
  840.             if (!isset($_SESSION['_PEAR_Frontend_Web_ScriptIndex'])) {
  841.                 $_SESSION['_PEAR_Frontend_Web_ScriptIndex'$i;
  842.             }
  843.             if ($i != $_SESSION['_PEAR_Frontend_Web_ScriptIndex']{
  844.                 continue;
  845.             }
  846.             if (!$nonsession{
  847.                 // restore values from previous sessions to the install script
  848.                 foreach ($_SESSION['_PEAR_Frontend_Web_Scripts'][$ias $name => $val{
  849.                     if ($name{0== '_'{
  850.                         // only public variables will be restored
  851.                         continue;
  852.                     }
  853.                     $scripts[$i]->_obj->$name $val;
  854.                 }
  855.             }
  856.             $this->_installScript = true;
  857.             $this->startSession();
  858.             $this->runInstallScript($scripts[$i]->_params$scripts[$i]->_obj$pkg);
  859.             $saves $scripts;
  860.             foreach ($saves as $i => $task{
  861.                 $saves[$i= (array) $task->_obj;
  862.             }
  863.             $_SESSION['_PEAR_Frontend_Web_Scripts'$saves;
  864.             unset($_SESSION['_PEAR_Frontend_Web_ScriptIndex']);
  865.         }
  866.         $this->_installScript = false;
  867.         unset($_SESSION['_PEAR_Frontend_Web_Scripts']);
  868.         $this->finishOutput($pkg->getPackage(' Install Script',
  869.             array('link' => $GLOBALS['URL'.
  870.             '?command=remote-info&pkg='.$pkg->getPackage(),
  871.                 'text' => 'Click for ' .$pkg->getPackage(' Information'));
  872.     }
  873.  
  874.     /**
  875.      * Instruct the runInstallScript method to skip a paramgroup that matches the
  876.      * id value passed in.
  877.      *
  878.      * This method is useful for dynamically configuring which sections of a post-install script
  879.      * will be run based on the user's setup, which is very useful for making flexible
  880.      * post-install scripts without losing the cross-Frontend ability to retrieve user input
  881.      * @param string 
  882.      */
  883.     function skipParamgroup($id)
  884.     {
  885.         $_SESSION['_PEAR_Frontend_Web_ScriptSkipSections'][$sectionName= true;
  886.     }
  887.  
  888.     /**
  889.      * @param array $xml contents of postinstallscript tag
  890.      * @param object $script post-installation script
  891.      * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2$pkg 
  892.      * @param string $contents contents of the install script
  893.      */
  894.     function runInstallScript($xml&$script&$pkg)
  895.     {
  896.         if (!isset($_SESSION['_PEAR_Frontend_Web_ScriptCompletedPhases'])) {
  897.             $_SESSION['_PEAR_Frontend_Web_ScriptCompletedPhases'= array();
  898.             $_SESSION['_PEAR_Frontend_Web_ScriptSkipSections'= array();
  899.         }
  900.         if (isset($_SESSION['_PEAR_Frontend_Web_ScriptObj'])) {
  901.             foreach ($_SESSION['_PEAR_Frontend_Web_ScriptObj'as $name => $val{
  902.                 if ($name{0== '_'{
  903.                     // only public variables will be restored
  904.                     continue;
  905.                 }
  906.                 $script->$name $val;
  907.             }
  908.         else {
  909.             $_SESSION['_PEAR_Frontend_Web_ScriptObj'= (array) $script;
  910.         }
  911.         if (!is_array($xml|| !isset($xml['paramgroup'])) {
  912.             $script->run(array()'_default');
  913.         else {
  914.             if (!isset($xml['paramgroup'][0])) {
  915.                 $xml['paramgroup'][0= array($xml['paramgroup']);
  916.             }
  917.             foreach ($xml['paramgroup'as $i => $group{
  918.                 if (isset($_SESSION['_PEAR_Frontend_Web_ScriptSkipSections'][$group['id']])) {
  919.                     continue;
  920.                 }
  921.                 if (isset($_SESSION['_PEAR_Frontend_Web_ScriptSection'])) {
  922.                     if ($i $_SESSION['_PEAR_Frontend_Web_ScriptSection']{
  923.                         $lastgroup $group;
  924.                         continue;
  925.                     }
  926.                 }
  927.                 if (isset($_SESSION['_PEAR_Frontend_Web_answers'])) {
  928.                     $answers $_SESSION['_PEAR_Frontend_Web_answers'];
  929.                 }
  930.                 if (isset($group['name'])) {
  931.                     if (isset($answers)) {
  932.                         if (isset($answers[$group['name']])) {
  933.                             switch ($group['conditiontype']{
  934.                                 case '=' :
  935.                                     if ($answers[$group['name']] != $group['value']{
  936.                                         continue 2;
  937.                                     }
  938.                                 break;
  939.                                 case '!=' :
  940.                                     if ($answers[$group['name']] == $group['value']{
  941.                                         continue 2;
  942.                                     }
  943.                                 break;
  944.                                 case 'preg_match' :
  945.                                     if (!@preg_match('/' $group['value''/',
  946.                                           $answers[$group['name']])) {
  947.                                         continue 2;
  948.                                     }
  949.                                 break;
  950.                                 default :
  951.                                     $this->_clearScriptSession();
  952.                                 return;
  953.                             }
  954.                         }
  955.                     else {
  956.                         $this->_clearScriptSession();
  957.                         return;
  958.                     }
  959.                 }
  960.                 if (!isset($group['param'][0])) {
  961.                     $group['param'= array($group['param']);
  962.                 }
  963.                 $_SESSION['_PEAR_Frontend_Web_ScriptSection'$i;
  964.                 if (!isset($answers)) {
  965.                     $answers = array();
  966.                 }
  967.                 if (isset($group['param'])) {
  968.                     if (method_exists($script'postProcessPrompts')) {
  969.                         $prompts $script->postProcessPrompts($group['param']$group['name']);
  970.                         if (!is_array($prompts|| count($prompts!= count($group['param'])) {
  971.                             $this->outputData('postinstall''Error: post-install script did not ' .
  972.                                 'return proper post-processed prompts');
  973.                             $prompts $group['param'];
  974.                         else {
  975.                             foreach ($prompts as $i => $var{
  976.                                 if (!is_array($var|| !isset($var['prompt']||
  977.                                       !isset($var['name']||
  978.                                       ($var['name'!= $group['param'][$i]['name']||
  979.                                       ($var['type'!= $group['param'][$i]['type'])) {
  980.                                     $this->outputData('postinstall''Error: post-install script ' .
  981.                                         'modified the variables or prompts, severe security risk. ' .
  982.                                         'Will instead use the defaults from the package.xml');
  983.                                     $prompts $group['param'];
  984.                                 }
  985.                             }
  986.                         }
  987.                         $answers array_merge($answers,
  988.                             $this->confirmDialog($prompts$pkg->getPackage()));
  989.                     else {
  990.                         $answers array_merge($answers,
  991.                             $this->confirmDialog($group['param']$pkg->getPackage()));
  992.                     }
  993.                 }
  994.                 if ($answers{
  995.                     array_unshift($_SESSION['_PEAR_Frontend_Web_ScriptCompletedPhases'],
  996.                         $group['id']);
  997.                     if (!$script->run($answers$group['id'])) {
  998.                         $script->run($_SESSION['_PEAR_Frontend_Web_ScriptCompletedPhases'],
  999.                             '_undoOnError');
  1000.                         $this->_clearScriptSession();
  1001.                         return;
  1002.                     }
  1003.                 else {
  1004.                     $script->run(array()'_undoOnError');
  1005.                     $this->_clearScriptSession();
  1006.                     return;
  1007.                 }
  1008.                 $lastgroup $group;
  1009.                 foreach ($group['param'as $param{
  1010.                     // rename the current params to save for future tests
  1011.                     $answers[$group['id''::' $param['name']] $answers[$param['name']];
  1012.                     unset($answers[$param['name']]);
  1013.                 }
  1014.                 // save the script's variables and user answers for the next round
  1015.                 $_SESSION['_PEAR_Frontend_Web_ScriptObj'= (array) $script;
  1016.                 $_SESSION['_PEAR_Frontend_Web_answers'$answers;
  1017.                 $_SERVER['REQUEST_METHOD''';
  1018.             }
  1019.         }
  1020.         $this->_clearScriptSession();
  1021.     }
  1022.  
  1023.     function _clearScriptSession()
  1024.     {
  1025.         unset($_SESSION['_PEAR_Frontend_Web_ScriptObj']);
  1026.         unset($_SESSION['_PEAR_Frontend_Web_answers']);
  1027.         unset($_SESSION['_PEAR_Frontend_Web_ScriptSection']);
  1028.         unset($_SESSION['_PEAR_Frontend_Web_ScriptCompletedPhases']);
  1029.         unset($_SESSION['_PEAR_Frontend_Web_ScriptSkipSections']);
  1030.     }
  1031.  
  1032.     /**
  1033.      * Ask for user input, confirm the answers and continue until the user is satisfied
  1034.      * @param array an array of arrays, format array('name' => 'paramname', 'prompt' =>
  1035.      *               'text to display', 'type' => 'string'[, default => 'default value'])
  1036.      * @param string Package Name
  1037.      * @return array|false
  1038.      */
  1039.     function confirmDialog($params$pkg)
  1040.     {
  1041.         $answers = array();
  1042.         $prompts $types = array();
  1043.         foreach ($params as $param{
  1044.             $prompts[$param['name']] $param['prompt'];
  1045.             $types[$param['name']] $param['type'];
  1046.             if (isset($param['default'])) {
  1047.                 $answers[$param['name']] $param['default'];
  1048.             else {
  1049.                 $answers[$param['name']] '';
  1050.             }
  1051.         }
  1052.         $attempt = 0;
  1053.         do {
  1054.             if ($attempt{
  1055.                 $_SERVER['REQUEST_METHOD''';
  1056.             }
  1057.             $title !$attempt $pkg ' Install Script Input' 'Please fill in all values';
  1058.             $answers $this->userDialog('run-scripts'$prompts$types$answers$title'',
  1059.                 array('pkg' => $pkg));
  1060.             if ($answers === false{
  1061.                 return false;
  1062.             }
  1063.             $attempt++;
  1064.         while (count(array_filter($answers)) != count($prompts));
  1065.         $_SERVER['REQUEST_METHOD''POST';
  1066.         return $answers;
  1067.     }
  1068.  
  1069.     /**
  1070.      * Display a formular and return the given input (yes. needs to requests)
  1071.      *
  1072.      * @param string $command  command from which this method was called
  1073.      * @param array  $prompts  associative array. keys are the inputfieldnames
  1074.      *                          and values are the description
  1075.      * @param array  $types    (optional) array of inputfieldtypes (text, password,
  1076.      *                          etc.) keys have to be the same like in $prompts
  1077.      * @param array  $defaults (optional) array of defaultvalues. again keys have
  1078.      *                          to be the same like in $prompts
  1079.      * @param string $title    (optional) title of the page
  1080.      * @param string $icon     (optional) iconhandle for this page
  1081.      * @param array  $extra    (optional) extra parameters to put in the form action
  1082.      *
  1083.      * @access public
  1084.      *
  1085.      * @return array input sended by the user
  1086.      */
  1087.  
  1088.     function userDialog($command$prompts$types = array()$defaults = array()$title '',
  1089.                         $icon ''$extra = array())
  1090.     {
  1091.         // If this is an POST Request, we can return the userinput
  1092.         if (isset($_GET["command"]&& $_GET["command"]==$command
  1093.             && $_SERVER["REQUEST_METHOD"== "POST"{
  1094.             if (isset($_POST['cancel'])) {
  1095.                 return false;
  1096.             }
  1097.             $result = array();
  1098.             foreach($prompts as $key => $prompt{
  1099.                 $result[$key$_POST[$key];
  1100.             }
  1101.             return $result;
  1102.         }
  1103.  
  1104.         // If this is an Answer GET Request , we can return the userinput
  1105.         if (isset($_GET["command"]&& $_GET["command"]==$command
  1106.             && isset($_GET["userDialogResult"]&& $_GET["userDialogResult"]=='get'{
  1107.             $result = array();
  1108.             foreach($prompts as $key => $prompt{
  1109.                 $result[$key$_GET[$key];
  1110.             }
  1111.             return $result;
  1112.         }
  1113.  
  1114.         // Assign title and icon to some commands
  1115.         if ($command == 'login'{
  1116.             $title 'Login';
  1117.             $icon 'login';
  1118.         }
  1119.  
  1120.         $tpl $this->_initTemplate("userDialog.tpl.html"$title$icon);
  1121.         $tpl->setVariable("Command"$command);
  1122.         $extrap '';
  1123.         if (count($extra)) {
  1124.             $extrap '&';
  1125.             foreach ($extra as $name => $value{
  1126.                 $extrap .= urlencode($name'=' urlencode($value);
  1127.             }
  1128.         }
  1129.         $tpl->setVariable("extra"$extrap);
  1130.         if (isset($this->_data[$command])) {
  1131.             $tpl->setVariable("Headline"nl2br($this->_data[$command]));
  1132.         }
  1133.  
  1134.         if (is_array($prompts)) {
  1135.             $maxlen = 0;
  1136.             foreach($prompts as $key => $prompt{
  1137.                 if (strlen($prompt$maxlen{
  1138.                     $maxlen strlen($prompt);
  1139.                 }
  1140.             }
  1141.  
  1142.             foreach($prompts as $key => $prompt{
  1143.                 $tpl->setCurrentBlock("InputField");
  1144.                 $type    (isset($types[$key])    $types[$key]    'text');
  1145.                 $default (isset($defaults[$key]$defaults[$key'');
  1146.                 $tpl->setVariable("prompt"$prompt);
  1147.                 $tpl->setVariable("name"$key);
  1148.                 $tpl->setVariable("default"$default);
  1149.                 $tpl->setVariable("type"$type);
  1150.                 if ($maxlen > 25{
  1151.                     $tpl->setVariable("width"'width="275"');
  1152.                 }
  1153.                 $tpl->parseCurrentBlock();
  1154.             }
  1155.         }
  1156.         if ($command == 'run-scripts'{
  1157.             $tpl->setVariable("cancel"'<input type="submit" value="Cancel" name="cancel">');
  1158.         }
  1159.         $tpl->show();
  1160.         exit;
  1161.     }
  1162.  
  1163.     /**
  1164.      * Write message to log
  1165.      *
  1166.      * @param string $text message which has to written to log
  1167.      *
  1168.      * @access public
  1169.      *
  1170.      * @return boolean true
  1171.      */
  1172.  
  1173.     function log($text)
  1174.     {
  1175.         $GLOBALS['_PEAR_Frontend_Web_log'.= $text."\n";
  1176.         $this->_savedOutput[$text;
  1177.         return true;
  1178.     }
  1179.  
  1180.     /**
  1181.      * Sends the required file along with Headers and exits the script
  1182.      *
  1183.      * @param string $handle handle of the requested file
  1184.      * @param string $group  group of the requested file
  1185.      *
  1186.      * @access public
  1187.      *
  1188.      * @return null nothing, because script exits
  1189.      */
  1190.  
  1191.     function outputFrontendFile($handle$group)
  1192.     {
  1193.         $handles = array(
  1194.             "css" => array(
  1195.                 "style" => "style.css",
  1196.                 "dhtml" => "dhtml.css",
  1197.                 ),
  1198.             "js" => array(
  1199.                 "dhtml" => "dhtml.js",
  1200.                 "nodhtml" => "nodhtml.js",
  1201.                 ),
  1202.             "image" => array(
  1203.                 "logout" => array(
  1204.                     "type" => "gif",
  1205.                     "file" => "logout.gif",
  1206.                     ),
  1207.                 "login" => array(
  1208.                     "type" => "gif",
  1209.                     "file" => "login.gif",
  1210.                     ),
  1211.                 "config" => array(
  1212.                     "type" => "gif",
  1213.                     "file" => "config.gif",
  1214.                     ),
  1215.                 "pkglist" => array(
  1216.                     "type" => "png",
  1217.                     "file" => "pkglist.png",
  1218.                     ),
  1219.                 "pkgsearch" => array(
  1220.                     "type" => "png",
  1221.                     "file" => "pkgsearch.png",
  1222.                     ),
  1223.                 "package" => array(
  1224.                     "type" => "jpeg",
  1225.                     "file" => "package.jpg",
  1226.                     ),
  1227.                 "category" => array(
  1228.                     "type" => "jpeg",
  1229.                     "file" => "category.jpg",
  1230.                     ),
  1231.                 "install" => array(
  1232.                     "type" => "gif",
  1233.                     "file" => "install.gif",
  1234.                     ),
  1235.                 "install_wait" => array(
  1236.                     "type" => "gif",
  1237.                     "file" => "install_wait.gif",
  1238.                     ),
  1239.                 "install_ok" => array(
  1240.                     "type" => "gif",
  1241.                     "file" => "install_ok.gif",
  1242.                     ),
  1243.                 "install_fail" => array(
  1244.                     "type" => "gif",
  1245.                     "file" => "install_fail.gif",
  1246.                     ),
  1247.                 "uninstall" => array(
  1248.                     "type" => "gif",
  1249.                     "file" => "trash.gif",
  1250.                     ),
  1251.                 "info" => array(
  1252.                     "type" => "gif",
  1253.                     "file" => "info.gif",
  1254.                     ),
  1255.                 "infoplus" => array(
  1256.                     "type" => "gif",
  1257.                     "file" => "infoplus.gif",
  1258.                     ),
  1259.                 "pear" => array(
  1260.                     "type" => "gif",
  1261.                     "file" => "pearsmall.gif",
  1262.                     ),
  1263.                 "error" => array(
  1264.                     "type" => "gif",
  1265.                     "file" => "error.gif",
  1266.                     ),
  1267.                 "manual" => array(
  1268.                     "type" => "gif",
  1269.                     "file" => "manual.gif",
  1270.                     ),
  1271.                 "download" => array(
  1272.                     "type" => "gif",
  1273.                     "file" => "download.gif",
  1274.                     ),
  1275.                 ),
  1276.             );
  1277.  
  1278.         $file $handles[$group][$handle];
  1279.         switch ($group{
  1280.             case 'css':
  1281.                 header("Content-Type: text/css");
  1282.                 readfile(dirname(__FILE__).'/Web/'.$file);
  1283.                 exit;
  1284.             case 'image':
  1285.                 $filename dirname(__FILE__).'/Web/'.$file['file'];
  1286.                 header("Content-Type: image/".$file['type']);
  1287.                 header("Expires: ".gmdate("D, d M Y H:i:s \G\M\T"time(+ 60*60*24*100));
  1288.                 header("Last-Modified: ".gmdate("D, d M Y H:i:s \G\M\T"filemtime($filename)));
  1289.                 header("Cache-Control: public");
  1290.                 header("Pragma: ");
  1291.                 readfile($filename);
  1292.                 exit;
  1293.             case 'js':
  1294.                 header("Content-Type: text/javascript");
  1295.                 readfile(dirname(__FILE__).'/Web/'.$file);
  1296.                 exit;
  1297.         }
  1298.     }
  1299.  
  1300.     /*
  1301.      * From DB::Pager. Removing Pager dependency.
  1302.      * @private
  1303.      */
  1304.     function __getData($from$limit$numrows$maxpages = false)
  1305.     {
  1306.         if (empty($numrows|| ($numrows < 0)) {
  1307.             return null;
  1308.         }
  1309.         $from (empty($from)) ? 0 : $from;
  1310.  
  1311.         if ($limit <= 0{
  1312.             return false;
  1313.         }
  1314.  
  1315.         // Total number of pages
  1316.         $pages ceil($numrows/$limit);
  1317.         $data['numpages'$pages;
  1318.  
  1319.         // first & last page
  1320.         $data['firstpage'= 1;
  1321.         $data['lastpage']  $pages;
  1322.  
  1323.         // Build pages array
  1324.         $data['pages'= array();
  1325.         for ($i=1; $i <= $pages$i++{
  1326.             $offset $limit ($i-1);
  1327.             $data['pages'][$i$offset;
  1328.             // $from must point to one page
  1329.             if ($from == $offset{
  1330.                 // The current page we are
  1331.                 $data['current'$i;
  1332.             }
  1333.         }
  1334.         if (!isset($data['current'])) {
  1335.             return PEAR::raiseError (null'wrong "from" param'null,
  1336.                                      nullnull'DB_Error'true);
  1337.         }
  1338.               // Limit number of pages (Goole algorithm)
  1339.         if ($maxpages{
  1340.             $radio floor($maxpages/2);
  1341.             $minpage $data['current'$radio;
  1342.             if ($minpage < 1{
  1343.                 $minpage = 1;
  1344.             }
  1345.             $maxpage $data['current'$radio - 1;
  1346.             if ($maxpage $data['numpages']{
  1347.                 $maxpage $data['numpages'];
  1348.             }
  1349.             foreach (range($minpage$maxpageas $page{
  1350.                 $tmp[$page$data['pages'][$page];
  1351.             }
  1352.             $data['pages'$tmp;
  1353.             $data['maxpages'$maxpages;
  1354.         else {
  1355.             $data['maxpages'= null;
  1356.         }
  1357.  
  1358.         // Prev link
  1359.         $prev $from $limit;
  1360.         $data['prev'($prev >= 0$prev : null;
  1361.  
  1362.         // Next link
  1363.         $next $from $limit;
  1364.         $data['next'($next $numrows$next : null;
  1365.  
  1366.         // Results remaining in next page & Last row to fetch
  1367.         if ($data['current'== $pages{
  1368.             $data['remain'= 0;
  1369.             $data['to'$numrows;
  1370.         else {
  1371.             if ($data['current'== ($pages - 1)) {
  1372.                 $data['remain'$numrows ($limit*($pages-1));
  1373.             else {
  1374.                 $data['remain'$limit;
  1375.             }
  1376.             $data['to'$data['current'$limit;
  1377.         }
  1378.         $data['numrows'$numrows;
  1379.         $data['from']    $from + 1;
  1380.         $data['limit']   $limit;
  1381.  
  1382.         return $data;
  1383.     }
  1384.  
  1385.     // }}}
  1386. }
  1387.  
  1388. ?>

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