/
connection.php
159 lines (156 loc) · 5.5 KB
/
connection.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
$is_connected = false;
$authorized = false;
if($configuration["use_cookies"]==true) {
if(isset($configuration["hide"])) {
make_config_cookie("playlist_hide", $hide);
}
}
$connection = fsockopen($configuration["mpd_host"], $configuration["mpd_port"], $errno, $errstr, 10);
if(isset($connection) && is_resource($connection)) {
while(!feof($connection)) {
$gt = fgets($connection, 1024);
if(parse_mpd_var($gt))
break;
}
if(array_key_exists("action", $_REQUEST) && $_REQUEST["action"] == "Logout") {
eat_config_cookie("password");
} else {
$pass = (array_key_exists("action", $_REQUEST) && $_REQUEST["action"] == "Login" ? $_REQUEST["password"] : (isset($configuration["password"]) ? $configuration["password"] : null));
if(isset($pass)) {
if(do_mpd_command($connection, "password ".$pass) === true) {
$authorized = true;
if($configuration["use_cookies"]=="yes")
make_config_cookie("password", $pass);
}
}
}
if(array_key_exists("command", $_REQUEST)) {
switch($_REQUEST["command"]) {
case "addall":
$files = array();
$command = "add";
$ls = do_mpd_command($connection, "lsinfo".(array_key_exists("directory", $configuration) ? " \"".$configuration["directory"]."\"" : "" ), null, true);
if(array_key_exists("file", $ls)) {
if(is_array($ls["file"])) {
foreach($ls["file"] as $key => $file) {
$files[] = "\"".$file."\"";
}
} else {
$files[] = "\"".$ls["file"]."\"";
}
if(do_mpd_command_list($connection, $command, $files) === true) {
$command_successful = true;
} else {
$command_successful = false;
}
}
break;
case "addall_recursive":
$files = array();
$command = "add";
$ls = do_mpd_command($connection, "listall".(array_key_exists("directory", $configuration) ? " \"".$configuration["directory"]."\"" : "" ), null, true);
if(array_key_exists("file", $ls)) {
if(is_array($ls["file"])) {
foreach($ls["file"] as $key => $file) {
$files[] = "\"".$file."\"";
}
} else {
$files[] = "\"".$ls["file"]."\"";
}
if(do_mpd_command_list($connection, $command, $files) === true) {
$command_successful = true;
} else {
$command_successful = false;
}
}
break;
case "addlist":
$files = array();
$command = "add";
$ls = $_REQUEST["arg"];
if(is_array($ls)) {
foreach($ls as $key => $file) {
$files[] = "\"".$file."\"";
}
} else {
$files[] = "\"".$ls."\"";
}
if(do_mpd_command_list($connection, $command, $files) === true) {
$command_successful = true;
} else {
$command_successful = false;
}
break;
case "upload_playlist":
$files = array();
$command = "add";
$handle = fopen($_FILES["playlist"]["tmp_name"], "r");
while (!feof($handle)) {
$buffer = fgets($handle, 4096);
$files[] = $buffer;
}
fclose($handle);
if(do_mpd_command_list($connection, $command, $files) === true) {
$command_successful = true;
} else {
$command_successful = false;
}
break;
case "add":
$command = $_REQUEST["command"];
if(array_key_exists("arg", $_REQUEST) && strlen($_REQUEST["arg"])>0) $command.=" \"".$_REQUEST["arg"]."\"";
if (credit()>0 && credit("-1") === true && do_mpd_command($connection, $command) === true){
$command_successful = true;
} else {
$command_successful = false;
}
break;
default:
$command = $_REQUEST["command"];
if(array_key_exists("arg", $_REQUEST) && strlen($_REQUEST["arg"])>0) $command.=" \"".$_REQUEST["arg"]."\"";
if(do_mpd_command($connection, $command) === true) {
$command_successful = true;
} else {
$command_successful = false;
}
}
}
if(array_key_exists("slidercommand", $_REQUEST)) {
$command = $_REQUEST["slidercommand"]." \"";
if ($_REQUEST["sliderintonly"] == "true") $command .= round((($_REQUEST["slider_x"] * ($_REQUEST["slidermax"] - $_REQUEST["slidermin"])) / $_REQUEST["sliderlength"]) + $_REQUEST["slidermin"]);
else $command .= ((($_REQUEST["slider_x"] * ($_REQUEST["slidermax"] - $_REQUEST["slidermin"])) / $_REQUEST["sliderlength"]) + $_REQUEST["slidermin"]);
$command .= "\"";
if(do_mpd_command($connection, $command) === true) {
$command_successful = true;
} else {
$command_successful = false;
}
}
$files = array();
$letters_files = array();
if (array_key_exists ("searched", $configuration)) {
$ls = do_mpd_command ($connection, $configuration["searched"], null, true);
} else {
$ls = do_mpd_command($connection, "lsinfo".(array_key_exists("directory", $configuration) ? " \"".$configuration["directory"]."\"" : "" ), null, true);
}
if (is_array ($ls) && array_key_exists ("file", $ls)) {
if (is_array ($ls["file"])) {
foreach ($ls["file"] as $key => $file) {
$tmp = do_mpd_command($connection, "listallinfo \"".$file."\"", null, true);
$files[] = $tmp;
if (!isset ($letters_files[strtoupper (mbFirstChar (get_songinfo_first($tmp, isset($configuration["sort"]) ? $configuration["sort"] : array("file"), 0)))]))
$letters_files[strtoupper (mbFirstChar (get_songinfo_first($tmp, isset($configuration["sort"]) ? $configuration["sort"] : array("file"), 0)))] = true;
}
} else {
$tmp = do_mpd_command($connection, "listallinfo \"".$ls["file"]."\"", null, true);
$files[] = $tmp;
$letters_files[strtoupper (mbFirstChar (get_songinfo_first($tmp, isset($configuration["sort"]) ? $configuration["sort"] : array("file"), 0)))] = 1;
}
$files = array_values($files);
usort($files, "sort_song");
}
$mpd_status = do_mpd_command ($connection, "status", null, true);
$is_connected = true;
}
?>