소스 검색

Update censorship usage 2

Visman 5 년 전
부모
커밋
3d9d33c7c6

+ 1 - 1
app/Core/View.php

@@ -56,7 +56,7 @@ class View extends Dirk
         $perfix = <<<'EOD'
 <?php
 
-use function \ForkBB\{__, cens, num, dt, utc, size};
+use function \ForkBB\{__, num, dt, utc, size};
 
 ?>
 EOD;

+ 0 - 2
app/Models/DataModel.php

@@ -3,8 +3,6 @@
 namespace ForkBB\Models;
 
 use ForkBB\Models\Model;
-use InvalidArgumentException;
-use RuntimeException;
 
 class DataModel extends Model
 {

+ 10 - 3
app/Models/Model.php

@@ -3,7 +3,6 @@
 namespace ForkBB\Models;
 
 use ForkBB\Core\Container;
-use RuntimeException;
 
 class Model
 {
@@ -73,7 +72,8 @@ class Model
      */
     protected function unsetCalc($name): void
     {
-        unset($this->zAttrsCalc[$name]); //????
+        unset($this->zAttrsCalc[$name]);
+        unset($this->zAttrsCalc['censor' . \ucfirst($name)]);
 
         if (isset($this->zDepend[$name])) {
             $this->zAttrsCalc = \array_diff_key($this->zAttrsCalc, \array_flip($this->zDepend[$name]));
@@ -143,8 +143,15 @@ class Model
             return $this->zAttrsCalc[$name];
         } elseif (\method_exists($this, $method = 'get' . $name)) {
             return $this->zAttrsCalc[$name] = $this->$method();
+        } elseif (\array_key_exists($name, $this->zAttrs)) {
+            return $this->zAttrs[$name];
+        } elseif (
+            0 === \strpos($name, 'censor')
+            && isset($this->zAttrs[$root = \lcfirst(\substr($name, 6))])
+        ) {
+            return $this->zAttrsCalc[$name] = $this->c->censorship->censor($this->zAttrs[$root]);
         } else {
-            return $this->zAttrs[$name] ?? null;
+            return null;
         }
     }
 

+ 1 - 1
app/Models/Page.php

@@ -396,7 +396,7 @@ abstract class Page extends Model
                         $name = $crumb->forum_name;
                     // для темы
                     } elseif (isset($crumb->subject)) {
-                        $name = $crumb->censSubject;
+                        $name = $crumb->censorSubject;
                     // все остальное
                     } 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->censSubject, $topic->link, $forum->forum_name, $forum->link),
+                    'value'   => __('Post #%s ', $post->id, $post->link, $topic->censorSubject, $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') . ' «' . $post->parent->censSubject . '»',
+                            'value'   => __('Topic') . ' «' . $post->parent->censorSubject . '»',
                         ],
                         'info2' => [
                             'type'    => '', //????

+ 3 - 1
app/Models/Pages/Edit.php

@@ -53,7 +53,9 @@ class Edit extends Page
                 null !== $v->preview
                 && ! $v->getErrors()
             ) {
-                $this->previewHtml = $this->c->Parser->parseMessage(null, (bool) $v->hide_smilies);
+                $this->previewHtml = $this->c->censorship->censor(
+                    $this->c->Parser->parseMessage(null, (bool) $v->hide_smilies)
+                );
             }
         } else {
             $args['_vars'] = [ //????

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

@@ -252,7 +252,7 @@ class Moderate extends Page
                 'Topic',
                 [
                     'id'   => $this->curTopic->id,
-                    'name' => $this->curTopic->censSubject,
+                    'name' => $this->curTopic->censorSubject,
                     'page' => $page,
                 ]
             );
@@ -559,7 +559,7 @@ class Moderate extends Page
         $headers = [];
         foreach ($objects as $object) {
             if ($object instanceof Topic) {
-                $headers[] = __('Topic «%s»', $object->censSubject);
+                $headers[] = __('Topic «%s»', $object->censorSubject);
             } 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->censSubject),
+                'value'   => __('All posts will be posted in the «%s» topic', $this->firstTopic->censorSubject),
 //                'html'    => true,
             ];
         }

+ 3 - 1
app/Models/Pages/Post.php

@@ -52,7 +52,9 @@ class Post extends Page
                 null !== $v->preview
                 && ! $v->getErrors()
             ) {
-                $this->previewHtml = $this->c->Parser->parseMessage(null, (bool) $v->hide_smilies);
+                $this->previewHtml = $this->c->censorship->censor(
+                    $this->c->Parser->parseMessage(null, (bool) $v->hide_smilies)
+                );
             }
         }
 

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

@@ -399,7 +399,7 @@ class Edit extends Profile
                 'class'   => 'pline',
                 'type'    => 'str',
                 'caption' => __('Email info'),
-                'value'   => $this->c->censorship->censor($this->curUser->email),
+                'value'   => $this->curUser->censorEmail,
             ];
         }
         if ($this->rules->editEmail) {
@@ -443,8 +443,8 @@ class Edit extends Profile
                 'class'   => 'pline',
                 'type'    => 'link',
                 'caption' => __('Website'),
-                'value'   => $this->c->censorship->censor($this->curUser->url),
-                'href'    => $this->c->censorship->censor($this->curUser->url),
+                'value'   => $this->curUser->censorUrl,
+                'href'    => $this->curUser->censorUrl,
             ];
         }
         $form['sets']['contacts'] = [

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

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

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

@@ -172,7 +172,7 @@ class Report extends Page
             ),
             'reason'       => $report->message,
             'forumId'      => $report->post->parent->parent->id,
-            'topicSubject' => $report->post->parent->censSubject,
+            'topicSubject' => $report->post->parent->censorSubject,
         ];
 
         return $this->c->Mail

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

@@ -152,7 +152,7 @@ class Topic extends Page
             'Topic',
             [
                 'id'   => $topic->id,
-                'name' => $topic->censSubject,
+                'name' => $topic->censorSubject,
                 '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->censSubject}[/from]\n" . $post->message;
+                $post->message = "[from]{$post->parent->subject}[/from]\n" . $post->message;
             }
             $post->topic_id = $toTopic->id;
             $this->c->posts->update($post);

+ 10 - 18
app/Models/Topic/Model.php

@@ -15,14 +15,14 @@ class Model extends DataModel
      *
      * @param Container $container
      */
