mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-05 02:39:47 +02:00
I am not proud... but it works
This commit is contained in:
parent
dcb93abc50
commit
664bd9a28a
6 changed files with 155 additions and 51 deletions
|
@ -41,28 +41,51 @@ switch ($action) {
|
||||||
case 'edit_song':
|
case 'edit_song':
|
||||||
$catalog = new Catalog();
|
$catalog = new Catalog();
|
||||||
$song = new Song($_REQUEST['song_id']);
|
$song = new Song($_REQUEST['song_id']);
|
||||||
$new_song = $song;
|
$new_song = new Song();
|
||||||
|
|
||||||
/* Setup the vars so we can use the update_song function */
|
/* Setup the vars so we can use the update_song function */
|
||||||
$new_song->title = scrub_in($_REQUEST['title']);
|
$new_song->title = revert_string(scrub_in($_REQUEST['title']));
|
||||||
$new_song->track = scrub_in($_REQUEST['track']);
|
$new_song->track = revert_string(scrub_in($_REQUEST['track']));
|
||||||
$new_song->year = scrub_in($_REQUEST['year']);
|
$new_song->year = revert_string(scrub_in($_REQUEST['year']));
|
||||||
$new_song->comment = scrub_in($_REQUEST['comment']);
|
$new_song->comment = revert_string(scrub_in($_REQUEST['comment']));
|
||||||
$new_song->genre = scrub_in($_REQUEST['genre']);
|
|
||||||
$new_song->album = scrub_in($_REQUEST['album']);
|
/* If no change in string take Drop down */
|
||||||
$new_song->artist = scrub_in($_REQUEST['artist']);
|
if (strcasecmp(stripslashes($_REQUEST['genre_string']),$song->get_genre_name()) == 0) {
|
||||||
/* Check the drop down vs string bs */
|
$genre = $song->get_genre_name($_REQUEST['genre']);
|
||||||
if (strlen($_REQUEST['genre_string'])) {
|
|
||||||
$new_song->genre = $catalog->check_genre($_REQUEST['genre_string']);
|
|
||||||
}
|
}
|
||||||
if (strlen($_REQUEST['album_string'])) {
|
else {
|
||||||
$new_song->album = $catalog->check_album($_REQUEST['album_string']);
|
$genre = scrub_in($_REQUEST['genre_string']);
|
||||||
}
|
}
|
||||||
if (strlen($_REQUEST['artist_string'])) {
|
|
||||||
$new_song->artist = $catalog->check_artist($_REQUEST['artist_string']);
|
if (strcasecmp(stripslashes($_REQUEST['album_string']),$song->get_album_name()) == 0) {
|
||||||
|
$album = $song->get_album_name($_REQUEST['album']);
|
||||||
}
|
}
|
||||||
/* Update this mofo */
|
else {
|
||||||
|
$album = scrub_in($_REQUEST['album_string']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcasecmp(stripslashes($_REQUEST['artist_string']),$song->get_artist_name()) == 0) {
|
||||||
|
$artist = $song->get_artist_name($_REQUEST['artist']);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$artist = scrub_in($_REQUEST['artist_string']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Use the check functions to get / create ids for this info */
|
||||||
|
$new_song->genre = $catalog->check_genre(revert_string($genre));
|
||||||
|
$new_song->album = $catalog->check_album(revert_string($album));
|
||||||
|
$new_song->artist = $catalog->check_artist(revert_string($artist));
|
||||||
|
|
||||||
|
/* Update this mofo, store an old copy for cleaning */
|
||||||
|
$old_song = new Song();
|
||||||
|
$old_song->artist = $song->artist;
|
||||||
|
$old_song->album = $song->album;
|
||||||
|
$old_song->genre = $song->genre;
|
||||||
$song->update_song($song->id,$new_song);
|
$song->update_song($song->id,$new_song);
|
||||||
|
|
||||||
|
/* Now that it's been updated clean old junk entries */
|
||||||
|
$catalog = new Catalog();
|
||||||
|
$catalog->clean_single_song($old_song);
|
||||||
|
|
||||||
/* Add a tagging record of this so we can fix the file */
|
/* Add a tagging record of this so we can fix the file */
|
||||||
if ($_REQUEST['flag']) {
|
if ($_REQUEST['flag']) {
|
||||||
|
@ -75,9 +98,10 @@ switch ($action) {
|
||||||
$flag_id = scrub_in($_REQUEST['flag_id']);
|
$flag_id = scrub_in($_REQUEST['flag_id']);
|
||||||
$flag = new Flag($flag_id);
|
$flag = new Flag($flag_id);
|
||||||
$flag->delete_flag();
|
$flag->delete_flag();
|
||||||
|
$flag->format_name();
|
||||||
$url = return_referer();
|
$url = return_referer();
|
||||||
$title = _('Flag Removed');
|
$title = _('Flag Removed');
|
||||||
$body = _('Flag Removed from') . " " . $flag->print_name();
|
$body = _('Flag Removed from') . " " . $flag->name;
|
||||||
show_confirmation($title,$body,$url);
|
show_confirmation($title,$body,$url);
|
||||||
break;
|
break;
|
||||||
case 'show_edit_song':
|
case 'show_edit_song':
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Catalog Class
|
* Catalog Class
|
||||||
* This class handles all actual work in regards to the catalog, it contains functions for creating/listing/updated the catalogs.
|
* This class handles all actual work in regards to the catalog, it contains functions for creating/listing/updated the catalogs.
|
||||||
|
@ -1251,6 +1252,48 @@ class Catalog {
|
||||||
|
|
||||||
} //clean_catalog
|
} //clean_catalog
|
||||||
|
|
||||||
|
/**
|
||||||
|
* clean_single_song
|
||||||
|
* This function takes the elements of a single song object
|
||||||
|
* And checks to see if those specific elements are now orphaned
|
||||||
|
* this is often used in flagging, and is a faster way then calling
|
||||||
|
* the normal clean functions. The assumption is made that this is
|
||||||
|
* an old song object whoes information has already been updated in the
|
||||||
|
* database
|
||||||
|
*/
|
||||||
|
function clean_single_song($song) {
|
||||||
|
|
||||||
|
/* A'right let's check genre first */
|
||||||
|
$sql = "SELECT song.genre FROM song WHERE genre='" . $song->genre . "'";
|
||||||
|
$db_results = mysql_query($sql, dbh());
|
||||||
|
|
||||||
|
if (!mysql_num_rows($db_results)) {
|
||||||
|
$sql = "DELETE FROM genre WHERE id='" . $song->genre . "'";
|
||||||
|
$db_results = mysql_query($sql, dbh());
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now for the artist */
|
||||||
|
$sql = "SELECT song.artist FROM song WHERE artist='" . $song->artist . "'";
|
||||||
|
$db_results = mysql_query($sql, dbh());
|
||||||
|
|
||||||
|
if (!mysql_num_rows($db_results)) {
|
||||||
|
$sql = "DELETE FROM artist WHERE id='" . $song->artist . "'";
|
||||||
|
$db_results = mysql_query($sql, dbh());
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now for the album */
|
||||||
|
$sql = "SELECT song.album FROM song WHERE album='" . $song->album . "'";
|
||||||
|
$db_results = mysql_query($sql, dbh());
|
||||||
|
|
||||||
|
if (!mysql_num_rows($db_results)) {
|
||||||
|
$sql = "DELETE FROM album WHERE id='" . $song->album . "'";
|
||||||
|
$db_results = mysql_query($sql, dbh());
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} // clean_single_song
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* clean_genres
|
* clean_genres
|
||||||
* This functions cleans up unused genres
|
* This functions cleans up unused genres
|
||||||
|
|
|
@ -36,6 +36,10 @@ class Flag {
|
||||||
var $date;
|
var $date;
|
||||||
var $approved=0;
|
var $approved=0;
|
||||||
|
|
||||||
|
/* Generated Values */
|
||||||
|
var $name; // Blank
|
||||||
|
var $title; // Blank
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* This takes a flagged.id and then pulls in the information for said flag entry
|
* This takes a flagged.id and then pulls in the information for said flag entry
|
||||||
|
@ -190,11 +194,10 @@ class Flag {
|
||||||
} // approve
|
} // approve
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* print_name
|
* format_name
|
||||||
* This function formats and prints out a userfriendly name of the flagged
|
* This function formats and sets the $this->name variable and $this->title
|
||||||
* object
|
|
||||||
*/
|
*/
|
||||||
function print_name() {
|
function format_name() {
|
||||||
|
|
||||||
switch ($this->object_type) {
|
switch ($this->object_type) {
|
||||||
case 'song':
|
case 'song':
|
||||||
|
@ -208,7 +211,20 @@ class Flag {
|
||||||
break;
|
break;
|
||||||
} // end switch on object type
|
} // end switch on object type
|
||||||
|
|
||||||
echo "<span title=\"$title\">$name</span>";
|
$this->title = $title;
|
||||||
|
$this->name = $name;
|
||||||
|
|
||||||
|
} // format_name()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* print_name
|
||||||
|
* This function formats and prints out a userfriendly name of the flagged
|
||||||
|
* object
|
||||||
|
*/
|
||||||
|
function print_name() {
|
||||||
|
|
||||||
|
$this->format_name();
|
||||||
|
echo "<span title=\"" . $this->title . "\">" . $this->name . "</span>";
|
||||||
|
|
||||||
} // print_name
|
} // print_name
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,8 @@ class Song {
|
||||||
/* Variables from DB */
|
/* Variables from DB */
|
||||||
var $id;
|
var $id;
|
||||||
var $file;
|
var $file;
|
||||||
var $album;
|
var $album; // album.id (Int)
|
||||||
var $artist;
|
var $artist; // artist.id (Int)
|
||||||
var $title;
|
var $title;
|
||||||
var $year;
|
var $year;
|
||||||
var $comment;
|
var $comment;
|
||||||
|
@ -40,7 +40,7 @@ class Song {
|
||||||
var $size;
|
var $size;
|
||||||
var $time;
|
var $time;
|
||||||
var $track;
|
var $track;
|
||||||
var $genre;
|
var $genre; // genre.id (Int)
|
||||||
var $type;
|
var $type;
|
||||||
var $mime;
|
var $mime;
|
||||||
var $played;
|
var $played;
|
||||||
|
@ -178,16 +178,18 @@ class Song {
|
||||||
|
|
||||||
} // get_album_songs
|
} // get_album_songs
|
||||||
|
|
||||||
/*!
|
/**
|
||||||
@function get_album_name
|
* get_album_name
|
||||||
@discussion gets the name of $this->album
|
* gets the name of $this->album, allows passing of id
|
||||||
*/
|
*/
|
||||||
function get_album_name() {
|
function get_album_name($album_id=0) {
|
||||||
|
|
||||||
$sql = "SELECT name,prefix FROM album WHERE id='$this->album'";
|
if (!$album_id) { $album_id = $this->album; }
|
||||||
|
|
||||||
|
$sql = "SELECT name,prefix FROM album WHERE id='" . sql_escape($album_id) . "'";
|
||||||
$db_results = mysql_query($sql, dbh());
|
$db_results = mysql_query($sql, dbh());
|
||||||
|
|
||||||
$results = mysql_fetch_array($db_results);
|
$results = mysql_fetch_assoc($db_results);
|
||||||
|
|
||||||
if ($results['prefix']) {
|
if ($results['prefix']) {
|
||||||
return $results['prefix'] . " " .$results['name'];
|
return $results['prefix'] . " " .$results['name'];
|
||||||
|
@ -198,16 +200,18 @@ class Song {
|
||||||
|
|
||||||
} // get_album_name
|
} // get_album_name
|
||||||
|
|
||||||
/*!
|
/**
|
||||||
@function get_artist_name
|
* get_artist_name
|
||||||
@discussion gets the name of $this->artist
|
* gets the name of $this->artist, allows passing of id
|
||||||
*/
|
*/
|
||||||
function get_artist_name() {
|
function get_artist_name($artist_id=0) {
|
||||||
|
|
||||||
$sql = "SELECT name,prefix FROM artist WHERE id='$this->artist'";
|
if (!$artist_id) { $artist_id = $this->artist; }
|
||||||
|
|
||||||
|
$sql = "SELECT name,prefix FROM artist WHERE id='" . sql_escape($artist_id) . "'";
|
||||||
$db_results = mysql_query($sql, dbh());
|
$db_results = mysql_query($sql, dbh());
|
||||||
|
|
||||||
$results = mysql_fetch_array($db_results);
|
$results = mysql_fetch_assoc($db_results);
|
||||||
|
|
||||||
if ($results['prefix']) {
|
if ($results['prefix']) {
|
||||||
return $results['prefix'] . " " . $results['name'];
|
return $results['prefix'] . " " . $results['name'];
|
||||||
|
@ -218,16 +222,19 @@ class Song {
|
||||||
|
|
||||||
} // get_album_name
|
} // get_album_name
|
||||||
|
|
||||||
/*!
|
/**
|
||||||
@function get_genre_name
|
* get_genre_name
|
||||||
@discussion gets the name of the genre
|
* gets the name of the genre, allow passing of a specified
|
||||||
*/
|
* id
|
||||||
function get_genre_name() {
|
*/
|
||||||
|
function get_genre_name($genre_id=0) {
|
||||||
|
|
||||||
$sql = "SELECT name FROM genre WHERE id='$this->genre'";
|
if (!$genre_id) { $genre_id = $this->genre; }
|
||||||
|
|
||||||
|
$sql = "SELECT name FROM genre WHERE id='" . sql_escape($genre_id) . "'";
|
||||||
$db_results = mysql_query($sql, dbh());
|
$db_results = mysql_query($sql, dbh());
|
||||||
|
|
||||||
$results = mysql_fetch_array($db_results);
|
$results = mysql_fetch_assoc($db_results);
|
||||||
|
|
||||||
return $results['name'];
|
return $results['name'];
|
||||||
|
|
||||||
|
@ -557,6 +564,9 @@ class Song {
|
||||||
|
|
||||||
if (!$song_id) { $song_id = $this->id; }
|
if (!$song_id) { $song_id = $this->id; }
|
||||||
|
|
||||||
|
/* Can't update to blank */
|
||||||
|
if (!strlen(trim($value)) && $field != 'comment') { return false; }
|
||||||
|
|
||||||
$value = sql_escape($value);
|
$value = sql_escape($value);
|
||||||
|
|
||||||
$sql = "UPDATE song SET $field='$value' WHERE id='$song_id'";
|
$sql = "UPDATE song SET $field='$value' WHERE id='$song_id'";
|
||||||
|
|
|
@ -807,6 +807,18 @@ function scrub_out($str) {
|
||||||
|
|
||||||
} // scrub_out
|
} // scrub_out
|
||||||
|
|
||||||
|
/**
|
||||||
|
* revert_string
|
||||||
|
* This returns a scrubed string to it's most normal state
|
||||||
|
* Uhh yea better way to do this please?
|
||||||
|
*/
|
||||||
|
function revert_string($string) {
|
||||||
|
|
||||||
|
$string = unhtmlentities($string,ENT_QUOTES,conf('site_charset'));
|
||||||
|
return $string;
|
||||||
|
|
||||||
|
} // revert_string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* make_bool
|
* make_bool
|
||||||
* This takes a value and returns what I consider to be the correct boolean value
|
* This takes a value and returns what I consider to be the correct boolean value
|
||||||
|
|
|
@ -21,10 +21,9 @@
|
||||||
*/
|
*/
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<p class="header1"><?php echo _('Edit Song'); ?></p>
|
<span class="header1"><?php echo _('Edit Song'); ?></span>
|
||||||
|
|
||||||
<form name="edit_song" method="post" enctype="multipart/form-data" action="<?php echo conf('web_path'); ?>/admin/flag.php">
|
<form name="edit_song" method="post" enctype="multipart/form-data" action="<?php echo conf('web_path'); ?>/admin/flag.php">
|
||||||
<table>
|
<table class="text-box">
|
||||||
<tr class="<?php echo flip_class(); ?>">
|
<tr class="<?php echo flip_class(); ?>">
|
||||||
<td><?php echo _('File'); ?>:</td>
|
<td><?php echo _('File'); ?>:</td>
|
||||||
<td><?php echo scrub_out($song->file); ?></td>
|
<td><?php echo scrub_out($song->file); ?></td>
|
||||||
|
@ -56,7 +55,7 @@
|
||||||
<td>
|
<td>
|
||||||
<?php show_genre_select('genre',$song->genre); ?>
|
<?php show_genre_select('genre',$song->genre); ?>
|
||||||
<br /><?php echo _('OR'); ?><br />
|
<br /><?php echo _('OR'); ?><br />
|
||||||
<input type="textbox" name="genre_string" value="<?php echo scrub_out($song->get_genre_name()); ?>" />
|
<input type="textbox" name="genre_string" value="<?php echo scrub_out($song->f_genre); ?>" />
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="<?php echo flip_class(); ?>">
|
<tr class="<?php echo flip_class(); ?>">
|
||||||
|
@ -74,7 +73,7 @@
|
||||||
<tr class="<?php echo flip_class(); ?>">
|
<tr class="<?php echo flip_class(); ?>">
|
||||||
<td><?php echo _('Comment'); ?></td>
|
<td><?php echo _('Comment'); ?></td>
|
||||||
<td>
|
<td>
|
||||||
<input type="textbox" name="comment" value="<?Php echo scrub_out($song->comment); ?>" size="45" />
|
<input type="textbox" name="comment" value="<?php echo scrub_out($song->comment); ?>" size="45" />
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="<?php echo flip_class(); ?>">
|
<tr class="<?php echo flip_class(); ?>">
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue