/docs/_data/widgets/tpl_docs_nav.php

https://github.com/gtd/templation · PHP · 23 lines · 16 code · 5 blank · 2 comment · 5 complexity · 5829c56d6e4359d005b1f2efc3077459 MD5 · raw file

  1. <?php
  2. /* TPL Docs Navigation Widget */
  3. //Read in index file to get list of files.
  4. $fp = fopen('index.php','r') or die("Wuh?");
  5. $toc = fread($fp,filesize('index.php'));
  6. preg_match_all('/<a href="([^"#]*)">(.*)<\/a>/',$toc,$matches);
  7. for($i = 0; $i < count($matches[1]); $i++) {
  8. $pages[] = array('link'=>$matches[1][$i], 'title'=>$matches[2][$i]);
  9. if( substr($_SERVER['PHP_SELF'],strrpos($_SERVER['PHP_SELF'],'/') + 1) == $matches[1][$i] ) $num = $i;
  10. }
  11. if(isset($num)) {
  12. $output = '<div class="navigation">';
  13. $output .= '<a href="'.$pages[$num-1]['link'].'" class="leftNav"><span>'.$pages[$num-1]['title'].'</span></a>';
  14. $output .= '<a href="index.php" class="centerNav"><span>Table of Contents</span></a>';
  15. if($num+1 < count($pages)) $output .= '<a href="'.$pages[$num+1]['link'].'" class="rightNav"><span>'.$pages[$num+1]['title'].'</span></a>';
  16. $output .= "<div style=\"clear: both\"></div></div>\n\n\n";
  17. }
  18. ?>