Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

post id avatars #1374

Merged
merged 4 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion core/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,10 @@ public function get_avatar_url(): ?string
{
// FIXME: configurable
global $config;
if ($config->get_string("avatar_host") === "gravatar") {
$avatar_host = $config->get_string("avatar_host");
if ($avatar_host === "post") {
return $this->get_avatar_post_link();
} elseif ($avatar_host === "gravatar") {
if (!empty($this->email)) {
$hash = md5(strtolower($this->email));
$s = $config->get_string("avatar_gravatar_size");
Expand All @@ -251,6 +254,22 @@ public function get_avatar_url(): ?string
return null;
}

public function get_avatar_post_link(): ?string
{
global $database;
$user_config = new DatabaseConfig($database, "user_config", "user_id", (string)$this->id);
$id = $user_config->get_int("avatar_post_id", 0);
if ($id === 0) {
return null;
}
$image = Image::by_id($id);
if ($image) {
return $image->get_thumb_link();
}
$user_config->set_int("avatar_post_id", 0);
Mjokfox marked this conversation as resolved.
Show resolved Hide resolved
return null;
}

/**
* Get an auth token to be used in POST forms
*
Expand Down
7 changes: 1 addition & 6 deletions ext/comment/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,7 @@ protected function comment_to_html(Comment $comment, bool $trim = false): string
</div>
";
} else {
$h_avatar = "";
if (!empty($comment->owner_email)) {
$hash = md5(strtolower($comment->owner_email));
$cb = date("Y-m-d");
$h_avatar = "<img alt='avatar' src=\"//www.gravatar.com/avatar/$hash.jpg?cacheBreak=$cb\"><br>";
}
$h_avatar = $comment->get_owner()->get_avatar_html();
$h_reply = " - <a href='javascript: replyTo($i_image_id, $i_comment_id, \"$h_name\")'>Reply</a>";
$h_ip = $user->can(Permissions::VIEW_IP) ? "<br>".show_ip($comment->poster_ip, "Comment posted {$comment->posted}") : "";
$h_del = "";
Expand Down
10 changes: 10 additions & 0 deletions ext/user/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ public function onSetupBuilding(SetupBuildingEvent $event): void

$hosts = [
"None" => "none",
"Post id" => "post",
Mjokfox marked this conversation as resolved.
Show resolved Hide resolved
"Gravatar" => "gravatar"
];

Expand Down Expand Up @@ -457,6 +458,15 @@ public function onSetupBuilding(SetupBuildingEvent $event): void
$sb->end_table();
}

public function onUserOptionsBuilding(UserOptionsBuildingEvent $event): void
{
global $config;
if ($config->get_string("avatar_host") === "post") {
$sb = $event->panel->create_new_block("Avatar");
$sb->add_int_option("avatar_post_id", 'Avatar post ID: ');
}
}

public function onPageSubNavBuilding(PageSubNavBuildingEvent $event): void
{
global $user;
Expand Down