Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Extend plugin to filter comments not just discussions
A nice little plugin. If you edit class.civiltongue.plugin.php and add the following after the DiscussionModel_BeforeSaveDiscussion_Handler function (line 49).
The plugin will filter on comments as well as the original discussions.
public function CommentModel_BeforeSaveComment_Handler(&$Sender) {
$FormPostValues = $Sender->EventArguments['FormPostValues'];
// Get config
$Words = C('Plugins.CivilTongue.Words', null);
$Replacement = C('Plugins.CivilTongue.Replacement', '');
if($Words !== null) {
$ExplodedWords = explode(';', $Words);
$Patterns = array();
foreach($ExplodedWords as $Word) {
$Patterns[] = '/\b' . preg_quote(ltrim(rtrim($Word))) . '\b/is';
}
$FormPostValues['Body'] = preg_replace($Patterns, $Replacement, $FormPostValues['Body']);
$Sender->EventArguments['FormPostValues'] = $FormPostValues;
}
}
The plugin will filter on comments as well as the original discussions.
1
Comments
Also a nice additional feature would be able to show an image so we could have a filter word like 'whoopise' and when you hover your mouse over link it shows a image of our choice (if you like per word, or just the same image for all words).
Just some ideas :-)
private function replaceUnAllowedWords($msg,$replacement) {
$Words = C ( 'Plugins.CivilTongue.Words', null );
$Patterns = array ();
if ($Words !== null) {
$ss=split(";", $Words);
for($i=0;$iEventArguments ['FormPostValues'];
$Replacement = C ( 'Plugins.CivilTongue.Replacement', '' );
$Patterns = $this->GetPatterns ();
if (count ( $Patterns ) > 0) {
// $FormPostValues ['Body'] = preg_replace ( $Patterns, $Replacement, $FormPostValues ['Body'] );
$FormPostValues ['Body']=$this->replaceUnAllowedWords($FormPostValues['Body'], $Replacement);
$Sender->EventArguments ['FormPostValues'] = $FormPostValues;
}
}
public function DiscussionModel_BeforeSaveDiscussion_Handler(&$Sender) {
$FormPostValues = $Sender->EventArguments ['FormPostValues'];
$Replacement = C ( 'Plugins.CivilTongue.Replacement', '' );
$Patterns = $this->GetPatterns ();
if (count ( $Patterns ) > 0) {
// $FormPostValues ['Name'] = preg_replace ( $Patterns, $Replacement, $FormPostValues ['Name'] );
// $FormPostValues ['Body'] = preg_replace ( $Patterns, $Replacement, $FormPostValues ['Body'] );
$FormPostValues ['Name'] = $this->replaceUnAllowedWords($FormPostValues['Name'], $Replacement);
$FormPostValues ['Body'] = $this->replaceUnAllowedWords($FormPostValues['Body'], $Replacement);
$Sender->EventArguments ['FormPostValues'] = $FormPostValues;
}
}
cheers