<?php if (!defined('PmWiki')) exit(); /* autoLink.php, a recipe for PmWiki based on code provided by Patrick R. Michaud, Eemeli Aro, and Peter Bowers compiled by Adam Overton, August 2009 . . . 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. http://www.gnu.org/copyleft/gpl.html This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. . . . Using autoLink.php: This recipe displays any specified word, phrase or name as a link, throughout the entire site. To enable this recipe, in your config.php, declare $NameToLinkArray, containing the names you'd like have displayed as links, and then include the recipe itself, for instance: # reminder: all keys must be completely lowercase in order for this to work! $NameToLinkArray = array( 'john doe' => 'http://www.johndoe.com', 'acme corp' => 'http://www.acme.com' ); # now enable this recipe: include_once('cookbook/autoLink.php'); Note that any words, names and phrases can be prevented from linking by preceding it with the backtick (`) character. */ $RecipeInfo['autoLink']['Version'] = '2009-08-26'; Markup('names', 'inline', '/(`?)\b(' . join('|', array_keys($NameToLinkArray)) . ')\b/ei', 'AutoNameToLinkFunc("$2","$1")' ); function AutoNameToLinkFunc($name, $escape) { global $NameToLinkArray; if ($escape) return $name; $link = '%newwin%[['.$NameToLinkArray[strtolower($name)].'|'.Keep($name).']]'; return $link; }