Browse Source

2017-12-15

Visman 7 years ago
parent
commit
8f6f0696ea
5 changed files with 98 additions and 126 deletions
  1. 20 14
      app/Core/Router.php
  2. 59 93
      app/Models/Pages/Edit.php
  3. 4 4
      app/functions.php
  4. 8 8
      app/lang/English/common.po
  5. 7 7
      app/lang/Russian/common.po

+ 20 - 14
app/Core/Router.php

@@ -88,7 +88,11 @@ class Router
             && ($route = $this->route('GET', rawurldecode(parse_url($url, PHP_URL_PATH))))
             && ($route = $this->route('GET', rawurldecode(parse_url($url, PHP_URL_PATH))))
             && $route[0] === self::OK
             && $route[0] === self::OK
         ) {
         ) {
-            return $url;
+            if (isset($route[3])) {
+                return $this->link($route[3], $route[2]);
+            } else {
+                return $url;
+            }
         } else {
         } else {
             return $this->link($defMarker, $defArgs);
             return $this->link($defMarker, $defArgs);
         }
         }
@@ -172,16 +176,18 @@ class Router
 
 
         if (isset($this->statical[$uri])) {
         if (isset($this->statical[$uri])) {
             if (isset($this->statical[$uri][$method])) {
             if (isset($this->statical[$uri][$method])) {
-                return [self::OK, $this->statical[$uri][$method], []];
+                list($handler, $marker) = $this->statical[$uri][$method];
+                return [self::OK, $handler, [], $marker];
             } elseif ($head && isset($this->statical[$uri]['GET'])) {
             } elseif ($head && isset($this->statical[$uri]['GET'])) {
-                return [self::OK, $this->statical[$uri]['GET'], []];
+                list($handler, $marker) = $this->statical[$uri]['GET'];
+                return [self::OK, $handler, [], $marker];
             } else {
             } else {
                 $allowed = array_keys($this->statical[$uri]);
                 $allowed = array_keys($this->statical[$uri]);
             }
             }
         }
         }
 
 
-        $pos = strpos(substr($uri, 1), '/');
-        $base = false === $pos ? $uri : substr($uri, 0, ++$pos);
+        $pos = strpos($uri, '/', 1);
+        $base = false === $pos ? $uri : substr($uri, 0, $pos);
 
 
         if (isset($this->dynamic[$base])) {
         if (isset($this->dynamic[$base])) {
             foreach ($this->dynamic[$base] as $pattern => $data) {
             foreach ($this->dynamic[$base] as $pattern => $data) {
@@ -190,21 +196,21 @@ class Router
                 }
                 }
 
 
                 if (isset($data[$method])) {
                 if (isset($data[$method])) {
-                    $data = $data[$method];
+                    list($handler, $keys, $marker) = $data[$method];
                 } elseif ($head && isset($data['GET'])) {
                 } elseif ($head && isset($data['GET'])) {
-                    $data = $data['GET'];
+                    list($handler, $keys, $marker) = $data['GET'];
                 } else {
                 } else {
                     $allowed += array_keys($data);
                     $allowed += array_keys($data);
                     continue;
                     continue;
                 }
                 }
 
 
                 $args = [];
                 $args = [];
-                foreach ($data[1] as $key) {
+                foreach ($keys as $key) {
                     if (isset($matches[$key])) {
                     if (isset($matches[$key])) {
                         $args[$key] = $matches[$key];
                         $args[$key] = $matches[$key];
                     }
                     }
                 }
                 }
-                return [self::OK, $data[0], $args];
+                return [self::OK, $handler, $args, $marker];
             }
             }
         }
         }
         if (empty($allowed)) {
         if (empty($allowed)) {
@@ -243,22 +249,22 @@ class Router
             $data = null;
             $data = null;
             if (is_array($method)) {
             if (is_array($method)) {
                 foreach ($method as $m) {
                 foreach ($method as $m) {
-                    $this->statical[$route][$m] = $handler;
+                    $this->statical[$route][$m] = [$handler, $marker];
                 }
                 }
             } else {
             } else {
-                $this->statical[$route][$method] = $handler;
+                $this->statical[$route][$method] = [$handler, $marker];
             }
             }
         } else {
         } else {
             $data = $this->parse($route);
             $data = $this->parse($route);
             if (false === $data) {
             if (false === $data) {
-                throw new \Exception('Route is incorrect');
+                throw new InvalidArgumentException('Route is incorrect');
             }
             }
             if (is_array($method)) {
             if (is_array($method)) {
                 foreach ($method as $m) {
                 foreach ($method as $m) {
-                    $this->dynamic[$data[0]][$data[1]][$m] = [$handler, $data[2]];
+                    $this->dynamic[$data[0]][$data[1]][$m] = [$handler, $data[2], $marker];
                 }
                 }
             } else {
             } else {
-                $this->dynamic[$data[0]][$data[1]][$method] = [$handler, $data[2]];
+                $this->dynamic[$data[0]][$data[1]][$method] = [$handler, $data[2], $marker];
             }
             }
         }
         }
 
 