-    public function __construct(Container $container)
-    {
-        parent::__construct($container);
-
-        $this->zDepend = [
-            'subject' => ['censSubject'],
-        ];
-    }
+#    public function __construct(Container $container)
+#    {
+#        parent::__construct($container);
+#
+#        $this->zDepend = [
+#            'subject' => ['censSubject'],
+#       ];
+#    }
 
     /**
      * Получение родительского раздела
@@ -77,14 +77,6 @@ class Model extends DataModel
         }
     }
 
-    /**
-     * Цензурированный заголовок топика
-     */
-    protected function getcensSubject(): string
-    {
-        return $this->c->censorship->censor($this->subject);
-    }
-
     /**
      * Ссылка на тему
      *
@@ -96,7 +88,7 @@ class Model extends DataModel
             'Topic',
             [
                 'id'   => $this->moved_to ?: $this->id,
-                'name' => $this->censSubject,
+                'name' => $this->censorSubject,
             ]
         );
     }
@@ -296,7 +288,7 @@ class Model extends DataModel
                 'Topic',
                 [
                     'id'   => $this->id,
-                    'name' => $this->censSubject,
+                    'name' => $this->censorSubject,
                 ]
             );
         }

+ 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 $this->c->censorship->censor($this->title);
+            return $this->censorTitle;
         } elseif ('' != $this->g_user_title) {
-            return $this->c->censorship->censor($this->g_user_title);
+            return $this->censorG_user_title;
         } elseif ($this->isGuest) {
             return __('Guest');
         } elseif ($this->isUnverified) {

+ 0 - 21
app/functions.php

@@ -12,7 +12,6 @@ use ForkBB\Core\Container;
 function _init(Container $c): void
 {
     __(null, $c);
-    cens('', $c);
     dt(0, true, '', '', true, true, $c);
 }
 
@@ -73,26 +72,6 @@ function e(string $arg): string
     return \htmlspecialchars($arg, \ENT_HTML5 | \ENT_QUOTES | \ENT_SUBSTITUTE, 'UTF-8');
 }
 
-/**
- * Цензура
- *
- * @param string $arg
- * @param Container $container
- *
- * @return string
- */
-function cens(string $arg, Container $container = null): string
-{
-    static $c;
-
-    if (null !== $container) {
-        $c = $container;
-        return '';
-    }
-
-    return $c->censorship->censor($arg);
-}
-
 /**
  * Возвращает число в формате текущего пользователя
  *

+ 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 !!}">{{ $topic->censSubject }}</a></h3>
+                <h3><span class="f-fredirtext">{!! __('Moved') !!}</span> <a class="f-ftname" href="{!! $topic->link !!}">{{ $topic->censorSubject }}</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 !!}">{{ $topic->censSubject }}</a>
+                  <a class="f-ftname" href="{!! $topic->link !!}">{{ $topic->censorSubject }}</a>
             @if ($topic->pagination)
                   <span class="f-tpages">
                 @foreach ($topic->pagination as $cur)

+ 1 - 1
app/templates/layouts/subforums.forkbb.php

@@ -53,7 +53,7 @@
               </div>
               <div class="f-cell f-clast">
         @if ($cur->tree->last_post_id)
-                <span class="f-cltopic">{!! __('Last post in the topic "<a href="%1$s">%2$s</a>"', $cur->tree->linkLast, cens($cur->tree->last_topic)) !!}</span>
+                <span class="f-cltopic">{!! __('Last post in the topic "<a href="%1$s">%2$s</a>"', $cur->tree->linkLast, $cur->tree->censorLast_topic) !!}</span>
                 <span class="f-clposter">{!! __('by %s', $cur->tree->last_poster) !!}</span>
                 <span class="f-cltime">{!! dt($cur->tree->last_post) !!}</span>
         @else

+ 1 - 1
app/templates/post.forkbb.php

@@ -20,7 +20,7 @@
       <h2>{!! __('Post preview') !!}</h2>
       <div class="f-post-body">
         <div class="f-post-main">
-          {!! cens($p->previewHtml) !!}
+          {!! $p->previewHtml !!}
         </div>
       </div>
     </section>

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

@@ -54,7 +54,7 @@
 @endif
     </div>
     <section class="f-main f-topic">
-      <h2>{{ $p->model->censSubject }}</h2>
+      <h2>{{ $p->model->censorSubject }}</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 {{ $p->model->censSubject }}</h3>
+          <h3>@if ($post->postNumber > 1) {!! __('Re') !!} @endif {{ $p->model->censorSubject }}</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
@@ -106,7 +106,7 @@
           <ul class="f-user-info-add">
             <li>{!! __('Registered:') !!} {{ dt($post->user->registered, true) }}</li>
             @if ($post->user->location)
-            <li>{!! __('From') !!} {{ cens($post->user->location) }}</li>
+            <li>{!! __('From') !!} {{ $post->user->censorLocation }}</li>
             @endif
           </ul>
         @endif

+ 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 {{ $post->parent->censSubject }}</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->censorSubject }}</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 !!}">{{ $post->parent->censSubject }}</a></li>
+            <li class="f-psi-topic">{!! __('Topic') !!}: <a href="{!! $post->parent->link !!}">{{ $post->parent->censorSubject }}</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>