summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl 'vollmerk' Vollmer <vollmer@ampache.org>2006-03-27 07:59:33 +0000
committerKarl 'vollmerk' Vollmer <vollmer@ampache.org>2006-03-27 07:59:33 +0000
commit664bd9a28aa10eedee3deb82cda9b99b91b51fa0 (patch)
tree7ab60c5a038ccde3aa24f9fa18fd71bc6a2b515b
parentdcb93abc50ddea7da48f104ad3b861dee342d623 (diff)
downloadampache-664bd9a28aa10eedee3deb82cda9b99b91b51fa0.tar.gz
ampache-664bd9a28aa10eedee3deb82cda9b99b91b51fa0.tar.bz2
ampache-664bd9a28aa10eedee3deb82cda9b99b91b51fa0.zip
I am not proud... but it works
-rw-r--r--admin/flag.php58
-rw-r--r--lib/class/catalog.class.php43
-rw-r--r--lib/class/flag.class.php26
-rw-r--r--lib/class/song.class.php58
-rw-r--r--lib/general.lib.php12
-rw-r--r--templates/show_edit_song.inc.php9
6 files changed, 155 insertions, 51 deletions
diff --git a/admin/flag.php b/admin/flag.php
index 2c8e4c16..f3de980a 100644
--- a/admin/flag.php
+++ b/admin/flag.php
@@ -41,28 +41,51 @@ switch ($action) {
case 'edit_song':
$catalog = new Catalog();
$song = new Song($_REQUEST['song_id']);
- $new_song = $song;
+ $new_song = new Song();
/* Setup the vars so we can use the update_song function */
- $new_song->title = scrub_in($_REQUEST['title']);
- $new_song->track = scrub_in($_REQUEST['track']);
- $new_song->year = scrub_in($_REQUEST['year']);
- $new_song->comment = scrub_in($_REQUEST['comment']);
- $new_song->genre = scrub_in($_REQUEST['genre']);
- $new_song->album = scrub_in($_REQUEST['album']);
- $new_song->artist = scrub_in($_REQUEST['artist']);
- /* Check the drop down vs string bs */
- if (strlen($_REQUEST['genre_string'])) {
- $new_song->genre = $catalog->check_genre($_REQUEST['genre_string']);
+ $new_song->title = revert_string(scrub_in($_REQUEST['title']));
+ $new_song->track = revert_string(scrub_in($_REQUEST['track']));
+ $new_song->year = revert_string(scrub_in($_REQUEST['year']));
+ $new_song->comment = revert_string(scrub_in($_REQUEST['comment']));
+
+ /* If no change in string take Drop down */
+ if (strcasecmp(stripslashes($_REQUEST['genre_string']),$song->get_genre_name()) == 0) {
+ $genre = $song->get_genre_name($_REQUEST['genre']);
}
- if (strlen($_REQUEST['album_string'])) {
- $new_song->album = $catalog->check_album($_REQUEST['album_string']);
+ else {
+ $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']);
+ }
+ 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']);
}
- /* Update this mofo */
+ 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);
+
+ /* 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 */
if ($_REQUEST['flag']) {
@@ -75,9 +98,10 @@ switch ($action) {
$flag_id = scrub_in($_REQUEST['flag_id']);
$flag = new Flag($flag_id);
$flag->delete_flag();
+ $flag->format_name();
$url = return_referer();
$title = _('Flag Removed');
- $body = _('Flag Removed from') . " " . $flag->print_name();
+ $body = _('Flag Removed from') . " " . $flag->name;
show_confirmation($title,$body,$url);
break;
case 'show_edit_song':
diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php
index 55630719..c2af2cda 100644
--- a/lib/class/catalog.class.php
+++ b/lib/class/catalog.class.php
@@ -18,6 +18,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
+
/**
* Catalog Class
* This class handles all actual work in regards to the catalog, it contains functions for creating/listing/updated the catalogs.
@@ -1252,6 +1253,48 @@ class 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
* This functions cleans up unused genres
* @package Catalog
diff --git a/lib/class/flag.class.php b/lib/class/flag.class.php
index dc6f44a3..a95e73c8 100644
--- a/lib/class/flag.class.php
+++ b/lib/class/flag.class.php
@@ -36,6 +36,10 @@ class Flag {
var $date;
var $approved=0;
+ /* Generated Values */
+ var $name; // Blank
+ var $title; // Blank
+
/**
* Constructor
* This takes a flagged.id and then pulls in the information for said flag entry
@@ -190,11 +194,10 @@ class Flag {
} // approve
/**
- * print_name
- * This function formats and prints out a userfriendly name of the flagged
- * object
+ * format_name
+ * This function formats and sets the $this->name variable and $this->title
*/
- function print_name() {
+ function format_name() {
switch ($this->object_type) {
case 'song':
@@ -208,7 +211,20 @@ class Flag {
break;
} // 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
diff --git a/lib/class/song.class.php b/lib/class/song.class.php
index 44ce9602..a68a96dc 100644
--- a/lib/class/song.class.php
+++ b/lib/class/song.class.php
@@ -29,8 +29,8 @@ class Song {
/* Variables from DB */
var $id;
var $file;
- var $album;
- var $artist;
+ var $album; // album.id (Int)
+ var $artist; // artist.id (Int)
var $title;
var $year;
var $comment;
@@ -40,7 +40,7 @@ class Song {
var $size;
var $time;
var $track;
- var $genre;
+ var $genre; // genre.id (Int)
var $type;
var $mime;
var $played;
@@ -178,16 +178,18 @@ class Song {
} // get_album_songs
- /*!
- @function get_album_name
- @discussion gets the name of $this->album
- */
- function get_album_name() {
+ /**
+ * get_album_name
+ * gets the name of $this->album, allows passing of id
+ */
+ 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());
- $results = mysql_fetch_array($db_results);
+ $results = mysql_fetch_assoc($db_results);
if ($results['prefix']) {
return $results['prefix'] . " " .$results['name'];
@@ -198,16 +200,18 @@ class Song {
} // get_album_name
- /*!
- @function get_artist_name
- @discussion gets the name of $this->artist
- */
- function get_artist_name() {
+ /**
+ * get_artist_name
+ * gets the name of $this->artist, allows passing of id
+ */
+ function get_artist_name($artist_id=0) {
+
+ if (!$artist_id) { $artist_id = $this->artist; }
- $sql = "SELECT name,prefix FROM artist WHERE id='$this->artist'";
+ $sql = "SELECT name,prefix FROM artist WHERE id='" . sql_escape($artist_id) . "'";
$db_results = mysql_query($sql, dbh());
- $results = mysql_fetch_array($db_results);
+ $results = mysql_fetch_assoc($db_results);
if ($results['prefix']) {
return $results['prefix'] . " " . $results['name'];
@@ -218,16 +222,19 @@ class Song {
} // get_album_name
- /*!
- @function get_genre_name
- @discussion gets the name of the genre
- */
- function get_genre_name() {
+ /**
+ * get_genre_name
+ * gets the name of the genre, allow passing of a specified
+ * id
+ */
+ 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());
- $results = mysql_fetch_array($db_results);
+ $results = mysql_fetch_assoc($db_results);
return $results['name'];
@@ -557,6 +564,9 @@ class Song {
if (!$song_id) { $song_id = $this->id; }
+ /* Can't update to blank */
+ if (!strlen(trim($value)) && $field != 'comment') { return false; }
+
$value = sql_escape($value);
$sql = "UPDATE song SET $field='$value' WHERE id='$song_id'";
diff --git a/lib/general.lib.php b/lib/general.lib.php
index fde2f01c..c8df6183 100644
--- a/lib/general.lib.php
+++ b/lib/general.lib.php
@@ -808,6 +808,18 @@ function scrub_out($str) {
} // 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
* This takes a value and returns what I consider to be the correct boolean value
* This is used instead of settype alone because settype considers 0 and "false" to
diff --git a/templates/show_edit_song.inc.php b/templates/show_edit_song.inc.php
index b39651b0..a3c24af6 100644
--- a/templates/show_edit_song.inc.php
+++ b/templates/show_edit_song.inc.php
@@ -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">
-<table>
+<table class="text-box">
<tr class="<?php echo flip_class(); ?>">
<td><?php echo _('File'); ?>:</td>
<td><?php echo scrub_out($song->file); ?></td>
@@ -56,7 +55,7 @@
<td>
<?php show_genre_select('genre',$song->genre); ?>
<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>
</tr>
<tr class="<?php echo flip_class(); ?>">
@@ -74,7 +73,7 @@
<tr class="<?php echo flip_class(); ?>">
<td><?php echo _('Comment'); ?></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>
</tr>
<tr class="<?php echo flip_class(); ?>">