+ 59 - 93
app/Models/Pages/Edit.php

@@ -100,110 +100,76 @@ class Edit extends Page
      */
      */
     protected function endEdit(Post $post, Validator $v)
     protected function endEdit(Post $post, Validator $v)
     {
     {
-        $now       = time();
-        $user      = $this->c->user;
-        $username  = $user->isGuest ? $v->username : $user->username;
-        $merge     = false;
-        $executive = $user->isAdmin || $user->isModerator($model);
-        
-        // подготовка к объединению/сохранению сообщения
-        if (null === $v->subject) {
-            $createTopic = false;
-            $forum       = $model->parent;
-            $topic       = $model;
-            
-            if (! $user->isGuest && $topic->last_poster === $username) {
-                if ($executive) {
-                    if ($v->merge_post) {
-                        $merge = true;
-                    } 
-                } else {
-                    if ($this->c->config->o_merge_timeout > 0 // ???? стоит завязать на время редактирование сообщений?
-                        && $now - $topic->last_post < $this->c->config->o_merge_timeout
-                    ) {
-                        $merge = true;
-                    }
-                }
+        $now         = time();
+        $user        = $this->c->user;
+        $executive   = $user->isAdmin || $user->isModerator($post);
+        $topic       = $post->parent;
+        $editSubject = $post->id === $topic->first_post_id;
+        $calcPost    = false;
+        $calcTopic   = false;
+        $calcForum   = false;
+
+        // текст сообщения
+        if ($post->message !== $v->message) {
+            $post->message       = $v->message;
+            $post->edited        = $now;
+            $post->edited_by     = $user->username;
+            $calcPost            = true;
+            if ($post->id === $topic->last_post_id) {
+                $calcTopic       = true;
+                $calcForum       = true;
             }
             }
-        // создание темы
-        } else {
-            $createTopic = true;
-            $forum       = $model;
-            $topic       = $this->c->ModelTopic;
-
-            $topic->subject     = $v->subject;
-            $topic->poster      = $username;
-            $topic->last_poster = $username;
-            $topic->posted      = $now;
-            $topic->last_post   = $now;
-            $topic->sticky      = $v->stick_topic ? 1 : 0;
-            $topic->stick_fp    = $v->stick_fp ? 1 : 0;
-#           $topic->poll_type   = ;
-#           $topic->poll_time   = ;
-#           $topic->poll_term   = ;
-#           $topic->poll_kol    = ;
-    
-            $topic->insert();
         }
         }
-
-        // попытка объеденить новое сообщение с крайним в теме
-        if ($merge) {
-            $lastPost  = $this->c->ModelPost->load($topic->last_post_id);
-            $newLength = mb_strlen($lastPost->message . $v->message, 'UTF-8');
-
-            if ($newLength < $this->c->MAX_POST_SIZE - 100) {
-                $lastPost->message   = $lastPost->message . "\n[after=" . ($now - $topic->last_post) . "]\n" . $v->message; //????
-                $lastPost->edited    = $now;
-                $lastPost->edited_by = $username;
-
-                $lastPost->update();
-            } else {
-                $merge = false;
-            }
+        // показ смайлов
+        if ($this->c->config->o_smilies == '1' && (bool) $post->hide_smilies !== (bool) $v->hide_smilies ) {
+            $post->hide_smilies  = $v->hide_smilies ? 1 : 0;
         }
         }
-        
-        // создание нового сообщения
-        if (! $merge) {
-            $post = $this->c->ModelPost;
-        
-            $post->poster       = $username;
-            $post->poster_id    = $this->c->user->id;
-            $post->poster_ip    = $this->c->user->ip;
-            $post->poster_email = $v->email;
-            $post->message      = $v->message; //?????
-            $post->hide_smilies = $v->hide_smilies ? 1 : 0;
-#           $post->edit_post    =
-            $post->posted       = $now;
-#           $post->edited       =
-#           $post->edited_by    =
-            $post->user_agent   = $this->c->user->userAgent;
-            $post->topic_id     = $topic->id;
-        
-            $post->insert();
+        // редактирование без ограничений
+        if ($executive && (bool) $post->edit_post !== (bool) $v->edit_post) {
+            $post->edit_post     = $v->edit_post ? 1 : 0;
         }
         }
 
 
-        if ($createTopic) {
-            $topic->forum_id      = $forum->id;
-            $topic->first_post_id = $post->id;
+        if ($editSubject) {
+            // заголовок темы
+            if ($topic->subject !== $v->subject) {
+                $topic->subject  = $v->subject;
+                $post->edited    = $now;
+                $post->edited_by = $user->username;
+                $calcForum       = true;
+            }
+            // выделение темы
+            if ($executive && (bool) $topic->sticky !== (bool) $v->stick_topic) {
+                $topic->sticky   = $v->stick_topic ? 1 : 0;
+            }
+            // закрепление первого сообшения
+            if ($executive && (bool) $topic->stick_fp !== (bool) $v->stick_fp) {
+                $topic->stick_fp = $v->stick_fp ? 1 : 0;
+            }
         }
         }
 
 
-        // обновление данных в теме и разделе
-        $topic->calcStat()->update();
-        $forum->calcStat()->update();
+        // обновление сообщения
+        $post->update();
 
 
-        // обновление данных текущего пользователя
-        if (! $merge && ! $user->isGuest && $forum->no_sum_mess != '1') {
-            $user->num_posts = $user->num_posts + 1;
+        // обновление темы
+        if ($calcTopic) {
+            $topic->calcStat();
+        }
+        $topic->update();
 
 
-            if ($user->g_promote_next_group != '0' && $user->num_posts >= $user->g_promote_min_posts) {
-                $user->group_id = $user->g_promote_next_group;
-            }
+        // обновление раздела
+        if ($calcForum) {
+            $topic->parent->calcStat();
+        }
+        $topic->parent->update();
+        
+        // антифлуд 
+        if ($calcPost || $calcForum) { 
+            $user->last_post = $now; //????
+            $user->update();
         }
         }
-        $user->last_post = $now;
-        $user->update();
         
         
         return $this->c->Redirect
         return $this->c->Redirect
-            ->page('ViewPost', ['id' => $merge ? $lastPost->id : $post->id])
-            ->message(\ForkBB\__('Post redirect'));
+            ->page('ViewPost', ['id' => $post->id])
+            ->message(\ForkBB\__('Edit redirect'));
     }
     }
 }
 }

