<?php

/*  
    Copyright (2003) Ross Kowaski
    Modified 12-Jul-2003 by Patrick R. Michaud

    This script provides two options for automatically 
    generating a list of the groups avilable in a pmwiki.
    To use the script, place it in your local directory,
    include the script by adding the following line to your local.php

    include_once("local/grouplist.php"); in config.php

    , then add [[$Grouplisth]] or [[$Grouplistv]] to your wiki page.
    The h and v at the end of the command are for horizontal and vertical 
    formatting of the resulting list.

    Updated 13-Jul-2003 by pmichaud
      - Changed output to be XHTML-compliant
      - Made output configurable
      - Only uses files in wiki.d which are valid pagenames
      - works with E_NOTICE set

 Updated 18-dec-2004 by kowalski
      - added pagename= for more universal function
      - fixed remarked include_once from deprecated local.php to config.php
    

*/

SDV($InlineReplacements['/\\[\\[\\$Grouplist([hv]).*?\\]\\]/e'],
  "FmtGrouplist('$1')");
SDV($GroupListFmt['v'],
  "<a href='$ScriptUrl?pagename=\$Group'><font size='2'>\$Group</font></a><br />");
SDV($GroupListFmt['h'],
  "<a href='$ScriptUrl?pagename=\$Group'>\$Group</a> &nbsp; &nbsp;");   

function FmtGrouplist($type) 
{
  global $WikiDir,$GroupNamePattern,$PageTitlePattern,$DefaultTitle,
    $GroupListFmt; 
  $dirp = @opendir($WikiDir); if (!$dirp) return '';  
  while (($p=readdir($dirp))!==false) {
    if (preg_match("/^($GroupNamePattern)\.$PageTitlePattern\$/",$p,$match))
      @$grouplist[$match[1]]++;
  }
  closedir($dirp);
  ksort($grouplist); reset($grouplist);
  $out = array();
  foreach($grouplist as $g=>$v) {
    $out[] = FmtPageName($GroupListFmt[$type],"$g.$DefaultTitle");
  }
  return implode('',$out);
}

?>