mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-03 17:59:21 +02:00
fix missing page headers on democratic playlist, also show the voters
This commit is contained in:
parent
4b191ae6bb
commit
b49a271f88
8 changed files with 118 additions and 75 deletions
|
@ -46,20 +46,21 @@ database_password = password
|
|||
|
||||
; Length that a session will last, the default is very restrictive
|
||||
; at 15min
|
||||
; DEFAULT: 900
|
||||
session_length = 900
|
||||
; DEFAULT: 1800
|
||||
session_length = 1800
|
||||
|
||||
; Length that the session for a single streaming instance will last
|
||||
; the default is one hour. With some clients, and long songs this can
|
||||
; the default is two hours. With some clients, and long songs this can
|
||||
; cause playback to stop, increase this value if you experience that
|
||||
stream_length = 3600
|
||||
; DEFAULT: 7200
|
||||
stream_length = 7200
|
||||
|
||||
; This length defines how long a 'remember me' session and cookie will
|
||||
; last, the default is 3600, same as length. It is up to the administrator
|
||||
; last, the default is 7200, same as length. It is up to the administrator
|
||||
; of the box to increase this, for reference 86400 = 1 day
|
||||
; 604800 = 1 week and 2419200 = 1 month
|
||||
; DEAFULT: 3600
|
||||
remember_length = 3600
|
||||
; DEAFULT: 7200
|
||||
remember_length = 7200
|
||||
|
||||
; Name of the Session/Cookie that will sent to the browser
|
||||
; default should be fine
|
||||
|
|
|
@ -83,6 +83,7 @@ switch ($_REQUEST['action']) {
|
|||
require_once Config::get('prefix') . '/templates/show_democratic.inc.php';
|
||||
$objects = $democratic->get_items();
|
||||
Song::build_cache($democratic->object_ids);
|
||||
Democratic::build_vote_cache($democratic->vote_ids);
|
||||
Browse::set_type('democratic');
|
||||
Browse::reset();
|
||||
Browse::set_static_content(1);
|
||||
|
|
|
@ -4,6 +4,10 @@
|
|||
|
||||
--------------------------------------------------------------------------
|
||||
v.3.5-Alpha3
|
||||
- Fixed missing page headers on democratic playlist
|
||||
- Show who voted for the sogns on democratic playlist
|
||||
- Increase default stream length to account for the fact that movies
|
||||
are a good bit longer then songs
|
||||
- Correct Issues with multi-byte characters in Lyrics (Thx Momo-i)
|
||||
- Added caching to Video
|
||||
- Added Video calls to the API
|
||||
|
|
|
@ -36,6 +36,8 @@ class Democratic extends tmpPlaylist {
|
|||
// Build local, buy local
|
||||
public $tmp_playlist;
|
||||
public $object_ids = array();
|
||||
public $vote_ids = array();
|
||||
public $user_votes = array();
|
||||
|
||||
/**
|
||||
* constructor
|
||||
|
@ -53,23 +55,26 @@ class Democratic extends tmpPlaylist {
|
|||
|
||||
} // constructor
|
||||
|
||||
|
||||
/**
|
||||
* get_info
|
||||
* This returns the data from the database
|
||||
* build_vote_cache
|
||||
* This builds a vote cache of the objects we've got in the playlist
|
||||
*/
|
||||
private function get_info($id) {
|
||||
public static function build_vote_cache($ids) {
|
||||
|
||||
$id = Dba::escape($id);
|
||||
if (!is_array($ids) OR !count($ids)) { return false; }
|
||||
|
||||
$sql = "SELECT * FROM `democratic` WHERE `id`='$id'";
|
||||
$db_results = Dba::query($sql);
|
||||
$idlist = '(' . implode(',',$ids) . ')';
|
||||
|
||||
$row = Dba::fetch_assoc($db_results);
|
||||
$sql = "SELECT `object_id`,COUNT(`user`) AS `count` FROM user_vote WHERE `object_id` IN $idlist GROUP BY `object_id`";
|
||||
$db_results = Dba::read($sql);
|
||||
|
||||
return $row;
|
||||
while ($row = Dba::fetch_assoc($db_results)) {
|
||||
parent::add_to_cache('democratic_vote',$row['object_id'],$row['count']);
|
||||
}
|
||||
|
||||
} // get_info
|
||||
return true;
|
||||
|
||||
} // build_vote_cache
|
||||
|
||||
/**
|
||||
* set_parent
|
||||
|
@ -187,7 +192,7 @@ class Democratic extends tmpPlaylist {
|
|||
$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`.`id`,`tmp_playlist_data`.`object_type`, `user_vote`.`date`, `tmp_playlist_data`.`object_id` " .
|
||||
$sql = "SELECT `user_vote`.`object_id` AS `vote_id`,`user_vote`.`user`,`tmp_playlist_data`.`id`,`tmp_playlist_data`.`object_type`, `user_vote`.`date`, `tmp_playlist_data`.`object_id` " .
|
||||
"FROM `tmp_playlist_data` $vote_join " .
|
||||
"WHERE `tmp_playlist_data`.`tmp_playlist`='" . Dba::escape($this->tmp_playlist) . "' $order";
|
||||
$db_results = Dba::query($sql);
|
||||
|
@ -202,6 +207,8 @@ class Democratic extends tmpPlaylist {
|
|||
|
||||
// Extra set of data for caching!
|
||||
$this->object_ids[] = $results['object_id'];
|
||||
$this->vote_ids[] = $results['vote_id'];
|
||||
$this->user_votes[$results['vote_id']][] = $results['user'];
|
||||
|
||||
// First build a variable that holds the number of votes for an object
|
||||
$name = 'vc_' . $results['object_id'];
|
||||
|
@ -212,11 +219,15 @@ class Democratic extends tmpPlaylist {
|
|||
}
|
||||
|
||||
|
||||
// Append oen to the vote
|
||||
// Append one to the vote
|
||||
${$name}++;
|
||||
$primary_key = ${$name};
|
||||
$secondary_key = $votes[$results['object_id']];
|
||||
$items[$primary_key][$secondary_key][$results['id']] = array($results['object_id'],$results['object_type'],$results['id']);
|
||||
$items[$primary_key][$secondary_key][$results['id']] = array('object_id'=>$results['object_id'],'object_type'=>$results['object_type'],'id'=>$results['id']);
|
||||
} // gather data
|
||||
|
||||
foreach ($this->user_votes as $key=>$data) {
|
||||
parent::add_to_cache('democratic_voters',$key,$data);
|
||||
}
|
||||
|
||||
// Sort highest voted stuff to the top
|
||||
|
@ -266,7 +277,7 @@ class Democratic extends tmpPlaylist {
|
|||
if (count($items) > $offset) {
|
||||
$array = array_slice($items,$offset,1);
|
||||
$item = array_shift($array);
|
||||
$results['object_id'] = $item['0'];
|
||||
$results['object_id'] = $item['object_id'];
|
||||
}
|
||||
|
||||
/* If nothing was found and this is a voting playlist then get from base_playlist */
|
||||
|
@ -564,5 +575,39 @@ class Democratic extends tmpPlaylist {
|
|||
|
||||
} // clear_votes
|
||||
|
||||
/**
|
||||
* get_vote
|
||||
* This returns the current count for a specific song on this tmp_playlist
|
||||
*/
|
||||
public function get_vote($object_id) {
|
||||
|
||||
if (parent::is_cached('democratic_vote',$object_id)) {
|
||||
return parent::get_from_cache('democratic_vote',$object_id);
|
||||
}
|
||||
|
||||
$object_id = Dba::escape($object_id);
|
||||
|
||||
$sql = "SELECT COUNT(`user`) AS `count` FROM user_vote " .
|
||||
"WHERE `object_id`='$object_id'";
|
||||
$db_results = Dba::read($sql);
|
||||
|
||||
$results = Dba::fetch_assoc($db_results);
|
||||
|
||||
return $results['count'];
|
||||
|
||||
} // get_vote
|
||||
|
||||
/**
|
||||
* get_voters
|
||||
* This returns the users that voted for the specified object
|
||||
* This is an array of user ids
|
||||
*/
|
||||
public function get_voters($object_id) {
|
||||
|
||||
return parent::get_from_cache('democratic_voters',$object_id);
|
||||
|
||||
} // get_voters
|
||||
|
||||
|
||||
} // Democratic class
|
||||
?>
|
||||
|
|
|
@ -89,19 +89,15 @@ class Stream {
|
|||
} // start
|
||||
|
||||
/**
|
||||
* manual_url_add
|
||||
* This manually adds a URL to the stream object for passing
|
||||
* to whatever, this is an exception for when we don't actually
|
||||
* have a object_id but instead a weird or special URL
|
||||
* add_urls
|
||||
* Add an array of urls, it may be a single one who knows, this
|
||||
* is used for things that aren't coming from media objects
|
||||
*/
|
||||
public function manual_url_add($url) {
|
||||
public function add_urls($urls=array()) {
|
||||
|
||||
if (is_array($url)) {
|
||||
$this->urls[] = array_merge($url,$this->urls);
|
||||
}
|
||||
else {
|
||||
$this->urls[] = $url;
|
||||
}
|
||||
if (!is_array($urls)) { return false; }
|
||||
|
||||
$this->urls = array_merge($urls,$this->urls);
|
||||
|
||||
} // manual_url_add
|
||||
|
||||
|
@ -521,6 +517,13 @@ class Stream {
|
|||
$localplay->add($media);
|
||||
} // foreach object
|
||||
|
||||
/**
|
||||
* Add urls after the fact
|
||||
*/
|
||||
foreach ($this->urls as $url) {
|
||||
$localplay->add($url);
|
||||
}
|
||||
|
||||
$localplay->play();
|
||||
|
||||
} // create_localplay
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
* tmp_playlist and tmp_playlist_data tables, and sneaks out at night to
|
||||
* visit user_vote from time to time
|
||||
*/
|
||||
class tmpPlaylist {
|
||||
class tmpPlaylist extends database_object {
|
||||
|
||||
/* Variables from the Datbase */
|
||||
public $id;
|
||||
|
@ -311,24 +311,6 @@ class tmpPlaylist {
|
|||
|
||||
} // add_object
|
||||
|
||||
/**
|
||||
* get_vote
|
||||
* This returns the current count for a specific song on this tmp_playlist
|
||||
*/
|
||||
public function get_vote($object_id) {
|
||||
|
||||
$object_id = Dba::escape($object_id);
|
||||
|
||||
$sql = "SELECT COUNT(`user`) AS `count` FROM user_vote " .
|
||||
" WHERE object_id='$object_id'";
|
||||
$db_results = Dba::query($sql);
|
||||
|
||||
$results = Dba::fetch_assoc($db_results);
|
||||
|
||||
return $results['count'];
|
||||
|
||||
} // get_vote
|
||||
|
||||
/**
|
||||
* vote_active
|
||||
* This checks to see if this playlist is a voting playlist
|
||||
|
|
|
@ -113,7 +113,7 @@ switch ($_REQUEST['action']) {
|
|||
break;
|
||||
case 'democratic':
|
||||
$democratic = new Democratic($_REQUEST['democratic_id']);
|
||||
$urls[] = $democratic->play_url();
|
||||
$urls = array($democratic->play_url());
|
||||
break;
|
||||
case 'download':
|
||||
$media_ids[] = $_REQUEST['song_id'];
|
||||
|
@ -161,9 +161,7 @@ switch ($_REQUEST['method']) {
|
|||
|
||||
/* Start the Stream */
|
||||
$stream = new Stream($stream_type,$media_ids);
|
||||
if (is_array($urls)) {
|
||||
$stream->manual_url_add($urls);
|
||||
}
|
||||
$stream->add_urls($urls);
|
||||
$stream->start();
|
||||
|
||||
} // end method switch
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
*/
|
||||
$web_path = Config::get('web_path');
|
||||
?>
|
||||
<?php require Config::get('prefix') . '/templates/list_header.inc.php'; ?>
|
||||
<table class="tabledata" cellpadding="0" cellspacing="0">
|
||||
<colgroup>
|
||||
<col id="col_action" />
|
||||
|
@ -63,24 +64,31 @@ else {
|
|||
<?php
|
||||
$democratic = Democratic::get_current_playlist();
|
||||
$democratic->set_parent();
|
||||
foreach($object_ids as $row_id=>$object_data) {
|
||||
$song = new Song($object_data['0']);
|
||||
$song->format();
|
||||
foreach($object_ids as $row_id=>$data) {
|
||||
$media = new $data['object_type']($data['object_id']);
|
||||
$media->format();
|
||||
$voters = $democratic->get_voters($row_id);
|
||||
$voters_string = '';
|
||||
foreach ($voters as $client_id) {
|
||||
$client = new User($client_id);
|
||||
$voters_string .= $client->fullname . ',';
|
||||
}
|
||||
$voters_string = rtrim($voters_string,',');
|
||||
?>
|
||||
<tr class="<?php echo flip_class(); ?>">
|
||||
<td class="cel_action">
|
||||
<?php if ($democratic->has_vote($song->id)) { ?>
|
||||
<?php if ($democratic->has_vote($media->id)) { ?>
|
||||
<?php echo Ajax::button('?page=democratic&action=delete_vote&row_id=' . $row_id,'delete',_('Remove Vote'),'remove_vote_' . $row_id); ?>
|
||||
<?php } else { ?>
|
||||
<?php echo Ajax::button('?page=democratic&action=add_vote&object_id=' . $song->id . '&type=' . scrub_out($object_data['1']),'tick',_('Add Vote'),'remove_vote_' . $row_id); ?>
|
||||
<?php echo Ajax::button('?page=democratic&action=add_vote&object_id=' . $media->id . '&type=' . scrub_out($data['object_type']),'tick',_('Add Vote'),'remove_vote_' . $row_id); ?>
|
||||
<?php } ?>
|
||||
</td>
|
||||
<td class="cel_votes"><?php echo scrub_out($democratic->get_vote($row_id)); ?></td>
|
||||
<td class="cel_title"><?php echo $song->f_link; ?></td>
|
||||
<td class="cel_album"><?php echo $song->f_album_link; ?></td>
|
||||
<td class="cel_artist"><?php echo $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_votes" >(<?php echo scrub_out($democratic->get_vote($row_id)); ?>) <span class="information"><?php echo scrub_out($voters_string); ?></span></td>
|
||||
<td class="cel_title"><?php echo $media->f_link; ?></td>
|
||||
<td class="cel_album"><?php echo $media->f_album_link; ?></td>
|
||||
<td class="cel_artist"><?php echo $media->f_artist_link; ?></td>
|
||||
<td class="cel_time"><?php echo $media->f_time; ?></td>
|
||||
<?php if (Access::check('interface','100')) { ?>
|
||||
<td class="cel_admin">
|
||||
<?php echo Ajax::button('?page=democratic&action=delete&row_id=' . $row_id,'disable',_('Delete'),'delete_row_' . $row_id); ?>
|
||||
</td>
|
||||
|
@ -96,7 +104,7 @@ foreach($object_ids as $row_id=>$object_data) {
|
|||
<th class="cel_album"><?php echo _('Album'); ?></th>
|
||||
<th class="cel_artist"><?php echo _('Artist'); ?></th>
|
||||
<th class="cel_time"><?php echo _('Time'); ?></th>
|
||||
<?php if ($GLOBALS['user']->has_access(100)) { ?>
|
||||
<?php if (Access::check('interface','100')) { ?>
|
||||
<th class="cel_admin"><?php echo _('Admin'); ?></th>
|
||||
<?php } ?>
|
||||
</tr>
|
||||
|
@ -104,3 +112,4 @@ foreach($object_ids as $row_id=>$object_data) {
|
|||
} // end else
|
||||
?>
|
||||
</table>
|
||||
<?php require Config::get('prefix') . '/templates/list_header.inc.php'; ?>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue