From 8f6f0696ea8111f60ad9d8f7c2a31d086cd0a25b Mon Sep 17 00:00:00 2001 From: Visman Date: Fri, 15 Dec 2017 22:09:00 +0700 Subject: [PATCH] 2017-12-15 --- app/Core/Router.php | 34 ++++---- app/Models/Pages/Edit.php | 158 +++++++++++++++---------------------- app/functions.php | 8 +- app/lang/English/common.po | 16 ++-- app/lang/Russian/common.po | 14 ++-- 5 files changed, 101 insertions(+), 129 deletions(-) diff --git a/app/Core/Router.php b/app/Core/Router.php index 8badd0f6..3350a999 100644 --- a/app/Core/Router.php +++ b/app/Core/Router.php @@ -88,7 +88,11 @@ class Router && ($route = $this->route('GET', rawurldecode(parse_url($url, PHP_URL_PATH)))) && $route[0] === self::OK ) { - return $url; + if (isset($route[3])) { + return $this->link($route[3], $route[2]); + } else { + return $url; + } } else { return $this->link($defMarker, $defArgs); } @@ -172,16 +176,18 @@ class Router if (isset($this->statical[$uri])) { 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'])) { - return [self::OK, $this->statical[$uri]['GET'], []]; + list($handler, $marker) = $this->statical[$uri]['GET']; + return [self::OK, $handler, [], $marker]; } else { $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])) { foreach ($this->dynamic[$base] as $pattern => $data) { @@ -190,21 +196,21 @@ class Router } if (isset($data[$method])) { - $data = $data[$method]; + list($handler, $keys, $marker) = $data[$method]; } elseif ($head && isset($data['GET'])) { - $data = $data['GET']; + list($handler, $keys, $marker) = $data['GET']; } else { $allowed += array_keys($data); continue; } $args = []; - foreach ($data[1] as $key) { + foreach ($keys as $key) { if (isset($matches[$key])) { $args[$key] = $matches[$key]; } } - return [self::OK, $data[0], $args]; + return [self::OK, $handler, $args, $marker]; } } if (empty($allowed)) { @@ -243,22 +249,22 @@ class Router $data = null; if (is_array($method)) { foreach ($method as $m) { - $this->statical[$route][$m] = $handler; + $this->statical[$route][$m] = [$handler, $marker]; } } else { - $this->statical[$route][$method] = $handler; + $this->statical[$route][$method] = [$handler, $marker]; } } else { $data = $this->parse($route); if (false === $data) { - throw new \Exception('Route is incorrect'); + throw new InvalidArgumentException('Route is incorrect'); } if (is_array($method)) { 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 { - $this->dynamic[$data[0]][$data[1]][$method] = [$handler, $data[2]]; + $this->dynamic[$data[0]][$data[1]][$method] = [$handler, $data[2], $marker]; } } diff --git a/app/Models/Pages/Edit.php b/app/Models/Pages/Edit.php index 7dc009b8..d224242d 100644 --- a/app/Models/Pages/Edit.php +++ b/app/Models/Pages/Edit.php @@ -100,110 +100,76 @@ class Edit extends Page */ 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; - } - } - } - // создание темы - } else { - $createTopic = true; - $forum = $model; - $topic = $this->c->ModelTopic; + $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; - $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 ($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; } } - - // создание нового сообщения - 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 ($this->c->config->o_smilies == '1' && (bool) $post->hide_smilies !== (bool) $v->hide_smilies ) { + $post->hide_smilies = $v->hide_smilies ? 1 : 0; + } + // редактирование без ограничений + 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; - } - - // обновление данных в теме и разделе - $topic->calcStat()->update(); - $forum->calcStat()->update(); - - // обновление данных текущего пользователя - if (! $merge && ! $user->isGuest && $forum->no_sum_mess != '1') { - $user->num_posts = $user->num_posts + 1; - - if ($user->g_promote_next_group != '0' && $user->num_posts >= $user->g_promote_min_posts) { - $user->group_id = $user->g_promote_next_group; + 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; } } - $user->last_post = $now; - $user->update(); + + // обновление сообщения + $post->update(); + + // обновление темы + if ($calcTopic) { + $topic->calcStat(); + } + $topic->update(); + + // обновление раздела + if ($calcForum) { + $topic->parent->calcStat(); + } + $topic->parent->update(); + + // антифлуд + if ($calcPost || $calcForum) { + $user->last_post = $now; //???? + $user->update(); + } 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')); } } diff --git a/app/functions.php b/app/functions.php index 3896c02f..2719f878 100644 --- a/app/functions.php +++ b/app/functions.php @@ -48,9 +48,9 @@ function __($arg, ...$args) if (empty($args)) { return $tr; } elseif (is_array($args[0])) { - return strtr($tr, array_map('\ForkBB\_e', $args[0])); + return strtr($tr, array_map('\ForkBB\e', $args[0])); } else { - $args = array_map('\ForkBB\_e', $args); + $args = array_map('\ForkBB\e', $args); return sprintf($tr, ...$args); } } @@ -62,7 +62,7 @@ function __($arg, ...$args) * * @return string */ -function _e($arg) +function e($arg) { return htmlspecialchars($arg, ENT_HTML5 | ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); } @@ -184,5 +184,5 @@ function size($size) $size /= 1024; } - return __('Size unit '.$units[$i], round($size, 2)); + return __('%s ' . $units[$i], round($size, 2)); } diff --git a/app/lang/English/common.po b/app/lang/English/common.po index fb0b0189..1bb48f6b 100644 --- a/app/lang/English/common.po +++ b/app/lang/English/common.po @@ -459,25 +459,25 @@ msgid "New reports" msgstr "There are new reports" msgid "Maintenance mode enabled" -msgstr "" +msgstr "Maintenance mode is enabled!" -msgid "Size unit B" +msgid "%s B" msgstr "%s B" -msgid "Size unit KiB" +msgid "%s KiB" msgstr "%s KiB" -msgid "Size unit MiB" +msgid "%s MiB" msgstr "%s MiB" -msgid "Size unit GiB" +msgid "%s GiB" msgstr "%s GiB" -msgid "Size unit TiB" +msgid "%s TiB" msgstr "%s TiB" -msgid "Size unit PiB" +msgid "%s PiB" msgstr "%s PiB" -msgid "Size unit EiB" +msgid "%s EiB" msgstr "%s EiB" diff --git a/app/lang/Russian/common.po b/app/lang/Russian/common.po index c56a27f5..0c7b9ef3 100644 --- a/app/lang/Russian/common.po +++ b/app/lang/Russian/common.po @@ -462,23 +462,23 @@ msgstr "Есть новые сигналы" msgid "Maintenance mode enabled" msgstr "Включен режим обслуживания!" -msgid "Size unit B" +msgid "%s B" msgstr "%s байт" -msgid "Size unit KiB" +msgid "%s KiB" msgstr "%s Кбайт" -msgid "Size unit MiB" +msgid "%s MiB" msgstr "%s Мбайт" -msgid "Size unit GiB" +msgid "%s GiB" msgstr "%s Гбайт" -msgid "Size unit TiB" +msgid "%s TiB" msgstr "%s Тбайт" -msgid "Size unit PiB" +msgid "%s PiB" msgstr "%s Пбайт" -msgid "Size unit EiB" +msgid "%s EiB" msgstr "%s Эбайт"