From 3b632ba6ef388405f3f21edeb1bf83f1ed0a71f9 Mon Sep 17 00:00:00 2001 From: deva Date: Mon, 25 Jan 2010 15:45:36 +0000 Subject: Added lyrics. Modfied layout. Added markup of textual sections. Reworked xml format. --- utils/modules/discography.php | 92 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 79 insertions(+), 13 deletions(-) (limited to 'utils/modules') diff --git a/utils/modules/discography.php b/utils/modules/discography.php index 9913113..478fdc0 100644 --- a/utils/modules/discography.php +++ b/utils/modules/discography.php @@ -11,6 +11,16 @@ function time2str($t) 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 .= "

".$head."

\n"; + $str .= str_replace("\n", "
\n", $tail); + return $str; +} + class Track { public $title; public $number; @@ -29,8 +39,20 @@ class Track { fwrite($fp, " \n"); } - public function show() + public function showLyrics() + { + $str = ""; + if($this->lyrics) { + $str .= createNewlines(htmlspecialchars_decode($this->lyrics)); + } + return $str; + } + + public function show($disc) { + global $GLOBALS; + + $page = $GLOBALS["page"]; $str = ""; $str .= "
\n"; @@ -48,7 +70,7 @@ class Track { $str .= "
".$this->title."
\n"; $str .= "
".time2str($this->playtime)."
\n"; if($this->lyrics) { - $str .= " Lyrics\n"; + $str .= " number."\">Lyrics\n"; } $str .= "
\n"; @@ -92,34 +114,56 @@ class Disc { fwrite($fp, " \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 .= "
\n"; + $str .= "
".$this->title." (".date("Y", $this->releasetime).")
\n"; $str .= " \n"; - $str .= "
".$this->title." (".date("Y", $this->releasetime).")
\n"; $str .= "
"; if($this->releasetime > time()) $str .= "To be"; else $str .= "Was"; - $str .= " released on ".$this->releaser.", ".date("F jS Y", $this->releasetime)."
\n"; - $str .= "
Tracks:
\n"; + $str .= " released by ".htmlspecialchars_decode($this->releaser)." on ".date("F jS Y", $this->releasetime)."
\n"; + $str .= "
"; + if($this->tracks && sizeof($this->tracks) > 1) { + $str .= "Tracks:"; + } else { + $str .= "Track:"; + } + $str .= "
\n"; $str .= "
\n"; $total = 0; - if($this->tracks) { + if($this->tracks) { foreach($this->tracks as $track) { - $str .= $track->show(); + $str .= $track->show($this->releasetime); $total += $track->playtime; } } - $str .= "
Total playtime: ".time2str($total)."
\n"; + if($this->tracks && sizeof($this->tracks) > 1) { + $str .= "
Total playtime: ".time2str($total)."
\n"; + } $str .= "
\n"; - $str .= "
".$this->description."
\n"; + $str .= "
".Markdown(htmlspecialchars_decode($this->description))."
\n"; $str .= " \n"; return $str; @@ -165,11 +209,27 @@ class Discography { public function run($params) { + global $GLOBALS; + $str = "
\n"; - if($this->discs) { - foreach($this->discs as $disc) { - $str .= $disc->show(); + $lyrics = $GLOBALS["lyrics"]; + $number = $GLOBALS["track"]; + + 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(); + } } } @@ -205,9 +265,15 @@ class Discography { $discs = $dom->getElementsByTagName('disc'); foreach($discs as $d) { + $description = ""; + $dess = $d->getElementsByTagName('description'); + foreach($dess as $des) { + $description = $des->textContent; + } + $disc = new Disc($d->getAttribute('title'), $d->getAttribute('releasetime'), - $d->getAttribute('description'), + $description, $d->getAttribute('cover'), $d->getAttribute('releaser')); -- cgit v1.2.3