summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/modules/discography.php249
1 files changed, 249 insertions, 0 deletions
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 @@
+<?php
+/* -*- Mode: php; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+include_once($UTIL_DIR . "/convert.php");
+include_once($UTIL_DIR . "/markdown.php");
+
+function time2str($t)
+{
+ $min = sprintf("%d", floor($t / 60));
+ $sec = $t % 60;
+ return sprintf("%d:%02d", $min ,$sec);
+}
+
+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 function show()
+ {
+ $str = "";
+ $str .= " <div class=\"track\">\n";
+
+ $str .= " <div 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."&amp;showslider=0&amp;width=25&amp;height=12&amp;skin=gfx/chicken.jpg\"/>\n";
+ $str .= " </object>\n";
+ } else {
+ }
+ $str .= " </div>\n";
+
+ $str .= " <div class=\"number\">".$this->number.". </div>\n";
+ $str .= " <div class=\"title\">".$this->title."</div>\n";
+ $str .= " <div class=\"playtime\">".time2str($this->playtime)."</div>\n";
+ if($this->lyrics) {
+ $str .= " <a href=\"?page=lyrics&amp;name=morsetsanguis\">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 {
+ public $title;
+ 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 function show()
+ {
+ $str = "";
+
+ $str .= " <div class=\"disc\">\n";
+ $str .= " <div class=\"cover\">\n";
+ $str .= " <a href=\"".$this->cover."\">\n";
+ $str .= " <img alt=\"".$this->title." cover\"\n";
+ $str .= " src=\"?mode=imagecache&amp;uri=" . $this->cover . "&amp;mw=200&amp;mh=200\"/>\n";
+ $str .= " </a>\n";
+ $str .= " </div>\n";
+ $str .= " <div class=\"record_title\">".$this->title." (".date("Y", $this->releasetime).")</div>\n";
+ $str .= " <div class=\"label\">";
+ if($this->releasetime > time()) $str .= "To be";
+ else $str .= "Was";
+ $str .= " released on ".$this->releaser.", ".date("F jS Y", $this->releasetime)."</div>\n";
+ $str .= " <div class=\"traclist_header\">Tracks:</div>\n";
+ $str .= " <div class=\"tracklist\">\n";
+ $total = 0;
+ if($this->tracks) {
+ foreach($this->tracks as $track) {
+ $str .= $track->show();
+ $total += $track->playtime;
+ }
+ }
+ $str .= " <div class=\"total_playtime\">Total playtime: ".time2str($total)."</div>\n";
+ $str .= " </div>\n";
+ $str .= " <div class=\"description\">".$this->description."</div>\n";
+ $str .= " </div>\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 = "<div class=\"discography\">\n";
+
+ if($this->discs) {
+ foreach($this->discs as $disc) {
+ $str .= $disc->show();
+ }
+ }
+
+ $str .= "</div>\n";
+
+ return $str;
+ }
+
+ public function add($disc) {
+ $key = $disc->releasetime;
+ $this->discs[$key] = $disc;
+ }
+
+ public function write()
+ {
+ $fp = fopen($this->file, "w");
+ fwrite($fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
+
+ fwrite($fp, "<discography>\n");
+ foreach($this->discs as $disc) {
+ $disc->write($fp);
+ }
+ fwrite($fp, "</discography>\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");
+}
+
+?>