author | Dan |
Fri, 12 Jun 2009 13:47:12 -0400 | |
changeset 75 | 2f39cb7f54c4 |
parent 74 | 7719085707d8 |
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 |
* Utility functions |
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 |
|
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
16 |
/** |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
17 |
* Utility/reporting functions |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
18 |
*/ |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
19 |
|
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
20 |
/** |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
21 |
* Report a fatal error and exit |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
22 |
* @param string Error message |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
23 |
*/ |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
24 |
|
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
25 |
function burnout($msg) |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
26 |
{ |
34
3b817b961984
Merging changes from nighthawk; added support for dumb terminals
Dan
parents:
33
diff
changeset
|
27 |
global $use_colors; |
9
63a257541313
Moved all Greyhound output to stderr so it will show up in AmaroK error messages; corrected some HTML bugs in the readme
Dan
parents:
8
diff
changeset
|
28 |
$h = @fopen('php://stderr', 'w'); |
34
3b817b961984
Merging changes from nighthawk; added support for dumb terminals
Dan
parents:
33
diff
changeset
|
29 |
if ( $use_colors ) |
3b817b961984
Merging changes from nighthawk; added support for dumb terminals
Dan
parents:
33
diff
changeset
|
30 |
{ |
3b817b961984
Merging changes from nighthawk; added support for dumb terminals
Dan
parents:
33
diff
changeset
|
31 |
fwrite($h, "\x1B[31;1m[Greyhound] fatal: \x1B[37;1m"); |
3b817b961984
Merging changes from nighthawk; added support for dumb terminals
Dan
parents:
33
diff
changeset
|
32 |
fwrite($h, "$msg\x1B[0m\n"); |
3b817b961984
Merging changes from nighthawk; added support for dumb terminals
Dan
parents:
33
diff
changeset
|
33 |
} |
3b817b961984
Merging changes from nighthawk; added support for dumb terminals
Dan
parents:
33
diff
changeset
|
34 |
else |
3b817b961984
Merging changes from nighthawk; added support for dumb terminals
Dan
parents:
33
diff
changeset
|
35 |
{ |
3b817b961984
Merging changes from nighthawk; added support for dumb terminals
Dan
parents:
33
diff
changeset
|
36 |
fwrite($h, "[Greyhound] fatal: $msg\n"); |
3b817b961984
Merging changes from nighthawk; added support for dumb terminals
Dan
parents:
33
diff
changeset
|
37 |
} |
9
63a257541313
Moved all Greyhound output to stderr so it will show up in AmaroK error messages; corrected some HTML bugs in the readme
Dan
parents:
8
diff
changeset
|
38 |
fclose($h); |
0
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
39 |
exit(1); |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
40 |
} |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
41 |
|
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
42 |
/** |
34
3b817b961984
Merging changes from nighthawk; added support for dumb terminals
Dan
parents:
33
diff
changeset
|
43 |
* Print a stylized status message, compatible with Linux consoles. Falls back to no control characters if on unsupported terminal. |
0
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
44 |
* @param string Status message |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
45 |
*/ |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
46 |
|
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
47 |
function status($msg) |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
48 |
{ |
34
3b817b961984
Merging changes from nighthawk; added support for dumb terminals
Dan
parents:
33
diff
changeset
|
49 |
global $use_colors; |
9
63a257541313
Moved all Greyhound output to stderr so it will show up in AmaroK error messages; corrected some HTML bugs in the readme
Dan
parents:
8
diff
changeset
|
50 |
$h = @fopen('php://stderr', 'w'); |
16
23d4cf2f183b
Disabled forking/keep-alive code, firefox doesn't seem to like the way it waits for requests
Dan
parents:
15
diff
changeset
|
51 |
$label = ( defined('HTTPD_WS_CHILD') ) ? 'Child ' . substr(strval(getmypid()), -3) : 'Greyhound'; |
34
3b817b961984
Merging changes from nighthawk; added support for dumb terminals
Dan
parents:
33
diff
changeset
|
52 |
if ( $use_colors ) |
3b817b961984
Merging changes from nighthawk; added support for dumb terminals
Dan
parents:
33
diff
changeset
|
53 |
{ |
3b817b961984
Merging changes from nighthawk; added support for dumb terminals
Dan
parents:
33
diff
changeset
|
54 |
fwrite($h, "\x1B[32;1m[$label] \x1B[32;0m$msg\x1B[0m\n"); |
3b817b961984
Merging changes from nighthawk; added support for dumb terminals
Dan
parents:
33
diff
changeset
|
55 |
} |
3b817b961984
Merging changes from nighthawk; added support for dumb terminals
Dan
parents:
33
diff
changeset
|
56 |
else |
3b817b961984
Merging changes from nighthawk; added support for dumb terminals
Dan
parents:
33
diff
changeset
|
57 |
{ |
3b817b961984
Merging changes from nighthawk; added support for dumb terminals
Dan
parents:
33
diff
changeset
|
58 |
fwrite($h, "[$label] $msg\n"); |
3b817b961984
Merging changes from nighthawk; added support for dumb terminals
Dan
parents:
33
diff
changeset
|
59 |
} |
9
63a257541313
Moved all Greyhound output to stderr so it will show up in AmaroK error messages; corrected some HTML bugs in the readme
Dan
parents:
8
diff
changeset
|
60 |
fclose($h); |
0
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
61 |
} |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
62 |
|
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
63 |
/** |
13
b5db2345c397
Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents:
9
diff
changeset
|
64 |
* Print a stylized warning message, compatible with Linux consoles |
b5db2345c397
Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents:
9
diff
changeset
|
65 |
* @param string message message |
b5db2345c397
Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents:
9
diff
changeset
|
66 |
*/ |
b5db2345c397
Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents:
9
diff
changeset
|
67 |
|
b5db2345c397
Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents:
9
diff
changeset
|
68 |
function warning($msg) |
b5db2345c397
Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents:
9
diff
changeset
|
69 |
{ |
34
3b817b961984
Merging changes from nighthawk; added support for dumb terminals
Dan
parents:
33
diff
changeset
|
70 |
global $use_colors; |
13
b5db2345c397
Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents:
9
diff
changeset
|
71 |
$h = @fopen('php://stderr', 'w'); |
34
3b817b961984
Merging changes from nighthawk; added support for dumb terminals
Dan
parents:
33
diff
changeset
|
72 |
if ( $use_colors ) |
3b817b961984
Merging changes from nighthawk; added support for dumb terminals
Dan
parents:
33
diff
changeset
|
73 |
{ |
3b817b961984
Merging changes from nighthawk; added support for dumb terminals
Dan
parents:
33
diff
changeset
|
74 |
fwrite($h, "\x1B[33;1m[Greyhound] \x1B[0m\x1B[33mWarning:\x1B[0m $msg\n"); |
3b817b961984
Merging changes from nighthawk; added support for dumb terminals
Dan
parents:
33
diff
changeset
|
75 |
} |
3b817b961984
Merging changes from nighthawk; added support for dumb terminals
Dan
parents:
33
diff
changeset
|
76 |
else |
3b817b961984
Merging changes from nighthawk; added support for dumb terminals
Dan
parents:
33
diff
changeset
|
77 |
{ |
3b817b961984
Merging changes from nighthawk; added support for dumb terminals
Dan
parents:
33
diff
changeset
|
78 |
fwrite($h, "[Greyhound] Warning: $msg\n"); |
3b817b961984
Merging changes from nighthawk; added support for dumb terminals
Dan
parents:
33
diff
changeset
|
79 |
} |
13
b5db2345c397
Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents:
9
diff
changeset
|
80 |
fclose($h); |
b5db2345c397
Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents:
9
diff
changeset
|
81 |
} |
b5db2345c397
Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents:
9
diff
changeset
|
82 |
|
b5db2345c397
Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents:
9
diff
changeset
|
83 |
/** |
0
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
84 |
* Performs an action with DCOP. |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
85 |
* @param string DCOP component, e.g. player, playlist, playlistbrowser, ... |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
86 |
* @param string Action to perform, e.g. stop, play, ... |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
87 |
* @param string additional parameters... (NOT IMPLEMENTED) |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
88 |
* @return mixed output of DCOP command |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
89 |
*/ |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
90 |
|
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
91 |
function dcop_action($component, $action) |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
92 |
{ |
69 | 93 |
file_put_contents('php://stderr', "[dcop] start..."); |
94 |
if ( function_exists('proc_open') ) |
|
95 |
{ |
|
96 |
$descriptorspec = array( |
|
97 |
0 => array('pipe', 'r'), |
|
98 |
1 => array('pipe', 'w'), |
|
99 |
2 => array('pipe', 'w') |
|
100 |
); |
|
101 |
$dcop_command = "dcop amarok $component $action"; |
|
102 |
$dcop_process = proc_open($dcop_command, $descriptorspec, $dcop_pipes); |
|
103 |
do |
|
104 |
{ |
|
105 |
$status = proc_get_status($dcop_process); |
|
106 |
usleep(2000); |
|
107 |
} while ( $status['running'] ); |
|
108 |
pcntl_waitpid($status['pid'], $status); |
|
109 |
$output = fgets($dcop_pipes[1], 1024); |
|
110 |
proc_close($dcop_process); |
|
111 |
} |
|
112 |
else |
|
113 |
{ |
|
114 |
$tmpfile = tempnam('amaweb', ''); |
|
115 |
if ( !$tmpfile ) |
|
116 |
burnout('tempnam() failed us'); |
|
117 |
||
118 |
// This is freezing up for some reason. |
|
119 |
system("dcop amarok $component $action > $tmpfile"); |
|
120 |
$output = @file_get_contents($tmpfile); |
|
121 |
@unlink($tmpfile); |
|
122 |
} |
|
123 |
file_put_contents('php://stderr', "got it...\r"); |
|
0
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
124 |
$output = trim($output); |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
125 |
|
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
126 |
// detect type of output |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
127 |
if ( $output == 'true' ) |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
128 |
return true; |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
129 |
else if ( $output == 'false' ) |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
130 |
return false; |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
131 |
else if ( preg_match('/^-?[0-9]+/', $output) ) |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
132 |
return intval($output); |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
133 |
else |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
134 |
return $output; |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
135 |
} |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
136 |
|
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
137 |
/** |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
138 |
* Rebuilds the copy of the playlist in RAM |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
139 |
*/ |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
140 |
|
2
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
141 |
$playlist_last_md5 = ''; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
142 |
|
75 | 143 |
function rebuild_playlist($force = false, $from_ipc = false) |
0
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
144 |
{ |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
145 |
// import what we need |
33
3b4aef1efff6
Removed requirement for detecting home directory; artwork fetcher relies on return from saveCurrentPlaylist now
Dan
parents:
32
diff
changeset
|
146 |
global $playlist, $amarok_home; |
0
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
147 |
// sync and load the playlist file |
75 | 148 |
// if we're coming from IPC, don't call DCOP, just load the existing file |
149 |
// this prevents the file from being generated 20 times and thus sometimes |
|
150 |
// causing simplexml to read a half-written file |
|
151 |
if ( !$from_ipc ) |
|
152 |
{ |
|
153 |
$playlist_file = dcop_action('playlist', 'saveCurrentPlaylist'); |
|
154 |
} |
|
155 |
else |
|
156 |
{ |
|
157 |
$playlist_file = $from_ipc; |
|
158 |
} |
|
33
3b4aef1efff6
Removed requirement for detecting home directory; artwork fetcher relies on return from saveCurrentPlaylist now
Dan
parents:
32
diff
changeset
|
159 |
// do we have amarok's home? |
3b4aef1efff6
Removed requirement for detecting home directory; artwork fetcher relies on return from saveCurrentPlaylist now
Dan
parents:
32
diff
changeset
|
160 |
if ( !$amarok_home ) |
3b4aef1efff6
Removed requirement for detecting home directory; artwork fetcher relies on return from saveCurrentPlaylist now
Dan
parents:
32
diff
changeset
|
161 |
$amarok_home = dirname($playlist_file); |
2
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
162 |
// check MD5 - if it's not changed, exit to save CPU cycles |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
163 |
global $playlist_last_md5; |
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
|
164 |
$effective_md5 = md5_playlist_file($playlist_file); |
75 | 165 |
if ( $playlist_last_md5 == $effective_md5 && !$force ) |
2
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
166 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
167 |
return true; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
168 |
} |
14
7a1573676cc4
Added jump-to-current function in iphone theme; fixed md5('') call if unique IDs empty in playlist XML file
Dan
parents:
13
diff
changeset
|
169 |
status('Rebuilding playlist cache'); |
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
|
170 |
$playlist_last_md5 = $effective_md5; |
75 | 171 |
$originalplaylist = $playlist_file; |
172 |
$xml = false; |
|
173 |
$unlinkplaylist = false; |
|
174 |
while ( !$xml ) |
|
0
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
175 |
{ |
75 | 176 |
// start XML parser |
177 |
try |
|
178 |
{ |
|
179 |
$xml = @simplexml_load_file($playlist_file); |
|
180 |
if ( $xml ) |
|
181 |
break; |
|
182 |
||
183 |
// if we can't load it, just wait - another process might have it loaded |
|
184 |
warning('Could not load playlist file; maybe another Greyhound thread has it loaded? Waiting half a second.'); |
|
185 |
usleep(500000); |
|
186 |
} |
|
187 |
catch ( Exception $e ) |
|
188 |
{ |
|
189 |
burnout("Caught exception trying to load playlist file:\n$e"); |
|
190 |
} |
|
0
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
191 |
} |
75 | 192 |
|
0
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
193 |
$attribs = $xml->attributes(); |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
194 |
if ( @$attribs['product'] != 'Amarok' ) |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
195 |
{ |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
196 |
burnout('Playlist is not in Amarok format'); |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
197 |
} |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
198 |
$playlist = array(); |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
199 |
foreach ( $xml->children() as $child ) |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
200 |
{ |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
201 |
$attribs = $child->attributes(); |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
202 |
$item = array( |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
203 |
'uri' => $attribs['uri'], |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
204 |
'title' => strval($child->Title), |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
205 |
'artist' => strval($child->Artist), |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
206 |
'album' => strval($child->Album), |
2
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
207 |
'length' => seconds_to_str(intval($child->Length)), |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
0
diff
changeset
|
208 |
'length_int' => intval($child->Length) |
0
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
209 |
); |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
210 |
$playlist[] = $item; |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
211 |
} |
75 | 212 |
if ( $unlinkplaylist ) |
213 |
{ |
|
214 |
unlink($playlist_file); |
|
215 |
} |
|
216 |
// tell all other worker threads to reload the playlist as well |
|
217 |
global $httpd; |
|
218 |
if ( is_object($httpd) && !$from_ipc ) |
|
32
86140ed9087d
Experimental: upon change to playlist, send SIGUSR1 to parent process and branch out to all children to force a playlist refresh
Dan
parents:
16
diff
changeset
|
219 |
{ |
75 | 220 |
$httpd->threader->ipc_send(array( |
221 |
'action' => 'reloadplaylist', |
|
222 |
'propagate' => true, |
|
223 |
'playlist_file' => $playlist_file |
|
224 |
)); |
|
225 |
} |
|
226 |
} |
|
227 |
||
228 |
function rebuild_playlist_ipc($command, $threader) |
|
229 |
{ |
|
230 |
status('IPC playlist rebuild received'); |
|
231 |
if ( isset($command['playlist']) ) |
|
232 |
{ |
|
233 |
status('IPC playlist rebuild: using playlist sent in IPC packet; length: ' . strlen($command['playlist'])); |
|
234 |
$GLOBALS['playlist'] = $command['playlist']; |
|
235 |
} |
|
236 |
else |
|
237 |
{ |
|
238 |
rebuild_playlist(true, $command['playlist_file']); |
|
32
86140ed9087d
Experimental: upon change to playlist, send SIGUSR1 to parent process and branch out to all children to force a playlist refresh
Dan
parents:
16
diff
changeset
|
239 |
} |
0
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
240 |
} |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
241 |
|
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
242 |
/** |
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
|
243 |
* Builds the correct MD5 check for the specified playlist XML file. This is designed to base on the list of actual tracks, disregarding |
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
|
244 |
* the rest of the text in the XML file. |
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
|
245 |
* @param string Path to playlist |
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
|
246 |
* @return string hash |
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
|
247 |
*/ |
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
|
248 |
|
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
|
249 |
function md5_playlist_file($file) |
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
|
250 |
{ |
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
|
251 |
$contents = @file_get_contents($file); |
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
|
252 |
if ( empty($contents) ) |
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
|
253 |
return false; |
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
|
254 |
$count = preg_match_all('/uniqueid="([a-fA-F0-9]+?)"/', $contents, $matches); |
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
|
255 |
$matches = implode("", $matches[1]); |
14
7a1573676cc4
Added jump-to-current function in iphone theme; fixed md5('') call if unique IDs empty in playlist XML file
Dan
parents:
13
diff
changeset
|
256 |
if ( empty($matches) ) |
7a1573676cc4
Added jump-to-current function in iphone theme; fixed md5('') call if unique IDs empty in playlist XML file
Dan
parents:
13
diff
changeset
|
257 |
{ |
7a1573676cc4
Added jump-to-current function in iphone theme; fixed md5('') call if unique IDs empty in playlist XML file
Dan
parents:
13
diff
changeset
|
258 |
// sometimes current.xml has blank unique IDs |
7a1573676cc4
Added jump-to-current function in iphone theme; fixed md5('') call if unique IDs empty in playlist XML file
Dan
parents:
13
diff
changeset
|
259 |
$count = preg_match_all('/url="([^"]+?)"/', $contents, $matches); |
7a1573676cc4
Added jump-to-current function in iphone theme; fixed md5('') call if unique IDs empty in playlist XML file
Dan
parents:
13
diff
changeset
|
260 |
$matches = implode("", $matches[1]); |
7a1573676cc4
Added jump-to-current function in iphone theme; fixed md5('') call if unique IDs empty in playlist XML file
Dan
parents:
13
diff
changeset
|
261 |
} |
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
|
262 |
return md5($matches); |
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
|
263 |
} |
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
|
264 |
|
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
|
265 |
/** |
0
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
266 |
* Converts a number to minute:second format |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
267 |
* @param int Seconds |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
268 |
* @return string format: mm:ss |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
269 |
*/ |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
270 |
|
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
271 |
function seconds_to_str($secs) |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
272 |
{ |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
273 |
$seconds = $secs % 60; |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
274 |
$minutes = ( $secs - $seconds ) / 60; |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
275 |
$seconds = strval($seconds); |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
276 |
$minutes = strval($minutes); |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
277 |
if ( strlen($seconds) < 2 ) |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
278 |
$seconds = "0$seconds"; |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
279 |
if ( strlen($minutes) < 2 ) |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
280 |
$minutes = "0$minutes"; |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
281 |
return "$minutes:$seconds"; |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
282 |
} |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
283 |
|
4 | 284 |
/** |
285 |
* Loads the specified theme into Smarty |
|
286 |
* @param string Theme ID |
|
287 |
* @return object Smarty object |
|
288 |
*/ |
|
289 |
||
290 |
function load_theme($theme_id) |
|
291 |
{ |
|
292 |
global $httpd; |
|
293 |
static $smarty = array(); |
|
50
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
294 |
if ( $theme_id === '__free__' ) |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
295 |
{ |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
296 |
$smarty = array(); |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
297 |
return false; |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
298 |
} |
4 | 299 |
if ( !isset($smarty[$theme_id]) ) |
300 |
{ |
|
301 |
$smarty[$theme_id] = new Smarty(); |
|
8
a8d108f37363
Modified to trap signals properly and not write to the root directory (only working directory)
Dan
parents:
6
diff
changeset
|
302 |
$smarty[$theme_id]->template_dir = GREY_ROOT . "/themes/$theme_id"; |
a8d108f37363
Modified to trap signals properly and not write to the root directory (only working directory)
Dan
parents:
6
diff
changeset
|
303 |
if ( !is_dir("./compiled/$theme_id") ) |
a8d108f37363
Modified to trap signals properly and not write to the root directory (only working directory)
Dan
parents:
6
diff
changeset
|
304 |
@mkdir("./compiled/$theme_id"); |
a8d108f37363
Modified to trap signals properly and not write to the root directory (only working directory)
Dan
parents:
6
diff
changeset
|
305 |
$smarty[$theme_id]->compile_dir = "./compiled/$theme_id"; |
4 | 306 |
$smarty[$theme_id]->config_dir = "./config"; |
8
a8d108f37363
Modified to trap signals properly and not write to the root directory (only working directory)
Dan
parents:
6
diff
changeset
|
307 |
$httpd->add_handler("themes/$theme_id", 'dir', GREY_ROOT . "/themes/$theme_id"); |
4 | 308 |
} |
309 |
return $smarty[$theme_id]; |
|
310 |
} |
|
50
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
311 |
|
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
312 |
/** |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
313 |
* Implementation of the "which" command in native PHP. |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
314 |
* @param string command |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
315 |
* @return string path to executable, or false on failure |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
316 |
*/ |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
317 |
|
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
318 |
function which($executable) |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
319 |
{ |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
320 |
$path = ( isset($_ENV['PATH']) ) ? $_ENV['PATH'] : ( isset($_SERVER['PATH']) ? $_SERVER['PATH'] : false ); |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
321 |
if ( !$path ) |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
322 |
// couldn't get OS's PATH |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
323 |
return false; |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
324 |
|
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
325 |
$win32 = ( PHP_OS == 'WINNT' || PHP_OS == 'WIN32' ); |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
326 |
$extensions = $win32 ? array('.exe', '.com', '.bat') : array(''); |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
327 |
$separator = $win32 ? ';' : ':'; |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
328 |
$paths = explode($separator, $path); |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
329 |
foreach ( $paths as $dir ) |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
330 |
{ |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
331 |
foreach ( $extensions as $ext ) |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
332 |
{ |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
333 |
$fullpath = "$dir/{$executable}{$ext}"; |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
334 |
if ( file_exists($fullpath) && is_executable($fullpath) ) |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
335 |
{ |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
336 |
return $fullpath; |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
337 |
} |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
338 |
} |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
339 |
} |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
340 |
return false; |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
341 |
} |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
342 |
|
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
343 |
/** |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
344 |
* Reload the config. |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
345 |
*/ |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
346 |
|
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
347 |
function grey_reload_config() |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
348 |
{ |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
349 |
global $httpd; |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
350 |
status('reloading the config'); |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
351 |
|
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
352 |
if ( file_exists('./greyhound-config.php') ) |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
353 |
{ |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
354 |
require('./greyhound-config.php'); |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
355 |
} |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
356 |
else |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
357 |
{ |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
358 |
// ignore this, it allows using a different config file when a Mercurial repository |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
359 |
// exists in Greyhound's root directory (to allow the devs to have their own config |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
360 |
// separate from the default) |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
361 |
|
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
362 |
if ( @is_dir(GREY_ROOT . '/.hg') ) |
64
ee64bb096f56
A few miscellaneous fixes including modifying WebServer to write data in chunks (improved performance and reliability on a slow connection)
Dan
parents:
57
diff
changeset
|
363 |
{ |
50
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
364 |
require(GREY_ROOT . '/config.dev.php'); |
64
ee64bb096f56
A few miscellaneous fixes including modifying WebServer to write data in chunks (improved performance and reliability on a slow connection)
Dan
parents:
57
diff
changeset
|
365 |
} |
50
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
366 |
else |
64
ee64bb096f56
A few miscellaneous fixes including modifying WebServer to write data in chunks (improved performance and reliability on a slow connection)
Dan
parents:
57
diff
changeset
|
367 |
{ |
50
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
368 |
require(GREY_ROOT . '/config.php'); |
64
ee64bb096f56
A few miscellaneous fixes including modifying WebServer to write data in chunks (improved performance and reliability on a slow connection)
Dan
parents:
57
diff
changeset
|
369 |
} |
50
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
370 |
} |
52
ab3541465382
Fixed globals from config file not being properly loaded from grey_reload_config()
Dan
parents:
50
diff
changeset
|
371 |
|
57 | 372 |
foreach ( array('public', 'enable_ipv4', 'enable_ipv6', 'allowcontrol', 'theme', 'allow_fork', 'use_auth', 'auth_data', 'configpass') as $var ) |
52
ab3541465382
Fixed globals from config file not being properly loaded from grey_reload_config()
Dan
parents:
50
diff
changeset
|
373 |
{ |
ab3541465382
Fixed globals from config file not being properly loaded from grey_reload_config()
Dan
parents:
50
diff
changeset
|
374 |
if ( isset($$var) ) |
ab3541465382
Fixed globals from config file not being properly loaded from grey_reload_config()
Dan
parents:
50
diff
changeset
|
375 |
{ |
ab3541465382
Fixed globals from config file not being properly loaded from grey_reload_config()
Dan
parents:
50
diff
changeset
|
376 |
$GLOBALS[$var] = $$var; |
ab3541465382
Fixed globals from config file not being properly loaded from grey_reload_config()
Dan
parents:
50
diff
changeset
|
377 |
} |
ab3541465382
Fixed globals from config file not being properly loaded from grey_reload_config()
Dan
parents:
50
diff
changeset
|
378 |
} |
50
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
379 |
} |
1b4288399b1f
Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents:
34
diff
changeset
|
380 |
|
74
7719085707d8
Security: Sessions are now based on HMAC-MD5 salts instead of concatenation
Dan
parents:
69
diff
changeset
|
381 |
/** |
7719085707d8
Security: Sessions are now based on HMAC-MD5 salts instead of concatenation
Dan
parents:
69
diff
changeset
|
382 |
* Decodes a hex string. |
7719085707d8
Security: Sessions are now based on HMAC-MD5 salts instead of concatenation
Dan
parents:
69
diff
changeset
|
383 |
* @param string $hex The hex code to decode |
7719085707d8
Security: Sessions are now based on HMAC-MD5 salts instead of concatenation
Dan
parents:
69
diff
changeset
|
384 |
* @return string |
7719085707d8
Security: Sessions are now based on HMAC-MD5 salts instead of concatenation
Dan
parents:
69
diff
changeset
|
385 |
*/ |
7719085707d8
Security: Sessions are now based on HMAC-MD5 salts instead of concatenation
Dan
parents:
69
diff
changeset
|
386 |
|
7719085707d8
Security: Sessions are now based on HMAC-MD5 salts instead of concatenation
Dan
parents:
69
diff
changeset
|
387 |
function hexdecode($hex) |
7719085707d8
Security: Sessions are now based on HMAC-MD5 salts instead of concatenation
Dan
parents:
69
diff
changeset
|
388 |
{ |
7719085707d8
Security: Sessions are now based on HMAC-MD5 salts instead of concatenation
Dan
parents:
69
diff
changeset
|
389 |
$hex = str_split($hex, 2); |
7719085707d8
Security: Sessions are now based on HMAC-MD5 salts instead of concatenation
Dan
parents:
69
diff
changeset
|
390 |
$bin_key = ''; |
7719085707d8
Security: Sessions are now based on HMAC-MD5 salts instead of concatenation
Dan
parents:
69
diff
changeset
|
391 |
foreach($hex as $nibble) |
7719085707d8
Security: Sessions are now based on HMAC-MD5 salts instead of concatenation
Dan
parents:
69
diff
changeset
|
392 |
{ |
7719085707d8
Security: Sessions are now based on HMAC-MD5 salts instead of concatenation
Dan
parents:
69
diff
changeset
|
393 |
$byte = chr(hexdec($nibble)); |
7719085707d8
Security: Sessions are now based on HMAC-MD5 salts instead of concatenation
Dan
parents:
69
diff
changeset
|
394 |
$bin_key .= $byte; |
7719085707d8
Security: Sessions are now based on HMAC-MD5 salts instead of concatenation
Dan
parents:
69
diff
changeset
|
395 |
} |
7719085707d8
Security: Sessions are now based on HMAC-MD5 salts instead of concatenation
Dan
parents:
69
diff
changeset
|
396 |
return $bin_key; |
7719085707d8
Security: Sessions are now based on HMAC-MD5 salts instead of concatenation
Dan
parents:
69
diff
changeset
|
397 |
} |
7719085707d8
Security: Sessions are now based on HMAC-MD5 salts instead of concatenation
Dan
parents:
69
diff
changeset
|
398 |