Address changes.

This commit is contained in:
Cody Cook 2025-02-22 17:20:19 -08:00
commit 635b3ddcbc
59 changed files with 7249 additions and 2745 deletions

View file

@ -4,32 +4,32 @@ namespace DJMixHosting;
class DownloadMix
{
private $db;
private $mix;
private $ready = false;
private $name;
private $djs;
private $filename;
private $url;
private $mix_id;
private Database $db;
private Mix $mix;
private bool $ready = false;
private string $name;
private string $djs;
private string $filename;
private string $url;
private int $mix_id;
private $content;
private $filesize = 0;
private $ext;
private int $filesize = 0;
private string $ext;
public function __construct($mix, $db)
{
$this->db = $db;
$this->mix = $mix;
$this->mix_id = $mix->get_id();
$this->mix_id = $mix->getId();
$this->preDownload();
}
private function preDownload()
private function preDownload(): void
{
$this->name = $this->mix->get_name();
$buildDJs = $this->mix->get_djs();
$this->url = $this->mix->get_url();
$this->name = $this->mix->getName();
$buildDJs = $this->mix->getDJs();
$this->url = $this->mix->getUrl();
$this->djs = '';
$djCount = 0;
foreach ($buildDJs as $dj) {
@ -42,7 +42,7 @@ class DownloadMix
}
public function download()
public function download(): void
{
$this->loadDownload();
if (!$this->ready) {
@ -56,23 +56,24 @@ class DownloadMix
}
header("Content-Description: File Transfer");
header("Content-Type: application/octet-stream");
header("Content-Length: " . $this->filesize);
header("Content-Disposition: attachment; filename=\"" . $this->filename . "\"");
echo $this->content;
}
}
private function loadDownload()
private function loadDownload(): void
{
$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);
$this->filename = $this->djs . ' - ' . $this->name . ' (Downloaded from UtahsDJs.com).' . $this->ext;
if ($this->filesize > 0) {
$this->ready = true;
}
}
private function checkForMixDownloadCount()
private function checkForMixDownloadCount(): bool
{
$stmt = $this->db->prepare("SELECT * FROM mix_meta WHERE attribute = 'downloads' and mix_id = ?");
$stmt->bind_param('i', $this->mix_id);
@ -87,7 +88,7 @@ class DownloadMix
}
}
private function incrementMixDownloadCount()
private function incrementMixDownloadCount(): void
{
$stmt = $this->db->prepare("UPDATE mix_meta SET value = value + 1 WHERE attribute = 'downloads' and mix_id = ?");
$stmt->bind_param('i', $this->mix_id);
@ -95,7 +96,7 @@ class DownloadMix
$stmt->close();
}
private function addMixDownloadCount()
private function addMixDownloadCount(): void
{
$stmt = $this->db->prepare("INSERT INTO mix_meta (mix_id, attribute, value) VALUES (?, 'downloads', 1)");
$stmt->bind_param('i', $this->mix_id);
@ -103,4 +104,9 @@ class DownloadMix
$stmt->close();
}
public function getExt(): string
{
return $this->ext;
}
}