HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Please upgrade here. These earlier versions are no longer being updated and have security issues.

Extend plugin to filter comments not just discussions

This discussion is related to the Civil Tongue addon.
edited January 2011 in Vanilla 2.0 - 2.8
A nice little plugin. If you edit class.civiltongue.plugin.php and add the following after the DiscussionModel_BeforeSaveDiscussion_Handler function (line 49).

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.

Comments

  • @scythah Thanks, i hadn't really ever got round to finishing the plugin. It now works for discussion title, body and comments as well. Future plan would to be having some options of where it should filter and implement it for all sections including activity and anywhere else it may be of use, so the admin can turn on filtering as they see fit.
  • @garymardell My pleasure. Very quick update by you too :)
  • @scythah I'm a student, don't have much better to do. :)
  • Good work guys. I've been enjoying populating the word list this week :)
  • Hi, Maybe I miss something but this plugin does not seem to work on Version 2.0.17.5, any chance of an update :-)))))

    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 :-)

  • I just google good forum framework and found vanilla 2 hours ago, I have been tried this plugin, but it is not working properly in my env. (vanilla 2.0.17.9 - release march 22). so I just create little enhancement:
    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 :)
Sign In or Register to comment.