<?php
// $Id: app.inc.php 1031 2009-07-18 13:46:41Z bb $
// Site-wide constants
// Separator between general navigation items
$NAV_SEP = " •\n";
// Separator between hierarchical navigation items
$NAV_SEP_HIER = " <strong>»</strong>\n";
class Application {
// general properties
var $site = "dr Beat(li)";
var $metaauthor = "Beat "2b" Bolli";
var $author = "<a href=\"/php/redir.php?d=bb\">Beat "2b" Bolli</a>";
var $title = '(none)';
var $language = 'de';
// style sheet
var $style = '/bb.css';
var $doctype = '';
var $htmltag = '';
var $head_attr = ''; // can specify additional <head> attributes here
var $js_includes = Array(); // can define JavaScript include files
var $head_add = ''; // can specify additional <head> content here
var $body_attr = ''; // can specify additional <body> attributes here
var $template_h1 = '<h1>%s</h1>';
var $menu; // menu/navigation bar to show
var $submenu; // page internal menu/navigation, shown after the title
var $sidebar = false; // sidebar true/false
var $logos; // Array of logos
function Application($title, $menu=null, $submenu=null) {
$this->doctype = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"
\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n\n";
$this->htmltag = "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"{$this->language}\">\n\n";
$this->title = $title;
$this->menu = $menu;
if ($this->menu && $this->title)
$this->menu->inactivate($this->title);
$this->submenu = $submenu;
$this->sidebar = isset($_GET['sidebar']) ? $_GET['sidebar'] : false;
$this->logos = Array();
$this->addLogo('<a href="http://creativecommons.org/licenses/by-nc-sa/1.0/"><img src="/pic/somerights.png" width="88" height="31" alt="Some rights reserved" /></a>');
}
function addLogo($logo) {
$this->logos[] = $logo;
}
function delLogo($ident) {
foreach ($this->logos as $i => $logo)
if (strpos($logo, $ident) !== false) {
unset($this->logos[$i]);
return;
}
}
function html_logos() {
return implode("\n", $this->logos);
}
function html() {
echo $this->doctype;
global $ID;
if ($ID)
echo "<!-- $ID -->\n\n";
echo $this->htmltag;
}
function head() {
echo "<head{$this->head_attr}>
<!-- \$Id: app.inc.php 1031 2009-07-18 13:46:41Z bb $ -->
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
<meta name=\"author\" content=\"{$this->metaauthor}\" />
<meta name=\"ICBM\" content=\"47.0452, 07.2715\" />
<link rel=\"contact\" href=\"/php/contact.php\" title=\"Contact address\" />
<link rel=\"publickey\" href=\"/pubkey.php\" title=\"GnuPG public key\" />
<link rel=\"author\" href=\"/about.php\" title=\"Über mich...\" />
<link rel=\"shortcut icon\" href=\"/pic/favicon.ico\" />
<link rel=\"openid.server\" href=\"http://www.drbeat.li/id/\" />
<link rel=\"openid.delegate\" href=\"http://www.drbeat.li/id/index.php\" />";
if ($this->style)
echo "<link rel=\"stylesheet\" href=\"{$this->style}\" type=\"text/css\" title=\"2b style\" />\n";
if ($this->menu)
echo $this->menu->html_links();
foreach ($this->js_includes as $js)
echo "<script type=\"text/javascript\" src=\"$js\"></script>\n";
if ($this->head_add)
echo $this->head_add, "\n";
echo "<title>{$this->site} - {$this->title}</title>
</head>
<body{$this->body_attr}><div id=\"body\"> <!-- braindamaged IE doesn't apply borders to the body tag :-( -->
";
}
function body($header1='') {
echo "<div id=\"header\">\n";
if ($this->menu)
echo $this->menu->html_nav();
printf($this->template_h1, $header1 ? $header1 : $this->title);
echo "\n</div>\n\n";
if ($this->submenu)
echo $this->submenu->html_nav();
echo "<div id=\"main\">\n";
if ($this->sidebar)
echo "\n<div id=\"content\">\n";
include "noie.inc.php";
}
function header($header1='') {
$this->html();
$this->head();
$this->body($header1);
}
function footer($noref=0) {
$nav = $this->menu ? $this->menu->html_nav() : '';
$subnav = $this->submenu ? $this->submenu->html_nav() : '';
$logos = $this->html_logos();
$uri = htmlspecialchars($_SERVER['REQUEST_URI']);
if ($this->sidebar) {
echo "</div> <!-- #content -->\n\n<div id=\"sidebar\">\n\n";
$this->doSidebar();
echo "</div> <!-- #sidebar -->\n\n";
}
echo "</div> <!-- #main -->
<div id=\"footer\">
$subnav$nav
<div id=\"epilogue\">\n";
if (!$noref)
echo "<a href=\"/php/access.php?uri={$uri}&dns=1\">accesses</a>
<!-- a href=\"/php/referrer.php?uri={$uri}\">referrers</a -->\n";
echo "© 2005 {$this->author}
$logos
</div>\n\n</div>\n\n</div>
<script src=\"http://www.google-analytics.com/urchin.js\" type=\"text/javascript\"></script>
<script type=\"text/javascript\">_uacct = \"UA-1007784-1\"; urchinTracker();</script>
</body>\n\n</html>\n";
} // footer()
function doSidebar() {
foreach (glob("/home/bb/public_html/sidebar.d/*") as $sideitem) {
if (substr($sideitem, -1) != '-' && substr($sideitem, -9) != 'index.php') {
include $sideitem;
echo "\n";
}
}
}
} // class Application
include 'album/album.inc.php';
class MenuItem {
var $rel;
var $name;
var $url;
function MenuItem($rel, $name, $url) {
$this->rel = $rel;
$this->name = $name;
$this->url = $url;
}
function href() {
return $this->name ?
$this->url ?
$this->rel ?
($this->rel == 'index') ?
"<a rel=\"{$this->rel}\" accesskey=\"0\" href=\"{$this->url}\">{$this->name}</a>" :
"<a rel=\"{$this->rel}\" href=\"{$this->url}\">{$this->name}</a>" :
"<a href=\"{$this->url}\">{$this->name}</a>" :
$this->name :
'';
}
function linkrel() {
return $this->rel ?
"<link rel=\"{$this->rel}\" href=\"{$this->url}\"" .
($this->name ? " title=\"{$this->name}\"" : '') . " />\n" : '';
}
} // class MenuItem
class Menu { // the whole menu
var $items;
var $sep;
function Menu($sep=false) {
global $NAV_SEP;
$this->items = array();
$this->sep = ($sep === false) ? $NAV_SEP : $sep;
}
function addItem($item) {
$this->items[] = $item;
}
function html_nav($prefix="") {
$items = array($prefix);
foreach ($this->items as $item)
$items[] = $item->href();
return "<p class=\"nav\">\n" . implode($this->sep, array_filter($items)) . "\n</p>\n";
}
function html_links() {
$links = '';
foreach ($this->items as $item)
$links .= $item->linkrel();
return $links;
}
function inactivate($name) {
foreach ($this->items as $i => $item)
if (strpos($name, $item->name) === 0)
$this->items[$i]->rel = $this->items[$i]->url = '';
}
} // class Menu
?>