--- Info161.php 2006-03-09 16:00:47.000000000 +0100 +++ Info170.php 2006-06-09 23:41:01.859375000 +0200 @@ -1,57 +1,123 @@ | -// +----------------------------------------------------------------------+ -// -// $Id: Info.php,v 1.24 2006/03/09 15:00:47 fa Exp $ +/** + * This package generate phpinfo() style PEAR information. + * + * PHP versions 4 and 5 + * + * LICENSE: This source file is subject to version 3.01 of the PHP license + * that is available through the world-wide-web at the following URI: + * http://www.php.net/license/3_01.txt. If you did not receive a copy of + * the PHP License and are unable to obtain it through the web, please + * send a note to license@php.net so we can mail you a copy immediately. + * + * @category PEAR + * @package PEAR_Info + * @author Davey Shafik + * @license http://www.php.net/license/3_01.txt PHP License 3.01 + * @version CVS: $Id:$ + * @since File available since Release 1.0.1 + */ require_once 'PEAR/Remote.php'; require_once 'PEAR/Registry.php'; /** - * PEAR_Info generate phpinfo() style PEAR information + * The PEAR_Info class generate phpinfo() style PEAR information. + * + * @category PEAR + * @package PEAR_Info + * @author Davey Shafik + * @license http://www.php.net/license/3_01.txt PHP License 3.01 + * @version Release: @package_version@ + * @since Class available since Release 1.0.1 */ class PEAR_Info { + /** + * Html code for phpinfo() style PEAR information + * + * @var string + * @access public + * @since 1.0.1 + */ + var $info; /** - * PEAR_Info Constructor - * @param pear_dir string[optional] - * @return bool + * Style sheet for the custom layout + * + * @var string + * @access public + * @since 1.7.0 + */ + var $css; + + /** + * instance of PEAR_config + * + * @var object + * @access public + * @since 1.0.1 + */ + var $config; + + /** + * instance of PEAR_Registry + * + * @var object + * @access public + * @since 1.0.1 + */ + var $reg; + + /** + * instance of PEAR_Remote + * + * @var object + * @access private + * @since 1.0.1 + */ + var $r; + + /** + * PHP 4 style constructor (ZE1) + * + * @param string $pear_dir (optional) The PEAR base install directory + * @param string $pear_user_config (optional) File to read user-defined options from + * @return void * @access public + * @since 1.0.1 */ + function PEAR_Info($pear_dir = false, $pear_user_config = false) + { + $this->__construct($pear_dir, $pear_user_config); + } - function PEAR_Info($pear_dir = FALSE, $pear_user_config = FALSE) + /** + * PHP 5 style constructor (ZE2) + * + * @param string $pear_dir (optional) The PEAR base install directory + * @param string $pear_user_config (optional) File to read user-defined options from + * @return void + * @access private + * @since 1.7.0 + */ + function __construct($pear_dir = false, $pear_user_config = false) { - if($pear_user_config === FALSE) { + if ($pear_user_config === false) { $this->config = new PEAR_Config(); } else { - $this->config = new PEAR_Config($pear_user_config); + $this->config = new PEAR_Config($pear_user_config); } - if ($pear_dir != FALSE) { + if ($pear_dir != false) { $this->config->set('php_dir',$pear_dir); } if (defined('PEAR_INFO_PROXY')) { - $this->config->set('http_proxy',PEAR_INFO_PROXY); + $this->config->set('http_proxy', PEAR_INFO_PROXY); } $this->r = new PEAR_Remote($this->config); $this->reg = new PEAR_Registry($this->config->get('php_dir')); // get PEARs packageInfo to show version number at the top of the HTML - if (method_exists($this->reg, 'getPackage')) { $pear = $this->reg->getPackage("PEAR"); $pear_version = $pear->getVersion(); @@ -64,102 +130,211 @@ class PEAR_Info if ($this->config->get('preferred_state') == 'stable') { $this->list_options = true; } - ob_start(); - ?> - - - - PEAR :: PEAR_Info() - - - - - - - - -
- PEAR Logo

PEAR

-
- PEAR Credits'; - // Get packageInfo and Show the HTML for the Packages - $this->getConfig(); - echo '
'; - $this->getPackages(); + $this->info = ' + + + + +
+ PEAR Logo

PEAR {pearversion}

+
+'; + $this->info = str_replace( + array('{phpself}', '{pearversion}'), + array(htmlentities($_SERVER['PHP_SELF']), $pear_version), + $this->info + ); + + if (!isset($_GET['credits'])) { + $this->info .= ' +

PEAR Credits

+'; + $this->info = str_replace( + '{phpself}', htmlentities($_SERVER['PHP_SELF']), + $this->info + ); - } else { - $this->getCredits(); - } - ?> - - - info = ob_get_contents(); - ob_end_clean(); - /* With later versions of this where we properly implement the CLI such and stuff - this will return the actual status of whether or not creating the PEAR_Info object worked */ - return true; + $this->info .= $this->getConfig(); + $this->info .= $this->getPackages(); + + } else { + $this->info .= $this->getCredits(); + } } /** * Set PEAR http_proxy for remote calls - * @param proxy string + * + * @param string $proxy HTTP Proxy Server Address + * @static * @return bool * @access public + * @since 1.0.6 */ - function setProxy($proxy) { - define('PEAR_INFO_PROXY',$proxy); - return true; + $res = define('PEAR_INFO_PROXY', $proxy); + return $res; + } + + /** + * Returns the custom style sheet to use for layout + * + * @param bool $content (optional) Either return css filename or string contents + * @return string + * @access public + * @since 1.7.0 + */ + function getStyleSheet($content = true) + { + if ($content) { + $styles = file_get_contents($this->css); + } else { + $styles = $this->css; + } + return $styles; + } + + /** + * Set the custom style sheet to use your own styles + * + * @param string $css (optional) File to read user-defined styles from + * @return bool True if custom styles, false if default styles applied + * @access public + * @since 1.7.0 + */ + function setStyleSheet($css = null) + { + // default stylesheet is into package data directory + if (!isset($css)) { + $this->css = '@data_dir@' . DIRECTORY_SEPARATOR + . '@package_name@' . DIRECTORY_SEPARATOR + . 'pearinfo.css'; + } + + $res = isset($css) && file_exists($css); + if ($res) { + $this->css = $css; + } + return $res; } /** * Retrieve and format PEAR Packages info - * @return void + * + * @return string * @access private + * @since 1.0.1 */ - function getPackages() { $latest = @$this->r->call('package.listLatestReleases'); - $available = $this->reg->listPackages(); + $available = $this->reg->listAllPackages(); if (PEAR::isError($available)) { - echo '

An Error occured fetching the package list. Please try again.

'; - return FALSE; + $e = '

An Error occured while fetching the package list.' + . ' Please try again.

'; + return $e; } if (!is_array($available)) { - echo '

The package list could not be fetched from the remote server. Please try again.

'; - return FALSE; + $e = '

The package list could not be fetched from the remote server.' + . ' Please try again.

'; + return $e; } - natcasesort($available); if ((PEAR::isError($latest)) || (!is_array($latest))) { - $latest = FALSE; + $latest = false; } + $packages = ''; - foreach ($available as $name) { - $installed = $this->reg->packageInfo($name); - if (isset($installed['package']) && strlen($installed['package']) > 1) { + foreach ($available as $channel => $pkg) { + foreach ($pkg as $name) { + $info = &$this->reg->getPackage($name, $channel); + if (is_object($info)) { + $installed['package'] = $info->getPackage(); + $installed['summary'] = $info->getSummary(); + $installed['version'] = $info->getVersion(); + $installed['description'] = $info->getDescription(); + $installed['release_state'] = $info->getState(); + } else { + $installed = $info; + $installed['release_state'] = $info['state']; + } + + $deps = $info->getDeps(); + if (is_array($deps)) { + static $_deps_rel_trans = array( + 'lt' => '<', + 'le' => '<=', + 'eq' => '=', + 'ne' => '!=', + 'gt' => '>', + 'ge' => '>=', + 'has' => 'has' + ); + static $_deps_type_trans = array( + 'pkg' => 'Package', + 'ext' => 'Extension', + 'php' => 'PHP' + ); + + $dependencies = ''; + $ptpl = ' + + + {dep_required} + + + {dep_type} + + + {dep_name} + + + {dep_rel} + + + {dep_version} + + +'; + foreach($deps as $dep) { + $dependencies .= str_replace( + array('{dep_required}', + '{dep_type}', + '{dep_name}', + '{dep_rel}', + '{dep_version}', + ), + array(($dep['optional'] == 'no') ? 'Yes' : 'No', + $_deps_type_trans[$dep['type']], + $dep['name'], + $_deps_rel_trans[$dep['rel']], + $dep['version'] + ), + $ptpl + ); + } + $ptpl = ' + + + Required + + + Type + + + Name + + + Relation + + + Version + + +'; + $dependencies = $ptpl . $dependencies; + } + if (!isset($old_index)) { $old_index = ''; } @@ -169,207 +344,282 @@ class PEAR_Info $old_index = $current_index; $this->index[] = $current_index; } + $ptpl = ' +

