cvs: pearweb /include browser.php /public_html packages.php /public_html/gifs moreinfo.gif /templates packages.html

From: Date: Fri, 22 Nov 2002 19:39:03 +0000
Subject: cvs: pearweb /include browser.php /public_html packages.php /public_html/gifs moreinfo.gif /templates packages.html
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-7538@lists.php.net to get a copy of this message
richard Fri Nov 22 14:39:03 2002 EDT Added files: /pearweb/public_html/gifs moreinfo.gif /pearweb/include browser.php /pearweb/templates packages.html Modified files: /pearweb/public_html packages.php Log: Make package listing screen nicer. Comments/suggestions welcome though bear in mind this is unfinished.

Index: pearweb/public_html/packages.php diff -u pearweb/public_html/packages.php:1.31 pearweb/public_html/packages.php:1.32 --- pearweb/public_html/packages.php:1.31 Tue Aug 13 11:48:16 2002 +++ pearweb/public_html/packages.php Fri Nov 22 14:39:03 2002 @@ -13,17 +13,22 @@ | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ - | Authors: | + | Authors: Richard Heyes | +----------------------------------------------------------------------+ - $Id: packages.php,v 1.31 2002/08/13 15:48:16 mj Exp $ + $Id: packages.php,v 1.32 2002/11/22 19:39:03 richard Exp $ */ /** * TODO * o Number of packages in brackets does not include packages in subcategories +* o Make headers in package list clickable for ordering */ -require 'HTML/Table.php'; +$template_dir = dirname(dirname(__FILE__)) . '/templates/'; + +require_once('HTML/Table.php'); +require_once('Pager/Pager.php'); +require_once('Net/URL.php'); /** * Returns an appropriate query string @@ -43,6 +48,18 @@ } /** +* Check for the hide/show all extended info boxes +*/ + if (!empty($_GET['hideMoreInfo'])) { + setcookie('hideMoreInfo', '1', time() + (86400 * 7)); + localRedirect('packages.php' . getQueryString(@$_GET['catpid'], @$_GET['catname'])); + + } elseif (!empty($_GET['showMoreInfo'])) { + setcookie('hideMoreInfo', '-1', time() + (86400 * 7)); + localRedirect('packages.php' . getQueryString(@$_GET['catpid'], @$_GET['catname'])); + } + +/** * Check input variables * Expected url vars: catpid (category parent id), catname, showempty */ @@ -160,55 +177,92 @@ } /** -* Print the urhere text, showempty link -* and the categories -*/ -echo '<table border="0" width="100%"><tr><th valign="top" align="left">Contents of :: '; -html_category_urhere($catpid, false); -echo '</th><td valign="top" align="right">'.$showempty_link.'</td></tr>'; -// echo '<tr><td colspan="2">Looking for something specific? Try the <a href="package-search.php">package search</a>.</td></tr>'; -print '</table>'; - -/** * Begin code for showing packages if we * aren't at the top level. */ -if (!empty($catpid)) { - $nrow = 0; - // Subcategories list - $more = ($showempty) ? 0 : 1; - $subcats = $dbh->getAll("SELECT id, name, summary FROM categories WHERE ". - "parent = $catpid AND npackages >= $more", DB_FETCHMODE_ASSOC); - if (count($subcats) > 0) { - $sub_links = array(); - foreach ($subcats as $subcat) { - $sub_links[] = '<b><a href="'.$_SERVER['PHP_SELF'].'?catpid='.$subcat['id'].'&catname='. - urlencode($subcat['name']).'" title="'.htmlspecialchars($subcat['summary']).'">'.$subcat['name'].'</a></b>'; - } - print '<br />Sub-categories: ' . implode(', ', $sub_links) . '<br />'; - } - - // Package list - $sth = $dbh->query("SELECT id, name, summary FROM packages WHERE category=$catpid ORDER BY name"); - print "<dl>\n"; - while ($sth->fetchInto($row)) { - extract($row); - print " <dt><a href=\"package-info.php?pacid=$id\">$name</a></dt>\n"; - print " <dd>$summary</dd>\n"; - print " <br /><br />\n"; - } -} - -echo $nrow != 0 ? $table->toHtml() : ''; -$sth->free(); + if (!empty($catpid)) { + $nrow = 0; + // Subcategories list + $minPackages = ($showempty) ? 0 : 1; + $subcats = $dbh->getAll("SELECT id, name, summary FROM categories WHERE " . + "parent = $catpid AND npackages >= $minPackages", DB_FETCHMODE_ASSOC); + if (count($subcats) > 0) { + foreach ($subcats as $subcat) { + $subCategories[] = sprintf('<b><a href="%s?catpid=%d&catname=%s" title="%s">%s</a></b>', + $_SERVER['PHP_SELF'], + $subcat['id'], + urlencode($subcat['name']), + htmlspecialchars($subcat['summary']), + $subcat['name']); + } + $subCategories = implode(', ', $subCategories); + } + + // Package list + $packages = $dbh->getAll("SELECT id, name, summary, license FROM packages WHERE category=$catpid ORDER BY name"); + + // Paging + $total = count($packages); + $pager = new Pager(array('totalItems' => $total, 'perPage' => 15)); + list($first, $last) = $pager->getOffsetByPageId(); + list($prev, $pages, $next) = $pager->getLinks('<nobr><img src="gifs/prev.gif" width="10" height="10" border="0" alt="&lt;&lt;" />Back</nobr>', '<nobr>Next<img src="gifs/next.gif" width="10" height="10" border="0" alt="&gt;&gt;" /></nobr>'); + + $packages = array_slice($packages, $first - 1, 15); + + foreach ($packages as $key => $pkg) { + $extendedInfo['numReleases'] = $dbh->getOne('SELECT COUNT(*) FROM releases WHERE package = ' . $pkg['id']); + $extendedInfo['status'] = $dbh->getOne('SELECT state FROM releases WHERE package = ' . $pkg['id'] . ' ORDER BY id DESC LIMIT 1'); + + // Make status coloured + switch ($extendedInfo['status']) { + case 'stable': + $extendedInfo['status'] = '<span style="color: #006600">Stable</span>'; + break; + + case 'beta': + $extendedInfo['status'] = '<span style="color: #ffc705">Beta</span>'; + break; + + case 'alpha': + $extendedInfo['status'] = '<span style="color: #ff0000">Alpha</span>'; + break; + } + + $packages[$key]['eInfo'] = $extendedInfo; + } + + /** + * More info visibility + */ + if (@$_COOKIE['hideMoreInfo'] == '1') { + $defaultMoreInfoVis = 'none'; + + } elseif (@$_COOKIE['hideMoreInfo'] == '-1') { + $defaultMoreInfoVis = 'inline'; + + } elseif ($_browser->is_ie5up) { + $defaultMoreInfoVis = 'none'; + + } else { + $defaultMoreInfoVis = 'inline'; + } + } + +/** +* Build URLs for hide/show all links +*/ + $url = new Net_URL(); + $url->addQueryString('hideMoreInfo', '1'); + $hideMoreInfoLink = $url->getURL(); + + $url->removeQueryString('hideMoreInfo'); + $url->addQueryString('showMoreInfo', '1'); + $showMoreInfoLink = $url->getURL(); -//Print total number of packages or a link to category stats -if(!$catpid) { - echo "<br /><br />\nTotal number of packages: " . $totalpackages; - echo "<br />" . make_link('/package-stats.php', 'View package statistics'); -} else { - echo "<br /><br />\n<a href=\"/package-stats.php?cid=$catpid\">Statistics for category &quot;$catname&quot;</a>"; -} +/** +* Template +*/ + error_reporting(E_ALL & ~E_NOTICE); + include($template_dir . 'packages.html'); -response_footer(); ?> Index: pearweb/include/browser.php +++ pearweb/include/browser.php <?php /* +----------------------------------------------------------------------+ | PEAR Web site version 1.0 | +----------------------------------------------------------------------+ | Copyright (c) 2001 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. | +----------------------------------------------------------------------+ | Authors: Richard Heyes | +----------------------------------------------------------------------+ $Id: browser.php,v 1.1 2002/11/22 19:39:02 richard Exp $ */ /** * Based on PEAR::Net_UserAgent_Detect */ class browser { /** * Array that stores all of the flags for the vendor and version of * the different browsers. The flags key values are show in the array. * @var array $browser */ var $browser = array('ns', 'ns2', 'ns3', 'ns4', 'ns4up', 'nav', 'ns6', 'ns6up', 'gecko', 'ie', 'ie3', 'ie4', 'ie4up', 'ie5', 'ie5_5', 'ie5up', 'ie6', 'ie6up', 'opera', 'opera2', 'opera3', 'opera4', 'opera5', 'opera5up', 'aol', 'aol3', 'aol4', 'aol5', 'aol6', 'aol7', 'webtv', 'aoltv', 'tvnavigator', 'hotjava', 'hotjava3', 'hotjava3up'); /** * The leading identifier is the very first term in the user agent string, which is * used to identify clients which are not Mosaic-based browsers. * @var string $leadingIdentifier */ var $leadingIdentifier = ''; /** * The full version of the client as supplied by the very first numbers in the user agent * @var float $version */ var $version = 0; /** * The major part of the client version, which is the integer value of the version. * @var integer $majorVersion */ var $majorVersion = 0; /** * The minor part of the client version, which is the decimal parts of the version * @var float $subVersion */ var $subVersion = 0; /** * Constructor * * @param */ function browser($in_useragent = null) { $this->detect($in_useragent); } /** * Detect the user agent and prepare flags, features and quirks based on what is found * * This is the core of the Net_UserAgent_Detect class. It moves its way through the user agent * string setting up the flags based on the vendors and versions of the browsers, determining * the OS and setting up the features and quirks owned by each of the relevant clients. * * @access public * @param string (optional) user agent override * @return void */ function detect($in_userAgent = null) { // Detemine what user agent we are using if (is_null($in_userAgent)) { $this->userAgent = $GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT']; } else { $this->userAgent = $in_userAgent; } // Get the lowercase version for case-insensitive searching $agt = strtolower($this->userAgent); // Initialize the flag arrays $brwsr =& $this->browser; $brwsr = array_flip($brwsr); // Get the type and version of the client preg_match(";^([[:alpha:]]+)[ /\(]*[[:alpha:]]*([\d]*)\.([\d\.]*);", $agt, $matches); @list(, $this->leadingIdentifier, $this->majorVersion, $this->subVersion) = $matches; if (empty($this->leadingIdentifier)) { $this->leadingIdentifier = 'Unknown'; } $this->version = $this->majorVersion . '.' . $this->subVersion; $brwsr['konq'] = (strpos($agt, 'konqueror') !== false); $brwsr['text'] = (strpos($agt, 'links') !== false) || (strpos($agt, 'lynx') !== false) || (strpos($agt, 'w3m') !== false); $brwsr['ns'] = (strpos($agt, 'mozilla') !== false) && !(strpos($agt, 'spoofer') !== false) && !(strpos($agt, 'compatible') !== false) && !(strpos($agt, 'hotjava') !== false) && !(strpos($agt, 'opera') !== false) && !(strpos($agt, 'webtv') !== false) ? 1 : 0; $brwsr['ns2'] = $brwsr['ns'] && $this->majorVersion == 2; $brwsr['ns3'] = $brwsr['ns'] && $this->majorVersion == 3; $brwsr['ns4'] = $brwsr['ns'] && $this->majorVersion == 4; $brwsr['ns4up'] = $brwsr['ns'] && $this->majorVersion >= 4; // determine if this is a Netscape Navigator $brwsr['nav'] = $brwsr['ns'] && ((strpos($agt, ';nav') !== false) || ((strpos($agt, '; nav') !== false))); $brwsr['ns6'] = !$brwsr['konq'] && $brwsr['ns'] && $this->majorVersion == 5; $brwsr['ns6up'] = $brwsr['ns6'] && $this->majorVersion >= 5; $brwsr['gecko'] = (strpos($agt, 'gecko') !== false); $brwsr['ie'] = (strpos($agt, 'msie') !== false) && !(strpos($agt, 'opera') !== false); $brwsr['ie3'] = $brwsr['ie'] && $this->majorVersion < 4; $brwsr['ie4'] = $brwsr['ie'] && $this->majorVersion == 4 && (strpos($agt, 'msie 4') !== false); $brwsr['ie4up'] = $brwsr['ie'] && $this->majorVersion >= 4; $brwsr['ie5'] = $brwsr['ie'] && $this->majorVersion == 4 && (strpos($agt, 'msie 5.0') !== false); $brwsr['ie5_5'] = $brwsr['ie'] && $this->majorVersion == 4 && (strpos($agt, 'msie 5.5') !== false); $brwsr['ie5up'] = $brwsr['ie'] && !$brwsr['ie3'] && !$brwsr['ie4']; $brwsr['ie5_5up'] = $brwsr['ie'] && !$brwsr['ie3'] && !$brwsr['ie4'] && !$brwsr['ie5']; $brwsr['ie6'] = $brwsr['ie'] && $this->majorVersion == 4 && (strpos($agt, 'msie 6.') !== false); $brwsr['ie6up'] = $brwsr['ie'] && !$brwsr['ie3'] && !$brwsr['ie4'] && !$brwsr['ie5'] && !$brwsr['ie5_5']; $brwsr['opera'] = (strpos($agt, 'opera') !== false); $brwsr['opera2'] = (strpos($agt, 'opera 2') !== false) || (strpos($agt, 'opera/2') !== false); $brwsr['opera3'] = (strpos($agt, 'opera 3') !== false) || (strpos($agt, 'opera/3') !== false); $brwsr['opera4'] = (strpos($agt, 'opera 4') !== false) || (strpos($agt, 'opera/4') !== false); $brwsr['opera5'] = (strpos($agt, 'opera 5') !== false) || (strpos($agt, 'opera/5') !== false); $brwsr['opera5up'] = $brwsr['opera'] && !$brwsr['opera2'] && !$brwsr['opera3'] && !$brwsr['opera4']; $brwsr['aol'] = (strpos($agt, 'aol') !== false); $brwsr['aol3'] = $brwsr['aol'] && $brwsr['ie3']; $brwsr['aol4'] = $brwsr['aol'] && $brwsr['ie4']; $brwsr['aol5'] = (strpos($agt, 'aol 5') !== false); $brwsr['aol6'] = (strpos($agt, 'aol 6') !== false); $brwsr['aol7'] = (strpos($agt, 'aol 7') !== false); $brwsr['webtv'] = (strpos($agt, 'webtv') !== false); $brwsr['aoltv'] = $brwsr['tvnavigator'] = (strpos($agt, 'navio') !== false) || (strpos($agt, 'navio_aoltv') !== false); $brwsr['hotjava'] = (strpos($agt, 'hotjava') !== false); $brwsr['hotjava3'] = $brwsr['hotjava'] && $this->majorVersion == 3; $brwsr['hotjava3up'] = $brwsr['hotjava'] && $this->majorVersion >= 3; /** * Setup easy access to the above variables */ foreach ($brwsr as $key => $value) { $this->{'is_' . $key} = $value; } } } ?> Index: pearweb/templates/packages.html +++ pearweb/templates/packages.html <script language="JavaScript" type="text/javascript"> <!-- function toggleMoreInfo(packageID, rowNode) { if (!document.getElementById) { location.href = 'http://pearweb/package-info.php?pacid=' + packageID; return; } var rowLayer = document.getElementById('moreInfo_' + packageID); var rowSpacerLayer = document.getElementById('moreInfo_' + packageID + '_spacer'); newDisplay = rowLayer.style.display == 'none' ? 'inline' : 'none'; rowLayer.style.display = newDisplay; rowSpacerLayer.style.display = newDisplay; } //--> </script> <table border="0" width="100%"> <tr> <th valign="top" align="left"> Contents of :: <?html_category_urhere($catpid, false)?> </th> <td valign="top" align="right"> <?=$showempty_link?> </td> </tr> </table> <?if($nrow):?> <?=$table->toHtml()?> <?endif?> <?if($catpid):?> <br /> <?if($subCategories):?> Sub-categories: <?=$subCategories?><br /><br /> <?endif?> <style type="text/css"> <!-- th.pkgListHeader { background-color: #cccccc; } td.tableHeader { background-color: #cccccc; border-bottom: 1px solid black; font-weight: bold; } td.moreInfo { background-color: #f0f0f0; border: 1px dashed #c0c0c0; position: relative; } .closeButton { position: absolute; top: 0px; right: 0px; font-family: Marlett; fonzt-size: 80%; background-color: #c0c0c0; border: 2px outset white; width: 1px; height: 1px; cursor: pointer; cursor: hand; } .moreInfoText { font-size: 80%; font-weight: bold; font-family: Verdana; } // --> </style> <table border="0" style="border: solid 1px black" cellspacing="0" cellpadding="0"> <tr> <td> <table border="0" width="100%" cellspacing="0"> <tr class="tableHeader"> <td class="tableHeader" width="50" align="left">&nbsp;<?=$prev?></td> <td class="tableHeader" align="center">Packages (<?=$first?> - <?=$last?> of <?=$total?>)</td> <td class="tableHeader" width="50" align="right"><?=$next?>&nbsp;</td> </tr> </table> </td> </tr> <tr> <td> <table border="0" id="packageList"> <tr> <th class="pkgListHeader">#</td> <th class="pkgListHeader"><nobr>Package name</nobr></td> <th class="pkgListHeader">Description</td> <th class="pkgListHeader">Status</td> <td>&nbsp;</td> </tr> <?foreach($packages as $p):?> <tr> <td valign="top"><?=$first++?></td> <td valign="top"><a href="package-info.php?pacid=<?=$p['id']?>"><strong><?=$p['name']?></strong></td> <td valign="top"><?=$p['summary']?></td> <td valign="top"><?=$p['eInfo']['status']?></td> <td valign="top"> <a href="#" onclick="toggleMoreInfo(<?=$p['id']?>); return false" onmouseover="window.status = 'View more info about <?=$p['name']?>'; return true" onmouseout="window.status = ''" title="View more info about <?=$p['name']?>"> <img src="gifs/moreinfo.gif" border="0" /> </a> </td> </tr> <!-- <tr <?if($_browser->is_ie5up):?> style="display: <?=$defaultMoreInfoVis?>" <?endif?> id="moreInfo_<?=$p['id']?>"> <td>&nbsp;</td> <td colspan="3" class="moreInfo"> <div style="background-color: #dddddd; border-bottom: 1px dashed #c0c0c0; position: absolute; top: 0px; left: 0px; width: 100%"> <div class="closeButton" onclick="toggleMoreInfo(<?=$p['id']?>)">r</div> <span class="moreInfoText">More information</span> </div> <br> <table border="0"> <tr> <td>Number of releases:</td> <td><?=$p['eInfo']['numReleases']?></td> </tr> </table> </td> <td>&nbsp;</td> </tr> <tr <?if($_browser->is_ie5up):?> style="display: <?=$defaultMoreInfoVis?>" <?endif?> id="moreInfo_<?=$p['id']?>_spacer"><td colspan="5">&nbsp;</td></tr> --> <?endforeach?> </table> </td> </tr> </table> <?endif?> <br /> <p align="center"> <?if(!$catpid):?> Total number of packages: <?=$totalpackages?><br /> <?make_link('/package-stats.php', 'View package statistics')?> <?else:?> <a href="/package-stats.php?cid=<?=$catpid?>">Statistics for category "<?=$catname?>"</a> <?endif?> </p> <?response_footer()?>
« previous php.pear.cvs (#7538) next »