From 27437304248e6d8fd44c2b997673ea112e08afa8 Mon Sep 17 00:00:00 2001 From: Karl 'vollmerk' Vollmer Date: Mon, 17 Mar 2008 00:50:16 +0000 Subject: force consistant charset on file add, add fix_filenames script and minor tweak for democratic play --- bin/fix_filenames.inc | 195 +++++++++++++++++++++++++++++++++++++++++ docs/CHANGELOG | 6 ++ docs/README | 7 +- lib/class/catalog.class.php | 67 ++++++-------- lib/class/democratic.class.php | 6 +- lib/general.lib.php | 8 +- templates/show_test.inc.php | 4 +- 7 files changed, 241 insertions(+), 52 deletions(-) create mode 100644 bin/fix_filenames.inc diff --git a/bin/fix_filenames.inc b/bin/fix_filenames.inc new file mode 100644 index 00000000..247e3724 --- /dev/null +++ b/bin/fix_filenames.inc @@ -0,0 +1,195 @@ + diff --git a/docs/CHANGELOG b/docs/CHANGELOG index a4f04fe2..5c352d3a 100755 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -4,6 +4,12 @@ -------------------------------------------------------------------------- v.3.4-Beta2 + - Added /bin/fix_filenames.inc for correcting filenames with + invalid chars + - Removed album art add on Verify now that there is a distinct + action for it + - Added ICONV check to ensure filenames are of correct charset + before inserting into the database - Fixed issue with encoding of id3v1/v2 tags - Fixed an issue with the clean function for playlists - DB Update, fixes the playlist create issue with full strict on diff --git a/docs/README b/docs/README index c90257cc..d9847ad8 100755 --- a/docs/README +++ b/docs/README @@ -120,8 +120,7 @@ Contents: PHP5-gd (recommended) PHP5 ICONV PHP5 ZLIB support (recommended) - MySQL >= 4.x http://www.mysql.com - 32MB of Ram + MySQL >= 4.1+ http://www.mysql.com 3. Setting Up @@ -151,8 +150,8 @@ Contents: Public SVN: https://svn.ampache.org/ IRC: irc.ampache.org #ampache (Freenode) Forums: http://ampache.org/forums - Bugs: http://bugs.ampache.org/open - Wiki: http://wiki.ampache.org + Bugs: http://trac.ampache.org/ + Wiki: http://trac.ampache.org/wiki Demo: http://ampache.org/demo Ampache Development Team diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php index 1e468e82..3fb50cd6 100644 --- a/lib/class/catalog.class.php +++ b/lib/class/catalog.class.php @@ -92,8 +92,9 @@ class Catalog { private function _create_filecache() { if (count($this->_filecache) == 0) { + $catalog_id = Dba::escape($this->id); // Get _EVERYTHING_ - $sql = "SELECT `id`,`file` FROM `song` WHERE `catalog`='$this->id'"; + $sql = "SELECT `id`,`file` FROM `song` WHERE `catalog`='$catalog_id'"; $db_results = Dba::query($sql); // Populate the filecache @@ -411,12 +412,14 @@ class Catalog { if (!is_resource($handle)) { debug_event('read',"Unable to Open $path",'5','ampache-catalog'); Error::add('catalog_add',_('Error: Unable to open') . ' ' . $path); + return false; } /* Change the dir so is_dir works correctly */ if (!chdir($path)) { debug_event('read',"Unable to chdir $path",'2','ampache-catalog'); Error::add('catalog_add',_('Error: Unable to change to directory') . ' ' . $path); + return false; } // Ensure that we've got our cache @@ -429,7 +432,6 @@ class Catalog { if ($file == '.' || $file == '..') { continue; } debug_event('read',"Starting work on $file inside $path",'5','ampache-catalog'); - /* Create the new path */ $full_file = $path.$slash_type.$file; @@ -483,7 +485,7 @@ class Catalog { if (preg_match($pattern ,$file)) { /* Now that we're sure its a file get filesize */ - $file_size = @filesize($full_file); + $file_size = filesize($full_file); if (!$file_size) { debug_event('read',"Unable to get filesize for $full_file",'2','ampache-catalog'); @@ -496,31 +498,33 @@ class Catalog { Error::add('catalog_add',"$full_file " . _('is not readable by ampache')); continue; } + + // Check to make sure the filename is of the expected charset + if (function_exists('iconv')) { + if (strcmp($full_file,iconv(Config::get('site_charset'),Config::get('site_charset') . '//IGNORE',$full_file)) != '0') { + debug_event('read',$full_file . ' has non-' . Config::get('site_charset') . ' characters and can not be indexed','1'); + Error::add('catalog_add',$full_file . ' ' . _('does not match site charset')); + continue; + } + } // end if iconv if (substr($file,-3,3) == 'm3u' AND $parse_m3u > 0) { $this->_playlists[] = $full_file; } // if it's an m3u else { - - /* If not found then insert, gets id3 information - * and then inserts it into the database - */ - if (!$found) { - $this->insert_local_song($full_file,$file_size); - - /* Stupid little cutesie thing */ - $this->count++; - if ( !($this->count%10)) { - $file = str_replace(array('(',')','\''),'',$full_file); - echo "\n"; - flush(); - } // update our current state - - } // not found + $this->insert_local_song($full_file,$file_size); + + /* Stupid little cutesie thing */ + $this->count++; + if ( !($this->count%10)) { + $file = str_replace(array('(',')','\''),'',$full_file); + echo "\n"; + flush(); + } // update our current state } // if it's not an m3u @@ -1701,27 +1705,8 @@ class Catalog { $info = self::update_song_from_tags($song,$this->sort_pattern,$this->rename_pattern); $album_id = $song->album; if ($info['change']) { - - // Check our cache, this avoids at the very least 2 queriest per song - if (!$album_art_check_cache[$song->album]) { - $album = new Album($song->album); - if (!$album->has_art) { - $found = $album->find_art($options,1); - if (count($found)) { - $image = get_image_from_source($found['0']); - $album->insert_art($image,$found['mime']); - $album_art_check_cache[$album->id] = 1; - } - } // if no art - else { - $album_art_check_cache[$album->id] = 1; - } - } // if not in cache - - flush(); $total_updated++; } - unset($info); } // end skip diff --git a/lib/class/democratic.class.php b/lib/class/democratic.class.php index af1be060..cebb3272 100644 --- a/lib/class/democratic.class.php +++ b/lib/class/democratic.class.php @@ -426,6 +426,11 @@ class Democratic extends tmpPlaylist { $sql = "DELETE FROM `democratic` WHERE `id`='$democratic_id'"; $db_results = Dba::query($sql); + $sql = "DELETE FROM `tmp_playlist` WHERE `session`='$democratic_id'"; + $db_results = Dba::query($sql); + + self::prune_tracks(); + return true; } // delete @@ -464,7 +469,6 @@ class Democratic extends tmpPlaylist { parent::create($insert_id,'vote','song'); } - return $db_results; } // create diff --git a/lib/general.lib.php b/lib/general.lib.php index 4e9f39c5..e9cf0e3b 100644 --- a/lib/general.lib.php +++ b/lib/general.lib.php @@ -382,7 +382,7 @@ function get_languages() { $results = array(); /* Prepend English */ - $results['en_US'] = _('English'); + $results['en_US'] = 'English'; while ($file = readdir($handle)) { @@ -393,16 +393,16 @@ function get_languages() { switch($file) { case 'de_DE'; $name = 'Deutsch'; break; - case 'en_US'; $name = _('English'); break; + case 'en_US'; $name = 'English'; break; case 'ca_CA'; $name = 'Català'; break; - case 'en_GB'; $name = _('British English'); break; + case 'en_GB'; $name = 'British English'; break; case 'es_ES'; $name = 'Español'; break; case 'el_GR'; $name = 'Greek (Ελληνικά)'; break; case 'fr_FR'; $name = 'Français'; break; case 'it_IT'; $name = 'Italiano'; break; case 'is_IS'; $name = 'Íslenska'; break; case 'nl_NL'; $name = 'Nederlands'; break; - case 'tr_TR'; $name = _('Turkish'); break; + case 'tr_TR'; $name = 'Turkish'; break; case 'zh_CN'; $name = _('Simplified Chinese') . " (简体中文)"; break; case 'ru_RU'; $name = 'Russian (Русский)'; break; default: $name = _('Unknown'); break; diff --git a/templates/show_test.inc.php b/templates/show_test.inc.php index dbde51d7..6fbfc45e 100644 --- a/templates/show_test.inc.php +++ b/templates/show_test.inc.php @@ -1,7 +1,7 @@ ] - + -- cgit