Localization Supplement

This commit is contained in:
veselcraft 2020-08-20 17:10:18 +03:00
commit 6f9a1065d9
5 changed files with 46 additions and 24 deletions

View file

@ -86,6 +86,8 @@ class Post extends Postable
{
if(ctype_space($content))
throw new \LengthException("Content length must be at least 1 character (not counting whitespaces).");
else if(iconv_strlen($content) > OPENVK_ROOT_CONF["openvk"]["preferences"]["wall"]["postSizes"]["maxSize"])
throw new \LengthException("Content is too large.");
$this->stateChanges("content", $content);
}

View file

@ -5,6 +5,9 @@ trait TRichText
{
private function formatEmojis(string $text): string
{
if(iconv_strlen($this->getRecord()->content) > OPENVK_ROOT_CONF["openvk"]["preferences"]["wall"]["postSizes"]["emojiProcessingLimit"])
return $text;
$emojis = \Emoji\detect_emoji($text);
$replaced = []; # OVK-113
foreach($emojis as $emoji) {
@ -32,7 +35,9 @@ trait TRichText
function getText(bool $html = true): string
{
$text = htmlentities($this->getRecord()->content, ENT_DISALLOWED | ENT_XHTML);
$proc = iconv_strlen($this->getRecord()->content) <= OPENVK_ROOT_CONF["openvk"]["preferences"]["wall"]["postSizes"]["processingLimit"];
if($html) {
if($proc) {
$rel = $this->isAd() ? "sponsored" : "ugc";
$text = preg_replace(
"%((https?|ftp):\/\/(\S*?\.\S*?))([\s)\[\]{},;\"\':<]|\.\s|$)%",
@ -44,6 +49,8 @@ trait TRichText
$text = preg_replace("%\[(id|club)([0-9]++)\|([\p{L} 0-9@]+)\]%Xu", "<a href='/$1$2'>$3</a>", $text);
$text = preg_replace("%(#([\p{L}_-]++[0-9]*[\p{L}_-]*))%Xu", "<a href='/feed/hashtag/$2'>$1</a>", $text);
$text = $this->formatEmojis($text);
}
$text = $this->removeZalgo($text);
$text = nl2br($text);
}

View file

@ -47,7 +47,7 @@ class Notifications
{
$db = $this->getEDB(false);
if(!$db)
return 1;
return 0;
$results = $db->query($this->getQuery($user, true, $offset, $archived));
@ -56,6 +56,12 @@ class Notifications
function getNotificationsByUser(User $user, int $offset, bool $archived = false, int $page = 1, ?int $perPage = NULL): \Traversable
{
$db = $this->getEDB(false);
if(!$db) {
yield from [];
return;
}
$results = $this->getEDB()->query($this->getQuery($user, false, $offset, $archived, $page, $perPage));
foreach($results->fetchAll() as $notif) {
$originModel = $this->getModel($notif->originModelType, $notif->originModelId);

View file

@ -163,10 +163,12 @@ final class WallPresenter extends OpenVKPresenter
else
$canPost = false;
if(!$canPost)
$this->flashFail("err", "Ошибка доступа", "Вам нельзя писать на эту стену.");
if(iconv_strlen($this->postParam("text") ?? "") > 280)
$this->flashFail("err", "Не удалось опубликовать пост", "Пост слишком большой.");
$flags = 0;
if($this->postParam("as_group") === "on")
$flags |= 0b10000000;
@ -189,7 +191,7 @@ final class WallPresenter extends OpenVKPresenter
(new Albums)->getUserWallAlbum($wallOwner)->addPhoto($photo);
}
} catch(ISE $ex) {
$this->flashFail("err", "Не удалось опубликовать пост", "Файл повреждён.");
$this->flashFail("err", "Не удалось опубликовать пост", "Файл изображения повреждён, слишком велик или одна сторона изображения в разы больше другой.");
}
$post = new Post;
@ -210,10 +212,10 @@ final class WallPresenter extends OpenVKPresenter
$post->setFlags($flags);
$post->save();
} catch(\LogicException $ex) {
$this->flashFail("err", "Не удалось опубликовать пост", "Нельзя опубликовать пустой пост.");
$this->flashFail("err", "Не удалось опубликовать пост", "Пост пустой или слишком большой.");
}
} else {
$this->flashFail("err", "Не удалось опубликовать пост", "Нельзя опубликовать пустой пост.");
$this->flashFail("err", "Не удалось опубликовать пост", "Пост пустой или слишком большой.");
}
if($wall > 0 && $wall !== $this->user->identity->getId())

View file

@ -22,6 +22,11 @@ openvk:
adminAccount: 1 # Change this ok
messages:
strict: false
wall:
postSizes:
maxSize: 60000
processingLimit: 3000
emojiProcessingLimit: 1000
menu:
links: