mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-03 09:49:30 +02:00
democratic play working, if still slightly sketchy
This commit is contained in:
parent
3508380e99
commit
27ba8110ca
10 changed files with 184 additions and 77 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -193,19 +193,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
|
||||
|
@ -391,33 +378,9 @@ 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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
|
50
server/democratic.ajax.php
Normal file
50
server/democratic.ajax.php
Normal file
|
@ -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:
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue