element if (!$title) { if (substr($link, 0, 4) == ''; return $a; } // anchor() function image($src, $alt, $title = null, $class = null) { // return an element $path = '/img/'; $img = ' [default] or element if (!$tag) $tag = 'acronym'; $a = '<' . $tag; if ($class) $a .= ' class="' . $class . '"'; $a .= ' title=" ' . $title . ' ">' . $abbr . ''; return $a; } // abbr() function tooltip($tool, $tip) { // custom tooltips global $_IE; // maybe if ($_IE) { $tip = str_replace('
', ' ', strip_tags($tip, '
')); $tooltip = '' . $tool . ''; } else { $tooltip = '' . $tool . '' . $tip . ''; } return $tooltip; } // tooltip() function linktip($href, $link, $tip) { // return a link replacing the title attribute with a custom tooltip global $_IE; // perhaps if ($_IE) { $tip = str_replace('
', ' ', strip_tags($tip, '
')); $link = '' . $link . ''; } else { $tooltip = '' . $link . '' . $tip . ''; $link = '' . $tooltip . ''; } return $link; } // linktip(); // external links function wiki_uri($path) { $uri = 'http://www.wikipedia.org/wiki/'; return $uri . $path; } function w3_uri($path) { $uri = 'http://www.w3.org/TR/'; return $uri . $path; } function PHP_builtin($fun) { $uri = 'http://www.php.net/manual/function.'; $uri .= str_replace('_', '-', $fun); $uri .= '.php'; $fun .= '()'; $title = 'PHP ' . $fun . ' function'; return anchor($uri, $fun, $title); } // PHP_builtin() function code($code) { return '' . $code . ''; } function cite($cite) { return '' . $cite . ''; } function vary($var) { global $ent; return code($ent['dollar'] . $var); } function tag($tag) { return code('<' . $tag . '>'); } function fun($fun) { return code($fun . '()'); } function tag_reference($tag) { // return a link to an external reference page on a particular HTML element $href = 'http://www.w3schools.com/tags/tag_'; $href .= $tag . '.asp'; $title = 'HTML <' . $tag . '> Reference'; return anchor($href, tag($tag), $title); } // tag_reference() function sql_reference($sql) { // same as above for SQL $href = 'http://www.w3schools.com/sql/sql_'; $href .= $sql . '.asp'; $title = 'SQL ' . ucfirst($sql) . ' Reference'; return anchor($href, $sql, $title); } // sql_reference() function lablist($order = null, $label = 'Labs') { // display a list of labs as links for this index $s = DIRECTORY_SEPARATOR; global $db, $did, $page, $pebbles; if ($did) { $orderby = ' order by'; if ($order) { // fid=4 desc, fid=5 desc, fid=6 desc, fid=14 desc, fid=9 desc $l = count($order); $l--; foreach ($order as $i => $fid) { if ($i == $l) $orderby .= ' fid=' . $fid . ' desc'; else $orderby .= ' fid=' . $fid . ' desc,'; } } else $orderby .= ' file.fid'; $_s = 'select file.name, file.title, media.ext'; $_s .= ' from file, media'; $_s .= ' where file.mid=media.mid and file.did=' . $did; $_s .= $orderby; if ($_r = mysql_query($_s, $db)) { while (list($name, $title, $ext) = mysql_fetch_row($_r)) { $files[] = $name; $titles[$name] = $title; $exts[$name] = $ext; } mysql_free_result($_r); } // virtual directory aka relative path $pb = $pebbles; // pop a local copy or you destroy the orignal list($vdir,) = array_pop($pb); while (list($dir,) = array_pop($pb)) $vdir .= $dir . $s; $vdir .= $page['name'] . $s; } if (!$files) print '

Oops! Can\'t find any labs for this index.

' . "\n"; else { print <<<_U
    _U; foreach ($files as $f) { $href = $vdir . $f . '.' . $exts[$f]; $title = $f . '.' . $exts[$f]; $li = '
  1. '; $li .= $titles[$f] . '
  2. ' . "\n"; print $li; } print '
' . "\n"; } } // lablist() function updated() { global $page, $ent; // return file modification time of a script // in "local" and "standard" [W3C] formats $format = array( 'local' => 'l, F jS, Y @ g:i A T', 'w3c' => 'Y-m-d\TH:i:s\Z' ); $file = $_SERVER['PATH_TRANSLATED']; $mod = filemtime($file); $local = date($format['local'], $mod); // file modified timestamp $w3c = '[]'; $top = ' Top of '; $top .= ($page['h1']) ? $page['h1'] : $page['title']; $top .= ($index and $page['name'] != '/') ? ' Index ' : ' Page '; print <<<_U Last updated: $local $w3c ${ent['nbsp']} _U; } // updated() function dirlist() { // display a list of directories and files as links $s = DIRECTORY_SEPARATOR; global $db, $did, $page, $pebbles; if ($did) { $_s = 'select name, title from dir where pid=' . $did; if ($_r = mysql_query($_s, $db)) { while (list($name, $title) = mysql_fetch_row($_r)) { $dirs[] = $name; $titles[$name] = $title; } mysql_free_result($_r); } $_s = 'select file.name, file.title, media.ext'; $_s .= ' from file, media'; $_s .= ' where file.mid=media.mid and file.did=' . $did; $_s .= ' order by file.fid'; if ($_r = mysql_query($_s, $db)) { while (list($name, $title, $ext) = mysql_fetch_row($_r)) { $files[] = $name; $titles[$name] = $title; $exts[$name] = $ext; } mysql_free_result($_r); } // virtual directory aka relative path $pb = $pebbles; // pop a local copy or you destroy the orignal list($vdir,) = array_pop($pb); while (list($dir,) = array_pop($pb)) $vdir .= $dir . $s; $vdir .= $page['name'] . $s; } else { // get linkable files from the system, to use this feature // an index file should set $did = 0; see: /proto/index.php $rdir = dirname($_SERVER['PATH_TRANSLATED']); $vdir = dirname($_SERVER['SCRIPT_NAME']); $vdir .= $s; $rdir .= $s; if ($dh = @opendir($rdir)) { while ($file = readdir($dh)) { if ($file{0} != '.') { switch (filetype($rdir . $file)) { case 'dir': $dirs[] = $file; break; case 'file': list($base, $ext) = explode('.', $file); if ($base != 'index') { $files[] = $base; $exts[$base] = $ext; } break; } } } closedir($dh); if ($dirs) sort($dirs); if ($files) sort($files); } else print "Can't open: $vdir!\n"; } if (!($dirs or $files)) print '

Oops! Directory appears to be empty.

' . "\n"; else { print <<<_U

Contents:

    _U; if ($dirs) { foreach ($dirs as $d) { $href = $vdir . $d . $s; $title = $titles[$d]; $li = '
  • '; $li .= $d . '/
  • ' . "\n"; print $li; } } if ($files) { foreach ($files as $f) { $href = $vdir . $f . '.' . $exts[$f]; $title = $titles[$f]; $li = '
  • '; $li .= $f . '
  • ' . "\n"; print $li; } } print '
' . "\n"; } } // dirlist() // lib/markup.php ?>