+ 4 - 4
app/functions.php

@@ -48,9 +48,9 @@ function __($arg, ...$args)
     if (empty($args)) {
     if (empty($args)) {
         return $tr;
         return $tr;
     } elseif (is_array($args[0])) {
     } elseif (is_array($args[0])) {
-        return strtr($tr, array_map('\ForkBB\_e', $args[0]));
+        return strtr($tr, array_map('\ForkBB\e', $args[0]));
     } else {
     } else {
-        $args = array_map('\ForkBB\_e', $args);
+        $args = array_map('\ForkBB\e', $args);
         return sprintf($tr, ...$args);
         return sprintf($tr, ...$args);
     }
     }
 }
 }
@@ -62,7 +62,7 @@ function __($arg, ...$args)
  *
  *
  * @return string
  * @return string
  */
  */
-function _e($arg)
+function e($arg)
 {
 {
     return htmlspecialchars($arg, ENT_HTML5 | ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
     return htmlspecialchars($arg, ENT_HTML5 | ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
 }
 }
@@ -184,5 +184,5 @@ function size($size)
         $size /= 1024;
         $size /= 1024;
     }
     }
 
 
-    return __('Size unit '.$units[$i], round($size, 2));
+    return __('%s ' . $units[$i], round($size, 2));
 }
 }

