diff --git a/lib/class/playlist.class.php b/lib/class/playlist.class.php index f46bc66f..515edde4 100644 --- a/lib/class/playlist.class.php +++ b/lib/class/playlist.class.php @@ -252,13 +252,25 @@ class Playlist { } // get_users + /** + * update + * This function takes a key'd array of data and runs updates + */ + public function update($data) { + + if ($data['name'] != $this->name) { + $this->update_name($data['name']); + } + + } // update + /** * update_type * This updates the playlist type, it calls the generic update_item function */ - function update_type($new_type) { + private function update_type($new_type) { - if ($this->_update_item('type',$new_type,'100')) { + if ($this->_update_item('type',$new_type,'50')) { $this->type = $new_type; } @@ -268,9 +280,9 @@ class Playlist { * update_name * This updates the playlist name, it calls the generic update_item function */ - function update_name($new_name) { + private function update_name($new_name) { - if ($this->_update_item('name',$new_name,'100')) { + if ($this->_update_item('name',$new_name,'50')) { $this->name = $new_name; } @@ -280,16 +292,16 @@ class Playlist { * _update_item * This is the generic update function, it does the escaping and error checking */ - function _update_item($field,$value,$level) { + private function _update_item($field,$value,$level) { if ($GLOBALS['user']->id != $this->user AND !$GLOBALS['user']->has_access($level)) { return false; } - $value = sql_escape($value); + $value = Dba::escape($value); - $sql = "UPDATE playlist SET $field='$value' WHERE id='" . sql_escape($this->id) . "'"; - $db_results = mysql_query($sql, dbh()); + $sql = "UPDATE `playlist` SET $field='$value' WHERE `id`='" . Dba::escape($this->id) . "'"; + $db_results = Dba::query($sql); return $db_results; diff --git a/lib/class/scrobbler.class.php b/lib/class/scrobbler.class.php index d01b5000..78c5f36e 100644 --- a/lib/class/scrobbler.class.php +++ b/lib/class/scrobbler.class.php @@ -29,6 +29,7 @@ class scrobbler { public $submit_port; public $submit_url; public $queued_tracks; + public $reset_handshake = false; /** * Constructor @@ -206,16 +207,19 @@ class scrobbler { $split_response = preg_split("/\r\n\r\n/", $buffer); if(!isset($split_response[1])) { $this->error_msg = 'Did not receive a valid response'; + $this->reset_handshake = true; return false; } $response = explode("\n", $split_response[1]); if(!isset($response[0])) { $this->error_msg = 'Unknown error submitting tracks'. "\nDebug output:\n".$buffer; + $this->reset_handshake = true; return false; } if(substr($response[0], 0, 6) == 'FAILED') { $this->error_msg = $response[0]; + $this->reset_handshake = true; return false; } if(substr($response[0], 0, 7) == 'BADAUTH') { @@ -224,11 +228,13 @@ class scrobbler { } if (substr($response[0],0,10) == 'BADSESSION') { $this->error_msg = 'Invalid Session passed (' . trim($response[0]) . ')'; + $this->reset_handshake = true; return false; } if(substr($response[0], 0, 2) != 'OK') { $this->error_msg = 'Response Not ok, unknown error'. "\nDebug output:\n".$buffer; + $this->reset_handshake = true; return false; } diff --git a/modules/plugins/Lastfm.plugin.php b/modules/plugins/Lastfm.plugin.php index 20de8ea5..fd9cca82 100644 --- a/modules/plugins/Lastfm.plugin.php +++ b/modules/plugins/Lastfm.plugin.php @@ -102,13 +102,24 @@ class AmpacheLastfm { // Create our scrobbler with everything this time and then queue it $scrobbler = new scrobbler($this->username,$this->password,$this->hostname,$this->port,$this->path,$this->challenge); + + // Check to see if the scrobbling works if (!$scrobbler->queue_track($song->f_artist_full,$song->f_album_full,$song->title,time(),$song->time,$song->track)) { + // Depending on the error we might need to do soemthing here return false; } // Go ahead and submit it now if (!$scrobbler->submit_tracks()) { debug_event('LastFM','Error Submit Failed: ' . $scrobbler->error_msg,'3'); + if ($scrobbler->reset_handshake) { + debug_event('LastFM','Re-running Handshake due to error','3'); + $this->set_handshake($user_id); + // Try try again + if ($scrobbler->submit_tracks()) { + return true; + } + } return false; } diff --git a/play/index.php b/play/index.php index 15e06041..497be35a 100644 --- a/play/index.php +++ b/play/index.php @@ -28,6 +28,7 @@ define('NO_SESSION','1'); require_once '../lib/init.php'; require_once Config::get('prefix') . '/modules/horde/Browser.php'; +ob_end_clean(); /* These parameters had better come in on the url. */ diff --git a/server/ajax.server.php b/server/ajax.server.php index 9ea93b3c..b8b71aae 100644 --- a/server/ajax.server.php +++ b/server/ajax.server.php @@ -62,9 +62,8 @@ switch ($_REQUEST['action']) { /* Controls the editing of objects */ case 'show_edit_object': - if (!$GLOBALS['user']->has_access('50')) { - exit; - } + // Set the default required level + $level = '50'; switch ($_GET['type']) { case 'album': @@ -87,6 +86,15 @@ switch ($_REQUEST['action']) { $radio = new Radio($_GET['id']); $radio->format(); break; + case 'playlist': + $key = 'playlist_row_' . $_GET['id']; + $playlist = new Playlist($_GET['id']); + $playlist->format(); + // If the current user is the owner, only user is required + if ($playlist->user == $GLOBALS['user']->id) { + $level = '25'; + } + break; default: $key = 'rfc3514'; echo xml_from_array(array($key=>'0x1')); @@ -94,6 +102,11 @@ switch ($_REQUEST['action']) { break; } // end switch on type + // Make sure they got them rights + if (!$GLOBALS['user']->has_access($level)) { + exit; + } + ob_start(); require Config::get('prefix') . '/templates/show_edit_' . $_GET['type'] . '_row.inc.php'; $results[$key] = ob_get_contents(); @@ -101,8 +114,18 @@ switch ($_REQUEST['action']) { echo xml_from_array($results); break; case 'edit_object': + + $level = '50'; + + if ($_POST['type'] = 'playlist') { + $playlist = new Playlist($_POST['id']); + if ($GLOBALS['user']->id == $playlist->user) { + $level = '25'; + } + } + // Make sure we've got them rights - if (!$GLOBALS['user']->has_access('50')) { + if (!$GLOBALS['user']->has_access($level)) { exit; } @@ -131,6 +154,11 @@ switch ($_REQUEST['action']) { $song->update($_POST); $song->format(); break; + case 'playlist': + $key = 'playlist_row_' . $_POST['id']; + $playlist->update($_POST); + $playlist->format(); + break; case 'live_stream': $key = 'live_stream_' . $_POST['id']; Radio::update($_POST); diff --git a/templates/show_edit_playlist_row.inc.php b/templates/show_edit_playlist_row.inc.php new file mode 100644 index 00000000..69e59ed0 --- /dev/null +++ b/templates/show_edit_playlist_row.inc.php @@ -0,0 +1,36 @@ + +