-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathCensoring.php
More file actions
104 lines (79 loc) · 3.39 KB
/
Censoring.php
File metadata and controls
104 lines (79 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
/**
* Copyright (C) 2015-2019 FeatherBB
* based on code by (C) 2008-2015 FluxBB
* and Rickard Andersson (C) 2002-2008 PunBB
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
*/
namespace FeatherBB\Model\Admin;
use FeatherBB\Core\Database as DB;
use FeatherBB\Core\Error;
use FeatherBB\Core\Interfaces\Cache as CacheInterface;
use FeatherBB\Core\Interfaces\Hooks;
use FeatherBB\Core\Interfaces\Input;
use FeatherBB\Core\Interfaces\Router;
use FeatherBB\Core\Utils;
use FeatherBB\Model\Cache;
class Censoring
{
public function addWord()
{
$searchFor = Utils::trim(Input::post('new_search_for'));
$replaceWith = Utils::trim(Input::post('new_replace_with'));
if ($searchFor == '') {
throw new Error(__('Must enter word message'), 400);
}
$setSearchWord = ['search_for' => $searchFor,
'replace_with' => $replaceWith];
$setSearchWord = Hooks::fire('model.admin.censoring.add_censoring_word_data', $setSearchWord);
$result = DB::table('censoring')
->create()
->set($setSearchWord)
->save();
// Regenerate the censoring cache
CacheInterface::store('search_for', Cache::getCensoring('search_for'));
CacheInterface::store('replace_with', Cache::getCensoring('replace_with'));
return Router::redirect(Router::pathFor('adminCensoring'), __('Word added redirect'));
}
public function updateWord()
{
$id = intval(key(Input::post('update')));
$searchFor = Utils::trim(Input::post('search_for')[$id]);
$replaceWith = Utils::trim(Input::post('replace_with')[$id]);
if ($searchFor == '') {
throw new Error(__('Must enter word message'), 400);
}
$setSearchWord = ['search_for' => $searchFor,
'replace_with' => $replaceWith];
$setSearchWord = Hooks::fire('model.admin.censoring.update_censoring_word_start', $setSearchWord);
$result = DB::table('censoring')
->findOne($id)
->set($setSearchWord)
->save();
// Regenerate the censoring cache
CacheInterface::store('search_for', Cache::getCensoring('search_for'));
CacheInterface::store('replace_with', Cache::getCensoring('replace_with'));
return Router::redirect(Router::pathFor('adminCensoring'), __('Word updated redirect'));
}
public function removeWord()
{
$id = intval(key(Input::post('remove')));
$id = Hooks::fire('model.admin.censoring.remove_censoring_word_start', $id);
$result = DB::table('censoring')->findOne($id);
$result = Hooks::fireDB('model.admin.censoring.remove_censoring_word', $result);
$result = $result->delete();
// Regenerate the censoring cache
CacheInterface::store('search_for', Cache::getCensoring('search_for'));
CacheInterface::store('replace_with', Cache::getCensoring('replace_with'));
return Router::redirect(Router::pathFor('adminCensoring'), __('Word removed redirect'));
}
public function getWords()
{
$wordData = [];
$wordData = DB::table('censoring')
->orderByAsc('id');
$wordData = Hooks::fireDB('model.admin.censoring.update_censoring_word_query', $wordData);
$wordData = $wordData->findArray();
return $wordData;
}
}