Hello Tobias,
I am the webmaster at
http://www.puzzlers.org and added the navigation footer to pages like
http://www.puzzlers.org/dokuwiki/doku.php?id=krewe:noms:kite due to the very large number of pages in that one directory.
The trail starts in the website template where my content <DIV> reads:
<div class="page">
<!-- wikipage start -->
<?php tpl_content() ?>
<!-- Puzzler page footer start -->
<?php puz_insert_php("_footer.php"); ?>
<!-- Puzzler page footer stop -->
<!-- wikipage stop -->
</div>
The three lines are my "hook" to generate that navigation. I include a custom script file in the template (for my site it is puzzlers.php), and it includes the puz_insert_php(file) function:
function puz_insert_php($php_file) {
global $ACT;
global $REV;
global $ID;
//global $TEXT;
//global $PRE;
//global $SUF;
//global $SUM;
//global $IDX;
//echo "<!-- ACT: $ACT -->\n";
switch($ACT){
case 'show':
//echo "<!-- DEBUG ID: $ID -->\n";
echo "\n\t\t<!-- Puzzler inserted PHP start -->\n";
$file = preg_replace("/.txt/", "/$php_file", wikiFN(getNS($ID)));
echo "\n\t\t<!-- DEBUG: \$file=$file -->\n";
if(@file_exists($file)){
ob_start();
$text = io_readFile($file);
if($INFO['perm'] == AUTH_ADMIN) {
eval("?>$text");
} else {
@eval("?>$text");
}
$content = ob_get_contents();
ob_end_clean();
echo $content;
} else {
echo "\t\t<!-- PHP file was not found -->\n";
}
echo "\n\t\t<!-- Puzzler inserted PHP stop -->\n";
break;
case 'preview':
case 'edit':
case 'wordblock':
case 'search':
case 'revisions':
case 'diff':
case 'recent':
case 'index':
case 'backlink':
case 'conflict':
case 'locked':
case 'login':
case 'register':
case 'denied':
case 'admin':
case 'profile';
break;
default:
msg("Failed to handle command: ".hsc($ACT),-1);
}
}
Using this external file and function allows me to upgrade Dokuwiki from time to time by adding my customizations (all with a puz_ prefix) into the current template format. And this function is generic enough that I can put pretty much any PHP script in for the footer of the page.
The footer script in the Noms area you asked about (below) is not pretty, but gets what I needed done for the pages I had to work with. I have an outline of the code after the code.
_footer.php (begin)
<!-- NOM page Footer -->
<hr />
<style type="text/css" media="screen">
div.nav-outer {
align='center'
}
div.nav-left {
float: left;
vertical-align: text-top;
text-align: left;
}
div.nav-center {
#float: left;
vertical-align: text-bottom;
text-align: center;
}
div.nav-right {
float:right;
vertical-align:text-top;
text-align:right;
}
span.nav-left {
vertical-align: text-top;
text-align: left;
}
span.nav-right {
vertical-align:text-top;
text-align:right;
}
</style>
<?php
function pointers($cells, $count, $to_id) {
require_once(DOKU_INC.'inc/parser/xhtml.php');
static $xhtml_renderer = NULL;
if($count < 0) {
// Left pointers
for($image = $cells * -1; $image < 0; $image++) {
if($image >= $count) {
// output a left pointer
$res .= "<img src=\"/dokuwiki/lib/exe/fetch.php?w=&h=&cache=cache&media=images:arrows:nomleft.gif\" class=\"media\" alt=\"Prev\" />";
} else {
// Ouput a blank to the left of the pointers
$res .= "<img src=\"/dokuwiki/lib/exe/fetch.php?w=&h=&cache=cache&media=images:arrows:nomzero.gif\" class=\"media\" alt=\"Prev\" />";
}
} // for
} else {
// right pointers
for($image = 0; $image < $cells; $image++) {
if($image < $count) {
// outpur a right pointer
$res .= "<img src=\"/dokuwiki/lib/exe/fetch.php?w=&h=&cache=cache&media=images:arrows:nomright.gif\" class=\"media\" alt=\"Next\" />";
} else {
// Ouput a blank to the right of the pointers
$res .= "<img src=\"/dokuwiki/lib/exe/fetch.php?w=&h=&cache=cache&media=images:arrows:nomzero.gif\" class=\"media\" alt=\"Next\" />";
}
} // for
} // left or right pointers?
return "<a href=\"/dokuwiki/doku.php?cache=cache&id=" . $to_id .
"\" class=\"internallink\" title=\"$to_id\" onclick=\"return svchk()\" " .
"onkeypress=\"return svchk()\">" . $res . "</a>";
}
function Build_Nom_Nav() {
$dir = dirname(wikiFN(getID()));
$data = array();
$ns = getNS(getID());
$current = noNS(getID());
$links = -1;
//echo "\t\t\t\t<!-- DEBUG \$dir=$dir -->\n";
search($data, $dir,'search_index',array('ns' => $ns));
foreach ($data as $item){
// echo "\t\t\t\t<!-- DEBUG \$item['id']=" .$item["id"] . " -->\n";
if( $item['type'] == 'f') { // only do files
if( $item["id"] == $current ) {
//echo "\t\t\t\t<!-- DEBUG FOUND -->\n";
$links = 0; // Found ... start counting links
// Build the prior links list
echo "\n\t<div class='nav-outer'>\n";
echo "\n\t<div class='nav-left'>\n";
if(isset($prior1)) {
echo "\t\t<span class='nav-left'>" . pointers(3, -1, "$ns:$prior1");
echo html_wikilink($prior1) ."</span><br />\n";
}
if(isset($prior2)) {
echo "\t\t<span class='nav-left'>" . pointers(3, -2, "$ns:$prior2");
echo html_wikilink($prior2) ."</span><br />\n";
}
if(isset($prior3)) {
echo "\t\t<span class='nav-left'>" . pointers(3, -3, "$ns:$prior3");
echo html_wikilink($prior3) ."</span><br />\n";
}
echo "\n\t</div> <!-- nav-left -->";
echo "\n\t<div class='nav-center'>" . html_wikilink($ns) . "</div>";
echo "\n\t<div class='nav-right'>\n";
} else {
if($links < 0) {
// searching -- cache the last e entries
$prior3 = $prior2;
$prior2 = $prior1;
$prior1 = $item["id"];
} elseif ($links < 3) {
$links++;
//echo "\t\t\t\t<!-- DEBUG following: $links -->\n";
echo "\t\t<span class='nav-right'>" . html_wikilink($item["id"]);
echo pointers(3, $links, "$ns:" . $item["id"]) ."</span><br />\n";
} else {
echo "\n\t</div> <!-- nav-right -->";
echo "\n\t</div> <!-- nav-outer -->";
//echo "\t\t\t\t<!-- DEBUG DONE -->\n";
break; // we're done ... no need to check any more
} // if (found, following, or done)
} // if(found)
} // if(is a file)
} // foreach()
} // Build_Nom_Nav()
echo "\t\t<!-- Building Nom footer -->\n";
Build_Nom_Nav();
echo "\t\t<!-- Done building Nom footer -->\n";
?>
_footer.php (end)
In the footer script in the Noms area (above), I essentially:
1. Output some local styles.
2. Scan the directory for files, then sort them into alpha order.
3. Iterate across the file list keeping track of the last 3 pages until the current page is found in the list
4. Output the left (before) set of links + the "up" in the navigation and start counting
$links = 0.
5. for the next three pages in the list, output the right (after) set of links for navigation
6. stop looking at files after the 3rd right hand link.
This file is the "hard part" you can't see on my site; everything else is sort of findable on the web (my graphics, the important parts of the puz_insert_php(file) function -- its just one of the "do" functions from docuwiki where I replaced the output with the meat of the include_form code which is a plugin in Docuwiki. In fact, you could probably just replace that function call with the include form plugin to include the _footer.php ;-).
I hope that helps,
Kite