diff options
-rw-r--r-- | democratic.php | 14 | ||||
-rwxr-xr-x | docs/CHANGELOG | 3 | ||||
-rw-r--r-- | lib/class/democratic.class.php | 100 | ||||
-rw-r--r-- | lib/class/tmpplaylist.class.php | 49 | ||||
-rw-r--r-- | play/index.php | 17 | ||||
-rw-r--r-- | server/ajax.server.php | 4 | ||||
-rw-r--r-- | server/democratic.ajax.php | 50 | ||||
-rw-r--r-- | stream.php | 5 | ||||
-rw-r--r-- | templates/show_democratic_playlist.inc.php | 7 | ||||
-rw-r--r-- | templates/show_manage_democratic.inc.php | 12 |
10 files changed, 184 insertions, 77 deletions
diff --git a/democratic.php b/democratic.php index 67953f03..bf208e5b 100644 --- a/democratic.php +++ b/democratic.php @@ -87,13 +87,9 @@ switch ($_REQUEST['action']) { access_denied(); break; } - - $stream_type = scrub_in($_REQUEST['play_type']); - $tmp_playlist = new tmpPlaylist($_REQUEST['tmp_playlist_id']); - $stream = new Stream($stream_type,array()); - $stream->manual_url_add(unhtmlentities($tmp_playlist->get_vote_url())); - $stream->start(); - if ($stream_type != 'localplay') { exit; } + // Tmp just to make this work + header("Location: " . Config::get('web_path') . "/stream.php?action=democratic"); + exit; break; case 'manage_playlists': if (!$GLOBALS['user']->has_access('75')) { @@ -116,8 +112,8 @@ switch ($_REQUEST['action']) { $tmp_playlist->update_playlist($_REQUEST['playlist_id']); case 'show_playlist': default: - $tmp_playlist = Democratic::get_current_playlist(); - $objects = $tmp_playlist->get_items(); + $democratic = Democratic::get_current_playlist(); + $objects = $democratic->get_items(); require_once Config::get('prefix') . '/templates/show_democratic.inc.php'; break; } // end switch on action diff --git a/docs/CHANGELOG b/docs/CHANGELOG index 4131bb93..ab204325 100755 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -4,6 +4,9 @@ -------------------------------------------------------------------------- v.3.4-Alpha3 + - Inital Version of Democratic play working, minor speed improvements + to normal tmpplaylist class due to simplification and removal + of democratic related code - Added ability to do batch downloads on the FS failed downloads currently will not be garbage collected (Thx COF) - Added default mime type if none found (image/jpg) diff --git a/lib/class/democratic.class.php b/lib/class/democratic.class.php index 78bf5fde..0944dcae 100644 --- a/lib/class/democratic.class.php +++ b/lib/class/democratic.class.php @@ -79,8 +79,8 @@ class Democratic extends tmpPlaylist { public function get_items() { $order = "GROUP BY tmp_playlist_data.id ORDER BY `count` DESC, user_vote.date ASC"; - $vote_select = ", COUNT(user_vote.user) AS `count`"; - $vote_join = "INNER JOIN user_vote ON user_vote.object_id=tmp_playlist_data.id"; + $vote_select = ", COUNT(user_vote.user) AS `count`"; + $vote_join = "INNER JOIN user_vote ON user_vote.object_id=tmp_playlist_data.id"; /* Select all objects from this playlist */ $sql = "SELECT tmp_playlist_data.object_type, tmp_playlist_data.id, tmp_playlist_data.object_id $vote_select " . @@ -99,6 +99,62 @@ class Democratic extends tmpPlaylist { } // get_items + /** + * get_url + * This returns the special play URL for democratic play, only open to ADMINs + */ + public function get_url() { + + $link = Config::get('web_path') . '/play/index.php?demo_id=' . scrub_out($this->id) . + '&sid=' . Stream::get_session() . '&uid=' . scrub_out($GLOBALS['user']->id); + return $link; + + } // get_url + + /** + * get_next_object + * This returns the next object in the tmp_playlist most of the time this + * will just be the top entry, but if there is a base_playlist and no + * items in the playlist then it returns a random entry from the base_playlist + */ + public function get_next_object($offset='') { + + $tmp_id = Dba::escape($this->id); + + // Format the limit statement + $limit_sql = $offset ? intval($offset) . ',1' : '1'; + + /* Add conditions for voting */ + $vote_select = ", COUNT(user_vote.user) AS `count`"; + $order = " GROUP BY tmp_playlist_data.id ORDER BY `count` DESC, user_vote.date ASC"; + $vote_join = "INNER JOIN user_vote ON user_vote.object_id=tmp_playlist_data.id"; + + $sql = "SELECT tmp_playlist_data.object_id $vote_select FROM tmp_playlist_data $vote_join " . + "WHERE tmp_playlist_data.tmp_playlist = '$tmp_id' $order LIMIT $limit_sql"; + $db_results = Dba::query($sql); + + $results = Dba::fetch_assoc($db_results); + + /* If nothing was found and this is a voting playlist then get from base_playlist */ + if (!$results) { + + /* Check for a playlist */ + if ($this->base_playlist != '0') { + /* We need to pull a random one from the base_playlist */ + $base_playlist = new Playlist($this->base_playlist); + $data = $base_playlist->get_random_songs(1); + $results['object_id'] = $data['0']; + } + else { + $sql = "SELECT `id` as `object_id` FROM `song` WHERE `enabled`='1' ORDER BY RAND() LIMIT 1"; + $db_results = Dba::query($sql); + $results = Dba::fetch_assoc($db_results); + } + } + + return $results['object_id']; + + } // get_next_object /** * vote @@ -179,6 +235,46 @@ class Democratic extends tmpPlaylist { } // add_vote + /** + * remove_vote + * This is called to remove a vote by a user for an object, it uses the object_id + * As that's what we'll have most the time, no need to check if they've got an existing + * vote for this, just remove anything that is there + */ + public function remove_vote($object_id) { + + $object_id = Dba::escape($object_id); + $user_id = Dba::escape($GLOBALS['user']->id); + + $sql = "DELETE FROM user_vote USING user_vote INNER JOIN tmp_playlist_data ON tmp_playlist_data.id=user_vote.object_id " . + "WHERE user='$user_id' AND tmp_playlist_data.object_id='$object_id' " . + "AND tmp_playlist_data.tmp_playlist='" . Dba::escape($this->id) . "'"; + $db_results = Dba::query($sql); + + /* Clean up anything that has no votes */ + self::prune_tracks(); + + return true; + + } // remove_vote + + /** + * delete_votes + * This removes the votes for the specified object on the current playlist + */ + public function delete_votes($row_id) { + + $row_id = Dba::escape($row_id); + + $sql = "DELETE FROM `user_vote` WHERE `object_id`='$row_id'"; + $db_results = Dba::query($sql); + + $sql = "DELETE FROM `tmp_playlist_data` WHERE `id`='$row_id'"; + $db_results = Dba::query($sql); + + return true; + + } // delete_votes } // Democratic class diff --git a/lib/class/tmpplaylist.class.php b/lib/class/tmpplaylist.class.php index 1ab3ea39..781067dd 100644 --- a/lib/class/tmpplaylist.class.php +++ b/lib/class/tmpplaylist.class.php @@ -194,19 +194,6 @@ class tmpPlaylist { } // get_next_object /** - * get_vote_url - * This returns the special play URL for democratic play, only open to ADMINs - */ - public function get_vote_url() { - - $link = Config::get('web_path') . '/play/index.php?tmp_id=' . scrub_out($this->id) . - '&sid=' . scrub_out(session_id()) . '&uid=' . scrub_out($GLOBALS['user']->id); - - return $link; - - } // get_vote_url - - /** * count_items * This returns a count of the total number of tracks that are in this tmp playlist */ @@ -392,32 +379,8 @@ class tmpPlaylist { } // vote_active /** - * remove_vote - * This is called to remove a vote by a user for an object, it uses the object_id - * As that's what we'll have most the time, no need to check if they've got an existing - * vote for this, just remove anything that is there - */ - public function remove_vote($object_id) { - - $object_id = Dba::escape($object_id); - $user_id = Dba::escape($GLOBALS['user']->id); - - $sql = "DELETE FROM user_vote USING user_vote INNER JOIN tmp_playlist_data ON tmp_playlist_data.id=user_vote.object_id " . - "WHERE user='$user_id' AND tmp_playlist_data.object_id='$object_id' " . - "AND tmp_playlist_data.tmp_playlist='" . Dba::escape($this->id) . "'"; - $db_results = Dba::query($sql); - - /* Clean up anything that has no votes */ - self::prune_tracks(); - - return true; - - } // remove_vote - - /** * delete_track - * This deletes a track and any assoicated votes, we only check for - * votes if it's vote playlist, id is a object_id + * This deletes a track from the tmpplaylist */ public function delete_track($id) { @@ -428,18 +391,10 @@ class tmpPlaylist { " WHERE `id`='$id'"; $db_results = Dba::query($sql); - /* If this is a voting playlit prune votes */ - if ($this->type == 'vote') { - $sql = "DELETE FROM user_vote USING user_vote " . - "LEFT JOIN tmp_playlist_data ON user_vote.object_id = tmp_playlist_data.id " . - "WHERE tmp_playlist_data.id IS NULL"; - $db_results = Dba::query($sql); - } - return true; } // delete_track - + /** * clear_playlist * This is really just a wrapper function, it clears the entire playlist diff --git a/play/index.php b/play/index.php index 7577b396..55bce5ac 100644 --- a/play/index.php +++ b/play/index.php @@ -36,11 +36,11 @@ $song_id = scrub_in($_REQUEST['song']); $sid = scrub_in($_REQUEST['sid']); /* This is specifically for tmp playlist requests */ -$tmp_id = scrub_in($_REQUEST['tmp_id']); +$demo_id = scrub_in($_REQUEST['demo_id']); $random = scrub_in($_REQUEST['random']); /* First things first, if we don't have a uid/song_id stop here */ -if (empty($song_id) && empty($tmp_id) && empty($random)) { +if (empty($song_id) && empty($demo_id) && empty($random)) { debug_event('no_song',"Error: No Song UID Specified, nothing to play",'2'); exit; } @@ -60,13 +60,6 @@ if (make_bool($GLOBALS['user']->disabled)) { exit; } -/* If we're using auth and we can't find a username for this user */ -if (Config::get('use_auth') AND !$GLOBALS['user']->username AND !$GLOBALS['user']->is_xmlrpc() ) { - debug_event('user_not_found',"Error $user->username not found, stream access denied",'3'); - echo "Error: No User Found"; - exit; -} - // If we're doing XML-RPC check _GET if (Config::get('xml_rpc')) { $xml_rpc = $_GET['xml_rpc']; @@ -113,10 +106,10 @@ if (Config::get('access_control')) { * current song, and do any other crazyness * we need to */ -if ($tmp_id) { - $tmp_playlist = new tmpPlaylist($tmp_id); +if ($demo_id) { + $democratic = new Democratic($demo_id); /* This takes into account votes etc and removes the */ - $song_id = $tmp_playlist->get_next_object(); + $song_id = $democratic->get_next_object(); } /** diff --git a/server/ajax.server.php b/server/ajax.server.php index 21b19f7a..4f9a954b 100644 --- a/server/ajax.server.php +++ b/server/ajax.server.php @@ -61,6 +61,10 @@ switch ($_REQUEST['page']) { require_once Config::get('prefix') . '/server/stream.ajax.php'; exit; break; + case 'democratic': + require_once Config::get('prefix') . '/server/democratic.ajax.php'; + exit; + break; default: // A taste of compatibility break; diff --git a/server/democratic.ajax.php b/server/democratic.ajax.php new file mode 100644 index 00000000..1bf2cdcb --- /dev/null +++ b/server/democratic.ajax.php @@ -0,0 +1,50 @@ +<?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. + +*/ + +/** + * Sub-Ajax page, requires AJAX_INCLUDE as one + */ +if (AJAX_INCLUDE != '1') { exit; } + +switch ($_REQUEST['action']) { + case 'delete': + if (!$GLOBALS['user']->has_access('75')) { + exit; + } + + $democratic = Democratic::get_current_playlist(); + $democratic->delete_votes($_REQUEST['row_id']); + + ob_start(); + $objects = $democratic->get_items(); + require_once Config::get('prefix') . '/templates/show_democratic_playlist.inc.php'; + $results['democratic_playlist'] = ob_get_contents(); + ob_end_clean(); + + break; + default: + $results['rfc3514'] = '0x1'; + break; +} // switch on action; + +// We always do this +echo xml_from_array($results); +?> @@ -159,6 +159,11 @@ switch ($_REQUEST['action']) { $options = array('limit' => $_REQUEST['random'], 'random_type' => $_REQUEST['random_type'],'size_limit'=>$_REQUEST['size_limit']); $song_ids = get_random_songs($options, $matchlist); break; + case 'democratic': + $democratic = Democratic::get_current_playlist(); + $urls[] = $democratic->get_url(); + $song_ids = array(); + break; case 'download': $song_ids[] = $_REQUEST['song_id']; default: diff --git a/templates/show_democratic_playlist.inc.php b/templates/show_democratic_playlist.inc.php index eba142f4..5798d522 100644 --- a/templates/show_democratic_playlist.inc.php +++ b/templates/show_democratic_playlist.inc.php @@ -31,7 +31,7 @@ </colgroup> <?php if (!count($objects)) { - $playlist = new Playlist($tmp_playlist->base_playlist); + $playlist = new Playlist($democratic->base_playlist); ?> <tr> <td> @@ -63,15 +63,16 @@ foreach($objects as $row_id=>$object_data) { ?> <tr class="<?php echo flip_class(); ?>"> <td class="cel_action"> - <?php if ($tmp_playlist->has_vote($song_id)) { ?> + <?php if ($democratic->has_vote($song_id)) { ?> <?php } else { ?> <?php } ?> </td> - <td class="cel_votes"><?php echo scrub_out($tmp_playlist->get_vote($row_id)); ?></td> + <td class="cel_votes"><?php echo scrub_out($democratic->get_vote($row_id)); ?></td> <td class="cel_song"><?php echo $song->f_link . " / " . $song->f_album_link . " / " . $song->f_artist_link; ?></td> <td class="cel_time"><?php echo $song->f_time; ?></td> <?php if ($GLOBALS['user']->has_access(100)) { ?> <td class="cel_admin"> + <?php echo Ajax::button('?page=democratic&action=delete&row_id=' . $row_id,'delete',_('Delete'),'delete_row_' . $row_id); ?> </td> <?php } ?> </tr> diff --git a/templates/show_manage_democratic.inc.php b/templates/show_manage_democratic.inc.php index c490d856..c9612f23 100644 --- a/templates/show_manage_democratic.inc.php +++ b/templates/show_manage_democratic.inc.php @@ -30,19 +30,22 @@ show_box_top(_('Manage Democratic Playlists')); ?> <tr class="th-top"> <th class="cel_number"><?php echo _('Playlist'); ?></th> <th class="cel_base_playlist"><?php echo _('Base Playlist'); ?></th> - <th class="cel_vote_count"><?php echo _('Current Number of Votes'); ?></th> + <th class="cel_vote_count"><?php echo _('Songs'); ?></th> <th class="cel_action"><?php echo _('Action'); ?></th> </tr> <?php foreach ($playlists as $democratic_id) { $democratic = new Democratic($democratic_id); $playlist = new Playlist($democratic->base_playlist); + $playlist->format(); ?> -<tr> +<tr class="<?php echo flip_class(); ?>"> <td><?php echo abs($democratic->id); ?></td> - <td><?php echo scrub_out($playlist->name); ?></td> + <td><?php echo $playlist->f_link; ?></td> <td><?php echo $democratic->count_items(); ?></td> - <td> </td> + <td> + <a href="<?php echo Config::get('web_path'); ?>/stream.php?action=democratic"><?php echo get_user_icon('all'); ?></a> + </td> </tr> <?php } if (!count($playlists)) { ?> <tr> @@ -50,6 +53,7 @@ show_box_top(_('Manage Democratic Playlists')); ?> </tr> <?php } ?> </table> +<br /> <div> <a class="button" href="<?php echo Config::get('web_path'); ?>/democratic.php?action=show_create"><?php echo _('Create New Playlist'); ?></a> </div> |