, Copyright 2007. * see http://www.pmwiki.org/wiki/Cookbook/Hg * Modified by: Kathryn Andersen v'2007-02-12' * ---- * Modified by: Feral v'2007-02-14' * I added (:nl:)s next to the (:include:) statements as [[PmWiki/LayoutVariables#GroupFooterFmt]] denotes that a (:nl:) after the (:include:) is default. However, in my tests I found a (:nl:) before the (:include:) was also necessary to arrive at the same output. * I also added code for a (:clusterbreadcrumbs:) directive that will output a clickable 'breadcrumbs' style trail. * ---- */ /* * Set up various variables */ $RecipeInfo['Cluster']['Version'] = '2007-02-14'; SDV($ClusterSeparator, '-'); SDV($ClusterMaxLevels, 7); /* ================================================================ * Page Variables */ $FmtPV['$g0'] = 'ClusterCountLevels($group)'; $FmtPV['$n0'] = 'ClusterCountLevels($name)'; for ($i=0; $i < $ClusterMaxLevels; $i++) { $hg = "g" . ($i + 1); $hn = "n" . ($i + 1); $FmtPV['$' . $hg] = 'ClusterSplitName($group, ' . $i . ')'; $FmtPV['$' . $hn] = 'ClusterSplitName($name, ' . $i . ')'; } $FmtPV['$SideBar'] = 'ClusterSideBarName($group)'; $FmtPV['$GroupTitle'] = 'ClusterGroupTitle($pn, $var)'; $FmtPV['$GroupTitlespaced'] = 'ClusterGroupTitle($pn, $var)'; /* ================================================================ * Markup for link shortcuts */ Markup('[[cluster','= count($parts)) return ''; else return $parts[$ind]; } function ClusterGroupTitle($pagename, $var, $fmt = NULL) { global $DefaultName, $SpaceWikiWords, $AsSpacedFunction; // look for a group-title for this specific group, first if (is_null($fmt)) { SDV($GroupTitlePathFmt, array( '$Group.GroupAttributes', '$Group.GroupHeader', '$Group.GroupFooter', '$Group.$Group', "\$Group.$DefaultName")); $fmt = $GroupTitlePathFmt; } foreach((array)$fmt as $f) { $pn = FmtPageName($f, $pagename); $page = ReadPage($pn, READPAGE_CURRENT); if ($page['title']) { return $page['title']; } } // okay, didn't find one $num_parts = PageVar($pagename, '$g0'); if ($num_parts == 1) { $grouptitle = PageVar($pagename, '$Group'); } else { // get the last part of the group $grouptitle = PageVar($pagename, '$g' . PageVar($pagename, '$g0')); } return ($var == '$GroupTitlespaced' || $SpaceWikiWords) ? $AsSpacedFunction($grouptitle) : $grouptitle; } function ClusterSideBarName($group) { global $ClusterSeparator; $groups = explode($ClusterSeparator, $group); while (count($groups) != 0) { $cluster_group = implode ($ClusterSeparator, $groups); if (PageExists("$cluster_group.SideBar")) { // short-circuit return! return "$cluster_group.SideBar"; } array_pop($groups); } return 'Site.SideBar'; } function ClusterLinks($pagename, $prefix, $inlink) { global $ClusterSeparator; $group = FmtPageName('$Group', $pagename); if ($prefix == "-") { return "[[$group$ClusterSeparator$inlink]]"; } $groups = explode($ClusterSeparator, $group); $c = strlen($prefix); $i = 0; while ($i < $c) { if (substr($prefix, 0, 1) == "*") $link = $link . $groups[$i] . $ClusterSeparator; if (substr($prefix, 0, 1) == "^") array_pop($groups); $i = $i + 1; } if (substr($prefix, 0, 1) == "*") $link = substr ($link, 0, -1); if (substr($prefix, 0, 1) == "^") $link = implode($ClusterSeparator, $groups); return "[[$link$inlink]]"; } // ---- // Blame the following on Feral... Markup('clusterbreadcrumbs','directives',"/\(:clusterbreadcrumbs:\)/e", "ClusterBreadCrumbs()"); function ClusterBreadCrumbs() { global $ClusterSeparator; global $pagename; $pagename = ResolvePageName($pagename); $EnablePGCust = 0; $m = preg_split('/[.\\/]/', $pagename); $group = $m[0]; $name = $m[1]; $out = ""; $groups = explode($ClusterSeparator, $group); $number = count($groups); for ($i=0; $i < $number; $i++) { if ( $i != 0) { $out.= " $ClusterSeparator "; } // $out.= "$i:"; $out.= "[["; for ($num = 0; $num <= $i; $num++) { if ( $num != 0) { $out.= $ClusterSeparator; } $out.= $groups[$num]; } $out.= "|"; $out.= $groups[$i]; $out.= "]]"; // $out.= " !! "; } // $out.= "
\n"; return $out; } // ///EOF