mirror of
https://github.com/php/web-php.git
synced 2026-03-23 23:02:13 +01:00
Do a web search from the manual-lookup page when a function is not found
This commit is contained in:
89
include/results.inc
Normal file
89
include/results.inc
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
// $Id: $
|
||||
function search_results($res, $q, $profile='all', $per_page=10, $s=0, $l='en', $show_title=true, $show_foot=true, $show_attrib=true) {
|
||||
$start_result = $s;
|
||||
$end_result = $s + $res['ResultSet']['totalResultsReturned'] -1;
|
||||
|
||||
$results_count = ($res['ResultSet']['totalResultsAvailable'] < 100 ? $res['ResultSet']['totalResultsAvailable'] : 'more than 100');
|
||||
|
||||
$disp_start_result = $start_result + 1;
|
||||
$disp_end_result = $end_result + 1;
|
||||
if($show_title) echo "<h2>Showing results $disp_start_result to $disp_end_result of $results_count</h2>\n";
|
||||
echo '<ul id="search-results">'."\n";
|
||||
$pos = $res['ResultSet']['firstResultPosition'];
|
||||
|
||||
$php_img_dir = 'http://static.php.net/www.php.net/images';
|
||||
$types = array(
|
||||
'pear' => '<img src="'. $php_img_dir .'/pear_item.gif" height="19" width="17" style="float:left; margin-left:-30px;"/>',
|
||||
'pecl' => '<img src="'. $php_img_dir .'/pecl_item.gif" height="19" width="17" style="float:left; margin-left:-30px;"/>',
|
||||
'pecl4win' => '<img src="'. $php_img_dir .'/pecl_item_win.gif" height="22" width="21" style="float:left; margin-left:-31px;"/>',
|
||||
'peclbugs' => '<img src="'. $php_img_dir .'/pecl_item_bug.gif" height="19" width="17" style="float:left; margin-left:-30px;"/>',
|
||||
'pearbugs' => '<img src="'. $php_img_dir .'/pear_item_bug.gif" height="19" width="17" style="float:left; margin-left:-30px;"/>',
|
||||
'talks' => '<img src="'. $php_img_dir .'/ele-icon.gif" height="20" width="32" style="float:left; margin-left:-40px;"/>',
|
||||
'snaps' => '<img src="'. $php_img_dir .'/logos/php_xpstyle_ico.png" height="32" width="32" style="float:left; margin-left:-40px;"/>',
|
||||
'cvsweb' => '<img src="'. $php_img_dir .'/logos/php_script_ico.png" height="32" width="32" style="float:left; margin-left:-40px;"/>',
|
||||
'viewcvs' => '<img src="'. $php_img_dir .'/logos/php_script_ico.png" height="32" width="32" style="float:left; margin-left:-40px;"/>',
|
||||
'news' => '<img src="'. $php_img_dir .'/logos/php-icon-white.gif" height="32" width="32" style="float:left; margin-left:-40px;"/>',
|
||||
'php' => '<img src="'. $php_img_dir .'/logos/php-icon-white.gif" height="32" width="32" style="float:left; margin-left:-40px;"/>',
|
||||
'doc' => '<img src="'. $php_img_dir .'/logos/php-icon-white.gif" height="32" width="32" style="float:left; margin-left:-40px;"/>',
|
||||
'bugs' => '<img src="'. $php_img_dir .'/php_bug.gif" height="32" width="32" style="float:left; margin-left:-40px;"/>',
|
||||
'gtk' => '<img src="'. $php_img_dir .'/logos/php-gtk-white.gif" height="26" width="32" style="float:left; margin-left:-40px;"/>'
|
||||
);
|
||||
|
||||
foreach($res['ResultSet']['Result'] as $i => $hit) {
|
||||
$cnt = $pos + $i;
|
||||
|
||||
$d = date('j M Y', $hit['ModificationDate']);
|
||||
$cachelink = '';
|
||||
if (isset($hit['Cache'])) {
|
||||
$cachelink = " - <a href=\"{$hit['Cache']}\">Cached</a>";
|
||||
}
|
||||
|
||||
// rewrite mirrors urls (\w\w\d? or www, but not qa, doc, gtk and ~/user)
|
||||
$real_url = preg_replace('@^http://(?!doc|qa|gtk)\w{2,3}\.php\.net(?!/~)(.*)$@', '$1', $hit['Url']);
|
||||
$displayurl = preg_replace('@^http://(?:(?!doc|qa|php|gtk)\w{2,3}\.)?(.+[^/])/?$@', '$1', $hit['Url']);
|
||||
$type = substr($displayurl,0,strpos($displayurl,'.'));
|
||||
if($type=='pecl' && strstr($displayurl,"/bugs/")) $type = "peclbugs";
|
||||
if($type=='pear' && strstr($displayurl,"/bugs/")) $type = "pearbugs";
|
||||
if($type=='smarty') continue;
|
||||
$display_title = str_replace(array('PHP:', '&'), array('', '&'), $hit['Title']);
|
||||
|
||||
// Fall back to the PHP logo for unknown hits
|
||||
if (!isset($types[$type])) {
|
||||
$type = "php";
|
||||
}
|
||||
|
||||
// Fix &gt; double escaping
|
||||
$summary = str_replace('&', '&', $hit['Summary']);
|
||||
echo <<<EOB
|
||||
<li>
|
||||
<p class="result">{$types[$type]}<a href="{$real_url}">{$display_title}</a></p>
|
||||
<p class="summary">{$summary}</p>
|
||||
<p class="meta">{$displayurl} - {$d} {$cachelink}</p>
|
||||
</li>
|
||||
EOB;
|
||||
}
|
||||
echo "</ul>\n";
|
||||
if($show_attrib):
|
||||
echo <<<EOB
|
||||
<span style="margin-left: 3em; margin-top: 1em; float: left; font-family: Verdana, Tahoma, Helvetica, Arial;
|
||||
font-size: 11px; color:#555;">results by <img style="margin-bottom:4px;" src="/images/bing.png" align="center"/></span>
|
||||
EOB;
|
||||
endif;
|
||||
if($show_foot):
|
||||
echo <<<EOB
|
||||
<div id="results_nav"><h4>Results Page:</h4>
|
||||
<ul id="results_nav_list">
|
||||
EOB;
|
||||
$start = 0;
|
||||
for($z=1; $z < 11; $z++) {
|
||||
if($start > $res['ResultSet']['totalResultsAvailable']) {
|
||||
break;
|
||||
}
|
||||
printf('<li><a href="/results.php?q=%s&start=%d&p=%s&l=%s">%d</a></li>', urlencode($q), $start, $profile, urlencode($l), $z);
|
||||
$start += $per_page;
|
||||
}
|
||||
echo '</ul></div>';
|
||||
endif;
|
||||
}
|
||||
?>
|
||||
17
quickref.php
17
quickref.php
@@ -19,6 +19,7 @@
|
||||
$_SERVER['BASE_PAGE'] = 'quickref.php';
|
||||
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/prepend.inc';
|
||||
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/errors.inc';
|
||||
include $_SERVER['DOCUMENT_ROOT'] . '/include/results.inc';
|
||||
|
||||
// Constant values for the display
|
||||
define("COLUMNS", 3);
|
||||
@@ -146,6 +147,22 @@ $notfound_enc = urlencode($notfound_sc);
|
||||
|
||||
<?php quickref_table($maybe, false); ?>
|
||||
|
||||
<?php
|
||||
if(strlen($notfound) > 2):
|
||||
$srch_rqst = "/ws.php?profile=local&q=".urlencode($notfound)."&lang=$LANG&results=5&start=0&mirror=".trim(substr($MYSITE,7),'/');
|
||||
$url = "http://www.php.net".$srch_rqst;
|
||||
$data = fetch_contents($url);
|
||||
if(!is_array($data)) {
|
||||
$res = unserialize($data);
|
||||
if(is_array($res) && $res['ResultSet']['totalResultsAvailable'] > 0) {
|
||||
// Ok, we got some results from the search backend
|
||||
echo "<br /><h1>Site Search Results</h1>\n";
|
||||
search_results($res, $notfound, 'local', 10, 0, $LANG, false, false, false);
|
||||
echo '<br clear="left"/>';
|
||||
}
|
||||
}
|
||||
endif;
|
||||
?>
|
||||
<h1>Other forms of search</h1>
|
||||
|
||||
<p>
|
||||
|
||||
87
results.php
87
results.php
@@ -2,6 +2,7 @@
|
||||
// $Id$
|
||||
$_SERVER['BASE_PAGE'] = 'results.php';
|
||||
include $_SERVER['DOCUMENT_ROOT'] . '/include/prepend.inc';
|
||||
include $_SERVER['DOCUMENT_ROOT'] . '/include/results.inc';
|
||||
#include $_SERVER['DOCUMENT_ROOT'] . '/include/loadavg.inc';
|
||||
|
||||
function exit_with_pretty_error($title, $header, $msg) {
|
||||
@@ -32,8 +33,8 @@ if ($MQ) {
|
||||
|
||||
if(strlen($l)>2) $l = substr($l,0,2); // Just take the first 2 chars. eg. pt_BR = pt
|
||||
|
||||
$q = urlencode($q);
|
||||
$l = urlencode($l);
|
||||
$uq = urlencode($q);
|
||||
$ul = urlencode($l);
|
||||
|
||||
$s = (isset($_GET['start']) && is_numeric($_GET['start'])) ? (int)$_GET['start'] : 0;
|
||||
$profile = (isset($_GET['p']) && is_string($_GET['p'])) ? $_GET['p'] : 'all';
|
||||
@@ -42,7 +43,7 @@ $per_page = 10;
|
||||
$valid_profiles = array('all', 'local', 'manual', 'news', 'bugs', 'pear', 'pecl', 'talks');
|
||||
$scope = in_array($profile, $valid_profiles) ? $profile : 'all';
|
||||
$srch_host = "www.php.net";
|
||||
$srch_rqst = "/ws.php?profile=$scope&q=$q&lang=$l&results=$per_page&start=$s&mirror=".trim(substr($MYSITE,7),'/');
|
||||
$srch_rqst = "/ws.php?profile=$scope&q=$uq&lang=$ul&results=$per_page&start=$s&mirror=".trim(substr($MYSITE,7),'/');
|
||||
$url = "http://".$srch_host.$srch_rqst;
|
||||
|
||||
$data = fetch_contents($url);
|
||||
@@ -66,85 +67,7 @@ if ($res['ResultSet']['totalResultsAvailable'] == 0) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$start_result = $s;
|
||||
$end_result = $s + $res['ResultSet']['totalResultsReturned'] -1;
|
||||
search_results($res, $q, $scope, $per_page, $s, $l);
|
||||
|
||||
$results_count = ($res['ResultSet']['totalResultsAvailable'] < 100 ? $res['ResultSet']['totalResultsAvailable'] : 'more than 100');
|
||||
|
||||
$disp_start_result = $start_result + 1;
|
||||
$disp_end_result = $end_result + 1;
|
||||
echo <<<EOB
|
||||
<h2>Showing results $disp_start_result to $disp_end_result of $results_count</h2>
|
||||
<ul id="search-results">
|
||||
EOB;
|
||||
$pos = $res['ResultSet']['firstResultPosition'];
|
||||
|
||||
$php_img_dir = 'http://static.php.net/www.php.net/images';
|
||||
$types = array(
|
||||
'pear' => '<img src="'. $php_img_dir .'/pear_item.gif" height="19" width="17" style="float:left; margin-left:-30px;"/>',
|
||||
'pecl' => '<img src="'. $php_img_dir .'/pecl_item.gif" height="19" width="17" style="float:left; margin-left:-30px;"/>',
|
||||
'pecl4win' => '<img src="'. $php_img_dir .'/pecl_item_win.gif" height="22" width="21" style="float:left; margin-left:-31px;"/>',
|
||||
'peclbugs' => '<img src="'. $php_img_dir .'/pecl_item_bug.gif" height="19" width="17" style="float:left; margin-left:-30px;"/>',
|
||||
'pearbugs' => '<img src="'. $php_img_dir .'/pear_item_bug.gif" height="19" width="17" style="float:left; margin-left:-30px;"/>',
|
||||
'talks' => '<img src="'. $php_img_dir .'/ele-icon.gif" height="20" width="32" style="float:left; margin-left:-40px;"/>',
|
||||
'snaps' => '<img src="'. $php_img_dir .'/logos/php_xpstyle_ico.png" height="32" width="32" style="float:left; margin-left:-40px;"/>',
|
||||
'cvsweb' => '<img src="'. $php_img_dir .'/logos/php_script_ico.png" height="32" width="32" style="float:left; margin-left:-40px;"/>',
|
||||
'viewcvs' => '<img src="'. $php_img_dir .'/logos/php_script_ico.png" height="32" width="32" style="float:left; margin-left:-40px;"/>',
|
||||
'news' => '<img src="'. $php_img_dir .'/logos/php-icon-white.gif" height="32" width="32" style="float:left; margin-left:-40px;"/>',
|
||||
'php' => '<img src="'. $php_img_dir .'/logos/php-icon-white.gif" height="32" width="32" style="float:left; margin-left:-40px;"/>',
|
||||
'doc' => '<img src="'. $php_img_dir .'/logos/php-icon-white.gif" height="32" width="32" style="float:left; margin-left:-40px;"/>',
|
||||
'bugs' => '<img src="'. $php_img_dir .'/php_bug.gif" height="32" width="32" style="float:left; margin-left:-40px;"/>',
|
||||
'gtk' => '<img src="'. $php_img_dir .'/logos/php-gtk-white.gif" height="26" width="32" style="float:left; margin-left:-40px;"/>'
|
||||
);
|
||||
|
||||
foreach($res['ResultSet']['Result'] as $i => $hit) {
|
||||
$cnt = $pos + $i;
|
||||
|
||||
$d = date('j M Y', $hit['ModificationDate']);
|
||||
$cachelink = '';
|
||||
if (isset($hit['Cache'])) {
|
||||
$cachelink = " - <a href=\"{$hit['Cache']}\">Cached</a>";
|
||||
}
|
||||
|
||||
// rewrite mirrors urls (\w\w\d? or www, but not qa, doc, gtk and ~/user)
|
||||
$real_url = preg_replace('@^http://(?!doc|qa|gtk)\w{2,3}\.php\.net(?!/~)(.*)$@', '$1', $hit['Url']);
|
||||
$displayurl = preg_replace('@^http://(?:(?!doc|qa|php|gtk)\w{2,3}\.)?(.+[^/])/?$@', '$1', $hit['Url']);
|
||||
$type = substr($displayurl,0,strpos($displayurl,'.'));
|
||||
if($type=='pecl' && strstr($displayurl,"/bugs/")) $type = "peclbugs";
|
||||
if($type=='pear' && strstr($displayurl,"/bugs/")) $type = "pearbugs";
|
||||
if($type=='smarty') continue;
|
||||
$display_title = str_replace(array('PHP:', '&'), array('', '&'), $hit['Title']);
|
||||
|
||||
// Fall back to the PHP logo for unknown hits
|
||||
if (!isset($types[$type])) {
|
||||
$type = "php";
|
||||
}
|
||||
|
||||
// Fix &gt; double escaping
|
||||
$summary = str_replace('&', '&', $hit['Summary']);
|
||||
echo <<<EOB
|
||||
<li>
|
||||
<p class="result">{$types[$type]}<a href="{$real_url}">{$display_title}</a></p>
|
||||
<p class="summary">{$summary}</p>
|
||||
<p class="meta">{$displayurl} - {$d} {$cachelink}</p>
|
||||
</li>
|
||||
EOB;
|
||||
}
|
||||
echo <<<EOB
|
||||
</ul>
|
||||
<span style="margin-left: 3em; margin-top: 1em; float: left; font-family: Verdana, Tahoma, Helvetica, Arial;
|
||||
font-size: 11px; color:#555;">results by <img style="margin-bottom:4px;" src="/images/bing.png" align="center"/></span>
|
||||
<div id="results_nav"><h4>Results Page:</h4>
|
||||
<ul id="results_nav_list">
|
||||
EOB;
|
||||
$start = 0;
|
||||
for($z=1; $z < 11; $z++) {
|
||||
if($start > $res['ResultSet']['totalResultsAvailable']) {
|
||||
break;
|
||||
}
|
||||
printf('<li><a href="/results.php?q=%s&start=%d&p=%s&l=%s">%d</a></li>', $q, $start, $scope, $l, $z);
|
||||
$start += $per_page;
|
||||
}
|
||||
echo '</ul></div>';
|
||||
site_footer();
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user