* * Use page keywords and categories as tags * * Developed and tested using PmWiki 2.2.x * * To install, add the following to your configuration file: include_once("$FarmD/cookbook/bloge-tags.php"); * This is a part of the Bloge bundle of recipes, but may be used by itself. * For more information, please see the online documentation at * http://www.pmwiki.org/wiki/Cookbook/Bloge-Tags and at * http://www.pmwiki.org/wiki/Cookbook/Bloge * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. */ $RecipeInfo['Bloge-Tags']['Version'] = '2009-08-11'; ## {$TagList} gives a list of links to tags, {$TagCount} the number or tags $FmtPV['$TagList'] = 'BlogeTagList($pn)'; $FmtPV['$TagCount'] = 'BlogeTagList($pn, TRUE)'; $SaveAttrPatterns['/\\{[^{]*\\$TagList\\}/'] = ' '; ## overload (:keywords:) directive to add links to $page['targets'] Markup('keywords', 'directives', "/\\(:keywords?\\s+(.+?):\\)/ei", "PZZ(BlogeTagKeywords(\$pagename, PSS('$1')))"); function BlogeTagKeywords($pagename, $kwlist) { global $CategoryGroup, $BlogeTag, $LinkTargets; $kwlist = SetProperty($pagename, 'keywords', $kwlist, ', '); SDV($BlogeTag['group'], $CategoryGroup); if (empty($BlogeTag['group'])) return; $kwa = preg_split('/\s*,\s*/', $kwlist, -1, PREG_SPLIT_NO_EMPTY); if (!empty($kwa)) foreach ( $kwa as $kw ) { $kwp = MakePageName($pagename, "{$BlogeTag['group']}/$kw"); if ( !$kwp || !empty($LinkTargets[$kwp]) ) continue; $LinkTargets[$kwp] = 1; } } function BlogeTagList($pagename, $count=FALSE) { global $PCache, $CategoryGroup, $BlogeTag; SDVA($BlogeTag, array( 'group' => $CategoryGroup, 'linkfmt' => "", 'prefix' => '$[Tags]: ', 'separator' => ', ' )); if (empty($BlogeTag['group'])) return ''; preg_match_all("/\b{$BlogeTag['group']}\.([^,]+)/", @$PCache[$pagename]['targets'], $m, PREG_SET_ORDER); if (!$m) return ''; if ($count) return count($m); $ta = array(); foreach( $m as $tag ) $ta[] = MakeLink($pagename, $tag[0], $tag[1],'', $BlogeTag['linkfmt']); return $BlogeTag['prefix'].Keep(implode($BlogeTag['separator'], $ta),'L'); }