Browse Source

Update censorship usage

Visman 5 years ago
parent
commit
e26a286818

+ 1 - 1
app/Models/Page.php

@@ -396,7 +396,7 @@ abstract class Page extends Model
                         $name = $crumb->forum_name;
                     // для темы
                     } elseif (isset($crumb->subject)) {
-                        $name = \ForkBB\cens($crumb->subject);
+                        $name = $crumb->censSubject;
                     // все остальное
                     } else {
                         $name = 'no name';

+ 1 - 1
app/Models/Pages/Admin/Reports.php

@@ -100,7 +100,7 @@ class Reports extends Admin
                 $forum = $topic->parent;
                 $cur['fields']['post' . $report->id] = [
                     'type'    => 'str',
-                    'value'   => __('Post #%s ', $post->id, $post->link, $topic->subject, $topic->link, $forum->forum_name, $forum->link),
+                    'value'   => __('Post #%s ', $post->id, $post->link, $topic->censSubject, $topic->link, $forum->forum_name, $forum->link),
                     'html'    => true,
                 ];
             } else {

+ 1 - 1
app/Models/Pages/Delete.php

@@ -105,7 +105,7 @@ class Delete extends Page
                     'info' => [
                         'info1' => [
                             'type'    => '', //????
-                            'value'   => __('Topic') . ' «' . \ForkBB\cens($post->parent->subject) . '»',
+                            'value'   => __('Topic') . ' «' . $post->parent->censSubject . '»',
                         ],
                         'info2' => [
                             'type'    => '', //????

+ 3 - 3
app/Models/Pages/Moderate.php

@@ -252,7 +252,7 @@ class Moderate extends Page
                 'Topic',
                 [
                     'id'   => $this->curTopic->id,
-                    'name' => $this->curTopic->subject,
+                    'name' => $this->curTopic->censSubject,
                     'page' => $page,
                 ]
             );
@@ -559,7 +559,7 @@ class Moderate extends Page
         $headers = [];
         foreach ($objects as $object) {
             if ($object instanceof Topic) {
-                $headers[] = __('Topic «%s»', \ForkBB\cens(($object->subject)));
+                $headers[] = __('Topic «%s»', $object->censSubject);
             } else {
                 $headers[] = __('Post «%1$s by %2$s»', \ForkBB\dt($object->posted), $object->poster);
             }
@@ -578,7 +578,7 @@ class Moderate extends Page
         if ($this->firstTopic instanceof Topic) {
             $form['sets']['info']['info']['info2'] = [
                 'type'    => '', //????
-                'value'   => __('All posts will be posted in the «%s» topic', $this->firstTopic->subject),
+                'value'   => __('All posts will be posted in the «%s» topic', $this->firstTopic->censSubject),
 //                'html'    => true,
             ];
         }

+ 2 - 2
app/Models/Pages/PostValidatorTrait.php

@@ -19,7 +19,7 @@ trait PostValidatorTrait
     public function vCheckSubject(Validator $v, $subject, $attr, $executive)
     {
         // после цензуры заголовок темы путой
-        if ('' == \ForkBB\cens($subject)) {
+        if ('' == $this->c->censorship->censor($subject)) {
             $v->addError('No subject after censoring');
         // заголовок темы только заглавными буквами
         } elseif (
@@ -45,7 +45,7 @@ trait PostValidatorTrait
     public function vCheckMessage(Validator $v, $message, $attr, $executive)
     {
         // после цензуры текст сообщения пустой
-        if ('' == \ForkBB\cens($message)) {
+        if ('' == $this->c->censorship->censor($message)) {
             $v->addError('No message after censoring');
         // текст сообщения только заглавными буквами
         } elseif (

+ 4 - 4
app/Models/Pages/Profile/Edit.php

@@ -165,7 +165,7 @@ class Edit extends Profile
     {
         if ('' != $signature) {
             // после цензуры текст сообщения пустой
-            if ('' == \ForkBB\cens($signature)) {
+            if ('' == $this->c->censorship->censor($signature)) {
                 $v->addError('No signature after censoring');
             // количество строк
             } elseif (\substr_count($signature, "\n") >= $this->c->config->p_sig_lines) {
@@ -399,7 +399,7 @@ class Edit extends Profile
                 'class'   => 'pline',
                 'type'    => 'str',
                 'caption' => __('Email info'),
-                'value'   => \ForkBB\cens($this->curUser->email),
+                'value'   => $this->c->censorship->censor($this->curUser->email),
             ];
         }
         if ($this->rules->editEmail) {
@@ -443,8 +443,8 @@ class Edit extends Profile
                 'class'   => 'pline',
                 'type'    => 'link',
                 'caption' => __('Website'),
-                'value'   => \ForkBB\cens($this->curUser->url),
-                'href'    => \ForkBB\cens($this->curUser->url),
+                'value'   => $this->c->censorship->censor($this->curUser->url),
+                'href'    => $this->c->censorship->censor($this->curUser->url),
             ];
         }
         $form['sets']['contacts'] = [

+ 6 - 6
app/Models/Pages/Profile/View.php

@@ -108,7 +108,7 @@ class View extends Profile
                 'class'   => 'pline',
                 'type'    => 'str',
                 'caption' => __('Realname'),
-                'value'   => \ForkBB\cens($this->curUser->realname),
+                'value'   => $this->c->censorship->censor($this->curUser->realname),
             ];
         }
         $genders = [
@@ -132,7 +132,7 @@ class View extends Profile
                 'class'   => 'pline',
                 'type'    => 'str',
                 'caption' => __('Location'),
-                'value'   => \ForkBB\cens($this->curUser->location),
+                'value'   => $this->c->censorship->censor($this->curUser->location),
             ];
         }
         if (! empty($fields)) {
@@ -150,7 +150,7 @@ class View extends Profile
                 'class'   => 'pline',
                 'type'    => 2 === $this->curUser->email_setting ? 'str' : 'link',
                 'caption' => __('Email info'),
-                'value'   => \ForkBB\cens($this->curUser->email),
+                'value'   => $this->c->censorship->censor($this->curUser->email),
                 'href'    => 'mailto:' . $this->curUser->email,
             ];
         }
@@ -160,7 +160,7 @@ class View extends Profile
                     'class'   => 'pline',
                     'type'    => 'link',
                     'caption' => __('Email info'),
-                    'value'   => \ForkBB\cens($this->curUser->email),
+                    'value'   => $this->c->censorship->censor($this->curUser->email),
                     'href'    => 'mailto:' . $this->curUser->email,
                 ];
             } elseif (1 === $this->curUser->email_setting) {
@@ -187,8 +187,8 @@ class View extends Profile
                 'class'   => 'pline',
                 'type'    => 'link',
                 'caption' => __('Website'),
-                'value'   => \ForkBB\cens($this->curUser->url),
-                'href'    => \ForkBB\cens($this->curUser->url),
+                'value'   => $this->c->censorship->censor($this->curUser->url),
+                'href'    => $this->c->censorship->censor($this->curUser->url),
             ];
         }
         if (! empty($fields)) {

+ 6 - 6
app/Models/Pages/Report.php

@@ -162,17 +162,17 @@ class Report extends Page
     protected function sendReport(ReportModel $report): bool
     {
         $tplData = [
-            'fMailer' => __('Mailer', $this->c->config->o_board_title),
-            'username' => $report->author->username,
-            'postLink' => $this->c->Router->link(
+            'fMailer'      => __('Mailer', $this->c->config->o_board_title),
+            'username'     => $report->author->username,
+            'postLink'     => $this->c->Router->link(
                 'ViewPost',
                 [
                     'id' => $report->post->id,
                 ]
             ),
-            'reason' => $report->message,
-            'forumId' => $report->post->parent->parent->id,
-            'topicSubject' => $report->post->parent->subject,
+            'reason'       => $report->message,
+            'forumId'      => $report->post->parent->parent->id,
+            'topicSubject' => $report->post->parent->censSubject,
         ];
 
         return $this->c->Mail

+ 1 - 1
app/Models/Pages/Topic.php

@@ -152,7 +152,7 @@ class Topic extends Page
             'Topic',
             [
                 'id'   => $topic->id,
-                'name' => \ForkBB\cens($topic->subject),
+                'name' => $topic->censSubject,
                 'page' => $topic->page
             ]
         );

+ 1 - 1
app/Models/Post/Move.php

@@ -25,7 +25,7 @@ class Move extends Action
             $topics[$post->topic_id] = $post->parent;
 
             if ($useFrom) {
-                $post->message = "[from]{$post->parent->subject}[/from]\n" . $post->message;
+                $post->message = "[from]{$post->parent->censSubject}[/from]\n" . $post->message;
             }
             $post->topic_id = $toTopic->id;
             $this->c->posts->update($post);

+ 25 - 2
app/Models/Topic/Model.php

@@ -2,6 +2,7 @@
 
 namespace ForkBB\Models\Topic;
 
+use ForkBB\Core\Container;
 use ForkBB\Models\DataModel;
 use ForkBB\Models\Forum\Model as Forum;
 use PDO;
@@ -9,6 +10,20 @@ use RuntimeException;
 
 class Model extends DataModel
 {
+    /**
+     * Конструктор
+     *
+     * @param Container $container
+     */
+    public function __construct(Container $container)
+    {
+        parent::__construct($container);
+
+        $this->zDepend = [
+            'subject' => ['censSubject'],
+        ];
+    }
+
     /**
      * Получение родительского раздела
      *
@@ -62,6 +77,14 @@ class Model extends DataModel
         }
     }
 
+    /**
+     * Цензурированный заголовок топика
+     */
+    protected function getcensSubject(): string
+    {
+        return $this->c->censorship->censor($this->subject);
+    }
+
     /**
      * Ссылка на тему
      *
@@ -73,7 +96,7 @@ class Model extends DataModel
             'Topic',
             [
                 'id'   => $this->moved_to ?: $this->id,
-                'name' => \ForkBB\cens($this->subject),
+                'name' => $this->censSubject,
             ]
         );
     }
@@ -273,7 +296,7 @@ class Model extends DataModel
                 'Topic',
                 [
                     'id'   => $this->id,
-                    'name' => \ForkBB\cens($this->subject),
+                    'name' => $this->censSubject,
                 ]
             );
         }

+ 2 - 2
app/Models/User/Model.php

@@ -228,9 +228,9 @@ class Model extends DataModel
         if (isset($this->c->bans->userList[\mb_strtolower($this->username)])) { //????
             return __('Banned');
         } elseif ('' != $this->title) {
-            return \ForkBB\cens($this->title);
+            return $this->c->censorship->censor($this->title);
         } elseif ('' != $this->g_user_title) {
-            return \ForkBB\cens($this->g_user_title);
+            return $this->c->censorship->censor($this->g_user_title);
         } elseif ($this->isGuest) {
             return __('Guest');
         } elseif ($this->isUnverified) {

+ 2 - 2
app/templates/forum.forkbb.php

@@ -91,7 +91,7 @@
               <div class="f-ficon"></div>
             @endif
               <div class="f-finfo">
-                <h3><span class="f-fredirtext">{!! __('Moved') !!}</span> <a class="f-ftname" href="{!! $topic->link !!}">{{ cens($topic->subject) }}</a></h3>
+                <h3><span class="f-fredirtext">{!! __('Moved') !!}</span> <a class="f-ftname" href="{!! $topic->link !!}">{{ $topic->censSubject }}</a></h3>
               </div>
             </div>
           </li>
@@ -118,7 +118,7 @@
             @if ($topic->poll_type)
                   <span class="f-polltxt">{!! __('Poll') !!}</span>
             @endif
-                  <a class="f-ftname" href="{!! $topic->link !!}">{{ cens($topic->subject) }}</a>
+                  <a class="f-ftname" href="{!! $topic->link !!}">{{ $topic->censSubject }}</a>
             @if ($topic->pagination)
                   <span class="f-tpages">
                 @foreach ($topic->pagination as $cur)

+ 2 - 2
app/templates/topic.forkbb.php

@@ -54,7 +54,7 @@
 @endif
     </div>
     <section class="f-main f-topic">
-      <h2>{{ cens($p->model->subject) }}</h2>
+      <h2>{{ $p->model->censSubject }}</h2>
 @foreach ($p->posts as $id => $post)
     @if (empty($post->id) && $iswev = ['e' => [__('Message %s was not found in the database', $id)]])
         @include ('layouts/iswev')
@@ -64,7 +64,7 @@
         <input id="checkbox-{!! $post->id !!}" class="f-post-checkbox" type="checkbox" name="ids[{!! $post->id !!}]" value="{!! $post->id !!}" form="id-form-mod">
         @endif
         <header class="f-post-header">
-          <h3>@if ($post->postNumber > 1) {!! __('Re') !!} @endif {{ cens($p->model->subject) }}</h3>
+          <h3>@if ($post->postNumber > 1) {!! __('Re') !!} @endif {{ $p->model->censSubject }}</h3>
         @if ($p->enableMod && $post->postNumber > 1)
           <label class="f-post-posted" for="checkbox-{!! $post->id !!}" title="{{ __('Select for moderation') }}"><time datetime="{{ utc($post->posted) }}">{{ dt($post->posted) }}</time></label>
         @else

+ 2 - 2
app/templates/topic_in_search.forkbb.php

@@ -51,7 +51,7 @@
         <header class="f-post-header">
           <h3>
             <span class="f-psh-forum"><a href="{!! $post->parent->parent->link !!}" title="{!! __('Go to forum') !!}">{{ $post->parent->parent->forum_name }}</a></span>
-            <span class="f-psh-topic"><a href="{!! $post->parent->link !!}" title="{!! __('Go to topic') !!}">@if ($post->id !== $post->parent->first_post_id) {!! __('Re') !!} @endif {{ cens($post->parent->subject) }}</a></span>
+            <span class="f-psh-topic"><a href="{!! $post->parent->link !!}" title="{!! __('Go to topic') !!}">@if ($post->id !== $post->parent->first_post_id) {!! __('Re') !!} @endif {{ $post->parent->censSubject }}</a></span>
             <span class="f-post-posted"><a href="{!! $post->link !!}" title="{!! __('Go to post') !!}" rel="bookmark"><time datetime="{{ utc($post->posted) }}">{{ dt($post->posted) }}</time></a></span>
           </h3>
           <span class="f-post-number">#{!! $post->postNumber !!}</span>
@@ -74,7 +74,7 @@
           </ul>
           <ul class="f-post-search-info">
             <li class="f-psi-forum">{!! __('Forum') !!}: <a href="{!! $post->parent->parent->link !!}">{{ $post->parent->parent->forum_name }}</a></li>
-            <li class="f-psi-topic">{!! __('Topic') !!}: <a href="{!! $post->parent->link !!}">{{ cens($post->parent->subject) }}</a></li>
+            <li class="f-psi-topic">{!! __('Topic') !!}: <a href="{!! $post->parent->link !!}">{{ $post->parent->censSubject }}</a></li>
             <li class="f-psi-reply">{!! __('%s Reply', $post->parent->num_replies, num($post->parent->num_replies)) !!}</li>
         @if ($post->parent->showViews)
             <li class="f-psi-view">{!! __('%s View', $post->parent->num_views, num($post->parent->num_views)) !!}</li>