1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
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."&showslider=0&width=25&height=12&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&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&uri=" . $this->cover . "&mw=200&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");
}
?>
|