, Copyright 2007. * see http://www.pmwiki.org/wiki/Cookbook/Hg * Modified by: Kathryn Andersen */ /* * Set up various variables */ $RecipeInfo['Cluster']['Version'] = '2007-03-17'; SDV($ClusterSeparator, '-'); SDV($ClusterMaxLevels, 7); SDV($ClusterBreadCrumbSeparator, $ClusterSeparator); /* ================================================================ * 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)'; //$FmtPV['$ClusterRightBar'] = 'ClusterRightBarName($group)'; $FmtPV['$RightBar'] = 'ClusterRightBarName($group)'; $FmtPV['$BreadCrumb'] = 'ClusterBreadCrumb($pn)'; /* ================================================================ * 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; global $SiteGroup; $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 "$SiteGroup.SideBar"; } function ClusterRightBarName($group) { global $ClusterSeparator; global $SiteGroup; $groups = explode($ClusterSeparator, $group); while (count($groups) != 0) { $cluster_group = implode ($ClusterSeparator, $groups); if (PageExists("$cluster_group.RightBar")) { // short-circuit return! return "$cluster_group.RightBar"; } array_pop($groups); } return "$SiteGroup.RightBar"; } 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]]"; } function ClusterBreadCrumb($pagename) { global $ClusterSeparator; global $ClusterBreadCrumbSeparator; global $DefaultName; $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.= " $ClusterBreadCrumbSeparator "; } $out.= '[['; for ($num = 0; $num <= $i; $num++) { if ( $num != 0) { $out.= $ClusterSeparator; } $out.= $groups[$num]; } $out.= '/|'; $out.= $groups[$i]; $out.= ']]'; } if ($name != $DefaultName && $name != $group) { $out .= " $ClusterBreadCrumbSeparator "; $out .= "'''" . '{*$Namespaced}' . "'''"; } return $out; } // [Feral:075/07@16:35] Seems to work great! // Usage: Place in config.php: // (This is for Cookbook:TriadSkin, but the idea is the same for any) //$GroupTitleFmt="
"; //$GroupTitleFmt.="
"; //$GroupTitleFmt.=ClusterBreadCrumbHTML($pagename, false); //$GroupTitleFmt.="
"; //$GroupTitleFmt.="
"; //$GroupTitleFmt.="$grouptitle"; //$GroupTitleFmt.="
"; //$GroupTitleFmt.="
"; function ClusterBreadCrumbHTML($pagename, $include_last=false) { global $ClusterSeparator; global $ScriptUrl; global $EnablePathInfo; if ( $EnablePathInfo) { $path_part = '/'; $path_tail = $path_part; } else { $path_part = '?n='; $path_tail = ''; } $m = preg_split('/[.\\/]/', $pagename); $group = $m[0]; $name = $m[1]; $out = ""; $groups = explode($ClusterSeparator, $group); $depth = 0; $count_groups = count($groups) -1; foreach($groups as $item) { if ( !$include_last) { if ( $depth >= $count_groups) { break; } } $depth_index = 0; $group_path = ''; for($depth_index = 0; $depth_index <= $depth; $depth_index++) { if ( $depth_index>0) { $group_path .= "$ClusterSeparator"; } $group_path .= $groups[$depth_index]; } $path_name = $item; if ( $depth>0) { $out.= " $ClusterSeparator "; } $out.= "$path_name"; $depth++; } return $out; }