Source of /common.php


<?
global $copyyears;
$copyyears = "2006&ndash;13";

global
$pagesroot;
if (
substr($_SERVER['PHP_SELF'], 0, 9) == "/mrphlip/")
    
$pagesroot = "/mrphlip/";
else
    
$pagesroot = "/";

global
$scriptroot;
$scriptroot = __FILE__;
$tmp = strrpos($scriptroot, '/');
$scriptroot = substr($scriptroot, 0, $tmp + 1);

global
$starttime, $localhost;
$starttime = microtime(TRUE);
$localhost = $_SERVER['REMOTE_ADDR'] == "127.0.0.1";

global
$isie;
$isie = FALSE;
$tmp = strtolower($_SERVER['HTTP_USER_AGENT']);
if (
strpos($tmp, "msie") !== FALSE || strpos($tmp, "internet explorer") !== FALSE)
    
$isie = TRUE;
if (
strpos($tmp, "opera") !== FALSE)
    
$isie = FALSE;

if (
$localhost || isset($use_error_reporting))
    
error_reporting(E_ALL);
else
    
error_reporting(0);

if (
$_SERVER['SCRIPT_FILENAME'] == __FILE__)
{
    global
$allowviewsource;
    
$allowviewsource = 1;
    if (!isset(
$_REQUEST['viewsource']))
        
error_page("This page cannot be viewed alone.");
}

require_once(
"viewsource.php");