{package}

+ + + + + + + + + + + + + + + + +'; + + if (!empty($dependencies)) { + $ptpl .= ' + + + +'; + } + + $packages .= str_replace( + array('{package}', + '{summary}', + '{version}', + '{description}', + '{release_state}', + '{dependencies}' + ), + array(trim($installed['package']), + nl2br(htmlentities(trim($installed['summary']))), + trim($installed['version']), + nl2br(htmlentities(trim($installed['description']))), + trim($installed['release_state']), + $dependencies + ), + $ptpl + ); + + if ($latest != false) { + if (isset($latest[$installed['package']])) { + if (version_compare($latest[$installed['package']]['version'], + $installed['version'], '>')) { + $ptpl = ' + + + +'; + $packages .= str_replace( + array('{package}', + '{latest_version}', + '{latest_state}' + ), + array(trim($installed['package']), + $latest[$installed['package']]['version'], + $latest[$installed['package']]['state'] + ), + $ptpl + ); + } + } + } $packages .= ' -

' .trim($installed['package']). '

-
+ Summary + + {summary} +
+ Version + + {version} +
+ Description + + {description} +
+ State + + {release_state} +
+ Dependencies + + + {dependencies} +
+
+ Latest Version + + {latest_version}({latest_state}) +
- - - - - - - - - - - - - - - - - - - '; - if ($latest != FALSE) { - if (isset($latest[$installed['package']])) { - if (version_compare($latest[$installed['package']]['version'],$installed['version'],'>')) { - $packages .= ' - - - '; - } - } - } - $packages .= ' - - -
- Summary - - ' .nl2br(htmlentities(trim($installed['summary']))). ' -
- Version - - ' .trim($installed['version']). ' -
- Description - - ' .nl2br(htmlentities(trim($installed['description']))). ' -
- State - - ' .trim($installed['release_state']). ' -
- Information -
- Latest Version - - ' .$latest[$installed['package']]['version'] . ' - ('. $latest[$installed['package']]['state']. ') -
Top
'; + + Top + + +'; } } - ?> -

PEAR Packages

- - - - - - + +
- Index -
- PEAR Packages + + + + + + - -
+ Index +
+'; foreach ($this->index as $i) { - ?> - | - | -
-
- '.strtoupper($i).''; + } + $index .= ' | +
+ +'; + $s = $index . $packages; + return $s; } /** * Retrieves and formats the PEAR Config data - * @return void + * + * @return string * @access private + * @since 1.0.1 */ - function getConfig() { $keys = $this->config->getKeys(); sort($keys); - ?> -

PEAR Config

- - PEAR Config +
'; foreach ($keys as $key) { if (($key != 'password') && ($key != 'username') && ($key != 'sig_keyid') && ($key != 'http_proxy')) { - ?> - - - - - + + +'; + $html_config = str_replace( + array('{key}', '{value}'), + array($key, $this->config->get($key)), + $html_config + ); + $html_pear_config .= $html_config; } } - ?> -
config->get($key); ?>
{key}{value}
- + +'; + return $html_pear_config; } /** * Retrieves and formats the PEAR Credits - * @return void + * + * @return string * @access private + * @since 1.0.1 */ - function getCredits() { - ?> -

PEAR Credits

- - - - - - - -
- PEAR Website Team -
- Stig Bakken, - Thomas V.V.Cox, - Martin Jansen, - Colin Viebrock, - Richard Heyes -
-
- - - - - - - -
- PEAR documentation team -
- Thomas V.V.Cox, - Martin Jansen, - Alexander Merz -
- reg->listPackages(); - + $html_pear_credits = ' +

PEAR Credits

+ + + + + + + +
+ PEAR Website Team +
+ Stig Bakken, + Thomas V.V.Cox, + Martin Jansen, + Colin Viebrock, + Richard Heyes +
+ + + + + + + + +
+ PEAR documentation team +
+ Thomas V.V.Cox, + Martin Jansen, + Alexander Merz +
+'; + $available = $this->reg->listAllPackages(); if (PEAR::isError($available)) { - echo '

An Error occured fetching the credits from the remote server. Please try again.

'; - return FALSE; + $e = '

An Error occured while fetching the credits from the remote server.' + . ' Please try again.

'; + return $e; } if (!is_array($available)) { - echo '

The credits could not be fetched from the remote server. Please try again.

'; - return FALSE; - } - echo '
'; - echo ''; - sort($available); - foreach ($available as $name) { - $installed = $this->reg->packageInfo($name); - if (isset($installed['package']) && strlen($installed['package']) > 1) { - ?> - - - - - The credits could not be fetched from the remote server.' + . ' Please try again.

'; + return $e; + } + $html_pear_credits .= ' +
PackageMaintainers
- - - - ' .htmlentities($i['name']). '' .' (' .$i['role']. ')'; - } - echo implode(', ',$maintainers); - ?> -
+ +'; + foreach ($available as $channel => $pkg) { + foreach ($pkg as $name) { + $info = &$this->reg->getPackage($name, $channel); + if (is_object($info)) { + $installed['package'] = $info->getPackage(); + $installed['maintainers'] = $info->getMaintainers(); + } else { + $installed = $info; + } + + $ptpl = ' + + + +'; + $maintainers = array(); + foreach ($installed['maintainers'] as $i) { + $maintainers[] = '' + . htmlentities($i['name']) + . '' + .' (' . $i['role'] . ')'; + } + $maintainers = implode(', ',$maintainers); + + $html_pear_credits .= str_replace( + array('{packageURI}', + '{package}', + '{maintainers}' + ), + array(trim(strtolower($installed['package'])), + trim($installed['package']), + $maintainers + ), + $ptpl + ); } } - echo '
PackageMaintainers
+ {package} + + {maintainers} +
'; + $html_pear_credits .= ''; + return $html_pear_credits; } /** * outputs the PEAR logo + * * @return void * @access public + * @since 1.0.1 */ - function pearImage() { $pear_image = 'R0lGODlhaAAyAMT/AMDAwP3+/TWaAvD47Pj89vz++zebBDmcBj6fDEekFluvKmu3PvX68ujz4XvBS8LgrNXqxeHw1ZnPaa/dgvv9+cLqj8LmltD2msnuls'; @@ -391,33 +641,92 @@ class PEAR_Info /** * Shows PEAR_Info output + * * @return void * @access public + * @since 1.0.1 + * @deprecated use display() instead */ - function show() { - echo $this->info; + $this->display(); } - + /** - * Check if a package is installed + * Displays PEAR_Info output + * + * @return void + * @access public + * @since 1.7.0 */ - - function packageInstalled($package_name, $version = null, $pear_user_config = null) - { - if(is_null($pear_user_config)) { - $config = new PEAR_Config(); - } else { - $config = new PEAR_Config($pear_user_config); + function display() + { + echo $this->toHtml(); + } + + /** + * Returns PEAR_Info output (html code) + * + * @return string + * @access public + * @since 1.7.0 + */ + function toHtml() + { + if (!isset($this->css)) { + // when no user-styles defined, used the default values + $this->setStyleSheet(); } - + $styles = $this->getStyleSheet(); + + $body = $this->info; + + $html = << + + +PEAR :: PEAR_Info() + + + + +$body + + +HTML; + return $html; + } + + /** + * Check if a package is installed + * + * @param string $name Package name + * @param string $version (optional) The minimal version that should be installed + * @param string $channel (optional) The package channel distribution + * @param string $pear_user_config (optional) File to read user-defined options from + * @static + * @return bool + * @access public + * @since 1.6.0 + */ + function packageInstalled($name, $version = null, $channel = null, $pear_user_config = null) + { + $config = new PEAR_Config($pear_user_config); $reg = new PEAR_Registry($config->get('php_dir')); - + if (is_null($version)) { - return $reg->packageExists($package_name); - } else { - $installed = $reg->packageInfo($package_name); + return $reg->packageExists($name, $channel); + } else { + $info = &$reg->getPackage($name, $channel); + if (is_object($info)) { + $installed['version'] = $info->getVersion(); + } else { + $installed = $info; + } return version_compare($version, $installed['version'], '<='); } } @@ -427,4 +736,4 @@ if (isset($_GET['pear_image'])) { PEAR_Info::pearImage(); exit; } -?> +?> \ No newline at end of file