diff options
author | deva <deva> | 2011-11-01 09:32:21 +0000 |
---|---|---|
committer | deva <deva> | 2011-11-01 09:32:21 +0000 |
commit | 42c62cb041a2b2b95c9cda0c20fcf70334fd244c (patch) | |
tree | 38371eb37ff7348585ee84438b326c25055e2cbe /utils/modules/discography.php | |
parent | 208e3b642149a9ac701a43397d31990f9b27ca79 (diff) |
Rewl og krat... needs cleaning up - after port to GIT.origin
Diffstat (limited to 'utils/modules/discography.php')
-rw-r--r-- | utils/modules/discography.php | 480 |
1 files changed, 284 insertions, 196 deletions
diff --git a/utils/modules/discography.php b/utils/modules/discography.php index 3bbce99..d390a3b 100644 --- a/utils/modules/discography.php +++ b/utils/modules/discography.php @@ -1,92 +1,100 @@ -<?php -/* -*- Mode: php; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +<?php /* -*- Mode: php; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ global $UTIL_DIR; include_once($UTIL_DIR . "/convert.php"); include_once($UTIL_DIR . "/markdown.php"); +include_once($UTIL_DIR . "/refs.php"); function time2str($t) { - $min = sprintf("%d", floor($t / 60)); - $sec = $t % 60; - return sprintf("%d:%02d", $min ,$sec); + $min = sprintf("%d", floor($t / 60)); + $sec = $t % 60; + return sprintf("%d:%02d", $min ,$sec); } function createNewlines($in) { - $str = ""; - $head = substr($in, 0, strpos($in, "\n")); - $tail = substr($in, strpos($in, "\n")+1); - $str .= "<div class=\"header\"><h2 class=\"lyrics_header\"><div class=\"header_text\">".$head."</div></h2></div>\n"; - $str .= str_replace("\n", "<br/>\n", $tail); - return $str; + $str = ""; + $head = substr($in, 0, strpos($in, "\n")); + $tail = substr($in, strpos($in, "\n")+1); + $str .= "<div class=\"header\"><h2 class=\"lyrics_header\">". + "<div class=\"header_text\">".$head."</div></h2></div>\n"; + $str .= str_replace("\n", "<br/>\n", $tail); + return $str; } class Track { - public $title; - public $number; - public $playtime; - public $previewurl; - public $lyrics; - - public function write($fp) - { - fwrite($fp, " <track title=\"" . - htmlspecialchars($this->title, ENT_QUOTES, "UTF-8") . "\"\n"); - fwrite($fp, " number=\"" . $this->number . "\"\n"); - fwrite($fp, " playtime=\"" . $this->playtime . "\"\n"); - fwrite($fp, " previewurl=\"" . $this->previewurl . "\">\n"); - fwrite($fp, " <lyrics>".htmlspecialchars($this->lyrics, ENT_QUOTES, "UTF-8")."</lyrics>\n"); - fwrite($fp, " </track>\n"); - } + public $title; + public $number; + public $playtime; + public $previewurl; + public $lyrics; - public function showLyrics() - { - $str = ""; - if($this->lyrics) { - $str .= createNewlines(htmlspecialchars_decode($this->lyrics)); - } - return $str; - } + public function write($fp) + { + fwrite($fp, " <track title=\"" . + htmlspecialchars($this->title, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " number=\"" . $this->number . "\"\n"); + fwrite($fp, " playtime=\"" . $this->playtime . "\"\n"); + fwrite($fp, " previewurl=\"" . $this->previewurl . "\">\n"); + fwrite($fp, " <lyrics>". + htmlspecialchars($this->lyrics, ENT_QUOTES, "UTF-8")."</lyrics>\n"); + fwrite($fp, " </track>\n"); + } - public function show($disc) - { - global $GLOBALS; - - $page = $GLOBALS["page"]; - $str = ""; - $str .= " <div class=\"track\">\n"; - - $str .= " <span class=\"preview\">\n"; - if($this->previewurl) { - $str .= " <object type=\"application/x-shockwave-flash\" data=\"player_mp3_maxi.swf\" width=\"25\" height=\"12\">\n"; - $str .= " <param name=\"movie\" value=\"player_mp3_maxi.swf\"/>\n"; - $str .= " <param name=\"FlashVars\" value=\"mp3=".$this->previewurl."&showslider=0&width=25&height=12&skin=design/mors/chicken.jpg\"/>\n"; - $str .= " </object>\n"; - } else { - } - $str .= " </span>\n"; - - $str .= " <span class=\"number\">".$this->number.". </span>\n"; - $str .= " <span class=\"title\">".$this->title."</span>\n"; - $str .= " <span class=\"playtime\">".time2str($this->playtime)."</span>\n"; - if($this->lyrics) { - $str .= " <a href=\"?page=".$page."&lyrics=".$disc."&track=".$this->number."\">Lyrics</a>\n"; - } - $str .= " </div>\n"; - - return $str; - } + public function showLyrics() + { + $str = ""; + if($this->lyrics) { + $str .= createNewlines(htmlspecialchars_decode($this->lyrics)); + } + return $str; + } - public function Track($title, $number, $playtime, $previewurl, $lyrics) - { - $this->title = $title; - $this->number = $number; - $this->playtime = $playtime; - $this->previewurl = $previewurl; - $this->lyrics = $lyrics; - } + public function show($disc) + { + global $GLOBALS; + + $page = $GLOBALS["page"]; + $str = ""; + $str .= " <div class=\"track\">\n"; + + $str .= " <span class=\"preview\">\n"; + if($this->previewurl) { + $str .= " <object type=\"application/x-shockwave-flash\" ". + "data=\"player_mp3_maxi.swf\" width=\"25\" height=\"12\">\n"; + $str .= " <param name=\"movie\" ". + "value=\"player_mp3_maxi.swf\"/>\n"; + $str .= " <param name=\"FlashVars\" value=\"mp3=". + $this->previewurl."&showslider=0&width=25&height=12&". + "skin=design/rotr/chicken.jpg\"/>\n"; + $str .= " </object>\n"; + } else { + } + $str .= " </span>\n"; + + $str .= " <span class=\"number\">".$this->number.". </span>\n"; + $str .= " <span class=\"title\">".$this->title."</span>\n"; + $str .= " <span class=\"playtime\">".time2str($this->playtime). + "</span>\n"; + if($this->lyrics) { + $str .= " <a href=\"?page=".$page."&lyrics=".$disc. + "&track=".$this->number."\">Lyrics</a>\n"; + } + $str .= " </div>\n"; + + return $str; + } + + public function Track($title, $number, $playtime, $previewurl, $lyrics) + { + $this->title = $title; + $this->number = $number; + $this->playtime = $playtime; + $this->previewurl = $previewurl; + $this->lyrics = $lyrics; + } } class Disc { @@ -94,88 +102,137 @@ class Disc { public $releasetime; public $description; public $cover; - public $releaser; - public $tracks = array(); - - public function write($fp) - { - fwrite($fp, " <disc title=\"" . - htmlspecialchars($this->title, ENT_QUOTES, "UTF-8") . "\"\n"); - fwrite($fp, " releasetime=\"" . $this->releasetime . "\"\n"); - fwrite($fp, " description=\"" . - htmlspecialchars($this->description, ENT_QUOTES, "UTF-8") . "\"\n"); - fwrite($fp, " cover=\"" . $this->cover . "\"\n"); - fwrite($fp, " releaser=\"" . $this->releaser . "\">\n"); - fwrite($fp, " <tracks>\n"); - if($this->tracks) { - foreach($this->tracks as $track) { - $track->write($fp); - } - } - fwrite($fp, " </tracks>\n"); - fwrite($fp, " </disc>\n"); - } + public $releaser; + public $tracks = array(); + // public $reviews = array(); + public $refs; - public function showLyrics($number) - { - $str = ""; - if($this->tracks) { - foreach($this->tracks as $track) { - if($track->number == $number) { - $str .= $track->showLyrics(); - break; - } - } - } - return $str; + public function write($fp) + { + fwrite($fp, " <disc title=\"" . + htmlspecialchars($this->title, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " releasetime=\"" . $this->releasetime . "\"\n"); + fwrite($fp, " description=\"" . + htmlspecialchars($this->description, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " cover=\"" . $this->cover . "\"\n"); + fwrite($fp, " releaser=\"" . $this->releaser . "\">\n"); + fwrite($fp, " <tracks>\n"); + if($this->tracks) { + foreach($this->tracks as $track) { + $track->write($fp); + } + } + fwrite($fp, " </tracks>\n"); + if($this->refs) $this->refs->write($fp, " "); + fwrite($fp, " </disc>\n"); + } + + public function showLyrics($number) + { + $str = ""; + if($this->tracks) { + foreach($this->tracks as $track) { + if($track->number == $number) { + $str .= $track->showLyrics(); + break; } + } + } + return $str; + } - public function show() - { - $str = ""; - - $str .= " <div class=\"disc\">\n"; - $str .= " <span class=\"record_title\">".$this->title." (".date("Y", $this->releasetime).")</span>\n"; - $str .= " <div class=\"cover\">\n"; - $str .= " <a href=\"".$this->cover."\">\n"; - $str .= " <img alt=\"".$this->title." cover\"\n"; - $str .= " src=\"?mode=imagecache&uri=" . $this->cover . "&mod=discography&cat=cover\"/>\n"; - $str .= " </a>\n"; - $str .= " </div>\n"; - $str .= " <span class=\"label\">"; - if($this->releasetime > time()) $str .= "To be"; - else $str .= "Was"; - $str .= " released by ".htmlspecialchars_decode($this->releaser)." on ".date("F jS Y", $this->releasetime)."</span>\n"; - $str .= " <span class=\"tracklist_header\">"; - if($this->tracks && sizeof($this->tracks) > 1) { - $str .= "Tracks:"; - } else { - $str .= "Track:"; - } - $str .= "</span>\n"; - $str .= " <div class=\"tracklist\">\n"; - $total = 0; - if($this->tracks) { - foreach($this->tracks as $track) { + public function show() + { + $str = ""; + + $str .= " <div class=\"disc\">\n"; + $str .= " <span class=\"record_title\">".$this->title." (". + date("Y", $this->releasetime).")</span>\n"; + $str .= " <div class=\"cover\">\n"; + $str .= " <a href=\"".$this->cover."\">\n"; + $str .= " <img alt=\"".$this->title." cover\"\n"; + $str .= " src=\"?mode=imagecache&uri=" . + $this->cover . "&mod=discography&cat=cover\"/>\n"; + $str .= " </a>\n"; + $str .= " </div>\n"; + $str .= " <span class=\"label\">"; + if($this->releasetime > time()) $str .= "To be"; + else $str .= "Was"; + $str .= " released by ".htmlspecialchars_decode($this->releaser)." on ". + date("F jS Y", $this->releasetime)."</span>\n"; + $str .= " <span class=\"tracklist_header\">"; + if($this->tracks && sizeof($this->tracks) > 1) { + $str .= "Tracks:"; + } else { + $str .= "Track:"; + } + $str .= "</span>\n"; + $str .= " <div class=\"tracklist\">\n"; + $total = 0; + if($this->tracks) { + foreach($this->tracks as $track) { $str .= $track->show($this->releasetime); $total += $track->playtime; - } - } - if($this->tracks && sizeof($this->tracks) > 1) { - $str .= " <span class=\"total_playtime\">Total playtime: ".time2str($total)."</span>\n"; - } - $str .= " </div>\n"; - $str .= " <span class=\"description\">".Markdown(htmlspecialchars_decode($this->description))."</span>\n"; - $str .= " </div>\n"; - - return $str; + } + } + if($this->tracks && sizeof($this->tracks) > 1) { + $str .= " <span class=\"total_playtime\">Total playtime: ". + time2str($total)."</span>\n"; + } + $str .= " </div>\n"; + $str .= " <span class=\"description\">". + Markdown(htmlspecialchars_decode($this->description))."</span>\n"; + + if($this->refs) $str .= $this->refs->show(); + + $str .= " </div>\n"; + + return $str; + } + + public function showCompact() + { + $str = ""; + + $str .= " <div class=\"disc\">\n"; + /* + $str .= " <span class=\"record_title\">".$this->title." (". + date("Y", $this->releasetime).")</span>\n"; + */ + $str .= " <div class=\"cover\">\n"; + $str .= " <a href=\"?page=discography\">\n"; + $str .= " <img alt=\"".$this->title." cover\"\n"; + $str .= " src=\"?mode=imagecache&uri=" . + $this->cover . "&mod=discography&cat=compactcover\"/>\n"; + $str .= " </a>\n"; + $str .= " </div>\n"; + $str .= " <span class=\"label\">"; + if($this->releasetime > time()) $str .= "Coming ".date("F jS Y", $this->releasetime); + else $str .= "Out now!"; + $str .= "</span>\n"; + $str .= " </div>\n"; + $str .= "</div>\n"; + + return $str; } - public function addTrack($track) - { - $key = $track->number; - $this->tracks[$key] = $track; - } + public function addTrack($track) + { + $key = $track->number; + $this->tracks[$key] = $track; + } + /* + public function addReview($review) + { + $key = $review->id; + $this->reviews[$key] = $review; + } + */ + + public function addRefs($refs) + { + $this->refs = $refs; + } public function Disc($title, $releasetime, $description, $cover, $releaser) { @@ -195,8 +252,8 @@ class Discography { // Admin config public $admin_title = "Discography"; public $admin_submodules = array("Add Disc" => "add", - "Edit Disc" => "edit", - "Delete Disc" => "delete"); + "Edit Disc" => "edit", + "Delete Disc" => "delete"); public function admin($sub, $action, $vars) { switch($sub) { @@ -211,36 +268,55 @@ class Discography { public function run($params) { - global $GLOBALS; + global $GLOBALS; - $str = "<div class=\"discography\">\n"; + $str = "<div class=\"discography\">\n"; - $lyrics = $GLOBALS["lyrics"]; - $number = $GLOBALS["track"]; + foreach($params as $param => $value) { + switch($param) { + case "latest": + $id = -1; + foreach($this->discs as $disc) { + if($disc->releasetime > $id) $id = $disc->releasetime; + } + if($id != -1) { + $disc = $this->discs[$id]; + return $str .= $disc->showCompact(); + } + break; + + default: + $lyrics = $GLOBALS["lyrics"]; + $number = $GLOBALS["track"]; + + //foreach($params as $param => $value) {} + + if($lyrics && $number) { + if($this->discs) { + foreach($this->discs as $disc) { + if($disc->releasetime == $lyrics) { + $str .= $disc->showLyrics($number); + break; + } + } + } + } else { + if($this->discs) { + foreach($this->discs as $disc) { + $str .= $disc->show(); + } + } + } - //foreach($params as $param => $value) {} + break; + } + } - if($lyrics && $number) { - if($this->discs) { - foreach($this->discs as $disc) { - if($disc->releasetime == $lyrics) { - $str .= $disc->showLyrics($number); - break; - } - } - } - } else { - if($this->discs) { - foreach($this->discs as $disc) { - $str .= $disc->show(); - } - } - } - $str .= "</div>\n"; + $str .= "</div>\n"; - return $str; + return $str; } public function add($disc) { @@ -248,15 +324,18 @@ class Discography { $this->discs[$key] = $disc; } - public function getImageSize($cat) - { - switch($cat) { - case "cover": - return new ImageSize($this->coverwidth, $this->coverheight); - default: - die(404); - } - } + public function getImageSize($cat) + { + switch($cat) { + case "cover": + return new ImageSize($this->coverwidth, $this->coverheight, true); + case "compactcover": + // return new ImageSize($this->compactcoverwidth, $this->compactcoverheight, true); + return new ImageSize(150, 150, true); + default: + die(404); + } + } public function write() { @@ -265,7 +344,7 @@ class Discography { fwrite($fp, "<discography>\n"); foreach($this->discs as $disc) { - $disc->write($fp); + $disc->write($fp); } fwrite($fp, "</discography>\n"); @@ -274,32 +353,34 @@ class Discography { private function read() { + $reviews = loadModule("reviews"); + $dom = new DomDocument; $dom->preserveWhiteSpace = FALSE; $dom->load($this->file); - $discography = $dom->documentElement; + $discography = $dom->documentElement; - $this->coverwidth = $discography->getAttribute('coverwidth'); - $this->coverheight = $discography->getAttribute('coverheight'); + $this->coverwidth = $discography->getAttribute('coverwidth'); + $this->coverheight = $discography->getAttribute('coverheight'); $discs = $dom->getElementsByTagName('disc'); foreach($discs as $d) { - $description = ""; - $dess = $d->getElementsByTagName('description'); - foreach($dess as $des) { + $description = ""; + $dess = $d->getElementsByTagName('description'); + foreach($dess as $des) { $description = $des->textContent; - } + } $disc = new Disc($d->getAttribute('title'), - $d->getAttribute('releasetime'), - $description, - $d->getAttribute('cover'), - $d->getAttribute('releaser')); + $d->getAttribute('releasetime'), + $description, + $d->getAttribute('cover'), + $d->getAttribute('releaser')); - $tracks = $d->getElementsByTagName('track'); - foreach($tracks as $t) { + $tracks = $d->getElementsByTagName('track'); + foreach($tracks as $t) { $lyrics = ""; $ls = $t->getElementsByTagName('lyrics'); foreach($ls as $l) { @@ -311,9 +392,16 @@ class Discography { $t->getAttribute('playtime'), $t->getAttribute('previewurl'), $lyrics); - + $disc->addTrack($track); - } + } + + $rs = $d->getElementsByTagName('refs'); + foreach($rs as $r) { + $refs = new Refs($r); + $disc->addRefs($refs); + break; + } $this->add($disc); } |