summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bin/fix_filenames.inc195
-rwxr-xr-xdocs/CHANGELOG6
-rwxr-xr-xdocs/README7
-rw-r--r--lib/class/catalog.class.php67
-rw-r--r--lib/class/democratic.class.php6
-rw-r--r--lib/general.lib.php8
-rw-r--r--templates/show_test.inc.php4
7 files changed, 241 insertions, 52 deletions
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 @@
+<?php
+/*
+
+ Copyright 2001 - 2008 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.
+
+*/
+
+define('NO_SESSION','1');
+$path = dirname(__FILE__);
+$prefix = realpath($path . '/../');
+require_once $prefix . '/lib/init.php';
+
+ob_end_clean();
+
+/*
+ * Pull the root path of your catalogs one by one
+ * and then do a directory sweep and check all of the files
+ * that would be cataloged and see if they have the correct charset
+ * if they don't prompt for a rename, unless $i_am_crazy is true then just
+ * do it
+ */
+
+// If set to true / 1 then it will not prompt!
+//$GLOBALS['i_am_crazy'] = true;
+
+if (!function_exists('iconv')) {
+ echo "ERROR: Iconv required for this functionality, quiting\n";
+ exit;
+}
+
+$sql = "SELECT * FROM `catalog` WHERE `catalog_type`='local'";
+$db_results = Dba::query($sql);
+
+while ($row = Dba::fetch_assoc($db_results)) {
+
+ charset_directory_correct($row['path']);
+
+} // end of the catalogs
+
+
+/**************************************************
+ ****************** FUNCTIONS *********************
+ **************************************************/
+/**
+ * charset_directory_correct
+ * This function calls its self recursivly
+ * and corrects all of the non-matching filenames
+ * it looks at the i_am_crazy var and if not set prompts for change
+ */
+function charset_directory_correct($path) {
+
+ // Correctly detect the slash we need to use here
+ if (strstr($path,"/")) {
+ $slash_type = '/';
+ }
+ else {
+ $slash_type = '\\';
+ }
+
+ /* Open up the directory */
+ $handle = opendir($path);
+
+ if (!is_resource($handle)) {
+ echo "ERROR: Unable to open $path\n";
+ return false;
+ }
+
+ if (!chdir($path)) {
+ echo "ERROR: Unable to chdir to $path\n";
+ return false;
+ }
+
+ while ( false !== ($file = readdir($handle) ) ) {
+
+ if ($file == '.' || $file == '..') { continue; }
+
+ $full_file = $path.$slash_type.$file;
+
+ if (is_dir($full_file)) {
+ charset_directory_correct($full_file);
+ continue;
+ }
+
+ $translated_filename = iconv(Config::get('site_charset'),Config::get('site_charset') . '//IGNORE',$full_file);
+
+ if (strcmp($full_file,$translated_filename) != '0') {
+ echo "--------------------------------------------------------------------------------------------\n";
+ echo "OLD:$full_file has invalid chars\nNEW:$translated_filename\n";
+ echo "--------------------------------------------------------------------------------------------\n";
+ if (!$GLOBALS['i_am_crazy']) {
+ echo "Rename File (Y/N):";
+ $input = trim(fgets(STDIN));
+ if (strcasecmp($input,'Y') == 0) { charset_rename_file($full_file,$translated_filename); }
+ else { echo "\n\tNot Renaming...\n\n"; }
+ }
+ else {
+ charset_rename_file($full_file,$translated_filename);
+ }
+ }
+
+ } // while reading file
+
+} // charset_directory_correct
+
+/**
+ * charset_rename_file
+ * This just takes a source / dest and does the renaming
+ */
+function charset_rename_file($full_file,$translated_filename) {
+
+ // First break out the base directory name and make sure it exists
+ // incase our crap char is in the directory
+ $directory = dirname($translated_filename);
+ $data = preg_split("/[\/\\\]/",$directory);
+ $path = '';
+
+ foreach ($data as $dir) {
+
+ $dir = charset_clean_name($dir);
+ $path .= "/" . $dir;
+
+ if (!is_dir($path)) {
+ echo "\tMaking $path directory\n";
+ $results = mkdir($path);
+ if (!$results) {
+ echo "Error: Unable to create $path move failed, stopping\n";
+ return false;
+ }
+ } // if the dir doesn't exist
+
+ } // end foreach
+
+ // Now to copy the file
+ $results = copy($full_file,$translated_filename);
+
+ if (!$results) {
+ echo "Error: Copy Failed, not deleteing old file\n";
+ return false;
+ }
+
+ $old_sum = filesize($full_file);
+ $new_sum = filesize($translated_filename);
+
+ if ($old_sum != $new_sum OR !$new_sum) {
+ echo "Error: Size Inconsistency, not deleting" . $full_file . "\n";
+ return false;
+ }
+
+ $results = unlink($full_file);
+
+ if (!$results) { echo "Error: Unable to delete " . $full_file . "\n"; return false; }
+
+
+ echo "File Moved...\n\n";
+
+ return true;
+
+} // charset_rename_file
+
+/**
+ * charset_clean_name
+ * We have to have some special rules here
+ * This is run on every individual element of the search
+ * Before it is put togeather, this removes / and \ and also
+ * once I figure it out, it'll clean other stuff
+ */
+function charset_clean_name($string) {
+
+ /* First remove any / or \ chars */
+ $string = preg_replace('/[\/\\\]/','-',$string);
+
+ $string = str_replace(':',' ',$string);
+
+ $string = preg_replace('/[\!\:\*]/','_',$string);
+
+ return $string;
+
+} // charset_clean_name
+
+
+?>
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 "<script type=\"text/javascript\">\n";
- echo "update_txt('" . $this->count ."','add_count_" . $this->id . "');";
- echo "update_txt('" . addslashes(htmlentities($file)) . "','add_dir_" . $this->id . "');";
- echo "\n</script>\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 "<script type=\"text/javascript\">\n";
+ echo "update_txt('" . $this->count ."','add_count_" . $this->id . "');";
+ echo "update_txt('" . addslashes(htmlentities($file)) . "','add_dir_" . $this->id . "');";
+ echo "\n</script>\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&#224;'; break;
- case 'en_GB'; $name = _('British English'); break;
+ case 'en_GB'; $name = 'British English'; break;
case 'es_ES'; $name = 'Espa&ntilde;ol'; break;
case 'el_GR'; $name = 'Greek (&#x0395;&#x03bb;&#x03bb;&#x03b7;&#x03bd;&#x03b9;&#x03ba;&#x03ac;)'; break;
case 'fr_FR'; $name = 'Fran&ccedil;ais'; break;
case 'it_IT'; $name = 'Italiano'; break;
case 'is_IS'; $name = '&Iacute;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') . " (&#x7b80;&#x4f53;&#x4e2d;&#x6587;)"; break;
case 'ru_RU'; $name = 'Russian (&#x0420;&#x0443;&#x0441;&#x0441;&#x043a;&#x0438;&#x0439;)'; 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 @@
<?php
/*
- Copyright (c) 2001 - 2007 Ampache.org
+ Copyright (c) 2001 - 2008 Ampache.org
All Rights Reserved
this program is free software; you can redistribute it and/or
@@ -112,7 +112,7 @@
?>]
</td>
<td>
- <?php echo _('This test checks to make sure you have Iconv support installed. Iconv support is not required for Ampache, but it is highly recommended'); ?>
+ <?php echo _('This test checks to make sure you have Iconv support installed. Iconv support is required for Ampache'); ?>
</td>
</tr>
<tr>