Advertisement:

Author Topic: Disable censored words in thread title?  (Read 681 times)

Offline brettuk

  • Semi-Newbie
  • *
  • Posts: 86
Disable censored words in thread title?
« on: May 28, 2018, 11:50:23 AM »
Hi,

Is there any way I can exclude the thread title from being affected by censored words?

I am currently using the feature to apply affiliate links when a certain word is mentioned, however, when the censored word is used in the title, it attempts to apply a link, which renders as BBC code.

Thanks!
Currently Working On A Love, Dating, Marriage & Relationship Forum: https://letschatlove.com

Additionally, SERP Audit which is an SEO audit compilation service.

Offline GigaWatt

  • Support Specialist
  • Sr. Member
  • *
  • Posts: 869
  • Gender: Male
    • Macedonian electronics forum
Re: Disable censored words in thread title?
« Reply #1 on: May 28, 2018, 05:28:08 PM »
It's probably in Post.php and in Load.php.

I just tried searching for censorText in Post.php, it shows up in a lot of places, you'd have to do a lot of manual editing. In Load.php it's present only in 2 or 3 places. That should be easily fixable.

In any case, make a backup of both files before you do any editing.

Code: (Post.php) [Select]
// Get the stuff ready for the form.
$form_subject = $row['subject'];
$form_message = un_preparsecode($row['body']);
censorText($form_message);
censorText($form_subject);

Code: (Post.php) [Select]
// Censor the message and subject.
censorText($form_message);
censorText($form_subject);

Code: (Post.php) [Select]
// Censor the subject.
censorText($form_subject);

Code: (Post.php) [Select]
// Get the subject of the topic we're about to announce.
$request = $smcFunc['db_query']('', '
SELECT m.subject
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
WHERE t.id_topic = {int:current_topic}',
array(
'current_topic' => $topic,
)
);
list ($context['topic_subject']) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);

censorText($context['announce_topic']['subject']);

Code: (Post.php) [Select]
// Get the topic subject and censor it.
$request = $smcFunc['db_query']('', '
SELECT m.id_msg, m.subject, m.body
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
WHERE t.id_topic = {int:current_topic}',
array(
'current_topic' => $topic,
)
);
list ($id_msg, $context['topic_subject'], $message) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);

censorText($context['topic_subject']);
censorText($message);

Code: (Post.php) [Select]
// Censor the subject and body...
censorText($topicData[$key]['subject']);
censorText($topicData[$key]['body']);

Code: (Post.php) [Select]
// Want to modify a single message by double clicking it?
if (isset($_REQUEST['modify']))
{
censorText($row['subject']);
"This is really a generic concept about human thinking - when faced with large tasks we're naturally inclined to try to break them down into a bunch of smaller tasks that together make up the whole."

"A 500 error loosely translates to the webserver saying, "WTF?"..."

Online Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 56,473
  • Gender: Male
    • Kindred-999 on GitHub
Re: Disable censored words in thread title?
« Reply #2 on: May 28, 2018, 07:30:57 PM »
This is one of the problems wth misusing the word censor....
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

Offline brettuk

  • Semi-Newbie
  • *
  • Posts: 86
Re: Disable censored words in thread title?
« Reply #3 on: May 30, 2018, 04:12:51 PM »
Thanks Giga, I appreciate your help.

All is working, however, the censored functionality seems to still be taking effect in the topic list view section.

e.g at this relationship advice for men board, that we have, we have a subject named 'Male [urlx=https://bit.ly/2kv8dg8]perfume[/url]'.

perfume is a censored word that turns into a link.

Any ideas?

Thanks so much for your help.
Currently Working On A Love, Dating, Marriage & Relationship Forum: https://letschatlove.com

Additionally, SERP Audit which is an SEO audit compilation service.

Offline GigaWatt

  • Support Specialist
  • Sr. Member
  • *
  • Posts: 869
  • Gender: Male
    • Macedonian electronics forum
Re: Disable censored words in thread title?
« Reply #4 on: May 30, 2018, 07:50:09 PM »
I didn't mention this, but I didn't list all of the paces in which censorText appeared in Post.php. There were too many, I just posted code snippets until I lost my nerve :D.

EDIT: censorText also appears in Display.php... luckily, only 4 times O:).

Code: [Select]
// Censor the title...
censorText($topicinfo['subject']);
$context['page_title'] = $topicinfo['subject'];

