summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/class/playlist.class.php28
-rw-r--r--lib/class/scrobbler.class.php6
-rw-r--r--modules/plugins/Lastfm.plugin.php11
-rw-r--r--play/index.php1
-rw-r--r--server/ajax.server.php36
-rw-r--r--templates/show_edit_playlist_row.inc.php36
-rw-r--r--templates/show_edit_playlist_song_row.inc.php49
-rw-r--r--templates/show_playlist_row.inc.php3
8 files changed, 158 insertions, 12 deletions
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
@@ -253,12 +253,24 @@ 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 @@
+<?php
+/*
+
+ Copyright (c) 2001 - 2007 Ampache.org
+ All rights reserved.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License v2
+ as published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+?>
+<td colspan="5">
+<form method="post" id="edit_playlist_<?php echo $playlist->id; ?>" action="#">
+<table border="0" cellpadding="0" cellspacing="0">
+<tr>
+ <td>
+ <input type="textbox" name="name" size="9" value="<?php echo scrub_out($playlist->name); ?>" />
+ </td>
+ <td>
+ <input type="hidden" name="id" value="<?php echo $playlist->id; ?>" />
+ <input type="hidden" name="type" value="playlist" />
+ <?php echo Ajax::button('?action=edit_object&id=' . $playlist->id . '&type=playlist','download',_('Save Changes'),'save_playlist_' . $playlist->id,'edit_playlist_' . $playlist->id); ?>
+ </td>
+</tr>
+</table>
+</td>
diff --git a/templates/show_edit_playlist_song_row.inc.php b/templates/show_edit_playlist_song_row.inc.php
new file mode 100644
index 00000000..4e713168
--- /dev/null
+++ b/templates/show_edit_playlist_song_row.inc.php
@@ -0,0 +1,49 @@
+<?php
+/*
+
+ Copyright (c) 2001 - 2007 Ampache.org
+ All rights reserved.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License v2
+ as published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+?>
+<td colspan="8">
+<form method="post" id="edit_song_<?php echo $song->id; ?>" action="#">
+<table border="0" cellpadding="3" cellspacing="0">
+<tr>
+<td>
+ <input type="textbox" name="name" value="<?php echo scrub_out($song->title); ?>" />
+</td>
+<td>
+ <?php show_artist_select('artist',$song->artist); ?>
+</td>
+<td>
+ <?php show_album_select('album',$song->album); ?>
+</td>
+<td>
+ <?php show_genre_select('genre',$song->genre); ?>
+</td>
+<td>
+ <input type="textbox" name="track" size="3" value="<?php echo scrub_out($song->track); ?>" />
+</td>
+<td>
+ <input type="hidden" name="id" value="<?php echo $song->id; ?>" />
+ <input type="hidden" name="type" value="song" />
+ <?php echo Ajax::button('?action=edit_object&id=' . $song->id . '&type=song','download',_('Save Changes'),'save_song_' . $song->id,'edit_song_' . $song->id); ?>
+</td>
+</tr>
+</table>
+</form>
+</td>
diff --git a/templates/show_playlist_row.inc.php b/templates/show_playlist_row.inc.php
index f4c4cc3b..99f3caf4 100644
--- a/templates/show_playlist_row.inc.php
+++ b/templates/show_playlist_row.inc.php
@@ -32,4 +32,7 @@
<?php echo get_user_icon('batch_download',_('Batch Download')); ?>
</a>
<?php } ?>
+ <?php if ($playlist->has_access()) { ?>
+ <?php echo Ajax::button('?action=show_edit_object&type=playlist&id=' . $playlist->id,'edit',_('Edit'),'edit_playlist_' . $playlist->id); ?>
+ <?php } ?>
</td>