1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-03 01:39:28 +02:00

added in basic browse by song functionality with filtering of unplayed

This commit is contained in:
Karl 'vollmerk' Vollmer 2007-05-06 22:19:37 +00:00
parent 691c838e90
commit 0dcbad80cd
7 changed files with 217 additions and 267 deletions

View file

@ -37,6 +37,7 @@ require_once 'lib/init.php';
/* Display the headers and menus */
require_once Config::get('prefix') . '/templates/header.inc.php';
echo '<div id="browse_content">';
switch($_REQUEST['action']) {
case 'file':
@ -104,37 +105,8 @@ switch($_REQUEST['action']) {
break;
case 'song':
Browse::set_type('song');
/* Setup the View Object */
$view = new View();
$view->import_session_view();
$match = scrub_in($_REQUEST['match']);
require (conf('prefix') . '/templates/show_box_top.inc.php');
show_alphabet_list('song_title','browse.php',$match,'song_title');
/* Detect if it's Browse, and if so don't fill it in */
if ($match == 'Browse') { $match = ''; }
show_alphabet_form($match,_('Show Titles Starting With'),"browse.php");
require (conf('prefix') . '/templates/show_box_bottom.inc.php');
$sql = $song->get_sql_from_match($_REQUEST['match']);
if ($_REQUEST['keep_view']) {
$view->initialize();
}
else {
$db_results = mysql_query($sql, dbh());
$total_items = mysql_num_rows($db_results);
$offset_limit = 999999;
if ($match != 'Show All') { $offset_limit = $user->prefs['offset_limit']; }
$view = new View($sql, 'browse.php?action=song_title','title',$total_items,$offset_limit);
}
if ($view->base_sql) {
$songs = $song->get_songs($view->sql);
show_songs($songs,0,0);
}
$song_ids = Browse::get_objects();
Browse::show_objects($song_ids);
break;
case 'catalog':
@ -146,6 +118,8 @@ switch($_REQUEST['action']) {
break;
} // end Switch $action
echo '</div>';
/* Show the Footer */
show_footer();
?>

BIN
images/icon_add.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 733 B

View file

@ -29,12 +29,14 @@
*/
class Browse {
// Public static vars that are cached
public static $sql;
/**
* constructor
* This should never be called
*/
private __construct() {
private function __construct() {
// Rien a faire
@ -56,9 +58,14 @@ class Browse {
case 'unplayed':
case 'rated':
$key = $_REQUEST['key'];
$_SESSION['browse']['filter'][$key] = make_bool($_REQUEST['value']);
if ($_SESSION['browse']['filter'][$key]) {
unset($_SESSION['browse']['filter'][$key]);
}
else {
$_SESSION['browse']['filter'][$key] = 1;
}
break;
default
default:
// Rien a faire
break;
} // end switch
@ -87,4 +94,145 @@ class Browse {
} // set_type
/**
* get_objects
* This gets an array of the ids of the objects that we are
* currently browsing by it applies the sql and logic based
* filters
*/
public static function get_objects() {
// First we need to get the SQL statement we are going to run
// This has to run against any possible filters (dependent on type)
$sql = self::get_sql();
$db_results = Dba::query($sql);
$results = array();
while ($data = Dba::fetch_assoc($db_results)) {
// If we've hit our offset limit
if (count($results) >= $GLOBALS['user']->prefs['offset_limit']) { return $results; }
// Make sure that this object passes the logic filter
if (self::logic_filter($data['id'])) {
$results[] = $data['id'];
}
} // end while
return $results;
} // get_objects
/**
* get_sql
* This returns the sql statement we are going to use this has to be run
* every time we get the objects because it depends on the filters and the
* type of object we are currently browsing
*/
public static function get_sql() {
// Get our base SQL must always return ID
switch ($_SESSION['browse']['type']) {
case 'album':
break;
case 'artist':
break;
case 'genre':
break;
case 'song':
default:
$sql = "SELECT `song`.`id` FROM `song` ";
break;
} // end base sql
// No sense to go further if we don't have filters
if (!is_array($_SESSION['browse']['filter'])) { return $sql; }
// Foreach the filters and see if any of them can be applied
// as part of a where statement in this sql (type dependent)
$where_sql = "WHERE 1=1 AND ";
foreach ($_SESSION['browse']['filter'] as $key=>$value) {
$where_sql .= self::sql_filter($key,$value);
} // end foreach
$where_sql = rtrim($where_sql,'AND ');
$sql .= $where_sql;
self::$sql = $sql;
return $sql;
} // get_sql
/**
* sql_filter
* This takes a filter name and value and if it is possible
* to filter by this name on this type returns the approiate sql
* if not returns nothing
*/
private static function sql_filter($filter,$value) {
$filter_sql = '';
if ($_SESSION['browse']['type'] == 'song') {
switch($filter) {
case 'alpha_match':
$filter_sql = " `song`.`title` LIKE '" . Dba::escape($value) . "%' AND ";
break;
case 'unplayed':
$filter_sql = " `song`.`played`='0' AND ";
break;
default:
// Rien a faire
break;
} // end list of sqlable filters
} // if it is a song
if ($_SESSION['browse']['type'] == 'album') {
} // end album
return $filter_sql;
} // sql_filter
/**
* logic_filter
* This runs the filters that we can't easily apply
* to the sql so they have to be done after the fact
* these should be limited as they are often intensive and
* require additional queries per object... :(
*/
private static function logic_filter($object_id) {
return true;
} // logic_filter
/**
* show_objects
* This takes an array of objects
* and requires the correct template based on the
* type that we are currently browsing
*/
public static function show_objects($object_ids) {
switch ($_SESSION['browse']['type']) {
case 'song':
show_box_top();
require_once Config::get('prefix') . '/templates/show_songs.inc.php';
show_box_bottom();
break;
} // end switch on type
} // show_object
} // browse

View file

@ -126,12 +126,12 @@ class Song {
} // fill_ext_info
/*!
@function format_type
@discussion gets the type of song we are trying to
play, used to set mime headers and to trick
players into playing them correctly
*/
/**
* format_type
* gets the type of song we are trying to
* play, used to set mime headers and to trick
* players into playing them correctly
*/
function format_type($override='') {
// If we pass an override for downsampling or whatever then use it
@ -633,20 +633,6 @@ class Song {
} // _update_ext_item
/*!
@function format_song
@discussion this takes a song object
and formats it for display
and returns the object cleaned up
*/
function format_song() {
$this->format();
return true;
}
/**
* format
* This takes the current song object

View file

@ -1,7 +1,7 @@
<?php
/*
Copyright (c) 2001 - 2006 Ampache.org
Copyright (c) 2001 - 2007 Ampache.org
All rights reserved.
This program is free software; you can redistribute it and/or

View file

@ -1,211 +0,0 @@
<?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.
*/
$web_path = conf('web_path');
/* If it's a playlist and they've got rights */
if (is_object($playlist) && ($GLOBALS['user']->username == $playlist->user || $GLOBALS['user']->has_access('100'))) {
$tab = 1;
$playlist_owner = true;
}
//Horrible hack!
if ($_SERVER['SCRIPT_NAME'] == '/browse.php') {
// Setup the links
$link_end = '</a>';
$title_start = '<a href="' . $web_path . '/browse.php?keep_view=true&amp;sort_type=song.title&amp;sort_order=0">';
$track_start = '<a href="' . $web_path . '/browse.php?keep_view=true&amp;sort_type=song.track&amp;sort_order=0">';
$bit_start = '<a href="' . $web_path . '/browse.php?keep_view=true&amp;sort_type=song.bitrate&amp;sort_order=0">';
}
?>
<?php require(conf('prefix') . '/templates/show_box_top.inc.php'); ?>
<form id="songs" method="post" enctype="multipart/form-data" action="#" style="Display:inline;">
<table class="tabledata" cellspacing="0" cellpadding="0" border="0">
<?php if (is_object($GLOBALS['view'])) { ?>
<tr class="table-header" align="center">
<td colspan="12">
<?php if ($GLOBALS['view']->offset_limit) { require (conf('prefix') . "/templates/list_header.inc"); } ?>
</td>
</tr>
<?php } ?>
<tr class="table-header">
<th>&nbsp;&nbsp;<a href="#" onclick="check_select('song'); return false;">Select</a></th>
<?php if ($playlist_owner) { ?>
<th><?php echo _('Track'); ?></th>
<?php } ?>
<th><?php echo $title_start . _('Song title') . $link_end; ?></th>
<th><?php echo _('Artist'); ?></th>
<th><?php echo _('Album'); ?></th>
<th><?php echo $track_start . _('Track') . $link_end; ?></th>
<th><?php echo _('Time'); ?></th>
<th><?php echo _('Size'); ?></th>
<th><?php echo $bit_start . _('Bitrate') . $link_end; ?></th>
<th><?php echo _('Genre'); ?></th>
<th><?php echo _('Action'); ?></th>
<?php if (conf('ratings')) { ?>
<th width="95px"><?php echo _('Rating'); ?></th>
<?php } ?>
</tr>
<?php
/* FIXME: don't even get me started with how many things are wrong with this code */
foreach ($song_ids as $song_id) {
/* Arr matey crapy code abounds! */
if (is_object($playlist)) {
if ($song_id['song']) {
$song = new Song($song_id['song']);
$track_id = $song_id['id'];
}
else {
$song = new Song();
$song->title = 'Dynamic Song';
$track_id = $song_id['id'];
}
} // end if playlist
elseif (!is_object($song_id)) {
unset($text_class);
$song = new Song($song_id);
$track_id = $song->id;
}
else {
$song = $song_id;
$track_id = $song->id;
}
$song->format_song();
// Still needed crap
$totalsize += $song->size;
$totaltime += $song->time;
/* If it's disabled */
if ($song->status == "disabled") { $text_class = "class=\"disabled\""; }
?>
<tr class="<?php echo flip_class(); ?>">
<td align="center">
<input type="checkbox" name="song[]" value="<?php echo $track_id; ?>" id="song_<?php echo $track_id; ?>" />
</td>
<?php
if ($playlist_owner) {
$tracknum = $playlist->get_track($track_id); ?>
<td>
<input type="text" tabindex="<?php echo $tab; ?>" size="3" name="<?php echo "tr_" . $track_id; ?>" value="<?php echo $tracknum; ?>" onchange="<?php echo "document.getElementById('song_" . $track_id . "').checked='checked';"; ?>" />
</td>
<?php $tab++;
} ?>
<td>
<?php if ($song->has_flag()) { echo "<strong>**</strong>"; } ?>
<a href="<?php echo $web_path; ?>/song.php?action=single_song&amp;song_id=<?php echo $song->id; ?>" title="<?php echo scrub_out($song->title); ?>" <?php echo $text_class; ?>><?php echo scrub_out($song->f_title); ?></a>
</td>
<td>
<a href="<?php echo $web_path; ?>/artists.php?action=show&amp;artist=<?php echo scrub_out($song->artist); ?>" title="<?php echo scrub_out($song->f_artist_full); ?>" <?php echo $text_class; ?>><?php echo scrub_out($song->f_artist); ?></a>
</td>
<td>
<a href="<?php echo $web_path; ?>/albums.php?action=show&amp;album=<?php echo scrub_out($song->album); ?>" title="<?php echo scrub_out($song->f_album_full); ?>" <?php echo $text_class; ?>><?php echo scrub_out($song->f_album); ?></a>
</td>
<td align="right">
<?php echo $song->track; ?>
</td>
<td align="right">
<?php echo $song->f_time; ?>
</td>
<td align="right" nowrap="nowrap">
<?php echo $song->f_size; ?> MB
</td>
<td align="right">
<?php echo $song->f_bitrate; ?>
</td>
<td>
<a href="<?php echo $web_path; ?>/genre.php?action=show_genre&amp;genre_id=<?php echo $song->genre; ?>">
<?php echo $song->f_genre; ?>
</a>
</td>
<td>
<a href="<?php echo $web_path; ?>/flag.php?action=show_flag&amp;type=song&amp;id=<?php echo $song->id; ?>">
<?php
if ($song->has_flag()) {
echo get_user_icon('flag');
}
else {
echo get_user_icon('flag_off');
}
?>
</a>
<?php if ($GLOBALS['user']->has_access('100')) { ?>
<a href="<?php echo $web_path; ?>/admin/flag.php?action=show_edit_song&amp;song=<?php echo $song->id; ?>">
<?php echo get_user_icon('edit'); ?>
</a>
<?php if ($song->enabled) { ?>
<a href="<?php echo $web_path; ?>/admin/flag.php?action=disable&amp;song_ids=<?php echo $song->id; ?>">
<?php echo get_user_icon('disable'); ?>
</a>
<?php } else { ?>
<a href="<?php echo $web_path; ?>/admin/flag.php?action=enabled&amp;song_ids=<?php echo $song->id; ?>">
<?php echo get_user_icon('enable'); ?>
</a>
<?php } //status ?>
<?php } //access ?>
<?php if ($GLOBALS['user']->prefs['download']) { ?>
<a href="<?php echo $web_path; ?>/download/index.php?action=download&amp;song_id=<?php echo $song->id; ?>&amp;sid=<?php echo scrub_out(session_id()); ?>&amp;fn=<?php echo rawurlencode($song->f_artist_full . " - " . $song->title . "." . $song->type); ?>">
<?php echo get_user_icon('download'); ?>
</a>
<?php } ?>
<?php if ($GLOBALS['user']->prefs['direct_link']) { ?>
<a href="<?php echo scrub_out($song->get_url()); ?>">
<?php echo get_user_icon('link'); ?>
</a>
<?php } ?>
</td>
<?php if(conf('ratings')) { ?>
<td id="rating_<?php echo $song->id; ?>_song">
<?php show_rating($song->id,'song'); ?>
</td>
<?php } ?>
</tr>
<?php
}// foreach loop
$time = floor($totaltime/60) . ":" . sprintf("%02d", ($totaltime%60) );
$megs = sprintf("%.2f", ($totalsize/1048576));
$num = count($song_ids);
?>
<tr class="table-header">
<td></td>
<?php if (is_object($playlist)) { ?> <td></td> <?php } ?>
<td><?php echo _("Total"); ?>:</td>
<td nowrap="nowrap"><?php echo $num; ?> song(s)</td>
<td></td>
<td></td>
<td align="right" nowrap="nowrap"><?php echo $time; ?></td>
<td align="right" nowrap="nowrap"><?php echo $megs; ?> MB</td>
<td></td>
<td></td>
<td colspan="2"></td>
</tr>
<?php if (is_object($GLOBALS['view'])) { ?>
<tr class="even" align="center">
<td colspan="12">
<?php if ($GLOBALS['view']->offset_limit) { require (conf('prefix') . "/templates/list_header.inc"); } ?>
</td>
</tr>
<?php } ?>
</table>
<br />
<?php show_play_selected(); ?>
</form>
<?php require(conf('prefix') . '/templates/show_box_bottom.inc.php'); ?>

View file

@ -0,0 +1,53 @@
<?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.
*/
// First let's setup some vars we're going to use a lot
$web_path = Config::get('web_path');
$ajax_url = Config::get('ajax_url');
?>
<table class="tabledata" cellspacing="0" cellpadding="0">
<tr class="table-header" align="center">
<td colspan="12">
<?php //require Config::get('prefix') . '/templates/list_header.inc.php'; ?>
</td>
</tr>
<tr class="table-header">
<th><?php echo _('Add'); ?></th>
<th><?php echo _('Song Title'); ?></th>
<th><?php echo _('Artist'); ?></th>
<th><?php echo _('Album'); ?></th>
</tr>
<?php
foreach ($object_ids as $song_id) {
$song = new Song($song_id);
$song->format();
?>
<tr class="<?php echo flip_class(); ?>">
<td onclick="ajaxPut('<?php echo $ajax_url; ?>?action=basket&amp;type=song&amp;id=<?php echo $song->id; ?>');return true;">
<?php echo get_user_icon('add'); ?>
</td>
<td><?php echo $song->f_link; ?></td>
<td><?php echo $song->f_artist_link; ?></td>
<td><?php echo $song->f_album_link; ?></td>
</tr>
<?php } ?>
</table>