We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Custom word filter for Discussion Forum module

Development and Programming

Muiris's avatar
Muiris
7 posts
14 years ago
Muiris's avatar Muiris

Hi,

I’m having an issue adding some PHP to the Discussion Forum’s template files. I know EE has a site-wide word censoring feature but ideally we’d limit it to just the forums (there’s a reason). I’ve found code that works fine on a non-EE test page but trying to add it to the thread_rows function produces errors.

Depending on how I’ve tried to integrate it, it’s resulted in the dreaded white screen, blank posts in a perfect page otherwise (i.e. the {body} variable isn’t called correctly) or relatively normal (but unfiltered) posts with some of the PHP printed out after the post body.

The relevant part of the theme_threads.php template is (note: only the {body} section needs to be filtered):

function thread_rows()
{
return <<< EOF

<--- Code for ignore list, member info, [Report] links, etc. --->

<td class="tableCellOne" valign="top" colspan="2">
    <div class="post">
    {body}
    </div>
    {if edited}<div class="edited"><em>[ {lang:edited}: {edit_date format="%D %j %F %Y at %H:%i"} {lang:by} <a href="http://{path:edit_author_profile}">{edit_author}</a> ]</em></div>{/if}
    {if attachments}
    {include:post_attachments}
    {/if}
    {if signature}
    {include:signature}
    {/if}
</td>

<--- Code for edit butons, mod buttons, etc. --->

EOF;
}

The code, taken from http://www.codingforums.com/showthread.php?t=135849 is:

include ("filter.php"); //NOTE: This call works fine in a non-EE test page.
$str = <<<EOF
<--- Whatever you need filtered goes here so I've tried a few ways of getting {body} in here --->
EOF;
// bad words:
$replace_str = "whatever you want to replace the bad words with";
$bad_words = array('word 1 to replace','word 2 to replace');
print ReplaceBadWords($str, $bad_words, $replace_str);

I’ve made changes to the templates relatively comfortably before but haven’t quite been able to figure this one out alone. Problem would seem likely to be the conflicting EOF calls though? Even a way to include the filter in the core files where {body} is defined would be an option as we won’t be upgrading the forum install. Any help appreciated…

       
John Henry Donovan's avatar
John Henry Donovan
12,339 posts
14 years ago
John Henry Donovan's avatar John Henry Donovan

Hi Muiris,

Moving to development forum as more appropriate there

Have you turned on Error Reporting?

Try updating the following to include a full server path to filter.php

include ("filter.php");

Note you could also create an extension and maybe use the forum_submission_page hook

       
Muiris's avatar
Muiris
7 posts
14 years ago
Muiris's avatar Muiris

Thanks for the suggestion John Henry but the path change had no effect. It seems to be the call to {body} that disrupts the filter code as the PHP before {body} never gets printed out in the forums but the code after it sometimes is.

It’s actually a relatively short-term feature that we’d need so an extension would probably be overkill. That’s even if I fancied my chances at building it, which I’m not sure I would 😊

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.