' . $WPCategoriesPlural . ': ' ); SDV( $WPCategoriesBetween, ' | ' ); SDV( $WPCategoriesPost, '' ); SDV( $HTMLStylesFmt['WPCategories'], '.WPCategoriesBox { border: 1px solid #aaa; background-color: #f9f9f9; margin-top: 1em; clear: both; padding: .5em 5px .6em 5px; line-height: 1.5em; } '); ## internal. Here we'll collect the links. $WPCategoriesStack = array(); ## Markup for finding links to categories. Sample links are: ## [[Category:Something]] ## [[Category.Foo bar]] ## [[Category/BarFoo]] ## Note, that other link formats (like [[(Category.)Foobar]], ## [[Category.Foobar]], [[Category/Foobar]] ) are not ## recognised (or at least that's what I aimed for...)! Markup( 'CollectCategoryLinks', 'CollectCategoryLinks', '/^\\[\\[!([^\\|]*?)\\]\\]/e', "WPCategoriesCollect('\$1')" ); if( IsEnabled($EnableWPCategoriesInline,0) ) { Markup( 'CollectCategoryLinks-inline', '>CollectCategoryLinks', '/(\\[\\[' . $WPCategoriesGroup . '[\\.\\/:]([^\\|]*?)\\]\\])/e', "WPCategoriesCollect('\$2','\$1')" ); Markup( 'Collect!CategoryLinks-inline', '>Collect!CategoryLinks', '/(\\[\\[!([^\\|]*?)\\]\\])/e', "WPCategoriesCollect('\$2','\$1')" ); } ## internal. ## A (:WPCategoriesList:) markup variable. It will be substituted ## with the Category-box. See also the "Implementation note" below, ## and WPCategoriesShow(). Markup( 'DisplayCategoryLinks', '>Collect!CategoryLinks', '/\\(:WPCategoriesList:\\)/e', 'WPCategoriesShow()' ); ## Add a backlinks-listing to all Category-group pages. if( $WPCategoriesAutoBacklinks ) $WPCategoriesListPages = '(:if group ' . $WPCategoriesGroup . ":)\n" . FmtPageName( $WPCategoriesListingHeader, $pagename ) . "\n" . '(:pagelist link={$Group}.{$Name} list=normal:)' . '(:if:)'; else $WPCategoriesListPages = ''; ## Showing the Categories-box in the page footer. ## ## Implementation note: ## We're doing that by using a new markup directive. $GroupFooterFmt = $WPCategoriesListPages . '(:WPCategoriesList:)' . $GroupFooterFmt; ## internal. ## This function is invoked when Category-link markup is found. ## It removes the link from the page, stacking it for later usage. function WPCategoriesCollect( $category, $keep=FALSE ) { global $WPCategoriesStack, $WPCategoriesGroup; global $LinkTargets; $WPCategoriesStack[] = '[[' . $WPCategoriesGroup . '/' . $category . ']]'; ## We have removed the link from the page above; the (not so) side ## effect is, that PmWiki engine won't know there's a certain link in ## the page at all, and thus it won't be saved in a special attribute of ## the page, named 'targets' (*). That'd result in the page not showing ## in Category's backlinks, what is certainly bad. Therefore, we must ## take the hacky way and add it to said attribute ourselves: @$LinkTargets[ MakePageName( $pagename, $WPCategoriesGroup . '/' . $category ) ]++; ## (*) That's because PmWiki collects page links information when ## saving the page, by running Markup-substitution, results of ## which are then ignored, apart from a special global variable ## $LinkTargets, which is set by link-parsing Markup handlers. return $keep ? $keep : ''; } ## internal. ## This function renders the Categories box when a special (:WPCategoriesList:) ## markup is found. function WPCategoriesShow() { global $WPCategoriesStack, $WPCategoriesPre, $WPCategoriesBetween, $WPCategoriesPost; if( $WPCategoriesStack ) { ## array_keys(array_flip($a)) returns unique values ## (reference: http://www.php.net/manual/en/function.array-unique.php) return FmtPageName( $WPCategoriesPre . implode($WPCategoriesBetween, array_keys(array_flip($WPCategoriesStack))) . $WPCategoriesPost, $pagename ); } else return ''; }