コード例 #1
0
ファイル: filldb.php プロジェクト: h3xstream/bandlogos
function loadLogos($dir)
{
    if (!is_dir($dir)) {
        echo "Invalid directory";
    } else {
        global $nbInsert;
        global $_PATH;
        if ($handle = opendir($dir)) {
            while (($file = readdir($handle)) !== false) {
                ///---Extraction
                $parts = explode('.', $file);
                $ext = array_pop($parts);
                ///---Valid formats
                if (!($ext == 'gif' || $ext == 'jpg' || $ext == 'png')) {
                    continue;
                }
                ///---Name repack
                $name = join(".", $parts);
                $name = str_replace('__', '.', $name);
                $name = str_replace('_', '%', $name);
                ///---Extra Validations
                //Check for special caracters not encoded
                if (strpos($name, '_') !== false || strpos($name, ' ') !== false) {
                    echo "<b>" . $name . " sould be rename to " . str_replace(array('_', ' '), array('+', '+'), $name) . ".</b><br/>";
                    continue;
                } else {
                    if (strpos($name, '%') === false) {
                        $nameCheck = urlencode(str_replace(array('+'), array(''), $name));
                        //Char excludes
                        //Some caracter are not support yet
                        if (strpos($nameCheck, '%') !== false) {
                            echo "<b>" . $name . " is not properly parse.</b><br/>";
                            continue;
                        }
                    }
                }
                $prev = $name;
                ///---Insert in db
                if (artistExist($name)) {
                    continue;
                }
                echo $name . " - ";
                $newDate = filemtime(Config::FOLDER_LOGOS . $file);
                //Date of modification (new file)
                $newArtist = new Artist($name, $file, "", -1, $newDate);
                Artists::addArtist($newArtist);
                $nbInsert++;
            }
            closedir($handle);
        }
    }
}