]> Joshua Wise's Git repositories - patchfork.git/blame_incremental - player/config.php
Tweak support for Amazon coverart grabbing to be able to use keyword search, too...
[patchfork.git] / player / config.php
... / ...
CommitLineData
1<?php
2/*
3 Pitchfork Music Player Daemon Client
4 Copyright (C) 2007 Roger Bystrøm
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; version 2 of the License.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18*/
19 require_once("../inc/function_test.php");
20 function get_checkbox_from_config($name) {
21 $var = get_config($name);
22 if(!is_null($var)&&strlen($var)) {
23 return "checked='checked'";
24 }
25 return "";
26 }
27
28 function return_bytes($val) {
29 $val = trim($val);
30 $last = strtolower($val{strlen($val)-1});
31 switch($last) {
32 // The 'G' modifier is available since PHP 5.1.0
33 case 'g':
34 $val *= 1024;
35 case 'm':
36 $val *= 1024;
37 case 'k':
38 $val *= 1024;
39 }
40
41 return $val;
42 }
43
44
45 $title = "";
46 @ob_start();
47 require_once("../inc/base.php");
48 require_once("../lang/master.php");
49?>
50<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
51<html>
52<head>
53<meta name="robots" content="noindex,nofollow" />
54<style type="text/css">
55 body {
56 font: 12.4px/160% sans-serif;
57 }
58 .main_container {
59 border: 1px solid #e2e2e2;
60 background-color: #f7f7f7;
61 padding-left: 8px;
62 padding-bottom: 10px;
63 }
64 .red-box {
65 border: 1px solid #a20000;
66 background-color: #ffcccc;
67 padding-left: 5px;
68 }
69 #pinfo {
70 border: 1px solid #877E6E;
71 background-color: #DEE7F7;
72 background: #f1f1f1;
73 padding: 0px 5px 0px 5px;
74 position: absolute;
75 top: 30px;
76 right: 20px;
77 }
78 select, input {
79 font-size: 0.90em;
80 line-height: 1em;
81 }
82</style>
83<script type='text/javascript'>
84 var showing = false;
85 function toggle_showing_plentries() {
86 var e = null;
87 var i =3;
88 showing = !showing;
89 while(e = document.getElementById('ple_' + i)) {
90 e.style.display = showing?"":"none";
91 i++;
92 }
93 var t = document.getElementById('plentry_show');
94 t.innerHTML = showing?"&nbsp;&nbsp;Hide nonstandard [~]":"&nbsp;&nbsp;Show nonstandard [+]";
95 }
96</script>
97<title><?php echo m("Pitchfork MPD Client Configuration"); ?></title>
98</head>
99<body>
100<?php
101 $new_config = $config?false:true;
102 if(!$config) {
103 $config = simplexml_load_string("<?xml version='1.0' ?>\n<root>\n</root>\n");
104 }
105 if(isset($_POST['submit'])) {
106 $vars = array( 'mpd_host', 'mpd_port', 'mpd_pass', 'login_pass', 'update_delay',
107 'metadata_disable', 'theme', 'stop_button', 'shout_url', 'pagination', 'lang',
108 'aws_keyid', 'aws_secret');
109 foreach ($vars as $var) {
110 $add = "";
111 if(isset($_POST[$var])&&trim($_POST[$var])!="")
112 $add = trim($_POST[$var]);
113
114 if($var=="pagination") {
115 if(!is_numeric($add))
116 $add = 0;
117 else $add = intval($add);
118 }
119 else if($var=="login_pass"&&strlen($add)>0) {
120 if($add== HASH_PASS)
121 continue;
122 $add = generate_hash($add);
123 }
124 else if ($var=='aws_secret') {
125 if ($add == HASH_PASS)
126 continue;
127 }
128
129
130 if(isset($config->$var)) {
131 $config->$var = $add;
132 }
133 else {
134 $config->addChild($var, $add);
135 }
136 }
137
138 $plentry = null;
139 if(isset($config->plentry))
140 $plentry = $config->plentry;
141 else
142 $plentry = $config->addChild("plentry");
143
144 foreach($pl_fields as $field) {
145 $val = isset($_POST['plentry_' . $field])?"yes":"";
146 $plentry->$field = $val;
147 }
148
149 // need to save config!
150 if($config->asXML("../config/config.xml")) {
151 header("Location: index.php");
152 echo "<p>If you're not redirected, go here: <a href='index.php'>player</a></p>";
153 exit();
154 }
155 else {
156 echo "<p class='error'>Could not save your configuration, check that config/config.xml is writeable</p>\n";
157 }
158 }
159
160 if(!is_writeable("../config")) {
161 echo "<p class='red-box'>";
162 echo m("Warning: Your config/ directory is not writeable! Please change owner of directory to apache user.");
163 echo "</p>\n";
164 }
165 @ob_end_flush();
166
167?>
168
169
170
171<div class='main_container' id='main_container'>
172
173<h1>Pitchfork configuration</h1>
174
175<?php if(isset($_GET['new_config']))
176 echo "<p>" . m("Let us take a minute to configure this player") . "</p>\n";
177 else echo "<p>" . m("Configure settings") . "</p>";
178?>
179<form action="config.php<?php echo $new_config?'?new_config':''; ?>" method="post">
180<h2><?php echo m("Connection-settings"); ?> </h2>
181<p><?php echo m("Where can I find your MPD-server?"); ?></p>
182<table>
183<tr><td><?php echo m("Hostname:"); ?> </td>
184<td><input type='text' value='<?php echo htmlspecialchars(get_config('mpd_host', 'localhost')) ?>' name='mpd_host' /></td></tr>
185<tr><td><?php echo m("Port:");?>
186</td><td><input type='text' value='<?php echo htmlspecialchars(get_config('mpd_port', '6600')) ?>' name='mpd_port' /></td></tr>
187<tr><td><?php echo m("Password:");?>
188</td><td><input type='password' value='<?php echo htmlspecialchars(get_config('mpd_pass', '')) ?>' name='mpd_pass' /></td></tr>
189
190</table>
191<h2><?php echo m("User interface");?></h2>
192<p><?php echo m("Some other settings!");?><br/></p>
193<table>
194<tr><td><?php echo m("Update time:"); ?>
195</td><td><input type='text' title='<?php echo m("How often we should request updates from the server");?>' value='<?php echo htmlspecialchars(get_config('update_delay', '1')) ?>' name='update_delay' /></td></tr>
196 <tr><td><?php echo m("Login password (optional):");?>
197 </td><td><input type='password' title='<?php echo m("If you want to require a password to see these pages you may specify it here");?>' value='<?php
198
199 $pass = get_config('login_pass', '');
200 if(substr($pass,0, 4)=="sha:") {
201 echo HASH_PASS;
202 }
203 else {
204 echo htmlspecialchars($pass);
205 }
206
207?>' name='login_pass' /></td></tr>
208<tr><td><?php echo m("Theme:");?> </td>
209<td>
210<select name='theme'>
211<?php
212$themes = get_available_themes();
213$ctheme = get_config("theme", "default");
214foreach($themes as $theme) {
215 echo "\n<option value='$theme' ";
216 if($theme==$ctheme)
217 echo "selected='selected' ";
218 echo ">$theme</option>";
219}
220
221?>
222</select>
223</td>
224</tr>
225<tr><td><?php echo m("Language:");?> </td><td>
226<select name="lang">
227<?php
228 // TODO: move
229 $languages = array("eu" => "Basque", "en" => "English", "fr" => "French", "de" => "German");
230 $clang = get_config("lang", "en");
231 foreach($languages as $l => $n) {
232 echo "\n<option value='$l'";
233 if($l==$clang)
234 echo " selected='selected' ";
235 echo ">$n</option>";
236 }
237?>
238</select>
239</td></tr>
240
241<tr><td><?php echo m("Include stop button:");?></td><td>
242<input type='checkbox' <?php if(!is_null(get_config("stop_button"))) echo "checked='checked'"; ?> name='stop_button' value='yesplease' />
243</td></tr>
244<tr><td><?php echo m("Pagination:");?></td><td><input name='pagination' type='text' value="<?php echo get_config("pagination", 0); ?>"
245title="<?php echo m("Maximum number of entries pr. page. Set to 0 to disable.");?>" size="5" /></td></tr>
246<tr><td>&nbsp; </td><td> </td></tr>
247<tr><td colspan="2"><?php echo m("Show these fields in the playlist:");?> </td></tr>
248<tr><td>&nbsp;</td><td><input type='checkbox' disabled='disabled' checked='checked' id='tnode_1' /> <label for='tnode_1'>
249<?php echo m("Position"); ?></label></td></tr>
250<?php
251
252$selected_fields = get_selected_plfields();
253$length = count($pl_fields);
254for($i=0; $i<$length;$i++) {
255 if($i==3) {
256 echo "<tr><td colspan='2' style='cursor: pointer;' id='plentry_show' onclick='toggle_showing_plentries();'>&nbsp;&nbsp;";
257 echo m("Show nonstandard") . " [+]</td></tr>";
258 }
259 echo "<tr id='ple_$i' ";
260 if($i>=3)
261 echo "style='display: none; ' ";
262 echo "><td>&nbsp;</td><td>";
263 echo "<input type='checkbox' ";
264 if($selected_fields[$i])
265 echo "checked='checked' ";
266 echo "name='plentry_".$pl_fields[$i]."' id='pl_i_$i' /> <label for='pl_i_$i'>".$pl_fields[$i]."</label></td></tr>\n";
267}
268
269?>
270<tr><td>&nbsp;</td><td><input type='checkbox' disabled='disabled' checked='checked' id='tnode_2' /> <label for='tnode_2'> Time</label></td></tr>
271</table>
272<h2>Metadata</h2>
273<p><?php echo m("Configuration for retrieving metadata. This requires that the machine Patchfork is running on can access the internet. ".
274 "In order to use this feature, you must now have an Amazon AWS account; to get one, <a href=\"http://aws.amazon.com\">visit aws.amazon.com</a>. ".
275 "Then, get an <a href=\"https://aws-portal.amazon.com/gp/aws/developer/account/index.html?ie=UTF8&action=access-key\">access key</a>, and fill in the details below."); ?></p>
276<table>
277<tr><td><?php echo m("Disable metadata:"); ?> </td><td><input type='checkbox' <?php echo get_checkbox_from_config('metadata_disable') ?> name='metadata_disable' /></td></tr>
278<tr><td><?php echo m("Amazon Access Key ID:"); ?></td><td><input type='text' width='20' value='<?php echo htmlspecialchars(get_config('aws_keyid', '')) ?>' name='aws_keyid' /></td></tr>
279<tr><td><?php echo m("Amazon Secret Access Key:"); ?></td><td><input type='password' width='40' value='<?
280 $pass = get_config('aws_secret', '');
281 if(strlen($pass) != 0) {
282 echo HASH_PASS;
283 }
284 ?>' name='aws_secret' /></td></tr>
285</table>
286<h2><?php echo m("Shoutcast integration"); ?></h2>
287<p>
288<?php echo m("Optionally specify the URL to the shout stream provided by mpd to enable integration with pitchfork.");?> <br/>
289<input size="35" type='text' name='shout_url' value='<?php if(!is_null(get_config("shout_url"))) echo htmlspecialchars(get_config("shout_url")); ?>' />
290</p>
291<p style='padding: 12px 0px 12px 00px;'>
292<input name='cancel' type='button' value='Cancel' onclick='window.location = "index.php" ' />
293<input name='submit' type="submit" value="Save" />
294</p>
295</form>
296<?php if(!isset($_GET['new_config'])) { ?>
297<hr/>
298<p>
299For lyrics search to work in the directory browser file-names has to be saved with the lyrics, however when you move/delete files from your library this file reference become wrong. This button removes any references to such files.
300<br/>
301<span id='housecleaning_info'></span>
302<input type='button' value='Housecleaning' onclick='location.href="metadata.php?housecleaning"'/>
303</p>
304<?php }
305
306function print_yesno($test, $fatal) {
307 if($test) return "<span style='color: green;'>" . m("Yes") . "</span>";
308 else return "<span style='color: " . ($fatal?"red":"orange") . ";'>" . m("No") . "</span>";
309}
310
311// function_name:fatal (0/1)
312function test_function($stuff) {
313 $stuff = explode(":", $stuff);
314 $name = $stuff[0];
315 echo $name . ": ";
316 echo print_yesno(function_exists($name), $stuff[1]);
317 echo "<br/>\n";
318}
319
320?>
321
322<div id='pinfo'>
323<h2><?php echo m("Pitchfork info"); ?></h2>
324<p style='padding: 0px 0px 4px 0px;'>
325<?php
326 echo m("Release version:") . " $release_version<br/>\n";
327 echo m("Release date:") . " $release_date<br/><br/>\n";
328 $pl = get_playback();
329 $has_commands = true;
330 try {
331 if($pl) {
332 $commands = $pl->getCommands();
333 /* these are just some of the needed commands */
334 $needed = array("outputs", "disableoutput", "enableoutput", "plchangesposid");
335 $res = array_intersect($needed, $commands);
336 if(count($res)!=count($needed))
337 $has_commands = false;
338 $pl->disconnect();
339 }
340 }
341 catch(PEAR_Exception $e) {
342 $has_commands = false;
343 }
344
345 echo m("Connect to mpd:"). " ". print_yesno($pl, true) . "<br/>\n";
346 if($pl) {
347 echo m("MPD commands:")." " . print_yesno($has_commands, true) . "<br />\n";
348 }
349 echo m("Metadata directory:"). " " . print_yesno((file_exists($metadata_dir)&&is_writeable($metadata_dir))
350 ||(!file_exists($metadata_dir)&&is_writeable($config_dir)), true);
351?>
352</p>
353
354<h3><?php echo m("Functions:"); ?></h3>
355<p style='padding: 0px 0px 4px 0px; '>
356<?php
357 // name:fatal
358 foreach(array("json_encode:0", "simplexml_load_string:1", "mb_internal_encoding:0") as $f)
359 test_function($f);
360 echo "SimpleXMLaddChild: ";
361 $sxe = array_to_xml(array("test"));
362 if($sxe)
363 echo print_yesno(is_callable(array($sxe, "addChild"), true), true) . "<br/>";
364 else echo "<span class='color: red'>error</span>\n";
365 $mem = ceil(return_bytes(ini_get("memory_limit"))/(1024*1024));
366 echo m("PHP memory limit:") . " <span style='color: " . ($mem<32?"orange":"green") . "'>" . $mem . "MB</span>";
367
368?>
369</p>
370<?php
371 if(get_magic_quotes_runtime()) {
372 echo "<p style='color: orange'>";
373 echo m("Warning: Magic quotes runtime is on, <br/>please use pitchfork.conf or turn<br/> of manually.");
374 echo "</p>\n";
375 }
376 if(get_magic_quotes_gpc()) {
377 echo "<p style='color: orange'>";
378 echo m("Warning: Magic quotes gpc is on, <br/>please use pitchfork.conf or turn<br/> of manually.");
379 echo "</p>\n";
380 }
381
382?>
383</div>
384
385</div>
386
387</body>
388</html>
This page took 0.027925 seconds and 4 git commands to generate.