1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-03 09:49:30 +02:00

fixed mysql5 crap, thx WarrenG cleaned up some of the show_songs code and stuff that calls it, did a little work on playlists

This commit is contained in:
Karl 'vollmerk' Vollmer 2006-01-04 08:11:01 +00:00
parent c917726df7
commit 4e9823cd10
17 changed files with 203 additions and 141 deletions

View file

@ -46,20 +46,16 @@ if ($_REQUEST['action'] === 'clear_art') {
} // clear_art } // clear_art
// if we have album // if we have album
elseif (isset($album)) { elseif (isset($album)) {
$album = new Album($album); $album = new Album($_REQUEST['album']);
$album->format_album(); $album->format_album();
$artist_obj = new Artist($artist_obj);
require (conf('prefix') . "/templates/show_album.inc"); require (conf('prefix') . "/templates/show_album.inc");
if (isset($artist) && $artist_obj->name == "Unknown (Orphaned)" ) { /* Get the song ids for this album */
$song_ids = get_song_ids_from_artist_and_album($artist, $album->id); $song_ids = $album->get_song_ids($_REQUEST['artist']);
}
else {
$song_ids = get_song_ids_from_album($album->id);
}
show_songs($song_ids,0,$album); show_songs($song_ids,0,$album);
} // isset(album) } // isset(album)
// Finds the Album art from amazon // Finds the Album art from amazon

View file

@ -39,14 +39,15 @@ switch($action) {
case 'show': case 'show':
case 'Show': case 'Show':
show_alphabet_list('artists','artists.php'); show_alphabet_list('artists','artists.php');
$artist = new Artist(scrub_in($_REQUEST['artist'])); $artist = new Artist($_REQUEST['artist']);
$artist->show_albums(); $artist->show_albums();
break; break;
case 'show_all_songs': case 'show_all_songs':
$artist = get_artist_name(scrub_in($_REQUEST['artist'])); $artist = new Artist($_REQUEST['artist']);
echo "<h2>" . _("All songs by") . " $artist</h2>"; $artist->format_artist();
$song_ids = get_song_ids_from_artist($_REQUEST['artist']); $song_ids = $artist->get_song_ids();
require(conf('prefix') . '/templates/show_artist_box.inc.php');
show_songs($song_ids); show_songs($song_ids);
break; break;

View file

@ -4,6 +4,9 @@
-------------------------------------------------------------------------- --------------------------------------------------------------------------
v.3.3.2-Beta1 v.3.3.2-Beta1
- Added the Import From File action for playlists back. The link
was just missing
- Fixed SQL errors with Windows + Mysql5.x (Thx WarrenG)
- Rewrote entire Playlist class and document to use the new id - Rewrote entire Playlist class and document to use the new id
field in database, also added support for playlist tracks field in database, also added support for playlist tracks
that are based on search critera. NOT FINISHED! that are based on search critera. NOT FINISHED!

View file

@ -105,6 +105,30 @@ class Album {
} // get_songs } // get_songs
/**
* get_song_ids
* This returns an array of the song id's that are on this album. This is used by the
* show_songs function and can be pased and artist if you so desire to limit it to that
*/
function get_song_ids($artist='') {
/* If they pass an artist then constrain it based on the artist as well */
if ($artist) {
$artist_sql = " AND artist='" . sql_escape($artist) . "'";
}
$sql = "SELECT id FROM song WHERE album='" . sql_escape($this->id) . "' $artist_sql ORDER BY track";
$db_results = mysql_query($sql, dbh());
$results = array();
while ($r = mysql_fetch_assoc($db_results)) {
$results[] = $r['id'];
}
return $results;
} // get_song_ids
/*! /*!
@function format_album @function format_album
@ -466,29 +490,6 @@ class Album {
} // find_art } // find_art
/*!
@function get_song_ids
@discussion returns a list of song_ids on the album
get_songs returns a list of song objects
*/
// it seems get_songs really should call this,
// but I don't feel comfortable imposing that - RCR
function get_song_ids( $limit = 0 ) {
$results = array();
$sql = "SELECT id FROM song WHERE album='$this->id' ORDER BY track, title";
if ($limit) { $sql .= " LIMIT $limit"; }
$db_results = mysql_query($sql, dbh());
while ($r = mysql_fetch_object($db_results)) {
$results[] = $r->id;
}
return $results;
} // get_song_ids
} //end of album class } //end of album class
?> ?>

View file

@ -67,7 +67,7 @@ class Artist {
function get_info() { function get_info() {
/* Grab the basic information from the catalog and return it */ /* Grab the basic information from the catalog and return it */
$sql = "SELECT * FROM artist WHERE id='$this->id'"; $sql = "SELECT * FROM artist WHERE id='" . sql_escape($this->id) . "'";
$db_results = mysql_query($sql, dbh()); $db_results = mysql_query($sql, dbh());
$results = mysql_fetch_object($db_results); $results = mysql_fetch_object($db_results);
@ -112,6 +112,24 @@ class Artist {
} // get_songs } // get_songs
/**
* get_song_ids
* This gets an array of song ids that are assoicated with this artist. This is great for using
* with the show_songs function
*/
function get_song_ids() {
$sql = "SELECT id FROM song WHERE artist='" . sql_escape($this->id) . "' ORDER BY album, track";
$db_results = mysql_query($sql, dbh());
while ($r = mysql_fetch_assoc($db_results)) {
$results[] = $r['id'];
}
return $results;
} // get_song_ids
/*! /*!
@function get_random_songs @function get_random_songs
@discussion gets a random number, and @discussion gets a random number, and
@ -265,7 +283,6 @@ class Artist {
/* Set Vars */ /* Set Vars */
$web_path = conf('web_path'); $web_path = conf('web_path');
$albums = $this->get_albums(); $albums = $this->get_albums();
$this->format_artist(); $this->format_artist();
$artist = $this; $artist = $this;

View file

@ -1668,7 +1668,13 @@ class Catalog {
/* If not found create */ /* If not found create */
else { else {
$sql = "INSERT INTO artist (name, prefix) VALUES ('$artist', '$prefix')"; $prefix_txt = 'NULL';
if ($prefix) {
$prefix_txt = "'$prefix'";
}
$sql = "INSERT INTO artist (name, prefix) VALUES ('$artist', $prefix_txt)";
$db_results = mysql_query($sql, dbh()); $db_results = mysql_query($sql, dbh());
$artist_id = mysql_insert_id(dbh()); $artist_id = mysql_insert_id(dbh());
@ -1744,8 +1750,13 @@ class Catalog {
/* If not found create */ /* If not found create */
else { else {
$prefix_txt = 'NULL';
$sql = "INSERT INTO album (name, prefix,year) VALUES ('$album', '$prefix','$album_year')"; if ($prefix) {
$prefix_txt = "'$prefix'";
}
$sql = "INSERT INTO album (name, prefix,year) VALUES ('$album',$prefix_txt,'$album_year')";
$db_results = mysql_query($sql, dbh()); $db_results = mysql_query($sql, dbh());
$album_id = mysql_insert_id(dbh()); $album_id = mysql_insert_id(dbh());
@ -1780,9 +1791,10 @@ class Catalog {
@param $genre The name of the genre @param $genre The name of the genre
*/ */
function check_genre($genre) { function check_genre($genre) {
if (!$genre) { /* If a genre isn't specified force one */
return false; if (strlen($genre) < 1) {
$genre = "Unknown (Orphaned)";
} }
if ($this->genres[$genre]) { if ($this->genres[$genre]) {

View file

@ -76,8 +76,12 @@ class Playlist {
*/ */
function get_track($id) { function get_track($id) {
$sql = "SELECT track FROM playlist_data WHERE id='" . sql_escape($id) . "'";
$db_results = mysql_query($sql, dbh());
$result = mysql_fetch_assoc($db_results);
return $result['track'];
} // get_track } // get_track

View file

@ -44,10 +44,12 @@ class Rating {
$this->id = $id; $this->id = $id;
$this->type = $type; $this->type = $type;
if (intval($id) > 1) { if (intval($id) > 1) {
$this->get_average(); $this->get_average();
} }
else {
$this->rating='0';
}
} // Rating } // Rating

View file

@ -33,6 +33,8 @@
*/ */
function show_playlists() { function show_playlists() {
show_playlist_menu();
/* Always show yours first */ /* Always show yours first */
$playlists = get_playlists('private'); $playlists = get_playlists('private');
$type = 'Private'; $type = 'Private';
@ -52,6 +54,37 @@ function show_playlists() {
} // show_playlists } // show_playlists
/**
* show_playlist
* This function takes a playlist object and calls show_songs after
* runing get_items()
*/
function show_playlist($playlist) {
/* Create the Playlist */
$song_ids = $playlist->get_items();
show_playlist_menu();
if (count($song_ids) > 0) {
show_songs($song_ids, $playlist);
}
else {
echo "<div class=\"text-box\">" . _("No songs in this playlist.") . "</div>\n";
}
} // show_playlist
/**
* show_playlist_menu
* This shows a little pretty box that contains the playlist 'functions'
*/
function show_playlist_menu() {
require (conf('prefix') . '/templates/show_playlist_box.inc.php');
} // show_playlist_menu
/** /**
* get_playlists * get_playlists
* This function takes private,adminprivate or public and returns an array of playlist objects * This function takes private,adminprivate or public and returns an array of playlist objects

View file

@ -203,19 +203,6 @@ if (!function_exists('_')) {
} // _ } // _
} // if _ isn't defined } // if _ isn't defined
/**
* show_playlist_menu
* playlist functions
*/
function show_playlist_menu () {
echo "<br /><span class=\"header2\">" . _("Playlist Actions") . ": <a href=\"" . conf('web_path') . "/playlist.php?action=new\">" . _("New") ."</a> | ";
echo "<a href=\"" . conf('web_path') . "/playlist.php\"> " . _("View All") . "</a> | ";
echo "<a href=\"" . conf('web_path') . "/playlist.php?action=show_import_playlist\"> " . _("Import") . "</a>";
echo "</span><br /><br />";
} // show_playlist_menu
/** /**
* show_admin_menu * show_admin_menu
* shows the admin menu * shows the admin menu
@ -441,25 +428,6 @@ function show_edit_profile($username) {
} // show_edit_profile } // show_edit_profile
/**
* show_playlist
* This function takes a playlist object and calls show_songs after
* runing get_items()
*/
function show_playlist($playlist) {
/* Create the Playlist */
$song_ids = $playlist->get_items();
if (count($song_ids) > 0) {
show_songs($song_ids, $playlist->id);
}
else {
echo "<div class=\"text-box\">" . _("No songs in this playlist.") . "</div>\n";
}
} // show_playlist
/** /**
* show_play_selected * show_play_selected
* this shows the playselected/add to playlist * this shows the playselected/add to playlist

View file

@ -228,28 +228,6 @@ function get_song_ids_from_album ($album) {
} }
function get_song_ids_from_artist ($artist) {
global $settings;
$dbh = dbh();
$song_ids = array();
$artist = sql_escape($artist);
$query = "SELECT id FROM song" .
" WHERE artist = '$artist'" .
" ORDER BY album, track";
$db_result = mysql_query($query, $dbh);
while ( $r = mysql_fetch_object($db_result) ) {
$song_ids[] = $r->id;
}
return $song_ids;
}
/* /*
* get_song_ids_from_artist_and_album(); * get_song_ids_from_artist_and_album();
* *
@ -313,21 +291,12 @@ function get_songs_from_type ($type, $results, $artist_id = 0) {
/* Lets tie it to album too, so we can show art ;) */ /* Lets tie it to album too, so we can show art ;) */
/*********************************************************/ /*********************************************************/
/* One symbol, m(__)m */ /* One symbol, m(__)m */
function show_songs ($song_ids, $playlist_id=0, $album=0) { function show_songs ($song_ids, $playlist, $album=0) {
$dbh = dbh(); $dbh = dbh();
// Get info about current user // Get info about current user
$user = new User($_SESSION['userdata']['username']); $user = $GLOBALS['user'];
// Get info about playlist owner
if (isset($playlist_id) && $playlist_id != 0) {
$sql = "SELECT user FROM playlist WHERE id = '$playlist_id'";
$db_result = mysql_query($sql, $dbh);
if ($r = mysql_fetch_array($db_result)) {
$pluser = get_user_byid($r[0]);
}
}
$totaltime = 0; $totaltime = 0;
$totalsize = 0; $totalsize = 0;
@ -336,7 +305,7 @@ function show_songs ($song_ids, $playlist_id=0, $album=0) {
return true; return true;
}// function show_songs } // function show_songs

View file

@ -147,8 +147,8 @@ function make_local_session_only($data,$id=0)
$local_expirecol = libglue_param('local_expirecol'); $local_expirecol = libglue_param('local_expirecol');
$local_typecol = libglue_param('local_typecol'); $local_typecol = libglue_param('local_typecol');
$sql= "INSERT INTO $local_table ". $sql= "INSERT INTO $local_table ".
" ($local_sid,$local_usercol,$local_typecol)". " ($local_sid,$local_usercol,$local_typecol,value)".
" VALUES ('$id','$username','$type')"; " VALUES ('$id','$username','$type','')";
$db_result = mysql_query($sql, $local_dbh); $db_result = mysql_query($sql, $local_dbh);
if($db_result) return TRUE; if($db_result) return TRUE;

View file

@ -92,7 +92,8 @@ elseif ( $_REQUEST['playlist_id'] AND $action != 'play_selected') {
} }
} }
elseif ( $_REQUEST['artist'] ) { elseif ( $_REQUEST['artist'] ) {
$song_ids = get_song_ids_from_artist( $_REQUEST['artist'] ); $artist = new Artist($_REQUEST['artist']);
$song_ids = $artist->get_song_ids();
} }
/*! /*!
@action Random Song @action Random Song

View file

@ -26,28 +26,7 @@ $artist_id = $artist->id;
$web_path = conf('web_path'); $web_path = conf('web_path');
?> ?>
<br /> <br />
<table class="text-box"> <?php require (conf('prefix') . '/templates/show_artist_box.inc.php'); ?>
<tr>
<td>
<span class="header1"><?php print _("Albums by") . " " . $artist->full_name; ?></span>
<ul>
<?php
if (conf('ratings')) {
show_rating($artist->id,'artist');
} // end if ratings
echo "<br />\n";
?>
<li><a href="<?php print $web_path; ?>/artists.php?action=show_all_songs&amp;artist=<?php print $artist_id; ?>"><?php print _("Show All Songs By") . " " . $artist->full_name; ?></a></li>
<li><a href="<?php print $web_path; ?>/song.php?action=m3u&amp;artist=<?php print $artist_id; ?>"><?php print _("Play All Songs By") . " " . $artist->full_name; ?></a></li>
<li><a href="<?php print $web_path; ?>/song.php?action=m3u&amp;artist_random=<?php print $artist_id; ?>"><?php print _("Play Random Songs By") . " " . $artist->full_name; ?></a></li>
<?php if ($user->has_access('100')) { ?>
<li><a href="<?php echo $web_path; ?>/artists.php?action=update_from_tags&amp;artist=<?php print $artist_id; ?>"><?php print _("Update from tags"); ?></a></li>
<li><a href="<?php echo $web_path; ?>/artists.php?action=show_rename&amp;artist=<?php echo $artist_id; ?>"><?php echo _("Rename Artist"); ?></a></li>
<?php } ?>
</ul>
</td>
</tr>
</table>
<!-- *** Multi-Album Art Display Thx MrBlahh Updated by clader *** --> <!-- *** Multi-Album Art Display Thx MrBlahh Updated by clader *** -->
<br /> <br />
<form name="songs" method="post" enctype="multipart/form-data" action="artists.php"> <form name="songs" method="post" enctype="multipart/form-data" action="artists.php">

View file

@ -0,0 +1,44 @@
<?php
/*
Copyright (c) 2001 - 2006 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
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
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.
*/
?>
<table class="text-box">
<tr>
<td>
<span class="header1"><?php print _("Albums by") . " " . $artist->full_name; ?></span>
<ul>
<?php
if (conf('ratings')) {
show_rating($artist->id,'artist');
} // end if ratings
echo "<br />\n";
?>
<li><a href="<?php print $web_path; ?>/artists.php?action=show_all_songs&amp;artist=<?php print $artist_id; ?>"><?php print _("Show All Songs By") . " " . $artist->full_name; ?></a></li>
<li><a href="<?php print $web_path; ?>/song.php?action=m3u&amp;artist=<?php print $artist_id; ?>"><?php print _("Play All Songs By") . " " . $artist->full_name; ?></a></li>
<li><a href="<?php print $web_path; ?>/song.php?action=m3u&amp;artist_random=<?php print $artist_id; ?>"><?php print _("Play Random Songs By") . " " . $artist->full_name; ?></a></li>
<?php if ($user->has_access('100')) { ?>
<li><a href="<?php echo $web_path; ?>/artists.php?action=update_from_tags&amp;artist=<?php print $artist_id; ?>"><?php print _("Update from tags"); ?></a></li>
<li><a href="<?php echo $web_path; ?>/artists.php?action=show_rename&amp;artist=<?php echo $artist_id; ?>"><?php echo _("Rename Artist"); ?></a></li>
<?php } ?>
</ul>
</td>
</tr>
</table>

View file

@ -0,0 +1,31 @@
<?php
/*
Copyright (c) 2001 - 2006 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
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
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.
*/
?>
<table class="text-box">
<tr><td>
<span class="header1"><?php echo _('Playlist Actions'); ?></span><br />
&nbsp;&nbsp;&nbsp;<a href="<?php echo conf('web_path'); ?>/playlist.php?action=new"><?php echo _('Create New Playlist'); ?></a><br />
&nbsp;&nbsp;&nbsp;<a href="<?php echo conf('web_path'); ?>/playlist.php"><?php echo _('View All Playlists'); ?></a><br />
&nbsp;&nbsp;&nbsp;<a href="<?php echo conf('web_path'); ?>/playlist.php?action=show_import_playlist"><?php echo _('Import From File'); ?></a><br />
</td></tr>
</table>

View file

@ -55,11 +55,12 @@ if (is_object($playlist) && ($GLOBALS['user']->username == $playlist->user || $G
<?php <?php
/* FIXME: don't even get me started with how many things are wrong with this code */ /* FIXME: don't even get me started with how many things are wrong with this code */
foreach ($song_ids as $song_id) { foreach ($song_ids as $song_id) {
/* Arr matey crapy code abounds! */ /* Arr matey crapy code abounds! */
if ($playlist_owner) { if (is_object($playlist)) {
if ($song_id['song']) { if ($song_id['song']) {
$song = new Song($song_id['song']); $song = new Song($song_id['song']);
$track_id = $song_id['id'];
} }
else { else {
$song = new Song(); $song = new Song();
@ -90,11 +91,11 @@ if (is_object($playlist) && ($GLOBALS['user']->username == $playlist->user || $G
<input type="checkbox" name="song[]" value="<?php echo $song->id; ?>" id="song_<?php echo $song->id; ?>" /> <input type="checkbox" name="song[]" value="<?php echo $song->id; ?>" id="song_<?php echo $song->id; ?>" />
</td> </td>
<?php <?php
if (is_object($playlist) && ($GLOBALS['user']->username == $playlist->user || $GLOBALS['user']->has_access('100'))) { if ($playlist_owner) {
/* $tracknum = $playlist->get_track($track_id); */ $tracknum = $playlist->get_track($track_id);
?> ?>
<td> <td>
<input type="text" tabindex="<?php echo $tab; ?>" size="3" name="<?php echo "tr_" . $song->id; ?>" value="<?php echo $tracknum ?>" onchange="<?php echo "document.getElementById('song_" . $track_id . "').checked='checked';"; ?>" /> <input type="text" tabindex="<?php echo $tab; ?>" size="3" name="<?php echo "tr_" . $song->id; ?>" value="<?php echo $tracknum; ?>" onchange="<?php echo "document.getElementById('song_" . $track_id . "').checked='checked';"; ?>" />
</td> </td>
<?php $tab++; } ?> <?php $tab++; } ?>
<td> <td>
@ -161,7 +162,7 @@ if (is_object($playlist) && ($GLOBALS['user']->username == $playlist->user || $G
?> ?>
<tr class="table-header"> <tr class="table-header">
<td></td> <td></td>
<?php if (isset($playlist_id) && $playlist_id != 0 && ($user->username == $pluser->username || $user->access === 'admin')) { ?> <td></td> <?php } ?> <?php if (is_object($playlist)) { ?> <td></td> <?php } ?>
<td><?php echo _("Total"); ?>:</td> <td><?php echo _("Total"); ?>:</td>
<td nowrap="nowrap"><?php echo $num; ?> song(s)</td> <td nowrap="nowrap"><?php echo $num; ?> song(s)</td>
<td></td> <td></td>