mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-05 07:20:58 +08:00
bbcode_attach_to_img
This commit is contained in:
@@ -17,7 +17,7 @@ class CommentResource extends JsonResource
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
'text' => $this->text,
|
'text' => bbcode_attach_to_img($this->text),
|
||||||
'updated_at' => format_datetime($this->editdate),
|
'updated_at' => format_datetime($this->editdate),
|
||||||
'created_at' => format_datetime($this->added),
|
'created_at' => format_datetime($this->added),
|
||||||
'create_user' => new UserResource($this->whenLoaded('create_user')),
|
'create_user' => new UserResource($this->whenLoaded('create_user')),
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ return [
|
|||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'expiration' => 129600,
|
'expiration' => 5256000,
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -6552,16 +6552,32 @@ function hide_text($text) {
|
|||||||
|
|
||||||
function bbcode_attach_to_img(string $text) {
|
function bbcode_attach_to_img(string $text) {
|
||||||
$pattern = "/\[attach\]([0-9a-zA-z][0-9a-zA-z]*)\[\/attach\]/is";
|
$pattern = "/\[attach\]([0-9a-zA-z][0-9a-zA-z]*)\[\/attach\]/is";
|
||||||
preg_match_all($pattern, $text, $matches);
|
return preg_replace_callback($pattern, function ($matches) {
|
||||||
if (empty($matches)) {
|
$dlkey = $matches[1];
|
||||||
return $text;
|
$httpdirectory_attachment = get_setting('attachment.httpdirectory');
|
||||||
}
|
$row = \Nexus\Database\NexusDB::remember('attachment_'.$dlkey.'_content', 86400, function() use ($dlkey) {
|
||||||
$attachments = \App\Models\Attachment::query()->whereIn("dlkey", $matches[1])->get();
|
$record = \App\Models\Attachment::query()->where("dlkey", $dlkey)->first();
|
||||||
if ($attachments->isEmpty()) {
|
if ($record) {
|
||||||
return $text;
|
return $record->toArray();
|
||||||
}
|
}
|
||||||
$httpdirectory_attachment = get_setting('attachment.httpdirectory');
|
return [];
|
||||||
|
});
|
||||||
|
if (empty($row) || $row['isimage'] != 1) {
|
||||||
|
do_log(sprintf("dlkey: %s get attachment %s not exists or not image", $dlkey, json_encode($row)));
|
||||||
|
return $matches[0];
|
||||||
|
}
|
||||||
|
$driver = $row['driver'] ?? 'local';
|
||||||
|
if ($driver == "local") {
|
||||||
|
if ($row['thumb'] == 1){
|
||||||
|
$url = $httpdirectory_attachment."/".$row['location'].".thumb.jpg";
|
||||||
|
} else {
|
||||||
|
$url = $httpdirectory_attachment."/".$row['location'];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$url = \Nexus\Attachment\Storage::getDriver($driver)->getImageUrl($row['location']);
|
||||||
|
}
|
||||||
|
return "[img]" . $url . "[/img]";
|
||||||
|
}, $text, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
Reference in New Issue
Block a user