mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-21 05:43:55 -07:00
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:
parent
126c75cd57
commit
5971379b6c
5 changed files with 35 additions and 7 deletions
|
@ -16,6 +16,7 @@
|
||||||
- Some improvements for integrity checker [\#1501](https://github.com/torrentpier/torrentpier/pull/1501) ([belomaxorka](https://github.com/belomaxorka))
|
- 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 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))
|
- 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))
|
- 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))
|
- New Crowdin updates [\#1504](https://github.com/torrentpier/torrentpier/pull/1504), [\#1513](https://github.com/torrentpier/torrentpier/pull/1513) ([Exileum](https://github.com/Exileum))
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ if ($mode != '') {
|
||||||
bb_die('Could not insert data into words table');
|
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>');
|
$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);
|
bb_die($message);
|
||||||
|
@ -94,7 +94,7 @@ if ($mode != '') {
|
||||||
bb_die('Could not remove data from words table');
|
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>'));
|
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 {
|
} else {
|
||||||
|
|
21
library/includes/datastore/build_censor.php
Normal file
21
library/includes/datastore/build_censor.php
Normal 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);
|
|
@ -34,18 +34,23 @@ class Censor
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
global $bb_cfg;
|
global $bb_cfg, $datastore;
|
||||||
|
|
||||||
if (!$bb_cfg['use_word_censor']) {
|
if (!$bb_cfg['use_word_censor']) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$words = CACHE('bb_cache')->get('censored')) {
|
// Get censored words
|
||||||
$words = DB()->fetch_rowset("SELECT word, replacement FROM " . BB_WORDS);
|
if (!$censoredWords = $datastore->get('censor')) {
|
||||||
CACHE('bb_cache')->set('censored', $words, 7200);
|
$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->words[] = '#(?<![\p{Nd}\p{L}_])(' . str_replace('\*', '[\p{Nd}\p{L}_]*?', preg_quote($word['word'], '#')) . ')(?![\p{Nd}\p{L}_])#iu';
|
||||||
$this->replacements[] = $word['replacement'];
|
$this->replacements[] = $word['replacement'];
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@ class Common
|
||||||
*/
|
*/
|
||||||
public array $known_items = [
|
public array $known_items = [
|
||||||
'cat_forums' => 'build_cat_forums.php',
|
'cat_forums' => 'build_cat_forums.php',
|
||||||
|
'censor' => 'build_censor.php',
|
||||||
'check_updates' => 'build_check_updates.php',
|
'check_updates' => 'build_check_updates.php',
|
||||||
'files_integrity' => 'build_files_integrity.php',
|
'files_integrity' => 'build_files_integrity.php',
|
||||||
'jumpbox' => 'build_cat_forums.php',
|
'jumpbox' => 'build_cat_forums.php',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue