cvs: phpweb / quickref.php

From: Date: Sun, 20 Jul 2003 15:18:15 +0000
Subject: cvs: phpweb / quickref.php
Groups: php.mirrors 
Request: Send a blank email to php-mirrors+get-19415@lists.php.net to get a copy of this message
goba Sun Jul 20 11:18:15 2003 EDT Modified files: /phpweb quickref.php Log: Quickref remake: - updating code to use modern control structures and variables - double the size of "found functions" for searches - distribute results and the big function list in 3 columns, instead of 2, as there is many data, and there is plenty of space for that - make use of the user's language preference while searching, so only results available in the preferred language will be returned Index: phpweb/quickref.php diff -u phpweb/quickref.php:1.24 phpweb/quickref.php:1.25 --- phpweb/quickref.php:1.24 Sat May 17 18:13:15 2003 +++ phpweb/quickref.php Sun Jul 20 11:18:15 2003 @@ -1,110 +1,148 @@ <?php -/* $Id: quickref.php,v 1.24 2003/05/17 22:13:15 jacques Exp $ */ -require_once 'prepend.inc'; +// $Id: quickref.php,v 1.25 2003/07/20 15:18:15 goba Exp $ -$NUMACROSS = 2; -$SHOW_CLOSE = 10; +/* -// A quick fix, the whole file needs a cleanup [Goba] -$lang = $LANG; - -function makeTable($lang,$array) { - global $NUMACROSS; - - echo '<table border="0" cellpadding="5" cellspacing="0" width="580">'; - echo '<tr valign="top"><td width="50%">'; - $i = 0; - $limit = ceil(count($array)/$NUMACROSS); - asort($array); - while (list($file,$name)=each($array)) { - if ($i>0 && $i%$limit==0) { - echo "</td><td width=\"50%\">\n"; - } - echo "<a href=\"/manual/".$lang."/".$file."\">".$name."</a><br>\n"; - $i++; - } - echo '</td></tr></table>'; + This page is either directly called from the browser, in + which case it will always show the full list of "functions" + in the user's preferred language version of the PHP + documentation. + + In other cases this file is included from manual-lookup.php, + which sets $notfound, so we know what function to search for, + and display results for that search. + +*/ + +// Ensure that our environment is set up +include_once $_SERVER['DOCUMENT_ROOT'] . '/include/prepend.inc'; + +// Constant values for the display +define("COLUMNS", 3); +define("SHOW_CLOSE", 20); + +// Print out the table of found (or all) functions +function quickref_table($functions) +{ + global $LANG; + + echo '<table border="0" cellpadding="5" cellspacing="0" width="100%">'; + echo '<tr valign="top"><td>'; + + // Prepare the data + $i = 0; + $limit = ceil(count($functions) / COLUMNS); + asort($functions); + + // Print out all rows + foreach ($functions as $file => $name) { + + // Start a new column + if ($i > 0 && $i % $limit==0) { + echo "</td><td>\n"; + } + echo "<a href=\"/manual/$LANG/$file\">$name</a><br />\n"; + $i++; + } + echo '</td></tr></table>'; } -$d = dir("$DOCUMENT_ROOT/manual/en"); -$functions = $maybe = $temp = array(); +$dirh = opendir($_SERVER['DOCUMENT_ROOT'] . "/manual/$LANG"); +$functions = $maybe = $temp = $parts = array(); $p = 0; -while ( $entry=$d->read() ) { - if (substr($entry, 0, 1) == ".") { - continue; - } - if (ereg('(function|class)\.(.+)\.php',$entry,$x)) { - $funcname = str_replace('-', '_', $x[2]); - $functions[$entry] = $funcname; - - if (function_exists('similar_text') && $notfound) { - similar_text($funcname, $notfound, $p); - $temp[$entry] = $p; - } - - } +// Get all file names from the directory +while (($entry = readdir($dirh)) !== FALSE) { + + // Skip names starting with a dot + if (substr($entry, 0, 1) == ".") { continue; } + + // For function and class pages, get the name out + if (preg_match('!(function|class)\.(.+)\.php!', $entry, $parts)) { + $funcname = str_replace('-', '_', $parts[2]); + $functions[$entry] = $funcname; + + // Compute similarity of the name to the requested one + if (function_exists('similar_text') && $notfound) { + similar_text($funcname, $notfound, $p); + $temp[$entry] = $p; + } + } } -$d->close(); -arsort($temp); +closedir($dirh); -$i = 0; -while (list($file,$p)=each($temp)) { - $funcname = $functions[$file]; - $maybe[$file] = $funcname; - if ($p>=70 || stristr($funcname,$notfound)) { - $maybe[$file] = '<b>' . $functions[$file] . '</b>'; - } - if ($i++ > $SHOW_CLOSE) { - break; - } -} +// We have found file names +if (count($temp) > 0) { + // Sort names by percentage + arsort($temp); + + // Collect SHOW_CLOSE number of names from the top + foreach ($temp as $file => $p) { + + // Stop, if we found enough matches + if (count($maybe) >= SHOW_CLOSE) { break; } + + // If the two are more then 70% similar or $notfound is a substring + // of $funcname, then the match is a very similar one + if ($p >= 70 || (strpos($functions[$file], $notfound) !== FALSE)) { + $maybe[$file] = '<b>' . $functions[$file] . '</b>'; + } + // Otherwise it is just similar + else { + $maybe[$file] = $functions[$file]; + } + } + unset($matches, $temp); +} -commonHeader("PHP Manual Quick Reference"); +commonHeader("Manual Quick Reference"); ?> <h1>PHP Function List</h1> -<?php if ($notfound) { ?> +<?php if ($notfound && count($maybe) > 0) { ?> <p> -Sorry, but the function <b><?php echo htmlspecialchars($notfound); ?></b> is not in the online manual. -Perhaps you misspelled it, or it is a relatively new function that hasn't -made it into the online documentation yet. The following are the -<?php echo $SHOW_CLOSE; ?> functions which seem to be closest in spelling -to <b><?php echo htmlspecialchars($notfound); ?></b> (really good matches are in bold). Perhaps -you were looking for one of these: + Sorry, but the function <b><?php echo htmlspecialchars($notfound); ?></b> + is not in the online manual. Perhaps you misspelled it, or it is a relatively + new function that hasn't made it into the online documentation yet. The + following are the <?php echo count($maybe); ?> functions which seem to be + closest in spelling to <b><?php echo htmlspecialchars($notfound); ?></b> + (really good matches are in bold). Perhaps you were looking for one of these: </p> -<?php makeTable($lang,$maybe); ?> +<?php quickref_table($maybe); ?> <p> -If you want to search the entire PHP website for the string -&quot;<b><?php echo htmlspecialchars($notfound); ?></b>&quot;, then -<?php print_link('search.php?show=wholesite&amp;pattern='.urlencode(htmlspecialchars($notfound)), 'click here'); ?>. + If you want to search the entire PHP website for the string + "<b><?php echo htmlspecialchars($notfound); ?></b>", then +<?php + print_link('search.php?show=wholesite&amp;pattern=' . + urlencode(htmlspecialchars($notfound)), + 'click here'); +?>. </p> <p> -For a quick overview over all PHP functions, -<?php print_link('quickref.php', 'click here') ?>. + For a quick overview over all documented PHP functions, + <?php print_link('quickref.php', 'click here'); ?>. </p> <?php - commonFooter(); - exit; + commonFooter(); + exit; } ?> <p> -Here is a list of all the PHP functions. Click on any one of them to -jump to that page in the manual. + Here is a list of all the documented PHP functions. + Click on any one of them to jump to that page in the + manual. </p> -<?php makeTable($lang,$functions); ?> - -</td></tr> -</table> - -<?php commonFooter(); ?> +<?php +quickref_table($functions); +commonFooter(); +?> \ No newline at end of file

« previous php.mirrors (#19415) next »