Skip to content

Commit

Permalink
native emoji badges and nerf the system
Browse files Browse the repository at this point in the history
  • Loading branch information
pjc09h committed Sep 12, 2023
1 parent d76037c commit 2f158de
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 54 deletions.
22 changes: 4 additions & 18 deletions app/Badges.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,42 +106,28 @@ public static function hasBadge(int $userId, int $badgeId): bool
* Creates HTML for displaying a badge.
*
* @param int $badgeId
* @param bool $tooltip should the html contain a tooltip?
* @return ?string html
*/
public static function displayBadge(int $badgeId, bool $tooltip = true): ?string
public static function displayBadge(int $badgeId): ?string
{
$app = \Gazelle\App::go();

$query = "select * from badges where id = ?";
$row = $app->dbNew->row($query, [$badgeId]);
#!d($row);exit;

/*
if (!$row) {
return null;
}
*/

if ($tooltip) {
$html = "<img class='badge' alt='{$row["Name"]}: {$row["Description"]}' title='{$row["Name"]}: {$row["Description"]}' src='{$row["Icon"]}'>";
} else {
$html = "<img class='badge' alt='{$row["Name"]}: {$row["Description"]}' src='{$row["Icon"]}'>"; # no title
}

return $html;
return "<span class='badge tooltip' title='{$row["name"]}: {$row["description"]}'>{$row["icon"]}</span>";
}


/**
* displayBadges
*/
public static function displayBadges(array $badgeIds, $tooltip = false): string
public static function displayBadges(array $badgeIds): string
{
$data = [];

foreach ($badgeIds as $badgeId) {
$data[] = self::displayBadge($badgeId, $tooltip);
$data[] = self::displayBadge($badgeId);
}

$data = implode("", $data);
Expand Down
2 changes: 1 addition & 1 deletion app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ public static function format_username(?int $userId = null, $showBadges = false,

# badges
if ($showBadges) {
$badgeHtml = Badges::displayBadges(Badges::getDisplayedBadges($userId), true);
$badgeHtml = Badges::displayBadges(Badges::getDisplayedBadges($userId));
} else {
$badgeHtml = "";
}
Expand Down
36 changes: 18 additions & 18 deletions config/public.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,15 +408,15 @@
# God I wish I didn't have to do this but I just don't care anymore
$AutomatedBadgeIDs = [
"DL" => [
"8" => 10,
"16" => 11,
"32" => 12,
"64" => 13,
"128" => 14,
"256" => 15,
"512" => 16,
"1024" => 17,
"2048" => 18,
"16" => 10,
"32" => 11,
"64" => 12,
"128" => 13,
"256" => 14,
"512" => 15,
"1024" => 16,
"2048" => 17,
"4096" => 18,
],

"UL" => [
Expand All @@ -432,15 +432,15 @@
],

"Posts" => [
"5" => 30,
"10" => 31,
"25" => 32,
"50" => 33,
"100" => 34,
"250" => 35,
"500" => 36,
"1000" => 37,
"2500" => 38,
"10" => 30,
"20" => 31,
"50" => 32,
"100" => 33,
"200" => 34,
"500" => 35,
"1000" => 36,
"2000" => 37,
"5000" => 38,
]
];
ENV::setPub(
Expand Down
6 changes: 4 additions & 2 deletions resources/scss/assets/icons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,14 @@ span.badges {
display: flex;
flex-flow: row wrap;
gap: 1.5rem;
user-select: none;
}

img.badge,
img.icon {
.badge,
.icon {
max-width: 1.5rem;
max-height: 1.5rem;
user-select: none;
}

/* donor */
Expand Down
1 change: 1 addition & 0 deletions resources/scss/global/user.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
display: flex;
flex-flow: row wrap;
gap: 1rem;
user-select: none;
}

/* recent torrent activity, e.g., last five uploads */
Expand Down
24 changes: 12 additions & 12 deletions sections/store/badge.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

$ShopBadgeIDs = [40, 41, 42, 43, 44, 45, 46, 47, 48];
$Prices = [
40 => 500,
41 => 1000,
42 => 2500,
43 => 5000,
44 => 10000,
45 => 25000,
46 => 50000,
47 => 100000,
48 => 250000
40 => 1000,
41 => 2000,
42 => 5000,
43 => 10000,
44 => 20000,
45 => 50000,
46 => 100000,
47 => 200000,
48 => 500000,
];

if (!$BadgeID) {
Expand All @@ -25,7 +25,7 @@
$Err = 'Invalid badge ID';
} elseif (Badges::hasBadge($UserID, $BadgeID)) {
$Err = 'You already have this badge';
} elseif ((int) $BadgeID !== $ShopBadgeIDs[0] && !Badges::hasBadge($UserID, $ShopBadgeIDs[array_search($BadgeID, $ShopBadgeIDs)-1])) {
} elseif ((int) $BadgeID !== $ShopBadgeIDs[0] && !Badges::hasBadge($UserID, $ShopBadgeIDs[array_search($BadgeID, $ShopBadgeIDs) - 1])) {
$Err = "You haven't purchased the badges before this one!";
}

Expand Down Expand Up @@ -79,7 +79,7 @@
</div>
<?php
} else {
View::header('Store'); ?>
View::header('Store'); ?>
<div>
<h2 id='general'>Purchase Badge?</h2>
<div class='box pad'>
Expand Down Expand Up @@ -107,5 +107,5 @@
</div>
</div>
<?php
}
}
View::footer();
6 changes: 3 additions & 3 deletions sections/user/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@
# badges
if ($isOwnProfile) {
$badges = Badges::getBadges($userId);
$badgesDisplay = Badges::displayBadges(array_keys($badges), true);
$badgesDisplay = Badges::displayBadges(array_keys($badges));
} else {
$badges = Badges::getDisplayedBadges($userId);
$badgesDisplay = Badges::displayBadges($badges, true);
$badgesDisplay = Badges::displayBadges($badges);
}


Expand Down Expand Up @@ -1147,7 +1147,7 @@ class="brackets">Show</a></span>&nbsp;
$i = 0;
foreach (array_keys($AllBadges) as $BadgeID) {
?><input type="checkbox" name="badges[]" class="badge_checkbox"
value="<?=$BadgeID?>" <?=(in_array($BadgeID, $UserBadgeIDs)) ? " checked" : ""?>/><?=Badges::displayBadge($BadgeID, true)?>
value="<?=$BadgeID?>" <?=(in_array($BadgeID, $UserBadgeIDs)) ? " checked" : ""?>/><?=Badges::displayBadge($BadgeID)?>
<?php $i++;
if ($i % 8 == 0) {
echo "<br>";
Expand Down

0 comments on commit 2f158de

Please sign in to comment.