+ 8 - 8
app/lang/English/common.po

@@ -459,25 +459,25 @@ msgid "New reports"
 msgstr "There are new reports"
 msgstr "There are new reports"
 
 
 msgid "Maintenance mode enabled"
 msgid "Maintenance mode enabled"
-msgstr "<a href=\"%s\"Maintenance mode is enabled!</a>"
+msgstr "<a href=\"%s\">Maintenance mode is enabled!</a>"
 
 
-msgid "Size unit B"
+msgid "%s B"
 msgstr "%s B"
 msgstr "%s B"
 
 
-msgid "Size unit KiB"
+msgid "%s KiB"
 msgstr "%s KiB"
 msgstr "%s KiB"
 
 
-msgid "Size unit MiB"
+msgid "%s MiB"
 msgstr "%s MiB"
 msgstr "%s MiB"
 
 
-msgid "Size unit GiB"
+msgid "%s GiB"
 msgstr "%s GiB"
 msgstr "%s GiB"
 
 
-msgid "Size unit TiB"
+msgid "%s TiB"
 msgstr "%s TiB"
 msgstr "%s TiB"
 
 
-msgid "Size unit PiB"
+msgid "%s PiB"
 msgstr "%s PiB"
 msgstr "%s PiB"
 
 
-msgid "Size unit EiB"
+msgid "%s EiB"
 msgstr "%s EiB"
 msgstr "%s EiB"

+ 7 - 7
app/lang/Russian/common.po

@@ -462,23 +462,23 @@ msgstr "Есть новые сигналы"
 msgid "Maintenance mode enabled"
 msgid "Maintenance mode enabled"
 msgstr "<a href=\"%s\">Включен режим обслуживания!</a>"
 msgstr "<a href=\"%s\">Включен режим обслуживания!</a>"
 
 
-msgid "Size unit B"
+msgid "%s B"
 msgstr "%s байт"
 msgstr "%s байт"
 
 
-msgid "Size unit KiB"
+msgid "%s KiB"
 msgstr "%s Кбайт"
 msgstr "%s Кбайт"
 
 
-msgid "Size unit MiB"
+msgid "%s MiB"
 msgstr "%s Мбайт"
 msgstr "%s Мбайт"
 
 
-msgid "Size unit GiB"
+msgid "%s GiB"
 msgstr "%s Гбайт"
 msgstr "%s Гбайт"
 
 
-msgid "Size unit TiB"
+msgid "%s TiB"
 msgstr "%s Тбайт"
 msgstr "%s Тбайт"
 
 
-msgid "Size unit PiB"
+msgid "%s PiB"
 msgstr "%s Пбайт"
 msgstr "%s Пбайт"
 
 
-msgid "Size unit EiB"
+msgid "%s EiB"
 msgstr "%s Эбайт"
 msgstr "%s Эбайт"