Skip to content

Commit

Permalink
Add option to set default avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
sangnguyenplus committed Feb 19, 2025
1 parent 1227f54 commit a2778c9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"provider": "FriendsOfBotble\\Comment\\Providers\\CommentServiceProvider",
"author": "Friends of Botble",
"url": "https://friendsofbotble.com",
"version": "1.1.20",
"version": "1.1.21",
"description": "Allow visitors to comment on your website.",
"minimum_core_version": "7.2.6"
}
2 changes: 2 additions & 0 deletions resources/lang/en/comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
'display_admin_badge' => 'Display admin badge for admin comments',
'show_admin_role_name_for_admin_badge' => 'Show admin role name for admin badge',
'show_admin_role_name_for_admin_badge_helper' => 'If enabled, the admin badge will display the admin role name instead of the default "Admin" text. If the admin role name is empty, the default text will be used. If user has multiple roles, the first role will be used.',
'default_avatar' => 'Default avatar',
'default_avatar_helper' => 'Default avatar for author when they do not have an avatar. If you do not select any image, it will be generated using Gravatar. Image size should be 150x150px.',
],
],
];
10 changes: 10 additions & 0 deletions src/Forms/Settings/CommentSettingForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace FriendsOfBotble\Comment\Forms\Settings;

use Botble\Base\Facades\Html;
use Botble\Base\Forms\FieldOptions\MediaImageFieldOption;
use Botble\Base\Forms\FieldOptions\OnOffFieldOption;
use Botble\Base\Forms\FieldOptions\RadioFieldOption;
use Botble\Base\Forms\Fields\MediaImageField;
use Botble\Base\Forms\Fields\OnOffCheckboxField;
use Botble\Base\Forms\Fields\RadioField;
use Botble\Base\Forms\FormAbstract;
Expand Down Expand Up @@ -99,6 +101,14 @@ public function setup(): void
->helperText(trans('plugins/fob-comment::comment.settings.form.show_admin_role_name_for_admin_badge_helper'))
->value(setting('fob_comment_show_admin_role_name_for_admin_badge', 'true'))
->toArray()
)
->add(
'fob_comment_default_avatar',
MediaImageField::class,
MediaImageFieldOption::make()
->label(trans('plugins/fob-comment::comment.settings.form.default_avatar'))
->helperText(trans('plugins/fob-comment::comment.settings.form.default_avatar_helper'))
->value(setting('fob_comment_default_avatar'))
);
}
}
2 changes: 2 additions & 0 deletions src/Http/Requests/Settings/CommentSettingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace FriendsOfBotble\Comment\Http\Requests\Settings;

use Botble\Base\Rules\MediaImageRule;
use Botble\Base\Rules\OnOffRule;
use Botble\Support\Http\Requests\Request;

Expand All @@ -17,6 +18,7 @@ public function rules(): array
'fob_comment_comment_order' => ['required', 'in:asc,desc'],
'fob_comment_display_admin_badge' => [new OnOffRule()],
'fob_comment_show_admin_role_name_for_admin_badge' => [new OnOffRule()],
'fob_comment_default_avatar' => ['nullable', new MediaImageRule()],
];
}
}
5 changes: 5 additions & 0 deletions src/Models/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Botble\ACL\Contracts\HasPermissions;
use Botble\Base\Models\BaseModel;
use Botble\Media\Facades\RvMedia;
use FriendsOfBotble\Comment\Enums\CommentStatus;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
Expand Down Expand Up @@ -60,6 +61,10 @@ protected function avatarUrl(): Attribute
return $this->author->avatar_url;
}

if ($defaultAvatar = setting('fob_comment_default_avatar')) {
return RvMedia::getImageUrl($defaultAvatar, 'thumb');
}

$email = strtolower(trim($this->email));
$hash = hash('sha256', $email);

Expand Down

0 comments on commit a2778c9

Please sign in to comment.