I am glad you found it useful. Use this plugin code for a simple work-around that looks for whole words would be to use the following code:
/**
* ContextLinks
* Written By Jesse Rochman
* January 30, 2008
*
* Version 1.0
*
* Events: OnWebPagePrerender
*
* Paste the following into the Configuration:
* &parents=Parents;string;0 &replace_with=Match Source;string;pagetitle
*
* Usage:
* Parents should be a comma delimited list of IDs for which children you want context links.
* Document field to use for the Match Source would likely be pagetitle, alias, longtitle, description, or menutitle.
*
*
*/
$e= & $modx->Event;
switch ($e->name) {
case "OnWebPagePrerender" : //mo register only for backend
$parents = explode(',',$parents);
foreach ($parents as $parent) {
$children = $modx->getActiveChildren($parent,$replace_with,'DESC', $fields= 'id, ' . $replace_with);
foreach ($children as $child) {
//Dumb whole word search. If Keyword is "Man". The plugin will not match "manhole." (This is good).
//Will not match "man," "man." "'man'" (This is bad because it is thrown off by the punctuation).
/*
$replaced_string = ' ' . $child[$replace_with] . ' ';
$context_link = ' <a href="' . $modx->makeUrl($child['id']) . '">' . $child[$replace_with] . '</a>';
$modx->documentOutput = str_replace($replaced_string, $context_link, $modx->documentOutput);
*/
//Somewhat smarter whole word search, but a little agressive. If Keyword is "Man". The plugin will not match "manhole." (This is good).
//Will match "man," "man." "'man;" "'man'" (This is even better). However, it will also match these keywords if inside attribute fields for your HTML, creating messy links.
///*
$replaced_string = $child[$replace_with];
$context_link = '<a href="' . $modx->makeUrl($child['id']) . '">' . $child[$replace_with] . '</a>';
$modx->documentOutput = preg_replace('`\\' . $replaced_string . '\b`', $context_link, $modx->documentOutput);
//*/
}
}
break;
default :
return; // stop here - this is very important.
}
Any hints on the making these searches better would be nice. Also any hints on how to narrow the scope of the replacement to certain document fields such as pagetitle, content, and longtitle.