1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-03 17:59:21 +02:00

democratic play working, if still slightly sketchy

This commit is contained in:
Karl 'vollmerk' Vollmer 2007-11-24 21:16:13 +00:00
parent 3508380e99
commit 27ba8110ca
10 changed files with 184 additions and 77 deletions

View file

@ -87,13 +87,9 @@ switch ($_REQUEST['action']) {
access_denied(); access_denied();
break; break;
} }
// Tmp just to make this work
$stream_type = scrub_in($_REQUEST['play_type']); header("Location: " . Config::get('web_path') . "/stream.php?action=democratic");
$tmp_playlist = new tmpPlaylist($_REQUEST['tmp_playlist_id']); exit;
$stream = new Stream($stream_type,array());
$stream->manual_url_add(unhtmlentities($tmp_playlist->get_vote_url()));
$stream->start();
if ($stream_type != 'localplay') { exit; }
break; break;
case 'manage_playlists': case 'manage_playlists':
if (!$GLOBALS['user']->has_access('75')) { if (!$GLOBALS['user']->has_access('75')) {
@ -116,8 +112,8 @@ switch ($_REQUEST['action']) {
$tmp_playlist->update_playlist($_REQUEST['playlist_id']); $tmp_playlist->update_playlist($_REQUEST['playlist_id']);
case 'show_playlist': case 'show_playlist':
default: default:
$tmp_playlist = Democratic::get_current_playlist(); $democratic = Democratic::get_current_playlist();
$objects = $tmp_playlist->get_items(); $objects = $democratic->get_items();
require_once Config::get('prefix') . '/templates/show_democratic.inc.php'; require_once Config::get('prefix') . '/templates/show_democratic.inc.php';
break; break;
} // end switch on action } // end switch on action

View file

@ -4,6 +4,9 @@
-------------------------------------------------------------------------- --------------------------------------------------------------------------
v.3.4-Alpha3 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 - Added ability to do batch downloads on the FS failed downloads
currently will not be garbage collected (Thx COF) currently will not be garbage collected (Thx COF)
- Added default mime type if none found (image/jpg) - Added default mime type if none found (image/jpg)

View file

@ -79,8 +79,8 @@ class Democratic extends tmpPlaylist {
public function get_items() { public function get_items() {
$order = "GROUP BY tmp_playlist_data.id ORDER BY `count` DESC, user_vote.date ASC"; $order = "GROUP BY tmp_playlist_data.id ORDER BY `count` DESC, user_vote.date ASC";
$vote_select = ", COUNT(user_vote.user) AS `count`"; $vote_select = ", COUNT(user_vote.user) AS `count`";
$vote_join = "INNER JOIN user_vote ON user_vote.object_id=tmp_playlist_data.id"; $vote_join = "INNER JOIN user_vote ON user_vote.object_id=tmp_playlist_data.id";
/* Select all objects from this playlist */ /* Select all objects from this playlist */
$sql = "SELECT tmp_playlist_data.object_type, tmp_playlist_data.id, tmp_playlist_data.object_id $vote_select " . $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_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 * vote
@ -179,6 +235,46 @@ class Democratic extends tmpPlaylist {
} // add_vote } // 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 } // Democratic class

View file

@ -193,19 +193,6 @@ class tmpPlaylist {
} // get_next_object } // 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 * count_items
* This returns a count of the total number of tracks that are in this tmp playlist * This returns a count of the total number of tracks that are in this tmp playlist
@ -391,33 +378,9 @@ class tmpPlaylist {
} // vote_active } // 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 * delete_track
* This deletes a track and any assoicated votes, we only check for * This deletes a track from the tmpplaylist
* votes if it's vote playlist, id is a object_id
*/ */
public function delete_track($id) { public function delete_track($id) {
@ -428,18 +391,10 @@ class tmpPlaylist {
" WHERE `id`='$id'"; " WHERE `id`='$id'";
$db_results = Dba::query($sql); $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; return true;
} // delete_track } // delete_track
/** /**
* clear_playlist * clear_playlist
* This is really just a wrapper function, it clears the entire playlist * This is really just a wrapper function, it clears the entire playlist

View file

@ -36,11 +36,11 @@ $song_id = scrub_in($_REQUEST['song']);
$sid = scrub_in($_REQUEST['sid']); $sid = scrub_in($_REQUEST['sid']);
/* This is specifically for tmp playlist requests */ /* 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']); $random = scrub_in($_REQUEST['random']);
/* First things first, if we don't have a uid/song_id stop here */ /* 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'); debug_event('no_song',"Error: No Song UID Specified, nothing to play",'2');
exit; exit;
} }
@ -60,13 +60,6 @@ if (make_bool($GLOBALS['user']->disabled)) {
exit; 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 we're doing XML-RPC check _GET
if (Config::get('xml_rpc')) { if (Config::get('xml_rpc')) {
$xml_rpc = $_GET['xml_rpc']; $xml_rpc = $_GET['xml_rpc'];
@ -113,10 +106,10 @@ if (Config::get('access_control')) {
* current song, and do any other crazyness * current song, and do any other crazyness
* we need to * we need to
*/ */
if ($tmp_id) { if ($demo_id) {
$tmp_playlist = new tmpPlaylist($tmp_id); $democratic = new Democratic($demo_id);
/* This takes into account votes etc and removes the */ /* This takes into account votes etc and removes the */
$song_id = $tmp_playlist->get_next_object(); $song_id = $democratic->get_next_object();
} }
/** /**

View file

@ -61,6 +61,10 @@ switch ($_REQUEST['page']) {
require_once Config::get('prefix') . '/server/stream.ajax.php'; require_once Config::get('prefix') . '/server/stream.ajax.php';
exit; exit;
break; break;
case 'democratic':
require_once Config::get('prefix') . '/server/democratic.ajax.php';
exit;
break;
default: default:
// A taste of compatibility // A taste of compatibility
break; break;

View 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);
?>

View file

@ -159,6 +159,11 @@ switch ($_REQUEST['action']) {
$options = array('limit' => $_REQUEST['random'], 'random_type' => $_REQUEST['random_type'],'size_limit'=>$_REQUEST['size_limit']); $options = array('limit' => $_REQUEST['random'], 'random_type' => $_REQUEST['random_type'],'size_limit'=>$_REQUEST['size_limit']);
$song_ids = get_random_songs($options, $matchlist); $song_ids = get_random_songs($options, $matchlist);
break; break;
case 'democratic':
$democratic = Democratic::get_current_playlist();
$urls[] = $democratic->get_url();
$song_ids = array();
break;
case 'download': case 'download':
$song_ids[] = $_REQUEST['song_id']; $song_ids[] = $_REQUEST['song_id'];
default: default:

View file

@ -31,7 +31,7 @@
</colgroup> </colgroup>
<?php <?php
if (!count($objects)) { if (!count($objects)) {
$playlist = new Playlist($tmp_playlist->base_playlist); $playlist = new Playlist($democratic->base_playlist);
?> ?>
<tr> <tr>
<td> <td>
@ -63,15 +63,16 @@ foreach($objects as $row_id=>$object_data) {
?> ?>
<tr class="<?php echo flip_class(); ?>"> <tr class="<?php echo flip_class(); ?>">
<td class="cel_action"> <td class="cel_action">
<?php if ($tmp_playlist->has_vote($song_id)) { ?> <?php if ($democratic->has_vote($song_id)) { ?>
<?php } else { ?> <?php } else { ?>
<?php } ?> <?php } ?>
</td> </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_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> <td class="cel_time"><?php echo $song->f_time; ?></td>
<?php if ($GLOBALS['user']->has_access(100)) { ?> <?php if ($GLOBALS['user']->has_access(100)) { ?>
<td class="cel_admin"> <td class="cel_admin">
<?php echo Ajax::button('?page=democratic&action=delete&row_id=' . $row_id,'delete',_('Delete'),'delete_row_' . $row_id); ?>
</td> </td>
<?php } ?> <?php } ?>
</tr> </tr>

View file

@ -30,19 +30,22 @@ show_box_top(_('Manage Democratic Playlists')); ?>
<tr class="th-top"> <tr class="th-top">
<th class="cel_number"><?php echo _('Playlist'); ?></th> <th class="cel_number"><?php echo _('Playlist'); ?></th>
<th class="cel_base_playlist"><?php echo _('Base 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> <th class="cel_action"><?php echo _('Action'); ?></th>
</tr> </tr>
<?php <?php
foreach ($playlists as $democratic_id) { foreach ($playlists as $democratic_id) {
$democratic = new Democratic($democratic_id); $democratic = new Democratic($democratic_id);
$playlist = new Playlist($democratic->base_playlist); $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 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><?php echo $democratic->count_items(); ?></td>
<td>&nbsp;</td> <td>
<a href="<?php echo Config::get('web_path'); ?>/stream.php?action=democratic"><?php echo get_user_icon('all'); ?></a>
</td>
</tr> </tr>
<?php } if (!count($playlists)) { ?> <?php } if (!count($playlists)) { ?>
<tr> <tr>
@ -50,6 +53,7 @@ show_box_top(_('Manage Democratic Playlists')); ?>
</tr> </tr>
<?php } ?> <?php } ?>
</table> </table>
<br />
<div> <div>
<a class="button" href="<?php echo Config::get('web_path'); ?>/democratic.php?action=show_create"><?php echo _('Create New Playlist'); ?></a> <a class="button" href="<?php echo Config::get('web_path'); ?>/democratic.php?action=show_create"><?php echo _('Create New Playlist'); ?></a>
</div> </div>