author | Dan |
Fri, 12 Jun 2009 11:57:08 -0400 | |
changeset 74 | 7719085707d8 |
parent 44 | 92dd253f501c |
permissions | -rw-r--r-- |
0
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
1 |
<?php |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
2 |
|
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
3 |
/** |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
4 |
* Playlist displayer |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
5 |
* |
6
5f35ebc4f9bb
First release version. Renamed to Greyhound and readme/license files added.
Dan
parents:
5
diff
changeset
|
6 |
* Greyhound - real web management for Amarok |
5
9b96265b5918
Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents:
4
diff
changeset
|
7 |
* Copyright (C) 2008 Dan Fuhry |
0
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
8 |
* |
5
9b96265b5918
Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents:
4
diff
changeset
|
9 |
* This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License |
9b96265b5918
Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents:
4
diff
changeset
|
10 |
* as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
9b96265b5918
Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents:
4
diff
changeset
|
11 |
* |
9b96265b5918
Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents:
4
diff
changeset
|
12 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
9b96265b5918
Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents:
4
diff
changeset
|
13 |
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. |
0
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
14 |
*/ |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
15 |
|
21
74edc873234f
Made the webserver a bit smarter. It handles running as root properly (only allows it if user/group specified and port < 1024) and directory listing is massively smarter.
Dan
parents:
10
diff
changeset
|
16 |
function amarok_playlist($httpd, $socket) |
0
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
17 |
{ |
4 | 18 |
global $theme, $playlist, $allowcontrol; |
44
92dd253f501c
First shot at getting a session management system in place. Login and logout pages are there, and auth seems to be working and sufficiently secure for the moment. Sessions last indefinitely and are cookie-based.
Dan
parents:
40
diff
changeset
|
19 |
global $use_auth; |
21
74edc873234f
Made the webserver a bit smarter. It handles running as root properly (only allows it if user/group specified and port < 1024) and directory listing is massively smarter.
Dan
parents:
10
diff
changeset
|
20 |
|
44
92dd253f501c
First shot at getting a session management system in place. Login and logout pages are there, and auth seems to be working and sufficiently secure for the moment. Sessions last indefinitely and are cookie-based.
Dan
parents:
40
diff
changeset
|
21 |
if ( !session_check() ) |
21
74edc873234f
Made the webserver a bit smarter. It handles running as root properly (only allows it if user/group specified and port < 1024) and directory listing is massively smarter.
Dan
parents:
10
diff
changeset
|
22 |
{ |
44
92dd253f501c
First shot at getting a session management system in place. Login and logout pages are there, and auth seems to be working and sufficiently secure for the moment. Sessions last indefinitely and are cookie-based.
Dan
parents:
40
diff
changeset
|
23 |
$httpd->header('HTTP/1.1 307 Temporary Redirect'); |
92dd253f501c
First shot at getting a session management system in place. Login and logout pages are there, and auth seems to be working and sufficiently secure for the moment. Sessions last indefinitely and are cookie-based.
Dan
parents:
40
diff
changeset
|
24 |
$httpd->header('Location: /login'); |
92dd253f501c
First shot at getting a session management system in place. Login and logout pages are there, and auth seems to be working and sufficiently secure for the moment. Sessions last indefinitely and are cookie-based.
Dan
parents:
40
diff
changeset
|
25 |
|
92dd253f501c
First shot at getting a session management system in place. Login and logout pages are there, and auth seems to be working and sufficiently secure for the moment. Sessions last indefinitely and are cookie-based.
Dan
parents:
40
diff
changeset
|
26 |
return; |
21
74edc873234f
Made the webserver a bit smarter. It handles running as root properly (only allows it if user/group specified and port < 1024) and directory listing is massively smarter.
Dan
parents:
10
diff
changeset
|
27 |
} |
4 | 28 |
|
10
d3059e20b0fa
SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
6
diff
changeset
|
29 |
$iphone = ( ( strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') || |
4 | 30 |
strpos($_SERVER['HTTP_USER_AGENT'], 'iPod') || |
31 |
strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') || |
|
10
d3059e20b0fa
SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
6
diff
changeset
|
32 |
isset($_GET['m']) ) |
d3059e20b0fa
SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
6
diff
changeset
|
33 |
&& !isset($_GET['f']) |
4 | 34 |
); |
35 |
$theme_id = ( $iphone ) ? 'iphone' : $theme; |
|
36 |
$smarty = load_theme($theme_id); |
|
0
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
37 |
|
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
38 |
$active = dcop_action('playlist', 'getActiveIndex'); |
4 | 39 |
$smarty->assign('theme', $theme_id); |
0
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
40 |
$smarty->assign('playlist', $playlist); |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
41 |
$smarty->assign('active', $active); |
1 | 42 |
$smarty->assign('scripts', array( |
43 |
'ajax.js', |
|
2
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
1
diff
changeset
|
44 |
'domutils.js', |
10
d3059e20b0fa
SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
6
diff
changeset
|
45 |
'volume.js', |
d3059e20b0fa
SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
6
diff
changeset
|
46 |
'dom-drag.js', |
d3059e20b0fa
SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
6
diff
changeset
|
47 |
'position.js' |
1 | 48 |
)); |
3
e7447a6044ec
$allowcontrol = false working and turned on now; switched default port back to 7447 instead of random; added favicon and apple-touch-icon
Dan
parents:
2
diff
changeset
|
49 |
$smarty->assign('allow_control', $allowcontrol); |
44
92dd253f501c
First shot at getting a session management system in place. Login and logout pages are there, and auth seems to be working and sufficiently secure for the moment. Sessions last indefinitely and are cookie-based.
Dan
parents:
40
diff
changeset
|
50 |
$smarty->assign('use_auth', $use_auth); |
92dd253f501c
First shot at getting a session management system in place. Login and logout pages are there, and auth seems to be working and sufficiently secure for the moment. Sessions last indefinitely and are cookie-based.
Dan
parents:
40
diff
changeset
|
51 |
$smarty->assign('greyhound_version', GREY_VERSION); |
40
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
52 |
$smarty->register_function('sprite', 'smarty_function_sprite'); |
0
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
53 |
$smarty->display('playlist.tpl'); |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
54 |
} |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
55 |
|
25 | 56 |
function artwork_request_handler($httpd, $socket) |
57 |
{ |
|
33
3b4aef1efff6
Removed requirement for detecting home directory; artwork fetcher relies on return from saveCurrentPlaylist now
Dan
parents:
25
diff
changeset
|
58 |
global $amarok_home; |
25 | 59 |
|
40
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
60 |
// get PATH_INFO |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
61 |
$pathinfo = @substr(@substr($_SERVER['REQUEST_URI'], 1), @strpos(@substr($_SERVER['REQUEST_URI'], 1), '/')+1); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
62 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
63 |
// should we do a collage (for CSS sprites instead of sending hundreds of individual images)? |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
64 |
if ( preg_match('/^collage(?:\/([0-9]+))?$/', $pathinfo, $match) ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
65 |
{ |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
66 |
// default size is 50px per image |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
67 |
$collage_size = ( isset($match[1]) ) ? intval($match[1]) : 50; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
68 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
69 |
$artwork_dir = "$amarok_home/albumcovers"; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
70 |
if ( !file_exists("$artwork_dir/collage_{$collage_size}.png") ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
71 |
{ |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
72 |
if ( !generate_artwork_collage("$artwork_dir/collage_{$collage_size}.png", $collage_size) ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
73 |
{ |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
74 |
echo 'Error: generate_artwork_collage() failed'; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
75 |
return; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
76 |
} |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
77 |
} |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
78 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
79 |
$target_file = "$artwork_dir/collage_{$collage_size}.png"; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
80 |
// we have it now, send the image through |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
81 |
$fh = @fopen($target_file, 'r'); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
82 |
if ( !$fh ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
83 |
return false; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
84 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
85 |
$httpd->header('Content-type: image/png'); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
86 |
$httpd->header('Content-length: ' . filesize($target_file)); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
87 |
$httpd->header('Expires: Wed, 1 Jan 2020 01:00:00 GMT'); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
88 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
89 |
// kinda sorta a hack. |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
90 |
$headers = implode("\r\n", $httpd->response_headers); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
91 |
$httpd->send_client_headers($socket, $httpd->response_code, $httpd->content_type, $headers); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
92 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
93 |
while ( $d = fread($fh, 10240) ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
94 |
{ |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
95 |
$socket->write($d); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
96 |
} |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
97 |
fclose($fh); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
98 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
99 |
return; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
100 |
} |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
101 |
|
25 | 102 |
if ( !isset($_GET['artist']) || !isset($_GET['album']) ) |
103 |
{ |
|
104 |
echo 'Please specify artist and album.'; |
|
105 |
return; |
|
106 |
} |
|
107 |
// get hash |
|
108 |
$artwork_hash = md5( strtolower(trim($_GET['artist'])) . strtolower(trim($_GET['album'])) ); |
|
33
3b4aef1efff6
Removed requirement for detecting home directory; artwork fetcher relies on return from saveCurrentPlaylist now
Dan
parents:
25
diff
changeset
|
109 |
$artwork_dir = "$amarok_home/albumcovers"; |
25 | 110 |
if ( file_exists("$artwork_dir/large/$artwork_hash") ) |
111 |
{ |
|
112 |
// artwork file found - scale and convert to PNG |
|
113 |
if ( !is_dir("$artwork_dir/greyhoundthumbnails") ) |
|
114 |
{ |
|
115 |
if ( !@mkdir("$artwork_dir/greyhoundthumbnails") ) |
|
116 |
{ |
|
117 |
return false; |
|
118 |
} |
|
119 |
} |
|
120 |
// check for the scaled cover image |
|
121 |
$target_file = "$artwork_dir/greyhoundthumbnails/$artwork_hash.png"; |
|
122 |
if ( !file_exists($target_file) ) |
|
123 |
{ |
|
124 |
// not scaled yet, scale to uniform 50x50 image |
|
125 |
$artwork_filetype = get_image_filetype("$artwork_dir/large/$artwork_hash"); |
|
126 |
if ( !$artwork_filetype ) |
|
127 |
{ |
|
40
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
128 |
// image is not supported (PNG, GIF, or JPG required) |
25 | 129 |
return false; |
130 |
} |
|
131 |
// we'll need to copy the existing artwork file to our thumbnail dir to let scale_image() detect the type properly (it doesn't use magic bytes) |
|
132 |
if ( !copy("$artwork_dir/large/$artwork_hash", "$artwork_dir/greyhoundthumbnails/tmp{$artwork_hash}.$artwork_filetype") ) |
|
133 |
{ |
|
134 |
return false; |
|
135 |
} |
|
136 |
// finally, scale the image |
|
137 |
if ( !scale_image("$artwork_dir/greyhoundthumbnails/tmp{$artwork_hash}.$artwork_filetype", $target_file, 50, 50) ) |
|
138 |
{ |
|
139 |
return false; |
|
140 |
} |
|
141 |
// delete our temp file |
|
142 |
if ( !unlink("$artwork_dir/greyhoundthumbnails/tmp{$artwork_hash}.$artwork_filetype") ) |
|
143 |
{ |
|
144 |
echo 'Couldn\'t delete the temp file'; |
|
145 |
return false; |
|
146 |
} |
|
147 |
} |
|
148 |
// we have it now, send the image through |
|
149 |
$fh = @fopen($target_file, 'r'); |
|
150 |
if ( !$fh ) |
|
151 |
return false; |
|
40
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
152 |
|
25 | 153 |
$httpd->header('Content-type: image/png'); |
154 |
$httpd->header('Content-length: ' . filesize($target_file)); |
|
155 |
$httpd->header('Expires: Wed, 1 Jan 2020 01:00:00 GMT'); |
|
40
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
156 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
157 |
// kinda sorta a hack. |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
158 |
$headers = implode("\r\n", $httpd->response_headers); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
159 |
$httpd->send_client_headers($socket, $httpd->response_code, $httpd->content_type, $headers); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
160 |
|
25 | 161 |
while ( !feof($fh) ) |
162 |
{ |
|
40
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
163 |
$socket->write(fread($fh, 51200)); |
25 | 164 |
} |
165 |
fclose($fh); |
|
166 |
} |
|
167 |
else |
|
168 |
{ |
|
169 |
// artwork file doesn't exist |
|
170 |
$ar = htmlspecialchars($_GET['artist']); |
|
171 |
$al = htmlspecialchars($_GET['album']); |
|
172 |
$httpd->send_http_error($socket, 404, "The requested artwork file for $ar:$al could not be found on this server."); |
|
173 |
} |
|
174 |
} |
|
175 |
||
40
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
176 |
/** |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
177 |
* Generates a collage of all album art for use as a CSS sprite. Also generates a textual .map file in the format of "hash xpos ypos\n" |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
178 |
* to allow retrieving positions of images. Requires GD. |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
179 |
* @param string Name of the collage file. Map file will be the same filename except with the extension ".map" |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
180 |
* @param int Size of each image, in pixels. Artwork images will be stretched to a 1:1 aspect ratio. Optional, defaults to 50. |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
181 |
* @return bool True on success, false on failure. |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
182 |
*/ |
25 | 183 |
|
40
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
184 |
function generate_artwork_collage($target_file, $size = 50) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
185 |
{ |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
186 |
// check for required GD functionality |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
187 |
if ( !function_exists('imagecopyresampled') || !function_exists('imagepng') ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
188 |
return false; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
189 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
190 |
status("generating size $size collage"); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
191 |
$stderr = fopen('php://stderr', 'w'); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
192 |
if ( !$stderr ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
193 |
// this should really never fail. |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
194 |
return false; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
195 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
196 |
// import amarok globals |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
197 |
global $amarok_home; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
198 |
$artwork_dir = "$amarok_home/albumcovers"; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
199 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
200 |
// map file path |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
201 |
$mapfile = preg_replace('/\.[a-z]+$/', '', $target_file) . '.map'; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
202 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
203 |
// open map file |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
204 |
$maphandle = @fopen($mapfile, 'w'); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
205 |
if ( !$maphandle ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
206 |
return false; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
207 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
208 |
$mapheader = <<<EOF |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
209 |
# this artwork collage map gives the locations of various artwork images within the collage |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
210 |
# format is: |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
211 |
# hash x y |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
212 |
# x and y are indices, not pixel values (obviously), and hash is the name of the artwork file in large/ |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
213 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
214 |
EOF; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
215 |
fwrite($maphandle, $mapheader); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
216 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
217 |
// build a list of existing artwork files |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
218 |
$artwork_list = array(); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
219 |
if ( $dh = @opendir("$artwork_dir/large") ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
220 |
{ |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
221 |
while ( $fp = @readdir($dh) ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
222 |
{ |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
223 |
if ( preg_match('/^[a-f0-9]{32}$/', $fp) ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
224 |
{ |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
225 |
$artwork_list[] = $fp; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
226 |
} |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
227 |
} |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
228 |
closedir($dh); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
229 |
} |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
230 |
else |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
231 |
{ |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
232 |
return false; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
233 |
} |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
234 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
235 |
// at least one image? |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
236 |
if ( empty($artwork_list) ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
237 |
return false; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
238 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
239 |
// asort it to make sure map is predictable |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
240 |
asort($artwork_list); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
241 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
242 |
// number of columns |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
243 |
$cols = 20; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
244 |
// number of rows |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
245 |
$rows = ceil( count($artwork_list) / $cols ); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
246 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
247 |
// image dimensions |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
248 |
$image_width = $cols * $size; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
249 |
$image_height = $rows * $size; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
250 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
251 |
// create image |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
252 |
$collage = imagecreatetruecolor($image_width, $image_height); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
253 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
254 |
// generator loop |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
255 |
// start at row 0, column 0 |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
256 |
$col = -1; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
257 |
$row = 0; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
258 |
$srow = $row + 1; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
259 |
fwrite($stderr, " -> row $srow of $rows\r"); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
260 |
$time_map = microtime(true); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
261 |
foreach ( $artwork_list as $artwork_file ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
262 |
{ |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
263 |
// calculate where we are |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
264 |
$col++; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
265 |
if ( $col == $cols ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
266 |
{ |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
267 |
// reached column limit, reset $cols and increment row |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
268 |
$col = 0; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
269 |
$row++; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
270 |
$srow = $row + 1; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
271 |
fwrite($stderr, " -> row $srow of $rows\r"); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
272 |
} |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
273 |
// x and y offset of scaled image |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
274 |
$xoff = $col * $size; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
275 |
$yoff = $row * $size; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
276 |
// set offset |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
277 |
fwrite($maphandle, "$artwork_file $col $row\n"); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
278 |
// load image |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
279 |
$createfunc = ( get_image_filetype("$artwork_dir/large/$artwork_file") == 'jpg' ) ? 'imagecreatefromjpeg' : 'imagecreatefrompng'; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
280 |
$aw = @$createfunc("$artwork_dir/large/$artwork_file"); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
281 |
if ( !$aw ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
282 |
{ |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
283 |
$aw = @imagecreatefromwbmp("$artwork_dir/large/$artwork_file"); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
284 |
if ( !$aw ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
285 |
{ |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
286 |
// couldn't load image, silently continue |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
287 |
continue; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
288 |
} |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
289 |
} |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
290 |
list($aw_width, $aw_height) = array(imagesx($aw), imagesy($aw)); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
291 |
// scale and position image |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
292 |
$result = imagecopyresampled($collage, $aw, $xoff, $yoff, 0, 0, $size, $size, $aw_width, $aw_height); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
293 |
if ( !$result ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
294 |
{ |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
295 |
// couldn't scale image, silently continue |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
296 |
continue; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
297 |
} |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
298 |
// free the temp image |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
299 |
imagedestroy($aw); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
300 |
} |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
301 |
$time_map = round(1000 * (microtime(true) - $time_map)); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
302 |
$time_write = microtime(true); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
303 |
fclose($maphandle); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
304 |
fwrite($stderr, " -> saving image\r"); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
305 |
if ( !imagepng($collage, $target_file) ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
306 |
return false; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
307 |
imagedestroy($collage); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
308 |
$time_write = round(1000 * (microtime(true) - $time_write)); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
309 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
310 |
$avg = round($time_map / count($artwork_list)); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
311 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
312 |
status("collage generation complete, returning success; time (ms): map/avg/write $time_map/$avg/$time_write"); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
313 |
return true; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
314 |
} |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
315 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
316 |
/** |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
317 |
* Returns an img tag showing artwork from the specified size collage sprite. |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
318 |
* @param string Artist |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
319 |
* @param string Album |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
320 |
* @param int Collage size |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
321 |
* @return string |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
322 |
*/ |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
323 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
324 |
function get_artwork_sprite($artist, $album, $size = 50) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
325 |
{ |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
326 |
// import amarok globals |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
327 |
global $amarok_home; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
328 |
$artwork_dir = "$amarok_home/albumcovers"; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
329 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
330 |
if ( !is_int($size) ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
331 |
return ''; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
332 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
333 |
// hash of cover |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
334 |
$coverid = md5(strtolower(trim($artist)) . strtolower(trim($album))); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
335 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
336 |
$tag = '<img alt=" " src="/spacer.gif" width="' . $size . '" height="' . $size . '" '; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
337 |
if ( file_exists("$artwork_dir/collage_{$size}.map") ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
338 |
{ |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
339 |
$mapdata = parse_collage_map("$artwork_dir/collage_{$size}.map"); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
340 |
if ( isset($mapdata[$coverid]) ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
341 |
{ |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
342 |
$css_x = -1 * $size * $mapdata[$coverid][0]; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
343 |
$css_y = -1 * $size * $mapdata[$coverid][1]; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
344 |
$tag .= "style=\"background-image: url(/artwork/collage/$size); background-repeat: no-repeat; background-position: {$css_x}px {$css_y}px;\" "; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
345 |
} |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
346 |
} |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
347 |
$tag .= '/>'; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
348 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
349 |
return $tag; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
350 |
} |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
351 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
352 |
/** |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
353 |
* Parses the specified artwork map file. Return an associative array, keys being the artwork file hashes and values being array(x, y). |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
354 |
* @param string Map file |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
355 |
* @return array |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
356 |
*/ |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
357 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
358 |
function parse_collage_map($mapfile) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
359 |
{ |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
360 |
if ( !file_exists($mapfile) ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
361 |
return array(); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
362 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
363 |
$fp = @fopen($mapfile, 'r'); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
364 |
if ( !$fp ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
365 |
return false; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
366 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
367 |
$map = array(); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
368 |
while ( $line = fgets($fp) ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
369 |
{ |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
370 |
// parse out comments |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
371 |
$line = trim(preg_replace('/#(.+)$/', '', $line)); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
372 |
if ( empty($line) ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
373 |
continue; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
374 |
list($hash, $x, $y) = explode(' ', $line); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
375 |
if ( !preg_match('/^[a-f0-9]{32}$/', $hash) || !preg_match('/^[0-9]+$/', $x) || !preg_match('/^[0-9]+$/', $y) ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
376 |
// invalid line |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
377 |
continue; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
378 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
379 |
// valid line, append map array |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
380 |
$map[$hash] = array( |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
381 |
intval($x), |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
382 |
intval($y) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
383 |
); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
384 |
} |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
385 |
fclose($fp); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
386 |
return $map; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
387 |
} |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
388 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
389 |
/** |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
390 |
* Finds out if a collage file is outdated (e.g. missing artwork images) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
391 |
* @param int Size of collage |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
392 |
* @return bool true if outdated |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
393 |
*/ |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
394 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
395 |
function collage_is_outdated($size = 50) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
396 |
{ |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
397 |
global $amarok_home; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
398 |
$artwork_dir = "$amarok_home/albumcovers"; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
399 |
$mapfile = "$artwork_dir/collage_{$size}.map"; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
400 |
if ( !file_exists($mapfile) ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
401 |
{ |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
402 |
// consider it outdated if it doesn't exist |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
403 |
return true; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
404 |
} |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
405 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
406 |
// load existing image map |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
407 |
$map = parse_collage_map($mapfile); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
408 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
409 |
// build a list of existing artwork files |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
410 |
$artwork_list = array(); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
411 |
if ( $dh = @opendir("$artwork_dir/large") ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
412 |
{ |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
413 |
while ( $fp = @readdir($dh) ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
414 |
{ |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
415 |
if ( preg_match('/^[a-f0-9]{32}$/', $fp) ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
416 |
{ |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
417 |
// found an artwork file |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
418 |
if ( !isset($map[$fp]) ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
419 |
{ |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
420 |
// this artwork isn't in the map file, return outdated |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
421 |
closedir($dh); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
422 |
status("size $size collage is outdated"); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
423 |
return true; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
424 |
} |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
425 |
} |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
426 |
} |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
427 |
closedir($dh); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
428 |
} |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
429 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
430 |
// if we reach here, we haven't found anything missing. |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
431 |
return false; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
432 |
} |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
433 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
434 |
/** |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
435 |
* Smarty function for sprite generation. |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
436 |
* @access private |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
437 |
*/ |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
438 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
439 |
function smarty_function_sprite($params, &$smarty) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
440 |
{ |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
441 |
// don't perform the exhaustive check more than once per execution |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
442 |
static $checks_done = array(); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
443 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
444 |
if ( empty($params['artist']) ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
445 |
return 'Error: missing "artist" parameter'; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
446 |
if ( empty($params['album']) ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
447 |
return 'Error: missing "album" parameter'; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
448 |
if ( empty($params['size']) ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
449 |
$params['size'] = 50; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
450 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
451 |
$params['size'] = intval($params['size']); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
452 |
$size =& $params['size']; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
453 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
454 |
// if the collage file doesn't exist or is missing artwork, renew it |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
455 |
// but only perform this check once per execution per size |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
456 |
if ( !isset($checks_done[$size]) ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
457 |
{ |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
458 |
global $amarok_home; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
459 |
$artwork_dir = "$amarok_home/albumcovers"; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
460 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
461 |
$collage_file = "$artwork_dir/collage_{$size}"; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
462 |
$collage_is_good = file_exists("$collage_file.png") && file_exists("$collage_file.map") && !collage_is_outdated($size); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
463 |
if ( !$collage_is_good ) |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
464 |
{ |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
465 |
generate_artwork_collage("$collage_file.png", $size); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
466 |
} |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
467 |
$checks_done[$size] = true; |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
468 |
} |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
469 |
|
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
470 |
return get_artwork_sprite($params['artist'], $params['album'], $params['size']); |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
471 |
} |
bd3372a2afc1
Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents:
33
diff
changeset
|
472 |