Source of: /include/shared-manual.inc
<?php include_once $_SERVER['DOCUMENT_ROOT'] . '/include/prepend.inc';
$PGI = array(); $SIDEBAR_DATA = '';
function manual_setup($page_data)
{
if (myphpnet_beta()) {
return manual_setup_beta($page_data);
}
global $PGI;
$PGI = array_merge($PGI, $page_data); $_SERVER['BASE_PAGE'] = 'manual/' . language_convert($PGI['head'][1]) . "/" . $PGI['this'][0];
if (($time = @filemtime($_SERVER['DOCUMENT_ROOT'] ."/". $_SERVER['BASE_PAGE'])) != false) {
$PGI['lastmod'] = gmdate("D, d M Y", $time);
} else {
$PGI['lastmod'] = "Unkown";
}
}
function manual_header()
{
if (myphpnet_beta()) {
return manual_header_beta();
}
global $PGI, $LAST_UPDATED, $MYSITE;
$title = $PGI['this'][1];
list($encoding, $lang) = $PGI['head'];
header("Last-Modified: " . gmdate("D, d M Y H:i:s ", $LAST_UPDATED) . "GMT");
header("Vary: Cookie");
header("Content-type: text/html;charset=utf-8");
header("Content-language: $lang");
$_SERVER['BASE_HREF'] = $MYSITE . $_SERVER['BASE_PAGE'];
$sections = get_manual_search_sections();
array_shift($sections);
$shorturl = substr($PGI['this'][0], 0, -4);
foreach($sections as $section) {
if (strpos($PGI['this'][0], $section) === 0) {
$shorturl = substr($PGI['this'][0], strlen($section), -4);
}
}
manual_sidebar();
$link = array(
"contents" => $PGI["home"][0],
"index" => $PGI["up"][0],
"prev" => $PGI["prev"][0],
"next" => $PGI["next"][0],
"schema.dc" => "http://purl.org/dc/elements/1.1/",
"schema.rdfs" => "http://www.w3.org/2000/01/rdf-schema#",
array(
"rev" => "canonical",
"rel" => "self alternate shorter shorturl shortlink",
"href" => "http://php.net/" . $shorturl,
),
array(
"rel" => "license",
"href" => "http://creativecommons.org/licenses/by/3.0/",
"about" => "#content",
),
);
if (isset($PGI["extra_header_links"])) {
$link[] = (array)$PGI["extra_header_links"];
}
site_header("$title - Manual", array(
"link" => $link,
"profile" => "http://purl.org/NET/erdf/profile",
"extra_headers" => array(
"Link" => "<http://php.net/" . $shorturl . ">; rel=shorturl",
),
"headtags" => array(
'<meta http-equiv="Content-language" content="' . $lang . '" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var toggleImage = function(elem) {
if ($(elem).hasClass("shown")) {
$(elem).removeClass("shown").addClass("hidden");
$("img", elem).attr("src", "/images/notes-add.gif");
}
else {
$(elem).removeClass("hidden").addClass("shown");
$("img", elem).attr("src", "/images/notes-reject.gif");
}
};
$(".soft-deprecation-notice h1.title").each(function() {
$(this).prepend("<a class=\'toggler shown\' href=\'#\'><img src=\'/images/notes-reject.gif\' alt=\'minimize\' /></a> ");
});
$(".refsect1 h3.title").each(function() {
url = "https://bugs.php.net/report.php?bug_type=Documentation+problem&manpage=" + $(this).parent().parent().attr("id") + "%23" + $(this).parent().attr("id");
$(this).parent().prepend("<div class=\'reportbug\'><a href=\'" + url + "\'>Report a bug</a></div>");
$(this).prepend("<a class=\'toggler shown\' href=\'#\'><img src=\'/images/notes-reject.gif\' alt=\'reject note\' /></a> ");
});
$("#usernotes .head").each(function() {
$(this).prepend("<a class=\'toggler shown\' href=\'#\'><img src=\'/images/notes-reject.gif\' alt=\'reject note\' /></a> ");
});
$(".soft-deprecation-notice h1.title .toggler").click(function() {
$(this).parent().siblings().slideToggle("slow");
toggleImage(this);
return false;
});
$(".refsect1 h3.title .toggler").click(function() {
$(this).parent().siblings().slideToggle("slow");
toggleImage(this);
return false;
});
$("#usernotes .head .toggler").click(function() {
$(this).parent().next().slideToggle("slow");
toggleImage(this);
return false;
});
});
</script>
<script type="text/javascript" src="/js/usernotes.js"></script>
',
),
));
manual_navbar();
}
function manual_footer()
{
if (myphpnet_beta()) {
return manual_footer_beta();
}
global $PGI;
list($filename, $title) = $PGI['this'];
echo "<br /><br />";
manual_notes();
echo "<br />";
site_footer();
}
function manual_sidebar()
{
global $PGI, $SIDEBAR_DATA;
$BAR = "<!--UdmComment-->\n<ul class=\"toc\">\n";
$BAR .= ' <li class="header home"><a href="' . $PGI['home'][0] . '">' .
$PGI['home'][1] . "</a></li>\n";
if (isset($PGI['parents']) && ($c = count($PGI['parents'])-1) > 0) {
for($i=$c-1; $i>=0; $i--) {
$BAR .= ' <li class="header up"><a href="' . $PGI['parents'][$i][0] . '">' .
$PGI['parents'][$i][1] . "</a></li>\n";
}
}
if (($PGI['home'][1] !== $PGI['up'][1]) && $PGI['up'][1]) {
$BAR .= ' <li class="header up"><a href="' . $PGI['up'][0] . '">' .
$PGI['up'][1] . "</a></li>\n";
}
foreach($PGI['toc'] as $tocitem) {
list($url, $title) = $tocitem;
$liclass = ($url == $PGI['this'][0]) ? ' class="active"' : "";
if (preg_match("!^[a-zA-Z0-9_>():&;-]+$!", $title)) {
$wrap = '<span class="w"> </span>';
$title = str_replace(array('_', '->', '::', '->'), array("_$wrap", "->$wrap", "::$wrap", "->$wrap"), $title);
}
$BAR .= " <li{$liclass}>" .
make_link($url, $title) . "</li>\n";
}
$SIDEBAR_DATA = "$BAR</ul><!--/UdmComment-->\n";
}
function manual_navbar($location = "top")
{
global $PGI, $LANG, $LANGUAGES, $INACTIVE_ONLINE_LANGUAGES, $ACTIVE_ONLINE_LANGUAGES;
echo "<!--UdmComment-->\n<div class=\"manualnavbar manualnavbar_$location\">\n <span class=\"next\">\n";
if (isset($PGI['next']) && isset($PGI['next'][1])) {
echo " <a href=\"{$PGI['next'][0]}\">" .
$PGI['next'][1] .
make_image('caret-r.gif', '>') .
"</a>\n";
}
echo " </span>\n <span class=\"prev\">\n";
if (isset($PGI['prev']) && isset($PGI['prev'][1])) {
echo " <a href=\"{$PGI['prev'][0]}\">" .
make_image('caret-l.gif', '<') .
$PGI['prev'][1] . "</a>\n";
} else {
echo " \n";
}
echo " </span>\n <hr />\n";
$filename = $PGI['this'][0];
$elink = '[<a href="https://edit.php.net/?project=PHP&perm=' . $PGI['head'][1] . '/' . $filename. '">edit</a>]';
echo " <span class=\"lastupdated\">{$elink} Last updated: {$PGI['lastmod']}</span>\n";
echo " <div class=\"langchooser\">\n";
if ($location != 'bottom') {
$links = array();
foreach ($ACTIVE_ONLINE_LANGUAGES as $code => $name) {
if (!preg_match("!/$code/!", $_SERVER['BASE_PAGE'])
) {
$links[] = array("$code/$filename", $name);
}
}
$links[] = array('help-translate.php', 'Other');
echo ' <form action="/manual/change.php" method="get">' . "\n" .
' <p>view this page in </p><fieldset><select name="page">'. "\n";
foreach ($links as $link) {
echo ' <option value="' . $link[0] . '">' . $link[1] . "</option>\n";
}
echo " </select>\n" .
' <input type="image" src="' . $_SERVER['STATIC_ROOT'] .
'/images/small_submit.gif" id="changeLangImage" ' .
'alt="Change language" />' . "\n </fieldset></form>\n";
} else {
echo " \n";
}
echo " </div>\n";
echo "</div>\n<!--/UdmComment-->\n\n";
}
function manual_notes()
{
if (myphpnet_beta()) {
return manual_notes_beta();
}
list($filename, $title) = $GLOBALS['PGI']['this'];
if (substr($filename, -4) == '.php') {
$filename = substr($filename, 0, -4);
}
$notes = manual_notes_load($filename);
uasort($notes, "manual_notes_sort");
if(count($notes) > 2) {
manual_navbar("bottom");
}
$addnotelink = '/manual/add-note.php?sect=' . $filename .
'&redirect=' . $_SERVER['BASE_HREF'];
$addnotesnippet =
make_link($addnotelink, make_image('notes-add.gif', 'add a note', FALSE, 'class="middle"')) .
' <small>' .
make_link($addnotelink, 'add a note') .
'</small>';
$num_notes = count($notes);
list($redir_filename) = $GLOBALS['PGI']['this'];
if (substr($redir_filename, -4) == '.php') {
$redir_filename = substr($redir_filename, 0, -4);
}
echo <<<END_USERNOTE_HEADER
<div id="usernotes">
<div class="head">
<span class="action">{$addnotesnippet}</span>
<small>User Contributed Notes</small>
<strong>{$title}</strong> - [<em>{$num_notes}</em> notes]
</div>
END_USERNOTE_HEADER;
if (sizeof($notes) == 0) {
echo "\n <div class=\"note\">There are no user contributed notes for this page.</div>";
}
else {
echo '<div id="allnotes">';
foreach($notes as $note) {
manual_note_display(
$note['xwhen'], $note['user'], $note['note'], $note['id'], $note['votes']
);
}
echo "</div>\n";
echo "\n <div class=\"foot\">$addnotesnippet</div>\n";
}
echo "</div>";
}
function manual_notes_beta() {
list($filename, $title) = $GLOBALS['PGI']['this'];
if (substr($filename, -4) == '.php') {
$filename = substr($filename, 0, -4);
}
$notes = manual_notes_load($filename);
uasort($notes, "manual_notes_sort");
$addnotelink = '/manual/add-note.php?sect=' . $filename .
'&redirect=' . $_SERVER['BASE_HREF'];
$addnotesnippet =
make_link($addnotelink, make_image('notes-add.gif', 'add a note', FALSE, 'class="middle"')) .
' <small>' .
make_link($addnotelink, 'add a note') .
'</small>';
$num_notes = count($notes);
if ($num_notes) {
$num_notes = "<span class=\"count\"><strong>$num_notes note" . ($num_notes == 1 ? '' : 's') . "</strong></span>";
} else {
$num_notes = null;
}
echo <<<END_USERNOTE_HEADER
<section id="usernotes">
<div class="head">
<span class="action">{$addnotesnippet}</span>
<h3 class="title">User Contributed Notes {$num_notes}</h3>
</div>
END_USERNOTE_HEADER;
if (sizeof($notes) == 0) {
echo "\n <div class=\"note\">There are no user contributed notes for this page.</div>";
}
else {
echo '<div id="allnotes">';
foreach($notes as $note) {
manual_note_display(
$note['xwhen'], $note['user'], $note['note'], $note['id'], $note['votes']
);
}
echo "</div>\n";
echo "\n <div class=\"foot\">$addnotesnippet</div>\n";
}
}
function manual_notes_load($id)
{
$notes = array();
$hash = substr(md5($id), 0, 16);
$notes_file = $_SERVER['DOCUMENT_ROOT'] . "/backend/notes/" .
substr($hash, 0, 2) . "/$hash";
if (!file_exists($notes_file)) {
return $notes;
}
if ($fp = @fopen($notes_file, "r")) {
while (!feof($fp)) {
$line = chop(fgets($fp, 12288));
if ($line == "") { continue; }
@list($id, $sect, $rate, $ts, $user, $note, $up, $down) = explode("|", $line);
$notes[$id] = array(
"id" => $id,
"sect" => $sect,
"rate" => $rate,
"xwhen" => $ts,
"user" => $user,
"note" => base64_decode($note),
"votes" => array("up"=> (int)$up, "down"=> (int)$down)
);
}
fclose($fp);
}
return $notes;
}
function manual_note_display($date, $name, $text, $id, $votes = array('up'=>0,'down'=>0), $voteOption = true)
{
if ($name) {
$name = "\n <strong class=\"user\"><em>" . htmlspecialchars($name) . "</em></strong>";
} else {
$name = "<strong class=\"user\"><em>Anonymous</em></strong>";
}
$name = ($id ? "\n <a href=\"#$id\" class=\"name\">$name</a><a class=\"genanchor\" href=\"#$id\"> ¶</a>" : "\n $name");
$datestr = relTime(new DateTime("@{$date}"));
$fdatestr = date("Y-m-d h:i", $date);
$text = clean_note($text);
$vote = $votes['up'] - $votes['down'];
$p = floor(($votes['up'] / (($votes['up'] + $votes['down']) ? $votes['up'] + $votes['down'] : 1)) * 100);
$rate = !$p && !($votes['up'] + $votes['down']) ? "no votes..." : "$p% like this...";
if ($voteOption) {
list($redir_filename) = $GLOBALS['PGI']['this'];
if (substr($redir_filename, -4) == '.php') {
$redir_filename = substr($redir_filename, 0, -4);
}
$rredir_filename = urlencode($redir_filename);
$votediv = <<<VOTEDIV
<div class="votes">
<div id="Vu{$id}">
<a href="/manual/vote-note.php?id={$id}&page={$rredir_filename}&vote=up" title="Vote up!" class="usernotes-voteu">up</a>
</div>
<div id="Vd{$id}">
<a href="/manual/vote-note.php?id={$id}&page={$rredir_filename}&vote=down" title="Vote down!" class="usernotes-voted">down</a>
</div>
<div class="tally" id="V{$id}" title="{$rate}">
{$vote}
</div>
</div>
VOTEDIV;
} else {
$votediv = null;
}
if (isset($_COOKIE['IS_DEV']) && $id) {
$admin = "\n <span class=\"admin\">\n " .
make_popup_link(
'https://master.php.net/manage/user-notes.php?action=edit+' . $id,
make_image('notes-edit.gif', 'edit note'),
'admin',
'scrollbars=yes,width=650,height=400'
) . "\n " .
make_popup_link(
'https://master.php.net/manage/user-notes.php?action=reject+' . $id,
make_image('notes-reject.gif', 'reject note'),
'admin',
'scrollbars=no,width=300,height=200'
) . "\n " .
make_popup_link(
'https://master.php.net/manage/user-notes.php?action=delete+' . $id,
make_image('notes-delete.gif', 'delete note'),
'admin',
'scrollbars=no,width=300,height=200'
) . "\n </span>";
} else {
$admin = '';
}
echo <<<USER_NOTE_TEXT
<a name="$id"></a><div class="note">{$votediv}{$name}{$admin}<div class="date" title="$fdatestr"><strong>{$datestr}</strong></div>
<div class="text" id="Hcom{$id}">
{$text}
</div>
</div>
USER_NOTE_TEXT;
}
function manual_setup_beta($setup) {
global $PGI, $MYSITE;
$PGI = $setup;
$_SERVER['BASE_PAGE'] = 'manual/' . language_convert($setup['head'][1]) . "/" . $setup['this'][0];
$_SERVER['BASE_HREF'] = $MYSITE . $_SERVER['BASE_PAGE'];
$siblings = array();
foreach($setup["toc"] as $entry) {
$methodname = $entry[1];
if(strpos($entry[1], '::') !== false) {
list($classname, $methodname) = explode('::', $entry[1]);
}
$siblings[] = array(
"title" => $methodname,
"link" => $entry[0],
"current" => $setup["this"][0] == $entry[0],
);
}
$menu = array();
foreach(array_reverse($setup["parents"]) as $parent) {
$menu[] = array(
"title" => $parent[1],
"link" => $parent[0],
"children" => array(),
);
}
if ($setup["up"][0]) {
$menu[] = array(
"title" => $setup["up"][1],
"link" => $setup["up"][0],
"children" => $siblings,
);
}
$_SERVER["BASE_PAGE"] = "/manual/" . $setup["head"][1] . "/" . $setup["this"][0];
$config = array(
"current" => "docs",
"leftmenu" => $menu,
"meta-navigation" => array(
"contents" => $setup["home"][0],
"index" => $setup["up"][0],
"prev" => $setup["prev"][0],
"next" => $setup["next"][0],
),
"lang" => $setup["head"][1],
);
site_header($setup["this"][1] . " - Manual ", $config);
echo '
<aside id="quicktoc">
<div class="language">'.manual_language_chooser($setup['head'][1], $setup['this'][0]).'</div>
<div class="content"></div>
<div class="links">
<a title="Report a bug" href="http://bugs.php.net/report.php?bug_type=Documentation+problem&manpage=' . $PGI['this'][0] . '">Report a bug</a>
<a title="Edit this page" href="https://edit.php.net/?project=PHP&perm=' . $PGI['head'][1] . '/' . $PGI['this'][0] . '">Edit this page</a>
</div>
</aside>';
echo '</aside>';
}
function manual_language_chooser($currentlang, $currentpage) {
global $ACTIVE_ONLINE_LANGUAGES;
$links = array();
foreach ($ACTIVE_ONLINE_LANGUAGES as $lang => $name) {
$links[] = array("$lang/$currentpage", $name, $lang);
}
$rt = '<h5>Language</h5>'.
'<form action="/manual/change.php" method="get" id="changelang" name="changelang">'.
'<fieldset>'.
'<select onchange="document.changelang.submit()" name="page" id="changelang-langs">';
foreach ($links as $link) {
$rt.= "<option value='{$link[0]}' " .($link[2] == $currentlang ? "selected" : ""). ">{$link[1]}</option>\n";
}
$rt.= '<option value="help-translate.php">Other</option>'.
'</select>'.
'</fieldset>'.
'</form>';
return $rt;
}
function manual_header_beta(){}
function manual_footer_beta() {
echo "</section>";
manual_notes();
site_footer(array('elephpants' => true));
}
function relTime(DateTime $date) {
$current = new DateTime;
$diff = $current->diff($date);
$units = array("year" => $diff->format("%y"),
"month" => $diff->format("%m"),
"day" => $diff->format("%d"),
"hour" => $diff->format("%h"),
"minute" => $diff->format("%i"),
"second" => $diff->format("%s"),
);
$out = "just now...";
foreach ($units as $unit => $amount) {
if (empty($amount)) {
continue;
}
$out = $amount . " " . ($amount == 1 ? $unit : $unit . "s") . " ago";
break;
}
return $out;
}
function manual_notes_sort($a, $b)
{
if ($a['votes']['up'] + $a['votes']['down'] < 1) {
$c = 1;
} else {
$c = $a['votes']['up'] + $a['votes']['down'];
}
if ($b['votes']['up'] + $b['votes']['down'] < 1) {
$d = 1;
} else {
$d = $b['votes']['up'] + $b['votes']['down'];
}
$voteA = $a['votes']['up'] / $c;
$voteB = $b['votes']['up'] / $d;
$rateA = $a['votes']['up'] - $a['votes']['down'];
$rateB = $b['votes']['up'] - $b['votes']['down'];
if ($voteA > $voteB) {
if ($b['xwhen'] >= mktime(0,0,0,date('n'),date('j'),date('Y')) && $voteB > -1) return 1;
if ($voteB === 0 && $d === 1 && $voteA <= 0.30 && $c >= 4) return 1;
return -1;
}
elseif ($voteA < $voteB) {
if ($a['xwhen'] >= mktime(0,0,0,date('n'),date('j'),date('Y')) && $voteA > -1) return -1;
if ($voteA === 0 && $c === 1 && $voteB <= 0.30 && $d >= 4) return -1;
return 1;
}
else {
if ($rateA > $rateB) {
return -1;
}
elseif ($rateA < $rateB) {
return 1;
}
else {
if ($a['xwhen'] > $b['xwhen']) {
return -1;
}
elseif ($a['xwhen'] < $b['xwhen']) {
return 1;
}
else {
return 0;
}
}
}
}