Word censor code optimization (#1537)

* Word censor code optimization

* Update CHANGELOG.md

* Updated

* Updated

* Update build_censor.php

* Update admin_words.php
This commit is contained in:
Roman Kelesidis 2024-07-13 13:00:46 +07:00 committed by GitHub
commit 5971379b6c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 35 additions and 7 deletions

View file

@ -16,6 +16,7 @@
- Some improvements for integrity checker [\#1501](https://github.com/torrentpier/torrentpier/pull/1501) ([belomaxorka](https://github.com/belomaxorka))
- Hide in topic: Added country hiding [\#1535](https://github.com/torrentpier/torrentpier/pull/1535) ([belomaxorka](https://github.com/belomaxorka))
- Hide vote button in topic for guests [\#1507](https://github.com/torrentpier/torrentpier/pull/1507) ([belomaxorka](https://github.com/belomaxorka))
- Word censor code optimization [\#1537](https://github.com/torrentpier/torrentpier/pull/1537) ([belomaxorka](https://github.com/belomaxorka))
- Minor improvements [\#1502](https://github.com/torrentpier/torrentpier/pull/1502), [\#1506](https://github.com/torrentpier/torrentpier/pull/1506), [\#1509](https://github.com/torrentpier/torrentpier/pull/1509), [\#1511](https://github.com/torrentpier/torrentpier/pull/1511), [\#1515](https://github.com/torrentpier/torrentpier/pull/1515), [\#1516](https://github.com/torrentpier/torrentpier/pull/1516), [\#1517](https://github.com/torrentpier/torrentpier/pull/1517), [\#1519](https://github.com/torrentpier/torrentpier/pull/1519), [\#1523](https://github.com/torrentpier/torrentpier/pull/1523), [\#1525](https://github.com/torrentpier/torrentpier/pull/1525), [\#1530](https://github.com/torrentpier/torrentpier/pull/1530), [\#1532](https://github.com/torrentpier/torrentpier/pull/1532), [\#1536](https://github.com/torrentpier/torrentpier/pull/1536) ([belomaxorka](https://github.com/belomaxorka))
- New Crowdin updates [\#1504](https://github.com/torrentpier/torrentpier/pull/1504), [\#1513](https://github.com/torrentpier/torrentpier/pull/1513) ([Exileum](https://github.com/Exileum))

View file

@ -80,7 +80,7 @@ if ($mode != '') {
bb_die('Could not insert data into words table');
}
CACHE('bb_cache')->rm('censored');
$datastore->update('censor');
$message .= '<br /><br />' . sprintf($lang['CLICK_RETURN_WORDADMIN'], '<a href="admin_words.php">', '</a>') . '<br /><br />' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '<a href="index.php?pane=right">', '</a>');
bb_die($message);
@ -94,7 +94,7 @@ if ($mode != '') {
bb_die('Could not remove data from words table');
}
CACHE('bb_cache')->rm('censored');
$datastore->update('censor');
bb_die($lang['WORD_REMOVED'] . '<br /><br />' . sprintf($lang['CLICK_RETURN_WORDADMIN'], '<a href="admin_words.php">', '</a>') . '<br /><br />' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '<a href="index.php?pane=right">', '</a>'));
} else {

View file

@ -0,0 +1,21 @@
<?php
/**
* TorrentPier Bull-powered BitTorrent tracker engine
*
* @copyright Copyright (c) 2005-2024 TorrentPier (https://torrentpier.com)
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
*/
if (!defined('BB_ROOT')) {
die(basename(__FILE__));
}
$sql = "SELECT * FROM " . BB_WORDS;
$words = [];
foreach (DB()->fetch_rowset($sql) as $row) {
$words[$row['word_id']] = $row;
}
$this->store('censor', $words);

View file

@ -34,18 +34,23 @@ class Censor
*/
public function __construct()
{
global $bb_cfg;
global $bb_cfg, $datastore;
if (!$bb_cfg['use_word_censor']) {
return;
}
if (!$words = CACHE('bb_cache')->get('censored')) {
$words = DB()->fetch_rowset("SELECT word, replacement FROM " . BB_WORDS);
CACHE('bb_cache')->set('censored', $words, 7200);
// Get censored words
if (!$censoredWords = $datastore->get('censor')) {
$datastore->update('censor');
$censoredWords = $datastore->get('censor');
}
foreach ($words as $word) {
if (isset($censoredWords['no_words'])) {
return;
}
foreach ($censoredWords as $word) {
$this->words[] = '#(?<![\p{Nd}\p{L}_])(' . str_replace('\*', '[\p{Nd}\p{L}_]*?', preg_quote($word['word'], '#')) . ')(?![\p{Nd}\p{L}_])#iu';
$this->replacements[] = $word['replacement'];
}

View file

@ -39,6 +39,7 @@ class Common
*/
public array $known_items = [
'cat_forums' => 'build_cat_forums.php',
'censor' => 'build_censor.php',
'check_updates' => 'build_check_updates.php',
'files_integrity' => 'build_files_integrity.php',
'jumpbox' => 'build_cat_forums.php',