From 36e6e23a680191f418567eec2b58904d207ac0af Mon Sep 17 00:00:00 2001 From: Cody Cook Date: Tue, 30 Apr 2024 19:38:37 -0700 Subject: [PATCH] Various new features. --- classes/DJ.php | 6 +- classes/DJs.php | 51 ++++++++ classes/Mix.php | 42 +++++- dj.php | 237 ++++------------------------------ djs.php | 44 +++++++ genre.php | 22 +--- genres.php | 66 +--------- includes/footer.php | 4 +- includes/globals.php | 110 ++++++++++++++++ includes/header.php | 52 +++++++- includes/navbar.php | 37 +++--- index.php | 24 +--- locale/en_US/messages.php | 3 +- mix.php | 262 ++++++++++++-------------------------- 14 files changed, 437 insertions(+), 523 deletions(-) create mode 100644 classes/DJs.php create mode 100644 djs.php create mode 100644 includes/globals.php diff --git a/classes/DJ.php b/classes/DJ.php index 56514fe..dc17038 100644 --- a/classes/DJ.php +++ b/classes/DJ.php @@ -16,7 +16,7 @@ class DJ private string $created = ""; private string $updated = ""; private string $claimed_by = ""; - private $db = null; + private mysqli $db; public function __construct($value, $db) @@ -125,8 +125,8 @@ class DJ if (isset($dj['created'])) { $this->created = $dj['created']; } - if (isset($dj['updated'])) { - $this->updated = $dj['updated']; + if (isset($dj['lastupdated'])) { + $this->updated = $dj['lastupdated']; } return true; diff --git a/classes/DJs.php b/classes/DJs.php new file mode 100644 index 0000000..636238e --- /dev/null +++ b/classes/DJs.php @@ -0,0 +1,51 @@ +db = $db; + if (!$this->load_all_djs()) { + return false; + } else { + return true; + } + + } + + private function load_all_djs(): bool + { + $djs = $this->get_all_djs(); + if ($djs) { + $this->djs = $djs; + return true; + } else { + return false; + } + } + + public function get_all_djs($order = "ASC") + { + $stmt = $this->db->prepare("SELECT * FROM djs ORDER BY name $order"); + $stmt->execute(); + $result = $stmt->get_result(); + $djs = $result->fetch_all(MYSQLI_ASSOC); + $stmt->close(); + return $djs; + } + + public function get_nonzero_djs($order = "ASC") + { + $stmt = $this->db->prepare("SELECT * FROM djs WHERE count > 0 ORDER BY name $order"); + $stmt->execute(); + $result = $stmt->get_result(); + $djs = $result->fetch_all(MYSQLI_ASSOC); + $stmt->close(); + return $djs; + } +} \ No newline at end of file diff --git a/classes/Mix.php b/classes/Mix.php index 1108d8a..0c34416 100644 --- a/classes/Mix.php +++ b/classes/Mix.php @@ -20,6 +20,7 @@ class Mix private $created; private $updated; private $playcount = 0; + private $tracklist = []; public function __construct($value, $db) @@ -121,6 +122,34 @@ class Mix } } + + private function evaluate_tracklist(): array + { + if (empty($this->tracklist)){ + return []; + } else { + // if the first item in the array is also an array, then return it + if (is_array($this->tracklist[0]['value'])){ + + return $this->tracklist[0]['value']; + } else { + return explode("\n", $this->tracklist[0]['value']); + } + } + + } + + private function load_mix_tracklist() + { + $stmt = $this->db->prepare("SELECT value FROM mix_meta WHERE attribute = 'tracklist' AND mix_id = ?"); + $stmt->bind_param("i", $this->id); + $stmt->execute(); + $result = $stmt->get_result(); + $tracklist = $result->fetch_all(MYSQLI_ASSOC); + $stmt->close(); + return $tracklist; + } + public function get_img(): string { return $this->cover; @@ -186,10 +215,21 @@ class Mix $this->genre = $this->get_mix_genres(); $this->playcount = $this->get_playcount(); - + $this->tracklist = $this->load_mix_tracklist(); + $this->tracklist = $this->evaluate_tracklist(); return true; } + public function get_description() + { + return $this->description; + } + + public function get_tracklist(): array + { + return $this->tracklist; + } + } diff --git a/dj.php b/dj.php index f4af77c..6fddd5a 100644 --- a/dj.php +++ b/dj.php @@ -1,14 +1,6 @@ - - - - - - -
@@ -85,210 +68,44 @@ if (isset($_GET['dj']) && $_GET['dj'] != "") {
-
-
-
    - get_socials() != []) { + ?> +
    +
    +
      + get_socials(); + foreach ($socials as $key => $value) { + echo social_line($key, $value); } - - return " -
    • - -

      $value -

      -
    • "; - } - - $socials = $dj->get_socials(); - - foreach ($socials as $key => $value) { - echo social_line($key, $value); - } - - ?> - -
    + ?> +
+
- +
-

Full Name

+

-

Johnatan Smith

-
-
-
-
-
-

Email

-
-
-

example@example.com

-
-
-
-
-
-

Phone

-
-
-

(097) 234-5678

-
-
-
-
-
-

Mobile

-
-
-

(098) 765-4321

-
-
-
-
-
-

Address

-
-
-

Bay Area, San Francisco, CA

-
-
-
-
-
-
-
-
-

assigment Project - Status -

-

Web Design

-
-
-
-

Website Markup

-
-
-
-

One Page

-
-
-
-

Mobile Template

-
-
-
-

Backend API

-
-
-
-
-
-
-
-
-
-

assigment Project - Status -

-

Web Design

-
-
-
-

Website Markup

-
-
-
-

One Page

-
-
-
-

Mobile Template

-
-
-
-

Backend API

-
-
-
+

get_name(); ?>

+ get_bio() != "") { + echo box_line($locale['bio'], $dj->get_bio()); + } + echo box_line($locale['lastupdated'], $dj->get_updated()); + ?>
+
@@ -306,5 +123,3 @@ if (isset($_GET['dj']) && $_GET['dj'] != "") {
- - \ No newline at end of file diff --git a/djs.php b/djs.php new file mode 100644 index 0000000..6da0137 --- /dev/null +++ b/djs.php @@ -0,0 +1,44 @@ + +
+
+
+
+ +
+
+ + get_nonzero_djs(); + $count = 0; + foreach ($djs as $dj) { + card_output($count, $dj, $locale); + echo '' . $locale['view'] . ''; + echo '
'; + echo ''; + echo ''; + if ($count % 4 == 3) { + echo ''; + } + $count++; + } + ?> + + +
+ \ No newline at end of file diff --git a/genre.php b/genre.php index ea3a414..5cadd1b 100644 --- a/genre.php +++ b/genre.php @@ -1,14 +1,6 @@ - - - - - - -
@@ -193,6 +179,4 @@ if (isset($_GET['genre']) && $_GET['genre'] != "") {
- - - \ No newline at end of file + \ No newline at end of file diff --git a/genres.php b/genres.php index 78ea391..e42c99e 100644 --- a/genres.php +++ b/genres.php @@ -1,14 +1,6 @@ - - - - - - - - -
@@ -75,20 +32,7 @@ $genres = new Genres($db); $genres = $genres->get_nonzero_genres(); $count = 0; foreach ($genres as $genre) { - if ($count % 4 == 0) { - echo '
'; - } - echo '
'; - echo '
'; - echo '
'; - echo '
' . $genre['name'] . '
'; - echo '

' . $genre['count'] . ' '; - if ($genre['count'] == 1) { - echo $locale['mix']; - } else { - echo $locale['mixes']; - } - echo '

'; + card_output($count, $genre, $locale); echo '' . $locale['view'] . ''; echo '
'; echo '
'; @@ -102,6 +46,4 @@ $genres = new Genres($db);
- - - \ No newline at end of file + \ No newline at end of file diff --git a/includes/footer.php b/includes/footer.php index 7ba576a..3ef6263 100644 --- a/includes/footer.php +++ b/includes/footer.php @@ -7,4 +7,6 @@ }); }); - \ No newline at end of file + + + \ No newline at end of file diff --git a/includes/globals.php b/includes/globals.php new file mode 100644 index 0000000..b37d193 --- /dev/null +++ b/includes/globals.php @@ -0,0 +1,110 @@ +'; + } + echo '
'; + echo '
'; + echo '
'; + echo '
' . $dj['name'] . '
'; + echo '

' . $dj['count'] . ' '; + if ($dj['count'] == 1) { + echo $locale['mix']; + } else { + echo $locale['mixes']; + } + echo '

'; +} + +function social_line($social, $value): string +{ + $icon = ""; + $url = ""; + $color = "#000000"; + + switch ($social) { + case "facebook": + $icon = "fa-brands fa-facebook"; + $url = "https://www.facebook.com/$value"; + $color = "#3b5998"; + $name = "Facebook"; + break; + case "instagram": + $icon = "fa-brands fa-instagram"; + $url = "https://www.instagram.com/$value"; + $color = "#ac2bac"; + $name = "Instagram"; + break; + case "twitter": + $icon = "fa-brands fa-twitter"; + $url = "https://www.twitter.com/$value"; + $color = "#55acee"; + $name = "Twitter"; + break; + case "myspace": + $icon = "fa-brands fa-myspace"; + $url = "https://www.myspace.com/$value"; + $color = "#000000"; + $name = "Myspace"; + break; + case "soundcloud": + $icon = "fa-brands fa-soundcloud"; + $url = "https://www.soundcloud.com/$value"; + $color = "#ff8800"; + $name = "Soundcloud"; + break; + case "mixcloud": + $icon = "fa-brands fa-mixcloud"; + $url = "https://www.mixcloud.com/$value"; + $color = "#00c7f7"; + $name = "Mixcloud"; + break; + case "spotify": + $icon = "fa-brands fa-spotify"; + $url = "https://www.spotify.com/$value"; + $color = "#1DB954"; + $name = "Spotify"; + break; + } + + return " +
  • + +

    $value +

    +
  • "; +} + +function box_line($title, $value): string +{ + + return "
    +
    +
    +

    $title

    +
    +
    +

    $value

    +
    +
    "; + +} \ No newline at end of file diff --git a/includes/header.php b/includes/header.php index 3d0d914..fe9ecab 100644 --- a/includes/header.php +++ b/includes/header.php @@ -1,7 +1,45 @@ - - -<?php echo $config['app']['name']; ?> - - - - + + + + + + <?php echo $config['app']['name']; ?> + + + + + + + + + + + \ No newline at end of file diff --git a/includes/navbar.php b/includes/navbar.php index be1f153..bd96e35 100644 --- a/includes/navbar.php +++ b/includes/navbar.php @@ -14,7 +14,7 @@ $current_lang = $_SESSION['lang'] ?? $config['app']['locale']; ?>
    diff --git a/index.php b/index.php index 4c0be4e..903a052 100644 --- a/index.php +++ b/index.php @@ -1,22 +1,6 @@ - - - - - - - +require 'includes/globals.php'; +require 'includes/header.php'; ?>
    @@ -30,6 +14,4 @@ require_once 'includes/lang_loader.php';
    - - - \ No newline at end of file + \ No newline at end of file diff --git a/locale/en_US/messages.php b/locale/en_US/messages.php index 2105888..1fe9359 100644 --- a/locale/en_US/messages.php +++ b/locale/en_US/messages.php @@ -33,5 +33,6 @@ return [ "searchResults" => "Search Results", "searchResultsFor" => "Search Results for", "searchResultsFound" => "Search Results Found", - + "tracklist" => "Tracklist", + "lastupdated" => "Last Updated", ]; \ No newline at end of file diff --git a/mix.php b/mix.php index 5110c00..0306172 100644 --- a/mix.php +++ b/mix.php @@ -1,14 +1,6 @@ - - - - - - - +require 'includes/header.php'; ?>
    @@ -42,7 +26,6 @@ if (isset($_GET['mix']) && $_GET['mix'] != "") { aria-current="page">get_name() != "") { echo $mix->get_name(); - } else { echo $locale['notfound']; } @@ -53,184 +36,101 @@ if (isset($_GET['mix']) && $_GET['mix'] != "") {
    -
    -
    -
    -
    - avatar -
    get_name(); - ?>
    -

    -
    +
    +
    +
    +
    + get_img() != "") { + echo "avatar"; + } ?> +

    get_name(); + ?>

    + get_description() != "") { + echo "

    " . $mix->get_description() . "

    "; + } + ?> +

    -
    -
    -
    -
    -
    -

    -
    -
    -

    get_name(); ?>

    -
    +
    +
    +
    +
    +
    +
    +

    -
    -
    -
    -

    -
    -
    -

    - +

    get_name(); ?>

    +
    +
    +
    +
    +
    +

    +
    +
    +

    + get_djs(); - $djCount = count($djs); - $i = 0; - foreach ($djs as $dj) { - echo "" . $dj->get_name() . ""; - if ($i < $djCount - 1) { - echo ", "; - } - $i++; + // loop through the $mix['djs'] array and output them in comma separated format + $djs = $mix->get_djs(); + $djCount = count($djs); + $i = 0; + foreach ($djs as $dj) { + echo "" . $dj->get_name() . ""; + if ($i < $djCount - 1) { + echo ", "; } + $i++; + } - ?> + ?> -

    -
    -
    -
    -
    -
    -

    Phone

    -
    -
    -

    (097) 234-5678

    -
    -
    -
    -
    -
    -

    Mobile

    -
    -
    -

    (098) 765-4321

    -
    -
    -
    -
    -
    -

    Address

    -
    -
    -

    Bay Area, San Francisco, CA

    -
    -
    -
    -
    -
    -
    -
    -
    -

    assigment Project - Status -

    -

    Web Design

    -
    -
    -
    -

    Website Markup

    -
    -
    -
    -

    One Page

    -
    -
    -
    -

    Mobile Template

    -
    -
    -
    -

    Backend API

    -
    -
    -
    -
    -
    -
    -
    -
    -
    -

    assigment Project - Status -

    -

    Web Design

    -
    -
    -
    -

    Website Markup

    -
    -
    -
    -

    One Page

    -
    -
    -
    -

    Mobile Template

    -
    -
    -
    -

    Backend API

    -
    -
    -
    -
    +

    + get_tracklist() != []) { + echo "
    "; + echo "
    "; + echo "

    " . $locale['tracklist'] . "

    "; + echo "
      "; + $tracklist = $mix->get_tracklist(); + foreach ($tracklist as $track) { + echo "
    • "; + echo $track; + echo "
    • "; + } + echo "
    "; + echo "
    "; + echo "
    "; + } + + ?> +
    - -
    -
    - +
    +
    + +
    +
    +
    - + + ?>
    - - - \ No newline at end of file + \ No newline at end of file