diff options
-rw-r--r-- | lib/class/localplay.class.php | 37 | ||||
-rwxr-xr-x | modules/kajax/ajax.js | 45 | ||||
-rw-r--r-- | modules/localplay/mpd.controller.php | 11 | ||||
-rw-r--r-- | server/ajax.server.php | 6 | ||||
-rw-r--r-- | templates/show_localplay.inc.php | 2 |
5 files changed, 82 insertions, 19 deletions
diff --git a/lib/class/localplay.class.php b/lib/class/localplay.class.php index a3492ff3..11510f30 100644 --- a/lib/class/localplay.class.php +++ b/lib/class/localplay.class.php @@ -105,6 +105,25 @@ class Localplay { } // has_function + /** + * format_name + * This function takes the track name and checks to see if 'skip' + * is supported in the current player, if so it returns a 'skip to' + * link, otherwise it returns just the text + */ + function format_name($name,$id) { + + $name = scrub_out($name); + + if ($this->has_function('skip')) { + $url = conf('web_path') . '/server/ajax.server.php?action=localplay&cmd=skip&value=' . $id; + + $name = "<span style=\"cursor:pointer;text-decoration:underline;\" onclick=\"ajaxRequest('$url');\">$name</span>"; + } + + return $name; + + } // format_name /** * _map_functions @@ -130,6 +149,7 @@ class Localplay { $this->_function_map['pause'] = $data['pause']; $this->_function_map['next'] = $data['next']; $this->_function_map['prev'] = $data['prev']; + $this->_function_map['skip'] = $data['skip']; $this->_function_map['get_playlist'] = $data['get_playlist']; $this->_function_map['get_playing'] = $data['get_playing']; @@ -261,6 +281,23 @@ class Localplay { } // get /** + * skip + * This isn't a required function, it tells the daemon to skip to the specified song + */ + function skip($song_id) { + + $function = $this->_function_map['skip']; + + if (!$this->_player->$function($song_id)) { + debug_event('localplay','Error: Unable to skip to next song, check ' . $this->type . ' controller','1'); + return false; + } + + return true; + + } // skip + + /** * next * This isn't a required function, it tells the daemon to go to the next * song diff --git a/modules/kajax/ajax.js b/modules/kajax/ajax.js index 0ed70087..cbe86c78 100755 --- a/modules/kajax/ajax.js +++ b/modules/kajax/ajax.js @@ -2,7 +2,31 @@ var http_request = false;
var IE = true;
- function makeRequest(url,getTerms) {
+ function ajaxRequest(url) {
+ if (window.ActiveXObject) { // IE
+ try {
+ http_request = new ActiveXObject("Msxml2.XMLHTTP");
+ }
+ catch (e) {
+ try {
+ http_request = new ActiveXObject("Microsoft.XMLHTTP");
+ }
+ catch (e) {}
+ }
+ }
+ else { // Mozilla
+ IE = false;
+ http_request = new XMLHttpRequest();
+ }
+ if (!http_request) {
+ return false;
+ }
+ http_request.onreadystatechange = function() { };
+ http_request.open('GET', url, true);
+ http_request.send(null);
+ }
+
+ function ajaxPut(url,uid) {
if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
@@ -21,23 +45,14 @@ if (!http_request) {
return false;
}
- http_request.onreadystatechange = function() {};
- http_request.open('GET', url+"?"+getTerms, false);
+ http_request.onreadystatechange = function() { getContents(http_request,uid); };
+ http_request.open('GET', url, true);
http_request.send(null);
}
- function getContents(http_request) {
+ function getContents(http_request,uid) {
if (http_request.readyState == 4) {
- if (http_request.status == 200) {
-
- }
+ data = http_request.responseText;
+ document.getElementById(uid).innerHTML = data;
}
}
-
- function ajaxPut(url,getTerms,uid) {
- makeRequest(url,getTerms);
-
- data = http_request.responseText;
- document.getElementById(uid).innerHTML = data;
- }
-
diff --git a/modules/localplay/mpd.controller.php b/modules/localplay/mpd.controller.php index ac595b26..81bf3adf 100644 --- a/modules/localplay/mpd.controller.php +++ b/modules/localplay/mpd.controller.php @@ -66,6 +66,7 @@ class AmpacheMpd { $map['connect'] = 'connect'; /* Recommended Functions */ + $map['skip'] = 'skip'; $map['next'] = 'next'; $map['prev'] = 'prev'; $map['pause'] = 'pause'; @@ -186,6 +187,16 @@ class AmpacheMpd { } // stop + /** + * skip + * This tells MPD to skip to the specified song + */ + function skip($song) { + + if (is_null($this->_mpd->SkipTo($song))) { return false; } + return true; + + } // skip /** * next diff --git a/server/ajax.server.php b/server/ajax.server.php index fc691045..bb38d7cc 100644 --- a/server/ajax.server.php +++ b/server/ajax.server.php @@ -38,9 +38,9 @@ switch ($action) { init_preferences(); $localplay = init_localplay(); $localplay->connect(); - $function = scrub_in($_GET['cmd']); - $localplay->$function(); - echo $function; + $function = scrub_in($_GET['cmd']); + $value = scrub_in($_GET['value']); + $localplay->$function($value); break; case 'change_play_type': init_preferences(); diff --git a/templates/show_localplay.inc.php b/templates/show_localplay.inc.php index e73a15cc..9329a114 100644 --- a/templates/show_localplay.inc.php +++ b/templates/show_localplay.inc.php @@ -47,7 +47,7 @@ $songs = $localplay->get(); <?php echo scrub_out($song['track']); ?> </td> <td> - <?php echo scrub_out($song['name']); ?> + <?php echo $localplay->format_name($song['name'],$song['id']); ?> </td> <td> <a href="<?php echo $web_path; ?>/localplay.php?action=delete_song&song_id=<?php echo $song['id']; ?>"><?php echo _('Delete'); ?></a> |