summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl 'vollmerk' Vollmer <vollmer@ampache.org>2007-07-29 21:42:42 +0000
committerKarl 'vollmerk' Vollmer <vollmer@ampache.org>2007-07-29 21:42:42 +0000
commit3fa94f564493d930f5049526e18d35c1213ba9ca (patch)
tree6c6dfe75bd3ade082cc9d69be457b281e4248c89
parente46b19547e7d16999b05577ec64631cc12796355 (diff)
downloadampache-3fa94f564493d930f5049526e18d35c1213ba9ca.tar.gz
ampache-3fa94f564493d930f5049526e18d35c1213ba9ca.tar.bz2
ampache-3fa94f564493d930f5049526e18d35c1213ba9ca.zip
fixed a few more warnings, fixed artist editing and improved album editing a little (so it cleans up after its self)
-rw-r--r--lib/class/album.class.php7
-rw-r--r--lib/class/artist.class.php233
-rw-r--r--lib/class/catalog.class.php26
-rw-r--r--server/ajax.server.php9
-rw-r--r--templates/show_artist_row.inc.php38
-rw-r--r--templates/show_artists.inc.php28
-rw-r--r--templates/show_edit_album_row.inc.php2
-rw-r--r--templates/show_edit_artist_row.inc.php36
8 files changed, 139 insertions, 240 deletions
diff --git a/lib/class/album.class.php b/lib/class/album.class.php
index 45e03bd9..02da0a10 100644
--- a/lib/class/album.class.php
+++ b/lib/class/album.class.php
@@ -625,8 +625,6 @@ class Album {
*/
public function update($data) {
- // Sadly we need a catalog object here
- $catalog = new Catalog();
$year = $data['year'];
$artist = $data['artist'];
@@ -641,9 +639,10 @@ class Album {
Song::update_artist($artist,$song_id);
}
$updated = 1;
+ Catalog::clean_artists();
}
- $album_id = $catalog->check_album($name,$year);
+ $album_id = Catalog::check_album($name,$year);
if ($album_id != $this->id) {
if (!is_array($songs)) { $songs = $this->get_songs(); }
foreach ($songs as $song_id) {
@@ -652,6 +651,7 @@ class Album {
}
$current_id = $album_id;
$updated = 1;
+ Catalog::clean_albums();
}
if ($updated) {
@@ -660,6 +660,7 @@ class Album {
Flag::add($song_id,'song','retag','Interface Album Update');
Song::update_utime($song_id);
} // foreach song of album
+ Catalog::clean_stats();
} // if updated
diff --git a/lib/class/artist.class.php b/lib/class/artist.class.php
index 3de53153..2d12e8c6 100644
--- a/lib/class/artist.class.php
+++ b/lib/class/artist.class.php
@@ -186,9 +186,6 @@ class Artist {
$name = truncate_with_ellipsis(trim($this->prefix . " " . $this->name));
$this->f_name = $name;
- //FIXME: This shouldn't be scrubing right here!!!!
- $this->full_name = scrub_out(trim($this->prefix . " " . $this->name));
-
$this->f_name_link = "<a href=\"" . Config::get('web_path') . "/artists.php?action=show&amp;artist=" . $this->id . "\" title=\"" . $this->full_name . "\">" . $name . "</a>";
// Get the counts
@@ -198,202 +195,40 @@ class Artist {
} // format
- /*!
- @function rename
- @discussion changes the name of the artist in the db,
- and then merge()s songs
- @param $newname the artist's new name, either a new
- artist will be created or songs added to existing
- artist if name exists already
- @return the id of the new artist, or false if an error
- */
- function rename($newname) {
-
- /*
- * There is this nifty function called check_artists in catalog that does exactly what we want it to do
- * to use it, we first have to hax us a catalog
- */
- $catalog = new Catalog();
-
- /* now we can get the new artist id in question */
- $newid = $catalog->check_artist($newname);
-
- /* check that it wasn't just whitespace that we were called to change */
- if ($newid == $this->id) {
- $GLOBALS['error']->add_error('artist_name',_("Error: Name Identical"));
- return false;
- }
-
- /* now we can just call merge */
- if (!$this->merge($newid))
- return false;
-
- //now return id
- return $newid;
-
- } // rename
-
- /*!
- @function merge
- @discussion changes the artist id of all songs by this artist
- to the given id and deletes self from db
- @param $newid the new artist id that this artist's songs should have
- @return the name of the new artist on success, false if error
- */
- function merge($newid) {
-
- $catalog = new Catalog();
-
- /* Make sure this is a valid ID */
- if (!is_numeric($newid)) {
- $GLOBALS['error']->add_error('general',"Error: Invalid Artist ID");
- return false;
- }
-
- // First check newid exists
- $check_exists_qstring = "SELECT name FROM artist WHERE id='" . $newid . "'"; //no need to escape newid, it's numeric
- $check_exists_query = mysql_query($check_exists_qstring, dbh());
-
- if ($check_exists_result = mysql_fetch_assoc($check_exists_query)) {
- $NewName = $check_exists_result['name'];
-
- // Now the query
- $sql = "UPDATE song SET artist='" . $newid . "' " .
- "WHERE artist='" . sql_escape($this->id) . "'";
- $db_results = mysql_query($sql, dbh());
-
- $num_stats_changed = $catalog->merge_stats('artist',$this->id,$newid);
-
- /* If we've done the merege we need to clean up */
- $catalog->clean_artists();
- $catalog->clean_albums();
-
- return $NewName;
- }
- else {
- $GLOBALS['error']->add_error('general',"Error: No such artist to merge with");
- return false;
- }
- } // merge
-
- /*!
- @function get_similar_artists
- @discussion returns an array of artist (id,name) arrays that are similar in name
- All whitespace and special chars are ignored
- @param extra arguments to normalize and compre, in that order
- @return array of artist, each element is (id,name)
- */
- function get_similar_artists ($n_rep_uml,$n_filter,$n_ignore,$c_mode,$c_count_w,$c_percent_w,$c_distance_l) {
- //strip out just about everything, including whitespace, numbers and weird chars, and then
- //lowercase it
- $name = $this->normalize_name($this->name,$n_rep_uml,$n_filter,$n_ignore);
-
- //now for a bit of mysql query
- $sql = "SELECT id, name FROM artist WHERE id != '" . sql_escape($this->id) . "'";
- $query = mysql_query($sql, dbh());
- //loop it
- $similar_artists = array();
- while ($r = mysql_fetch_assoc($query)) {
- $artist_name = $this->normalize_name($r['name'],$n_rep_uml,$n_filter,$n_ignore);
- //echo "'" . $r['name'] . "' => '" . $artist_name . "'<br/>\n";
- if ($this->compare_loose($name,$artist_name,$c_mode,$c_count_w,$c_percent_w,$c_distance_l)) {
- //echo "***MATCH***<br/>\n";
- $similar_artists[] = array($r['id'],$r['name']);
- }
- }
- return $similar_artists;
- } // get_similar_artists
-
-
- /*!
- @function normalize_name
- @param artist name to normalize
- @param $replace_umlaut wether to replace umlauts and others with the plain letter, default true
- @param $filter what to filter out, defulat /[^a-z ]/
- @param $ignore terms to ignore, default /\s(the|an?)\s/ (name is padded with whitespace beforehand)
- @returns the normalized version of the given artist name, containing only letters and single spaces
- */
- function normalize_name ($name,$replace_umlaut = NULL, $filter = NULL, $ignore = NULL) {
- if (is_null($replace_umlaut)) $replace_umlaut = true;
- if (is_null($filter)) $filter = "/[^a-z ]/";
- if (is_null($ignore)) $ignore = "/\s(the|an?)\s/";
- if ($replace_umlaut) {
- //convert ümlauts, idea from http://php.net/manual/en/function.str-replace.php#50081
- $umlauts = array("uml","acute","grave","cedil","ring","circ","tilde","lig","slash");
- $name = str_replace($umlauts,"",htmlentities($name));
- //now replace all &.; with .
- $name = preg_replace("/&(.);/","\$1",$name);
- //back to normal
- $name = html_entity_decode($name);
- }
- //lowercase
- $name = strtolower($name);
- //now rip out all the special chars and spaces
- $name = preg_replace($filter,"",$name);
- //now certains terms can be dropped completely
- //we have to add spaces on the sides though
- $name = " " . $name . " ";
- $name = preg_replace($ignore,"",$name);
- //now single spaces
- $name = preg_replace("/\s{2,}/"," ",$name);
- //return
- return trim($name);
- } //normalize_name
-
- /*!
- @function compare_loose
- @discussion percent and count are ORed together
- @param $name1 artist name
- @param $name2 artist name to compare against
- @param $mode the type of matching to perform, one of line or word, default word
- @param $countwords WORD MODE number of words that must be shared to match, 0 to disable, default 0
- @param $percentwords WORD MODE percentage of words that must be shared to match, 0 to disable, default 50%
- @param $distance LETTER MODE max levenshtein distance to pass as a match
- @return true if given params are similar, false if not
- */
- function compare_loose ($name1,$name2,$mode = NULL,$countwords = NULL,$percentwords = NULL,$distance = NULL) {
- if (is_null($mode)) $mode = "word";
- if (is_null($countwords)) $countwords = 0;
- if (is_null($percentwords)) $percentwords = 50;
- if (is_null($distance)) $distance = 2;
-
- //echo "Compare '$name1' vs. '$name2'<br/>\n";
-
- $modes = array("line" => 0,"word" => 0,"letter" => 0);
- $mode = (isset($modes[$mode]) ? $mode : "word");
- switch ($mode) {
- case "line":
- //this is still relevant because of the normalize
- return $name1 == $name2;
- break;
- case "word":
- //echo " COMPARE: Word mode<br/>\n";
- //first, count the number of terms in name1, and then the number that also appear in name2
- $words = explode(" ",$name1);
- $num_words = count($words);
- $num_words_shared = 0;
- foreach ($words as $word) {
- //echo " Looking for word '$word'... ";
- if (strpos($name2,$word) !== false) {
- //echo "MATCHED";
- $num_words_shared++;
- } else {
- //echo " Nope";
- }
- //echo "<br/>\n";
- }
- //now make the descision
- return (
- ($countwords > 0 && $num_words_shared >= $countwords) ||
- ($percentwords > 0 && $num_words_shared > 0 && $num_words_shared/$num_words >= $percentwords/100)
- );
- break;
- case "letter":
- //simple
- return levenshtein($name1,$name2) <= $distance;
- break;
- }
- } // compare_loose
+ /**
+ * update
+ * This takes a key'd array of data and updates the current artist
+ * it will flag songs as neeed
+ */
+ public function update($data) {
+
+ // Save our current ID
+ $current_id = $this->id;
+
+ $artist_id = Catalog::check_artist($data['name']);
+
+ // If it's changed we need to update
+ if ($artist_id != $this->id) {
+ $songs = $this->get_songs();
+ foreach ($songs as $song_id) {
+ Song::update_artist($artist_id,$song_id);
+ }
+ $updated = 1;
+ $current_id = $artist_id;
+ Catalog::clean_artists();
+ } // end if it changed
+
+ if ($updated) {
+ foreach ($songs as $song_id) {
+ Flag::add($song_id,'song','retag','Interface Artist Update');
+ Song::update_utime($song_id);
+ }
+ Catalog::clean_stats();
+ } // if updated
+
+ return $current_id;
+
+ } // update
} // end of artist class
?>
diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php
index 81bf8873..e92b1942 100644
--- a/lib/class/catalog.class.php
+++ b/lib/class/catalog.class.php
@@ -897,7 +897,7 @@ class Catalog {
foreach($songs as $song_id) {
$song = new Song($song_id);
- $info = self::update_song_from_tags($song);
+ $info = self::update_song_from_tags($song,'','');
if ($info['change']) {
$file = scrub_out($song->file);
@@ -1196,8 +1196,8 @@ class Catalog {
$data = explode("::", $song);
- $new_song->artist = $this->check_artist($data[0]);
- $new_song->album = $this->check_album($data[1],$data[4]);
+ $new_song->artist = self::check_artist($data[0]);
+ $new_song->album = self::check_album($data[1],$data[4]);
$new_song->title = $data[2];
$new_song->year = $data[4];
$new_song->bitrate = $data[5];
@@ -1206,7 +1206,7 @@ class Catalog {
$new_song->size = $data[8];
$new_song->time = $data[9];
$new_song->track = $data[10];
- $new_song->genre = $this->check_genre($data[11]);
+ $new_song->genre = self::check_genre($data[11]);
$new_song->file = $root_path . "/play/index.php?song=" . $data[12];
$new_song->catalog = $this->id;
@@ -1628,7 +1628,7 @@ class Catalog {
* check_artist
* $artist checks if there then return id else insert and return id
*/
- public function check_artist($artist) {
+ public static function check_artist($artist) {
// Only get the var ones.. less func calls
$cache_limit = Config::get('artist_cache_limit');
@@ -1705,7 +1705,7 @@ class Catalog {
* check_album
* Takes $album and checks if there then return id else insert and return id
*/
- public function check_album($album,$album_year=0) {
+ public static function check_album($album,$album_year=0) {
/* Clean up the album name */
$album = trim($album);
@@ -1793,7 +1793,7 @@ class Catalog {
* check_genre
* Finds the Genre_id from the text name
*/
- public function check_genre($genre) {
+ public static function check_genre($genre) {
/* If a genre isn't specified force one */
if (strlen(trim($genre)) < 1) {
@@ -1830,7 +1830,7 @@ class Catalog {
* set on the title, if it isn't it looks at the
* filename and trys to set the title based on that
*/
- public function check_title($title,$file=0) {
+ public static function check_title($title,$file=0) {
if (strlen(trim($title)) < 1) {
preg_match("/.+\/(.*)\.....?$/",$file,$matches);
@@ -1877,10 +1877,10 @@ class Catalog {
* We have the artist/genre/album name need to check it in the tables
* If found then add & return id, else return id
*/
- $artist_id = $this->check_artist($artist);
- $genre_id = $this->check_genre($genre);
- $album_id = $this->check_album($album,$year);
- $title = $this->check_title($title,$file);
+ $artist_id = self::check_artist($artist);
+ $genre_id = self::check_genre($genre);
+ $album_id = self::check_album($album,$year);
+ $title = self::check_title($title,$file);
$add_file = Dba::escape($file);
$sql = "INSERT INTO `song` (file,catalog,album,artist,title,bitrate,rate,mode,size,time,track,genre,addition_time,year)" .
@@ -1914,7 +1914,7 @@ class Catalog {
function insert_remote_song($song) {
$url = sql_escape($song->file);
- $title = $this->check_title($song->title);
+ $title = self::check_title($song->title);
$title = sql_escape($title);
$current_time = time();
diff --git a/server/ajax.server.php b/server/ajax.server.php
index fab96cda..2b1fdf30 100644
--- a/server/ajax.server.php
+++ b/server/ajax.server.php
@@ -93,6 +93,15 @@ switch ($action) {
}
$album->format();
break;
+ case 'artist':
+ $key = 'artist_' . $_POST['id'];
+ $artist = new Artist($_POST['id']);
+ $new_id = $artist->update($_POST);
+ if ($new_id != $_POST['id']) {
+ $artist = new Artist($new_id);
+ }
+ $artist->format();
+ break;
case 'song':
$key = 'song_' . $_POST['id'];
$song = new Song($_POST['id']);
diff --git a/templates/show_artist_row.inc.php b/templates/show_artist_row.inc.php
new file mode 100644
index 00000000..f394337e
--- /dev/null
+++ b/templates/show_artist_row.inc.php
@@ -0,0 +1,38 @@
+<?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.
+
+*/
+?>
+<td>
+ <?php echo Ajax::button('?action=basket&type=artist&id=' . $artist->id,'add',_('Add'),'add_artist_' . $artist->id); ?>
+ <?php echo Ajax::button('?action=basket&type=artist_random&id=' . $artist->id,'random',_('Random'),'random_artist_' . $artist->id); ?>
+</td>
+<td><?php echo $artist->f_name_link; ?></td>
+<td><?php echo $artist->songs; ?></td>
+<td><?php echo $artist->albums; ?></td>
+<td nowrap="nowrap">
+<?php if (Access::check_function('batch_download')) { ?>
+ <a href="<?php echo Config::get('web_path'); ?>/batch.php?action=artist&amp;id=<?php echo $artist->id; ?>">
+ <?php echo get_user_icon('batch_download','',_('Batch Download')); ?>
+ </a>
+<?php } ?>
+<?php if ($GLOBALS['user']->has_access(50)) { ?>
+ <?php echo Ajax::button('?action=show_edit_object&type=artist&id=' . $artist->id,'edit',_('Edit'),'edit_artist_' . $artist->id); ?>
+<?php } ?>
+</td>
diff --git a/templates/show_artists.inc.php b/templates/show_artists.inc.php
index 1bb92cb7..e1c7b270 100644
--- a/templates/show_artists.inc.php
+++ b/templates/show_artists.inc.php
@@ -41,31 +41,9 @@ foreach ($object_ids as $artist_id) {
$artist = new Artist($artist_id);
$artist->format();
?>
- <tr class="<?php echo flip_class(); ?>">
- <td>
- <span onclick="ajaxPut('<?php echo Config::get('ajax_url'); ?>?action=basket&amp;type=artist&amp;id=<?php echo $artist->id; ?>');return true;" >
- <?php echo get_user_icon('add'); ?>
- </span>
- <span onclick="ajaxPut('<?php echo Config::get('ajax_url'); ?>?action=basket&amp;type=artist_random&amp;id=<?php echo $artist->id; ?>');return true;" >
- <?php echo get_user_icon('random'); ?>
- </span>
- </td>
- <td><?php echo $artist->f_name_link; ?></td>
- <td><?php echo $artist->songs; ?></td>
- <td><?php echo $artist->albums; ?></td>
- <td nowrap="nowrap">
- <?php if (Access::check_function('batch_download')) { ?>
- <a href="<?php echo Config::get('web_path'); ?>/batch.php?action=artist&amp;id=<?php echo $artist->id; ?>">
- <?php echo get_user_icon('batch_download','',_('Batch Download')); ?>
- </a>
- <?php } ?>
- <?php if ($GLOBALS['user']->has_access(100)) { ?>
- <a href="<?php echo $web_path; ?>/admin/flag.php?action=show_edit_artist&amp;artist_id=<?php echo $artist->id; ?>">
- <?php echo get_user_icon('edit'); ?>
- </a>
- <?php } ?>
- </td>
- </tr>
+<tr id="artist_<?php echo $artist->id; ?>" class="<?php echo flip_class(); ?>">
+ <?php require Config::get('prefix') . '/templates/show_artist_row.inc.php'; ?>
+</tr>
<?php } //end foreach ($artists as $artist) ?>
<tr class="table-header">
<td><?php echo _('Add'); ?>
diff --git a/templates/show_edit_album_row.inc.php b/templates/show_edit_album_row.inc.php
index 340fb685..19bac5ef 100644
--- a/templates/show_edit_album_row.inc.php
+++ b/templates/show_edit_album_row.inc.php
@@ -22,6 +22,7 @@
<td colspan="6">
<form method="post" id="edit_album_<?php echo $album->id; ?>">
<table border="0" cellpadding="3" cellspacing="0">
+<tr>
<td>
<input type="textbox" name="name" value="<?php echo scrub_out($album->name); ?>" />
</td>
@@ -43,6 +44,7 @@
<input type="hidden" name="type" value="album" />
<?php echo Ajax::button('?action=edit_object&id=' . $album->id . '&type=album','download',_('Save Changes'),'save_album_' . $album->id,'edit_album_' . $album->id); ?>
</td>
+</tr>
</table>
</form>
</td>
diff --git a/templates/show_edit_artist_row.inc.php b/templates/show_edit_artist_row.inc.php
new file mode 100644
index 00000000..a3fef3f1
--- /dev/null
+++ b/templates/show_edit_artist_row.inc.php
@@ -0,0 +1,36 @@
+<?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.
+
+*/
+?>
+<td colspan="5">
+<form method="post" id="edit_artist_<?php echo $artist->id; ?>">
+<table border="0" cellpadding="3" cellspacing="0">
+<tr>
+<td>
+ <input type="textbox" name="name" value="<?php echo scrub_out($artist->f_name); ?>" />
+</td>
+<td>
+ <input type="hidden" name="id" value="<?php echo $artist->id; ?>" />
+ <input type="hidden" name="type" value="artist" />
+ <?php echo Ajax::button('?action=edit_object&id=' . $album->id . '&type=artist','download',_('Save Changes'),'save_artist_' . $artist->id,'edit_artist_' . $artist->id); ?>
+</tr>
+</table>
+</form>
+</td>