From cfdc5e4dd74e69381718063b97dcb529017ccead Mon Sep 17 00:00:00 2001 From: flashwave Date: Mon, 26 Sep 2022 19:09:33 +0000 Subject: [PATCH] Social shit in database now. --- pages/contact.php | 111 +++++++++++--------------------------------- pages/index.php | 39 ++++------------ public/css/2021.css | 16 +------ src/ContactInfo.php | 70 ++++++++++++++++++++++++++++ src/Contacts.php | 55 ++++++++++++++++++++++ 5 files changed, 160 insertions(+), 131 deletions(-) create mode 100644 src/ContactInfo.php create mode 100644 src/Contacts.php diff --git a/pages/contact.php b/pages/contact.php index fe1161c..f06996b 100644 --- a/pages/contact.php +++ b/pages/contact.php @@ -6,103 +6,44 @@ $router->get('/contact.html', mkiRedirect('/contact')); $router->get('/nintendo', mkiRedirect('/contact')); $router->get('/nintendo.php', mkiRedirect('/contact')); -$router->get('/contact', function() { - $contact = [ - [ - 'id' => 'contact', - 'title' => 'Direct Contact', - 'items' => [ - [ - 'id' => 'email', - 'name' => 'E-mail', - 'icon' => 'fmi fmi-email', - 'display' => 'contact@flash.moe', - 'link' => 'mailto:contact@flash.moe', - ], - ], - ], - - [ - 'id' => 'communities', - 'title' => 'Communities & Social Media', - 'items' => [ - [ - 'id' => 'flashii', - 'name' => 'Flashii', - 'icon' => 'fmi fmi-flashii', - 'display' => 'flash', - 'link' => '//flashii.net/profile.php?u=1', - ], - [ - 'id' => 'twitter', - 'name' => 'Twitter', - 'icon' => 'fmi fmi-twitter', - 'display' => '@flashwahaha', - 'link' => '//twitter.com/flashwahaha', - ], - [ - 'id' => 'youtube', - 'name' => 'YouTube', - 'icon' => 'fmi fmi-youtube', - 'display' => 'flashwave', - 'link' => '//youtube.com/c/flashwave', - ], - [ - 'id' => 'github', - 'name' => 'Github', - 'icon' => 'fmi fmi-github', - 'display' => 'flashwave', - 'link' => '//github.com/flashwave', - ], - [ - 'id' => 'lastfm', - 'name' => 'Last.fm', - 'icon' => 'fmi fmi-lastfm', - 'display' => 'flashwave_', - 'link' => '//last.fm/user/flashwave_', - ], - ], - ], - ]; +$router->get('/contact', function() use ($db) { + $contacts = (new Contacts($db))->getAll(); $body = fm_component('header', [ 'title' => 'flash.moe / contact', ]); - foreach($contact as $section) { - - $body .= << -
-
-

{$section['title']}

-
- -
+ $body .= << +
+
+

Contacts

+
+
+
HTML; - foreach($section['items'] as $social) { - $body .= ' -HTML; + if($contact->hasLink()) { + $body .= ''; + } else { + $body .= ''; } - $body .= '
'; + $body .= << +
+ + +
+ +HTML; } + $body .= ''; + $body .= fm_component('footer'); return $body; diff --git a/pages/index.php b/pages/index.php index fe9cc84..0dd1a50 100644 --- a/pages/index.php +++ b/pages/index.php @@ -158,30 +158,7 @@ $router->get('/', function() use ($db) { $projects = (new Projects($db))->getFeatured(); $languages = new Languages($db); - - $contact = [ - [ - 'id' => 'email', - 'name' => 'E-mail', - 'icon' => 'fmi fmi-email', - 'display' => 'contact@flash.moe', - 'link' => 'mailto:contact@flash.moe', - ], - [ - 'id' => 'flashii', - 'name' => 'Flashii', - 'icon' => 'fmi fmi-flashii', - 'display' => 'flash', - 'link' => '//flashii.net/profile.php?u=1', - ], - [ - 'id' => 'twitter', - 'name' => 'Twitter', - 'icon' => 'fmi fmi-twitter', - 'display' => '@flashwahaha', - 'link' => '//twitter.com/flashwahaha', - ], - ]; + $contacts = (new Contacts($db))->getHomePage(); $body = fm_component('header', [ 'title' => 'flash.moe', @@ -261,20 +238,20 @@ HTML;
HTML; - foreach($contact as $social) { - $body .= "
"; + foreach($contacts as $contact) { + $body .= "
getName()}\" style=\"--social-colour: {$contact->getColourHex()}\">"; - if(isset($social['link'])) { - $body .= ""; + if($contact->hasLink()) { + $body .= "getLink()}\" class=\"social-background\" target=\"_blank\" rel=\"noopener\">"; } else { $body .= "
"; } $body .= <<
+
HTML; diff --git a/public/css/2021.css b/public/css/2021.css index 341c585..c04c2f4 100644 --- a/public/css/2021.css +++ b/public/css/2021.css @@ -275,6 +275,7 @@ body { height: 100%; background-image: linear-gradient(0deg, #1118 0%, #2228 50%, #3338 50%, #5558 100%); transform: skew(-15deg); + background-color: var(--social-colour); } .social:active .social-background { background-image: linear-gradient(0deg, #1118 0%, #2228 50%, #3338 50%, #3338 100%); @@ -298,21 +299,6 @@ body { line-height: 1.3em; font-family: 'Electrolize', Verdana, 'Dejavu Sans', Arial, Helvetica, sans-serif; } -.social-twitter .social-background { background-color: #1da1f2; } -.social-youtube .social-background { background-color: #ff0000; } -.social-flashii .social-background { background-color: #8559a5; } -.social-github .social-background { background-color: #222222; } -.social-twitch .social-background { background-color: #6441a4; } -.social-steam .social-background { background-color: #2c2e35; } -.social-osu .social-background { background-color: #ff66aa; } -.social-tetrio .social-background { background-color: #40c045; } -.social-email .social-background { background-color: #4a3650; } -.social-lastfm .social-background { background-color: #ba0000; } -.social-nin-sw .social-background { background-color: #e60012; } -.social-nin-3ds .social-background { background-color: #ce171f; } -.social-nin-wiiu .social-background { background-color: #00acca; } -.social-paypal .social-background { background-color: #009cde; } -.social-patreon .social-background { background-color: #f86754; } .index-featured { display: grid; diff --git a/src/ContactInfo.php b/src/ContactInfo.php new file mode 100644 index 0000000..d99ac84 --- /dev/null +++ b/src/ContactInfo.php @@ -0,0 +1,70 @@ +name = $name; + $this->homePage = $homePage; + $this->order = $order; + $this->title = $title; + $this->icon = $icon; + $this->colour = $colour; + $this->display = $display; + $this->link = $link; + } + + public function getName(): string { + return $this->name; + } + + public function isHomePage(): bool { + return $this->homePage; + } + + public function getOrder(): int { + return $this->order; + } + + public function getTitle(): WString { + return $this->title; + } + + public function getIcon(): string { + return $this->icon; + } + + public function getColour(): int { + return $this->colour; + } + + public function getColourHex(): string { + return '#' . str_pad(dechex($this->colour), 6, '0', STR_PAD_LEFT); + } + + public function getDisplay(): WString { + return $this->display; + } + + public function hasLink(): bool { + return $this->link !== null; + } + + public function getLink(): ?string { + return $this->link; + } +} diff --git a/src/Contacts.php b/src/Contacts.php new file mode 100644 index 0000000..f6cd280 --- /dev/null +++ b/src/Contacts.php @@ -0,0 +1,55 @@ + 0 ORDER BY `cont_order` LIMIT 3'; + private const QUERY_ALL = self::QUERY . ' ORDER BY `cont_order`'; + + private IDbConnection $conn; + + public function __construct(IDbConnection $conn) { + $this->conn = $conn; + } + + public function getAll(): array { + $stmt = $this->conn->prepare(self::QUERY_ALL); + $stmt->execute(); + $result = $stmt->getResult(); + $objs = []; + + while($result->next()) + $objs[] = self::createObject($result); + + return $objs; + } + + public function getHomePage(): array { + $stmt = $this->conn->prepare(self::QUERY_HOME); + $stmt->execute(); + $result = $stmt->getResult(); + $objs = []; + + while($result->next()) + $objs[] = self::createObject($result); + + return $objs; + } + + private static function createObject(IDbResult $result): ContactInfo { + return new ContactInfo( + $result->getString(0), // name + $result->getInteger(1) !== 0, // homepage + $result->getInteger(2), // order + $result->getWString(3, 'utf-8'), // title + $result->getString(4), // icon + $result->getInteger(5), // colour + $result->getWString(6, 'utf-8'), // display + $result->isNull(7) ? null : $result->getString(7) // link + ); + } +}