function
page_header($title = 0, $iewarn = 0)
{
    global
$allowviewsource, $pagesroot, $scriptroot, $isie, $onloadscript;
    
    if (!
headers_sent()) // protect against "already sent headers" errors
        
header('Content-type: text/html; charset=utf-8'); // specify charset
    
print "<!DOCTYPE html>\n";
    print
"<html lang=\"en-au\">\n<head>\n<title>";
    if (
$title)
        print
$title . " &ndash; ";
    print
"Mr. Phlip</title>\n";
    print
"<link rel=\"stylesheet\" type=\"text/css\" href=\"${pagesroot}common.css\" media=\"screen, projection, handheld, print\">\n";
    print
"<link rel=\"stylesheet\" type=\"text/css\" href=\"${pagesroot}screen.css\" media=\"screen, projection, handheld\">\n";
    print
"<link rel=\"stylesheet\" type=\"text/css\" href=\"${pagesroot}print.css\" media=\"print\">\n";
    print
"<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">\n";
    print
"<script type=\"text/javascript\" src=\"${pagesroot}common.js\"></script>\n";
    if (
$isie)
    {
        print
"<link rel=\"stylesheet\" type=\"text/css\" href=\"${pagesroot}iecommon.css\" media=\"screen, projection, handheld, print\">\n";
        print
"<link rel=\"stylesheet\" type=\"text/css\" href=\"${pagesroot}iescreen.css\" media=\"screen, projection, handheld\">\n";
        print
"<link rel=\"stylesheet\" type=\"text/css\" href=\"${pagesroot}ieprint.css\" media=\"print\">\n";
        print
"<script type=\"text/javascript\" src=\"${pagesroot}iecommon.js\"></script>\n";
        print
"<meta http-equiv=\"imagetoolbar\" content=\"no\">\n";
    }
    print
"<link rel=\"icon\" href=\"${pagesroot}favicon.ico\" type=\"image/x-icon\">\n";
    print
"<link rel=\"shortcut icon\" href=\"${pagesroot}favicon.ico\" type=\"image/x-icon\">\n";
    if (
function_exists('extra_head_info'))
        
extra_head_info();
    print
"</head><body";
    if (isset(
$onloadscript))
        print
" onload=\"" . htmlentities($onloadscript) . "\"";
    print
">\n";
    
// some stuff I want preloaded, rather than loaded on demand
    
print "<div style=\"display:none\">";
    if (
$isie)
        print
"<img src=\"${pagesroot}ie_images/sidebar_button.png\" alt=\"\" height=\"1\" width=\"1\"><img src=\"${pagesroot}ie_images/sidebar_hover.png\" alt=\"\" height=\"1\" width=\"1\">";
    else
        print
"<img src=\"${pagesroot}images/sidebar_button.png\" alt=\"\" height=\"1\" width=\"1\"><img src=\"${pagesroot}images/sidebar_hover.png\" alt=\"\" height=\"1\" width=\"1\">";
    print
"</div>\n";
    if (
$iewarn && $isie)
    {
        print
"<div id=\"iewarning\">";
        print
"<img src=\"${pagesroot}ie_images/iewarn_close.png\" onClick=\"hide_iewarning()\" alt=\"[close]\" class=\"close\">";
        print
"<a href=\"msieinfo.php\"><img src=\"${pagesroot}ie_images/iewarn.png\" alt=\"Warning\" class=\"warning\">";
        print
"You appear to be using Microsoft Internet Explorer. This page contains code that Internet Explorer may display incorrectly. Click here for more information.";
        print
"</a></div>\n";
    }
    for (
$i = 1$i <= 8$i++)
        print
"<div id=\"bg$i\">";
    print
"\n<div id=\"sidebar\"><ul>\n";
    
$fp = fopen("${scriptroot}sidebar.csv", "r");
    
$padding = FALSE;
    while (
$a = fgets($fp, 1024))
    {
        
$a = trim($a);
        if (
$a == '')
        {
            
$padding = TRUE;
            continue;
        }
        if (
$a{0} == ';')
            continue;
        
$a = explode(',', $a);
        
$pad1 = $padding ? '<div class="newgroup">' : '';
        
$pad2 = $padding ? '</div>' : '';
        if (
count($a) < 3 || count($a) > 4)
        {
            print
"<li>${pad1}sidebar.csv: Bad number of commas$pad2</li>\n";
            
$padding = FALSE;
            continue;
        }
        if (
$a[1] == "<viewsource>")
        {
            if (!isset(
$allowviewsource) || !$allowviewsource || isset($_REQUEST['viewsource']))
                continue;
            
$a[1] = "$_SERVER[PHP_SELF]?viewsource=yep";
        }
        else
            
$a[1] = "$pagesroot$a[1]";
        if (isset(
$a[3]))
            
$a[3] = " title=\"" . htmlentities($a[3]) . "\"";
        else
            
$a[3] = "";
        print
"<li>$pad1<a style=\"background-color: " . htmlentities($a[0]) . "\" href=\"" . htmlentities($a[1]) . "\"$a[3]>$a[2]</a>$pad2</li>\n";
        
$padding = FALSE;
    }
    print
"</ul></div>\n";
    print
"<div id=\"logo\"><img src=\"${pagesroot}";
    if (
$isie)
        print
'ie_';
    print
"images/logo.png\" alt=\"[Logo]\" height=\"100\" width=\"400\"></div>";
    print
"<div id=\"content\">\n";
    if (
$title)
        print
"<h1 id=\"mainheader\">$title</h1>\n";
}
function
page_footer()
{
    global
$starttime, $localhost, $pagesroot, $copyyears;
    print
"</div>\n"// #content
    
print "<div class=\"clear\"></div>\n"// clear bottom of sidebar
    
print '<div id="w3c">';
    print
'<a href="https://validator.w3.org/check?uri=referer"><img src="https://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Strict" height="31" width="88"></a>';
    print
'<a href="https://jigsaw.w3.org/css-validator/check/referer"><img src="https://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS" height="31" width="88"></a>';
    print
'<a href="https://www.w3.org/WAI/WCAG1AAA-Conformance" title="Explanation of Level Triple-A Conformance"><img height="32" width="88" src="https://www.w3.org/WAI/wcag1AAA" alt="Level Triple-A conformance icon, W3C-WAI Web Content Accessibility Guidelines 1.0"></a>';
    print
"</div>\n";
    for (
$i = 1$i <= 8$i++)
        print
"</div>"// #bg$i
    
$url = htmlentities("https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
    print
"\n<address id=\"printfooter\">Retrieved from <a href=\"$url\">";
    print
strtr($url, array('//'=>"//&#8203;", '/'=>"/&#8203;", '?'=>"?&#8203;", '&amp;'=>"&amp;&#8203;"));
    print
"</a>.</address>\n";
    print
"<div id=\"copy\">Copyright &copy; $copyyears <a href=\"&#x6D;&#x61;&#x69;&#x6C;&#x74;&#x6f;&#x3A;&#x25;&#x37;&#x30;&#x25;&#x36;&#x38;&#x25;&#x36;&#x43;&#x25;&#x36;&#x39;&#x25;&#x37;&#x30;&#x25;&#x34;&#x30;&#x25;&#x36;&#x44;&#x25;&#x37;&#x32;&#x25;&#x37;&#x30;&#x25;&#x36;&#x38;&#x25;&#x36;&#x63;&#x25;&#x36;&#x39;&#x25;&#x37;&#x30;&#x25;&#x32;&#x65;&#x25;&#x36;&#x33;&#x25;&#x36;&#x66;&#x25;&#x36;&#x64;\">Phillip Bradbury</a>. <a href=\"${pagesroot}copyright.php\">Some rights reserved</a>.</div>\n";
    print
"<div id=\"anybrowser\">This page is best viewed in <a href=\"https://www.anybrowser.org/campaign/\">a web browser at a screen resolution</a>. Attempts to do otherwise may fail miserably.</div>\n";
    
$endtime = microtime(TRUE);
    if (
$localhost)
        print
"<div id=\"servetime\">Served in " . round($endtime - $starttime,3) . " seconds</div>\n";
    else
        print
"<!-- Served in " . round($endtime - $starttime,3) . " seconds -->\n";
    print
"<div id=\"contact\"><a href=\"https://officeofstrategicinfluence.com/spam/\">Contact me</a></div>\n";
    print
"</body></html>\n";
}
function
error_page($text, $myfault = 0)
{
    
page_header("Error");
    print
"<p class=\"error\">";
    print
nl2br(htmlentities($text));
    if (
$myfault)
        print
"</p><p>Please email me at <a href=\"&#x6d;&#x61;&#x69;&#x6c;&#x74;&#x6f;&#x3a;&#x25;&#x37;&#x30;&#x25;&#x36;&#x38;&#x25;&#x36;&#x43;&#x25;&#x36;&#x39;&#x25;&#x37;&#x30;&#x25;&#x34;&#x30;&#x25;&#x36;&#x64;&#x25;&#x37;&#x32;&#x25;&#x37;&#x30;&#x25;&#x36;&#x38;&#x25;&#x36;&#x43;&#x25;&#x36;&#x39;&#x25;&#x37;&#x30;&#x25;&#x32;&#x65;&#x25;&#x36;&#x33;&#x25;&#x36;&#x66;&#x25;&#x36;&#x44;\">&#x70;&#x68;&#x6c;&#x69;&#x70;&#x40;&#x6d;&#x72;&#x70;&#x68;&#x6c;&#x69;&#x70;&#x2e;&#x63;&#x6F;&#x6d;</a>, tell me the error message above and what you were trying to do.";
    print
"</p>";
    
page_footer();
    exit;
}

define ("ANYTHING", 0);
define ("ONLYFILES", 1);
define ("ONLYDIRS", 2);
function
dirlist($path, $only = 0, $regex = 0)
{
    
$d = dir($path);
    if (!
$d)
        return
FALSE;
    
$list = array();
    while(
$a = $d->read())
    {
        if (
$a{0} == '.')
            continue;
        if (
substr($a, -1) == '~')
            continue;
        if (
$only == ONLYFILES && !is_file($a))
            continue;
        if (
$only == ONLYDIRS && !is_dir($a))
            continue;
        if (
$regex && !preg_match($regex, $a))
            continue;
        
$list[] = $a;
    }
    
sort($list);
    return
$list;
}
function
myfgets($fp)
{
    
$a = fgets($fp);
    if (
$a === FALSE) return FALSE;
    return
trim($a, "\r\n");
}

function
ds_banner($icon, $iconalt, $text)
{
    print
"<table class=\"dsbanner\"><tr><td class=\"icon\"><img src=\"$icon\" alt=\"$iconalt\" width=\"32\" height=\"32\"></td><td class=\"text\">$text</td></tr></table>\n";
}
?>


Valid HTML 4.01 StrictValid CSSLevel Triple-A conformance icon, W3C-WAI Web Content Accessibility Guidelines 1.0
Retrieved from https://​www.mrphlip.com/​common.php?​viewsource=yep.
Copyright © 2006–13 Phillip Bradbury. Some rights reserved.
This page is best viewed in a web browser at a screen resolution. Attempts to do otherwise may fail miserably.
Contact me