Plugin examples

< ‌ index ‌ >

Word Filter

Description: Filter words from a document before it’s displayed on the web
System Events: OnWebPagePrerender

$words = array("snippet", "template"); // words to filter

$e = &$modx->Event;
switch ($e->name) {
case "OnWebPagePrerender":
$o = &$modx->documentOutput; // get a reference of the output
$o = str_replace($words,"<b>[filtered]</b>",$o);
 break;
default :
return; // stop here - this is very important.
 break;
}

 


Page-Not-Found Redirector:

Description: Redirects a user to selected document and sends a message
System Events: OnPageNotFound
Config: String: &pg=Error Page;int; &rep=Mail To;string;

$e = &$modx->Event;
switch ($e->name) {
case "OnPageNotFound":
if(!$pg) $modx->sendErrorPage();
else {
if ($mid) {
// send a message to a local account
$docid = $modx->documentIdentifier;
$subject = "Page not found";
$msg = "Someone tried to access document id $docid";
$modx->sendAlert("Error",$mid,0,$subject,$msg,0);
}
$url=$this->makeUrl($pg);
$this->sendRedirect($url, 1);
exit;
}
break;

default :
return; // stop here
break;
}
< ‌ index ‌ >