Code: [Select]
// Get all the options, and calculate the total votes.
$request = $smcFunc['db_query']('', '
SELECT pc.id_choice, pc.label, pc.votes, IFNULL(lp.id_choice, -1) AS voted_this
FROM {db_prefix}poll_choices AS pc
LEFT JOIN {db_prefix}log_polls AS lp ON (lp.id_choice = pc.id_choice AND lp.id_poll = {int:id_poll} AND lp.id_member = {int:current_member} AND lp.id_member != {int:not_guest})
WHERE pc.id_poll = {int:id_poll}',
array(
'current_member' => $user_info['id'],
'id_poll' => $topicinfo['id_poll'],
'not_guest' => 0,
)
);
$pollOptions = array();
$realtotal = 0;
$pollinfo['has_voted'] = false;
while ($row = $smcFunc['db_fetch_assoc']($request))
{
censorText($row['label']);
$pollOptions[$row['id_choice']] = $row;
$realtotal += $row['votes'];
$pollinfo['has_voted'] |= $row['voted_this'] != -1;
}
$smcFunc['db_free_result']($request);

Code: [Select]
// Do the censor thang.
censorText($message['body']);
censorText($message['subject']);
"This is really a generic concept about human thinking - when faced with large tasks we're naturally inclined to try to break them down into a bunch of smaller tasks that together make up the whole."

"A 500 error loosely translates to the webserver saying, "WTF?"..."

Offline brettuk

  • Semi-Newbie
  • *
  • Posts: 86
Re: Disable censored words in thread title?
« Reply #5 on: May 31, 2018, 03:34:41 PM »
Thanks for your help Giga,  I appreciate it, however, it's still not working as intended (the thread title in topic view).

Are there any other files that need to be edited that you can think of?
Currently Working On A Love, Dating, Marriage & Relationship Forum: https://letschatlove.com

Additionally, SERP Audit which is an SEO audit compilation service.

Offline GigaWatt

  • Support Specialist
  • Sr. Member
  • *
  • Posts: 869
  • Gender: Male
    • Macedonian electronics forum
Re: Disable censored words in thread title?
« Reply #6 on: June 01, 2018, 08:57:40 AM »
Did you find and edit all occurrences of censorText in Post.php? Because, as I previously noted, I didn't list all of them.

As for the other question, MessageIndex.php also contains instances of censorText.

Code: (MessageIndex.php) [Select]
// Begin 'printing' the message index for current board.
while ($row = $smcFunc['db_fetch_assoc']($result))
{
if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0')
continue;

if (!$pre_query)
$topic_ids[] = $row['id_topic'];

if (!empty($settings['message_index_preview']))
{
// Limit them to 128 characters - do this FIRST because it's a lot of wasted censoring otherwise.
$row['first_body'] = strip_tags(strtr(parse_bbc($row['first_body'], $row['first_smileys'], $row['id_first_msg']), array('<br />' => '')));
if ($smcFunc['strlen']($row['first_body']) > 128)
$row['first_body'] = $smcFunc['substr']($row['first_body'], 0, 128) . '...';
$row['last_body'] = strip_tags(strtr(parse_bbc($row['last_body'], $row['last_smileys'], $row['id_last_msg']), array('<br />' => '')));
if ($smcFunc['strlen']($row['last_body']) > 128)
$row['last_body'] = $smcFunc['substr']($row['last_body'], 0, 128) . '...';

// Censor the subject and message preview.
censorText($row['first_subject']);
censorText($row['first_body']);

// Don't censor them twice!
if ($row['id_first_msg'] == $row['id_last_msg'])
{
$row['last_subject'] = $row['first_subject'];
$row['last_body'] = $row['first_body'];
}
else
{
censorText($row['last_subject']);
censorText($row['last_body']);
}
}
else
{
$row['first_body'] = '';
$row['last_body'] = '';
censorText($row['first_subject']);

if ($row['id_first_msg'] == $row['id_last_msg'])
$row['last_subject'] = $row['first_subject'];
else
censorText($row['last_subject']);
}

So does News.php.

Code: (News.php) [Select]
// Limit the length of the message, if the option is set.
if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br />', "\n", $row['body'])) > $modSettings['xmlnews_maxlen'])
$row['body'] = strtr($smcFunc['substr'](str_replace('<br />', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br />')) . '...';

$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);

censorText($row['body']);
censorText($row['subject']);

PersonalMessage.php is also full of censorText instances, so is Poll.php, Printpage.php, Recent.php, Search.php, Stats.php, Subs-BoardIndex.php, Subs-Recent.php, Subs-Post.php and Who.php... i think I got 'em all :D.

Although, you probably don't have to comment out or alter the censorText function in all of them.
"This is really a generic concept about human thinking - when faced with large tasks we're naturally inclined to try to break them down into a bunch of smaller tasks that together make up the whole."

"A 500 error loosely translates to the webserver saying, "WTF?"..."

Offline Illori

  • Project Manager
  • SMF Master
  • *
  • Posts: 49,436
Re: Disable censored words in thread title?
« Reply #7 on: June 01, 2018, 09:15:12 AM »
This is one of the problems wth misusing the word censor....

as kindred said there has to be other ways to do this, did you check the mod site? this is not really the proper way to use the censor.

Offline GigaWatt

  • Support Specialist
  • Sr. Member
  • *
  • Posts: 869
  • Gender: Male
    • Macedonian electronics forum
Re: Disable censored words in thread title?
« Reply #8 on: June 01, 2018, 10:03:44 AM »
I agree, at first I thought it might require one or two edits in a couple of files, but as I started digging deeper into the problem, this is just... not the way to go.

It was kind of interesting just to see how many times censorText appeared and in which files :).

In any case, I'm with Illori and Kindred on this one, this is just too much work and too many things can (and probably will) go wrong.
"This is really a generic concept about human thinking - when faced with large tasks we're naturally inclined to try to break them down into a bunch of smaller tasks that together make up the whole."

"A 500 error loosely translates to the webserver saying, "WTF?"..."

Offline brettuk

  • Semi-Newbie
  • *
  • Posts: 86
Re: Disable censored words in thread title?
« Reply #9 on: June 03, 2018, 04:13:10 PM »
Thanks Giga, I appreciate it a lot - I have done all those.

It seems to have taken effect in more areas which is good, however, it's still showing on the damn topic list!

So, here, in this view.

If anyone else knows, or know the file that's normally used to edit this view, let me know.

In the meantime, I'll keep digging ...  :(
Currently Working On A Love, Dating, Marriage & Relationship Forum: https://letschatlove.com

Additionally, SERP Audit which is an SEO audit compilation service.

Offline GigaWatt

  • Support Specialist
  • Sr. Member
  • *
  • Posts: 869
  • Gender: Male
    • Macedonian electronics forum
Re: Disable censored words in thread title?
« Reply #10 on: June 03, 2018, 05:14:03 PM »
I think you should drop the edits thing. There's too much editing, something is bound to go wrong :S... maybe hooks is the way to go here, but that would require a mod.
"This is really a generic concept about human thinking - when faced with large tasks we're naturally inclined to try to break them down into a bunch of smaller tasks that together make up the whole."

"A 500 error loosely translates to the webserver saying, "WTF?"..."

Offline brettuk

  • Semi-Newbie
  • *
  • Posts: 86
Re: Disable censored words in thread title?
« Reply #11 on: June 04, 2018, 07:05:04 AM »
Yep!

There just doesn't seem like there's another candidate at the moment though, when a mod is concerned.

 >:(
Currently Working On A Love, Dating, Marriage & Relationship Forum: https://letschatlove.com

Additionally, SERP Audit which is an SEO audit compilation service.

Offline GigaWatt

  • Support Specialist
  • Sr. Member
  • *
  • Posts: 869
  • Gender: Male
    • Macedonian electronics forum
Re: Disable censored words in thread title?
« Reply #12 on: June 04, 2018, 08:39:33 AM »
Request a mod that uses hooks to change certain words when loading Display.php. This might even solve the problem with number of replaced words in a thread or a board (if number of replaced words >= a certain number, don't replace them any more).

I know how it should work in theory... I just don't know how to do it in PHP :D.
"This is really a generic concept about human thinking - when faced with large tasks we're naturally inclined to try to break them down into a bunch of smaller tasks that together make up the whole."

"A 500 error loosely translates to the webserver saying, "WTF?"..."

Offline brettuk

  • Semi-Newbie
  • *
  • Posts: 86
Re: Disable censored words in thread title?
« Reply #13 on: June 06, 2018, 11:44:57 AM »
Request a mod that uses hooks to change certain words when loading Display.php. This might even solve the problem with number of replaced words in a thread or a board (if number of replaced words >= a certain number, don't replace them any more).

I know how it should work in theory... I just don't know how to do it in PHP :D.

I'll get on it, I have a dev in mind that may be able to help.

Thanks for your help though Giga, I appreciate it.

See you around.  ;)
Currently Working On A Love, Dating, Marriage & Relationship Forum: https://letschatlove.com

Additionally, SERP Audit which is an SEO audit compilation service.

Offline GigaWatt

  • Support Specialist
  • Sr. Member
  • *
  • Posts: 869
  • Gender: Male
    • Macedonian electronics forum
Re: Disable censored words in thread title?
« Reply #14 on: June 06, 2018, 08:55:51 PM »
No problem ;).

Can this be marked as solved?
"This is really a generic concept about human thinking - when faced with large tasks we're naturally inclined to try to break them down into a bunch of smaller tasks that together make up the whole."

"A 500 error loosely translates to the webserver saying, "WTF?"..."