Changes.
This commit is contained in:
parent
4a5e5d224a
commit
70c8a87e15
25 changed files with 508 additions and 187 deletions
|
@ -9,7 +9,7 @@ class DJ
|
|||
private string $name = "";
|
||||
private string $bio = "";
|
||||
private string $slug = "";
|
||||
private string $img = "img/no-image1.png";
|
||||
private string $img = "/img/no-image1.png";
|
||||
private bool $active = false;
|
||||
private bool $claimed = false;
|
||||
private string $email = "";
|
||||
|
@ -17,7 +17,7 @@ class DJ
|
|||
|
||||
private string $created = "";
|
||||
private string $updated = "";
|
||||
private string $claimed_by = "";
|
||||
private string $claimedBy = "";
|
||||
private $db;
|
||||
private array $mixes = [];
|
||||
|
||||
|
@ -27,22 +27,21 @@ class DJ
|
|||
$this->db = $db;
|
||||
if (ctype_digit((string)$value)) {
|
||||
$this->id = (int)$value;
|
||||
return $this->load_from_id();
|
||||
return $this->loadByID();
|
||||
|
||||
} else {
|
||||
$this->slug = $value;
|
||||
return $this->load_from_slug();
|
||||
return $this->loadBySlug();
|
||||
}
|
||||
}
|
||||
|
||||
private function load_from_id(): bool
|
||||
private function loadByID(): bool
|
||||
{
|
||||
$socials = [];
|
||||
$dj = $this->get_dj_by_id($this->id);
|
||||
return $this->build_dj($dj);
|
||||
$dj = $this->getDJbyID($this->id);
|
||||
return $this->buildDJ($dj);
|
||||
}
|
||||
|
||||
private function get_dj_by_id()
|
||||
private function getDJbyID()
|
||||
{
|
||||
$stmt = $this->db->prepare("SELECT * FROM djs WHERE id = ?");
|
||||
$stmt->bind_param("i", $this->id);
|
||||
|
@ -57,7 +56,7 @@ class DJ
|
|||
* @param $dj
|
||||
* @return bool
|
||||
*/
|
||||
private function build_dj($dj): bool
|
||||
private function buildDJ($dj): bool
|
||||
{
|
||||
if ($dj) {
|
||||
if (isset($dj['id'])) {
|
||||
|
@ -130,7 +129,7 @@ class DJ
|
|||
$this->updated = $dj['lastupdated'];
|
||||
}
|
||||
|
||||
$this->load_dj_mixes();
|
||||
$this->loadDJMixes();
|
||||
|
||||
return true;
|
||||
} else {
|
||||
|
@ -138,7 +137,7 @@ class DJ
|
|||
}
|
||||
}
|
||||
|
||||
private function load_dj_mixes(): void
|
||||
private function loadDJMixes(): void
|
||||
{
|
||||
$stmt = $this->db->prepare("SELECT * FROM mix WHERE dj1 = ? OR dj2 = ? OR dj3 = ?");
|
||||
$stmt->bind_param("iii", $this->id, $this->id, $this->id);
|
||||
|
@ -154,14 +153,14 @@ class DJ
|
|||
|
||||
}
|
||||
|
||||
private function load_from_slug(): bool
|
||||
private function loadBySlug(): bool
|
||||
{
|
||||
$socials = [];
|
||||
$dj = $this->get_dj_by_slug($this->slug);
|
||||
return $this->build_dj($dj);
|
||||
$dj = $this->getDJbySlug($this->slug);
|
||||
return $this->buildDJ($dj);
|
||||
}
|
||||
|
||||
private function get_dj_by_slug($slug)
|
||||
private function getDJbySlug($slug)
|
||||
{
|
||||
$stmt = $this->db->prepare("SELECT * FROM djs WHERE slug = ?");
|
||||
$stmt->bind_param("s", $slug);
|
||||
|
@ -172,63 +171,70 @@ class DJ
|
|||
return $dj;
|
||||
}
|
||||
|
||||
public function get_slug(): string
|
||||
public function getSlug(): string
|
||||
{
|
||||
return $this->slug;
|
||||
}
|
||||
|
||||
public function get_id(): int
|
||||
public function getID(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function get_name(): string
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function get_bio(): string
|
||||
public function getBio(): string
|
||||
{
|
||||
return $this->bio;
|
||||
}
|
||||
|
||||
public function get_img(): string
|
||||
public function getImg(): string
|
||||
{
|
||||
return $this->img;
|
||||
}
|
||||
|
||||
public function get_active(): bool
|
||||
public function getActive(): bool
|
||||
{
|
||||
return $this->active;
|
||||
}
|
||||
|
||||
public function get_email(): string
|
||||
public function getEmail(): string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
public function get_socials(): array
|
||||
public function getSocials(): array
|
||||
{
|
||||
return $this->socials;
|
||||
}
|
||||
|
||||
public function get_created(): string
|
||||
public function getCreated(): string
|
||||
{
|
||||
return $this->created;
|
||||
}
|
||||
|
||||
public function get_updated(): string
|
||||
public function getUpdated(): string
|
||||
{
|
||||
return $this->updated;
|
||||
}
|
||||
|
||||
public function get_claimed(): bool
|
||||
public function getClaimed(): bool
|
||||
{
|
||||
return $this->claimed;
|
||||
}
|
||||
|
||||
public function get_dj_mixes()
|
||||
public function getDJMixes()
|
||||
{
|
||||
return $this->mixes;
|
||||
}
|
||||
|
||||
public function getClaimedBy()
|
||||
{
|
||||
return $this->claimedBy;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -49,4 +49,4 @@ class DJs
|
|||
$stmt->close();
|
||||
return $djs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,4 +13,4 @@ class Database extends mysqli
|
|||
// call the parent constructor with the config file
|
||||
parent::__construct($config['database']['host'], $config['database']['user'], $config['database']['pass'], $config['database']['db'], $config['database']['port'] ?? 3306);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
106
classes/DownloadMix.php
Normal file
106
classes/DownloadMix.php
Normal file
|
@ -0,0 +1,106 @@
|
|||
<?php
|
||||
|
||||
namespace DJMixHosting;
|
||||
|
||||
class DownloadMix
|
||||
{
|
||||
private $db;
|
||||
private $mix;
|
||||
private $ready = false;
|
||||
private $name;
|
||||
private $djs;
|
||||
private $filename;
|
||||
private $url;
|
||||
private $mix_id;
|
||||
private $content;
|
||||
private $filesize = 0;
|
||||
private $ext;
|
||||
|
||||
|
||||
public function __construct($mix, $db)
|
||||
{
|
||||
$this->db = $db;
|
||||
$this->mix = $mix;
|
||||
$this->mix_id = $mix->get_id();
|
||||
$this->preDownload();
|
||||
}
|
||||
|
||||
private function preDownload()
|
||||
{
|
||||
$this->name = $this->mix->get_name();
|
||||
$buildDJs = $this->mix->get_djs();
|
||||
$this->url = $this->mix->get_url();
|
||||
$this->djs = '';
|
||||
$djCount = 0;
|
||||
foreach ($buildDJs as $dj) {
|
||||
if ($djCount > 0) {
|
||||
$this->djs .= ', ';
|
||||
}
|
||||
$this->djs .= $dj->getName();
|
||||
$djCount++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function download()
|
||||
{
|
||||
$this->loadDownload();
|
||||
if (!$this->ready) {
|
||||
echo "I had a problem downloading the file.";
|
||||
return;
|
||||
} else {
|
||||
if ($this->checkForMixDownloadCount()) {
|
||||
$this->incrementMixDownloadCount();
|
||||
} else {
|
||||
$this->addMixDownloadCount();
|
||||
}
|
||||
header("Content-Description: File Transfer");
|
||||
header("Content-Type: application/octet-stream");
|
||||
header("Content-Disposition: attachment; filename=\"" . $this->filename . "\"");
|
||||
echo $this->content;
|
||||
}
|
||||
}
|
||||
|
||||
private function loadDownload()
|
||||
{
|
||||
$this->content = file_get_contents($this->url);
|
||||
$this->filesize = strlen($this->content);
|
||||
$this->ext = pathinfo(basename($this->url), PATHINFO_EXTENSION);
|
||||
$this->filename = $this->djs . ' - ' . $this->name . ' (Downloaded from UtahsDJs.com).' . pathinfo(basename($this->url), PATHINFO_EXTENSION);
|
||||
if ($this->filesize > 0) {
|
||||
$this->ready = true;
|
||||
}
|
||||
}
|
||||
|
||||
private function checkForMixDownloadCount()
|
||||
{
|
||||
$stmt = $this->db->prepare("SELECT * FROM mix_meta WHERE attribute = 'downloads' and mix_id = ?");
|
||||
$stmt->bind_param('i', $this->mix_id);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$row = $result->fetch_assoc();
|
||||
$stmt->close();
|
||||
if ($row) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private function incrementMixDownloadCount()
|
||||
{
|
||||
$stmt = $this->db->prepare("UPDATE mix_meta SET value = value + 1 WHERE attribute = 'downloads' and mix_id = ?");
|
||||
$stmt->bind_param('i', $this->mix_id);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
}
|
||||
|
||||
private function addMixDownloadCount()
|
||||
{
|
||||
$stmt = $this->db->prepare("INSERT INTO mix_meta (mix_id, attribute, value) VALUES (?, 'downloads', 1)");
|
||||
$stmt->bind_param('i', $this->mix_id);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
}
|
||||
|
||||
}
|
|
@ -96,7 +96,7 @@ class Genre
|
|||
|
||||
public function get_img(): string
|
||||
{
|
||||
return "img/no-image1.png";
|
||||
return "/img/no-image1.png";
|
||||
}
|
||||
|
||||
public function get_count(): int
|
||||
|
@ -123,4 +123,4 @@ class Genre
|
|||
return $mixes;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,4 +52,4 @@ class Genres
|
|||
$stmt->close();
|
||||
return $genres;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,19 +76,8 @@ class Mix
|
|||
$this->name = $mix['title'];
|
||||
$this->slug = $mix['slug'];
|
||||
$this->description = $mix['description'];
|
||||
if (isset($mix['cover'])) {
|
||||
|
||||
// is this legacy code?
|
||||
// the code is legacy if it starts with /dj/,
|
||||
// if it does, prefix with https://www.utahsdjs.com
|
||||
if (substr($mix['cover'], 0, 5) == "/djs/") {
|
||||
$mix['cover'] = substr($mix['cover'], 4);
|
||||
$this->cover = "https://cdn.utahsdjs.com" . $mix['cover'];
|
||||
} else {
|
||||
$this->cover = $mix['cover'];
|
||||
}
|
||||
}
|
||||
$this->url = $mix['url'];
|
||||
$this->cover = $this->legacyFix($mix['cover']);
|
||||
$this->url = $this->legacyFix($mix['url']);
|
||||
$this->seconds = $mix['seconds'];
|
||||
$this->duration = $this->configure_duration();
|
||||
$this->download_only = $mix['mediaplayer'];
|
||||
|
@ -114,6 +103,15 @@ class Mix
|
|||
return true;
|
||||
}
|
||||
|
||||
private function legacyFix(mixed $item)
|
||||
{
|
||||
if (str_starts_with($item, "/djs/")) {
|
||||
return "https://cdn.utahsdjs.com" . substr($item, 4);
|
||||
} else {
|
||||
return $item;
|
||||
}
|
||||
}
|
||||
|
||||
private function configure_duration(): array
|
||||
{
|
||||
$seconds = $this->seconds;
|
||||
|
@ -201,14 +199,18 @@ class Mix
|
|||
private function load_by_slug(): bool
|
||||
{
|
||||
$mix = $this->get_mix_by_slug();
|
||||
|
||||
if ($mix['title'] != "") {
|
||||
return $this->build_mix($mix);
|
||||
if ($mix) {
|
||||
if ($mix['title'] != "") {
|
||||
return $this->build_mix($mix);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function get_mix_by_slug()
|
||||
{
|
||||
$stmt = $this->db->prepare("SELECT * FROM mix WHERE slug = ?");
|
||||
|
@ -235,7 +237,7 @@ class Mix
|
|||
return $this->updated;
|
||||
}
|
||||
|
||||
public function get_img(): string
|
||||
public function get_img()
|
||||
{
|
||||
return $this->cover;
|
||||
}
|
||||
|
@ -275,7 +277,7 @@ class Mix
|
|||
return $this->url;
|
||||
}
|
||||
|
||||
public function get_cover(): string
|
||||
public function get_cover()
|
||||
{
|
||||
return $this->cover;
|
||||
}
|
||||
|
@ -316,5 +318,3 @@ class Mix
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ class Mixshow
|
|||
private $slug = "";
|
||||
private $db = null;
|
||||
private $description = "";
|
||||
private $cover = "img/no-image1.png";
|
||||
private $cover = "/img/no-image1.png";
|
||||
private $count;
|
||||
private $mixes = [];
|
||||
private $updated;
|
||||
|
@ -145,4 +145,4 @@ class Mixshow
|
|||
return $this->updated;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,4 +52,4 @@ class Mixshows
|
|||
$stmt->close();
|
||||
return $mixshows;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
61
classes/Playcount.php
Normal file
61
classes/Playcount.php
Normal file
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
namespace DJMixHosting;
|
||||
|
||||
class Playcount
|
||||
{
|
||||
|
||||
private $db;
|
||||
private $mix_id;
|
||||
|
||||
public function __construct($mix, $db)
|
||||
{
|
||||
$this->db = $db;
|
||||
$this->mix_id = $mix;
|
||||
}
|
||||
|
||||
public function getPlaycount()
|
||||
{
|
||||
$sql = "SELECT value FROM mix_meta WHERE mix_id = ? AND attribute = 'playcount'";
|
||||
$stmt = $this->db->prepare($sql);
|
||||
$stmt->execute([$this->mix_id]);
|
||||
$result = $stmt->get_result();
|
||||
$row = $result->fetch_assoc();
|
||||
return $row['value'];
|
||||
}
|
||||
|
||||
public function updatePlaycount(): void
|
||||
{
|
||||
if ($this->checkForPlaycount()) {
|
||||
$this->incrementPlaycount();
|
||||
} else {
|
||||
$this->addPlaycount();
|
||||
}
|
||||
}
|
||||
|
||||
private function checkForPlaycount()
|
||||
{
|
||||
$sql = "SELECT meta_id FROM mix_meta WHERE mix_id = ? AND attribute = 'playcount'";
|
||||
$stmt = $this->db->prepare($sql);
|
||||
$stmt->bind_param('i', $this->mix_id);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
return $result->fetch_assoc();
|
||||
}
|
||||
|
||||
private function incrementPlaycount()
|
||||
{
|
||||
$sql = "UPDATE mix_meta SET value = value + 1 WHERE mix_id = ? AND attribute = 'playcount'";
|
||||
$stmt = $this->db->prepare($sql);
|
||||
$stmt->execute([$this->mix_id]);
|
||||
}
|
||||
|
||||
public function addPlaycount()
|
||||
{
|
||||
$sql = "INSERT INTO mix_meta (mix_id, attribute, value) VALUES (?, 'playcount', 1)";
|
||||
$stmt = $this->db->prepare($sql);
|
||||
$stmt->execute([$this->mix_id]);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -59,4 +59,4 @@ class Schema
|
|||
*/
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue