* * 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-10'; ## 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, $BlogeTagGroup, $LinkTargets; $kwlist = SetProperty($pagename, 'keywords', $kwlist, ', '); SDV($BlogeTagGroup, $CategoryGroup); if (empty($BlogeTagGroup)) return; $kwa = preg_split('/\s*,\s*/', $kwlist, -1, PREG_SPLIT_NO_EMPTY); if (!empty($kwa)) foreach ( $kwa as $kw ) { $kwp = MakePageName($pagename, "$BlogeTagGroup/$kw"); if ( !$kwp || !empty($LinkTargets[$kwp]) ) continue; $LinkTargets[$kwp] = 1; } } ## (:tag-list:) gives a list of links to tags, with optional parameters: (:tag-list Group.Page sep=', ':) Markup('tag-list', 'links', "/\\(:tag-list\\b(.*?):\\)/ei", "BlogeListTags(\$pagename, PSS('$1'))"); $SaveAttrPatterns['/\\(:tag-list(\\s.*?)?:\\)/i'] = ' '; function BlogeListTags($pagename, $args='') { global $PCache, $CategoryGroup, $BlogeTagGroup, $BlogeLinkTagFmt; SDV($BlogeTagGroup, $CategoryGroup); if (empty($BlogeTagGroup)) return ''; SDV($BlogeLinkTagFmt, ""); $opt = ParseArgs($args); $pn = empty($opt['']) ? $pagename : MakePageName($pagename, reset($opt[''])); if (!isset($PCache[$pn]['time'])) { $page = RetrieveAuthPage($pn, 'read', FALSE, READPAGE_CURRENT); if (!$page) return ''; PCache($pn, $page); } $sep = str_replace('\\\\',"
\n", empty($opt['sep']) ? ', ' : $opt['sep'] ); preg_match_all("/\b$BlogeTagGroup\.([^,]+)/", @$PCache[$pn]['targets'], $m, PREG_SET_ORDER); if (!$m) return ''; $ta = array(); foreach( $m as $tag ) $ta[] = MakeLink($pagename, $tag[0], $tag[1],'', $BlogeLinkTagFmt); return Keep(implode($sep, $ta),'L'); }