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
|
; Length that a session will last, the default is very restrictive
|
||||||
; at 15min
|
; at 15min
|
||||||
; DEFAULT: 900
|
; DEFAULT: 1800
|
||||||
session_length = 900
|
session_length = 1800
|
||||||
|
|
||||||
; Length that the session for a single streaming instance will last
|
; 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
|
; 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
|
; 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
|
; of the box to increase this, for reference 86400 = 1 day
|
||||||
; 604800 = 1 week and 2419200 = 1 month
|
; 604800 = 1 week and 2419200 = 1 month
|
||||||
; DEAFULT: 3600
|
; DEAFULT: 7200
|
||||||
remember_length = 3600
|
remember_length = 7200
|
||||||
|
|
||||||
; Name of the Session/Cookie that will sent to the browser
|
; Name of the Session/Cookie that will sent to the browser
|
||||||
; default should be fine
|
; default should be fine
|
||||||
|
|
|
@ -83,6 +83,7 @@ switch ($_REQUEST['action']) {
|
||||||
require_once Config::get('prefix') . '/templates/show_democratic.inc.php';
|
require_once Config::get('prefix') . '/templates/show_democratic.inc.php';
|
||||||
$objects = $democratic->get_items();
|
$objects = $democratic->get_items();
|
||||||
Song::build_cache($democratic->object_ids);
|
Song::build_cache($democratic->object_ids);
|
||||||
|
Democratic::build_vote_cache($democratic->vote_ids);
|
||||||
Browse::set_type('democratic');
|
Browse::set_type('democratic');
|
||||||
Browse::reset();
|
Browse::reset();
|
||||||
Browse::set_static_content(1);
|
Browse::set_static_content(1);
|
||||||
|
|
|
@ -4,6 +4,10 @@
|
||||||
|
|
||||||
--------------------------------------------------------------------------
|
--------------------------------------------------------------------------
|
||||||
v.3.5-Alpha3
|
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)
|
- Correct Issues with multi-byte characters in Lyrics (Thx Momo-i)
|
||||||
- Added caching to Video
|
- Added caching to Video
|
||||||
- Added Video calls to the API
|
- Added Video calls to the API
|
||||||
|
|
|
@ -36,6 +36,8 @@ class Democratic extends tmpPlaylist {
|
||||||
// Build local, buy local
|
// Build local, buy local
|
||||||
public $tmp_playlist;
|
public $tmp_playlist;
|
||||||
public $object_ids = array();
|
public $object_ids = array();
|
||||||
|
public $vote_ids = array();
|
||||||
|
public $user_votes = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor
|
* constructor
|
||||||
|
@ -53,23 +55,26 @@ class Democratic extends tmpPlaylist {
|
||||||
|
|
||||||
} // constructor
|
} // constructor
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get_info
|
* build_vote_cache
|
||||||
* This returns the data from the database
|
* 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'";
|
$idlist = '(' . implode(',',$ids) . ')';
|
||||||
$db_results = Dba::query($sql);
|
|
||||||
|
|
||||||
$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
|
* 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`";
|
$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`.`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 " .
|
"FROM `tmp_playlist_data` $vote_join " .
|
||||||
"WHERE `tmp_playlist_data`.`tmp_playlist`='" . Dba::escape($this->tmp_playlist) . "' $order";
|
"WHERE `tmp_playlist_data`.`tmp_playlist`='" . Dba::escape($this->tmp_playlist) . "' $order";
|
||||||
$db_results = Dba::query($sql);
|
$db_results = Dba::query($sql);
|
||||||
|
@ -199,9 +204,11 @@ class Democratic extends tmpPlaylist {
|
||||||
|
|
||||||
// Itterate and build the sortable array
|
// Itterate and build the sortable array
|
||||||
while ($results = Dba::fetch_assoc($db_results)) {
|
while ($results = Dba::fetch_assoc($db_results)) {
|
||||||
|
|
||||||
// Extra set of data for caching!
|
// Extra set of data for caching!
|
||||||
$this->object_ids[] = $results['object_id'];
|
$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
|
// First build a variable that holds the number of votes for an object
|
||||||
$name = 'vc_' . $results['object_id'];
|
$name = 'vc_' . $results['object_id'];
|
||||||
|
@ -212,12 +219,16 @@ class Democratic extends tmpPlaylist {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Append oen to the vote
|
// Append one to the vote
|
||||||
${$name}++;
|
${$name}++;
|
||||||
$primary_key = ${$name};
|
$primary_key = ${$name};
|
||||||
$secondary_key = $votes[$results['object_id']];
|
$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
|
// Sort highest voted stuff to the top
|
||||||
krsort($items);
|
krsort($items);
|
||||||
|
@ -266,7 +277,7 @@ class Democratic extends tmpPlaylist {
|
||||||
if (count($items) > $offset) {
|
if (count($items) > $offset) {
|
||||||
$array = array_slice($items,$offset,1);
|
$array = array_slice($items,$offset,1);
|
||||||
$item = array_shift($array);
|
$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 */
|
/* 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
|
} // 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
|
} // Democratic class
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -89,19 +89,15 @@ class Stream {
|
||||||
} // start
|
} // start
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* manual_url_add
|
* add_urls
|
||||||
* This manually adds a URL to the stream object for passing
|
* Add an array of urls, it may be a single one who knows, this
|
||||||
* to whatever, this is an exception for when we don't actually
|
* is used for things that aren't coming from media objects
|
||||||
* have a object_id but instead a weird or special URL
|
|
||||||
*/
|
*/
|
||||||
public function manual_url_add($url) {
|
public function add_urls($urls=array()) {
|
||||||
|
|
||||||
if (is_array($url)) {
|
if (!is_array($urls)) { return false; }
|
||||||
$this->urls[] = array_merge($url,$this->urls);
|
|
||||||
}
|
$this->urls = array_merge($urls,$this->urls);
|
||||||
else {
|
|
||||||
$this->urls[] = $url;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // manual_url_add
|
} // manual_url_add
|
||||||
|
|
||||||
|
@ -520,6 +516,13 @@ class Stream {
|
||||||
} // switch on types
|
} // switch on types
|
||||||
$localplay->add($media);
|
$localplay->add($media);
|
||||||
} // foreach object
|
} // foreach object
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add urls after the fact
|
||||||
|
*/
|
||||||
|
foreach ($this->urls as $url) {
|
||||||
|
$localplay->add($url);
|
||||||
|
}
|
||||||
|
|
||||||
$localplay->play();
|
$localplay->play();
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
* tmp_playlist and tmp_playlist_data tables, and sneaks out at night to
|
* tmp_playlist and tmp_playlist_data tables, and sneaks out at night to
|
||||||
* visit user_vote from time to time
|
* visit user_vote from time to time
|
||||||
*/
|
*/
|
||||||
class tmpPlaylist {
|
class tmpPlaylist extends database_object {
|
||||||
|
|
||||||
/* Variables from the Datbase */
|
/* Variables from the Datbase */
|
||||||
public $id;
|
public $id;
|
||||||
|
@ -311,24 +311,6 @@ class tmpPlaylist {
|
||||||
|
|
||||||
} // add_object
|
} // 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
|
* vote_active
|
||||||
* This checks to see if this playlist is a voting playlist
|
* This checks to see if this playlist is a voting playlist
|
||||||
|
|
|
@ -113,7 +113,7 @@ switch ($_REQUEST['action']) {
|
||||||
break;
|
break;
|
||||||
case 'democratic':
|
case 'democratic':
|
||||||
$democratic = new Democratic($_REQUEST['democratic_id']);
|
$democratic = new Democratic($_REQUEST['democratic_id']);
|
||||||
$urls[] = $democratic->play_url();
|
$urls = array($democratic->play_url());
|
||||||
break;
|
break;
|
||||||
case 'download':
|
case 'download':
|
||||||
$media_ids[] = $_REQUEST['song_id'];
|
$media_ids[] = $_REQUEST['song_id'];
|
||||||
|
@ -161,9 +161,7 @@ switch ($_REQUEST['method']) {
|
||||||
|
|
||||||
/* Start the Stream */
|
/* Start the Stream */
|
||||||
$stream = new Stream($stream_type,$media_ids);
|
$stream = new Stream($stream_type,$media_ids);
|
||||||
if (is_array($urls)) {
|
$stream->add_urls($urls);
|
||||||
$stream->manual_url_add($urls);
|
|
||||||
}
|
|
||||||
$stream->start();
|
$stream->start();
|
||||||
|
|
||||||
} // end method switch
|
} // end method switch
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
*/
|
*/
|
||||||
$web_path = Config::get('web_path');
|
$web_path = Config::get('web_path');
|
||||||
?>
|
?>
|
||||||
|
<?php require Config::get('prefix') . '/templates/list_header.inc.php'; ?>
|
||||||
<table class="tabledata" cellpadding="0" cellspacing="0">
|
<table class="tabledata" cellpadding="0" cellspacing="0">
|
||||||
<colgroup>
|
<colgroup>
|
||||||
<col id="col_action" />
|
<col id="col_action" />
|
||||||
|
@ -37,12 +38,12 @@ if (!count($object_ids)) {
|
||||||
$playlist = new Playlist($democratic->base_playlist);
|
$playlist = new Playlist($democratic->base_playlist);
|
||||||
?>
|
?>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<?php echo _('Playing from base Playlist'); ?>:
|
<?php echo _('Playing from base Playlist'); ?>:
|
||||||
<a href="<?php echo $web_path; ?>/playlist.php?action=show_playlist&playlist_id=<?php echo $playlist->id; ?>">
|
<a href="<?php echo $web_path; ?>/playlist.php?action=show_playlist&playlist_id=<?php echo $playlist->id; ?>">
|
||||||
<?php echo scrub_out($playlist->name); ?>
|
<?php echo scrub_out($playlist->name); ?>
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php
|
<?php
|
||||||
} // if no songs
|
} // if no songs
|
||||||
|
@ -63,24 +64,31 @@ else {
|
||||||
<?php
|
<?php
|
||||||
$democratic = Democratic::get_current_playlist();
|
$democratic = Democratic::get_current_playlist();
|
||||||
$democratic->set_parent();
|
$democratic->set_parent();
|
||||||
foreach($object_ids as $row_id=>$object_data) {
|
foreach($object_ids as $row_id=>$data) {
|
||||||
$song = new Song($object_data['0']);
|
$media = new $data['object_type']($data['object_id']);
|
||||||
$song->format();
|
$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(); ?>">
|
<tr class="<?php echo flip_class(); ?>">
|
||||||
<td class="cel_action">
|
<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 echo Ajax::button('?page=democratic&action=delete_vote&row_id=' . $row_id,'delete',_('Remove Vote'),'remove_vote_' . $row_id); ?>
|
||||||
<?php } else { ?>
|
<?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 } ?>
|
<?php } ?>
|
||||||
</td>
|
</td>
|
||||||
<td class="cel_votes"><?php echo scrub_out($democratic->get_vote($row_id)); ?></td>
|
<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 $song->f_link; ?></td>
|
<td class="cel_title"><?php echo $media->f_link; ?></td>
|
||||||
<td class="cel_album"><?php echo $song->f_album_link; ?></td>
|
<td class="cel_album"><?php echo $media->f_album_link; ?></td>
|
||||||
<td class="cel_artist"><?php echo $song->f_artist_link; ?></td>
|
<td class="cel_artist"><?php echo $media->f_artist_link; ?></td>
|
||||||
<td class="cel_time"><?php echo $song->f_time; ?></td>
|
<td class="cel_time"><?php echo $media->f_time; ?></td>
|
||||||
<?php if ($GLOBALS['user']->has_access(100)) { ?>
|
<?php if (Access::check('interface','100')) { ?>
|
||||||
<td class="cel_admin">
|
<td class="cel_admin">
|
||||||
<?php echo Ajax::button('?page=democratic&action=delete&row_id=' . $row_id,'disable',_('Delete'),'delete_row_' . $row_id); ?>
|
<?php echo Ajax::button('?page=democratic&action=delete&row_id=' . $row_id,'disable',_('Delete'),'delete_row_' . $row_id); ?>
|
||||||
</td>
|
</td>
|
||||||
|
@ -96,7 +104,7 @@ foreach($object_ids as $row_id=>$object_data) {
|
||||||
<th class="cel_album"><?php echo _('Album'); ?></th>
|
<th class="cel_album"><?php echo _('Album'); ?></th>
|
||||||
<th class="cel_artist"><?php echo _('Artist'); ?></th>
|
<th class="cel_artist"><?php echo _('Artist'); ?></th>
|
||||||
<th class="cel_time"><?php echo _('Time'); ?></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>
|
<th class="cel_admin"><?php echo _('Admin'); ?></th>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -104,3 +112,4 @@ foreach($object_ids as $row_id=>$object_data) {
|
||||||
} // end else
|
} // end else
|
||||||
?>
|
?>
|
||||||
</table>
|
</table>
|
||||||
|
<?php require Config::get('prefix') . '/templates/list_header.inc.php'; ?>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue