Source for file pear-format-html.php
Documentation is available at pear-format-html.php
+----------------------------------------------------------------------+
| PEAR Web site version 1.0 |
+----------------------------------------------------------------------+
| Copyright (c) 2001-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 2.02 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available at through the world-wide-web at |
| http://www.php.net/license/2_02.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
+----------------------------------------------------------------------+
$Id: pear-format-html.php,v 1.192 2006/10/21 18:08:27 cellog Exp $
PEAR ::setErrorHandling (PEAR_ERROR_CALLBACK , 'error_handler');
static $extra_styles = array ();
// needed for error reporting handling in startup
$GLOBALS['_NODB'] = true;
require_once 'pear-cache.php';
// $dbh is initialized in pear-cache
$GLOBALS['_NODB'] = false;
// Handling things related to the manual
if (substr($self, 0 , 7 ) == '/manual') {
if (substr($self, 7 , 10 ) != "/index.php") {
require_once 'pear-manual.php';
* Prints out the XHTML headers and top of the page.
* @param string $title a string to go into the header's <title>
function response_header($title = 'The PHP Extension and Application Repository', $style = false , $extraHeaders = '')
global $_style, $_header_done, $SIDEBAR_DATA, $self, $auth_user;
$rts = rtrim($SIDEBAR_DATA);
if (substr($rts, -1 ) == '-') {
$SIDEBAR_DATA = substr($rts, 0 , -1 );
if (!$GLOBALS['_NODB']) {
// if reporting an error, no database access will be performed
include_once 'pear-auth.php';
if (!empty ($auth_user)) {
if (!empty ($auth_user->registered )) {
if ($auth_user->isAdmin ()) {
if ($GLOBALS['in_manual'] == false ) {
/* The manual-related code takes care of sending the right
header('Content-Type: text/html; charset=ISO-8859-15');
echo '<?xml version="1.0" encoding="ISO-8859-15" ?>';
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<title>PEAR :: <?php echo $title; ?></title>
<link rel="shortcut icon" href="/gifs/favicon.ico" />
<link rel="stylesheet" href="/css/style.css" />
foreach ($extra_styles as $style_file) {
echo ' <link rel="stylesheet" href="' . $style_file . "\" />\n";
<link rel="alternate" type="application/rss+xml" title="RSS feed" href="http:// <?php echo htmlspecialchars($_SERVER['HTTP_HOST']); ?>/feeds/latest.rss" />
if (!empty ($GLOBALS['ONLOAD'])) {
print 'onload="' . $GLOBALS['ONLOAD']. '"';
<table id="head-menu" class="head" cellspacing="0" cellpadding="0">
<?php print_link('/', make_image('pearsmall.gif', 'PEAR', false , false , false , false , 'margin: 5px;') ); ?><br />
print_link('/account-request.php', 'Register', false ,
if ($_SERVER['QUERY_STRING'] && $_SERVER['QUERY_STRING'] != 'logout=1') {
"{ $self}?{ $_SERVER['QUERY_STRING']}" ),
'Login', false , 'class="menuBlack"');
'Login', false , 'class="menuBlack"');
print '<small class="menuWhite">';
print 'Logged in as ' . strtoupper($auth_user->handle ) . ' (';
print '<a class="menuWhite" href="/user/' . $auth_user->handle . '">Info</a> | ';
print '<a class="menuWhite" href="/account-edit.php?handle=' . $auth_user->handle . '">Profile</a> | ';
print '<a class="menuWhite" href="/bugs/search.php?handle=' . $auth_user->handle . '&cmd=display">Bugs</a>';
print ")</small><br />\n";
if (empty ($_SERVER['QUERY_STRING'])) {
print_link('?logout=1', 'Logout', false , 'class="menuBlack"');
'Logout', false , 'class="menuBlack"');
print_link('/manual/', 'Documentation', false , 'class="menuBlack"');
print_link('/packages.php', 'Packages', false , 'class="menuBlack"');
print_link('/support/','Support',false , 'class="menuBlack"');
print_link('/bugs/','Bugs',false , 'class="menuBlack"');
<td class="head-search" colspan="2">
<form method="get" action="/search.php">
<p class="head-search"><span class="accesskey">S</span>earch for
<input class="small" type="text" name="q" value="" size="20" accesskey="s" />
<select name="in" class="small">
<option value="packages">Packages</option>
<option value="site">This site (using Yahoo!)</option>
<option value="users">Developers</option>
<option value="pear-dev">Developer mailing list</option>
<option value="pear-general">General mailing list</option>
<option value="pear-cvs">CVS commits mailing list</option>
<input type="image" src="/gifs/small_submit_white.gif" alt="search" style="vertical-align: middle;" />
<table class="middle" cellspacing="0" cellpadding="0">
if (isset ($SIDEBAR_DATA)) {
<!-- START LEFT SIDEBAR -->
<td class="sidebar_left">
<?php echo $SIDEBAR_DATA ?>
<!-- END LEFT SIDEBAR -->
<!-- START MAIN CONTENT -->
global $LAST_UPDATED, $MIRRORS, $MYSITE, $COUNTRIES,$SCRIPT_NAME, $RSIDEBAR_DATA;
$style = $GLOBALS['_style'];
<!-- END MAIN CONTENT -->
if (isset ($RSIDEBAR_DATA)) {
<!-- START RIGHT SIDEBAR -->
<td class="sidebar_right">
<?php echo $RSIDEBAR_DATA; ?>
<!-- END RIGHT SIDEBAR -->
<table class="foot" cellspacing="0" cellpadding="0">
<td class="foot-bar" colspan="2">
print_link('/about/privacy.php', 'PRIVACY POLICY', false , 'class="menuBlack"');
print_link('/about/credits.php', 'CREDITS', false , 'class="menuBlack"');
'Copyright © 2001-2006 The PHP Group'); ?><br />
Last updated: <?php echo $LAST_UPDATED; ?><br />
Bandwidth and hardware provided by:
if ($_SERVER['SERVER_NAME'] == 'pear.php.net') {
print_link('http://www.pair.com/', 'pair Networks');
print '<i>This is an unofficial mirror!</i>';
'/qa/' => 'Quality Assurance',
'/group/' => 'The PEAR Group',
'/manual/en/about-pear.php' => 'About PEAR',
'/manual/index.php' => 'Manual',
'/manual/en/faq.php' => 'FAQ',
'/support/' => 'Support',
'/packages.php' => 'List Packages',
'/search.php' => 'Search Packages',
'/package-stats.php' => 'Statistics'
'/accounts.php' => 'List Accounts',
'/release-upload.php' => 'Upload Release',
'/package-new.php' => 'New Package'
case 'developer_menu_public':
'/accounts.php' => 'List Accounts'
'/pepr/' => 'Browse Proposals',
'/pepr/pepr-proposal-edit.php' => 'New Proposal'
if (!empty ($menu_title)) {
$html .= " <strong>$menu_title</strong>\n";
$html .= '<ul class="side_pages">' . "\n";
foreach ($data as $url => $tit) {
$html .= ' <li class="side_page">';
$html .= '<strong>' . $tit . '</strong>';
$html .= '<a href="' . $url . '">' . $tit . '</a>';
print_link($url, '<strong>' . $text . '</strong>' );
* Display errors or warnings as a <ul> inside a <div>
* Here's what happens depending on $in:
* + string: value is printed
* + array: looped through and each value is printed.
* If array is empty, nothing is displayed.
* If a value contains a PEAR_Error object,
* + PEAR_Error: prints the value of getMessage() and getUserInfo()
* if DEVBOX is true, otherwise prints data from getMessage().
* @param string|array|PEAR_Error$in see long description
* @param string $class name of the HTML class for the <div> tag.
* @param string $head string to be put above the message
* @return bool true if errors were submitted, false if not
function report_error($in, $class = 'errors', $head = 'ERROR:')
if (PEAR ::isError ($in)) {
$in = array ($in->getMessage () . '... ' . $in->getUserInfo ());
$in = array ($in->getMessage ());
echo '<div class="' . $class . '">' . $head . '<ul>';
if (PEAR ::isError ($msg)) {
$msg = $msg->getMessage () . '... ' . $msg->getUserInfo ();
$msg = $msg->getMessage ();
* Forwards warnings to report_error()
* For use with PEAR_ERROR_CALLBACK to get messages to be formatted
* as warnings rather than errors.
* @param string|array|PEAR_Error$in see report_error() for more info
* @return bool true if errors were submitted, false if not
* Generates a complete PEAR web page with an error message in it then
* For use with PEAR_ERROR_CALLBACK error handling mode to print fatal
* @param string|array|PEAR_Error$in see report_error() for more info
* @param string $title string to be put above the message
* Displays success messages inside a <div>
* @param string $in the message to be displayed
echo '<div class="success">';
function BorderBox($title, $width = '90%', $indent = '', $cols = 1 ,
$title = implode('</th><th>', $title);
print "<!-- border box starts -->\n";
print " $i<table cellpadding=\"0\" cellspacing=\"1\" style=\"width: $this->width; border: 0px;\">\n";
print " $i <td style=\"background-color: #000000;\">\n";
print " $i <table cellpadding=\"2\" cellspacing=\"1\" style=\"width: 100%; border: 0px;\">\n";
print " $i <tr style=\"background-color: #CCCCCC;\">\n";
print " colspan=\"$this->cols\"";
print " $i <tr style=\"background-color: #FFFFFF;\">\n";
print "<!-- border box ends -->\n";
print " $i <th style=\"vertical-align: top; background-color: #CCCCCC;\">$heading</th>\n";
for ($j = 0; $j < $this->cols-1; $j++ ) {
print " $i <td style=\"vertical-align: top; background-color: #E8E8E8\">";
for ($j = 0; $j < $this->cols; $j++ ) {
print " $i <th style=\"vertical-align: top; background-color: #FFFFFF;\">";
for ($j = 0; $j < $this->cols; $j++ ) {
print " $i <td style=\"vertical-align: top; background-color: #FFFFFF;\">";
print " $i <td style=\"background-color: #E8E8E8;\"";
print " colspan=\"$this->cols\"";
* prints "urhere" menu bar
* Top Level :: XML :: XML_RPC
* @param bool $link_lastest If the last category should or not be a link
$html = '<a href="/packages.php">Top Level</a>';
$res = $dbh->query (" SELECT c.id, c.name
FROM categories c, categories cat
AND c.cat_left <= cat.cat_left
AND c.cat_right >= cat.cat_right" );
$nrows = $res->numRows ();
while ($res->fetchInto ($row, DB_FETCHMODE_ASSOC )) {
if (!$link_lastest && $i >= $nrows -1 ) {
" <a href=\"/packages.php?catpid={$row['id']}&catname={$row['name']}\">".
$html .= ' :: <strong>' . $row['name'] . '</strong>';
* Returns an absolute URL using Net_URL
* @param string $url All/part of a url
* @return string Full url
include_once 'Net/URL.php';
$obj = new Net_URL ($url);
* Redirects to the given full or partial URL.
* will turn the given url into an absolute url
* using the above getURL() function. This function
* @param string $url Full/partial url to redirect to
* @param bool $keepProtocol Whether to keep the current protocol or to force HTTP
$url = getURL($url, $keepProtocol);
if ($keepProtocol == false ) {
* Get URL to license text
* @todo Add more licenses here
* @param string Name of the license
* @return string Link to license URL
case 'PHP License 3.01' :
$link = 'http://www.php.net/license/3_01.txt';
$link = 'http://www.php.net/license/2_02.txt';
case 'GNU General Public License' :
$link = 'http://www.gnu.org/licenses/gpl.html';
case 'GNU Lesser General Public License' :
$link = 'http://www.gnu.org/licenses/lgpl.html';
$link = 'http://www.opensource.org/licenses/bsd-license.php';
$link = 'http://www.opensource.org/licenses/mit-license.php';
return ($link != '' ? '<a href="' . $link . '">' . $license . "</a>\n" : $license);
$bb = new BorderBox(" Notes for user $user" , $width);
$notes = $dbh->getAssoc ("SELECT id,nby,ntime,note FROM notes
WHERE uid = ? ORDER BY ntime", true , array ($user));
print '<table cellpadding="2" cellspacing="0" style="border: 0px;">' . "\n";
foreach ($notes as $nid => $data) {
print " <strong>{$data['nby']} {$data['ntime']}:</strong>";
print " <tr><td> </td></tr>\n";
* Create link to the account information page and to the user's wishlist
* @param string User's handle
* @param bool Should the wishlist link be skipped?
* @return mixed False on error, otherwise string
function user_link($handle, $compact = false )
$query = "SELECT name, wishlist FROM users WHERE handle = '" . $handle . "'";
$row = $dbh->getRow ($query, DB_FETCHMODE_ASSOC );
return sprintf("<a href=\"/user/%s\">%s</a> %s\n",
($row['wishlist'] != "" && $compact == false ? '['. make_link('http://' . htmlspecialchars($_SERVER['HTTP_HOST']) . '/wishlist.php/' . $handle, 'Wishlist'). ']' : '')
* Returns a hyperlink to something
function make_link($url, $linktext = '', $target = '', $extras = '')
return sprintf('<a href="%s"%s%s>%s</a>',
($target ? ' target="'. $target. '"' : ''),
($extras ? ' '. $extras : ''),
($linktext != '' ? $linktext : $url)
* Echos a hyperlink to something
function print_link($url, $linktext = '', $target = '', $extras = '')
echo make_link($url, $linktext, $target, $extras);
* Creates a link to the bug system
$linktext = 'Package Bugs';
return make_link('/bugs/search.php?cmd=display&status=Open&package_name[]=' . urlencode($package), $linktext);
$linktext = 'Report a new bug';
* Turns the provided email address into a "mailto:" hyperlink.
* The link and link text are obfuscated by alternating Ord and Hex
* @param string $email the email address to make the link for
* @param string $linktext a string for the visible part of the link.
* If not provided, the email address is used.
* @param string $extras a string of extra attributes for the <a> element
* @return string the HTML hyperlink of an email address
for ($i = 0 , $l = strlen($email); $i< $l; $i++ ) {
$tmp .= '&#' . ord($email[$i]) . ';';
$tmp .= '&#x' . dechex(ord($email[$i])) . ';';
return '<a ' . $extras . ' href="mailto:'
. $tmp . '">' . ($linktext != '' ? $linktext : $tmp) . '</a>';
* Prints an IMG tag for a sized spacer GIF
function spacer($width = 1 , $height = 1 , $align = '', $extras = '')
printf('<img src="/gifs/spacer.gif" width="%d" height="%d" style="border: 0px;" alt="" %s%s />',
($align ? 'align="'. $align. '" ' : ''),
* Tags the output of make_image() and resize it manually
$str = substr($str,0 ,-1 ) . sprintf(' height="%s" width="%s" />', $height, $width );
* Returns an IMG tag for a given file (relative to the images dir)
function make_image($file, $alt = '', $align = '', $extras = '', $dir = '',
$border = 0 , $styles = '')
if ($size = @getimagesize($_SERVER['DOCUMENT_ROOT']. $dir. '/'. $file)) {
$image = sprintf('<img src="%s/%s" style="border: %d;%s%s" %s alt="%s" %s />',
($styles ? ' '. $styles : ''),
($align ? ' float: '. $align. ';' : ''),
($extras ? ' '. $extras : '')
$image = sprintf('<img src="%s/%s" style="border: %d;%s%s" alt="%s" %s />',
($styles ? ' '. $styles : ''),
($align ? ' float: '. $align. ';' : ''),
($extras ? ' '. $extras : '')
* Prints an IMG tag for a given file
function print_image($file, $alt = '', $align = '', $extras = '', $dir = '',
print make_image($file, $alt, $align, $extras, $dir);
function delim($color = false , $delimiter = ' | ')
return sprintf('<span style="color: %s;">%s</span>', $color, $delimiter);
* Prints a horizontal delimiter
* Prints a tabbed navigation bar based on the parameter $items
echo '<div id="nav">' . "\n";
foreach ($items as $title => $item) {
echo '<a href="' . $item['url']
. '" title="' . $item['title'] . '"';
if ($page == $item['url']) {
echo '>' . $title . "</a>";
* Prints a tabbed navigation bar for the various package pages.
* @param int $pacid the id number of the package being viewed
* @param string $name the name of the package being viewed
* @param string $action the indicator of the current page view
$nav_items = array ('Main' => array ('url' => '',
'Download' => array ('url' => 'download',
'title' => 'Download releases of this package'),
'Documentation' => array ('url' => 'docs',
'title' => 'Read the available documentation'),
'Bugs' => array ('url' => 'bugs',
'title' => 'View/Report Bugs'),
'Trackbacks' => array ('url' => 'trackbacks',
'title' => 'Show Related Sites'),
'Wiki' => array('url' => 'wiki',
'title' => 'View wiki area')*/
if (isset ($auth_user) && is_object($auth_user)) {
$nav_items['Edit'] = array ('url' => '/package-edit.php?id='. $pacid,
'title' => 'Edit this package');
$nav_items['Edit Maintainers'] = array ('url' => '/admin/package-maintainers.php?pid='. $pacid,
'title' => 'Edit the maintainers of this package');
$nav_items['Delete'] = array ('url' => '/package-delete.php?id='. $pacid,
'title' => 'Delete this package');
foreach ($nav_items as $title => $item) {
if (!empty ($item['url']) && $item['url']{0 } == '/') {
print '<a href="' . $url . '"'
. ' title="' . $item['title'] . '" '
. ($action == $item['url'] ? ' class="active" ' : '')
* Sets <var>$_SESSION['captcha']</var> and
* <var>$_SESSION['captcha_time']</var> then prints the XHTML that
* displays a CAPTCHA image and a form input element
* Only generate a new <var>$_SESSION['captcha']</var> if it doesn't exist
* yet. This avoids the problem of the CAPTCHA value being changed but the
* old image remaining in the browser's cache. This is necessary because
* caching can not be reliably disabled.
* Use upper case letters to reduce confusion with some of these fonts.
* Input is passed through strtoupper() before comparison.
* Don't use "I" or "O" to avoid confusion with numbers. Don't use digits
* because some of the fonts don't handle them.
* @return string the CAPTCHA image and form intut
* @see validate_captcha(), captcha-image.php
if (!isset ($_SESSION['captcha'])) {
$_SESSION['captcha'] = '';
$useable = 'ABCDEFGHJKLMNPQRSTUVWXYZ';
for ($i = 0; $i < 4; $i++ ) {
$_SESSION['captcha_time'] = time();
return 'Type <img src="/captcha-image.php?x=' . time()
. '" alt="If you are unable to'
. ' read this image, click the help link to the right of'
. ' the input box" align="top" /> into this box...'
. ' <input type="text" size="4" maxlength="4" name="captcha" />'
. ' (<a href="/captcha-help.php" target="_blank">help</a>)'
. ' <br />If this image is hard to read, reload the page.';
* Check if the CAPTCHA value submitted by the user in
* <var>$_POST['captcha']</var> matches <var>$_SESSION['captcha']</var>
* and that the submission was made within the allowed time frame
* of the CAPTCHA being generated
* If the two values aen't the same or the length of time between CAPTCHA
* generation and form submission is too long, this function will unset()
* <var>$_SESSION['captcha']</var>. Unsetting it will cause
* generate_captcha() to come up with a new CAPTCHA value and image.
* This prevents brute force attacks.
* Similarly, if the submission is correct <var>$_SESSION['captcha']</var>
* is unset() in order to keep robots from making multiple requests with
* a correctly guessed CAPTCHA value.
* @param int $max_age the length of time in seconds since the CAPTCHA was
* generated during which a submission should be
* considered valid. Default is 300 seconds
* @return bool true if input matches captcha, false if not
* @see generate_captcha(), captcha-image.php
if (!isset ($_POST['captcha']) ||
!isset ($_SESSION['captcha']) ||
(time() - $_SESSION['captcha_time']) > $max_age ||
$_SESSION['captcha'] != strtoupper($_POST['captcha']))
unset ($_SESSION['captcha']);
unset ($_SESSION['captcha_time']);
unset ($_SESSION['captcha']);
unset ($_SESSION['captcha_time']);
* Turns bug/feature request numbers into hyperlinks
* If the bug number is prefixed by the word "PHP," the link will
* go to bugs.php.net. Otherwise, the bug is considered a PEAR bug.
* @param string $text the text to check for bug numbers
* @return string the string with bug numbers hyperlinked
$text = preg_replace('/(?<=php)\s*(bug|request)\s+#?([0-9]+)/i',
' <a href="http://bugs.php.net/\\2">\\1 \\2</a>',
$text = preg_replace('/(?<![>a-z])(bug|request)\s+#?([0-9]+)/i',
'<a href="/bugs/\\2">\\0</a>', $text);
Documentation generated on Tue, 24 Oct 2006 21:32:28 -0400 by phpDocumentor 1.3.0. PEAR Logo Copyright © PHP Group 2004.
|