From 530a15857e5fe2de33ffbcedfdbcd92cf8e6dea9 Mon Sep 17 00:00:00 2001 From: ghost Date: Mon, 27 Nov 2023 21:30:47 +0200 Subject: [PATCH] switch to composer package, add jdenticon lib --- README.md | 1 + composer.json | 14 ++++++++++++++ src/public/index.php | 24 ++++++++++++++++++++++-- 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 composer.json diff --git a/README.md b/README.md index 7ae452a..cf790a3 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ git checkout -b my-pr-branch-name #### Thanks * CSS background: [ColorSpace](https://mycolor.space/gradient?ori=to+right+top&hex=%23041B41&hex2=%232AB8C6&sub=1) +* Icons: [jdenticon](https://github.com/dmester/jdenticon-php) #### Feedback diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..bbcac2a --- /dev/null +++ b/composer.json @@ -0,0 +1,14 @@ +{ + "name": "yggverse/yggwave", + "description": "YGGwave ~ The Radio Catalog", + "type": "project", + "license": "MIT", + "autoload": { + "psr-4": { + "Yggverse\\Yggwave\\": "src/" + } + }, + "require": { + "jdenticon/jdenticon": "^1.0" + } +} diff --git a/src/public/index.php b/src/public/index.php index 1edb38b..d59d11b 100644 --- a/src/public/index.php +++ b/src/public/index.php @@ -5,6 +5,9 @@ ini_set('display_startup_errors', '1'); error_reporting(E_ALL); + // Load dependencies + require_once __DIR__ . '/../../vendor/autoload.php'; + class YGGwave { public static function getSignals() { @@ -21,6 +24,23 @@ if ($host = parse_url($data[2], PHP_URL_HOST)) { + $identicon = new \Jdenticon\Identicon(); + + $identicon->setValue( + $data[2] + ); + + $identicon->setSize(16); + + $identicon->setStyle( + [ + 'backgroundColor' => 'rgba(255, 255, 255, 0)', + 'padding' => 0 + ] + ); + + $icon = $identicon->getImageDataUri('webp'); + $hash = crc32($data[2]); $hex = str_split(substr(dechex($hash), 0, 6), 2); @@ -36,9 +56,9 @@ href="%s" title="%s">%s', htmlspecialchars($data[2]), htmlentities($data[1]), - sprintf('%s', urlencode($host), + style="%s" />', $icon, htmlentities($data[1]), sprintf('background:rgba(%s,%s,%s,.3)', $r, $g, $b)))); }