Skip to content

Commit

Permalink
DEV: Оптимизируем Services\Parser
Browse files Browse the repository at this point in the history
  • Loading branch information
evgip committed Jan 14, 2023
1 parent abefbb4 commit 4e2b0b8
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 39 deletions.
24 changes: 2 additions & 22 deletions app/Services/Parser/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace App\Services\Parser;

use App\Services\Parser\Convert;
use App\Services\Parser\{Convert, Filter};
use App\Models\AuditModel;
use UserData;

Expand Down Expand Up @@ -122,7 +122,7 @@ public static function cut($text, $length = 800)
}

if (!$afterCut) {
$beforeCut = self::fragment($text, $length);
$beforeCut = Filter::fragment($text, $length);
}

$button = false;
Expand All @@ -133,26 +133,6 @@ public static function cut($text, $length = 800)
return ['content' => $beforeCut, 'button' => $button];
}

// Getting a piece of text
public static function fragment($text, $lenght = 100, $strip = false)
{
$charset = 'UTF-8';
$token = '~';
$end = '...';

if ($strip) {
$text = str_replace('>', '', strip_tags($text));
}

if (mb_strlen($text, $charset) >= $lenght) {
$wrap = wordwrap($text, $lenght, $token);
$str_cut = mb_substr($wrap, 0, mb_strpos($wrap, $token, 0, $charset), $charset);
return $str_cut .= $end;
}

return $text;
}

public static function parseUser($content, $with_user = false, $to_uid = false)
{
preg_match_all('/@([^@,:\s,]+)/i', strip_tags($content), $matchs);
Expand Down
8 changes: 0 additions & 8 deletions app/Services/Parser/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ public static function noHTML(string $content, int $lenght = 150)
return self::fragment($str, $lenght);
}

public static function pre($tag, $params, $content)
{
$content = htmlspecialchars_decode($content);


return '<pre class="lb">' . $content . '</pre>';
}

public static function fragment(string $text, int $lenght = 150, string $charset = 'UTF-8')
{
if (mb_strlen($text, $charset) >= $lenght) {
Expand Down
2 changes: 1 addition & 1 deletion public/assets/css/style.css

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions resources/views/default/content/comment/comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<?php if (!empty($comment['answer_id'])) : ?>
<?php if ($comment['answer_published'] == 0 && $comment['answer_user_id'] != UserData::getUserId() && !UserData::checkAdmin()) continue; ?>
<div class="gray-600 max-w780">
<div class="content-body">
<div class="flex justify-between gap">
<div class="flex gap">
<a class="gray-600 flex gap-min" href="<?= url('profile', ['login' => $comment['login']]); ?>">
Expand All @@ -24,7 +24,7 @@
</div>
<?php else : ?>
<?php if ($comment['comment_published'] == 0 && $comment['comment_user_id'] != UserData::getUserId() && !UserData::checkAdmin()) continue; ?>
<div class="gray-600 max-w780">
<div class="content-body">
<div class="flex justify-between gap">
<div class="flex gap">
<a class="gray-600 flex gap-min" href="<?= url('profile', ['login' => $comment['login']]); ?>">
Expand Down
3 changes: 1 addition & 2 deletions resources/views/default/content/comment/comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@
<div class="box bg-beige sticky top-sm">
<?= __('meta.comments_desc'); ?>
</div>
</aside>
<?= insert('/_block/js-msg-flag'); ?>
</aside>
3 changes: 1 addition & 2 deletions resources/views/default/content/user/profile/comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@
<?= insert('/content/user/profile/sidebar', ['data' => $data]); ?>
</aside>
</div>
</div>
<?= insert('/_block/js-msg-flag'); ?>
</div>
6 changes: 4 additions & 2 deletions resources/views/default/css/components/components.css
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,12 @@ a:hover > img,
.trigger img { opacity: 0.8; }

.focus-id:hover { cursor: pointer }

.underline-hover:hover { text-decoration: underline; }

.content-body { max-width: 780px; }
.content-body {
max-width: 780px;
margin-top: 15px;
}

.content_tree:target,
.content_tree.edit {
Expand Down

0 comments on commit 4e2b0b8

Please sign in to comment.