From af2ce991eed7d22831aaed980828b624e787470f Mon Sep 17 00:00:00 2001 From: deva Date: Fri, 22 Jan 2010 19:51:04 +0000 Subject: Added Discography module --- utils/modules/discography.php | 249 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 249 insertions(+) create mode 100644 utils/modules/discography.php diff --git a/utils/modules/discography.php b/utils/modules/discography.php new file mode 100644 index 0000000..9913113 --- /dev/null +++ b/utils/modules/discography.php @@ -0,0 +1,249 @@ +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, " ".htmlspecialchars($this->lyrics, ENT_QUOTES, "UTF-8")."\n"); + fwrite($fp, " \n"); + } + + public function show() + { + $str = ""; + $str .= "
\n"; + + $str .= "
\n"; + if($this->previewurl) { + $str .= " \n"; + $str .= " \n"; + $str .= " previewurl."&showslider=0&width=25&height=12&skin=gfx/chicken.jpg\"/>\n"; + $str .= " \n"; + } else { + } + $str .= "
\n"; + + $str .= "
".$this->number.".
\n"; + $str .= "
".$this->title."
\n"; + $str .= "
".time2str($this->playtime)."
\n"; + if($this->lyrics) { + $str .= " Lyrics\n"; + } + $str .= "
\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 { + public $title; + public $releasetime; + public $description; + public $cover; + public $releaser; + public $tracks = array(); + + public function write($fp) + { + fwrite($fp, " 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, " \n"); + if($this->tracks) { + foreach($this->tracks as $track) { + $track->write($fp); + } + } + fwrite($fp, " \n"); + fwrite($fp, " \n"); + } + + public function show() + { + $str = ""; + + $str .= "
\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 .= "
\n"; + $total = 0; + if($this->tracks) { + foreach($this->tracks as $track) { + $str .= $track->show(); + $total += $track->playtime; + } + } + $str .= "
Total playtime: ".time2str($total)."
\n"; + $str .= "
\n"; + $str .= "
".$this->description."
\n"; + $str .= "
\n"; + + return $str; + } + + public function addTrack($track) + { + $key = $track->number; + $this->tracks[$key] = $track; + } + + public function Disc($title, $releasetime, $description, $cover, $releaser) + { + $this->title = $title; + $this->releasetime = $releasetime; + $this->description = $description; + $this->cover = $cover; + $this->releaser = $releaser; + } +} + +class Discography { + + private $file; + private $discs = array(); + + // Admin config + public $admin_title = "Discography"; + public $admin_submodules = array("Add Disc" => "add", + "Edit Disc" => "edit", + "Delete Disc" => "delete"); + public function admin($sub, $action, $vars) + { + switch($sub) { + case "add": + break; + case "edit": + break; + case "delete": + break; + } + } + + public function run($params) + { + $str = "
\n"; + + if($this->discs) { + foreach($this->discs as $disc) { + $str .= $disc->show(); + } + } + + $str .= "
\n"; + + return $str; + } + + public function add($disc) { + $key = $disc->releasetime; + $this->discs[$key] = $disc; + } + + public function write() + { + $fp = fopen($this->file, "w"); + fwrite($fp, "\n"); + + fwrite($fp, "\n"); + foreach($this->discs as $disc) { + $disc->write($fp); + } + fwrite($fp, "\n"); + + fclose($fp); + } + + private function read() + { + $dom = new DomDocument; + $dom->preserveWhiteSpace = FALSE; + $dom->load($this->file); + $discs = $dom->getElementsByTagName('disc'); + + foreach($discs as $d) { + $disc = new Disc($d->getAttribute('title'), + $d->getAttribute('releasetime'), + $d->getAttribute('description'), + $d->getAttribute('cover'), + $d->getAttribute('releaser')); + + $tracks = $d->getElementsByTagName('track'); + foreach($tracks as $t) { + $lyrics = ""; + $ls = $t->getElementsByTagName('lyrics'); + foreach($ls as $l) { + $lyrics = $l->textContent; + } + + $track = new Track($t->getAttribute('title'), + $t->getAttribute('number'), + $t->getAttribute('playtime'), + $t->getAttribute('previewurl'), + $lyrics); + + $disc->addTrack($track); + } + + $this->add($disc); + } + } + + public function Discography($file) + { + $this->file = $file; + if(file_exists($file)) $this->read(); + } + +} + +function discography_init() +{ + global $DATA_DIR; + return new Discography($DATA_DIR . "/discography.xml"); +} + +?> -- cgit v1.2.3