mirror of
https://github.com/php/web-php.git
synced 2026-04-28 09:23:14 +02:00
bc55d94455
the correct URI of a manual page which is currently served. The code uses no external calls, it is based on config params provided by sendmanualheaders() and manualheaders(), which are always properly parameterized on all manpages and are always called. The <base> printout is added with a comment now, so we can see if it works correcly. If yes, that the comment signs can be removed, making that effective. Then all the manual shortcuts can be changed to include() manual pages instead of redirecting to them. Relative links will work.
416 lines
13 KiB
C++
416 lines
13 KiB
C++
<?php // -*- C++ -*-
|
|
require_once 'prepend.inc';
|
|
|
|
// Set variable defaults
|
|
$NEXT = $PREV = $UP = $HOME = $PGI = array(false, false);
|
|
$TOC = array(); $SIDEBAR_DATA = ''; $BASE_FOR_MANPAGE = '';
|
|
|
|
// If we don't know anything about printing, set it to false
|
|
if (!isset($PRINT_PAGE)) { $PRINT_PAGE = FALSE; }
|
|
|
|
// Set up variables containing navigational information
|
|
// for this page and page part of the manual
|
|
function setupNavigation($data) {
|
|
global $NEXT, $PREV, $UP, $HOME, $TOC, $PGI, $tstamp;
|
|
$HOME = @$data["home"];
|
|
$HOME[0] = "./";
|
|
$NEXT = @$data["next"];
|
|
$PREV = @$data["prev"];
|
|
$UP = @$data["up"];
|
|
$TOC = @$data["toc"];
|
|
$PGI = @$data["this"];
|
|
$tstamp = gmdate("D, d M Y",getlastmod());
|
|
}
|
|
|
|
// Put all the border table of contents data to $SIDEBAR_DATA
|
|
function makeBorderTOC($this) {
|
|
global $NEXT, $PREV, $UP, $HOME, $TOC, $PHP_SELF, $DOCUMENT_ROOT, $SIDEBAR_DATA;
|
|
|
|
$SIDEBAR_DATA.= '<table border="0" cellpadding="0" cellspacing="5" width="100%">';
|
|
|
|
$SIDEBAR_DATA.= '<tr valign="top"><td>' .
|
|
make_link('./', make_image('caret-t.gif', '^') . $HOME[1] ) .
|
|
'<br></td></tr>';
|
|
|
|
$SIDEBAR_DATA.= '<tr bgcolor="#cccccc"><td>' . spacer(1, 1, TRUE) . '</td></tr>';
|
|
|
|
if (($HOME[1] != $UP[1]) && $UP[1]) {
|
|
$SIDEBAR_DATA.= '<tr valign="top"><td>' .
|
|
make_link($UP[0], make_image('caret-u.gif', '<') . $UP[1] ) .
|
|
'</td></tr>';
|
|
}
|
|
|
|
$SIDEBAR_DATA.= '<tr valign="top"><td><small class="sidetoc">';
|
|
|
|
for ($i = 0; $i < count($TOC); $i++) {
|
|
list($url, $title) = $TOC[$i];
|
|
if (!$url || !$title) {
|
|
continue;
|
|
}
|
|
if ($UP[0] == 'funcref.php') {
|
|
$title = eregi_replace(" functions\$", "", $title);
|
|
}
|
|
$img = 'box-0.gif';
|
|
if ($title == $this) {
|
|
$img = 'box-1.gif';
|
|
$title = "<b>$title</b>";
|
|
}
|
|
$SIDEBAR_DATA .= ' ' .
|
|
make_link($url, make_image($img, "·") . $title ) .
|
|
"<br />\n";
|
|
}
|
|
|
|
$SIDEBAR_DATA.= '</small></td></tr>';
|
|
$SIDEBAR_DATA.= '</table>';
|
|
}
|
|
|
|
// Print out manual navigation bar
|
|
function navigationBar($title,$id,$loc) {
|
|
global $NEXT, $PREV, $tstamp, $SERVER_NAME, $SERVER_PORT,
|
|
$PHP_SELF, $LANGUAGES, $REQUEST_URI, $www_static_root;
|
|
|
|
echo '<table border="0" width="100%" bgcolor="#e0e0e0" cellpadding="0" cellspacing="4">';
|
|
|
|
echo '<tr><td>';
|
|
if ($PREV[1]) {
|
|
echo make_link( $PREV[0] , make_image('caret-l.gif', '<') . $PREV[1] ) ;
|
|
}
|
|
echo '</td>';
|
|
|
|
echo '<td align="right">';
|
|
if ($NEXT[1]) {
|
|
echo make_link( $NEXT[0] , $NEXT[1] . make_image('caret-r.gif', '>') ) ;
|
|
}
|
|
echo '</td>';
|
|
echo '</tr>';
|
|
|
|
echo '<tr bgcolor="#cccccc"><td colspan="2">';
|
|
spacer(1,1);
|
|
echo '</td></tr>';
|
|
|
|
echo '<tr>';
|
|
echo '<td>';
|
|
|
|
// Print out language switch on top of manual pages
|
|
if ($loc != 'bottom') {
|
|
$links = array();
|
|
preg_match("!^/manual/(.+)/!", $REQUEST_URI, $langcode);
|
|
$links[] = array("$langcode[1]/print/$id", "printer friendly");
|
|
$links[] = array("$langcode[1]/printwn/$id", "printer friendly [+notes]");
|
|
foreach ($LANGUAGES as $code => $name) {
|
|
if (!preg_match("!/$code/!", $PHP_SELF) && file_exists("../$code/$id")) {
|
|
$links[] = array("$code/$id", $name);
|
|
}
|
|
}
|
|
echo '<form action="/manual/change.php" method="GET" class="thin"><small>view the </small>' .
|
|
'<select name="page" class="small">'. "\n";
|
|
foreach ($links as $link) {
|
|
echo '<option value="' . $link[0] . '">' . $link[1] . "</option>\n";
|
|
}
|
|
echo '</select>';
|
|
echo '<input type="image" src="' . $www_static_root . '/images/small_submit.gif" border="0" width="11" height="11" alt="" align="baseline"> <small>version of this page</small></form>';
|
|
|
|
} else {
|
|
echo "<small> </small>";
|
|
}
|
|
|
|
echo '</td><td align="right" valign="bottom"><small>Last updated: ' . $tstamp . '</small></td></tr>';
|
|
echo "</table>\n";
|
|
|
|
}
|
|
|
|
// Try to make email address printing safe (protect from spammers)
|
|
function safeEmail($email)
|
|
{
|
|
return str_replace(array('@', '.'), array(' at ', ' dot '), $email);
|
|
}
|
|
|
|
// Print out one user note entry
|
|
function makeEntry($date,$name,$blurb,$id=0) {
|
|
global $MAGIC_COOKIE;
|
|
?>
|
|
<tr valign="top">
|
|
<td bgcolor="#e0e0e0" colspan="2">
|
|
<?php
|
|
if ($id) { echo '<a name="#' . $id . '"></a>'; }
|
|
?>
|
|
<table border="0" cellpadding="2" cellspacing="0" width="100%">
|
|
<tr valign="top"><td>
|
|
<?php
|
|
$name = htmlspecialchars($name);
|
|
if ($name && $name != "php-general@lists.php.net" && $name != "user@example.com") {
|
|
if (ereg("(.+)@(.+)\.(.+)",$name)) {
|
|
$name = safeEmail($name);
|
|
}
|
|
echo "<b>".$name."</b><br>\n";
|
|
}
|
|
echo date("d-M-Y h:i",$date);
|
|
?>
|
|
</td>
|
|
<td align="right">
|
|
<?php
|
|
if (isset($MAGIC_COOKIE) && $id) {
|
|
print_popup_link('http://master.php.net/manage/user-notes.php?action=edit+' . $id,
|
|
make_image('notes-edit.gif', 'edit note'),
|
|
'admin',
|
|
'scrollbars=yes,width=650,height=400'
|
|
);
|
|
echo ' ';
|
|
print_popup_link('http://master.php.net/manage/user-notes.php?action=reject+' . $id,
|
|
make_image('notes-reject.gif', 'reject note'),
|
|
'admin',
|
|
'scrollbars=no,width=300,height=200'
|
|
);
|
|
echo ' ';
|
|
print_popup_link('http://master.php.net/manage/user-notes.php?action=delete+' . $id,
|
|
make_image('notes-delete.gif', 'delete note'),
|
|
'admin',
|
|
'scrollbars=no,width=300,height=200'
|
|
);
|
|
}
|
|
?>
|
|
<br></td>
|
|
</tr>
|
|
<tr bgcolor="#f0f0f0"><td colspan="2">
|
|
<?php echo clean_note($blurb); ?><br>
|
|
</td></tr>
|
|
</table>
|
|
</td>
|
|
</tr>
|
|
<?php
|
|
};
|
|
|
|
// Get user notes from the appropriate text dump
|
|
function manualGetUserNotes($title, $id) {
|
|
global $DOCUMENT_ROOT;
|
|
$notes = array();
|
|
$hash = substr(md5($id),0,16);
|
|
|
|
$notes_file = "$DOCUMENT_ROOT/backend/notes/".substr($hash,0,2)."/$hash";
|
|
if ($fp = @fopen($notes_file,"r")) {
|
|
while (!feof($fp)) {
|
|
$line = chop(fgets($fp,8096));
|
|
if ($line == "") continue;
|
|
list($id,$sect,$rate,$ts,$user,$note) = explode("|",$line);
|
|
$notes[] = array(
|
|
"id" => $id,
|
|
"sect" => $sect,
|
|
"rate" => $rate,
|
|
"xwhen" => $ts,
|
|
"user" => $user,
|
|
"note" => base64_decode($note)
|
|
);
|
|
}
|
|
fclose($fp);
|
|
}
|
|
return $notes;
|
|
}
|
|
|
|
// Print out all user notes for this manual page
|
|
function manualUserNotes($title, $id) {
|
|
|
|
global $PHP_SELF, $SERVER_NAME, $SERVER_PORT;
|
|
$cur = substr(dirname($PHP_SELF),-2);
|
|
if($cur=='al') $cur='en';
|
|
|
|
# don't want .php at the end of the id.
|
|
if (substr($id,-4) == '.php') $id = substr($id,0,-4);
|
|
|
|
$notes = manualGetUserNotes($title, $id);
|
|
|
|
$back_url = 'http://' . $SERVER_NAME .
|
|
(($SERVER_PORT==80) ? '' : ':'.$SERVER_PORT ) .
|
|
$PHP_SELF;
|
|
|
|
// Link target to add a note to the current manual page,
|
|
// and it's extended form with a [+] image
|
|
$addnotelink = '/manual/add-note.php?sect=' . $id . '&redirect=' . $back_url;
|
|
$addnotesnippet =
|
|
make_link($addnotelink, make_image('notes-add.gif', 'add a note')) .
|
|
' <small>' .
|
|
make_link($addnotelink, 'add a note', false, 'style="color:#000000"') .
|
|
'</small>';
|
|
|
|
echo "<table border=\"0\" cellpadding=\"4\" cellspacing=\"0\" width=\"100%\">\n";
|
|
echo "<tr bgcolor=\"#d0d0d0\" valign=\"top\">\n";
|
|
echo "<td><small>User Contributed Notes</small><br /><b>$title</b></td>\n";
|
|
echo "<td align=\"right\">$addnotesnippet";
|
|
|
|
/* This information has been included on add-note.php
|
|
echo " ";
|
|
print_link('/manual/about-notes.php',
|
|
make_image('notes-about.gif', 'about notes')
|
|
);
|
|
*/
|
|
echo "</td>\n</tr>\n";
|
|
|
|
if (sizeof($notes) == 0) {
|
|
echo '<tr valign="top">';
|
|
echo '<td bgcolor="#e0e0e0" colspan="2">';
|
|
echo 'There are no user contributed notes for this page.';
|
|
echo '</td></tr>';
|
|
} else {
|
|
foreach($notes as $note) {
|
|
makeEntry($note['xwhen'], $note['user'], $note['note'], $note['id']);
|
|
}
|
|
|
|
echo "<tr bgcolor=\"#d0d0d0\" valign=\"top\">\n";
|
|
echo "<td colspan=\"2\" align=\"right\">\n$addnotesnippet";
|
|
|
|
/* This information has been included on add-note.php
|
|
echo " ";
|
|
print_link('/manual/about-notes.php',
|
|
make_image('notes-about.gif', 'about notes')
|
|
);
|
|
*/
|
|
echo "</td>\n</tr>\n";
|
|
}
|
|
echo "</table>\n";
|
|
}
|
|
|
|
// Send manual HTTP headers, provide accurate language data
|
|
function sendManualHeaders($charset,$lang) {
|
|
global $LAST_UPDATED, $BASE_FOR_MANPAGE, $MYSITE;
|
|
|
|
header("Last-Modified: " . gmdate("D, d M Y H:i:s ", $LAST_UPDATED) . "GMT");
|
|
//header("Cache-Control: public, max-age=600");
|
|
header("Vary: Cookie");
|
|
header("Content-type: text/html;charset=$charset");
|
|
header("Content-language: $lang");
|
|
|
|
// Set initial base for manual page
|
|
// [will be extended in manualHeader()!]
|
|
$BASE_FOR_MANPAGE = $MYSITE . 'manual/' . language_convert($lang);
|
|
}
|
|
|
|
// Print out manual page header.
|
|
function manualHeader()
|
|
{
|
|
global $PRINT_PAGE, $PGI, $BASE_FOR_MANPAGE;
|
|
|
|
// XSL sheets provide params in the 'this' array
|
|
// element configured above, while old DSSSL sheets
|
|
// provide info via two parameters [title, id]
|
|
if (func_num_args() > 0) {
|
|
list($title, $id) = func_get_args();
|
|
} else {
|
|
list($id, $title) = $PGI;
|
|
}
|
|
|
|
// Finalize the manpage base with proper filename
|
|
$BASE_FOR_MANPAGE .= '/' . $id;
|
|
|
|
if ($PRINT_PAGE) {
|
|
manualPrintHeader($title);
|
|
} else {
|
|
makeBorderTOC($title);
|
|
commonHeader ($title. " - Manual");
|
|
navigationBar($title, $id, "top");
|
|
}
|
|
}
|
|
|
|
// Print out manual footer
|
|
function manualFooter()
|
|
{
|
|
global $PRINT_PAGE, $PRINT_NOTES, $PGI;
|
|
|
|
// XSL sheets provide params in the 'this' array
|
|
// element configured above, while old DSSSL sheets
|
|
// provide info via two parameters [title, id]
|
|
if (func_num_args() > 0) {
|
|
list($title, $id) = func_get_args();
|
|
} else {
|
|
list($id, $title) = $PGI;
|
|
}
|
|
|
|
if ($PRINT_PAGE) {
|
|
if ($PRINT_NOTES) {
|
|
echo "<br /><br />";
|
|
manualPrintUserNotes($title, $id);
|
|
}
|
|
manualPrintFooter();
|
|
} else {
|
|
echo "<br /><br />";
|
|
manualUserNotes($title, $id);
|
|
echo "<br />";
|
|
navigationBar($title, $id, "bottom");
|
|
commonFooter();
|
|
}
|
|
}
|
|
|
|
// =============================================================================
|
|
// Printer friendly support functions under this line
|
|
// =============================================================================
|
|
|
|
// "Printer optimized" header for manual pages
|
|
function manualPrintHeader ($title = '') {
|
|
global $REQUEST_URI, $SERVER_NAME, $NEXT, $PREV, $HOME;
|
|
$pageurl = "http://$SERVER_NAME$REQUEST_URI";
|
|
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<title>PHP<?php if ($title) echo ": $title";?></title>
|
|
<link rel="prev" href="<?php echo $PREV[0]; ?>">
|
|
<link rel="next" href="<?php echo $NEXT[0]; ?>">
|
|
<link rel="start" href="<?php echo $HOME[0]; ?>">
|
|
</head>
|
|
<body bgcolor="#ffffff" text="#000000" link="#000099" alink="#0000ff" vlink="#000099">
|
|
<table>
|
|
<tr>
|
|
<td><a href="/"><?php print_image('php.gif', 'PHP'); ?></a></td>
|
|
<td>
|
|
This is a printer friendly version of the PHP Manual.<br>
|
|
Original address of this page: <a href="<?php echo $pageurl; ?>"><?php echo $pageurl; ?></a><br>
|
|
<small><?php echo make_link('copyright.php', 'Copyright © 1997-2003 The PHP Documentation Group'); ?><br />All rights reserved.</small>
|
|
</td>
|
|
</tr>
|
|
</table><hr size="1" noshade>
|
|
<?php
|
|
}
|
|
|
|
// "Printer optimized" footer for manual pages
|
|
function manualPrintFooter() {
|
|
echo "</body>\n</html>";
|
|
}
|
|
|
|
// Print out all user notes for this manual page
|
|
function manualPrintUserNotes($title, $id) {
|
|
|
|
global $PHP_SELF, $SERVER_NAME, $SERVER_PORT;
|
|
$cur = substr(dirname($PHP_SELF),-2);
|
|
if ($cur=='al') $cur='en';
|
|
|
|
# don't want .php at the end of the id.
|
|
if (substr($id,-4) == '.php') $id = substr($id,0,-4);
|
|
|
|
$notes = manualGetUserNotes($title, $id);
|
|
|
|
$back_url = 'http://' . $SERVER_NAME .
|
|
(($SERVER_PORT==80) ? '' : ':'.$SERVER_PORT ) .
|
|
$PHP_SELF;
|
|
|
|
echo "<hr size=\"1\" noshade><h2>User Contributed Notes</h2>";
|
|
|
|
if (sizeof($notes) == 0) {
|
|
echo "<p>There are no user contributed notes for this page</p>";
|
|
} else {
|
|
foreach($notes as $note) {
|
|
makePrintEntry($note['xwhen'], $note['user'], $note['note'], $note['id']);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Make manual user note entry for printing
|
|
function makePrintEntry($date,$name,$blurb,$id=0) {
|
|
|
|
if ($name && $name != "php-general@lists.php.net" && $name != "user@example.com") {
|
|
if (ereg("(.+)@(.+)\.(.+)",$name)) {
|
|
$name = safeEmail($name);
|
|
}
|
|
echo "<b>".$name."</b><br>\n";
|
|
}
|
|
echo date("d-M-Y h:i",$date) . "<br><br>";
|
|
echo clean_note($blurb) . "<br><hr noshade size=\"1\" width=\"50%\" align=\"center\">";
|
|
|
|
}
|