<?php require 'libs/Smarty.class.php'; require 'functions/getAlbumList.php'; require 'functions/generateAlbumXML.php'; $smarty = new Smarty(); $smarty->debugging = false; $smarty->caching = false; $smarty->cache_lifetime = 120; // Global vars used in process $files_music_found = 0; $files_covers_found = 0; $dir_found = 0; $folder_depth = 0; $generatedXML = ""; $trackID = 1; $albumID = 1; $rootPath = "../data/"; $xmlPath = "xml/"; $path = $rootPath; // CLEAN FOLDER LOOKING FOR SPECIAL CHAR (like &) cleanAlbumFolder($path); // GENERATE XML FROM MUSIC LIBRARY generateAlbumList($path); // Listing albums to display results $arrayAlbums = getAllAlbums(); $smarty->assign("arrayAlbums", $arrayAlbums); $smarty->display('generateAlbumList.tpl');
function cleanAlbumFolder($path) { // This function clean files and folders searching for special char if (is_dir($path)) { if ($dh = opendir($path)) { for ($i = 0; ($file = readdir($dh)) !== false; $i++) { $currentScannedFileorFolder = $path . $file; if ($file != "." && $file != "..") { $specialChar = 0; if (filetype($currentScannedFileorFolder) == "dir") { $folderName = $file; $completePathfolderName = $path . $file . "/"; $newfolderName = $file; $specialChar = preg_match('/&/', $folderName); if ($specialChar != 0) { $newfolderName = str_replace("&", "and", $folderName); $completePathNewfolderName = $path . $newfolderName . "/"; //echo "RENAME FOLDER : OLD=".$completePathfolderName." NEW=".$completePathNewfolderName."<br />"; rename($completePathfolderName, $completePathNewfolderName); } $path .= $newfolderName . "/"; $path = cleanAlbumFolder($path); } elseif (substr($file, 0, 1) != ".") { $completefilepath = $path . $file; $fileName = $file; $specialChar = preg_match('/&/', $fileName); if ($specialChar != 0) { $newfilepath = str_replace("&", "and", $completefilepath); //echo "RENAME FILE : OLD=".$completefilepath." NEW=".$newfilepath."<br />"; rename($completefilepath, $newfilepath); } } } } closedir($dh); $new_path_array = explode("/", $path); $new_path = ""; for ($i = 0; $i < count($new_path_array) - 2; $i++) { $new_path .= $new_path_array[$i] . "/"; } return $new_path; } } }