Skip to content

Commit

Permalink
更新:修复艾特用户出错的bug,优化艾特解析
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuchunshu committed Aug 18, 2023
1 parent 1bf2f03 commit 6edc195
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/Plugins/Core/helpers.php
Expand Up @@ -199,7 +199,7 @@ function replace_all_at_space(string $content): string
{
$pattern = '/@(.*?)(?=[^ <\\/p>]+)/u';
return preg_replace_callback($pattern, static function ($match) {
return $match[0] . ' ';
return $match[0];
}, $content);
}
}
Expand Down
13 changes: 8 additions & 5 deletions app/Plugins/Core/src/Lib/TextParsing.php
@@ -1,6 +1,6 @@
<?php

declare (strict_types=1);
declare(strict_types=1);
/**
* This file is part of zhuchunshu.
* @link https://github.com/zhuchunshu
Expand All @@ -12,24 +12,27 @@

use App\Plugins\User\src\Models\User;
use Hyperf\Stringable\Str;

class TextParsing
{
public function keywords($keywords) : string
public function keywords($keywords): string
{
return <<<HTML
<a href="/keywords/{$keywords}.html">#{$keywords}</a>
HTML;
}
public function at($username) : string

public function at($username): string
{
$username = Str::after($username, '@');
$username = trim($username);
$username = strip_tags($username);
if (User::query()->where('username', $username)->exists()) {
$uid = User::query()->where('username', $username)->first()->id;
return <<<HTML
<a href="/users/{$username}.username">@{$username}</a>
<a href="/users/{$uid}.html">@{$username}</a>
HTML;
}
return '@' . $username;
}
}
}

0 comments on commit 6edc195

Please sign in to comment.